/* Salud — hoja de estilos única (app + login) */

:root {
    color-scheme: light;
    --bg: #f6f1ea;
    --card: #ffffff;
    --ink: #3a342e;
    --muted: #9a8f84;
    --line: #efe7dd;
    --field: #fdfbf8;
    --toast-bg: #3a342e;
    --toast-fg: #ffffff;
    --del-idle: #cfc4b8;
    --rose: #e96379;
    --peach: #f3a05c;
    --grad: linear-gradient(135deg, #e96379, #f3a05c);
    --tension: #e25c6e;
    --agua: #3aa0d8;
    --comida: #ee9b3f;
    --good: #3fa66a;   /* verde: comida sana / 2 litros de agua / check hecho */
    --bad: #e25c6e;    /* rojo: comida no / agua no */
    --flame: #e8742c;  /* naranja de la racha */
    --radius: 22px;
    --shadow: 0 6px 24px rgba(80, 60, 40, 0.09);
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --bg: #191613;
        --card: #262220;
        --ink: #ece5dc;
        --muted: #a3978a;
        --line: #3a332d;
        --field: #1f1c19;
        --toast-bg: #ece5dc;
        --toast-fg: #2a2521;
        --del-idle: #5d5347;
        --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
    }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    min-height: 100dvh;
    -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

/* ---------- Cabecera ---------- */

.hero {
    background: var(--grad);
    color: #fff;
    padding: calc(env(safe-area-inset-top, 0px) + 22px) 20px 26px;
    border-radius: 0 0 30px 30px;
    box-shadow: var(--shadow);
}

.hero-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    max-width: 560px;
    margin: 0 auto;
}

.hero h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.3px; }

.hero-date { margin: 2px 0 0; opacity: 0.92; font-size: 14px; text-transform: capitalize; }

/* Frase castiza del día (app.js FRASES_DIA) */
.hero-frase { margin: 8px 0 0; font-size: 14px; font-style: italic; opacity: 0.95; line-height: 1.35; }

.hero-actions { display: flex; gap: 8px; }

.icon-btn {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    text-decoration: none;
    font-size: 16px;
}

/* Resumen del día */

.summary {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    max-width: 560px;
    margin: 18px auto 0;
}

.summary-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 13.5px;
    font-weight: 600;
    backdrop-filter: blur(4px);
}

.summary-chip i { font-size: 14px; }

.chip-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}

/* ---------- Contenido ---------- */

main {
    max-width: 560px;
    margin: 0 auto;
    padding: 18px 16px calc(env(safe-area-inset-bottom, 0px) + 40px);
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
}

.card + .card { margin-top: 14px; }

.hidden { display: none !important; }

/* Botón de instalar la app */

.install-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--grad);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    box-shadow: 0 10px 26px rgba(233, 99, 121, 0.35);
    padding: 17px 18px;
    font-size: 17px;
    font-weight: 800;
    cursor: pointer;
    margin-bottom: 14px;
    transition: transform 0.12s ease;
}

.install-btn:active { transform: scale(0.97); }
.install-btn i { font-size: 21px; }

