/* ============================================================
   Identidad de Enbata
   Paleta y tipografías del sistema visual de Enbata (navy + azul de marca,
   Michroma para epígrafes y Space Grotesk para el resto). Sin dorado.
   Contrastes comprobados: el azul de marca #1D5391 nunca se usa como texto sobre navy.
   ============================================================ */
@font-face { font-family: "Space Grotesk"; font-weight: 400; font-display: swap; src: url("/fonts/space-grotesk-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Space Grotesk"; font-weight: 500; font-display: swap; src: url("/fonts/space-grotesk-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Space Grotesk"; font-weight: 600; font-display: swap; src: url("/fonts/space-grotesk-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Space Grotesk"; font-weight: 700; font-display: swap; src: url("/fonts/space-grotesk-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Michroma"; font-weight: 400; font-display: swap; src: url("/fonts/michroma-latin-400-normal.woff2") format("woff2"); }

:root {
  /* superficies (navy de marca) */
  --bg: #0E2030;
  --surface: #16304A;
  --surface-2: #1B3A58;
  --border: #2B4157;
  --text: #F3F7FB;
  --muted: #95ACC6;          /* 5,8:1 sobre tarjeta */
  --accent: #8FBCE8;         /* texto de acento: enlaces, pestaña activa */
  --brand: #1D5391;          /* azul de marca: botones, rellenos, resplandor */
  --brand-mid: #3E7DC4;      /* azul medio: barras y gráficas */
  --chart: #5B97D6;
  --wave: rgba(175, 205, 234, .10);
  --glow: rgba(29, 83, 145, .45);

  /* estados (reservados: nunca se usan como color de serie) */
  --ok: #3FCB86;
  --ok-bg: rgba(63, 203, 134, .14);
  --warn: #F0A92E;
  --warn-bg: rgba(240, 169, 46, .15);
  --down: #FF6B66;
  --down-bg: rgba(255, 107, 102, .15);
  --idle: #7F95AE;
  --idle-bg: rgba(127, 149, 174, .16);

  --radius: 14px;
  --skew: -26.5deg;          /* ángulo de la marca */
  --font: "Space Grotesk", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --display: "Michroma", "Space Grotesk", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #EEF3F8;
    --surface: #FFFFFF;
    --surface-2: #F3F6FA;
    --border: #D5DEE8;
    --text: #0B1B2A;
    --muted: #4A5B70;
    --accent: #1D5391;
    --brand: #1D5391;
    --brand-mid: #3E7DC4;
    --chart: #1D5391;
    --wave: rgba(29, 83, 145, .07);
    --glow: rgba(62, 125, 196, .20);
    --ok: #16774A;
    --ok-bg: rgba(22, 119, 74, .10);
    --warn: #9A5B00;
    --warn-bg: rgba(154, 91, 0, .10);
    --down: #C9302C;
    --down-bg: rgba(201, 48, 44, .10);
    --idle: #5E7086;
    --idle-bg: rgba(94, 112, 134, .12);
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); }
/* firma visual: textura de ondas y resplandor radial, fijos detrás del contenido */
body::before { content: ""; position: fixed; inset: 0; z-index: -2; pointer-events: none; background: var(--bg); }
.bg-waves { position: fixed; inset: 0; z-index: -1; pointer-events: none; overflow: hidden; }
.bg-waves svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.bg-waves path { fill: none; stroke: var(--wave); stroke-width: 1.6; vector-effect: non-scaling-stroke; }
.bg-waves::before { content: ""; position: absolute; width: 130vw; height: 70vh; left: 10vw; top: -28vh;
  background: radial-gradient(closest-side, var(--glow), transparent); }
body { min-height: 100dvh; font-size: 15px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---------- estructura ---------- */
.app { max-width: 720px; margin: 0 auto; padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 92px); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 18px; min-height: 40px; }
.topbar h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.topbar .back { display: inline-flex; align-items: center; gap: 4px; font-size: 16px; color: var(--accent); background: none; border: 0; padding: 8px 0; cursor: pointer; }
.topbar .actions { display: flex; gap: 8px; }
.sub { color: var(--muted); font-size: 13px; }

.icon-btn { width: 38px; height: 38px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; cursor: pointer; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; justify-content: center;
  background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom); }
.tabbar nav { display: flex; width: 100%; max-width: 720px; }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 9px 0 8px; color: var(--muted); font-size: 11px; font-weight: 500; }
.tabbar a svg { width: 24px; height: 24px; }
.tabbar a { position: relative; }
.tabbar a.active { color: var(--accent); }
.tabbar a.active::before { content: ""; position: absolute; top: 0; left: 50%; width: 26px; height: 3px; margin-left: -13px;
  background: var(--accent); transform: skewX(var(--skew)); }

/* ---------- estado ---------- */
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--idle); }
.row.s-up > .dot, .dot.s-up { background: var(--ok); }
.row.s-warning > .dot, .dot.s-warning { background: var(--warn); }
.row.s-down > .dot, .dot.s-down { background: var(--down); box-shadow: 0 0 0 0 var(--down); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--down) 70%, transparent); } 70% { box-shadow: 0 0 0 8px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.badge { align-self: flex-start; display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px; background: var(--idle-bg); color: var(--idle); white-space: nowrap; }
.badge.s-up { background: var(--ok-bg); color: var(--ok); }
.badge.s-warning { background: var(--warn-bg); color: var(--warn); }
.badge.s-down { background: var(--down-bg); color: var(--down); }

/* ---------- panel ---------- */
.hero { display: flex; align-items: center; gap: 16px; padding: 18px; border-radius: var(--radius); margin-bottom: 16px; background: var(--idle-bg); border: 1px solid transparent; }
.hero.s-up { background: var(--ok-bg); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.hero.s-warning { background: var(--warn-bg); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
.hero.s-down { background: var(--down-bg); border-color: color-mix(in srgb, var(--down) 40%, transparent); }
.hero-icon { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--idle); color: #fff; }
.hero.s-up .hero-icon { background: var(--ok); }
.hero.s-warning .hero-icon { background: var(--warn); }
.hero.s-down .hero-icon { background: var(--down); }
.hero-icon svg { width: 26px; height: 26px; }
.hero h2 { margin: 0 0 2px; font-size: 19px; letter-spacing: -.01em; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 26px; }
.tile { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; min-height: 124px; display: flex; flex-direction: column; gap: 8px; cursor: pointer; overflow: hidden; }
.tile::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--idle); }
.tile.s-up::before { background: var(--ok); }
.tile.s-warning::before { background: var(--warn); }
.tile.s-down::before { background: var(--down); }
.tile.pending { cursor: default; opacity: .6; }
.tile.pending::before { background: var(--border); }
.tile-head { display: flex; align-items: center; justify-content: space-between; }
.tile-head svg { width: 22px; height: 22px; color: var(--muted); }
.tile-name { font-weight: 600; font-size: 15px; }
.tile-main { font-size: 13px; color: var(--muted); margin-top: auto; }
.tile-counts { display: flex; gap: 10px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.tile-counts span { display: inline-flex; align-items: center; gap: 5px; }
.tile-counts .dot { width: 8px; height: 8px; animation: none; }

.section-title { font-family: var(--display); font-size: 10.5px; font-weight: 400; text-transform: uppercase; letter-spacing: .2em;
  color: var(--muted); margin: 0 4px 10px; display: flex; align-items: center; gap: 10px; }
.section-title::before { content: ""; width: 14px; height: 6px; background: var(--brand-mid); transform: skewX(var(--skew)); flex: none; }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 24px; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-top: 1px solid var(--border); }
.row:first-child { border-top: 0; }
a.row, .row.link { color: inherit; cursor: pointer; }
a.row:active, .row.link:active { background: var(--surface-2); }
.row-body { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { text-align: right; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.row-meta strong { display: block; color: var(--text); font-weight: 600; font-size: 14px; }
.chev { width: 16px; height: 16px; color: var(--muted); flex: none; }
.reason { font-size: 12.5px; margin-top: 2px; white-space: normal; }
.s-warning .reason { color: var(--warn); }
.s-down .reason { color: var(--down); }

.event-ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex: none; background: var(--idle-bg); color: var(--idle); }
.event-ico svg { width: 16px; height: 16px; }
.lvl-critical .event-ico { background: var(--down-bg); color: var(--down); }
.lvl-warning .event-ico { background: var(--warn-bg); color: var(--warn); }
.lvl-recovery .event-ico { background: var(--ok-bg); color: var(--ok); }

.empty { text-align: center; color: var(--muted); padding: 34px 20px; }
.empty svg { width: 40px; height: 40px; margin-bottom: 8px; opacity: .6; }

/* ---------- detalle ---------- */
.detail-head { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.detail-head .url { font-family: var(--mono); font-size: 13px; color: var(--muted); word-break: break-all; margin: 4px 0 12px; }
.detail-head .reason { font-size: 14px; margin-top: 10px; }
.metrics { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.metric .k { font-size: 12px; color: var(--muted); }
.metric .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.metric .v small { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }
.metric.warn .v { color: var(--warn); }
.metric.bad .v { color: var(--down); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.card h3 { margin: 0 0 10px; font-size: 14px; font-weight: 600; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .axis { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .line { fill: none; stroke: var(--chart); stroke-width: 2; stroke-linejoin: round; }
.chart .area { fill: color-mix(in srgb, var(--chart) 18%, transparent); }
.chart .fail { fill: var(--down); }
.uptime-bar { display: flex; gap: 2px; height: 28px; margin-top: 4px; }
.uptime-bar span { flex: 1; border-radius: 3px; background: var(--border); }
.uptime-bar .b-ok { background: var(--ok); }
.uptime-bar .b-part { background: var(--warn); }
.uptime-bar .b-bad { background: var(--down); }
.uptime-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }

.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); font-weight: 600; cursor: pointer; }
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.danger { color: var(--down); }
.btn.full { width: 100%; grid-column: 1 / -1; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- formularios ---------- */
.form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 4px 14px; margin-bottom: 14px; }
.field { padding: 12px 0; border-top: 1px solid var(--border); }
.field:first-child { border-top: 0; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select { width: 100%; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 11px 12px; font-size: 16px; outline: none; }
.field input:focus, .field select:focus { border-color: var(--accent); }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch { position: relative; width: 50px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .2s; }
.switch span::before { content: ""; position: absolute; width: 26px; height: 26px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(20px); }

.note { font-size: 13px; color: var(--muted); background: var(--surface-2); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; }
.note.warn { background: var(--warn-bg); color: var(--text); }

.login { min-height: 80dvh; display: flex; flex-direction: column; justify-content: center; }
.login .logo { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 18px; }
.login h1 { margin: 0 0 6px; font-size: 26px; }
.login p { color: var(--muted); margin: 0 0 22px; }

.toast { position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 84px); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px; font-weight: 500; transition: .25s; z-index: 50; max-width: calc(100% - 32px); pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.offline { background: var(--warn-bg); color: var(--warn); font-size: 13px; font-weight: 600; text-align: center; padding: 8px; border-radius: 10px; margin-bottom: 12px; }

@media (min-width: 620px) {
  .grid { grid-template-columns: repeat(4, 1fr); }
  .metrics { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- servidores (fase 2) ---------- */
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; white-space: normal; }
.txt-bad { color: var(--down); font-weight: 600; }
.txt-warn { color: var(--warn); font-weight: 600; }
.kv { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--border); font-size: 14px; }
.kv:first-of-type { border-top: 0; }
.kv > span:first-child { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.kv .dot { width: 8px; height: 8px; animation: none; }
.meter { padding: 6px 0 8px; }
.meter-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; margin-bottom: 6px; }
.meter-top span:first-child { font-family: var(--mono); font-size: 12.5px; }
.meter-top span:last-child { color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.meter-bar span { display: block; height: 100%; border-radius: 4px 0 0 4px; background: var(--brand-mid);
  clip-path: polygon(0 0, 100% 0, calc(100% - 4px) 100%, 0 100%); /* extremo sesgado, como la marca */ }
.meter-bar span.warn { background: var(--warn); }
.meter-bar span.bad { background: var(--down); }
.mini { padding: 4px 0 10px; border-top: 1px solid var(--border); }
.mini:first-of-type { border-top: 0; }
.mini-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding: 8px 0 4px; }
.mini-head strong { color: var(--text); font-variant-numeric: tabular-nums; }
.mini svg { width: 100%; height: 70px; touch-action: pan-y; cursor: crosshair; }
.chart .warn-line { stroke: var(--warn); stroke-width: 1; stroke-dasharray: 4 4; opacity: .6; vector-effect: non-scaling-stroke; }
.chart .cursor { stroke: var(--muted); stroke-width: 1; }
.code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 0 0 10px; white-space: pre-wrap; word-break: break-all; user-select: all; -webkit-user-select: all; }
.card .btn.full { min-height: 42px; }
.tabbar a { font-size: 10.5px; }

/* ---------- ampliación fases 1 y 2 ---------- */
.row-sub.wrap { white-space: normal; }
.finding { padding: 2px 0 6px; border-top: 1px solid var(--border); }
.finding:first-of-type { border-top: 0; }
.finding .kv { border-top: 0; align-items: flex-start; }
.finding .kv > span:first-child { align-items: flex-start; }
.finding .kv .dot { margin-top: 6px; }
.btn.small { min-height: 32px; padding: 0 12px; font-size: 13px; margin-left: 16px; }
.meter-note { font-size: 12px; color: var(--muted); margin-top: 5px; }
.kv > span:last-child { text-align: right; }
input[type="date"] { -webkit-appearance: none; appearance: none; min-height: 44px; }
input:disabled { opacity: .6; }
.finding .kv > span { text-align: left; }

/* ---------- identidad de Enbata ---------- */
.brandline { font-family: var(--display); font-size: 10px; letter-spacing: .22em; text-transform: uppercase; color: var(--accent);
  display: flex; align-items: center; gap: 8px; margin: 6px 0 -8px; }
.brandline::before { content: ""; width: 18px; height: 5px; background: var(--brand-mid); transform: skewX(var(--skew)); }
.topbar h1 { font-weight: 700; letter-spacing: -.02em; }
.badge { letter-spacing: .01em; }
.tile-name, .row-title, .detail-head h1, .hero h2 { letter-spacing: -.01em; }
.metric .v { font-weight: 700; letter-spacing: -.02em; }
.metric .k, .kv > span:first-child, .mini-head span:first-child { letter-spacing: .01em; }
.card h3 { font-family: var(--display); font-size: 10px; font-weight: 400; letter-spacing: .2em; text-transform: uppercase; color: var(--muted); margin-bottom: 12px; }
.hero { position: relative; overflow: hidden; }
.login .wordmark { font-family: var(--display); font-size: 22px; letter-spacing: .22em; margin: 0 0 4px; }
.login .tagline { font-family: var(--display); font-size: 10px; letter-spacing: .22em; text-transform: uppercase; color: var(--accent); margin: 0 0 24px; }
.login h1 { display: none; }
.footer-brand { text-align: center; font-family: var(--display); font-size: 9.5px; letter-spacing: .22em; text-transform: uppercase; color: var(--muted); margin: 28px 0 8px; opacity: .8; }
.tabbar[hidden] { display: none; }

/* ---------- acceso con Face ID ---------- */
.btn.faceid { min-height: 54px; font-size: 16px; }
.btn.faceid svg { width: 24px; height: 24px; }
.btn.linkish { background: none; border: 0; color: var(--accent); margin-top: 6px; font-weight: 500; }
.login p { color: var(--muted); }
.login .btn + .btn { margin-top: 8px; }
.faceid-note { display: flex; gap: 10px; align-items: center; }
.faceid-note svg { width: 22px; height: 22px; flex: none; color: var(--accent); }
.row .btn.small { margin-left: 8px; flex: none; }
