/* =====================================================================
   Casa Alpadi I — sistema visual
   Paleta de datos tomada sin cambios de la referencia validada:
   slot 1 azul, slot 2 naranja, slot 3 aqua. Superficies #fcfcfb / #1a1a19.
   ===================================================================== */

:root {
  color-scheme: light;

  /* Superficies e ink */
  --plane:        #f9f9f7;
  --surface:      #fcfcfb;
  --surface-2:    #f3f2ef;
  --ink:          #0b0b0b;
  --ink-2:        #52514e;
  --ink-muted:    #898781;
  --grid:         #e1e0d9;
  --axis:         #c3c2b7;
  --hairline:     rgba(11, 11, 11, .10);
  --shadow:       0 1px 2px rgba(11,11,11,.04), 0 8px 24px -12px rgba(11,11,11,.10);

  /* Series categoricas (orden fijo, nunca ciclado) */
  --s1: #2a78d6;   /* Miguel  / Real        */
  --s2: #eb6834;   /* María M / Presupuesto */
  --s3: #1baf7a;

  /* Estado (siempre acompañado de icono + etiqueta) */
  --good:     #0ca30c;
  --warning:  #fab219;
  --serious:  #ec835a;
  --critical: #d03b3b;
  --good-ink: #006300;

  --r-sm: 8px;
  --r:    12px;
  --r-lg: 18px;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:     #0d0d0d;
    --surface:   #1a1a19;
    --surface-2: #232322;
    --ink:       #ffffff;
    --ink-2:     #c3c2b7;
    --ink-muted: #898781;
    --grid:      #2c2c2a;
    --axis:      #383835;
    --hairline:  rgba(255,255,255,.10);
    --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --good-ink: #0ca30c;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --plane:     #0d0d0d;
  --surface:   #1a1a19;
  --surface-2: #232322;
  --ink:       #ffffff;
  --ink-2:     #c3c2b7;
  --ink-muted: #898781;
  --grid:      #2c2c2a;
  --axis:      #383835;
  --hairline:  rgba(255,255,255,.10);
  --shadow:    0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.6);
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --good-ink: #0ca30c;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .9rem; }
a  { color: var(--s1); }

/* ---------------------------------------------------------------- App shell */
.app { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: color-mix(in srgb, var(--plane) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--hairline);
}
.topbar-in {
  max-width: 1240px; margin: 0 auto; padding: 12px 20px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; flex: none;
  background: var(--s1); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 15px;
}
.brand-sub { font-size: .72rem; color: var(--ink-muted); letter-spacing: .04em; text-transform: uppercase; }

.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: .875rem; font-weight: 500; color: var(--ink-2);
  padding: 7px 13px; border-radius: 999px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--plane); }

.who { display: flex; align-items: center; gap: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  display: grid; place-items: center; color: #fff;
  font-size: .72rem; font-weight: 700;
}

/* ---------------------------------------------------------------- Filter row */
.filters {
  max-width: 1240px; margin: 0 auto; width: 100%;
  padding: 16px 20px 0;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  appearance: none; border: 0; background: transparent; cursor: pointer; font: inherit;
  font-size: .8rem; font-weight: 500; color: var(--ink-2);
  padding: 5px 12px; border-radius: 999px; white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

main { max-width: 1240px; margin: 0 auto; width: 100%; padding: 16px 20px 72px; }

/* ---------------------------------------------------------------- Cards */
.grid { display: grid; gap: 14px; }
.g-4 { grid-template-columns: repeat(4, 1fr); }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-2 { grid-template-columns: repeat(2, 1fr); }
.span-2 { grid-column: span 2; }

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-head {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  margin-bottom: 4px;
}
.card-head .spacer { margin-left: auto; }
.card-sub { font-size: .78rem; color: var(--ink-muted); margin: 2px 0 14px; }

/* ---------------------------------------------------------------- Stat tiles */
.stat-label { font-size: .78rem; color: var(--ink-muted); font-weight: 500; }
.stat-value {
  font-size: 1.85rem; font-weight: 650; letter-spacing: -0.02em;
  margin: 6px 0 2px; line-height: 1.1;
}
.stat-foot { font-size: .78rem; color: var(--ink-2); display: flex; align-items: center; gap: 5px; }
.delta { font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.delta.up   { color: var(--critical); }
.delta.down { color: var(--good-ink); }
.delta.flat { color: var(--ink-muted); }

/* ---------------------------------------------------------------- Meter */
.meter { height: 7px; border-radius: 999px; background: var(--surface-2); overflow: hidden; margin-top: 12px; }
.meter > i { display: block; height: 100%; border-radius: 999px; background: var(--s1); }
.meter.warn  > i { background: var(--warning); }
.meter.over  > i { background: var(--critical); }

/* ---------------------------------------------------------------- Tables */
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead th {
  text-align: left; font-weight: 600; font-size: .74rem; letter-spacing: .04em;
  text-transform: uppercase; color: var(--ink-muted);
  padding: 0 10px 8px; border-bottom: 1px solid var(--grid); white-space: nowrap;
}
tbody td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }

/* ---------------------------------------------------------------- Chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: .74rem; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.chip.good     { background: color-mix(in srgb, var(--good) 14%, transparent);     color: var(--good-ink); }
.chip.warning  { background: color-mix(in srgb, var(--warning) 20%, transparent);  color: #7a5200; }
.chip.critical { background: color-mix(in srgb, var(--critical) 14%, transparent); color: var(--critical); }
:root[data-theme="dark"] .chip.warning,
:root:where(:not([data-theme="light"])) .chip.warning { color: var(--warning); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; display: inline-block; }

/* ---------------------------------------------------------------- Controls */
button.btn, .btn {
  appearance: none; cursor: pointer; font: inherit; font-size: .85rem; font-weight: 550;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--hairline);
  background: var(--surface); color: var(--ink);
  display: inline-flex; align-items: center; gap: 6px; text-decoration: none;
}
button.btn:hover, .btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--s1); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn.sm { padding: 5px 10px; font-size: .78rem; border-radius: 8px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea {
  font: inherit; font-size: .875rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 10px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--s1) 45%, transparent); outline-offset: 1px;
  border-color: var(--s1);
}
label.field { display: block; }
label.field > span { display: block; font-size: .76rem; color: var(--ink-muted); margin-bottom: 5px; font-weight: 500; }

