:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #2a78d6;           /* Enviadas */
  --s2: #eb6834;           /* Borradores */
  --s3: #1baf7a;           /* Total */
  --seq: #2a78d6;
  --good: #0ca30c;
  --good-text: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422;
    --text: #ffffff; --text-2: #c3c2b7; --muted: #9a988f;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --seq: #3987e5;
    --good-text: #0ca30c; --accent: #3987e5;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242422;
  --text: #ffffff; --text-2: #c3c2b7; --muted: #9a988f;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255,255,255,0.10);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --seq: #3987e5;
  --good-text: #0ca30c; --accent: #3987e5;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; }
h2 { font-size: 15px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.eyebrow { margin: 0 0 2px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: transparent; color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Logo: versión con texto negro en tema claro y texto blanco en tema oscuro */
.logo { display: inline-flex; flex: none; }
.logo img { height: 40px; width: auto; display: block; }
.logo-dark { display: none !important; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .logo-light { display: none !important; }
  :root:not([data-theme="light"]) .logo-dark { display: block !important; }
}
:root[data-theme="dark"] .logo-light { display: none !important; }
:root[data-theme="dark"] .logo-dark { display: block !important; }
.topbar-meta { margin: 2px 0 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 520px; }
.topbar-meta:empty { display: none; }
.topbar-brand { display: flex; align-items: center; gap: 18px; min-width: 0; }
.topbar-brand .topbar-title { padding-left: 18px; border-left: 1px solid var(--border); min-width: 0; }
.login-card .logo { margin-bottom: 24px; }
.login-card .logo img { height: 48px; }

/* Top bar */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 24px;
  padding: 20px max(32px, calc((100% - 1320px) / 2 + 32px)); border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.topbar-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

main { max-width: 1320px; margin: 0 auto; padding: 24px 32px 64px; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.kpi-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); font-weight: 500; }
.kpi-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.kpi-value { font-size: 36px; font-weight: 650; line-height: 1.1; margin: 8px 0 4px; letter-spacing: -0.02em; }
.kpi-value .unit { font-size: 18px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.kpi-sub { font-size: 13px; color: var(--muted); }
.delta-up { color: var(--good-text); font-weight: 600; }

/* Alerts */
.alerts { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; margin: 16px 0 24px; }
.alerts:empty { display: none; }
.alert {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--alert, var(--warning));
  cursor: pointer; text-align: left; font: inherit; color: inherit;
}
.alert:hover { background: var(--surface-2); }
.alert-icon { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; font-weight: 700; color: #0b0b0b; background: var(--alert, var(--warning)); }
.alert strong { display: block; font-size: 14px; }
.alert span { font-size: 13px; color: var(--text-2); }

/* Cards / grid */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.span-2 { grid-column: span 2; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px 20px; box-shadow: var(--shadow); min-width: 0;
}
.card-head { margin-bottom: 14px; }
.card-head p { margin: 2px 0 0; }
.chart { position: relative; width: 100%; min-height: 220px; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart-empty { display: grid; place-items: center; min-height: 200px; color: var(--muted); font-size: 14px; text-align: center; padding: 0 24px; border: 1px dashed var(--grid); border-radius: 8px; }

/* SVG chart chrome */
.gridline { stroke: var(--grid); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.tick { fill: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.value-label { fill: var(--text-2); font-size: 12px; font-weight: 600; font-variant-numeric: tabular-nums; }
.crosshair { stroke: var(--axis); stroke-width: 1; }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 10px; font-size: 13px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend i.line { height: 3px; border-radius: 2px; width: 14px; }

/* Split bar */
.split { display: flex; height: 28px; gap: 2px; border-radius: 6px; overflow: hidden; background: var(--surface-2); }
.split > div { min-width: 2px; }
.split-labels { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; font-size: 14px; color: var(--text-2); flex-wrap: wrap; }
.split-labels b { color: var(--text); font-size: 18px; margin-right: 4px; }
.split-labels span { display: inline-flex; align-items: baseline; gap: 6px; }
.split-labels i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; align-self: center; }

/* Horizontal bars (HTML) */
.hbars { display: grid; gap: 10px; }
.hbar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr 48px; gap: 10px; align-items: center; font-size: 13px; }
.hbar-label { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { height: 12px; border-radius: 0 4px 4px 0; background: var(--surface-2); position: relative; }
.hbar-fill { height: 100%; border-radius: 0 4px 4px 0; background: var(--seq); }
.hbar-value { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.hbar:hover .hbar-label { color: var(--text); }

/* Diffusion */
.diff-row { margin-bottom: 16px; }
.diff-row p { margin: 0 0 6px; font-size: 13px; color: var(--text-2); }

/* Table */
.table-card { margin-top: 16px; }
.table-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input[type=search] {
  height: 36px; min-width: 280px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--page); color: var(--text); font: inherit; font-size: 14px;
}
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { height: 34px; padding: 0 12px; border: 0; background: transparent; color: var(--text-2); font: inherit; font-size: 13px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--surface-2); color: var(--text); font-weight: 600; }
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; cursor: pointer; user-select: none; }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
td { font-variant-numeric: tabular-nums; }
td.title { max-width: 280px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; }
.badge i { width: 8px; height: 8px; border-radius: 50%; }
.progress { display: inline-flex; align-items: center; gap: 8px; }
.progress-track { width: 80px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; background: var(--seq); border-radius: 3px; }
.warn-ico { color: var(--critical); font-weight: 700; margin-left: 4px; }

/* Detail dialog */
.detail {
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 24px 28px; border: 1px solid var(--border);
  border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.detail::backdrop { background: rgba(0,0,0,.45); }
.detail .close { position: absolute; top: 14px; right: 14px; width: 36px; padding: 0; }
.detail h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 22px 0 8px; display: flex; justify-content: space-between; }
.detail dl { display: grid; grid-template-columns: minmax(140px, 34%) 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.detail dt { color: var(--text-2); }
.detail dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.detail dd.missing { color: var(--critical); }
.detail-head h2 { font-size: 20px; padding-right: 40px; }
.detail-head p { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 100; pointer-events: none; padding: 8px 10px; border-radius: 8px;
  background: var(--text); color: var(--page); font-size: 13px; line-height: 1.4; max-width: 260px;
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.tooltip b { font-weight: 600; }
.tooltip .row { display: flex; align-items: center; gap: 6px; }
.tooltip i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* Toast / drop / empty */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 50; padding: 12px 18px; border-radius: 10px; background: var(--text); color: var(--page); font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); max-width: calc(100vw - 32px); }
.toast.error { background: var(--critical); color: #fff; }
.drop-overlay { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(42,120,214,.12); border: 3px dashed var(--accent); font-size: 20px; font-weight: 600; color: var(--accent); }
.empty { text-align: center; padding: 80px 16px; max-width: 520px; margin: 0 auto; }
.empty p { color: var(--text-2); }

/* Login */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; box-shadow: var(--shadow); }
.login-card h1 { margin-bottom: 24px; }
.login-card label { display: block; font-size: 13px; font-weight: 500; color: var(--text-2); margin-bottom: 6px; }
.login-card input { width: 100%; height: 42px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--page); color: var(--text); font: inherit; margin-bottom: 16px; }
.login-card .btn { width: 100%; height: 42px; }
.form-ok { color: var(--good-text); font-size: 14px; margin: -6px 0 14px; }
.login-card .back { display: block; text-align: center; margin-top: 16px; font-size: 14px; }
.form-error { color: var(--critical); font-size: 14px; margin: -6px 0 14px; }

@media (max-width: 860px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .topbar { padding: 14px 16px; position: static; }
  .logo img { height: 32px; }
  .topbar-brand { gap: 12px; }
  .topbar-brand .topbar-title { padding-left: 12px; }
  .topbar-brand h1 { font-size: 18px; }
  main { padding: 16px 16px 48px; }
  .filters input[type=search] { min-width: 0; width: 100%; }
  .filters { width: 100%; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 28px; }
  .detail dl { grid-template-columns: 1fr; gap: 2px; }
  .detail dd { margin-bottom: 8px; }
}
