/* HomeDashboard: mobile-first, dark by default, light when the device is light. */
:root {
    --bg: #0f1115;
    --card: #181b22;
    --card-2: #20242d;
    --text: #eef0f4;
    --muted: #8c93a1;
    --line: #2a2f3a;
    --accent: #4f9dff;
    --ok: #3ccf7a;
    --warn: #ffb547;
    --bad: #ff5c5c;
    --water: #4fc3ff;
    --heat: #ff8a3d;
    --car: #a78bfa;
    --sky: #ffd166;
    --radius: 20px;
    --gap: 14px;
    color-scheme: dark;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #f2f3f7;
        --card: #ffffff;
        --card-2: #f0f2f6;
        --text: #15181e;
        --muted: #6b7280;
        --line: #e3e6ec;
        color-scheme: light;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
             max(24px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
    min-height: 100vh;
}

h1, h2 { margin: 0; font-weight: 650; }
h1 { font-size: 30px; letter-spacing: -0.02em; }
h2 { font-size: 17px; }

.muted { color: var(--muted); }

.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}

/* Pull to refresh, and the stale-data line */
html, body { overscroll-behavior-y: none; }
.ptr {
    position: fixed; left: 50%; top: calc(env(safe-area-inset-top) - 52px); z-index: 20;
    width: 40px; height: 40px; margin-left: -20px; border-radius: 50%;
    display: grid; place-items: center; font-size: 17px;
    background: var(--card); color: var(--muted); box-shadow: 0 4px 16px rgb(0 0 0 / 0.25);
    opacity: 0; pointer-events: none; transition: transform 0.25s ease, opacity 0.25s ease;
}
.ptr.dragging { transition: none; }
.ptr.ready, .ptr.loading { color: var(--accent); }
.ptr.loading i { animation: spin 0.8s linear infinite; }
.stale {
    max-width: 1200px; margin: 0 auto 12px; padding: 10px 14px; border-radius: 14px;
    background: color-mix(in srgb, var(--warn) 16%, var(--card)); color: var(--warn); font-size: 14px;
}

