/* ringO — app-style (Android 17 / Material You). Mobile-first, escritorio = marco centrado.
   PROHIBIDO EL MORADO (DESIGN_RULES nº3). */
* { box-sizing: border-box; }
*, *::before, *::after { -webkit-tap-highlight-color: transparent; }

/* Manrope autoalojada (latin, 400-800) — sin CDN, precacheada en sw.js */
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("./fonts/manrope-400.woff2") format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("./fonts/manrope-500.woff2") format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("./fonts/manrope-600.woff2") format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("./fonts/manrope-700.woff2") format("woff2"); }
@font-face { font-family: "Manrope"; font-style: normal; font-weight: 800; font-display: swap;
  src: url("./fonts/manrope-800.woff2") format("woff2"); }

html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }
body {
  margin: 0;
  font-family: "Manrope", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: .2px;
  overscroll-behavior-y: none;
}
::selection { background: var(--accent-tint); }
::-webkit-scrollbar { display: none; }
a { color: var(--accent-strong); text-decoration: none; }

/* ---- top app bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 18px 10px;
  max-width: 560px; margin: 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}
.brand .word { font-weight: 700; font-size: 1.2rem; letter-spacing: .3px; display: flex; align-items: center; gap: 9px; }
.brand .word::before {
  content: ""; width: 12px; height: 12px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 5px var(--accent-tint), 0 0 16px var(--accent-tint);
}
.brand .tag { display: inline-block; font-size: .6rem; letter-spacing: 1.6px; color: var(--muted); text-transform: uppercase; font-weight: 700; margin-left: 21px; }
#theme-toggle {
  margin-left: auto;
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--surface-alt); border: 1px solid var(--border); color: var(--text);
  font-size: 1.05rem; cursor: pointer; display: grid; place-items: center;
  transition: background .15s;
}
#theme-toggle:active { background: var(--hover); }

/* ---- contenido: columna tipo app ---- */
main {
  max-width: 560px; margin: 0 auto;
  padding: 10px 14px calc(96px + env(safe-area-inset-bottom, 0px));
}
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.card, .notice {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 24px; padding: 18px;
  box-shadow: var(--shadow);
}
.card.mid, .card.full { grid-column: auto; }
.card h3 {
  margin: 0 0 12px; font-size: .7rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1.2px; font-weight: 700;
  display: flex; align-items: center; gap: 8px;
}
.card h3::before { content: ""; width: 5px; height: 14px; border-radius: 3px; background: var(--accent); }
.card h3 .right { margin-left: auto; text-transform: none; letter-spacing: 0; font-size: .8rem; color: var(--muted); font-weight: 600; }

/* ---- título de vista ---- */
.page-title { margin: 6px 0 4px; font-size: 1.85rem; font-weight: 700; letter-spacing: -.3px; }
.page-title small { color: var(--muted); font-weight: 600; font-size: .95rem; }
.page-sub { margin: 0 0 16px; color: var(--muted); font-size: .88rem; }

/* ---- hero (hoy) ---- */
.hero { display: flex; gap: 16px; align-items: center; padding: 22px; }
@media (max-width: 400px) { .hero { flex-direction: column; text-align: center; } }
.hero-info { flex: 1 1 auto; min-width: 0; }
.kpiset { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 10px; }

/* ---- anillo ---- */
.ringwrap { display: grid; place-items: center; width: 148px; height: 148px; flex: 0 0 auto; }
.ringwrap svg { transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: var(--border); stroke-width: 12; }
.ring-fg { fill: none; stroke-width: 12; stroke-linecap: round; transition: stroke-dasharray .6s ease; }
.ring-text { transform: rotate(90deg); transform-origin: 70px 70px; text-anchor: middle; }
.ring-text .r-val { font-size: 30px; font-weight: 700; fill: var(--text); }
.ring-text .r-lab { font-size: 9.5px; fill: var(--muted); letter-spacing: 1.5px; text-transform: uppercase; font-weight: 700; }

/* ---- chips / badges ---- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 999px; padding: 6px 12px; font-size: .8rem; font-weight: 700;
}
.chip.teal  { background: var(--accent-tint); color: var(--accent-strong); }
.chip.cyan  { background: var(--cyan-tint);    color: var(--cyan-strong); }
.chip.green { background: var(--good-tint);    color: var(--good-strong); }
.chip.amber { background: var(--warn-tint);    color: var(--warn-strong); }
.chip.red   { background: var(--bad-tint);     color: var(--bad-strong); }
.chip.muted { background: var(--border);       color: var(--muted); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip .big { font-size: 1rem; }

.row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 7px 0; font-size: .95rem; }
.row b { font-weight: 600; }
.muted { color: var(--muted); }
.good { color: var(--good-strong); } .warn { color: var(--warn-strong); } .bad { color: var(--bad-strong); }
.delta { font-size: .8rem; font-weight: 700; }

/* ---- gráficas ---- */
canvas.chart { width: 100% !important; height: 180px !important; }
canvas.chart.tall { height: 220px !important; }
.chart-note { color: var(--muted); font-size: .76rem; margin: 8px 0 0; line-height: 1.4; }

