:root {
  --ink: #17162B; --ink-2: #2B2946; --ink-3: #5B597A;
  --paper: #F5F2EC; --paper-2: #FFFFFF; --line: #E4DFD4; --line-2: #D2CCBF;
  --muted: #7B7891; --coral: #E6948C; --coral-ink: #B85A51; --ok: #3F8F5F; --warn: #C98A1B; --bad: #C0392B;
  --font-ui: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Archivo', 'DM Sans', system-ui, sans-serif;
  --side: 272px; --drawer: 440px; --r: 12px;
  --accent: #E6948C; --accent-soft: #FCF1F0;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font-ui); font-size: 14px; line-height: 1.45; color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.display { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.03em; line-height: 1.05; margin: 0; }
.num { font-family: var(--font-display); font-weight: 600; font-variant-numeric: lining-nums tabular-nums; letter-spacing: -0.03em; }
.muted { color: var(--muted); }
.kicker { margin: 0 0 4px; font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.grow { flex: 1; }

/* ── botones y campos ─────────────────────────────────────────────── */
.btn { border: 1px solid var(--line-2); background: var(--paper-2); border-radius: 999px; padding: 9px 16px; font-weight: 500; line-height: 1; transition: background .15s, border-color .15s; }
.btn:hover { border-color: var(--ink-3); }
.btn--primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn--primary:hover { background: var(--ink-2); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 7px 12px; font-size: 13px; }
.input { border: 1px solid var(--line-2); background: var(--paper-2); border-radius: 8px; padding: 8px 10px; min-height: 36px; }
.input:focus { outline: 2px solid var(--ink); outline-offset: 1px; }
.input--search { min-width: 260px; flex: 1; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.field { display: block; margin: 18px 0; }
.field span { display: block; font-size: 12px; font-weight: 600; color: var(--ink-3); margin-bottom: 6px; }
.field input { width: 100%; border: 1px solid var(--line-2); border-radius: 8px; padding: 10px 12px; }

/* ── login ─────────────────────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(900px 500px at 10% -10%, #FCE9E6 0%, transparent 60%), var(--paper); }
.login__card { width: min(420px, 100%); background: var(--paper-2); border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: 0 20px 60px rgba(23,22,43,.08); }
.login__card h1 { font-size: 28px; margin: 18px 0 6px; }
.login__card .btn { width: 100%; padding: 12px; }
.login__error { color: var(--bad); margin: 12px 0 0; }

/* ── marca ─────────────────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 10px; }
.brand__mark { width: 28px; height: 28px; border-radius: 8px; background: var(--ink); color: var(--coral); display: grid; place-items: center; font-family: var(--font-display); font-size: 12px; font-weight: 700; }
.brand__name { font-family: var(--font-display); font-weight: 600; letter-spacing: -.02em; font-size: 16px; }
.brand--light .brand__mark { background: #fff; color: var(--ink); }
.brand--light .brand__name { color: #fff; }

/* ── layout ────────────────────────────────────────────────────────── */
.app { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side { background: var(--ink); color: #fff; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side__top { display: flex; align-items: center; justify-content: space-between; padding: 20px 20px 12px; }
.side__close { display: none; background: none; border: 0; color: #fff; font-size: 24px; }
.side__foot { margin-top: auto; padding: 14px 16px 18px; border-top: 1px solid rgba(255,255,255,.1); }
.side__actions { display: flex; gap: 8px; margin-top: 10px; }
.side__actions .btn { border-color: rgba(255,255,255,.25); color: #fff; flex: 1; }
.side__actions .btn:hover { border-color: #fff; background: rgba(255,255,255,.06); }
.sync { display: flex; align-items: center; gap: 8px; font-size: 12px; color: rgba(255,255,255,.7); }
.sync__dot { width: 8px; height: 8px; border-radius: 50%; background: #888; flex: none; }
.sync__dot.is-ok { background: #5FD38D; } .sync__dot.is-busy { background: #F5C451; animation: pulse 1s infinite; } .sync__dot.is-bad { background: #F07167; }
@keyframes pulse { 50% { opacity: .3; } }

.nav { overflow-y: auto; padding: 6px 10px 10px; flex: 1; scrollbar-width: thin; }
.nav__item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: none; border: 0; color: rgba(255,255,255,.82); padding: 9px 10px; border-radius: 9px; font-size: 14px; }
.nav__item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav__item.is-active { background: rgba(255,255,255,.12); color: #fff; }
.nav__item--all { font-weight: 600; margin-bottom: 4px; }
.nav__logo { width: 22px; height: 22px; display: grid; place-items: center; flex: none; }
.nav__logo svg { width: 100%; height: 100%; }
.nav__dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin: 0 6px; }
.nav__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav__n { font-size: 12px; color: rgba(255,255,255,.5); font-variant-numeric: tabular-nums; }
.nav__item.is-active .nav__n { color: rgba(255,255,255,.8); }
.nav__toggle { width: 18px; height: 18px; display: grid; place-items: center; color: rgba(255,255,255,.45); font-size: 11px; transition: transform .15s; flex: none; }
.nav__group.is-open .nav__toggle { transform: rotate(90deg); }
.nav__sub { display: none; padding-left: 22px; margin: 2px 0 6px; }
.nav__group.is-open .nav__sub { display: block; }
.nav__sub .nav__item { padding: 6px 10px; font-size: 13px; color: rgba(255,255,255,.68); }
.nav__sub .nav__item::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .5; margin-right: 4px; flex: none; }

.main { min-width: 0; padding: 26px 32px 60px; }
.head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; }
.head__menu { display: none; background: none; border: 1px solid var(--line-2); border-radius: 8px; width: 38px; height: 38px; font-size: 18px; }
.head__titles h1 { font-size: 34px; }
.head__link { margin-left: auto; font-size: 13px; color: var(--ink-3); text-decoration: none; border-bottom: 1px solid var(--line-2); padding-bottom: 2px; }
.head__link:hover { color: var(--ink); border-color: var(--ink); }

/* ── kpis ──────────────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent); }
.kpi__label { font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.kpi__value { font-size: 30px; line-height: 1; }
.kpi__sub { font-size: 12px; color: var(--ink-3); margin-top: 6px; }

/* ── toolbar ───────────────────────────────────────────────────────── */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line-2); overflow-x: auto; }
.tab { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font-weight: 500; color: var(--ink-3); white-space: nowrap; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ── tabla ─────────────────────────────────────────────────────────── */
.table-wrap { background: var(--paper-2); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.count { margin: 0; padding: 10px 16px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.table { width: 100%; border-collapse: collapse; display: block; overflow-x: auto; }
.table thead, .table tbody, .table tr { display: table; width: 100%; table-layout: fixed; }
.table th { text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); background: #FBFAF7; white-space: nowrap; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: #FBF7F1; }
.table tr.is-test td { color: var(--muted); }
.table tr.is-dup td:first-child::before { content: '⟳ '; color: var(--warn); }
.cell-main { font-weight: 500; }
.cell-sub { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--paper); border: 1px solid var(--line); white-space: nowrap; }
.pill--brand { color: var(--pill-ink, var(--ink)); background: var(--pill-bg, var(--paper)); border-color: transparent; }
.more { display: block; margin: 12px auto; }
.empty { text-align: center; padding: 40px; color: var(--muted); margin: 0; }

/* ── drawer ────────────────────────────────────────────────────────── */
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--drawer), 100%); background: var(--paper-2); border-left: 1px solid var(--line); box-shadow: -20px 0 60px rgba(23,22,43,.12); z-index: 40; display: flex; flex-direction: column; }
.drawer__head { display: flex; align-items: flex-start; gap: 12px; padding: 22px 24px 14px; border-bottom: 1px solid var(--line); }
.drawer__head h2 { font-size: 22px; }
.drawer__close { margin-left: auto; background: none; border: 0; font-size: 26px; line-height: 1; color: var(--ink-3); }
.drawer__body { overflow-y: auto; padding: 16px 24px 32px; }
.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0 0 18px; font-size: 13px; }
.dl dt { color: var(--muted); } .dl dd { margin: 0; word-break: break-word; }
.dl dd a { color: var(--ink); }
.d-section { margin: 0 0 8px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.d-msg { background: var(--paper); border-radius: 10px; padding: 12px 14px; white-space: pre-wrap; margin: 0 0 18px; font-size: 13px; }
.d-notes { width: 100%; min-height: 80px; border: 1px solid var(--line-2); border-radius: 8px; padding: 10px; resize: vertical; }
.d-row { display: flex; align-items: center; gap: 10px; margin: 8px 0 18px; }
.d-saved { font-size: 12px; color: var(--ok); }
.scrim { position: fixed; inset: 0; background: rgba(23,22,43,.25); z-index: 30; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px; z-index: 50; box-shadow: 0 10px 30px rgba(0,0,0,.2); }

/* ── móvil ─────────────────────────────────────────────────────────── */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: min(320px, 88vw); z-index: 45; transform: translateX(-100%); transition: transform .2s; }
  .side.is-open { transform: none; }
  .side__close { display: block; }
  .head__menu { display: block; }
  .main { padding: 16px 16px 40px; }
  .head__titles h1 { font-size: 26px; }
  .head__link { display: none; }
  .input--search { min-width: 0; width: 100%; }
  .table thead, .table tbody, .table tr { table-layout: auto; min-width: 900px; }
}
