* { box-sizing: border-box; }

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f3f7;
  --border: #d8dde5;
  --text: #1a1f2c;
  --muted: #6b7280;
  --accent: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}

header nav a {
  display: inline-block;
  padding: 6px 14px;
  margin-right: 8px;
  color: var(--muted);
  text-decoration: none;
  border-radius: 4px;
  font-weight: 500;
}
header nav a:hover { color: var(--text); background: var(--surface-2); }
header nav a.active { color: var(--accent); background: var(--surface-2); }

.header-right { display: flex; align-items: center; gap: 16px; }

/* "Datos al ...": frescura del libro mayor importado. Discreto: es contexto,
   no un dato del P&L. Se pone ambar si el import tiene mas de 48h. */
.procedencia {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.procedencia.stale { color: var(--amber); }

.anio-selector { display: flex; align-items: center; gap: 8px; }
.anio-selector select {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 13px;
}

main {
  padding: 20px 24px;
  max-width: 100%;
  overflow-x: auto;
}

.loader { color: var(--muted); padding: 40px; text-align: center; }

h1 { font-size: 20px; margin: 0 0 16px 0; font-weight: 600; }
h2 { font-size: 15px; margin: 24px 0 8px 0; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }

table {
  border-collapse: collapse;
  width: 100%;
  font-variant-numeric: tabular-nums;
}

table th, table td {
  padding: 6px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table th:first-child, table td:first-child { text-align: left; }
table th {
  background: var(--surface);
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  position: sticky;
  top: 53px;
}

table tbody tr:hover { background: var(--surface-2); }

.megacuenta-name { font-weight: 500; cursor: pointer; }
.megacuenta-name:hover { color: var(--accent); text-decoration: underline; }

.tag {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 10px;
  margin-left: 6px;
  background: var(--surface-2);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.tag.no-presup { background: #fef3c7; color: var(--amber); }

.num { font-variant-numeric: tabular-nums; }
.num-zero { color: var(--muted); }
.num-positive { color: var(--green); }
.num-negative { color: var(--red); }

.diff-positive { color: var(--green); }
.diff-negative { color: var(--red); }
.meta-incumplida { color: var(--amber); }

.pct-bar {
  display: inline-block;
  width: 60px;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: middle;
  position: relative;
  overflow: hidden;
}
.pct-bar::after {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0;
  background: var(--accent);
  width: var(--pct, 0%);
}
.pct-bar.over::after { background: var(--red); width: 100%; }

tr.total-row {
  font-weight: 600;
  background: var(--surface);
  border-top: 2px solid var(--border);
}
tr.total-row td { border-top: 2px solid var(--accent); padding-top: 10px; }

.section { margin-bottom: 32px; }
.section .summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.metric {
  background: var(--surface);
  padding: 14px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.metric .label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.metric .value {
  font-size: 22px;
  font-weight: 600;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
.metric .value.positive { color: var(--green); }
.metric .value.negative { color: var(--red); }

.detail-panel {
  margin-top: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.detail-panel h3 { margin: 0 0 8px 0; font-size: 14px; }

/* === Dropdown del menu === */
header nav .dropdown {
  display: inline-block;
  position: relative;
}
header nav .dropdown-toggle {
  cursor: pointer;
}
header nav .dropdown-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  min-width: 180px;
  padding: 4px;
  z-index: 20;
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}
header nav .dropdown:hover .dropdown-menu,
header nav .dropdown:focus-within .dropdown-menu {
  display: block;
}
header nav .dropdown-menu a {
  display: block;
  margin: 0;
  padding: 6px 12px;
  border-radius: 3px;
}

small.muted {
  color: var(--muted);
  font-weight: normal;
  font-size: 12px;
  margin-left: 8px;
}

/* === Ejecucion: 3 sub-filas por megacuenta === */
.ejecucion-table tr.mega-header td {
  border-top: 2px solid var(--border);
  background: var(--surface);
  padding-top: 10px;
  padding-bottom: 4px;
  font-weight: 600;
  font-size: 13px;
}
.ejecucion-table tr.row-presup td {
  background: rgba(37, 99, 235, 0.05);
  color: var(--muted);
}
.ejecucion-table tr.row-gasto td {
  background: var(--surface);
}
.ejecucion-table tr.row-delta td {
  background: rgba(0, 0, 0, 0.04);
  font-size: 11px;
}
.ejecucion-table tr.row-presup td,
.ejecucion-table tr.row-gasto td,
.ejecucion-table tr.row-delta td {
  padding-top: 3px;
  padding-bottom: 3px;
  border-bottom: 1px solid var(--border);
}
.ejecucion-table .row-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left !important;
}
.ejecucion-table .row-total {
  font-weight: 600;
  border-left: 1px solid var(--border);
}
.delta-cell {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
}
.delta-cell small {
  font-size: 9px;
  opacity: 0.7;
}

/* === Celdas clickables -> drilldown === */
.gasto-cell.clickable,
.ingreso-cell.clickable {
  cursor: pointer;
  position: relative;
  transition: background 0.1s;
}
.gasto-cell.clickable:hover,
.ingreso-cell.clickable:hover {
  background: var(--accent) !important;
  color: #fff;
}
.gasto-cell.clickable:hover .num,
.gasto-cell.clickable:hover .num-zero,
.ingreso-cell.clickable:hover .num,
.ingreso-cell.clickable:hover .num-zero {
  color: #fff !important;
}

/* === Breadcrumb (sub-vistas) === */
.breadcrumb {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep {
  margin: 0 8px;
  color: var(--border);
}
.breadcrumb .current {
  color: var(--text);
}

/* === Navegacion mes anterior / siguiente === */
.mes-nav-wrapper {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 16px 0 8px 0;
  font-size: 13px;
}
.mes-nav {
  color: var(--accent);
  text-decoration: none;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}
.mes-nav:hover { background: var(--surface-2); }
.mes-nav.disabled {
  color: var(--muted);
  border-color: transparent;
  cursor: default;
  background: transparent;
}
.mes-current {
  font-weight: 600;
  color: var(--text);
}

/* === Celdas YoY (Top + Cliente) === */
.yoy-cell {
  font-size: 12px;
  text-align: right;
  white-space: nowrap;
  font-weight: 500;
}
.yoy-cell.yoy-nuevo {
  color: var(--accent);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.yoy-cell.yoy-perdido {
  color: var(--muted);
  font-style: italic;
}

/* === Top clientes: tabla ranking, barras, badges, hitos pareto === */

/* Estilo base del badge porcentual (lo comparten 25, 50, 75, 80) */
.top-table tr[class*="pareto-"] td {
  position: relative;
}
.top-table tr[class*="pareto-"] td:first-child::after {
  position: absolute;
  right: -28px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 9px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
  letter-spacing: 0.04em;
}

/* 25%: verde tenue (logro temprano de cuartil) */
.top-table tr.pareto-25 td {
  border-bottom: 2px dashed var(--green);
}
.top-table tr.pareto-25 td:first-child::after {
  content: ' 25%';
  background: var(--green);
  color: #0a0a0a;
}

/* 50%: azul accent (medio camino, hito clasico) */
.top-table tr.pareto-50 td {
  border-bottom: 2px dashed var(--accent);
}
.top-table tr.pareto-50 td:first-child::after {
  content: ' 50%';
  background: var(--accent);
  color: #fff;
}

/* 75%: naranjo tenue (3/4 del ingreso) */
.top-table tr.pareto-75 td {
  border-bottom: 2px dashed var(--amber);
}
.top-table tr.pareto-75 td:first-child::after {
  content: ' 75%';
  background: var(--amber);
  color: #fff;
}

/* 80%: rojo (regla de pareto: 20% de clientes hacen 80% del ingreso) */
.top-table tr.pareto-80 td {
  border-bottom: 2px dashed var(--red);
}
.top-table tr.pareto-80 td:first-child::after {
  content: ' 80%';
  background: var(--red);
  color: #fff;
}

.pct-bar-wrapper {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  width: 100%;
  position: relative;
}
.pct-bar-fill {
  height: 6px;
  background: var(--accent);
  border-radius: 2px;
  min-width: 1px;
  max-width: 80px;
  flex-shrink: 0;
}
.pct-bar-label {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  min-width: 48px;
  text-align: right;
}

.cat-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.cat-marketplace {
  background: rgba(37, 99, 235, 0.10);
  color: var(--accent);
}
.cat-enterprise {
  background: rgba(217, 119, 6, 0.12);
  color: var(--amber);
}

/* === Headers colapsables === */
h2.collapsible {
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 8px;
}
h2.collapsible:hover {
  color: var(--accent);
}
h2.collapsible .caret {
  display: inline-block;
  font-size: 13px;
  color: var(--muted);
  transition: transform 0.15s;
  width: 12px;
}
h2.collapsible:hover .caret {
  color: var(--accent);
}

/* === Vision: bloque MARGEN OPERACIONAL (3 sub-filas: Meta / Real / Cumpl) === */
.vision-table tr.row-block-meta td {
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 13px;
  padding: 10px 12px;
  border-top: 2px solid var(--accent);
  border-bottom: 1px solid var(--border);
  text-align: left;
}
.vision-table tr.row-meta-presup td {
  background: rgba(37, 99, 235, 0.05);
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-top: 4px;
  padding-bottom: 4px;
}
.vision-table tr.row-meta-real td {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  font-weight: 600;
  padding-top: 6px;
  padding-bottom: 6px;
}
.vision-table tr.row-meta-cumpl td {
  background: rgba(0,0,0,0.03);
  font-size: 13px;
  padding-top: 4px;
  padding-bottom: 4px;
  border-bottom: 1px dashed var(--border);
}
.vision-table tr.row-meta-real-acum td {
  background: rgba(0,0,0,0.02);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: normal;
  color: var(--muted);
  padding-top: 4px;
  padding-bottom: 4px;
}
.vision-table tr.row-meta-real-acum .num-muted {
  color: var(--muted);
}
.vision-table tr.row-meta-cumpl-acum td {
  background: rgba(0,0,0,0.03);
  font-size: 13px;
  padding-top: 4px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--accent);
}
.vision-table tr.row-meta-real-acum .row-label,
.vision-table tr.row-meta-cumpl-acum .row-label {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  padding-left: 24px;
  font-style: italic;
}
.vision-table tr.row-meta-presup .row-label,
.vision-table tr.row-meta-real .row-label,
.vision-table tr.row-meta-cumpl .row-label {
  color: var(--muted);
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  padding-left: 24px;
}

/* === Cliente: timeline + sparkline + link a razon social === */
.cliente-link {
  color: inherit;
  text-decoration: none;
}
.cliente-link:hover {
  text-decoration: underline;
}
.cliente-link .link-icon {
  color: var(--muted);
  font-size: 10px;
  margin-left: 4px;
  opacity: 0.6;
  transition: opacity 0.1s, color 0.1s;
}
.cliente-link:hover .link-icon {
  color: var(--accent);
  opacity: 1;
}

.cliente-timeline {
  margin-top: 8px;
}
.cliente-timeline .mes-link {
  color: var(--accent);
  text-decoration: none;
}
.cliente-timeline .mes-link:hover { text-decoration: underline; }
.cliente-timeline .spark-cell {
  height: 28px;
  vertical-align: bottom;
  padding: 2px;
}
.cliente-timeline .spark {
  background: var(--accent);
  width: 70%;
  margin: 0 auto;
  border-radius: 2px;
}
.cliente-timeline .spark.spark-neg {
  background: var(--red);
}

/* === Tabla de movimientos del drilldown === */
.movs-table {
  font-size: 12px;
}
.movs-table th, .movs-table td {
  padding: 4px 8px;
}
.movs-table .glosa-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}
.movs-table tbody tr:hover {
  background: var(--surface);
}

/* === Vision Global: toggles unidad / modo === */
.vision-toggles {
  display: flex;
  gap: 16px;
  margin: 8px 0 16px 0;
  flex-wrap: wrap;
}
.toggle-group {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface);
}
.toggle-group button, .toggle-group a {
  padding: 6px 14px;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  border-right: 1px solid var(--border);
}
.toggle-group button:last-child, .toggle-group a:last-child { border-right: none; }
.toggle-group button:hover, .toggle-group a:hover { color: var(--text); background: var(--surface-2); }
.toggle-group button.active, .toggle-group a.active {
  background: var(--accent);
  color: #fff;
}

/* === Vision global: bloques === */
.vision-table tr.block-header td {
  background: var(--surface-2);
  color: var(--accent);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 13px;
  padding: 10px 12px;
  border-top: 2px solid var(--accent);
  text-align: left;
}
.vision-table tr.block-header td small {
  color: var(--muted);
  font-weight: normal;
  text-transform: none;
  letter-spacing: 0;
  margin-left: 8px;
}
.vision-table tr.row-detail td:first-child {
  padding-left: 24px;
  color: var(--text);
}
.vision-table tr.row-detail td {
  background: rgba(0,0,0,0.1);
}
.vision-table tr.row-subtotal td {
  background: var(--surface);
  font-weight: 600;
  border-top: 1px solid var(--border);
}
.vision-table tr.row-result td {
  background: var(--surface-2);
  font-weight: 600;
  border-top: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  font-size: 15px;
  padding-top: 8px;
  padding-bottom: 8px;
}
.vision-table .row-total {
  font-weight: 600;
  border-left: 1px solid var(--border);
}
/* Fila YoY bajo subtotal: indica comparativo vs anio anterior */
.vision-table tr.row-yoy td {
  font-size: 13px;
  background: rgba(0,0,0,0.04);
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.vision-table tr.row-yoy td.row-label {
  padding-left: 24px;
  font-style: italic;
}
/* Variante: YoY bajo fila de detalle (marketplace/enterprise/megacuenta).
   Mas indentada y mas sutil que la YoY bajo subtotal. */
.vision-table tr.row-yoy.row-yoy-detalle td {
  font-size: 12px;
  background: rgba(0,0,0,0.02);
  border-bottom: none;
}
.vision-table tr.row-yoy.row-yoy-detalle td.row-label {
  padding-left: 40px;
}
.vision-table tr.row-yoy .yoy-nuevo,
.vision-table tr.row-yoy .yoy-perdido {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-style: normal;
}
.vision-table tr.row-yoy .yoy-nuevo { color: var(--accent); font-weight: 600; }
.vision-table tr.row-yoy .yoy-perdido { color: var(--muted); }

footer {
  padding: 16px 24px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  font-size: 11px;
}

/* === Visión global: +2px sobre el resto de la app ===
   Pedido de Joaco (2026-09-05): los números del P&L costaban de leer. El resto
   de las vistas queda en su tamaño original, por eso va todo scopeado a
   .vision-table / .vision-summary y no al body. */
.vision-table {
  font-size: 15px;   /* las filas de detalle no tenian tamaño propio: heredaban los 13px del body */
}
.vision-table th {
  font-size: 13px;   /* el global de `table th` es 11px */
}
.vision-summary .label { font-size: 13px; }
.vision-summary .value { font-size: 24px; }

/* ---- agregados de la version Rails ---- */
.anio-selector a { margin-left: 6px; padding: 2px 6px; border-radius: 4px; color: var(--muted); text-decoration: none; }
.anio-selector a.active { background: var(--accent); color: #fff; }
.usuario { color: var(--muted); font-size: 12px; margin-left: 16px; }
.link-button { display: inline; }
.link-button button { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0 0 0 8px; }
.flash { padding: 8px 24px; font-size: 13px; }
.flash-notice { background: #ecfdf5; color: #065f46; }
.flash-alert { background: #fef2f2; color: #991b1b; }
.login { max-width: 360px; margin: 80px auto; background: var(--surface); padding: 24px; border: 1px solid var(--border); border-radius: 8px; }
.login .campo { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.login .campo-inline { flex-direction: row; align-items: center; }
.login input[type=email], .login input[type=password] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 4px; }
.login input[type=submit] { padding: 6px 14px; background: var(--accent); color: #fff; border: none; border-radius: 4px; cursor: pointer; }
td a, .clickable a { color: inherit; text-decoration: none; display: block; }
.clickable a:hover { text-decoration: underline; }
details.administrativo > summary { cursor: pointer; font-size: 15px; font-weight: 600; margin: 24px 0 8px; list-style: none; }
details.administrativo > summary::before { content: "▶ "; }
details.administrativo[open] > summary::before { content: "▼ "; }
.vision-toggles a { text-decoration: none; }
/* El toggle de Gestion es un button (no un link con href="#"): se viste igual
   que los links del nav. */
header nav .dropdown-toggle {
  background: none;
  border: none;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  display: inline-block;
  padding: 6px 14px;
  margin-right: 8px;
  color: var(--muted);
  border-radius: 4px;
}
header nav .dropdown-toggle:hover { color: var(--text); background: var(--surface-2); }
header nav .dropdown-toggle.active { color: var(--accent); background: var(--surface-2); }

/* Fila unica de una tabla sin datos (movimientos de un mes vacio). */
.vacio { color: var(--muted); text-align: center; padding: 24px; }

/* Nota bajo el resumen y sobre la tabla (orden, filtros aplicados). */
.nota-tabla { font-size: 11px; margin: 4px 0 12px 0; }

/* Link "Ver <otra categoría>" al extremo derecho de la navegación de meses. */
.mes-nav-otra { margin-left: auto; }

/* Celda de texto largo (tipos de documento, megacuentas) con puntos suspensivos. */
.celda-truncada { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Detalle bajo la cifra de una tarjeta del resumen (meses activos, posición). */
.metric .value .sub { font-size: 11px; display: block; }

/* Fila de subtotal en las tablas de movimientos (egresos asociados del cliente). */
.movs-table tr.row-subtotal td { font-weight: 600; border-top: 2px solid var(--border); }

/* === Sincronizaciones (historial y boton) === */
.estado { padding: 2px 8px; border-radius: 10px; font-size: 11px; }
.estado-ok { background: #ecfdf5; color: #065f46; }
.estado-error { background: #fef2f2; color: #991b1b; }
.estado-corriendo, .estado-pendiente { background: #fffbeb; color: #92400e; }
.sync-accion form { display: flex; gap: 12px; align-items: center; }
.boton { padding: 6px 14px; background: var(--accent); color: #fff; border: none; border-radius: 4px; cursor: pointer; }
.boton:disabled { opacity: .5; cursor: default; }
.metric .value.small { font-size: 12px; }
