/* ============================================================
   Conciliador ARCA ↔ Flexxus - Cerámica Fantini
   Paleta tomada del logo: amarillo, naranja, celeste, verde agua
   ============================================================ */

:root {
  --negro: #111111;
  --gris-900: #1c1c1c;
  --gris-700: #3a3a3a;
  --gris-500: #6b6b6b;
  --gris-300: #cccccc;
  --gris-100: #f4f4f4;
  --blanco: #ffffff;

  --amarillo: #f5c93a;
  --naranja: #e96b3a;
  --celeste: #5fc4e7;
  --verde:   #8fd1b4;

  --ok:      #2e9e6a;
  --warn:    #e0a53a;
  --err:     #d94a4a;
  --info:    #3a8fe0;

  --shadow: 0 2px 8px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.10);
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--gris-100);
  color: var(--gris-900);
  font-size: 14px;
}

/* ============ HEADER ============ */
.app-header {
  background: var(--negro);
  color: var(--blanco);
  padding: 18px 28px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 4px solid;
  border-image: linear-gradient(90deg,
    var(--amarillo) 0%,
    var(--amarillo) 25%,
    var(--naranja)  25%,
    var(--naranja)  50%,
    var(--celeste)  50%,
    var(--celeste)  75%,
    var(--verde)    75%,
    var(--verde)    100%) 1;
}
.brand {
  display: flex;
  flex-direction: column;
  line-height: 1;
}
.brand-mark {
  font-weight: 700;
  font-size: 20px;
  letter-spacing: -0.3px;
  white-space: nowrap;
}
.brand-sub {
  font-size: 9px;
  letter-spacing: 3px;
  text-transform: uppercase;
  opacity: 0.65;
  margin-top: 4px;
}
.app-header h1 {
  font-size: 20px;
  font-weight: 500;
  margin: 0;
}
.app-header h1 span {
  color: var(--amarillo);
  font-weight: 700;
}

/* ============ LAYOUT ============ */
.container {
  max-width: 1280px;
  margin: 24px auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--blanco);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
  color: var(--gris-900);
  display: flex;
  align-items: center;
  gap: 10px;
}
.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: var(--negro);
  color: var(--amarillo);
  border-radius: 50%;
  font-size: 12px;
  font-weight: 700;
}

/* ============ Período ============ */
.row {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
}
.row label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  font-weight: 600;
  color: var(--gris-700);
  gap: 6px;
}
.row label.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
}
.row input[type=number],
.row select {
  font-size: 14px;
  padding: 8px 12px;
  border: 1px solid var(--gris-300);
  border-radius: 6px;
  background: var(--blanco);
  min-width: 160px;
  font-family: inherit;
}

/* ============ Archivos ============ */
.grid-files {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}
.grid-files-2 {
  grid-template-columns: repeat(2, 1fr);
  max-width: 900px;
}
@media (max-width: 900px) {
  .grid-files { grid-template-columns: 1fr; }
  .grid-files-2 { grid-template-columns: 1fr; }
}
.file-box {
  border: 1.5px dashed var(--gris-300);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--gris-100);
  transition: all .2s;
}
.file-box:hover {
  border-color: var(--negro);
  background: var(--blanco);
}
.file-box.loaded {
  border-style: solid;
  border-color: var(--ok);
  background: #f0faf5;
}
.file-box.error {
  border-color: var(--err);
  background: #fdf2f2;
}
.file-box-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
  flex-wrap: wrap;
}
.tag {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
}
.tag-arca    { background: var(--celeste); color: var(--negro); }
.tag-flexxus { background: var(--naranja); color: var(--blanco); }

