/* ── RESET & BASE ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Fondos */
  --bg:        #f5f0e8;  /* Fondo principal crema */
  --panel:     #ede8dc;  /* Fondo secundario */
  --card:      #ffffff; /* Tarjetas */
  --row-alt:   #f0ebe1;  /* Filas alternas */

  /* Bordes */
  --border:    #e0dbd0;

  /* Identidad Pergamino */
  --accent:    #3b5f65; /* Color principal */
  --accent2:   #7cb9b8; /* Medio / apoyo */

  /* Botones */
  --btn:       #3b5f65;
  --btn-hov:   #2f4d52;

  /* Texto */
  --text:      #2c2c2c;
  --subtext:   #595959;       /* oscurecido para WCAG AA (>=4.5:1 sobre crema) */

  /* Estados */
  --ok:        #5fa889;
  --ok-strong: #2f7558;       /* verde con contraste suficiente sobre fondos claros */
  --error:     #b85c5c;
  --error-strong: #8a3a3a;    /* rojo con contraste suficiente sobre fondos claros */
  --error-bg:  #fde7e7;
  --error-border: #d99898;

  /* Estados de filas (mapa semántico, no literal rojo/verde) */
  --green-row: #e6f1ee;
  --red-row:   #f3e6e6;

  /* Tipografía */
  --font:      'Segoe UI', system-ui, sans-serif;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg); color: var(--text); }

/* ── LAYOUT ───────────────────────────────────────────── */
body { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 310px;
  min-width: 260px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  padding: 0 0 16px;
  flex-shrink: 0;
}

.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── SIDEBAR HEADER ───────────────────────────────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
}
.logo { font-size: 28px; }
.app-title { font-size: 15px; font-weight: 700; color: var(--accent); }
.app-sub   { font-size: 11px; color: var(--subtext); }

/* ── USER BAR (sesión activa) ─────────────────────────── */
.user-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.user-name {
  font-size: 12px;
  color: var(--text);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.logout-link {
  font-size: 11px;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.logout-link:hover { color: var(--btn-hov); text-decoration: underline; }
.user-bar-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.admin-link {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
}
.admin-link:hover { background: var(--panel); color: var(--btn-hov); }

/* ── SECTION LABELS ───────────────────────────────────── */
.section-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--subtext);
  padding: 12px 16px 4px;
}
.section-label.mt-large { margin-top: 18px; }
.section-label.mt-medium { margin-top: 14px; }

/* ── FILE INPUTS ──────────────────────────────────────── */
.file-tip {
  font-size: 11px;
  color: var(--subtext);
  padding: 0 16px 6px;
}

.co-filter-hint {
  font-size: 11px;
  color: var(--subtext);
  padding: 0 12px;
  margin: 2px 0 4px;
}

.file-row {
  padding: 6px 12px;
  border-top: 1px solid var(--border);
}
.file-row-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.file-label {
  flex: 1;
  font-size: 11px;
  color: var(--text);
  font-weight: 600;
}
.file-count {
  font-size: 11px;
  color: var(--subtext);
}
.file-count.has-files { color: var(--ok-strong); font-weight: 700; }

.btn-file {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  cursor: pointer;
  transition: background .15s;
}
.btn-file:hover { background: var(--btn-hov); }

.file-list { display: flex; flex-direction: column; gap: 2px; }
.file-item {
  display: flex;
  align-items: center;
  background: var(--bg);
  border-radius: 3px;
  padding: 2px 6px;
  font-size: 10px;
  color: var(--subtext);
  gap: 4px;
}
.file-item span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-remove-file {
  background: none;
  border: none;
  color: var(--error);
  cursor: pointer;
  font-size: 11px;
  padding: 0 2px;
  line-height: 1;
}

/* ── DATE ROW ─────────────────────────────────────────── */
.date-row {
  display: flex;
  gap: 8px;
  padding: 4px 12px 0;
}
.date-group {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.date-group label {
  font-size: 11px;
  color: var(--subtext);
  font-weight: 600;
}
.date-group input[type="date"] {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 11px;
  padding: 5px 7px;
  width: 100%;
  outline: none;
}
.date-group input[type="date"]:focus {
  border-color: var(--accent);
}

/* ── CO SELECT ────────────────────────────────────────── */
.co-select {
  margin: 4px 12px 0;
  width: calc(100% - 24px);
  min-height: 140px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 12px;
  padding: 4px;
  outline: none;
  cursor: pointer;
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.06), 0 1px 3px rgba(0,0,0,0.04);
  transition: border-color .15s, box-shadow .15s;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.co-select:hover:not(:disabled) {
  border-color: var(--accent2);
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.06), 0 0 0 3px rgba(124,185,184,0.15);
}
.co-select:focus {
  border-color: var(--accent);
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.06), 0 0 0 3px rgba(59,95,101,0.18);
}
.co-select:disabled { opacity: .45; cursor: default; }
.co-select option {
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
}
.co-select option:checked {
  background: linear-gradient(var(--accent), var(--accent));
  color: #fff;
  font-weight: 600;
}

