/* ERP — sistema visual */
:root {
  --canvas: #F5F4EF; --surface: #FFFFFF; --surface-2: #FAF9F6; --surface-3: #F0EFE9;
  --line: #E7E4DC; --line-strong: #D8D4C9;
  --ink: #15241D; --ink-2: #4A5A52; --ink-3: #7D8A83; --ink-4: #A6AFA9;
  --brand: #0B4A34; --brand-2: #0E5A3F; --brand-ink: #FFFFFF; --brand-soft: #E5EFE8; --brand-softer: #F0F5F1;
  --gold: #A9864C; --gold-soft: #F3ECDF;
  --accent: #0E5A3F; --nav-active: #0B4A34; --nav-active-ink: #F6F3EC; --nav-active-icon: #E6CF9F;
  --ok: #1F7A4D; --ok-soft: #E3F1E8; --warn: #9A6A12; --warn-soft: #FBF0D9;
  --bad: #B0452F; --bad-soft: #F8E6E1; --info: #2F5E86; --info-soft: #E5EEF6;
  --chart: #0E5A3F; --chart-soft: #CFE2D6; --chart-grid: #EDEBE4;
  --shadow-sm: 0 1px 2px rgba(21,36,29,.05);
  --shadow: 0 1px 2px rgba(21,36,29,.04), 0 8px 24px -8px rgba(21,36,29,.10);
  --shadow-lg: 0 24px 64px -16px rgba(21,36,29,.28), 0 2px 8px rgba(21,36,29,.06);
  --radius: 16px; --radius-sm: 10px; --radius-xs: 8px;
  /* Las familias tipográficas se definen en type.css */
  --sidebar: 248px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --dark: 1; } }
:root[data-theme="dark"] {
  /* Carbón cálido con acentos salvia y champán: sobrio, sin verdes brillantes */
  --canvas: #111312; --surface: #171A19; --surface-2: #1C201E; --surface-3: #232826;
  --line: #2A2F2C; --line-strong: #383E3B;
  --ink: #EEEBE4; --ink-2: #BDB8AE; --ink-3: #8F8B83; --ink-4: #66635D;
  --brand: #2F5A49; --brand-2: #386854; --brand-ink: #F4EFE4; --brand-soft: #1F2C26; --brand-softer: #1B2420;
  --accent: #B7CDBF; --nav-active: #232A26; --nav-active-ink: #F4EFE4; --nav-active-icon: #CDAE78;
  --gold: #CDAE78; --gold-soft: #2A251C;
  --ok: #9CC3AC; --ok-soft: #1E2A24; --warn: #D7B472; --warn-soft: #2B2519; --bad: #D9907C; --bad-soft: #2E211D; --info: #A9BED3; --info-soft: #1D242B;
  --chart: #9BB9A8; --chart-soft: #34423B; --chart-grid: #252A28;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.25);
  --shadow: 0 1px 2px rgba(0,0,0,.25), 0 10px 30px -12px rgba(0,0,0,.55);
  --shadow-lg: 0 24px 64px -16px rgba(0,0,0,.75);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--canvas); color: var(--ink); font: 400 14px/1.55 var(--font); letter-spacing: -.011em; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; font-feature-settings: "ss01", "cv11"; text-rendering: optimizeLegibility; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