.ios-steps {
    margin: 0 0 14px;
    padding-left: 24px;
    font-size: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ios-note { color: var(--muted); font-size: 13.5px; margin: 0 0 6px; }

/* Avisos (notificaciones / tensión pendiente) */

.notif-card {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.notif-icon {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    background: rgba(233, 99, 121, 0.12);
    color: var(--rose);
    font-size: 18px;
}

.notif-text { flex: 1; display: flex; flex-direction: column; font-size: 13.5px; }
.notif-text strong { font-size: 14.5px; }
.notif-text span { color: var(--muted); }

/* ---------- Racha (días redondos seguidos) ---------- */

.racha-card { padding: 16px 16px 14px; border: 2px solid transparent; }
.racha-card.is-done { border-color: var(--good); }

.racha-top { display: flex; align-items: center; gap: 14px; }

.racha-flame {
    flex: 0 0 auto;
    width: 56px;
    height: 56px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 26px;
    background: rgba(232, 116, 44, 0.16);
    color: var(--flame);
}

/* sin racha: la llama, apagada */
.is-off .racha-flame { background: rgba(154, 143, 132, 0.14); color: var(--muted); }

.racha-text { display: flex; flex-direction: column; min-width: 0; }
.racha-text strong { font-size: 21px; font-weight: 800; letter-spacing: -0.2px; line-height: 1.2; }
.racha-text span { color: var(--muted); font-size: 14px; margin-top: 3px; }

/* los tres checks de hoy (botones: llevan a lo que falta) */
.racha-checks { display: flex; gap: 8px; margin-top: 14px; }

.rc {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1.5px solid var(--line);
    background: var(--field);
    color: var(--muted);
    border-radius: 14px;
    padding: 11px 4px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.rc:active { transform: scale(0.96); }
.rc i { font-size: 17px; }
.rc.done { background: rgba(63, 166, 106, 0.14); border-color: var(--good); color: var(--good); }

.racha-msg { margin: 12px 2px 0; font-size: 14.5px; font-weight: 600; color: var(--muted); }
.is-done .racha-msg { color: var(--good); }

/* ---------- Selectores del día (agua / comida) ---------- */

.pick-card { margin-top: 14px; }

.pick-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.pick-ico {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    display: grid;
    place-items: center;
    font-size: 19px;
}

.ci-agua     { background: rgba(58, 160, 216, 0.14); color: var(--agua); }
.ci-comida   { background: rgba(238, 155, 63, 0.16); color: var(--comida); }
.ci-tension  { background: rgba(226, 92, 110, 0.14); color: var(--tension); }
.ci-sad      { background: rgba(226, 92, 110, 0.14); color: var(--bad); }

.pick-title { display: flex; flex-direction: column; min-width: 0; }
.pick-title strong { font-size: 16px; }
.pick-sub { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }

.segmented {
    display: flex;
    gap: 8px;
}

.seg {
    flex: 1;
    border: 1.5px solid var(--line);
    background: var(--field);
    border-radius: 14px;
    padding: 12px 6px;
    font-size: 14px;
    font-weight: 700;
    color: var(--muted);
    cursor: pointer;
    transition: transform 0.1s ease, background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.seg:active { transform: scale(0.96); }

/* Agua: un botón gordo. El "¡Sí!" manda (más ancho y más alto); el "No" acompaña. */
.segmented-fat .seg { padding: 20px 8px; font-size: 19px; font-weight: 800; border-radius: 18px; }
.segmented-fat .seg-yes { flex: 1.7; }
.segmented-fat .seg i { margin-right: 6px; font-size: 17px; }

/* estados activos por valor (mismo código de color que la gráfica) */
.seg-yes.active { background: rgba(63, 166, 106, 0.16); border-color: var(--good); color: var(--good); }
.seg-no.active  { background: rgba(226, 92, 110, 0.14); border-color: var(--bad);  color: var(--bad); }

.pick-extra { margin-top: 14px; }
.pick-extra .field { margin-bottom: 12px; }

/* ---------- Botón grande de tensión ---------- */

.big-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--card);
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    margin-top: 14px;
    cursor: pointer;
    text-align: left;
    transition: transform 0.12s ease;
}

.big-btn:active { transform: scale(0.97); }

.big-icon {
    width: 54px;
    height: 54px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    font-size: 24px;
}

.big-label { flex: 1; display: flex; flex-direction: column; }
.big-label strong { font-size: 17px; }
.big-label small { color: var(--muted); font-size: 13px; margin-top: 2px; }

.big-plus {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: var(--tension);
    color: #fff;
    font-size: 14px;
}

/* ---------- Gráfico unificado ---------- */

.chart-card { margin-top: 14px; padding: 16px 14px 10px; }

.chart-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    padding: 0 4px;
}

.chart-head h3 {
    margin: 0;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--tension);
}

.chart-legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); font-weight: 600; }
.chart-legend span { display: inline-flex; align-items: center; }

.lg-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.lg-sys { background: var(--tension); }
.lg-dia { background: var(--agua); }

#chart svg { width: 100%; height: auto; display: block; }

.cg-line { stroke: var(--line); stroke-width: 1; }
.cg-sep { stroke: var(--line); stroke-width: 1; }
.cg-empty { fill: var(--line); }
.cg-ylabel { font-size: 9px; fill: var(--muted); text-anchor: end; }
.cg-xlabel { font-size: 9px; fill: var(--muted); text-anchor: middle; }
.cg-today-lbl { fill: var(--tension); font-weight: 800; }
.cg-lane { font-size: 8px; fill: var(--muted); font-weight: 700; }
.cg-plot-empty { font-size: 11px; fill: var(--muted); text-anchor: middle; }
.cg-today { fill: rgba(233, 99, 121, 0.08); }

