:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --text: #0f172a;
  --muted: #5b6478;
  --border: #dde2ee;
  --primary: #2563eb;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --crit: #b91c1c;
  --crit-bg: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --surface: #131a2e;
    --surface-2: #1b2440;
    --text: #e6eaf5;
    --muted: #97a1ba;
    --border: #263052;
    --primary: #5b8cff;
    --ok: #4ade80;
    --ok-bg: #12301f;
    --warn: #fbbf24;
    --warn-bg: #3a2d0b;
    --crit: #f87171;
    --crit-bg: #3b1416;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; overflow-wrap: break-word; }
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.15rem; margin-top: 1.6rem; }
h3 { font-size: 1rem; }
a { color: var(--primary); }
code, .mono { font-family: var(--mono); font-size: .88em; overflow-wrap: anywhere; }
.muted { color: var(--muted); }
.error { color: var(--crit); margin: 0; }

/* ---------- encabezado y navegación ---------- */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.5rem; padding: .7rem 20px; background: color-mix(in srgb, var(--surface) 90%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; display: flex; align-items: center; gap: .55rem; white-space: nowrap; }
.logo { width: 24px; height: 24px; border-radius: 7px; background: var(--primary); display: inline-block; flex: none; }
nav { display: flex; gap: .25rem; flex: 1; min-width: 0; overflow-x: auto; }
nav a { display: inline-flex; align-items: center; gap: .45rem; text-decoration: none; color: var(--muted); padding: .4rem .8rem; border-radius: 9px; font-weight: 500; position: relative; }
nav a:hover { background: var(--surface-2); }
nav a.active { background: var(--surface-2); color: var(--text); }
nav a svg { display: none; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
nav .short { display: none; }
.user { display: flex; align-items: center; gap: .6rem; font-size: .85rem; }
.view { max-width: 1200px; margin: 0 auto; padding: 24px 20px 40px; }
.foot { text-align: center; padding: 0 16px 24px; font-size: .8rem; }

/* ---------- tarjetas y medidores ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.kpi .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.9rem; font-weight: 700; margin: .1rem 0; }
.kpi .sub { color: var(--muted); font-size: .85rem; }
.bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: .5rem; }
.bar > span { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar.warn > span { background: var(--warn); }
.bar.crit > span { background: var(--crit); }

.banner { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem .8rem; padding: 14px 16px; border-radius: var(--radius); border: 1px solid var(--border); font-weight: 600; margin-bottom: 14px; }
.banner.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.banner.crit { background: var(--crit-bg); color: var(--crit); border-color: transparent; }

.chip { display: inline-block; padding: .1rem .6rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--warn); }
.chip.crit { background: var(--crit-bg); color: var(--crit); }
.badge { background: var(--crit); color: #fff; border-radius: 99px; font-size: .72rem; line-height: 1.35; padding: 0 .45rem; margin-left: .2rem; }

/* ---------- tablas ---------- */
.tw { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

.btn { font: inherit; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .5rem .9rem; border-radius: 10px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn.small { padding: .3rem .7rem; font-size: .85rem; }
.btn:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 55%, transparent); outline-offset: 2px; }

/* ---------- ingreso ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(420px, 100%); display: grid; gap: 14px; padding: 24px; }
.login-card h1 { font-size: 1.4rem; margin: 0; }
.login-brand { margin-bottom: -.4rem; }
label { display: grid; gap: .3rem; font-weight: 600; font-size: .88rem; }
input { font: inherit; padding: .65rem .75rem; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 100%; }

/* ---------- gráficos, proyectos y detalles ---------- */
.hours { display: flex; align-items: flex-end; gap: 3px; height: 70px; margin-top: .6rem; }
.hours span { flex: 1; background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.hours-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: .72rem; }
.spark { width: 100%; height: 60px; display: block; }
.spark polyline { fill: none; stroke: var(--primary); stroke-width: 2; vector-effect: non-scaling-stroke; }
.diagram { overflow-x: auto; text-align: center; }
.diagram svg { max-width: 100%; height: auto; }
.cols { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); }
.proj { display: grid; gap: .5rem; color: inherit; align-content: start; }
.proj, .proj:hover, .proj a { text-decoration: none; }
.proj:hover { border-color: var(--primary); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
ul.plain { margin: 0; padding-left: 1.1rem; }
.links { display: flex; flex-wrap: wrap; gap: .4rem .6rem; }
.links a { font-size: .85rem; padding: .25rem .7rem; border: 1px solid var(--border); border-radius: 999px; text-decoration: none; }
.links a:hover { border-color: var(--primary); }

/* ---------- teléfono ---------- */
@media (max-width: 900px) {
  body { font-size: 15px; }
  h1 { font-size: 1.35rem; }
  h2 { font-size: 1.05rem; margin-top: 1.3rem; }

  /* Encabezado compacto: marca a la izquierda, "Salir" a la derecha. La navegación pasa abajo, como en una app. */
  /* Sin desenfoque en el encabezado: un filtro así haría que la barra inferior "fija" se mida contra el encabezado. */
  .topbar { padding: .55rem 14px; gap: .5rem; justify-content: space-between; background: var(--surface); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .brand { font-size: 1rem; }
  #userEmail { display: none; }
  .user { margin-left: auto; }
  nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; flex: none; justify-content: space-around; gap: 2px; padding: .3rem .4rem calc(.3rem + var(--safe-bottom)); background: color-mix(in srgb, var(--surface) 94%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); border-top: 1px solid var(--border); }
  nav a { flex: 1 1 0; min-width: 0; min-height: 52px; flex-direction: column; justify-content: center; gap: .12rem; padding: .3rem .1rem; font-size: .68rem; font-weight: 600; text-align: center; }
  nav a svg { display: block; }
  nav a.active { background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); }
  nav .full { display: none; }
  nav .short { display: inline; }
  nav .badge { position: absolute; top: 3px; left: calc(50% + 6px); margin: 0; }

  .view { padding: 14px 12px 24px; }
  .foot { padding-bottom: calc(86px + var(--safe-bottom)); }
  .card { padding: 14px; }

  /* Medidores en 2 columnas compactas; el resto, una columna. */
  .grid:not(.wide) { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .grid.wide, .cols { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .kpi { padding: 12px; }
  .kpi .label { font-size: .7rem; }
  .kpi .value { font-size: 1.5rem; }
  .kpi .sub { font-size: .78rem; }

  .banner { padding: 12px 14px; }
  .btn { min-height: 42px; }
  .btn.small { min-height: 36px; }
  input { font-size: 16px; }
  .login { align-items: start; padding-top: 10vh; }
  .login-card { padding: 20px; }

  .kv { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .kv dt { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; margin-top: .55rem; }
  .kv dt:first-child { margin-top: 0; }
  #flow svg { min-width: 760px; }

  /* Las tablas pasan a tarjetas apiladas: cada fila es un bloque con "etiqueta: valor". */
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr.thead-row { display: none; }
  table.stack tr { padding: .6rem 0; border-bottom: 1px solid var(--border); }
  table.stack tr:last-child { border-bottom: 0; padding-bottom: 0; }
  table.stack tr:first-child, table.stack tr.thead-row + tr { padding-top: 0; }
  table.stack td { border: 0; padding: .15rem 0; display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; text-align: left; flex: none; }
  table.stack td .cv { min-width: 0; }
  table.stack td.long { flex-direction: column; align-items: flex-start; gap: .1rem; text-align: left; }
  table.stack td[data-label=""]::before { display: none; }
  table.stack td[data-label=""] { justify-content: flex-start; padding-top: .35rem; }
  .tw { overflow-x: visible; }
}
@media (max-width: 360px) {
  .brand span:last-child { font-size: .92rem; }
}

/* ---------- visitas ---------- */
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: 11px; margin: .3rem 0 1rem; max-width: 100%; }
.seg button { font: inherit; font-size: .85rem; border: 0; background: transparent; color: var(--muted); padding: .4rem .85rem; border-radius: 8px; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.kpis { grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); margin-bottom: 4px; }
.kpi .value.crit { color: var(--crit); }
.kpi .value.warn { color: var(--warn); }
.tchart { display: flex; align-items: flex-end; gap: 2px; height: 120px; margin-top: .4rem; }
.tc { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; }
.tc span { display: block; width: 100%; }
.s2 { background: var(--primary); }
.s4 { background: var(--warn); }
.s5 { background: var(--crit); }
.legend { font-size: .78rem; color: var(--muted); margin: .6rem 0 0; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin: 0 .3rem 0 .8rem; vertical-align: -1px; }
.legend i:first-child { margin-left: 0; }
.barlist { display: grid; gap: .75rem; }
.bl-top { display: flex; justify-content: space-between; gap: 1rem; font-size: .9rem; }
.bl .bar { height: 6px; margin-top: .3rem; }
.note { background: var(--warn-bg); color: var(--warn); padding: .65rem .85rem; border-radius: 10px; font-size: .85rem; margin: 0 0 14px; }
.chips { line-height: 2.2; }
@media (max-width: 900px) {
  .tchart { height: 96px; }
  nav a { font-size: .64rem; }
  .seg { display: flex; }
  .seg button { flex: 1; padding: .45rem .3rem; }
}
@media (max-width: 900px) {
  /* Listas largas de visitas: cada fila es una tarjeta con los datos en dos columnas (más corta que una columna sola). */
  table.stack.dense tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .4rem .9rem; align-items: start; }
  table.stack.dense td { display: block; width: auto; text-align: left; padding: 0; }
  table.stack.dense td::before { display: block; margin-bottom: .05rem; }
  table.stack.dense td:first-child, table.stack.dense td.long, table.stack.dense td:last-child { grid-column: 1 / -1; }
  table.stack.dense td[data-label=""] { padding: 0; }
  table.stack.dense tr.thead-row { display: none; }
}
a.ip { white-space: nowrap; }

/* ---------- visitas: explicaciones, detalle avanzado y explorador ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .4rem 1rem; align-items: center; margin-bottom: .6rem; }
.toolbar .seg { margin: .2rem 0; }
.hint { color: var(--muted); font-size: .8rem; margin: .45rem 0 0; line-height: 1.4; }
.kpi .hint { margin-top: .35rem; }
.summary { display: grid; gap: .45rem; margin: .3rem 0 0; padding-left: 1.1rem; }
details.help { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .65rem .9rem; margin: 0 0 14px; }
details.help summary { cursor: pointer; font-weight: 600; color: var(--primary); }
details.help[open] summary { margin-bottom: .6rem; }
dl.gloss { display: grid; grid-template-columns: max-content 1fr; gap: .5rem 1rem; }
dl.gloss dt { font-weight: 600; color: var(--text); }
a.drill { text-decoration: none; border-bottom: 1px dotted var(--muted); color: inherit; }
a.drill:hover { color: var(--primary); border-bottom-color: var(--primary); }
a.drill-card { text-decoration: none; color: inherit; display: block; }
a.drill-card:hover { border-color: var(--primary); }
.note.ok { background: var(--ok-bg); color: var(--ok); }
.fchips { display: flex; flex-wrap: wrap; gap: .4rem; }
.fchip { background: var(--surface-2); border: 1px solid var(--border); color: var(--text); text-decoration: none; padding: .25rem .65rem; border-radius: 999px; font-size: .82rem; }
.fchip:hover { border-color: var(--crit); color: var(--crit); }
form.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: .7rem 1rem; align-items: end; margin-bottom: 14px; }
form.filters select { font: inherit; padding: .6rem .7rem; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); width: 100%; }
form.filters label.wide { grid-column: 1 / -1; }
form.filters .actions { grid-column: 1 / -1; display: flex; gap: .6rem; flex-wrap: wrap; }
.btn { text-decoration: none; display: inline-block; }
.facets { grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.facets .chips { line-height: 2; }
.pager { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: 0 0 .8rem; }
td.small, .mono.small { font-size: .75rem; overflow-wrap: anywhere; }
@media (max-width: 900px) {
  dl.gloss { grid-template-columns: minmax(0, 1fr); gap: .1rem; }
  dl.gloss dd { margin: 0 0 .5rem; }
  .toolbar .seg { width: 100%; }
  form.filters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .6rem .7rem; }
  form.filters label { font-size: .8rem; }
}

/* ---------- detalle de recursos (procesador, memoria, disco) ---------- */
a.kpi.tap { display: block; color: inherit; text-decoration: none; transition: transform .12s, border-color .12s; }
a.kpi.tap:hover, a.kpi.tap:focus-visible { border-color: var(--primary); transform: translateY(-1px); }
a.kpi.tap .hint { color: var(--primary); }
.stack-bar { display: flex; height: 18px; border-radius: 99px; overflow: hidden; background: var(--surface-2); margin: .6rem 0 .3rem; }
.stack-bar span { display: block; height: 100%; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: .45rem; }