::selection { background: var(--brand-soft); }
.num, td.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); } .muted-2 { color: var(--ink-2); }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 2px; border-radius: 6px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 22px 14px 16px; background: color-mix(in srgb, var(--surface) 72%, transparent); border-right: 1px solid var(--line); backdrop-filter: saturate(1.4) blur(18px); }
.brand { padding: 4px 10px 18px; }
.brand img { width: 100%; max-width: 196px; display: block; }
:root[data-theme="dark"] .brand img { filter: brightness(0) invert(.9) sepia(.15); }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; margin: 0 -4px; padding: 0 4px; }
.nav-label { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-4); padding: 16px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 11px; height: 38px; padding: 0 12px; border-radius: 10px; color: var(--ink-2); font-weight: 500; transition: background .15s, color .15s; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav a:hover { background: var(--surface-3); color: var(--ink); }
.nav a.active { background: var(--nav-active); color: var(--nav-active-ink); box-shadow: inset 0 0 0 1px rgba(255,255,255,.04); }
.nav a.active svg { color: var(--nav-active-icon); }
.nav a.active svg { opacity: 1; }
.nav a .count { margin-left: auto; font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 99px; background: var(--gold-soft); color: var(--gold); }
.nav a.active .count { background: rgba(255,255,255,.18); color: inherit; }
.side-foot { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--gold-soft); color: var(--gold); font-weight: 700; font-size: 13px; flex: none; }
.side-foot .who { min-width: 0; flex: 1; line-height: 1.25; }
.side-foot .who b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot .who span { font-size: 12px; color: var(--ink-3); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 14px 36px; background: color-mix(in srgb, var(--canvas) 80%, transparent); backdrop-filter: saturate(1.4) blur(16px); border-bottom: 1px solid transparent; transition: border-color .2s; }
.topbar.scrolled { border-bottom-color: var(--line); }
.search-trigger { display: flex; align-items: center; gap: 10px; height: 38px; width: min(420px, 100%); padding: 0 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-3); cursor: pointer; box-shadow: var(--shadow-sm); }
.search-trigger:hover { border-color: var(--line-strong); }
.search-trigger svg { width: 16px; height: 16px; }
.kbd { margin-left: auto; font-size: 11px; padding: 1px 6px; border: 1px solid var(--line); border-radius: 6px; color: var(--ink-3); background: var(--surface-2); }
.topbar .spacer { flex: 1; }
.btn.menu-btn { display: none; }
.content { padding: 8px 36px 64px; max-width: 1480px; width: 100%; }
.page-enter { animation: enter .28s cubic-bezier(.2,.8,.2,1); }
@keyframes enter { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; padding: 18px 0 22px; flex-wrap: wrap; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.page-head h1 { margin: 4px 0 0; font: 600 30px/1.15 var(--font-display); letter-spacing: -.035em; }
.page-head h1.serif { font: 400 44px/1.05 var(--font-serif); letter-spacing: -.01em; }
.page-head p { margin: 6px 0 0; color: var(--ink-3); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-3); }
.crumbs a:hover { color: var(--ink); }
.crumbs svg { width: 14px; height: 14px; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 38px; padding: 0 15px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 560; font-size: 13.5px; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, transform .08s, box-shadow .15s; }
.btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 1px 2px rgba(0,0,0,.12), inset 0 1px 0 rgba(255,255,255,.08); }
.btn.primary:hover { background: var(--brand-2); border-color: var(--brand-2); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 32px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
.btn.icon { width: 38px; padding: 0; }
.btn.sm.icon { width: 32px; }
.btn[disabled] { opacity: .5; pointer-events: none; }
.btn.loading { pointer-events: none; opacity: .75; }
.btn.loading::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards & stats ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 22px 0; }
.card-head h3 { margin: 0; font-size: 15px; font-weight: 640; letter-spacing: -.01em; }
.card-head .sub { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
.card-head a.link, a.link { font-size: 13px; font-weight: 600; color: var(--accent); }
a.link:hover { text-decoration: underline; text-underline-offset: 3px; }
.grid { display: grid; gap: 16px; }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-main { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); }
.g-side { grid-template-columns: minmax(0, 1fr) 340px; }
.stat { padding: 18px 20px; position: relative; overflow: hidden; }
.stat .label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.stat .label .ic { width: 28px; height: 28px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-softer); color: var(--accent); }
.stat .label .ic svg { width: 15px; height: 15px; }
.stat .value { margin-top: 12px; font: 600 28px/1.1 var(--font-display); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat .foot { margin-top: 6px; font-size: 12.5px; color: var(--ink-3); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.stat.clickable { cursor: pointer; transition: transform .15s, box-shadow .15s; }
.stat.clickable:hover { transform: translateY(-1px); box-shadow: var(--shadow), 0 0 0 1px var(--line-strong); }
.delta { font-weight: 600; font-size: 12px; padding: 1px 7px; border-radius: 99px; }
.delta.up { color: var(--ok); background: var(--ok-soft); } .delta.down { color: var(--bad); background: var(--bad-soft); }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-3); color: var(--ink-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge.plain::before { display: none; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--accent); }
.badge.gold { background: var(--gold-soft); color: var(--gold); }
.tag { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 6px; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--ink-2); }

