:root {
  --bg: #f3f5f9; --surface: #ffffff; --surface-2: #f7f9fc; --ink: #0f1b2d; --muted: #5b6b82; --line: #e2e8f0;
  --brand: #1d4ed8; --brand-ink: #ffffff; --brand-soft: #e8efff;
  --input: #eef4ff; --input-line: #b9cdf7; --input-ink: #0b3aa8;
  --good: #0f8a5f; --good-soft: #e3f6ee; --warn: #b45309; --warn-soft: #fff4dd; --bad: #c62828; --bad-soft: #fdeaea; --info: #2563a8; --info-soft: #e6f1fb;
  --side: #0f1b2d; --side-ink: #c9d5e6; --side-active: #1f3050;
  --c-comercial: #d97706; --c-operaciones: #0284c7; --c-finanzas: #059669; --c-gerente: #7c3aed;
  --radius: 14px; --shadow: 0 1px 2px rgba(15, 27, 45, .06), 0 8px 24px -12px rgba(15, 27, 45, .18);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #131c2e; --surface-2: #18233a; --ink: #e6edf7; --muted: #93a3bb; --line: #25324a;
  --brand: #6b9bff; --brand-ink: #0b1220; --brand-soft: #1b2a4a;
  --input: #16284d; --input-line: #2f4a85; --input-ink: #a9c5ff;
  --good: #3ecf9a; --good-soft: #10332a; --warn: #f5b352; --warn-soft: #3a2c10; --bad: #ff7b7b; --bad-soft: #3d1717; --info: #7db7f0; --info-soft: #14283f;
  --side: #0a101c; --side-active: #1a2740; --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -.01em; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.neg { color: var(--bad); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-hero { background: radial-gradient(1200px 600px at 10% 10%, #24427a 0%, #0f1b2d 55%, #0a1220 100%); color: #e8eefb; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; }
.login-hero h1 { font-size: 40px; font-weight: 750; max-width: 12ch; }
.login-hero p { color: #b4c3de; max-width: 44ch; font-size: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: .02em; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #5b8cff, #7c3aed); display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px; }
.hero-stats { display: flex; gap: 28px; flex-wrap: wrap; }
.hero-stats div b { display: block; font-size: 22px; }
.hero-stats div span { color: #9fb1cf; font-size: 13px; }
.login-panel { display: grid; place-items: center; padding: 32px 20px; }
.login-card { width: min(420px, 100%); }
.login-card h2 { font-size: 24px; margin-bottom: 6px; }
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 20px 0; }
.role { border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px; padding: 12px; text-align: left; cursor: pointer; transition: .15s; display: flex; flex-direction: column; gap: 2px; }
.role:hover { border-color: var(--rc); }
.role[aria-pressed="true"] { border-color: var(--rc); box-shadow: 0 0 0 3px color-mix(in srgb, var(--rc) 18%, transparent); }
.role i { width: 10px; height: 10px; border-radius: 50%; background: var(--rc); display: block; margin-bottom: 6px; }
.role b { font-size: 14px; }
.role span { font-size: 12px; color: var(--muted); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.field input, .field select, textarea.notes { width: 100%; padding: 11px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); outline: none; }
.field input:focus, textarea.notes:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.btn { border: 0; border-radius: 10px; padding: 10px 16px; font-weight: 650; cursor: pointer; background: var(--brand); color: var(--brand-ink); transition: .15s; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; padding: 12px; }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn.danger { background: var(--bad); color: #fff; }
.err { color: var(--bad); font-size: 13.5px; min-height: 20px; margin: 6px 0; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 6px; overflow-y: auto; }
.side .brand { color: #fff; padding: 4px 8px 14px; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: #6f819d; padding: 12px 10px 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: inherit; text-decoration: none; font-weight: 550; font-size: 14px; cursor: pointer; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.on { background: var(--side-active); color: #fff; }
.nav a .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--dc, #55657f); flex: none; }
.nav a .badge { margin-left: auto; font-size: 11px; background: var(--bad); color: #fff; border-radius: 99px; padding: 1px 7px; font-weight: 700; }
.side-foot { margin-top: auto; padding: 10px; border-top: 1px solid rgba(255, 255, 255, .08); font-size: 13px; }
.side-foot b { color: #fff; display: block; }
.side-foot .row { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.side-foot .btn { background: rgba(255, 255, 255, .08); color: #fff; }
.main { min-width: 0; display: flex; flex-direction: column; }
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.top h1 { font-size: 19px; }
.top .sp { flex: 1; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-size: 12.5px; font-weight: 650; background: var(--surface); border: 1px solid var(--line); }
.pill.role-pill { color: #fff; border: 0; background: var(--rc); }
.pill.ok { background: var(--good-soft); color: var(--good); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.top select { padding: 6px 10px; border-radius: 9px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 600; }
.save-state { font-size: 12.5px; color: var(--muted); min-width: 92px; text-align: right; }
.kpis { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; padding: 14px 24px 0; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; min-width: 0; }
.kpi span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi b { font-size: 19px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.good b { color: var(--good); } .kpi.bad b { color: var(--bad); } .kpi.warn b { color: var(--warn); }
.content { padding: 16px 24px 90px; display: grid; gap: 16px; }
.cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.cols.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stack { display: grid; gap: 16px; min-width: 0; }

/* ---------- Cards & sheets ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px 10px; flex-wrap: wrap; }
.card-h h3 { font-size: 15.5px; }
.card-h p { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); flex-basis: 100%; }
.card-h .sp { flex: 1; }
.card-b { padding: 0 16px 16px; }
.scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.sheet { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.sheet th, .sheet td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.sheet thead th { position: sticky; top: 0; background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; border-top: 1px solid var(--line); }
.sheet th:first-child, .sheet td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; font-weight: 500; white-space: normal; min-width: 150px; max-width: 260px; }
.sheet thead th:first-child { background: var(--surface-2); }
.sheet tr.total > * { font-weight: 700; background: var(--surface-2); border-top: 1.5px solid var(--line); }
.sheet tr.sub > * { color: var(--muted); font-size: 12.5px; }
.sheet tr.sec > * { background: var(--surface-2); font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; text-align: left; }
.sheet tr.key > * { font-weight: 700; }
.sheet td.in { padding: 3px 4px; }
.sheet small { color: var(--muted); font-weight: 400; display: block; font-size: 11.5px; }
.sheet .code { font-family: var(--mono); font-size: 11px; color: var(--muted); }
input.cell, select.cell { width: 100%; min-width: 78px; padding: 6px 8px; border-radius: 7px; border: 1.5px solid var(--input-line); background: var(--input); color: var(--input-ink); text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; outline: none; }
select.cell { text-align: left; min-width: 120px; }
input.cell:focus, select.cell:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); background: var(--surface); }
input.cell:disabled, select.cell:disabled { background: transparent; border-color: transparent; color: var(--ink); opacity: 1; -webkit-text-fill-color: var(--ink); font-weight: 500; }
input.cell.invalid { border-color: var(--bad); background: var(--bad-soft); }
label.chk { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
label.chk input { width: 17px; height: 17px; accent-color: var(--brand); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); align-items: center; }
.legend i { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: -2px; margin-right: 5px; background: var(--input); border: 1.5px solid var(--input-line); }
.ro-banner { background: var(--info-soft); color: var(--info); border-radius: 10px; padding: 9px 12px; font-size: 13px; font-weight: 550; }

/* alerts */
.alerts { display: grid; gap: 8px; }
.alert { display: flex; gap: 10px; padding: 9px 12px; border-radius: 10px; font-size: 13.5px; align-items: flex-start; }
.alert::before { content: ""; width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex: none; background: currentColor; }
.alert.bad { background: var(--bad-soft); color: var(--bad); } .alert.warn { background: var(--warn-soft); color: var(--warn); } .alert.info { background: var(--info-soft); color: var(--info); } .alert.good { background: var(--good-soft); color: var(--good); }
.alert span { color: var(--ink); }
.alert em { font-style: normal; font-weight: 700; text-transform: capitalize; }

/* bars */
.bar { height: 12px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.b-t1 { background: #2563eb; } .b-t2 { background: #38bdf8; } .b-st { background: #f59e0b; } .b-sc { background: #ef4444; } .b-free { background: transparent; }
.keys { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: var(--muted); margin-top: 8px; }
.keys i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; }
.hbar { display: grid; grid-template-columns: 150px 1fr 96px; gap: 10px; align-items: center; font-size: 13px; padding: 4px 0; }
.hbar .track { height: 16px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.hbar .track i { display: block; height: 100%; border-radius: 5px; background: var(--brand); }
.hbar .track i.neg { background: var(--bad); } .hbar .track i.pos { background: var(--good); }
.hbar b { text-align: right; font-variant-numeric: tabular-nums; }

/* checklist & team */
.checks { display: grid; gap: 6px; }
.checks label { display: flex; gap: 10px; align-items: flex-start; padding: 7px 10px; border-radius: 9px; background: var(--surface-2); font-size: 13.5px; cursor: pointer; }
.checks input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--good); flex: none; }
.team { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.team .t { border: 1px solid var(--line); border-radius: 12px; padding: 12px; border-top: 4px solid var(--rc); }
.team .t h4 { margin: 0 0 4px; font-size: 14px; }
.prog { height: 6px; border-radius: 9px; background: var(--surface-2); overflow: hidden; margin: 8px 0 6px; }
.prog i { display: block; height: 100%; background: var(--good); }
textarea.notes { min-height: 70px; resize: vertical; font-size: 13.5px; }
.matrix-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.mx { font-size: 15px !important; font-weight: 700; color: var(--input-ink); }
.drop { border: 2px dashed var(--input-line); border-radius: 12px; padding: 18px; text-align: center; background: var(--input); color: var(--input-ink); }
.drop input { display: none; }

#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 99; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; font-size: 13.5px; box-shadow: var(--shadow); max-width: 340px; animation: pop .2s ease; }
.toast.bad { background: var(--bad); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
dialog { border: 0; border-radius: 16px; padding: 22px; width: min(420px, 92vw); background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, .35); }
dialog::backdrop { background: rgba(8, 14, 26, .55); }
dialog h3 { margin-bottom: 14px; }
dialog .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
.mobile-nav { display: none; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } .cols.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; }
  .login-hero { padding: 28px 22px; gap: 22px; }
  .login-hero h1 { font-size: 28px; max-width: none; }
  .login-hero p, .hero-stats { display: none; }
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .top { padding: 10px 14px; gap: 8px; }
  .top h1 { font-size: 16px; flex-basis: 100%; order: -1; }
  .kpis { padding: 12px 14px 0; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi b { font-size: 17px; }
  .content { padding: 12px 14px 96px; gap: 12px; }
  .cols, .cols.c3, .matrix-grid, .team { grid-template-columns: 1fr; }
  .card-h { padding: 12px 12px 8px; } .card-b { padding: 0 12px 12px; }
  .sheet th:first-child, .sheet td:first-child { min-width: 128px; max-width: 170px; }
  .hbar { grid-template-columns: 104px 1fr 84px; }
  .mobile-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--side); padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); gap: 2px; overflow-x: auto; scrollbar-width: none; }
  .mobile-nav::-webkit-scrollbar { display: none; }
  .mobile-nav a { flex: 1 0 auto; min-width: 68px; text-align: center; color: var(--side-ink); font-size: 11px; font-weight: 600; padding: 7px 8px; border-radius: 10px; text-decoration: none; cursor: pointer; position: relative; }
  .mobile-nav a i { display: block; width: 8px; height: 8px; border-radius: 50%; background: var(--dc, #55657f); margin: 0 auto 5px; }
  .mobile-nav a.on { background: var(--side-active); color: #fff; }
  .mobile-nav a .badge { position: absolute; top: 2px; right: 8px; background: var(--bad); color: #fff; border-radius: 99px; font-size: 10px; padding: 0 5px; }
  #toasts { bottom: 78px; left: 12px; right: 12px; }
  .save-state { min-width: 0; }
}
@media print { .side, .top, .mobile-nav, .kpis { display: none !important; } .shell { display: block; } }
#outM, #themeM { display: none; }
@media (max-width: 900px) { #outM, #themeM { display: inline-block; } }
