:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --border: #e3e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #2563eb;
  --accent-2: #1d4ed8;
  --accent-soft: #e8efff;
  --ok: #059669;
  --ok-soft: #e6f7f0;
  --warn: #d97706;
  --warn-soft: #fdf3e2;
  --bad: #dc2626;
  --bad-soft: #fdecec;
  --violet: #7c3aed;
  --side: #0b1220;
  --side-text: #c7d0e0;
  --side-muted: #6b7a93;
  --side-active: #17223a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .04);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0f1a; --surface: #111827; --surface-2: #172033; --border: #233049; --text: #e6ebf5; --muted: #93a1b8; --faint: #64748b;
    --accent: #4f8bff; --accent-2: #6b9dff; --accent-soft: #15254a; --ok: #34d399; --ok-soft: #0f2c24; --warn: #fbbf24; --warn-soft: #33270d;
    --bad: #f87171; --bad-soft: #3a1717; --side: #070b14; --side-active: #131c30; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0f1a; --surface: #111827; --surface-2: #172033; --border: #233049; --text: #e6ebf5; --muted: #93a1b8; --faint: #64748b;
  --accent: #4f8bff; --accent-2: #6b9dff; --accent-soft: #15254a; --ok: #34d399; --ok-soft: #0f2c24; --warn: #fbbf24; --warn-soft: #33270d;
  --bad: #f87171; --bad-soft: #3a1717; --side: #070b14; --side-active: #131c30; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.5 Inter, system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 16px; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 600; }
