/* =====================================================================
   VARIABLES GLOBALES
   Paleta pensada para un estudio contable: azul noche + acento dorado,
   fondo gris muy claro para que las tarjetas "floten" sobre la página.
   ===================================================================== */
:root {
  --navy-900: #16243f;
  --navy-800: #1f3354;
  --navy-700: #2b4570;
  --gold-500: #c79a3b;
  --gold-600: #ab7f24;
  --gray-50:  #f4f6f9;
  --gray-100: #e9edf3;
  --gray-200: #dbe1ea;
  --gray-400: #9aa6b8;
  --gray-600: #5b6779;
  --gray-800: #2b3340;
  --red-600:  #c0392b;
  --green-600:#1d7a4c;
  --surface:  #ffffff;
  --heading:  var(--navy-900);
  --radius: 8px;
  --shadow: 0 1px 2px rgba(22, 36, 63, 0.06), 0 4px 14px rgba(22, 36, 63, 0.08);
  --font-base: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", Consolas, monospace;
}

/* ── TEMA OSCURO ──
   Se activa con html[data-theme="dark"], el mismo atributo que ya usa
   el resto de la app (panel.html / styles.css) — así esta página
   respeta el tema que el usuario haya elegido ahí, en vez de quedar
   siempre clara mientras el resto puede ponerse oscuro. */
html[data-theme="dark"] {
  --gray-50:  #11151c;
  --gray-100: #1c212b;
  --gray-200: #2b3140;
  --gray-400: #6b7789;
  --gray-600: #9aa6b8;
  --gray-800: #e8ebf0;
  --surface:  #1a1f29;
  --heading:  #e8ebf0;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.25), 0 4px 14px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--gray-50);
  font-family: var(--font-base);
  color: var(--gray-800);
}

/* =====================================================================
   ENCABEZADO DE LA APLICACIÓN
   ===================================================================== */
.app-header {
  background: var(--navy-900);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}

.app-header__brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.app-header__mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius);
  background: var(--gold-500);
  color: var(--heading);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.app-header__brand h1 {
  font-size: 1.05rem;
  margin: 0;
  line-height: 1.2;
}

.app-header__brand p {
  margin: 0;
  font-size: 0.8rem;
  color: var(--gray-400);
}

.app-header__actions {
  display: flex;
  gap: 10px;
}

/* =====================================================================
   BARRA DE CLIENTE DEL ESTUDIO (aplica a toda la carga)
   ===================================================================== */
.cliente-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  background: #fff8e1;
  border-bottom: 1px solid #f0d98c;
  flex-wrap: wrap;
}
.cliente-bar label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #6b5500;
  white-space: nowrap;
}
.cliente-bar select {
  flex: 1 1 280px;
  max-width: 420px;
  padding: 8px 10px;
  border: 1px solid #e0c659;
  border-radius: 8px;
  font-size: 0.875rem;
  background: #fff;
  color: #1a2030;
}
.cliente-bar select.is-empty {
  border-color: #c0392b;
  box-shadow: 0 0 0 2px rgba(192,57,43,0.12);
}
.cliente-bar__hint {
  font-size: 0.78rem;
  color: #6b5500;
}

/* =====================================================================
   BOTONES
   ===================================================================== */
.btn {
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  padding: 10px 16px;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s ease, background 0.15s ease;
}
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: var(--gold-500);
  color: var(--heading);
}
.btn--primary:hover { background: var(--gold-600); }

.btn--ghost {
  background: transparent;
  color: #fff;
  border: 1px solid rgba(255,255,255,0.35);
}
.btn--ghost:hover { background: rgba(255,255,255,0.08); }

.btn--secondary {
  background: var(--navy-800);
  color: #fff;
  margin-top: 14px;
}
.btn--secondary:hover { background: var(--navy-700); }

.btn--icon {
  background: transparent;
  border: none;
  color: var(--red-600);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px 8px;
  border-radius: 6px;
}
.btn--icon:hover { background: #fbeceb; }

/* =====================================================================
   NAVEGACIÓN POR PESTAÑAS
   ===================================================================== */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--gray-200);
  padding: 6px 24px;
  position: sticky;
  top: 74px;
  z-index: 15;
}

.tab {
  font-family: inherit;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 14px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  white-space: nowrap;
}

.tab:hover { color: var(--navy-800); }

.tab.is-active {
  color: var(--heading);
  border-bottom-color: var(--gold-500);
}

/* =====================================================================
   LAYOUT GENERAL
   ===================================================================== */
.container {
  max-width: 980px;
  margin: 0 auto;
  padding: 28px 20px 80px;
}

.panel { display: none; }
.panel.is-active { display: block; animation: fadeIn 0.15s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

.card {
  background: var(--surface);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  margin-bottom: 20px;
}

.card__title {
  font-size: 1rem;
  margin: 0 0 4px;
  color: var(--heading);
}

.card__hint {
  font-size: 0.8rem;
  color: var(--gray-600);
  margin: 0 0 18px;
}

/* =====================================================================
   GRILLA DE CAMPOS
   ===================================================================== */
.grid {
  display: grid;
  gap: 16px 20px;
}
.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); align-items: end; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field--spacer { visibility: hidden; }

label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.req { color: var(--red-600); }
.opt { text-transform: none; font-weight: 400; color: var(--gray-400); }