.cg-sys, .cg-dia { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.cg-sys { stroke: var(--tension); }
.cg-dia { stroke: var(--agua); }
.cg-sys-dot { fill: var(--tension); }
.cg-dia-dot { fill: var(--agua); }

/* Leyenda de carriles del gráfico */

.chart-keys {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 18px;
    padding: 10px 6px 2px;
    margin-top: 4px;
    border-top: 1px solid var(--line);
}

.ck-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ck-title { font-size: 11px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.ck { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.ck-dot { width: 11px; height: 11px; border-radius: 4px; display: inline-block; }

.k-yes { background: var(--good); border-radius: 50%; }
.k-no  { background: var(--bad);  border-radius: 50%; }

.chart-note { font-size: 12.5px; color: var(--muted); margin: 8px 4px 6px; }
.chart-note + .chart-note { margin-top: -2px; }

/* Clasificación orientativa de lecturas: ok <130/85, elevada, alta ≥140/90 */

.tv-ok   { color: #3fa66a; }
.tv-warn { color: #c79204; }
.tv-high { color: #e25c6e; font-weight: 700; }

/* ---------- Historial ---------- */

#history { margin-top: 26px; }

.day-label {
    margin: 20px 4px 8px;
    font-size: 14px;
    font-weight: 800;
    color: var(--muted);
    text-transform: capitalize;
    letter-spacing: 0.2px;
}

.day-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.entry {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
}

.entry + .entry { border-top: 1px solid var(--line); }

.entry-icon {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border-radius: 13px;
    display: grid;
    place-items: center;
    font-size: 16px;
}

.ei-tension  { background: rgba(226, 92, 110, 0.13); color: var(--tension); }
.ei-agua     { background: rgba(58, 160, 216, 0.14); color: var(--agua); }
.ei-comida   { background: rgba(238, 155, 63, 0.15); color: var(--comida); }

.entry-body { flex: 1; min-width: 0; }
.entry-main { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.entry-sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }

.entry-side {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.entry-time { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.entry-del {
    border: none;
    background: none;
    color: var(--del-idle);
    font-size: 14px;
    padding: 6px;
    cursor: pointer;
    border-radius: 10px;
    transition: all 0.15s ease;
}

.entry-del.confirm {
    background: var(--tension);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    padding: 6px 10px;
}

/* Píldora de valor en el historial */

.pill {
    display: inline-block;
    margin-left: 4px;
    padding: 2px 11px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 800;
    color: #fff;
    vertical-align: 1px;
}

.pill-yes { background: var(--good); }
.pill-no  { background: var(--bad); }

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 40px 20px;
    font-size: 14.5px;
}

.empty-state i { font-size: 34px; display: block; margin-bottom: 10px; opacity: 0.5; }

/* ---------- Hoja inferior (bottom sheet) ---------- */

.backdrop {
    position: fixed;
    inset: 0;
    background: rgba(50, 35, 30, 0.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
    z-index: 40;
}

.backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--card);
    border-radius: 26px 26px 0 0;
    padding: 10px 20px calc(env(safe-area-inset-bottom, 0px) + 22px);
    transform: translateY(105%);
    transition: transform 0.28s cubic-bezier(0.32, 0.72, 0.25, 1);
    z-index: 50;
    max-width: 560px;
    margin: 0 auto;
    box-shadow: 0 -10px 40px rgba(60, 40, 30, 0.18);
}

.sheet.open { transform: translateY(0); }

.sheet-handle {
    width: 44px;
    height: 5px;
    border-radius: 99px;
    background: var(--line);
    margin: 4px auto 12px;
}

.sheet h2 {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0 0 16px;
    font-size: 19px;
}

.sheet-ico { flex: 0 0 auto; width: 40px; height: 40px; border-radius: 14px; display: grid; place-items: center; font-size: 17px; }

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 14px;
}

.field input, .field textarea {
    border: 1.5px solid var(--line);
    border-radius: 14px;
    padding: 12px 14px;
    font: inherit;
    font-size: 16px;
    color: var(--ink);
    background: var(--field);
    width: 100%;
}

.field input:focus, .field textarea:focus {
    outline: none;
    border-color: var(--rose);
    background: var(--card);
}

.field textarea { resize: vertical; }

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; min-width: 0; margin-bottom: 16px; }

/* ---------- Botones ---------- */

.btn {
    border: none;
    border-radius: 16px;
    padding: 13px 20px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.12s ease, opacity 0.15s ease;
}

.btn:active { transform: scale(0.97); }
.btn[disabled] { opacity: 0.6; }

.btn-primary { background: var(--grad); color: #fff; }
.btn-block { display: block; width: 100%; }

.btn-small {
    background: var(--grad);
    color: #fff;
    padding: 9px 16px;
    font-size: 13.5px;
    border-radius: 12px;
    flex: 0 0 auto;
}

/* ---------- Toast ---------- */

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 24px);
    transform: translate(-50%, 20px);
    background: var(--toast-bg);
    color: var(--toast-fg);
    border-radius: 20px;
    padding: 11px 20px;
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
    width: max-content;
    max-width: min(460px, calc(100vw - 32px));
    opacity: 0;
    pointer-events: none;
    transition: all 0.25s ease;
    z-index: 100;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Login ---------- */

.login-body {
    background: var(--grad);
    min-height: 100dvh;
    display: grid;
    place-items: center;
}

.login-wrap { width: 100%; padding: 24px; max-width: 420px; }

.login-card {
    background: var(--card);
    border-radius: 28px;
    padding: 34px 28px 30px;
    box-shadow: 0 20px 60px rgba(120, 40, 50, 0.25);
    text-align: center;
}

.login-logo {
    width: 76px;
    height: 76px;
    margin: 0 auto 14px;
    border-radius: 26px;
    background: var(--grad);
    color: #fff;
    font-size: 34px;
    display: grid;
    place-items: center;
    box-shadow: 0 10px 24px rgba(233, 99, 121, 0.4);
}

.login-card h1 { margin: 0; font-size: 28px; letter-spacing: -0.5px; }

.login-sub { margin: 4px 0 22px; color: var(--muted); font-size: 14.5px; }

.login-error {
    background: rgba(226, 92, 110, 0.1);
    color: var(--tension);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 600;
}

.login-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 14px;
}

.login-field input {
    border: 1.5px solid var(--line);
    border-radius: 14px;
    padding: 13px 15px;
    font: inherit;
    font-size: 16px;
    color: var(--ink);
    background: var(--field);
}

.login-field input:focus { outline: none; border-color: var(--rose); background: var(--card); }