h3 { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ---------- Layout */
.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; color: #fff; font-weight: 700; font-size: 16px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #2563eb, #7c3aed); display: grid; place-items: center; font-size: 13px; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--side-muted); }
.nav-group { margin: 14px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--side-muted); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--side-text); font-weight: 500; }
.nav a:hover { background: var(--side-active); text-decoration: none; color: #fff; }
.nav a.active { background: var(--side-active); color: #fff; box-shadow: inset 2px 0 0 var(--accent); }
.nav a.soon { color: var(--side-muted); }
.nav svg { width: 17px; height: 17px; flex: none; opacity: .9; }
.nav .pill { margin-left: auto; font-size: 10.5px; padding: 1px 7px; border-radius: 99px; background: #1e2a44; color: #9fb0cc; font-weight: 600; }
.nav .pill.hot { background: var(--bad); color: #fff; }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid #1a2438; font-size: 12.5px; }
.side-foot .who { color: #fff; font-weight: 600; }
.side-foot button { background: none; border: 0; color: var(--side-muted); padding: 0; cursor: pointer; }
.side-foot button:hover { color: #fff; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 28px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar .crumbs { color: var(--muted); font-size: 13px; }
.menu-btn { display: none; }
.content { padding: 24px 28px 48px; max-width: 1400px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

/* ---------- Componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-b { padding: 16px 18px; }
.grid { display: grid; gap: 16px; }
.g-kpi { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.g-2 { grid-template-columns: 2fr 1fr; }
.g-2e { grid-template-columns: 1fr 1fr; }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.kpi.alert .value { color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--faint); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.dot.warn { background: var(--warn); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); padding: 7px 13px; border-radius: 8px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.b-abierto { background: var(--accent-soft); color: var(--accent); }
.b-en_progreso { background: #efe9fd; color: var(--violet); }
.b-esperando_cliente { background: var(--warn-soft); color: var(--warn); }
.b-resuelto, .b-activo, .b-ok { background: var(--ok-soft); color: var(--ok); }
.b-cerrado, .b-retirado, .b-baja { background: var(--surface-2); color: var(--muted); }
.b-critica, .b-critico, .b-bad, .b-suspendido { background: var(--bad-soft); color: var(--bad); }
.b-alta, .b-error, .b-en_reparacion { background: #fdeee2; color: #ea580c; }
.b-media, .b-aviso, .b-prospecto, .b-almacen { background: var(--warn-soft); color: var(--warn); }
.b-baja-p, .b-info { background: var(--surface-2); color: var(--muted); }
:root[data-theme="dark"] .b-en_progreso, :root[data-theme="dark"] .b-alta { background: #2a1d45; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--surface-2); }
.overdue { color: var(--bad); font-weight: 600; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; padding: 12px 14px; border-bottom: 1px solid var(--border); }
.input, select.input, textarea.input { border: 1px solid var(--border); background: var(--surface); border-radius: 8px; padding: 7px 10px; min-width: 0; }
.input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea.input { width: 100%; min-height: 96px; resize: vertical; }
.search { min-width: 240px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; color: var(--muted); }
.field .input { width: 100%; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; }

.dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.dl dt { color: var(--muted); font-size: 12.5px; }
.dl dd { margin: 0; overflow-wrap: anywhere; }

.empty { padding: 36px; text-align: center; color: var(--muted); }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs a { padding: 8px 12px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- Conversación de ticket */
.thread { display: flex; flex-direction: column; gap: 12px; }
.msg { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--surface); }
.msg.internal { background: var(--warn-soft); border-color: transparent; }
.msg.client { background: var(--accent-soft); border-color: transparent; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: flex; gap: 8px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Gráficas */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: inherit; }
.chart .grid-line { stroke: var(--border); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.bars .bar-row { display: grid; grid-template-columns: 120px 1fr 40px; gap: 10px; align-items: center; font-size: 13px; padding: 4px 0; }
.bars .track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bars .fill { height: 100%; background: var(--accent); border-radius: 99px; }
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut-legend { display: grid; gap: 6px; font-size: 13px; }
.donut-legend span { display: flex; align-items: center; gap: 8px; }
.sys-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.sys-row:last-child { border-bottom: 0; }
.sys-metrics { grid-column: 1 / -1; display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.sys-metrics b { color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.event { display: flex; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.event:last-child { border-bottom: 0; }

/* ---------- Modal y avisos */
.modal-back { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 14px; width: min(680px, 100%); max-height: calc(100vh - 32px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.modal-h { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-b { padding: 18px 20px; }
.modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }
.x { background: none; border: 0; font-size: 20px; cursor: pointer; color: var(--muted); margin-left: auto; line-height: 1; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 10px; font-weight: 500; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); max-width: 360px; }
.toast.err { background: var(--bad); color: #fff; }
.secret { font-family: var(--mono); background: var(--surface-2); border: 1px dashed var(--border); padding: 10px 12px; border-radius: 8px; word-break: break-all; user-select: all; }
pre.code { font-family: var(--mono); font-size: 12px; background: #0b1220; color: #d6e2ff; padding: 14px; border-radius: 10px; overflow-x: auto; margin: 0; }

/* ---------- Login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: radial-gradient(1200px 600px at 20% 10%, #1d3a8a 0%, transparent 60%), radial-gradient(800px 500px at 90% 90%, #5b21b6 0%, transparent 55%), #070b14; color: #e6ebf5; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.login-art h2 { font-size: 34px; line-height: 1.15; font-weight: 700; max-width: 460px; letter-spacing: -.02em; }
.login-art ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 10px; color: #b5c2db; }
.login-art li::before { content: '→ '; color: #6b9dff; }
.login-form { display: grid; place-items: center; padding: 32px 16px; }
.login-form form { width: min(360px, 100%); display: grid; gap: 14px; }
.login-form .err { color: var(--bad); font-size: 13px; min-height: 18px; }

.soon-card { padding: 40px; text-align: center; }
.soon-card .tag { display: inline-block; font-size: 12px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 3px 10px; border-radius: 99px; margin-bottom: 10px; }
.soon-card ul { text-align: left; max-width: 520px; margin: 16px auto 0; color: var(--muted); }

@media (max-width: 1100px) {
  .g-2, .g-3, .g-2e { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .menu-btn { display: inline-flex; }
  .content { padding: 18px 16px 40px; }
  .topbar { padding: 12px 16px; }
  .form { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .search { min-width: 0; flex: 1; }
  .dl { grid-template-columns: 110px 1fr; }
  .g-kpi { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px 14px; }
  .kpi .value { font-size: 21px; }
}