input[type="checkbox"] {
  width: 19px; height: 19px; padding: 0; accent-color: var(--s1); cursor: pointer;
  flex: none;
}

/* ---------------------------------------------------------------- Charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .axisline { stroke: var(--axis); stroke-width: 1; shape-rendering: crispEdges; }
.chart text { fill: var(--ink-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart text.lbl { fill: var(--ink-2); font-size: 11.5px; font-variant-numeric: normal; }
.chart .hit { fill: transparent; cursor: crosshair; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .78rem; color: var(--ink-2); margin-bottom: 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.tip {
  position: absolute; pointer-events: none; z-index: 20; min-width: 128px;
  background: var(--surface); border: 1px solid var(--hairline);
  border-radius: 10px; box-shadow: var(--shadow); padding: 9px 11px;
  font-size: .78rem; opacity: 0; transition: opacity .1s;
}
.tip[data-on="1"] { opacity: 1; }
.tip b { display: block; font-size: .74rem; color: var(--ink-muted); font-weight: 600; margin-bottom: 5px; }
.tip .row { display: flex; align-items: center; gap: 7px; justify-content: space-between; }
.tip .row em { font-style: normal; color: var(--ink-2); }
.tip .row strong { font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- Modal */
dialog {
  border: 1px solid var(--hairline); border-radius: var(--r-lg); padding: 0;
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow);
  width: min(560px, calc(100vw - 32px)); max-height: 88dvh;
}
dialog::backdrop { background: rgba(11,11,11,.42); backdrop-filter: blur(2px); }
.modal-head { padding: 18px 20px 0; display: flex; align-items: center; gap: 10px; }
.modal-body { padding: 14px 20px; overflow-y: auto; max-height: 62dvh; }
.modal-foot { padding: 12px 20px 18px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--grid); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* ---------------------------------------------------------------- Misc */
.empty { text-align: center; padding: 40px 20px; color: var(--ink-muted); font-size: .875rem; }
.empty .big { font-size: 2rem; display: block; margin-bottom: 8px; }
.muted { color: var(--ink-muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 14px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--ink); color: var(--plane); padding: 10px 18px; border-radius: 999px;
  font-size: .84rem; font-weight: 500; z-index: 90; transition: transform .22s, opacity .22s; opacity: 0;
  box-shadow: var(--shadow);
}
.toast[data-on="1"] { transform: translateX(-50%) translateY(0); opacity: 1; }

/* ---------------------------------------------------------------- Auth */
.auth-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: min(400px, 100%); }

/* ---------------------------------------------------------------- Responsive */
@media (max-width: 1040px) { .g-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 860px) {
  .g-3, .g-2 { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
}
@media (max-width: 560px) {
  .g-4 { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 15px 16px; }
  .stat-value { font-size: 1.4rem; }
  .form-grid { grid-template-columns: 1fr; }
  main { padding: 14px 14px 64px; }
  .filters { padding: 14px 14px 0; }
  .topbar-in { padding: 10px 14px; }
  .t-wrap { margin: 0 -16px; padding: 0 16px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
