:root {
  --bg: #f5f5f7; --card: #fff; --ink: #1d1d1f; --muted: #6e6e73; --line: #e5e5ea; --accent: #0071e3; --accent-ink: #fff;
  --ok: #1f8f3d; --ok-bg: #e4f5e8; --warn: #a15c00; --warn-bg: #fff1d6; --bad: #c4231b; --bad-bg: #fde4e2; --idle: #6e6e73; --idle-bg: #ececf0;
  --radius: 20px; --rail: 56px; --bar: 56px; --gutter: 14px;
  /* Un solo modelo de inset: todo el CSS usa estas variables. app.js puede simularlas con ?inset=N (pruebas). */
  --sat: env(safe-area-inset-top, 0px); --sar: env(safe-area-inset-right, 0px); --sab: env(safe-area-inset-bottom, 0px); --sal: env(safe-area-inset-left, 0px); --shadow: 0 1px 2px rgba(0,0,0,.04), 0 6px 24px rgba(0,0,0,.05);
  color-scheme: light;
}
html[data-theme="oscuro"] {
  --bg: #000; --card: #1c1c1e; --ink: #f5f5f7; --muted: #a1a1a6; --line: #2c2c2e; --accent: #2997ff; --accent-ink: #00122b;
  --ok: #52d273; --ok-bg: #12301a; --warn: #ffb340; --warn-bg: #36280a; --bad: #ff6961; --bad-bg: #3b1513; --idle: #a1a1a6; --idle-bg: #2c2c2e;
  --shadow: none; color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #000; --card: #1c1c1e; --ink: #f5f5f7; --muted: #a1a1a6; --line: #2c2c2e; --accent: #2997ff; --accent-ink: #00122b;
    --ok: #52d273; --ok-bg: #12301a; --warn: #ffb340; --warn-bg: #36280a; --bad: #ff6961; --bad-bg: #3b1513; --idle: #a1a1a6; --idle-bg: #2c2c2e;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; hyphens: none; -webkit-hyphens: none; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif; overflow-x: hidden; }
a { color: inherit; text-decoration: none; }
h1, h2, p, dl, dd { margin: 0; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.muted { color: var(--muted); } .small { font-size: 13px; } .strong { color: var(--ink) !important; font-weight: 500; }
.inline { display: inline; margin: 0; }
.bad { color: var(--bad); } .warn { color: var(--warn); }

/* Navegación. Por defecto (Safari, ≤951 px): barra inferior compacta, sin rail junto a la barra lateral de Safari.
   Standalone / pantalla de inicio (display-mode o html[data-nav=standalone]): rail estrecho a la derecha. ≥952 px: rail a la izquierda. */
.rail { position: fixed; z-index: 10; left: 0; right: 0; bottom: 0; height: calc(var(--bar) + var(--sab)); padding: 0 max(4px, var(--sar)) var(--sab) max(4px, var(--sal));
  display: flex; flex-direction: row; align-items: stretch; justify-content: space-around; gap: 0; background: var(--card); border-top: 1px solid var(--line); }
.rail__brand { display: none; width: 34px; height: 34px; border-radius: 10px; background: var(--ink); color: var(--bg); place-items: center; font-weight: 700; margin: 2px 0 8px; flex: none; }
.rail__item { flex: 1 1 0; min-width: 44px; min-height: 48px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: var(--muted); font-size: 10px; font-weight: 500; letter-spacing: .01em; }
.rail__item.is-on { color: var(--accent); }
.rail__label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail__ico { position: relative; display: block; line-height: 0; }
.ico { width: 24px; height: 24px; }
.badge { position: absolute; top: -6px; right: -10px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; font-weight: 600; }
.badge--warn { background: var(--warn); }
.shell { padding: 0 max(16px, var(--sar)) calc(var(--bar) + var(--sab) + 28px) max(16px, var(--sal)); max-width: 100%; }
.top { display: flex; align-items: center; align-content: center; justify-content: space-between; gap: 8px; min-height: 56px; padding-top: var(--sat); flex-wrap: wrap; }
.top__app { font-weight: 600; color: var(--muted); font-size: 14px; }
.top__tools { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.back { display: inline-flex; align-items: center; min-height: 44px; padding-right: 12px; color: var(--accent); font-weight: 500; }
.page { max-width: 1040px; display: flex; flex-direction: column; gap: 14px; }
.title { font-size: 34px; line-height: 1.1; letter-spacing: -.02em; font-weight: 700; margin: 4px 0 6px; overflow-wrap: normal; word-break: normal; hyphens: none; }
h2 { font-size: 19px; letter-spacing: -.01em; font-weight: 650; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sect { margin: 10px 0 -4px; font-size: 22px; }
.lead { font-size: 22px; font-weight: 650; }

.pill { display: inline-flex; align-items: center; min-height: 28px; padding: 0 12px; border-radius: 14px; font-size: 12px; font-weight: 600; background: var(--idle-bg); }
.pill--demo { background: var(--warn-bg); color: var(--warn); }
.iconbtn { min-width: 44px; min-height: 44px; border: 0; border-radius: 22px; background: var(--card); color: var(--ink); display: inline-grid; place-items: center; cursor: pointer; box-shadow: var(--shadow); }
.banner { padding: 12px 16px; border-radius: 14px; background: var(--ok-bg); color: var(--ok); font-size: 14px; }
.banner--warn { background: var(--warn-bg); color: var(--warn); }
.card { background: var(--card); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.card--list { padding: 6px 6px; gap: 0; }
.pad { padding: 14px; }
.grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.count { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 12px; background: var(--idle-bg); color: var(--muted); font-size: 13px; font-weight: 600; }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.statswrap { container-type: inline-size; }
.stat { background: var(--card); border-radius: var(--radius); padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; min-height: 92px; min-width: 0; box-shadow: var(--shadow); white-space: nowrap; }
.stat b { font-size: 38px; line-height: 1; letter-spacing: -.03em; }
.stat span { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
/* Contenido estrecho (p. ej. con safe-area lateral grande): una tarjeta por fila, número + etiqueta en una sola línea */
@container (max-width: 340px) {
  .stats { grid-template-columns: 1fr; gap: 8px; }
  .stat { flex-direction: row; align-items: baseline; gap: 10px; min-height: 52px; padding: 10px 14px; }
  .stat b { font-size: 28px; }
  .stat span { font-size: 15px; }
}
.stat--ok b { color: var(--ok); } .stat--bad b { color: var(--bad); } .stat--idle b { color: var(--idle); }

.row { display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 12px; border-radius: 14px; min-width: 0; }
a.row:active, a.row:hover { background: var(--bg); }
.row--static:hover { background: none; }
.row--stack { flex-wrap: wrap; }
.row__main { display: flex; flex-direction: column; min-width: 0; flex: 1 1 0; overflow-wrap: normal; word-break: normal; hyphens: none; }
/* Si el chip dejaría el nombre sin ancho útil, el chip baja a su propia línea (bajo el nombre) en vez de robarle columna */
.row:has(> .chips) { flex-wrap: wrap; }
.row:has(> .chips) .row__main { flex-basis: 9rem; }
.row:has(> .chips) .chips { margin-left: auto; }
.row--stack .row__main { flex-basis: 140px; }
.row__main b { font-weight: 600; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; hyphens: none; -webkit-hyphens: none; line-height: 1.3; }
.row .chips { flex: none; flex-wrap: nowrap; justify-content: flex-end; }
.row small, small { color: var(--muted); font-size: 13px; }
.row + .row { border-top: 1px solid var(--line); border-radius: 0; }
.right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.amount--big { font-size: 22px; letter-spacing: -.02em; }
.more { display: inline-flex; align-items: center; min-height: 44px; color: var(--accent); font-weight: 500; }
.move { font-size: 13px; font-weight: 600; color: var(--warn); white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--idle); }
.dot--ok { background: var(--ok); } .dot--bad { background: var(--bad); } .dot--warn { background: var(--warn); }
.tag { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 10px; background: var(--idle-bg); color: var(--muted); flex: none; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 12px; background: var(--idle-bg); color: var(--idle); width: fit-content; }
.chip--ok { background: var(--ok-bg); color: var(--ok); } .chip--warn { background: var(--warn-bg); color: var(--warn); } .chip--bad { background: var(--bad-bg); color: var(--bad); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--idle-bg); display: grid; place-items: center; font-weight: 650; flex: none; }

.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; }
.facts dt { font-size: 12px; color: var(--muted); }
.facts dd { font-weight: 550; overflow-wrap: anywhere; }
.facts--tight { gap: 10px 16px; }
.web__head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.web__domain { font-size: 18px; overflow-wrap: anywhere; flex: 1 1 160px; }
.errline { background: var(--bad-bg); color: var(--bad); border-radius: 12px; padding: 8px 12px; font-size: 14px; overflow-wrap: anywhere; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 18px; border-radius: 22px; border: 0; background: var(--idle-bg); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; }
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.input { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; background: var(--bg); color: var(--ink); font: inherit; font-size: 16px; }
.input--auto { width: auto; }
textarea.input { resize: vertical; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form { display: flex; flex-direction: column; gap: 12px; }
.form--inline { flex-direction: row; flex-wrap: wrap; }
.form--inline .input { flex: 1 1 160px; width: auto; }
.searchbar .input { background: var(--card); box-shadow: var(--shadow); border-radius: 22px; }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg__item { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 14px; border-radius: 22px; background: var(--card); font-weight: 600; font-size: 14px; }
.seg__item.is-on { background: var(--accent); color: var(--accent-ink); }
.seg__item.is-on .count { background: rgba(255,255,255,.25); color: inherit; }

.funnel { display: grid; grid-template-columns: 1fr; gap: 14px; }
.qcard { border-top: 1px solid var(--line); padding-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.qcard a { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.qcard__foot { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.qmove .input { min-height: 44px; }
.fcol--aceptado h2 { color: var(--ok); }
.notice--alta { border-left: 5px solid var(--bad); }
.notice--media { border-left: 5px solid var(--warn); }
.notice__head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Acceso */
.login-body { min-height: 100vh; display: grid; place-items: center; }
.login { width: min(380px, 100% - 32px); display: flex; flex-direction: column; gap: 12px; padding: 24px 0; text-align: center; align-items: stretch; }
.login .card { text-align: left; }
.login .title { margin: 0; font-size: 40px; }
.login__logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 20px; background: var(--ink); color: var(--bg); display: grid; place-items: center; font-size: 30px; font-weight: 700; }

/* Standalone (pantalla de inicio): rail estrecho a la derecha. Dos bloques idénticos: media query real y gancho html[data-nav] */
@media (max-width: 951px) and (display-mode: standalone), (max-width: 951px) and (display-mode: fullscreen), (max-width: 951px) and (display-mode: minimal-ui) {
  html:not([data-nav]) .rail { top: 0; bottom: 0; left: auto; right: var(--sar); width: var(--rail); height: auto; padding: calc(10px + var(--sat)) 0 calc(10px + var(--sab));
    flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; border-top: 0; border-left: 1px solid var(--line); overflow-y: auto; }
  html:not([data-nav]) .rail__brand { display: grid; }
  html:not([data-nav]) .rail__item { flex: none; width: 50px; min-width: 0; min-height: 52px; font-size: 10px; }
  html:not([data-nav]) .rail__item.is-on { background: var(--accent); color: var(--accent-ink); }
  html:not([data-nav]) .shell { padding: 0 calc(var(--rail) + var(--gutter) + var(--sar)) calc(40px + var(--sab)) max(16px, var(--sal)); }
}
@media (max-width: 951px) {
  html[data-nav="standalone"] .rail { top: 0; bottom: 0; left: auto; right: var(--sar); width: var(--rail); height: auto; padding: calc(10px + var(--sat)) 0 calc(10px + var(--sab));
    flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px; border-top: 0; border-left: 1px solid var(--line); overflow-y: auto; }
  html[data-nav="standalone"] .rail__brand { display: grid; }
  html[data-nav="standalone"] .rail__item { flex: none; width: 50px; min-width: 0; min-height: 52px; font-size: 10px; }
  html[data-nav="standalone"] .rail__item.is-on { background: var(--accent); color: var(--accent-ink); }
  html[data-nav="standalone"] .shell { padding: 0 calc(var(--rail) + var(--gutter) + var(--sar)) calc(40px + var(--sab)) max(16px, var(--sal)); }
}
/* Anchos medios (Duo apaisado, iPad): más columnas, el rail sigue a la derecha */
@media (min-width: 640px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .funnel { grid-template-columns: 1fr 1fr; }
  .facts { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .shell { padding-left: max(24px, var(--sal)); }
  .title { font-size: 40px; }
}
/* Escritorio: rail a la izquierda con etiquetas */
@media (min-width: 952px) {
  .rail { top: 0; bottom: 0; right: auto; left: 0; width: 220px; height: auto; padding: 18px 14px; border-top: 0; border-left: 0; border-right: 1px solid var(--line); align-items: stretch; flex-direction: column; justify-content: flex-start; gap: 4px; overflow-y: auto; }
  .rail__brand { display: grid; }
  .rail__item.is-on { background: var(--accent); color: var(--accent-ink); }
  .rail__brand { margin: 0 0 14px 6px; }
  .rail__item { flex: none; width: auto; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 14px; min-height: 46px; border-radius: 12px; font-size: 15px; }
  .shell { margin-left: 220px; padding: 0 40px 60px; }
  .funnel { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .badge { right: -12px; }
}
@media (max-width: 380px) { .stat b { font-size: 32px; } .title { font-size: 30px; } }

/* Destinos táctiles: los enlaces de bloque ocupan al menos 44 px */
.qcard a, a.row__main { min-height: 44px; justify-content: center; }
.notice__head a { display: inline-flex; align-items: center; min-height: 44px; }

/* Por revisar (enlaces) */
.link__why { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.link__domain { font-size: 18px; overflow-wrap: anywhere; }
.actions .btn, .actions form { max-width: 100%; }