/* ---- fases de sueño ---- */
.sleepbar { display: flex; height: 20px; border-radius: 10px; overflow: hidden; gap: 2px; margin: 12px 0 10px; background: var(--border); }
.sleepbar > div { height: 100%; border-radius: 6px; }
.ph-light { background: #38bdf8; } .ph-deep { background: #0ea5e9; }
.ph-rem { background: var(--accent); } .ph-awake { background: #f59e0b; }
.legend { display: flex; gap: 12px; font-size: .78rem; color: var(--muted); flex-wrap: wrap; margin-bottom: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }

/* ---- listas tipo app (historial/avisos) ---- */
.rowitem, .alarm {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-alt); border: 1px solid var(--border);
  border-radius: 18px; padding: 12px 14px; margin-bottom: 8px;
}
.rowitem .l { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.rowitem .d { font-weight: 700; font-size: .95rem; }
.rowitem .s { color: var(--muted); font-size: .78rem; }
.rowitem .r { margin-left: auto; text-align: right; font-size: .88rem; line-height: 1.5; }
.alarm { align-items: flex-start; flex-direction: column; gap: 8px; }
.alarm .top { display: flex; align-items: center; gap: 8px; width: 100%; }
.alarm .date { margin-left: auto; color: var(--muted); font-size: .8rem; font-weight: 700; }
.alarm .msg { font-size: .92rem; line-height: 1.45; }
.alarm .msg b { color: var(--text); }

/* ---- controles ---- */
.seg { display: inline-flex; gap: 2px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--muted); font-weight: 700; font-size: .84rem;
  border-radius: 999px; padding: 8px 18px; cursor: pointer; min-height: 38px;
}
.seg button.active { background: var(--surface); color: var(--accent-strong); box-shadow: var(--shadow); }
button.btn {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px;
  padding: 12px 20px; font-weight: 700; cursor: pointer; font-size: .95rem; min-height: 46px;
  transition: filter .15s, transform .05s;
}
button.btn:active { transform: scale(.98); }
button.btn:disabled { opacity: .45; }
button.btn.ghost { background: transparent; color: var(--accent-strong); border: 1px solid var(--accent-border); }
input[type="number"], select {
  background: var(--surface-alt); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 9px 12px; font-size: .95rem; font-family: inherit; min-height: 42px;
}
input[type="number"]:focus, select:focus { outline: 2px solid var(--accent-tint); border-color: var(--accent); }

/* ---- avisos / vacío ---- */
.notice { text-align: center; padding: 34px 22px; }
.notice .ico { font-size: 2.4rem; margin-bottom: 10px; }

/* ---- skeleton ---- */
.sk { position: relative; overflow: hidden; background: var(--skeleton); border-radius: 14px; }
.sk::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent, var(--skeleton-shine), transparent);
  animation: sk 1.4s ease infinite;
}
@keyframes sk { 0% { transform: translateX(-100%); } 100% { transform: translateX(100%); } }
.sk.box { height: 130px; }
.sk.line { height: 14px; margin: 9px 0; }

/* ---- barra inferior tipo app (botón de navegación) ---- */
.bottombar {
  position: fixed; bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  left: 50%; transform: translateX(-50%);
  width: calc(100% - 20px); max-width: 540px;
  display: flex; justify-content: space-around; align-items: center;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border); border-radius: 30px;
  box-shadow: var(--shadow-elev);
  padding: 8px 6px; z-index: 30;
}
.bottombar button {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--muted); font-size: .62rem; font-weight: 700; letter-spacing: .3px;
  padding: 6px 2px; min-height: 48px; border-radius: 18px;
  transition: color .15s, background .15s;
}
.bottombar button svg { width: 22px; height: 22px; }
.bottombar button.active { color: var(--accent-strong); background: var(--accent-tint); }
.bottombar button:active { transform: scale(.94); }

/* ---- entrada de vistas ---- */
#view > * { animation: riseIn .18s ease both; }
@keyframes riseIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---- footer ---- */
.foot {
  max-width: 560px; margin: 0 auto; text-align: center; color: var(--muted);
  font-size: .74rem; padding: 4px 16px 8px;
  display: flex; justify-content: center; align-items: center; gap: 8px; flex-wrap: wrap;
}
.status-pill { display: inline-flex; align-items: center; gap: 7px; font-weight: 700; font-size: .74rem; }
.status-pill .sd { width: 8px; height: 8px; border-radius: 50%; }
.status-pill .sd.ok { background: var(--good); box-shadow: 0 0 8px var(--good-tint); }
.status-pill .sd.warn { background: var(--warn); }
.status-pill .sd.err { background: var(--bad); }

@media (min-width: 561px) {
  .grid { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
  .card.mid, .card.full { grid-column: 1 / -1; }
}