/* ── CO COMBOBOX ──────────────────────────────────────── */
.co-combobox {
  margin: 4px 12px 0;
  width: calc(100% - 24px);
}
.co-combo-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 10px;
  cursor: pointer;
  text-align: left;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: border-color .15s, box-shadow .15s, border-radius .15s;
}
.co-combo-trigger:hover:not(:disabled) {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(124,185,184,0.15);
}
.co-combo-trigger:disabled { opacity: .45; cursor: default; }
.co-combo-arrow {
  font-size: 10px;
  color: var(--subtext);
  transition: transform .2s;
  flex-shrink: 0;
  margin-left: 6px;
}
.co-combobox.open .co-combo-trigger {
  border-color: var(--accent);
  border-radius: 8px 8px 0 0;
  box-shadow: 0 0 0 3px rgba(59,95,101,0.15);
}
.co-combobox.open .co-combo-arrow { transform: rotate(180deg); }
.co-combo-dropdown {
  display: none;
  background: var(--card);
  border: 1.5px solid var(--accent);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.co-combobox.open .co-combo-dropdown { display: block; }
.co-combo-header {
  display: flex;
  gap: 6px;
  padding: 7px 10px 6px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.co-combo-action {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--accent);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.co-combo-action:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
#co-combo-list {
  max-height: 160px;
  overflow-y: auto;
  padding: 3px 0;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.co-combo-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background .1s;
}
.co-combo-item:hover { background: var(--row-alt); }
.co-combo-item input[type=checkbox] {
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  cursor: pointer;
}

/* ── BUTTONS ──────────────────────────────────────────── */
.btn-primary, .btn-secondary {
  margin: 6px 12px 0;
  width: calc(100% - 24px);
  border-radius: 6px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 0;
  cursor: pointer;
  transition: background .15s, color .15s, opacity .15s;
}
/* Acción principal: solid accent, blanco. Jerarquía dominante. */
.btn-primary {
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
}
.btn-primary:hover:not(:disabled) { background: var(--btn-hov); border-color: var(--btn-hov); }
/* Acciones secundarias: outline. Texto accent sobre fondo claro. */
.btn-secondary {
  background: var(--card);
  color: var(--accent);
  border: 1px solid var(--accent);
}
.btn-secondary:hover:not(:disabled) { background: var(--accent); color: #fff; }
.btn-primary:disabled, .btn-secondary:disabled {
  opacity: .5;
  cursor: default;
}

/* Variante compacta para botones inline pequeños (Limpiar filtro CO, Cerrar modal) */
.btn-compact {
  margin-top: 4px;
  padding: 4px 10px;
  font-size: 11px;
  width: auto;
}

/* ── LEGEND ───────────────────────────────────────────── */
.legend {
  margin: 14px 12px 0;
  background: var(--card);
  border-radius: 6px;
  padding: 10px 12px;
}
.legend-title { font-size: 11px; font-weight: 700; color: var(--subtext); margin-bottom: 6px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--subtext); margin: 3px 0; }
.dot { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.dot.green { background: var(--ok); }
.dot.red   { background: var(--error); }
.dot.grey  { background: var(--border); }

/* ── STATUS BAR ───────────────────────────────────────── */
.status-bar {
  margin: 10px 12px 0;
  font-size: 11px;
  color: var(--subtext);
  text-align: center;
  padding: 4px 0;
}

/* ── TABS ─────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
  scrollbar-width: none;
  position: relative;
}
.tab-bar::-webkit-scrollbar { display: none; }
/* Fade derecho que sugiere scroll horizontal cuando hay más tabs (mobile) */
@media (max-width: 768px) {
  .tab-bar {
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent 100%);
            mask-image: linear-gradient(to right, #000 calc(100% - 24px), transparent 100%);
  }
}

.tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--subtext);
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 12px 18px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── PANELS ───────────────────────────────────────────── */
.tab-panel {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
}
.tab-panel.active { display: flex; }

.panel-header {
  padding: 14px 20px 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-header h2 { font-size: 15px; font-weight: 700; }
.panel-sub { font-size: 11px; color: var(--subtext); }

.rappi-global {
  padding: 10px 20px;
  font-size: 12px;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  flex-shrink: 0;
}

/* ── WARNING BAR ──────────────────────────────────────── */
.warning-bar {
  background: #fff8e1;
  border-bottom: 1px solid #f5c842;
  padding: 8px 20px;
  font-size: 12px;
  color: #6b5000;
  flex-shrink: 0;
}
.warning-bar strong { display: block; margin-bottom: 4px; }
.warning-bar ul { margin: 0; padding-left: 16px; }
.warning-bar li { margin: 2px 0; }

/* ── ERROR BANNER (reemplaza alert() nativos) ──────────── */
.error-banner {
  position: relative;
  background: var(--error-bg);
  border-bottom: 1px solid var(--error-border);
  padding: 10px 40px 10px 20px;
  font-size: 12px;
  color: var(--error-strong);
  flex-shrink: 0;
  line-height: 1.5;
  animation: error-slide-in .15s ease-out;
}
.error-banner strong { display: inline; margin-right: 4px; }
.error-banner .error-close {
  position: absolute;
  top: 6px;
  right: 10px;
  background: none;
  border: none;
  color: var(--error-strong);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 6px;
  line-height: 1;
}
.error-banner .error-close:hover { color: #000; }
@keyframes error-slide-in {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── TABLES ───────────────────────────────────────────── */
.table-wrap {
  flex: 1;
  overflow: auto;
  padding: 12px 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
thead th {
  background: var(--card);
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  padding: 9px 12px;
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 2px solid var(--border);
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--text); }
thead th.num { text-align: right; }

tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover td { background: rgba(59,95,101,0.09) !important; cursor: pointer; }
tbody td {
  padding: 7px 12px;
  border-bottom: 1px solid rgba(255,255,255,.04);
  white-space: nowrap;
}
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Diferencia coloreada */
tr.row-pos td { background: var(--green-row) !important; }
tr.row-pos td.diff { color: var(--ok); font-weight: 600; }
tr.row-neg td { background: var(--red-row) !important; }
tr.row-neg td.diff { color: var(--error); font-weight: 600; }

.empty-msg {
  color: var(--subtext);
  text-align: center;
  padding: 40px !important;
  font-style: italic;
}

/* ── MODAL ────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 40px;
  min-width: 300px;
  text-align: center;
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 10px; }
.modal-msg   { font-size: 12px; color: var(--subtext); margin-bottom: 18px; }
.modal-box.siesa { min-width: 520px; max-width: 700px; max-height: 80vh; overflow-y: auto; }
.siesa-modal-body { text-align: left; font-size: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: center; }
.modal-actions .btn-secondary,
.modal-actions .btn-siesa-send { width: auto; padding: 8px 20px; margin: 0; }
@media (max-width: 768px) {
  .modal-box.siesa { min-width: 0; width: 92vw; }
}
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  width: 0;
  transition: width .3s ease;
}

/* ── SCROLLBAR ────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--subtext); }

/* ── RESPONSIVE ───────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: 0; border-right: none; border-bottom: 1px solid var(--border); max-height: 50vh; }
  body { flex-direction: column; }
}

/* ── RESUMEN: filas sin diferencia no se resaltan ──────── */
#tbl-resumen tbody tr:not(.row-pos):not(.row-neg) { background: transparent !important; }

/* ── FILA TOTAL POR CO EN RESUMEN ────────────────────── */
tr.co-total-row td {
  background: var(--panel) !important;
  border-top: 2px solid var(--accent2);
  border-bottom: 1px solid var(--border);
  padding: 9px 12px;
  font-size: 12px;
}

/* ── SEPARADOR VISUAL ENTRE GRUPOS DE CO ─────────────── */
tr.co-group-start td { border-top: 2px solid var(--accent2) !important; }

/* ── FILA TOTAL AL PIE DE TABLAS ─────────────────────── */
tfoot tr.footer-total td {
  background: var(--card) !important;
  border-top: 2px solid var(--accent);
  padding: 9px 12px;
  font-size: 12px;
}

/* ── SIESA BUTTONS ───────────────────────────────────── */
.siesa-divider {
  margin: 10px 12px 0;
  border-top: 1px solid var(--border);
}
.btn-siesa, .btn-siesa-send {
  margin: 6px 12px 0;
  width: calc(100% - 24px);
  border: none;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 12px;
  font-weight: 600;
  padding: 10px 0;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn-siesa {
  background: #2d4a7a;
  color: #fff;
  border: 1px solid #3d6aaa;
}
.btn-siesa:hover:not(:disabled) { background: #3d6aaa; }
.btn-siesa-send {
  background: #1a6b3c;
  color: #fff;
  border: 1px solid #2d9b5a;
}
.btn-siesa-send:hover:not(:disabled) { background: #2d9b5a; }
.btn-siesa:disabled, .btn-siesa-send:disabled { opacity: .4; cursor: default; }

/* SIESA Modal table */
.siesa-table { width:100%; border-collapse:collapse; font-size:11px; margin-top:10px; }
.siesa-table th { background:var(--card); color:var(--accent); padding:6px 8px;
                  text-align:left; border-bottom:2px solid var(--border); }
.siesa-table td { padding:5px 8px; border-bottom:1px solid rgba(255,255,255,.05); }
.siesa-table tr:nth-child(even) { background:var(--row-alt); }
.siesa-db  { color: var(--ok); font-weight:600; }
.siesa-cr  { color: var(--error); font-weight:600; }
.siesa-info { background:var(--card); border-radius:6px; padding:12px;
              margin-bottom:12px; font-size:12px; line-height:1.8; }
.siesa-info span { color:var(--accent); font-weight:600; }