/* ---------- Toolbar & filters ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 11px; border: 1px solid var(--line); }
.seg button { height: 30px; padding: 0 12px; border: 0; background: transparent; border-radius: 8px; color: var(--ink-2); font-weight: 560; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.seg button .n { font-size: 11px; color: var(--ink-3); font-weight: 600; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.searchbox { position: relative; flex: 1; min-width: 200px; max-width: 360px; }
.searchbox svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--ink-3); }
.searchbox input { padding-left: 34px !important; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .field > label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); font-weight: 400; }
.input, select.input, textarea.input { width: 100%; height: 40px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s; }
textarea.input { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; }
select.input { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%237D8A83' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; }
.input:hover { border-color: var(--line-strong); }
.input:focus { border-color: var(--brand-2); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand-2) 14%, transparent); }
.input.sm { height: 34px; border-radius: 9px; }
.input.right { text-align: right; font-variant-numeric: tabular-nums; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-weight: 500; user-select: none; }
.check input { appearance: none; width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--line-strong); background: var(--surface); display: grid; place-items: center; cursor: pointer; transition: all .15s; margin: 0; }
.check input:checked { background: var(--brand); border-color: var(--brand); }
.check input:checked::after { content: ""; width: 10px; height: 6px; border: 2px solid var(--brand-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.switch-row { display: flex; gap: 18px; flex-wrap: wrap; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; }
.tbl th { position: sticky; top: 0; z-index: 1; text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 11px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; user-select: none; }
.tbl th.sortable { cursor: pointer; } .tbl th.sortable:hover { color: var(--ink); }
.tbl th .arrow { opacity: .6; font-size: 10px; margin-left: 3px; }
.tbl th:first-child { border-top-left-radius: var(--radius); } .tbl th:last-child { border-top-right-radius: var(--radius); }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr.row-link { cursor: pointer; transition: background .12s; }
.tbl tbody tr.row-link:hover { background: var(--surface-2); }
.tbl .num, .tbl th.num { text-align: right; white-space: nowrap; }
.tbl td.strong { font-weight: 600; }
.tbl tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--line); border-bottom: 0; }
.tbl.compact td { padding: 9px 14px; }
.cell-main { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cell-main .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 420px; }
.cell-main .s { font-size: 12.5px; color: var(--ink-3); }
.thumb { width: 38px; height: 38px; border-radius: 10px; background: var(--surface-3); object-fit: cover; flex: none; display: grid; place-items: center; color: var(--ink-4); border: 1px solid var(--line); overflow: hidden; }
.thumb svg { width: 18px; height: 18px; }
.thumb.lg { width: 96px; height: 96px; border-radius: 18px; }
.thumb.sm { width: 30px; height: 30px; border-radius: 8px; }
.pager { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-3); }
.qty-neg { color: var(--bad); font-weight: 650; }
.qty-low { color: var(--warn); font-weight: 650; }

/* ---------- Empty ---------- */
.empty { text-align: center; padding: 56px 24px; color: var(--ink-3); }
.empty .ic { width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 16px; background: var(--brand-softer); color: var(--accent); display: grid; place-items: center; }
.empty .ic svg { width: 24px; height: 24px; }
.empty h4 { margin: 0 0 4px; color: var(--ink); font-size: 15px; }
.empty p { margin: 0 0 16px; }

