/* ==========================================================================
   Tesorería — sistema de diseño
   Neutro y limpio: superficies con borde fino, un único acento (--brand, de BRAND_COLOR)
   y verde/rojo reservados para el signo de los importes.
   ========================================================================== */

:root {
  color-scheme: light;
  --page: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --surface-sunken: #f1f0ec;
  --border: rgba(11, 11, 11, 0.09);
  --border-strong: rgba(11, 11, 11, 0.16);
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7d7b75;
  --grid: #e8e7e1;
  --pos: #0b7a35;
  --neg: #c22d2d;
  --warn: #9a6400;
  --info: #2a62b8;
  --pos-bg: #e8f5ec;
  --neg-bg: #fbeaea;
  --warn-bg: #fdf3dc;
  --info-bg: #e9f0fb;
  --forecast-bg: #f4f3ef;
  --hover: rgba(11, 11, 11, 0.04);
  --focus: color-mix(in srgb, var(--brand) 55%, transparent);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px -12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 24px 64px -16px rgba(0, 0, 0, 0.25);
  --radius: 14px;
  --radius-sm: 9px;
  --sidebar-w: 236px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0c;
    --surface: #171716;
    --surface-2: #1c1c1b;
    --surface-sunken: #121211;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.16);
    --text: #f0efec;
    --text-2: #c3c2b7;
    --muted: #8e8c85;
    --grid: #2a2a28;
    --pos: #3fbf6a;
    --neg: #f07171;
    --warn: #e0a83a;
    --info: #6ea2ef;
    --pos-bg: rgba(63, 191, 106, 0.12);
    --neg-bg: rgba(240, 113, 113, 0.12);
    --warn-bg: rgba(224, 168, 58, 0.12);
    --info-bg: rgba(110, 162, 239, 0.12);
    --forecast-bg: #1f1f1d;
    --hover: rgba(255, 255, 255, 0.05);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0c;
  --surface: #171716;
  --surface-2: #1c1c1b;
  --surface-sunken: #121211;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f0efec;
  --text-2: #c3c2b7;
  --muted: #8e8c85;
  --grid: #2a2a28;
  --pos: #3fbf6a;
  --neg: #f07171;
  --warn: #e0a83a;
  --info: #6ea2ef;
  --pos-bg: rgba(63, 191, 106, 0.12);
  --neg-bg: rgba(240, 113, 113, 0.12);
  --warn-bg: rgba(224, 168, 58, 0.12);
  --info-bg: rgba(110, 162, 239, 0.12);
  --forecast-bg: #1f1f1d;
  --hover: rgba(255, 255, 255, 0.05);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
.icon { flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.sr-only, .skip:not(:focus) { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.skip:focus { position: fixed; top: 8px; left: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Carcasa ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column; gap: 6px; padding: 16px 12px;
  background: var(--surface); border-right: 1px solid var(--border);
  transition: width 0.18s ease, transform 0.2s ease;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 14px; min-height: 52px; }
.brand-logo, .brand-initials {
  width: 34px; height: 34px; border-radius: 9px; flex: none; object-fit: contain; background: var(--surface-2);
  border: 1px solid var(--border);
}
.brand-initials { display: grid; place-items: center; font-weight: 700; font-size: 13px; background: var(--text); color: var(--surface); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text span { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 8px 10px; border-radius: var(--radius-sm); border: 0; background: none; cursor: pointer;
  color: var(--text-2); font-weight: 500; text-align: left; white-space: nowrap;
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: var(--surface-sunken); color: var(--text); }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand);
}
.nav-item.active .icon { color: var(--brand); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--border); padding-top: 10px; }

.nav-collapsed { --sidebar-w: 68px; }
.nav-collapsed .brand-text, .nav-collapsed .nav-item span { display: none; }
.nav-collapsed .nav-item { justify-content: center; }
.nav-collapsed .brand { justify-content: center; padding-left: 0; padding-right: 0; }

.main { margin-left: var(--sidebar-w); min-height: 100vh; transition: margin 0.18s ease; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 16px;
  padding: 14px 28px; min-height: 68px;
  background: color-mix(in srgb, var(--page) 82%, transparent); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.page-head { min-width: 0; flex: 1; }
.page-head h1 { font-size: 19px; }
.page-head p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; align-items: center; gap: 6px; }
.top-actions form { margin: 0; }
.company-switch select { max-width: 240px; }
.content { padding: 24px 28px 64px; max-width: 1480px; }
.scrim { display: none; }

/* ---------- Botones y controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface);
  font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--text); color: var(--surface); border-color: var(--text); }
.btn.primary:hover { opacity: 0.88; }
.btn.block { width: 100%; height: 42px; }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.icon-btn, .ghost-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; min-width: 34px; padding: 0 8px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: none; cursor: pointer; color: var(--text-2); white-space: nowrap;
}
.ghost-btn { border-color: var(--border); background: var(--surface); padding: 0 11px; font-weight: 500; font-size: 13px; }
.icon-btn:hover, .ghost-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.danger:hover { color: var(--neg); background: var(--neg-bg); }
.only-mobile { display: none; }
.when-dark { display: none; }
:root[data-theme="dark"] .when-dark { display: inline-flex; }
:root[data-theme="dark"] .when-light { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .when-dark { display: inline-flex; }
  :root:not([data-theme="light"]) .when-light { display: none; }
}

select, input[type="text"], input[type="number"], input[type="date"], input[type="email"],
input[type="password"], input[type="search"] {
  font: inherit; height: 36px; padding: 0 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); min-width: 0;
}
select { padding-right: 28px; }
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }

.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 11px; background: var(--surface-sunken); border: 1px solid var(--border); }
.segmented a { padding: 5px 12px; border-radius: 8px; font-size: 13px; font-weight: 500; color: var(--text-2); white-space: nowrap; }
.segmented a:hover { color: var(--text); }
.segmented a.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 18px; }
.filters .push { margin-left: auto; }
.filter-hint { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; cursor: help; }
.stepper { display: inline-flex; align-items: center; gap: 4px; padding: 3px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); }
.stepper strong { min-width: 52px; text-align: center; font-size: 15px; }

/* ---------- Layout ---------- */
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid.tight { gap: 8px; margin-bottom: 0; }
.cols-12 { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; } .span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; }
.grid > [class*="span-"] > .card, .grid > [class*="span-"] > .skeleton { height: 100%; margin-bottom: 0; }
.section-title { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin: 28px 0 12px; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head.padded { padding: 18px 20px 12px; margin: 0; }
.card-head p { margin-top: 3px; }
.card-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.padded { padding: 18px 20px; }
.link { color: var(--info); font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.link:hover { text-decoration: underline; }
.hint-line { display: flex; align-items: center; gap: 6px; margin: 4px 2px 16px; }

/* Héroe del Resumen */
.hero-top { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 18px 32px; margin-bottom: 8px; }
.eyebrow { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.hero-value { font-size: 40px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; margin: 4px 0 6px; }
.hero-stats { display: flex; flex-wrap: wrap; gap: 8px 28px; margin: 0; }
.hero-stats div { display: flex; flex-direction: column; min-width: 120px; }
.hero-stats dt { font-size: 12.5px; color: var(--muted); }
.hero-stats dd { margin: 2px 0 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }

.delta { display: inline-flex; align-items: center; gap: 3px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.delta.pos { color: var(--pos); } .delta.neg { color: var(--neg); }
.delta .muted { font-weight: 400; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi {
  position: relative; display: flex; flex-direction: column; gap: 4px; padding: 16px 18px; min-width: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  text-align: left; font: inherit; color: inherit;
}
.kpi.is-link { cursor: pointer; transition: border-color 0.15s, transform 0.15s; }
.kpi.is-link:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 500; padding-right: 18px; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
.kpi-value.pos { color: var(--pos); } .kpi-value.neg { color: var(--neg); }
.kpi-sub { font-size: 12.5px; color: var(--text-2); }
.kpi-go { position: absolute; top: 14px; right: 12px; color: var(--muted); opacity: 0; transition: opacity 0.15s; }
.kpi.is-link:hover .kpi-go { opacity: 1; }
.spark { display: block; height: 34px; margin-top: 6px; }

/* Alertas */
.alerts { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.alert a { display: flex; gap: 12px; align-items: flex-start; padding: 12px; border-radius: 11px; background: var(--surface-2); border: 1px solid var(--border); }
.alert a:hover { border-color: var(--border-strong); }
.alert-icon { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; flex: none; }
.alert.critical .alert-icon { background: var(--neg-bg); color: var(--neg); }
.alert.serious .alert-icon { background: var(--warn-bg); color: var(--warn); }
.alert.warning .alert-icon, .alert.info .alert-icon { background: var(--info-bg); color: var(--info); }
.alert-body { display: flex; flex-direction: column; gap: 2px; flex: 1; font-size: 13px; color: var(--text-2); }
.alert-body strong { color: var(--text); font-size: 13.5px; }
.alert-amount { font-weight: 600; color: var(--text); }
.alert-go { color: var(--muted); margin-top: 6px; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 6px; padding: 28px 16px; color: var(--muted); }
.empty strong { color: var(--text); }
.empty p { max-width: 380px; font-size: 13px; }

.notice { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 13px; }
.notice.warning { background: var(--warn-bg); color: var(--warn); }
.notice.critical { background: var(--neg-bg); color: var(--neg); }
.notice.info { background: var(--surface-sunken); color: var(--text-2); }

.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; background: var(--surface-sunken); color: var(--text-2); white-space: nowrap; }
.badge.info { background: var(--info-bg); color: var(--info); }
.badge.critical { background: var(--neg-bg); color: var(--neg); }
.ok { display: inline-flex; align-items: center; gap: 4px; color: var(--pos); font-size: 13px; font-weight: 500; }

/* ---------- Tablas ---------- */
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table thead th { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
.table tbody tr:last-child td, .table tbody tr:last-child th { border-bottom: 0; }
.table tfoot td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--border-strong); border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table.compact th, .table.compact td { padding: 7px 10px; }
.table tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover, .table tbody tr.clickable:focus-visible { background: var(--hover); }
.table tr.is-below td { background: var(--neg-bg); }
.table tr.is-past { opacity: 0.6; }
.table td.actions { width: 1%; text-align: right; }
.table td.actions form { margin: 0; }
.table th[data-sort] { cursor: pointer; user-select: none; }
.table th[data-sort]:hover { color: var(--text); }
.table th.sorted-asc::after { content: " ↑"; } .table th.sorted-desc::after { content: " ↓"; }
.zero { color: var(--muted); opacity: 0.6; }
.table th.main-col, .table td.main-col { background: color-mix(in srgb, var(--brand) 7%, transparent); }
.table tr.row-opening td { background: var(--surface-2); }
.table tr.row-overdue td { background: var(--warn-bg); }
.table tr.row-explain td { background: var(--surface-2); font-size: 12.5px; border-bottom-color: transparent; }
.table tr.row-explain .indent { padding-left: 16px; display: inline-block; }

/* Estado de flujos */
.statement { font-size: 12.5px; }
.statement th, .statement td { padding: 6px 10px; }
.statement .sticky-col { position: sticky; left: 0; z-index: 2; background: var(--surface); min-width: 240px; max-width: 320px; font-weight: 400; }
.statement thead .sticky-col { z-index: 3; background: var(--surface-2); }
.statement thead th small { display: block; font-size: 10.5px; font-weight: 400; color: var(--muted); }
.statement th.forecast, .statement td.forecast { background: var(--forecast-bg); }
.statement td.forecast { color: var(--text-2); }
.statement .total-col { font-weight: 600; border-left: 1px solid var(--border); }
.statement .row-section th, .statement .row-section td { font-weight: 600; background: var(--surface-2); border-top: 1px solid var(--border-strong); }
.statement .row-section .sticky-col { background: var(--surface-2); }
.statement .row-section.is-internal th, .statement .row-section.is-internal td { color: var(--muted); }
.statement .row-balance th, .statement .row-balance td { color: var(--text-2); }
.statement .row-balance.strong th, .statement .row-balance.strong td { color: var(--text); font-weight: 700; border-top: 1px solid var(--border-strong); }
.statement .row-net th, .statement .row-net td { font-weight: 600; border-top: 2px solid var(--border-strong); }
.statement .row-acc th, .statement .row-acc td { color: var(--text-2); font-size: 12px; background: var(--surface); }
.statement .indent { padding-left: 34px; display: inline-block; }
.expander, .expander-pad { display: inline-flex; align-items: center; gap: 4px; padding: 0 0 0 4px; border: 0; background: none; cursor: pointer; text-align: left; }
.expander-pad { padding-left: 22px; cursor: default; }
.expander .icon { transition: transform 0.15s; color: var(--muted); }
.expander[aria-expanded="true"] .icon { transform: rotate(90deg); }
.cell { border: 0; background: none; padding: 2px 4px; margin: -2px -4px; border-radius: 5px; cursor: pointer; font: inherit; color: inherit; font-variant-numeric: tabular-nums; }
.cell:hover { background: var(--hover); text-decoration: underline; text-decoration-color: var(--border-strong); }

/* Puente del flujo */
.bridge { margin: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.bridge div { display: flex; justify-content: space-between; gap: 12px; padding: 7px 4px; border-bottom: 1px dashed var(--border); }
.bridge dt { color: var(--text-2); }
.bridge dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.bridge .bridge-total dt, .bridge .bridge-total dd { color: var(--text); font-weight: 700; }

/* Tesorería */
.account-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-bottom: 16px; }
.account-card {
  display: flex; flex-direction: column; gap: 3px; padding: 16px 18px; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: border-color 0.15s, transform 0.15s;
}
.account-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.account-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.account-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.account-balance { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; margin-top: 6px; }
.account-balance.neg { color: var(--neg); }
.account-last { margin-top: 4px; }
.usage { display: flex; flex-direction: column; gap: 4px; margin-top: 6px; }
.usage-bar { display: block; height: 6px; border-radius: 6px; background: var(--surface-sunken); overflow: hidden; }
.usage-bar.inline { display: inline-block; width: 80px; vertical-align: middle; }
.usage-bar span { display: block; height: 100%; background: var(--text-2); border-radius: 6px; }

/* Listas y formularios */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 20px; border-top: 1px solid var(--border); }
.card.form .list li { padding: 10px 0; }
.list form { margin: 0; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form .card-head { margin-bottom: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; padding-top: 6px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.field input, .field select { width: 100%; }
.field .help { font-weight: 400; color: var(--muted); font-size: 12px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row[hidden] { display: none; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--text-2); }
.check input { margin-top: 2px; accent-color: var(--text); }
.inline-form { display: flex; gap: 6px; align-items: center; margin: 0; }
.inline-form select { max-width: 230px; }
.code-input { width: 96px; font-family: ui-monospace, Consolas, monospace; }
.toolbar { display: flex; gap: 8px; align-items: center; }
.search { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface); color: var(--muted); }
.search input { border: 0; height: 30px; padding: 0; width: 180px; background: none; box-shadow: none; }
.search input:focus { box-shadow: none; }
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--focus); }

details.card summary { display: flex; align-items: baseline; gap: 10px; cursor: pointer; list-style: none; }
details.card summary::-webkit-details-marker { display: none; }
details.card summary::before { content: "›"; color: var(--muted); transition: transform 0.15s; display: inline-block; }
details.card[open] summary::before { transform: rotate(90deg); }
details.card[open] summary { margin-bottom: 12px; }

/* Usuarios y permisos */
.user-list { list-style: none; margin: 0; padding: 0; }
.user-row { border-top: 1px solid var(--border); }
.user-row > .user-main, .user-row > .user-tags { padding: 12px 20px; }
.user-row:first-child { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.user-edit summary { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 20px; cursor: pointer; list-style: none; }
.user-edit summary::-webkit-details-marker { display: none; }
.user-edit summary:hover { background: var(--hover); }
.user-edit[open] summary { background: var(--surface-2); border-bottom: 1px solid var(--border); }
.user-edit[open] .user-chevron { transform: rotate(180deg); }
.user-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.user-main div { display: flex; flex-direction: column; }
.user-tags { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.avatar { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: var(--surface-sunken); color: var(--text-2); font-size: 12px; font-weight: 700; }
.perm { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 14px 12px; margin: 0; }
.perm legend { font-size: 12.5px; font-weight: 500; color: var(--text-2); padding: 0 4px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 16px; }
.row-actions { display: flex; gap: 8px; }
.delete-user { padding-top: 0; }
.danger-btn { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, var(--border)); }
.danger-btn:hover { background: var(--neg-bg); }
.icon-btn.is-active { color: var(--text); background: var(--surface-sunken); }

/* Knowledge */
.kb-search { margin-bottom: 18px; max-width: 520px; }
.kb-search .search { width: 100%; }
.kb-search .search input { width: 100%; }
.kb-section { margin-bottom: 26px; }
.kb-item { margin-bottom: 8px; padding: 0; }
.kb-item summary { padding: 14px 18px; font-weight: 600; font-size: 14px; color: var(--text); align-items: center; }
.kb-item[open] summary { border-bottom: 1px solid var(--border); margin-bottom: 0; }
.kb-body { padding: 14px 20px 18px 36px; color: var(--text-2); font-size: 13.5px; line-height: 1.6; }
.kb-body p { margin: 0 0 10px; }
.kb-body ul, .kb-body ol { margin: 0 0 10px; padding-left: 20px; }
.kb-body li { margin-bottom: 4px; }
.kb-body strong { color: var(--text); }
.kb-body code { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; background: var(--surface-sunken);
  padding: 1px 5px; border-radius: 4px; }
.kb-body .table { margin: 6px 0 12px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
kbd { font: 600 11.5px ui-monospace, Consolas, monospace; padding: 1px 6px; border-radius: 5px; border: 1px solid var(--border-strong); background: var(--surface-2); }
.kb-formula { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px;
  margin: 0 0 10px; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; color: var(--text); }

/* ---------- Gráficos ---------- */
.chart { width: 100%; }
.chart-wrap { position: relative; }
.chart-bar { position: absolute; top: -6px; right: -6px; z-index: 2; display: flex; align-items: center; gap: 12px; }
.chart-bar-text { display: none; }
.chart-full-btn { opacity: 0; background: var(--surface); transition: opacity 0.15s; }
.chart-wrap:hover .chart-full-btn, .chart-full-btn:focus-visible { opacity: 1; }
@media (hover: none) { .chart-full-btn { opacity: 1; } }
.chart-full-btn .when-full { display: none; }
/* Pantalla completa: por encima de la carcasa (40) y por debajo del panel de desglose (60) */
.chart-wrap.is-full {
  position: fixed; inset: 0; z-index: 55; display: flex; flex-direction: column; gap: 12px;
  padding: 20px 24px 24px; background: var(--surface);
}
.chart-wrap.is-full .chart-bar { position: static; justify-content: space-between; }
.chart-wrap.is-full .chart-bar-text { display: flex; flex-direction: column; gap: 2px; font-size: 16px; }
.chart-wrap.is-full .chart-full-btn { opacity: 1; border-color: var(--border); }
.chart-wrap.is-full .chart-full-btn .when-full { display: block; }
.chart-wrap.is-full .chart-full-btn .when-normal { display: none; }
.chart-wrap.is-full .chart { flex: 1; min-height: 0; height: auto !important; }
body.chart-open { overflow: hidden; }
.table-twin { margin-top: 12px; max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }

/* ---------- Esqueletos y errores ---------- */
.skeleton { height: var(--h); border-radius: var(--radius); margin-bottom: 16px; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 40%, var(--surface) 80%); background-size: 200% 100%; border: 1px solid var(--border); animation: shimmer 1.3s ease-in-out infinite; }
.skeleton-kpis { background: none; border: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.skeleton-kpis::before, .skeleton-kpis::after { content: ""; border-radius: var(--radius); border: 1px solid var(--border); background: inherit; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 40%, var(--surface) 80%); background-size: 200% 100%; animation: shimmer 1.3s ease-in-out infinite; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton, .skeleton-kpis::before, .skeleton-kpis::after { animation: none; } }
.htmx-request.lazy, .htmx-swapping { opacity: 0.6; }
.error-card { border-color: color-mix(in srgb, var(--neg) 35%, var(--border)); }
.error-head { display: flex; gap: 12px; color: var(--neg); }
.error-head strong { color: var(--text); }
.error-card pre { font-size: 11px; white-space: pre-wrap; color: var(--text-2); max-height: 260px; overflow: auto; }

/* ---------- Panel lateral ---------- */
.drawer { position: fixed; inset: 0; z-index: 60; pointer-events: none; }
.drawer-scrim { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.32); opacity: 0; transition: opacity 0.2s; }
.drawer-panel {
  position: absolute; top: 0; right: 0; bottom: 0; width: min(860px, 100vw); display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.drawer.open { pointer-events: auto; }
.drawer.open .drawer-scrim { opacity: 1; }
.drawer.open .drawer-panel { transform: none; }
#drawer-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.drawer-head { display: flex; justify-content: space-between; gap: 12px; padding: 20px 24px 12px; }
.drawer-head h2 { font-size: 18px; }
.drawer-head p { font-size: 13px; margin-top: 2px; }
.drawer-summary { display: flex; flex-wrap: wrap; gap: 8px 28px; padding: 4px 24px 16px; border-bottom: 1px solid var(--border); }
.drawer-summary div { display: flex; flex-direction: column; }
.drawer-summary span { font-size: 12px; color: var(--muted); }
.drawer-summary strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.drawer-toolbar { display: flex; justify-content: space-between; gap: 8px; padding: 12px 24px; }
.drawer-table { flex: 1; overflow: auto; padding: 0 12px 24px; }
.drawer-loading { padding: 24px; }

/* ---------- Avisos ---------- */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; }
.toast { display: flex; align-items: center; gap: 8px; padding: 11px 14px; border-radius: 11px; background: var(--text); color: var(--surface); font-size: 13px; box-shadow: var(--shadow-lg); animation: toast-in 0.25s ease; }
.toast.error { background: var(--neg); color: #fff; }
.toast.hide { opacity: 0; transform: translateY(8px); transition: all 0.3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Login ---------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 32px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); }
.login-mark { color: var(--text); }
.login-card h1 { font-size: 22px; }
.login-card .field input { height: 40px; }
.powered { text-align: center; font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .span-4, .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
}
@media (max-width: 820px) {
  .sidebar { transform: translateX(-100%); width: 248px; }
  .nav-collapsed .brand-text, .nav-collapsed .nav-item span { display: initial; }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(0, 0, 0, 0.35); }
  .main { margin-left: 0; }
  .only-mobile { display: inline-flex; }
  .topbar { padding: 10px 16px; gap: 8px; }
  .page-head p, .freshness span, .company-switch { display: none; }
  .content { padding: 16px 16px 48px; }
  .hero-value { font-size: 32px; }
  .field-row { grid-template-columns: 1fr; }
  .inline-form { flex-wrap: wrap; }
  .search input { width: 120px; }
  .statement .sticky-col { min-width: 170px; }
}