/* Cards */
.grid {
    display: grid; gap: var(--gap);
    grid-template-columns: 1fr;
    max-width: 1200px; margin: 0 auto;
}
@media (min-width: 700px) {
    .grid { grid-template-columns: repeat(2, 1fr); }
    .card.wide { grid-column: 1 / -1; }
}
@media (min-width: 1100px) {
    .grid { grid-template-columns: repeat(3, 1fr); }
    .card.wide { grid-column: auto / span 3; }
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 18px;
    min-width: 0;
}
.card.unavailable { opacity: 0.55; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.card-head h2 { flex: 1; }
.card-icon {
    display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 12px;
    font-size: 18px; background: var(--card-2);
}
.card-icon.water { color: var(--water); }
.card-icon.heat { color: var(--heat); }
.card-icon.car { color: var(--car); }
.card-icon.sky { color: var(--sky); }

.pill {
    font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 999px;
    background: var(--card-2); color: var(--muted); white-space: nowrap;
}
.pill.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.hot { background: color-mix(in srgb, var(--heat) 18%, transparent); color: var(--heat); }
.pill.cold { background: color-mix(in srgb, var(--water) 18%, transparent); color: var(--water); }

.big {
    font-size: 54px; font-weight: 300; letter-spacing: -0.03em; line-height: 1.05;
    font-variant-numeric: tabular-nums;
}
.big .unit { font-size: 22px; color: var(--muted); margin-left: 4px; letter-spacing: 0; }
.big.small { font-size: 32px; font-weight: 400; margin: 6px 0 4px; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.split .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.split .value { font-size: 18px; font-weight: 550; margin-top: 2px; font-variant-numeric: tabular-nums; }
.split .value.hot-text { color: var(--heat); }

/* Tank temperature scale */
.tank-scale {
    position: relative; height: 6px; border-radius: 3px; margin: 10px 0 6px;
    background: linear-gradient(90deg, #3b6cff, #ffd23f 55%, #ff4d4d);
}
.tank-scale span {
    position: absolute; top: 50%; left: 0; width: 14px; height: 14px; border-radius: 50%;
    background: var(--text); border: 3px solid var(--card); transform: translate(-50%, -50%);
    transition: left 0.6s ease;
}

/* Rows inside a card (immersion, boiler) */
.row {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 0 0; margin-top: 12px; border-top: 1px solid var(--line);
}
.row-icon { font-size: 20px; width: 24px; text-align: center; color: var(--muted); }
.row-icon.on { color: var(--warn); }
.row-icon.water-on { color: var(--water); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-title .muted { font-weight: 400; margin-left: 6px; font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 3px; background: var(--card-2); margin-top: 7px; overflow: hidden; }
.bar span {
    display: block; height: 100%; width: 0; border-radius: 3px;
    background: linear-gradient(90deg, var(--water), var(--accent));
    transition: width 0.6s ease;
}

/* Boost buttons */
.boost-btn {
    display: inline-flex; align-items: center; gap: 7px;
    min-height: 44px; padding: 0 16px; border-radius: 999px; border: 0;
    background: var(--card-2); color: var(--text); font: inherit; font-weight: 600; font-size: 15px;
    cursor: pointer; white-space: nowrap;
}
.boost-btn i { color: var(--muted); }
.boost-btn.active { background: color-mix(in srgb, var(--heat) 22%, var(--card-2)); }
.boost-btn.active i { color: var(--heat); }
.boost-btn:active { transform: scale(0.96); }
.boost-btn[disabled] { opacity: 0.6; cursor: default; }
.boost-btn.busy i { animation: spin 0.8s linear infinite; }

/* Weather */
.weather-now { display: flex; align-items: baseline; gap: 14px; flex-wrap: wrap; }
.weather-cond { font-size: 18px; color: var(--muted); }
.forecast {
    list-style: none; padding: 0; margin: 16px 0 0;
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px;
}
.forecast li {
    background: var(--card-2); border-radius: 14px; padding: 10px 4px; text-align: center;
    display: grid; gap: 4px; font-variant-numeric: tabular-nums;
}
.forecast .day { font-size: 13px; color: var(--muted); font-weight: 600; }
.forecast i { font-size: 22px; color: var(--sky); margin: 2px 0; justify-self: center; }
.forecast .hi { font-weight: 600; }
.forecast .lo { color: var(--muted); font-size: 14px; }
.forecast .rain { font-size: 12px; color: var(--water); min-height: 1.2em; }

/* Messages */
.problems {
    max-width: 1200px; margin: 16px auto 0; color: var(--muted); font-size: 13px;
}
.toast {
    position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom));
    transform: translateX(-50%); max-width: calc(100% - 32px);
    background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px;
    font-size: 15px; box-shadow: 0 8px 30px rgb(0 0 0 / 0.3); z-index: 10;
}
.toast.bad { background: var(--bad); color: #fff; }

/* Sign-in page */
.login-page { display: grid; place-items: center; }
.login-card {
    width: 100%; max-width: 360px; background: var(--card); border-radius: var(--radius);
    padding: 32px 24px; text-align: center;
}
.login-icon { font-size: 40px; color: var(--accent); margin-bottom: 8px; }
.login-card h1 { margin-bottom: 20px; }
.login-card input[type=password] {
    width: 100%; font: inherit; font-size: 17px; padding: 14px 16px; border-radius: 14px;
    border: 1px solid var(--line); background: var(--card-2); color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-error { color: var(--bad); margin: 12px 0 0; font-size: 15px; }
.btn-primary {
    width: 100%; margin-top: 16px; min-height: 50px; border: 0; border-radius: 14px;
    background: var(--accent); color: #fff; font: inherit; font-size: 17px; font-weight: 600; cursor: pointer;
}
.login-card code { background: var(--card-2); padding: 2px 6px; border-radius: 6px; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
