:root {
  color-scheme: light;
  --bg: #f2f1ee;
  --surface: #fbfaf8;
  --surface-2: #f4f2ee;
  --line: #e2dfd9;
  --text: #1d1b1a;
  --text-2: #5b5753;
  --muted: #8a857f;
  --brand: #a4505e;
  --brand-ink: #ffffff;
  --series: #a4505e;
  --good: #1f7a3a; --good-bg: #e3f2e7;
  --warn: #8a5a00; --warn-bg: #fbefd6;
  --bad: #b3261e;  --bad-bg: #fbe4e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 4px 16px rgba(0,0,0,.04);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121110; --surface: #1c1a19; --surface-2: #242120; --line: #34302d;
    --text: #f4f2ef; --text-2: #c3bdb6; --muted: #8f8880;
    --brand: #c86b7a; --brand-ink: #1c1a19; --series: #c86b7a;
    --good: #6fd08c; --good-bg: #173322; --warn: #f2c25c; --warn-bg: #3a2c0c; --bad: #ff8a80; --bad-bg: #3d1614;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121110; --surface: #1c1a19; --surface-2: #242120; --line: #34302d;
  --text: #f4f2ef; --text-2: #c3bdb6; --muted: #8f8880;
  --brand: #c86b7a; --brand-ink: #1c1a19; --series: #c86b7a;
  --good: #6fd08c; --good-bg: #173322; --warn: #f2c25c; --warn-bg: #3a2c0c; --bad: #ff8a80; --bad-bg: #3d1614;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
body { min-height: 100vh; }
a { color: var(--brand); }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 14px; }
.brand { background: #fbfaf8; border-radius: 12px; padding: 8px; text-align: center; }
.brand img { width: 100%; max-width: 180px; height: auto; display: block; margin: 0 auto; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { text-decoration: none; color: var(--text-2); padding: 9px 12px; border-radius: 10px; font-weight: 500; }
nav a:hover { background: var(--surface-2); }
nav a.on { background: var(--brand); color: var(--brand-ink); }
.who { margin-top: auto; font-size: 12px; color: var(--muted); word-break: break-all; }

main { padding: 18px 28px 48px; min-width: 0; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.sync { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; background: var(--surface-2); }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.banner { background: var(--warn-bg); color: var(--warn); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-weight: 500; }

h1 { font-size: 24px; margin: 4px 0 14px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 10px; }
.grid { display: grid; gap: 14px; }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card, .grid + .card, .card + .grid, .grid + .grid { margin-top: 14px; }
.grid > .card { margin-top: 0; }
.stat .label { color: var(--text-2); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .value.small-value { font-size: 18px; padding-top: 6px; }
.stat .sub { color: var(--muted); font-size: 12px; }

.status-line { display: flex; flex-wrap: wrap; gap: 6px 18px; color: var(--text-2); }
.status-line b { color: var(--text); font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td:first-child { white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); white-space: nowrap; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 10px; margin-bottom: 8px; }
.alert.rojo { background: var(--bad-bg); color: var(--bad); }
.alert.amarillo { background: var(--warn-bg); color: var(--warn); }

.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr auto; gap: 10px; align-items: center; }
.bar-row .name { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 14px; }
.bar-fill { height: 14px; background: var(--series); border-radius: 0 4px 4px 0; }
.chart { width: 100%; display: block; overflow: visible; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 17px; }
.chart .col { fill: var(--series); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .col, .chart .col.hover { opacity: .8; }
.tip { position: fixed; z-index: 30; pointer-events: none; background: var(--text); color: var(--bg); padding: 6px 10px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.seg { max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg button { white-space: nowrap; border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); font-weight: 600; }
input[type=text], input[type=search], input[type=date], input[type=password], select {
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
button.primary { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 10px; padding: 9px 16px; font-weight: 600; cursor: pointer; }
button.ghost { background: transparent; border: 1px solid var(--line); border-radius: 10px; padding: 6px 12px; cursor: pointer; color: var(--text-2); }
button:disabled { opacity: .45; cursor: not-allowed; }

.drawer { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 20; display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer-card { background: var(--surface); width: min(520px, 100%); height: 100%; overflow-y: auto; padding: 22px; position: relative; }
.drawer .close { position: absolute; right: 14px; top: 14px; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: start; }
.note { font-size: 12px; color: var(--muted); }
.msg { padding: 8px 12px; border-radius: 10px; font-size: 14px; }
.msg.ok { background: var(--good-bg); color: var(--good); }
.msg.err { background: var(--bad-bg); color: var(--bad); }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
details summary { cursor: pointer; color: var(--text-2); font-size: 13px; margin-top: 8px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

@media (max-width: 900px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g2 { grid-template-columns: 1fr; } }
@media (max-width: 700px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 16px; flex-direction: row; align-items: center; gap: 10px; }
  .brand { width: 72px; flex: none; padding: 4px; }
  nav { flex-direction: row; overflow-x: auto; flex: 1; min-width: 0; scrollbar-width: none; }
  .chart .axis { font-size: 30px; }
  .stat .value.small-value { font-size: 16px; }
  nav a { white-space: nowrap; padding: 7px 10px; }
  .who { display: none; }
  main { padding: 14px 16px 40px; }
  .stat .value { font-size: 22px; }
  .bar-row { grid-template-columns: minmax(70px, 110px) 1fr auto; }
  .form .row { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--bg); }
.login { width: 100%; max-width: 360px; display: grid; gap: 14px; }
.login img { width: 160px; margin: 0 auto; }
.login h1 { text-align: center; font-size: 20px; margin: 0; }
.login input { font-size: 16px; }
.login button { width: 100%; padding: 12px; font-size: 16px; }