.file-name {
  font-size: 12px;
  color: var(--gris-500);
  font-weight: 500;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hint {
  font-size: 12px;
  color: var(--gris-500);
  margin: 4px 0 10px;
}
.file-box input[type=file] {
  width: 100%;
  font-size: 12px;
}
.file-status {
  margin-top: 8px;
  font-size: 12px;
  font-weight: 500;
  min-height: 16px;
}
.file-status.ok  { color: var(--ok); }
.file-status.err { color: var(--err); }

/* ============ Controles de vinculación (File System Access API) ============ */
.vincular-controls {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.btn-link {
  background: transparent;
  border: 1px solid var(--gris-300);
  border-radius: 4px;
  padding: 4px 10px;
  font-family: inherit;
  font-size: 11px;
  color: var(--gris-700);
  cursor: pointer;
  transition: all .15s;
}
.btn-link:hover {
  border-color: var(--negro);
  color: var(--negro);
  background: white;
}
.btn-link:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-link.btn-recargar {
  border-color: var(--celeste);
  color: var(--info);
  font-weight: 600;
}
.btn-link.btn-recargar:hover {
  background: var(--celeste);
  color: var(--negro);
}
.btn-link.btn-drive {
  border-color: #4285f4;
  color: #4285f4;
}
.btn-link.btn-drive:hover {
  background: #4285f4;
  color: white;
}
.btn-link.btn-desvincular:hover {
  border-color: var(--err);
  color: var(--err);
}
.vincular-hint {
  font-size: 10px;
  color: var(--gris-500);
  font-style: italic;
  margin-top: 4px;
}

/* ============ Botones ============ */
.actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
}
.btn {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 18px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary {
  background: var(--negro);
  color: var(--amarillo);
}
.btn-primary:hover { background: var(--gris-900); transform: translateY(-1px); }
.btn-secondary {
  background: var(--amarillo);
  color: var(--negro);
}
.btn-secondary:hover { background: #ecc033; }
.btn-ghost {
  background: transparent;
  color: var(--gris-700);
  border: 1px solid var(--gris-300);
}
.btn-ghost:hover { background: var(--gris-100); border-color: var(--gris-500); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

/* ============ Mensajes ============ */
#mensajes { display: flex; flex-direction: column; gap: 8px; }
.msg {
  padding: 12px 16px;
  border-radius: 6px;
  font-size: 13px;
  border-left: 4px solid;
  background: var(--blanco);
  box-shadow: var(--shadow);
}
.msg-info  { border-color: var(--info); }
.msg-ok    { border-color: var(--ok);   background: #f0faf5; }
.msg-warn  { border-color: var(--warn); background: #fff8ea; }
.msg-err   { border-color: var(--err);  background: #fdf2f2; }

/* ============ KPIs ============ */
.kpis {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 12px;
}
@media (max-width: 800px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

.kpi {
  padding: 16px;
  border-radius: var(--radius);
  text-align: center;
  background: var(--gris-100);
  border-top: 4px solid var(--gris-300);
}
.kpi .n { font-size: 30px; font-weight: 700; line-height: 1; }
.kpi .l { font-size: 11px; font-weight: 600; margin-top: 6px; color: var(--gris-700); text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-ok   { border-top-color: var(--ok);   }
.kpi-ok   .n { color: var(--ok);   }
.kpi-warn { border-top-color: var(--warn); }
.kpi-warn .n { color: var(--warn); }
.kpi-err  { border-top-color: var(--err);  }
.kpi-err  .n { color: var(--err);  }
.kpi-dup  { border-top-color: var(--info); }
.kpi-dup  .n { color: var(--info); }

/* ============ Tabs ============ */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid var(--gris-300);
  margin-bottom: 16px;
  overflow-x: auto;
}
.tab {
  background: transparent;
  border: none;
  padding: 10px 18px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--gris-500);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all .15s;
}
.tab:hover { color: var(--gris-900); }
.tab.active {
  color: var(--negro);
  border-bottom-color: var(--amarillo);
}
.panel { display: none; }
.panel.active { display: block; }

/* ============ Tablas ============ */
.tabla-wrap {
  overflow-x: auto;
  border: 1px solid var(--gris-300);
  border-radius: 6px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
th {
  background: var(--gris-100);
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--gris-300);
  color: var(--gris-700);
  white-space: nowrap;
  position: sticky;
  top: 0;
  z-index: 1;
}
td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--gris-100);
  vertical-align: top;
}
tr:hover td { background: #fafafa; }
td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.dif-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #fdecec;
  color: var(--err);
  font-weight: 600;
  white-space: nowrap;
}
.dif-zero { background: #e8f5ee; color: var(--ok); }
.mono { font-family: "SF Mono", Consolas, Monaco, monospace; font-size: 12px; }

.empty {
  padding: 36px;
  text-align: center;
  color: var(--gris-500);
  font-style: italic;
}

.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.filter-bar input {
  padding: 6px 10px;
  border: 1px solid var(--gris-300);
  border-radius: 4px;
  font-family: inherit;
  font-size: 12px;
  min-width: 200px;
}
.row-count {
  font-size: 11px;
  color: var(--gris-500);
  margin-left: auto;
}

/* ============ Footer ============ */
.app-footer {
  width: 100%;
  text-align: center;
  padding: 32px 20px;
  background: var(--negro);
  color: #e8e8e8;
  font-size: 13px;
  font-style: italic;
  letter-spacing: 0.5px;
  border-top: 3px solid var(--amarillo);
  box-sizing: border-box;
}

/* ============================================================
 *  NAVEGACIÓN ENTRE VISTAS (Conciliación / Herramientas)
 * ============================================================ */
.app-header {
  flex-wrap: wrap;
}
.view-nav {
  display: flex;
  gap: 6px;
  margin-left: auto;
}
.view-tab {
  background: transparent;
  color: rgba(255,255,255,0.65);
  border: 1px solid rgba(255,255,255,0.15);
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all .15s;
}
.view-tab:hover {
  color: white;
  border-color: rgba(255,255,255,0.4);
}
.view-tab.active {
  background: var(--amarillo);
  color: var(--negro);
  border-color: var(--amarillo);
}

.view { display: none; }
.view.active {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ============ Grilla archivos variantes ============ */
.grid-files-1 {
  grid-template-columns: 1fr;
  max-width: 600px;
}

/* ============ Tag para herramientas ============ */
.tag-tools {
  background: var(--verde);
  color: var(--negro);
}

/* ============ KPIs extras ============ */
.kpis-4 { grid-template-columns: repeat(4, 1fr); }
.kpis-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 800px) {
  .kpis-4 { grid-template-columns: repeat(2, 1fr); }
  .kpis-5 { grid-template-columns: repeat(2, 1fr); }
}

.kpi-info  { border-top-color: var(--info);  }
.kpi-info  .n { color: var(--info);  }
.kpi-money { border-top-color: var(--amarillo); }
.kpi-money .n { color: var(--negro); }

/* ============ Badges de estado de herramientas ============ */
.badge-estado {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.badge-ok        { background: #e8f5ee; color: var(--ok); }
.badge-faltante  { background: #fdecec; color: var(--err); }
.badge-rota      { background: #fff1e0; color: #d37a00; }

/* Botones pequeños dentro de tabla (para editar estado, etc.) */
.btn-small {
  font-family: inherit;
  font-size: 11px;
  padding: 3px 8px;
  border: 1px solid var(--gris-300);
  background: white;
  border-radius: 4px;
  cursor: pointer;
}
.btn-small:hover { background: var(--gris-100); }

/* ============ MODALES ============ */
.modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal[style*="flex"] { display: flex !important; }
.modal-content {
  background: white;
  border-radius: var(--radius);
  width: 90%;
  max-width: 700px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-head, .modal-foot {
  padding: 16px 22px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-head {
  border-bottom: 1px solid var(--gris-300);
  justify-content: space-between;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-foot {
  border-top: 1px solid var(--gris-300);
  justify-content: flex-end;
}
.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}
.modal-close {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--gris-500);
  padding: 4px 10px;
  border-radius: 4px;
}
.modal-close:hover { background: var(--gris-100); color: var(--gris-900); }

/* Input de precios inline */
.precio-input {
  width: 120px;
  padding: 4px 8px;
  border: 1px solid var(--gris-300);
  border-radius: 4px;
  font-family: inherit;
  font-size: 12px;
  text-align: right;
}
.precio-input:focus { border-color: var(--amarillo); outline: none; }
.precio-faltante { background: #fff8ea !important; }

/* Tag de cantidad en tabla de personas */
.cant-cell {
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 10px;
  display: inline-block;
  min-width: 28px;
  text-align: center;
}
.cant-faltante { background: #fdecec; color: var(--err); }
.cant-rota     { background: #fff1e0; color: #d37a00; }
.cant-zero     { color: var(--gris-500); font-weight: 500; }

/* Entrada del historial */
.historial-entry {
  padding: 12px 16px;
  border-bottom: 1px solid var(--gris-100);
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
}
.historial-entry:hover { background: var(--gris-100); }
.historial-entry .fecha {
  font-weight: 700;
  font-size: 14px;
  min-width: 110px;
}
.historial-entry .stats {
  flex: 1;
  font-size: 12px;
  color: var(--gris-700);
}
.historial-entry .monto {
  font-weight: 700;
  color: var(--ok);
  font-variant-numeric: tabular-nums;
}

/* ============ Tabla de personas con desplegable ============ */
.persona-row[data-persona-idx] {
  cursor: pointer;
}
.persona-row[data-persona-idx]:hover {
  background: #fafafa;
}
.expand-ind {
  font-size: 13px;
  color: var(--gris-500);
  transition: transform .15s;
}
.persona-detalle {
  background: #fafafa;
}
.persona-detalle > td {
  padding: 12px 24px 16px !important;
}
.inner-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: white;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.inner-table th {
  background: white;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gris-500);
  padding: 8px 12px;
  border-bottom: 1px solid var(--gris-300);
}
.inner-table td {
  padding: 6px 12px;
  border-bottom: 1px solid #f0f0f0;
}
.arrastre-badge {
  display: inline-block;
  background: var(--err);
  color: white;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.7; }
}
