/* ===========================================================================
   ISP Suite Fibraya — sistema visual
   Tema claro por defecto, oscuro por preferencia del sistema o por el selector.
   Los pasos de color de las series salen de la paleta validada del skill de
   dataviz (checks de banda de luminosidad, croma, separacion CVD y contraste).
   =========================================================================== */

:root {
  color-scheme: light;

  /* superficies */
  --surface-0: #f4f4f1;   /* fondo de pagina */
  --surface-1: #fcfcfb;   /* tarjetas y superficie de graficos */
  --surface-2: #efeeea;   /* zonas hundidas, hover de fila */
  --line:      #e0dfd9;
  --line-soft: #eceae4;

  /* tinta */
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #7c7a73;

  /* acento de interfaz */
  --accent:      #2a78d6;
  --accent-ink:  #ffffff;
  --accent-soft: #e8f0fc;

  /* estado (reservado: nunca se usa como color de serie) */
  --ok:       #157a3c;
  --ok-bg:    #e3f3e9;
  --warn:     #8a5a00;
  --warn-bg:  #fbf0d8;
  --danger:   #b3261e;
  --danger-bg:#fbe4e2;

  /* series de datos */
  --series-1: #2a78d6;  /* bajada */
  --series-2: #eb6834;  /* subida */

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])) {
    color-scheme: dark;
    --surface-0: #121211;
    --surface-1: #1a1a19;
    --surface-2: #232322;
    --line:      #33332f;
    --line-soft: #2a2a28;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #97968c;
    --accent:      #3987e5;
    --accent-ink:  #ffffff;
    --accent-soft: #17293f;
    --ok:       #56c37c;
    --ok-bg:    #14291c;
    --warn:     #e0b33d;
    --warn-bg:  #2e2410;
    --danger:   #ff7b72;
    --danger-bg:#331917;
    --series-1: #3987e5;
    --series-2: #d95926;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --surface-0: #121211;
  --surface-1: #1a1a19;
  --surface-2: #232322;
  --line:      #33332f;
  --line-soft: #2a2a28;
  --text-primary:   #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted:     #97968c;
  --accent:      #3987e5;
  --accent-ink:  #ffffff;
  --accent-soft: #17293f;
  --ok:       #56c37c;
  --ok-bg:    #14291c;
  --warn:     #e0b33d;
  --warn-bg:  #2e2410;
  --danger:   #ff7b72;
  --danger-bg:#331917;
  --series-1: #3987e5;
  --series-2: #d95926;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 1px 3px rgba(0, 0, 0, .3);
}

/* --------------------------------------------------------------- base */

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--surface-0);
  color: var(--text-primary);
  font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.spacer { flex: 1; }
.error { color: var(--danger); min-height: 20px; margin: 10px 0 0; font-size: 14px; }
.num { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------ controles */

button, .btn {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  transition: filter .15s, background .15s, border-color .15s;
}

button:hover, .btn:hover { filter: brightness(1.07); text-decoration: none; }
button:active { filter: brightness(.95); }

button.ghost, .btn.ghost {
  background: var(--surface-1);
  color: var(--text-primary);
  border-color: var(--line);
}
button.ghost:hover, .btn.ghost:hover { background: var(--surface-2); filter: none; }

button.icon {
  padding: 8px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  background: var(--surface-1);
  color: var(--text-secondary);
  border-color: var(--line);
}

label {
  display: block;
  margin: 16px 0 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

input, select {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
}

input::placeholder { color: var(--text-muted); }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------------------------------------------------------- login */

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 390px; }
.login-card h1 { margin: 0 0 2px; font-size: 25px; letter-spacing: -.02em; }
.login-card > p { margin: 0 0 8px; }
.login-card button[type='submit'] { width: 100%; margin-top: 22px; }

/* --------------------------------------------------------------- layout */

header.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}
.brand .dot {
  width: 10px; height: 10px; border-radius: 3px;
  background: var(--accent);
}
.brand span { color: var(--text-muted); font-weight: 500; }

.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

main { padding: 24px; max-width: 1360px; margin: 0 auto; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -.02em; }
.page-head p { margin: 3px 0 0; color: var(--text-muted); font-size: 14px; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 20px; }

.card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.01em; }
.card-head p { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }

/* ----------------------------------------------------------- stat tiles */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow);
}

.stat .l {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 4px;
}
.stat .n {
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -.025em;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.stat .s { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.stat.ok .n { color: var(--ok); }
.stat.warn .n { color: var(--warn); }
.stat.danger .n { color: var(--danger); }

.stats.inline { margin: 0; }

/* --------------------------------------------------------------- tabla */

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th {
  text-align: left;
  padding: 9px 12px;
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}

tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type='search'] { flex: 1; min-width: 220px; max-width: 400px; }
.toolbar select { width: auto; min-width: 165px; }

.pager { display: flex; align-items: center; gap: 12px; margin-top: 16px; }

/* --------------------------------------------------------------- badges */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-ok     { background: var(--ok-bg);     color: var(--ok); }
.badge-warn   { background: var(--warn-bg);   color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted  { background: var(--surface-2); color: var(--text-secondary); }
.badge-plain::before { display: none; }

/* -------------------------------------------------------------- graficos */

.chart-figure { margin: 0; }

.chart-figure figcaption {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.chart-figure figcaption .title { font-weight: 700; font-size: 14.5px; }
.chart-figure figcaption .sub { font-size: 13px; color: var(--text-muted); }

.legend { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.legend .item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-secondary);
}
.legend .key { width: 11px; height: 11px; border-radius: 3px; }

.chart { width: 100%; display: block; overflow: visible; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .value-label { fill: var(--text-secondary); font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .hit:hover + .band, .chart .band.active { fill: var(--surface-2); }
.chart .band { fill: transparent; pointer-events: none; }

.tooltip {
  position: fixed;
  z-index: 60;
  pointer-events: none;
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .16);
  padding: 10px 12px;
  font-size: 13px;
  min-width: 160px;
}
.tooltip .t-title { font-weight: 700; margin-bottom: 6px; }
.tooltip .t-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tooltip .t-row .lbl { display: inline-flex; align-items: center; gap: 7px; color: var(--text-secondary); }
.tooltip .t-row .key { width: 9px; height: 9px; border-radius: 2px; }
.tooltip .t-row .val { font-variant-numeric: tabular-nums; font-weight: 600; }

.empty {
  padding: 28px 20px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 14px;
}

/* ---------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 16, .55);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
}

.modal-card {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 760px;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}

.modal-card h2 { margin: 0 0 4px; font-size: 19px; letter-spacing: -.02em; }

/* --------------------------------------------------------------- ficha */

.kv { display: grid; grid-template-columns: minmax(140px, auto) 1fr; gap: 9px 18px; }
.kv .k { color: var(--text-muted); font-size: 13px; }
.kv .v { font-size: 14px; }

.section-title {
  margin: 26px 0 10px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

@media (max-width: 860px) {
  .grid-2 { grid-template-columns: 1fr; }
  main { padding: 16px; }
  header.topbar { padding: 12px 16px; }
}

/* Impresion y modo de colores forzados: el texto y la tabla sostienen todo. */
@media (forced-colors: active) {
  .badge, .stat, .card { border: 1px solid CanvasText; }
}