/* ---------- Document (venta/compra/producción) ---------- */
.doc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; padding: 18px 0 20px; }
.doc-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.doc-title h1 { margin: 0; font: 600 30px/1.1 var(--font-display); letter-spacing: -.03em; }
.steps { display: flex; align-items: center; gap: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 4px; box-shadow: var(--shadow-sm); }
.steps span { display: flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 9px; font-size: 12.5px; font-weight: 600; color: var(--ink-4); }
.steps span .dot { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid currentColor; display: grid; place-items: center; font-size: 10px; }
.steps span.done { color: var(--accent); } .steps span.done .dot { background: var(--brand-2); border-color: var(--brand-2); color: var(--brand-ink); }
.steps span.current { color: var(--ink); background: var(--brand-softer); } .steps span.current .dot { border-color: var(--brand-2); color: var(--brand-2); }
.steps span.cancel { color: var(--bad); background: var(--bad-soft); }
.steps i { width: 14px; height: 1.5px; background: var(--line-strong); }
.meta-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1px; background: var(--line); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.meta-grid > div { background: var(--surface); padding: 14px 18px; min-width: 0; }
.meta-grid .k { font-size: 12px; color: var(--ink-3); font-weight: 500; }
.meta-grid .v { margin-top: 3px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.totals { margin-left: auto; width: min(340px, 100%); padding: 16px 22px 20px; }
.totals .row { display: flex; justify-content: space-between; padding: 5px 0; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.totals .row.grand { color: var(--ink); font: 600 20px/1.3 var(--font-display); letter-spacing: -.02em; border-top: 1px solid var(--line); margin-top: 8px; padding-top: 12px; }
.progress { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 99px; background: var(--brand-2); transition: width .4s; }
.progress.gold > i { background: var(--gold); }
.alert { display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: 12px; background: var(--warn-soft); color: var(--warn); font-size: 13.5px; }
.alert svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }
.alert b { color: inherit; }
.alert .body { color: var(--ink-2); } .alert .body b { color: var(--ink); }

/* Editor de líneas */
.lines-editor td { padding: 8px 10px; }
.lines-editor .input { height: 36px; }
.lines-editor .col-qty { width: 110px; } .lines-editor .col-price { width: 130px; } .lines-editor .col-disc { width: 90px; } .lines-editor .col-sub { width: 130px; } .lines-editor .col-x { width: 44px; }
.add-line { display: flex; align-items: center; gap: 8px; width: 100%; padding: 12px 14px; border: 0; background: transparent; color: var(--accent); font-weight: 600; cursor: pointer; border-top: 1px dashed var(--line); border-radius: 0 0 var(--radius) var(--radius); }
.add-line:hover { background: var(--brand-softer); }
.add-line svg { width: 16px; height: 16px; }

/* Combobox */
.combo { position: relative; }
.combo-list { position: absolute; z-index: 120; left: 0; right: 0; top: calc(100% + 4px); max-height: 320px; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 5px; min-width: 300px; }
.combo-list .opt { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.combo-list .opt.hl { background: var(--brand-softer); }
.combo-list .opt .t { font-weight: 560; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-list .opt .r { font-size: 12px; color: var(--ink-3); white-space: nowrap; font-variant-numeric: tabular-nums; }
.combo-list .none { padding: 12px; color: var(--ink-3); font-size: 13px; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: 0; z-index: 90; background: rgba(12,20,16,.32); backdrop-filter: blur(3px); animation: fade .18s; }
@keyframes fade { from { opacity: 0; } }
.drawer { position: fixed; z-index: 91; top: 10px; right: 10px; bottom: 10px; width: min(560px, calc(100vw - 20px)); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .26s cubic-bezier(.2,.8,.2,1); }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px 14px; border-bottom: 1px solid var(--line); }
.drawer-head h2 { margin: 0; font: 600 20px/1.2 var(--font-display); letter-spacing: -.02em; }
.drawer-body { padding: 20px 24px; overflow-y: auto; flex: 1; }
.drawer-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 24px; border-top: 1px solid var(--line); }
.modal { position: fixed; z-index: 91; left: 50%; top: 14vh; transform: translateX(-50%); width: min(460px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow-lg); padding: 24px; animation: pop .2s cubic-bezier(.2,.8,.2,1); }
.modal.wide { width: min(640px, calc(100vw - 32px)); }
@keyframes pop { from { transform: translateX(-50%) scale(.97); opacity: 0; } }
.modal h3 { margin: 0 0 6px; font: 600 18px/1.3 var(--font-display); }
.modal .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 22px; }