input, select, textarea {
  font-family: inherit;
  font-size: 0.9rem;
  padding: 10px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: var(--gray-50);
  color: var(--gray-800);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold-500);
  box-shadow: 0 0 0 3px rgba(199, 154, 59, 0.18);
  background: var(--surface);
}

input:disabled, select:disabled, textarea:disabled {
  background: var(--gray-100);
  color: var(--gray-400);
  cursor: not-allowed;
}

input[type="number"] { font-family: var(--font-mono); text-align: right; }

.field.has-error input,
.field.has-error select {
  border-color: var(--red-600);
  background: #fdf2f1;
}

.field__error {
  font-size: 0.75rem;
  color: var(--red-600);
  min-height: 1em;
}

/* =====================================================================
   TOTAL
   ===================================================================== */
.total-box {
  margin-top: 22px;
  border-top: 2px solid var(--heading);
  padding-top: 14px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.total-box span {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.total-box strong {
  font-size: 1.6rem;
  color: var(--heading);
  font-family: var(--font-mono);
}

/* =====================================================================
   TABLA DE ÍTEMS
   ===================================================================== */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.items-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--gray-600);
  border-bottom: 2px solid var(--gray-200);
  padding: 8px 8px;
}

.items-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

.items-table input {
  background: var(--surface);
  padding: 8px 9px;
}

.items-table td.text-right,
.items-table th:nth-child(3),
.items-table th:nth-child(4),
.items-table th:nth-child(5) {
  text-align: right;
}

.items-table input[type="number"] { text-align: right; }

.item-subtotal {
  font-family: var(--font-mono);
  text-align: right;
  white-space: nowrap;
}

.items-table tfoot td {
  border-bottom: none;
  border-top: 2px solid var(--heading);
  font-weight: 700;
  padding-top: 10px;
}

#subtotalItems { font-family: var(--font-mono); }

/* =====================================================================
   LISTA DE COMPROBANTES GUARDADOS
   ===================================================================== */
.saved-list { display: flex; flex-direction: column; gap: 10px; }

.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  padding: 12px 14px;
  background: var(--gray-50);
}

.saved-item__info strong { display: block; font-size: 0.9rem; color: var(--heading); }
.saved-item__info span { font-size: 0.78rem; color: var(--gray-600); }

.saved-item__actions { display: flex; gap: 8px; }

.saved-item__tag {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 1px 7px;
  border-radius: 99px;
  margin-right: 6px;
  vertical-align: middle;
}
.saved-item__tag--manual { background: #e8edf5; color: #16243f; }
.saved-item__tag--afip   { background: #fff3cd; color: #6b5500; }

.empty-state {
  color: var(--gray-400);
  font-size: 0.85rem;
  padding: 12px 0;
}

/* =====================================================================
   TOAST DE NOTIFICACIONES
   ===================================================================== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--navy-900);
  color: #fff;
  padding: 12px 18px;
  border-radius: 6px;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 50;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: var(--red-600); }
.toast.is-success { background: var(--green-600); }

/* =====================================================================
   SECCIÓN: IMPORTAR COMPROBANTES AFIP
   ===================================================================== */
.afip-dropzones-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 18px;
}
@media (max-width: 640px) {
  .afip-dropzones-grid { grid-template-columns: 1fr; }
}
.afip-dropzone-label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--heading);
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dropzone {
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  background: var(--gray-50);
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--gold-500);
  outline: none;
}
.dropzone.is-dragover {
  border-color: var(--gold-500);
  background: #fbf4e6;
}
.dropzone__title {
  margin: 0 0 4px;
  font-weight: 600;
  color: var(--heading);
  font-size: 0.92rem;
}
.dropzone__hint {
  margin: 0;
  font-size: 0.78rem;
  color: var(--gray-600);
}
.dropzone__filename {
  margin: 10px 0 0;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--gold-600);
}

.afip-toolbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.afip-toolbar .field { max-width: 280px; }
.afip-toolbar__resumen {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--navy-800);
  padding-bottom: 10px;
}

.afip-preview-table { margin-top: 18px; font-size: 0.8rem; }
.afip-preview-table th:nth-child(n+8),
.afip-preview-table td:nth-child(n+8) { text-align: right; }

.badge-op {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.badge-op--venta      { background: #dcfce7; color: #166534; }
.badge-op--compra     { background: #dbeafe; color: #1e40af; }
.badge-op--pendiente  { background: #fef3c7; color: #92400e; font-size: 0.62rem; }

.afip-actions {
  margin-top: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.afip-status {
  font-size: 0.82rem;
  color: var(--gray-600);
}

/* =====================================================================
   RESPONSIVE
   ===================================================================== */
@media (max-width: 720px) {
  .grid--2, .grid--3 { grid-template-columns: 1fr; }
  .field--spacer { display: none; }
  .app-header { padding: 14px 16px; flex-wrap: wrap; gap: 10px; }
  .app-header__actions { flex-wrap: wrap; }
  .tabs { top: 66px; padding: 0 12px; }
  .container { padding: 20px 12px 60px; }
  .afip-toolbar { flex-direction: column; align-items: stretch; }
  /* Las tablas de ítems (unidades, gastos, períodos, pagos, etc.) tienen
     muchas columnas — en vez de aplastarlas hasta que el texto se corte,
     les damos un ancho mínimo y dejamos que .table-wrap las scrollee
     horizontal (mismo patrón que .clients-table en styles.css). */
  .items-table { min-width: 640px; }
  .cliente-bar { padding: 10px 14px; }
  .cliente-bar select { max-width: 100%; }
}
