:root {
    --bg: #0a0e18;
    --bg2: #121a2c;
    --panel: #141c30;
    --panel2: #1b2540;
    --line: #253352;
    --txt: #e6ecfa;
    --muted: #8f9dbd;
    --accent: #7c5cff;
    --accent2: #38bdf8;
    --ok: #34d399;
    --warn: #fbbf24;
    --bad: #f87171;
    --snore: #38bdf8;
    --speech: #c084fc;
    --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: radial-gradient(1200px 800px at 50% -10%, #17203a 0%, var(--bg) 55%) no-repeat, var(--bg);
    color: var(--txt);
    font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    min-height: 100%;
    overscroll-behavior-y: contain;
}

body { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }

a { color: var(--accent2); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h2 { font-size: 1.05rem; letter-spacing: .01em; }
h3 { font-size: .95rem; color: var(--muted); margin-top: 1rem; }
small { font-size: .8rem; }
code { background: #0d1424; padding: .1em .35em; border-radius: 5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }
.tiny { font-size: .78rem; }

/* -------------------------------------------------------------------- topbar */

.topbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: calc(.7rem + env(safe-area-inset-top)) 1rem .7rem;
    position: sticky; top: 0; z-index: 20;
    background: rgba(10, 14, 24, .82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 1.05rem; margin: 0; letter-spacing: .04em; }
.moon { color: var(--accent); margin-right: .3rem; }
.topbar-right { display: flex; align-items: center; gap: .5rem; }

.pill {
    font-size: .75rem; padding: .2rem .5rem; border-radius: 999px;
    background: var(--panel2); color: var(--muted); border: 1px solid var(--line);
}
.pill.warn { color: var(--warn); border-color: #4a3a12; }

main { padding: 1rem; max-width: 900px; margin: 0 auto; }

/* -------------------------------------------------------------------- botones */

button, .primary, .secondary, .ghost, .danger, .chip {
    font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent;
    padding: .6rem .9rem; color: var(--txt); background: var(--panel2);
    transition: filter .15s, transform .05s;
}
button:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: default; }
.primary { background: linear-gradient(180deg, #8b6dff, #6d4bf0); }
.secondary { background: var(--panel2); border-color: var(--line); }
.ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.danger { background: #4a1d24; border-color: #6f2b34; color: #ffd9dc; }
.small { padding: .4rem .7rem; font-size: .85rem; }
.chip { background: transparent; border-color: var(--line); color: var(--muted); font-size: .8rem; padding: .35rem .6rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; align-items: center; }
a.primary, a.secondary, a.ghost { display: inline-block; }

/* -------------------------------------------------------------------- paneles */

.panel {
    background: linear-gradient(180deg, var(--panel), var(--bg2));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; margin-bottom: .6rem; }
.panel-head h2 { margin: 0; }
.danger-panel { border-color: #4a2630; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }

.notice {
    background: #2a2411; border: 1px solid #57451a; color: #ffe9b0;
    padding: .8rem 1rem; border-radius: var(--radius); margin-bottom: 1rem;
}
.notice p { margin: 0 0 .4rem; }

/* ------------------------------------------------------------------- grabar */

.record-stage { display: flex; flex-direction: column; align-items: center; gap: 1rem; }

.meter { position: relative; width: min(74vw, 280px); aspect-ratio: 1; }
.gauge { position: absolute; inset: 0; transform: rotate(-90deg); }
.gauge-bg { fill: none; stroke: #1d2740; stroke-width: 10; }
.gauge-arc {
    fill: none; stroke: url(#g) var(--accent2); stroke: var(--accent2);
    stroke-width: 10; stroke-linecap: round;
    transition: stroke-dashoffset .18s linear;
    filter: drop-shadow(0 0 6px rgba(56, 189, 248, .55));
}

.record-btn {
    position: absolute; inset: 14%;
    border-radius: 50%;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .2rem;
    background: radial-gradient(circle at 50% 30%, #2b2350, #171f36 70%);
    border: 1px solid #34406b;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 10px 30px rgba(0, 0, 0, .4);
}
.record-btn .rec-label { font-size: 1.25rem; font-weight: 700; letter-spacing: .08em; }
.record-btn .rec-sub { font-size: .74rem; color: var(--muted); }
.record-btn.recording {
    background: radial-gradient(circle at 50% 30%, #5a1f2c, #2a1220 70%);
    border-color: #7b2b3c;
    animation: pulse 2.6s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 0 0 0 rgba(248, 113, 113, .35); }
    50% { box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06), 0 0 0 14px rgba(248, 113, 113, 0); }
}

.live-readout { text-align: center; }
.timer { font-size: 2.1rem; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.live-status { color: var(--muted); font-size: .9rem; }
.live-status.on { color: var(--accent2); }
.live-db { color: var(--muted); font-size: .85rem; margin-top: .2rem; }
.live-db span { color: var(--txt); font-size: 1rem; font-variant-numeric: tabular-nums; }

.counters { display: grid; grid-template-columns: repeat(4, 1fr); gap: .5rem; width: 100%; }
.counter {
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    padding: .6rem .2rem; text-align: center;
}
.counter span { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.counter label { font-size: .7rem; color: var(--muted); }

.rec-log { width: 100%; max-height: 220px; overflow-y: auto; }
.log-row {
    display: grid; grid-template-columns: 4.6rem 4.6rem 1fr; gap: .4rem;
    font-size: .8rem; padding: .3rem .5rem; border-bottom: 1px solid #1b2338;
    font-variant-numeric: tabular-nums;
}
.log-row .log-kind { color: var(--snore); }
.log-row.speech .log-kind { color: var(--speech); font-weight: 600; }
.log-row .log-meta { color: var(--muted); text-align: right; }

.warnings { width: 100%; }
.warning { font-size: .78rem; color: var(--warn); padding: .2rem 0; }
.hint { color: var(--muted); font-size: .82rem; text-align: center; max-width: 34rem; }

/* ---------------------------------------------------------------- histórico */

.range-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: .8rem; }
.range-bar label { font-size: .78rem; color: var(--muted); display: flex; flex-direction: column; gap: .2rem; }
input[type="date"], input[type="number"], input[type="text"], input[type="password"], select, textarea {
    font: inherit; background: #0e1626; color: var(--txt);
    border: 1px solid var(--line); border-radius: 9px; padding: .45rem .55rem;
}
textarea.notes { width: 100%; resize: vertical; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(115px, 1fr)); gap: .5rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: .6rem .7rem; }
.card-value { font-size: 1.3rem; font-variant-numeric: tabular-nums; }
.card-label { font-size: .72rem; color: var(--muted); }
.card-sub { font-size: .7rem; color: #6f7da0; margin-top: .15rem; }

.session-list { display: flex; flex-direction: column; gap: .4rem; }
.session-row {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    padding: .7rem .8rem; color: var(--txt);
}
.sr-date { font-size: .92rem; }
.sr-sub { font-size: .76rem; color: var(--muted); }
.sr-side { display: flex; align-items: center; gap: .35rem; }
.chev { color: var(--muted); font-size: 1.2rem; }
.tag {
    font-size: .68rem; padding: .12rem .4rem; border-radius: 999px;
    border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.tag.ok { color: var(--ok); border-color: #1c4a3a; }
.tag.work { color: var(--accent2); border-color: #1d3a52; }
.tag.warn { color: var(--warn); border-color: #4a3a12; }
.tag.rec { color: var(--bad); border-color: #5a2430; }

/* ------------------------------------------------------------------ gráficas */

.chart { display: block; background: #0c1322; border-radius: 10px; border: 1px solid #1a2338; }
.chart .grid { stroke: #1e2942; stroke-width: 1; }
.chart .axis { fill: #6f7da0; font-size: 10px; }
.chart .axis.mid { text-anchor: middle; }
.chart .line-peak { fill: none; stroke: #24425f; stroke-width: 1; }
.chart .line-avg { fill: none; stroke: var(--accent2); stroke-width: 1.4; }
.chart .line-metric { fill: none; stroke: var(--warn); stroke-width: 1.6; }
.chart .dot-metric { fill: var(--warn); }
.chart .bar { fill: #4f46c9; }
.chart .night:hover .bar { fill: var(--accent); }
.chart .mark-snore { fill: var(--snore); opacity: .8; }
.chart .mark-speech { fill: var(--speech); }
.chart .band-pause { fill: rgba(248, 113, 113, .16); }

.legend { display: flex; align-items: center; gap: .4rem; font-size: .75rem; color: var(--muted); margin-top: .4rem; flex-wrap: wrap; }
.legend .key { width: 12px; height: 8px; border-radius: 2px; display: inline-block; margin-left: .6rem; }
.legend .key:first-child { margin-left: 0; }
.legend .key.bar { background: #4f46c9; }
.legend .key.line { background: var(--warn); }
.legend .key.snore { background: var(--snore); }
.legend .key.speech { background: var(--speech); }
.legend .key.pause { background: rgba(248, 113, 113, .5); }

/* -------------------------------------------------------------------- tablas */

.table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.table th { text-align: left; color: var(--muted); font-weight: 500; font-size: .75rem; padding: .3rem .4rem; border-bottom: 1px solid var(--line); }
.table td { padding: .35rem .4rem; border-bottom: 1px solid #182136; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ recortes */

.clip { background: #101828; border: 1px solid var(--line); border-radius: 11px; padding: .55rem .7rem; margin-bottom: .5rem; }
.clip-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.clip-time { font-size: .82rem; font-variant-numeric: tabular-nums; }
.clip-meta { font-size: .74rem; color: var(--muted); margin-left: auto; }
.clip-text { font-size: .9rem; margin-top: .35rem; color: #dbe3f7; }
.clip.mini { display: flex; align-items: center; gap: .5rem; margin: 0; }
.clip-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .5rem; }
.play {
    width: 32px; height: 32px; border-radius: 50%; padding: 0; flex: 0 0 32px;
    background: var(--panel2); border: 1px solid var(--line); font-size: .8rem;
}
.play.playing { background: var(--accent); border-color: var(--accent); }
.transcript {
    white-space: pre-wrap; background: #0c1322; border: 1px solid var(--line);
    border-radius: 10px; padding: .7rem; font-size: .85rem; max-height: 340px; overflow: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

/* ------------------------------------------------------------------- ajustes */

.form { display: grid; gap: .8rem; }
.field label { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; }
.field.checkbox label, .check { flex-direction: row !important; align-items: center; gap: .5rem; font-size: .85rem; }
.check input { width: 18px; height: 18px; }
.field small { display: block; margin-top: .2rem; }

/* -------------------------------------------------------------------- tabbar */

.tabbar {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    display: grid; grid-template-columns: repeat(4, 1fr);
    background: rgba(12, 17, 30, .94); backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
    display: flex; flex-direction: column; align-items: center; gap: .1rem;
    padding: .55rem 0; font-size: .68rem; color: var(--muted);
}
.tabbar a span { font-size: 1.1rem; line-height: 1; }
.tabbar a.active { color: var(--accent2); }

/* --------------------------------------------------------------- pantalla off */

.dim-overlay {
    position: fixed; inset: 0; z-index: 100; background: #000;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem;
    color: #2f3a55;
}
.dim-clock { font-size: 3rem; font-variant-numeric: tabular-nums; }
.dim-timer { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.dim-info { font-size: .8rem; }
.dim-overlay button { margin-top: 2rem; color: #2f3a55; border-color: #1a2130; }

/* --------------------------------------------------------------------- toast */

.toast {
    position: fixed; left: 50%; transform: translateX(-50%);
    bottom: calc(78px + env(safe-area-inset-bottom));
    background: var(--panel2); border: 1px solid var(--line); color: var(--txt);
    padding: .6rem .9rem; border-radius: 12px; z-index: 200; max-width: 90vw;
    box-shadow: 0 10px 30px rgba(0, 0, 0, .5); font-size: .88rem;
}
.toast.ok { border-color: #1c4a3a; }
.toast.error { border-color: #6f2b34; background: #33161c; }

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

.login-wrap {
    min-height: 100dvh; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 1rem; padding: 2rem;
}
.login-wrap form { display: flex; flex-direction: column; gap: .6rem; width: min(320px, 100%); }
.login-wrap h1 { font-size: 1.6rem; }
.login-wrap .err { color: var(--bad); font-size: .85rem; min-height: 1.2em; }