.palette { position: fixed; z-index: 95; left: 50%; top: 12vh; transform: translateX(-50%); width: min(640px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow-lg); overflow: hidden; animation: pop .18s; }
.palette input { width: 100%; height: 56px; border: 0; outline: 0; padding: 0 20px 0 52px; font-size: 16px; background: transparent; border-bottom: 1px solid var(--line); }
.palette .pi { position: absolute; left: 20px; top: 19px; width: 18px; height: 18px; color: var(--ink-3); }
.palette .results { max-height: 420px; overflow-y: auto; padding: 6px; }
.palette .grp { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-4); padding: 10px 12px 4px; }
.palette .item { display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 10px; cursor: pointer; }
.palette .item.hl { background: var(--brand-softer); }
.palette .item svg { width: 17px; height: 17px; color: var(--ink-3); flex: none; }
.palette .item .t { font-weight: 560; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette .item .r { font-size: 12.5px; color: var(--ink-3); }

.toasts { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 12px; background: var(--ink); color: var(--canvas); box-shadow: var(--shadow-lg); font-weight: 520; max-width: 420px; animation: toast .26s cubic-bezier(.2,.8,.2,1); }
.toast.err { background: var(--bad); color: #fff; }
.toast svg { width: 17px; height: 17px; flex: none; }
@keyframes toast { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Charts ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .tip { position: absolute; pointer-events: none; z-index: 5; background: var(--ink); color: var(--canvas); padding: 8px 11px; border-radius: 10px; font-size: 12.5px; box-shadow: var(--shadow-lg); white-space: nowrap; transform: translate(-50%, calc(-100% - 10px)); opacity: 0; transition: opacity .12s; }
.chart .tip b { display: block; font-size: 14px; font-variant-numeric: tabular-nums; }
.chart .tip.show { opacity: 1; }
.chart .axis { font-size: 11px; fill: var(--ink-3); }
.chart .grid-line { stroke: var(--chart-grid); stroke-width: 1; }
.chart .bar { fill: var(--chart); transition: opacity .15s; }
.chart .bar.dim { fill: var(--chart-soft); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .bar, .chart g.col:hover .bar { opacity: .82; }
.hbar { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.hbar .name { font-size: 13px; font-weight: 520; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbar .val { font-size: 13px; color: var(--ink-2); text-align: right; font-variant-numeric: tabular-nums; }
.hbar .track { grid-column: 1 / -1; height: 6px; border-radius: 99px; background: var(--surface-3); margin-bottom: 8px; }
.hbar .track i { display: block; height: 100%; border-radius: 99px; background: var(--chart); }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 11px 22px; border-top: 1px solid var(--line); }
.list-item:first-child { border-top: 0; }
a.list-item:hover { background: var(--surface-2); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .t { font-weight: 580; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .s { font-size: 12.5px; color: var(--ink-3); }
.timeline { padding: 6px 22px 18px; }
.timeline .ev { display: flex; gap: 12px; padding: 8px 0; position: relative; }
.timeline .ev::before { content: ""; position: absolute; left: 4px; top: 22px; bottom: -8px; width: 1px; background: var(--line); }
.timeline .ev:last-child::before { display: none; }
.timeline .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--brand-2); margin-top: 6px; flex: none; box-shadow: 0 0 0 3px var(--brand-softer); }
.timeline .t { font-size: 13.5px; } .timeline .s { font-size: 12px; color: var(--ink-3); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; }
.tabs button { height: 40px; padding: 0 14px; border: 0; background: none; color: var(--ink-3); font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--ink); }
.tabs button.on { color: var(--ink); border-bottom-color: var(--gold); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 14px; font-size: 13.5px; }
.kv .k { color: var(--ink-3); }
.hero-num { font: 600 34px/1.1 var(--font-display); letter-spacing: -.03em; font-variant-numeric: tabular-nums; }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-art { position: relative; overflow: hidden; background: radial-gradient(120% 90% at 20% 10%, #1C6B4C 0%, #0B4A34 45%, #062C1F 100%); color: #E9F2EC; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-art::after { content: ""; position: absolute; inset: 0; background: radial-gradient(60% 50% at 85% 90%, rgba(199,164,106,.22), transparent 70%); }
.auth-art img { width: 240px; filter: brightness(0) invert(1); opacity: .96; position: relative; z-index: 1; }
.auth-art h2 { position: relative; z-index: 1; font: 400 58px/1.0 var(--font-serif); letter-spacing: -.02em; margin: 0; max-width: 520px; }
.auth-art p { position: relative; z-index: 1; color: rgba(233,242,236,.72); max-width: 440px; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; background: var(--canvas); }
.auth-form form { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; }
.auth-form h1 { margin: 0; font: 600 28px/1.2 var(--font-display); letter-spacing: -.03em; }
.auth-form .btn { height: 44px; }
.auth-form .err { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- Print ---------- */
.print-doc { display: none; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; }
  .shell, .toasts, .overlay, .drawer, .modal, .palette { display: none !important; }
  .print-doc { display: block; color: #111; font-size: 12px; }
  .print-doc .ph { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid #0B4A34; padding-bottom: 14px; margin-bottom: 18px; }
  .print-doc img { width: 220px; }
  .print-doc h1 { font-size: 22px; margin: 0; color: #0B4A34; }
  .print-doc table { width: 100%; border-collapse: collapse; margin-top: 14px; }
  .print-doc th { text-align: left; border-bottom: 1px solid #999; padding: 6px; font-size: 11px; color: #555; }
  .print-doc td { padding: 6px; border-bottom: 1px solid #e5e5e5; }
  .print-doc .r { text-align: right; }
  .print-doc .tot { margin-left: auto; width: 260px; margin-top: 12px; }
  .print-doc .tot div { display: flex; justify-content: space-between; padding: 3px 0; }
  .print-doc .tot .g { font-size: 16px; font-weight: 700; border-top: 1px solid #333; margin-top: 6px; padding-top: 6px; }
  .print-doc .foot { margin-top: 40px; font-size: 11px; color: #666; text-align: center; }
}

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .g-main, .g-side { grid-template-columns: 1fr; }
  .meta-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 80; left: 0; top: 0; width: 272px; transform: translateX(-102%); transition: transform .25s cubic-bezier(.2,.8,.2,1); background: var(--surface); box-shadow: var(--shadow-lg); }
  .shell.nav-open .sidebar { transform: none; }
  .btn.menu-btn { display: inline-flex; }
  .topbar { padding: 12px 16px; }
  .content { padding: 4px 16px 48px; }
  .g-3, .g-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .page-head h1 { font-size: 26px; }
  .kbd { display: none; }
  .steps span .dot { display: none; } .steps span { padding: 0 10px; font-size: 12px; }
}
@media (max-width: 560px) {
  .g-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 14px; } .stat .value { font-size: 21px; }
  .meta-grid { grid-template-columns: 1fr; }
  .tbl .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- Catálogo en mosaico ---------- */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.pcard { overflow: hidden; display: flex; flex-direction: column; transition: transform .18s, box-shadow .18s; }
.pcard:hover { transform: translateY(-2px); box-shadow: var(--shadow), 0 0 0 1px var(--line-strong); }
.pimg { aspect-ratio: 1 / 1; background: var(--surface-2); display: grid; place-items: center; color: var(--ink-4); border-bottom: 1px solid var(--line); overflow: hidden; }
.pimg img { width: 100%; height: 100%; object-fit: contain; padding: 10px; mix-blend-mode: multiply; }
:root[data-theme="dark"] .pimg { background: #F3F2EE; }
.pimg svg { width: 34px; height: 34px; }
.pbody { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.pname { font-weight: 600; font-size: 13.5px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 35px; }
.pfoot { display: flex; justify-content: space-between; align-items: baseline; margin-top: auto; padding-top: 8px; font-variant-numeric: tabular-nums; }
.seg button svg { width: 15px; height: 15px; }
@media (max-width: 560px) { .pgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }
.auth-logo-sm { display: none; }
@media (max-width: 860px) { .auth-logo-sm { display: block; } }
:root[data-theme="dark"] .auth-logo-sm img { filter: brightness(0) invert(.92); }
.auth-logo { position: relative; z-index: 1; }
.auth-logo-sm { margin-bottom: 10px; } .auth-logo-sm img { width: 180px; }
.lines-editor td:first-child { min-width: 240px; }
.steps .dot svg { width: 11px; height: 11px; stroke-width: 2.6; }
.tbl td { white-space: nowrap; } .tbl td .cell-main .t { white-space: nowrap; }
.search-trigger > span:not(.kbd) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
@media (max-width: 560px) { #quick-new span { display: none; } #quick-new { width: 38px; padding: 0; } }
.tabs { scrollbar-width: none; } .tabs::-webkit-scrollbar { display: none; }

/* ---------- Celular: tablas como tarjetas ---------- */
@media (max-width: 640px) {
  .content { padding: 4px 12px 40px; }
  .page-head { padding: 10px 0 16px; }
  .page-head h1, .doc-title h1 { font-size: 24px; }
  .page-head h1.serif { font-size: 32px; }
  .page-actions { width: 100%; }
  .page-actions > .btn:not(.icon) { flex: 1; }
  .toolbar { gap: 8px; }
  .toolbar .seg { width: 100%; overflow-x: auto; scrollbar-width: none; }
  .toolbar .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: none; }
  .searchbox { max-width: none; min-width: 0; flex-basis: 100%; }
  .card-head, .card-pad { padding-left: 16px; padding-right: 16px; }
  .list-item { padding: 11px 16px; }
  .table-wrap { overflow: visible; }
  table.tbl, .tbl tbody, .tbl tfoot { display: block; }
  .tbl thead { display: none; }
  .tbl tbody tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
  .tbl tbody tr:last-child { border-bottom: 0; }
  .tbl td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 0; border: 0; white-space: normal; text-align: right; min-width: 0; font-size: 13.5px; }
  .tbl td::before { content: attr(data-label); color: var(--ink-3); font-size: 12px; font-weight: 500; text-align: left; white-space: nowrap; }
  .tbl td:first-child { grid-column: 1 / -1; justify-content: flex-start; text-align: left; font-size: 15px; padding-bottom: 4px; }
  .tbl td:first-child::before { display: none; }
  .tbl td:not(:first-child) { grid-column: 1 / -1; }
  .tbl td:empty, .tbl td[data-label=""]::before { display: none; }
  .tbl td.num:last-child { font-size: 15px; }
  .tbl .cell-main .t { max-width: 100%; white-space: normal; }
  .tbl tfoot tr { display: flex; justify-content: space-between; padding: 12px 16px; background: var(--surface-2); }
  .tbl tfoot td { padding: 0; border: 0; background: none; }
  .tbl tfoot td:empty { display: none; }
  .tbl.lines-editor td:first-child { min-width: 0; }
  .tbl.lines-editor td .input { max-width: 150px; }
  .tbl.lines-editor td:first-child .input { max-width: none; }
  .meta-grid > div { padding: 12px 16px; }
  .doc-head { padding: 10px 0 14px; }
  .steps { overflow-x: auto; }
  .totals { width: 100%; }
  .drawer { top: auto; left: 0; right: 0; bottom: 0; width: 100% !important; max-height: 92vh; border-radius: 22px 22px 0 0; animation: rise .28s cubic-bezier(.2,.8,.2,1); }
  @keyframes rise { from { transform: translateY(30px); opacity: 0; } }
  .drawer-head, .drawer-body, .drawer-foot { padding-left: 18px; padding-right: 18px; }
  .drawer-foot .btn { flex: 1; height: 44px; }
  .modal { top: auto; bottom: 12px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; align-items: stretch; }
  .pager { flex-direction: column; gap: 8px; }
  .topbar { padding: 10px 12px; gap: 8px; }
}
