/* ---------- Bas ---------- */
:root {
    --bg: #121011;
    --surface: #1c1819;
    --surface-raised: #241f20;
    --border: #2c2627;
    --text: #f2edea;
    --text-muted: #9c9391;
    --accent: #ffb938;      /* varmt lampsken */
    --accent-ink: #241603;
    --error: #ff5b4d;
    --imp-3: var(--error);  /* inloggningens röda prickar vid fel pinkod */
    --warn: #e8b25a;        /* inloggningens feltext */
    --blue: #2a46c9;        /* läggdagens blå (Manuell utlösning: Långsam) */
    --radius: 16px;
    --maxw: 520px;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: 'Inter', system-ui, sans-serif;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

.page {
    max-width: var(--maxw);
    margin: 0 auto;
    padding: calc(28px + env(safe-area-inset-top)) 20px calc(40px + env(safe-area-inset-bottom));
    min-height: 100vh;
}

button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* ---------- Rubrik ---------- */
.top { margin-bottom: 26px; }

.title {
    margin: 0;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 32px;
    letter-spacing: -0.01em;
}

.subtitle { margin: 6px 0 0; color: var(--text-muted); font-size: 15px; }

.group-title {
    margin: 0 0 10px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ---------- Meddelanden ---------- */
.notice {
    margin: 0 0 20px;
    padding: 12px 16px;
    border-radius: 12px;
    border: 1px solid var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, var(--surface));
    font-size: 14px;
}

.notice.is-error { border-color: var(--error); background: color-mix(in srgb, var(--error) 10%, var(--surface)); }

/* ---------- Kort (inställning/koppling) ---------- */
.card {
    padding: 20px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 15px;
    line-height: 1.5;
}

.card p { margin: 0 0 14px; color: var(--text-muted); }

.card-title {
    margin: 0 0 8px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 20px;
}

.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 10px; }
.steps code { font-size: 13px; overflow-wrap: anywhere; color: var(--accent); }

.primary-btn,
.submit-btn {
    appearance: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 54px;
    border: 0;
    border-radius: var(--radius);
    background: var(--accent);
    color: var(--accent-ink);
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 17px;
    text-decoration: none;
    cursor: pointer;
}

.primary-btn:active, .submit-btn:active { transform: scale(0.985); }

/* ---------- Tänd / släck alla ---------- */
.controls { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.big-btn {
    appearance: none;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 64px;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid var(--border);
    text-align: left;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 15px;
    line-height: 1.2;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.12s ease, opacity 0.15s ease;
}

.big-btn svg { flex-shrink: 0; width: 22px; height: 22px; }
.big-btn:active { transform: scale(0.97); }
.big-btn:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

.big-on {
    background: radial-gradient(circle at 25% 20%, #ffd27a, var(--accent) 60%);
    border-color: var(--accent);
    color: var(--accent-ink);
    box-shadow: 0 6px 24px rgba(255, 185, 56, 0.14);
}

.big-off { background: var(--surface); color: var(--text); }
.big-off svg { color: var(--text-muted); }

.big-btn.is-busy { opacity: 0.6; cursor: progress; }
.big-btn.is-busy svg { animation: pulse 0.9s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* Normalläge: rad under Tänd/Släck alla. */
.normal-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 12px;
    padding: 10px 10px 10px 16px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
}

.normal-text { margin: 0; font-size: 13.5px; color: var(--text-muted); line-height: 1.35; }

.outline-pill {
    appearance: none;
    flex-shrink: 0;
    height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--border));
    background: transparent;
    color: var(--accent);
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
}

.outline-pill.is-busy { opacity: 0.6; cursor: progress; }
.outline-pill:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

/* ---------- Program ---------- */
.programs { margin-top: 32px; }

.program {
    padding: 18px;
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    transition: border-color 0.2s ease;
}

.program.is-on { border-color: color-mix(in srgb, var(--accent) 45%, var(--border)); }

.program-head { display: flex; align-items: flex-start; gap: 16px; }
.program-text { flex: 1; min-width: 0; }

.program-name {
    margin: 0 0 4px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 19px;
}

.program-desc { margin: 0; color: var(--text-muted); font-size: 14px; line-height: 1.4; }

.program-info {
    list-style: none;
    margin: 14px 0 0;
    padding: 12px 0 0;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 14px;
}

.program-info .is-muted { color: var(--text-muted); }
.program-info .is-error { color: var(--error); }
.program-info .is-active { display: flex; align-items: center; gap: 8px; font-weight: 600; }

.dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 22%, transparent);
}

.program:not(.is-on) .dot { background: var(--text-muted); box-shadow: none; }

.program + .program { margin-top: 12px; }

.program-setup { margin-top: 12px; font-size: 14px; }

.program-setup summary {
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 0;
}

.program-setup .steps { margin: 10px 0 12px; font-size: 14px; line-height: 1.45; }

.hook-url {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 10px 10px 12px;
    border-radius: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
}

.hook-url code {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    overflow-wrap: anywhere;
    color: var(--text-muted);
    user-select: all;
}

.copy-btn {
    appearance: none;
    flex-shrink: 0;
    height: 36px;
    padding: 0 14px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.hook-note { margin: 8px 0 0; color: var(--text-muted); font-size: 12.5px; }

.test-btn {
    appearance: none;
    margin-top: 12px;
    height: 40px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--accent) 50%, var(--border));
    background: transparent;
    color: var(--accent);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}

.test-btn.is-busy { opacity: 0.6; cursor: progress; }

.program-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-top: 12px;
}

.program-actions .test-btn { margin-top: 0; }

/* Gul pill-knapp (t.ex. "Manuell utlösning"). */
.pill-btn {
    appearance: none;
    height: 40px;
    padding: 0 18px;
    border: 0;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-ink);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.pill-btn:active { transform: scale(0.97); }
.pill-btn:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }

/* ---------- Popup ---------- */
.dialog {
    width: min(400px, calc(100% - 32px));
    padding: 22px 20px 16px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}

.dialog::backdrop {
    background: rgba(8, 6, 7, 0.65);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.dialog[open] { animation: dialog-in 0.18s ease-out; }
@keyframes dialog-in { from { transform: translateY(12px) scale(0.98); opacity: 0; } }

.dialog-title {
    margin: 0 0 4px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 21px;
}

.dialog-text { margin: 0 0 18px; color: var(--text-muted); font-size: 14px; }

.dialog-choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.choice-btn {
    appearance: none;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    min-height: 104px;
    padding: 14px;
    border: 0;
    border-radius: 18px;
    text-align: left;
    cursor: pointer;
    touch-action: manipulation;
    transition: transform 0.12s ease, opacity 0.15s ease;
}

.choice-btn:active { transform: scale(0.97); }
.choice-btn:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.choice-btn.is-busy { opacity: 0.6; cursor: progress; }
.choice-btn.is-busy .choice-label { animation: pulse 0.9s ease-in-out infinite; }

.choice-label { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 19px; }
.choice-sub { font-size: 13px; line-height: 1.3; opacity: 0.85; }

.choice-now {
    background: radial-gradient(circle at 25% 20%, #ffd27a, var(--accent) 60%);
    color: var(--accent-ink);
}

.choice-slow {
    background: radial-gradient(circle at 25% 20%, #5b7cff, var(--blue) 65%);
    color: #fff;
}

.dialog-cancel {
    appearance: none;
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 12px;
    border: 0;
    background: none;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
}

/* Strömbrytare i iOS-stil. */
.switch {
    appearance: none;
    flex-shrink: 0;
    position: relative;
    width: 52px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: var(--surface-raised);
    box-shadow: inset 0 0 0 1px var(--border);
    cursor: pointer;
    transition: background 0.2s ease;
}

.switch-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--text);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    transition: transform 0.2s ease;
}

.switch[aria-checked="true"] { background: var(--accent); box-shadow: none; }
.switch[aria-checked="true"] .switch-knob { transform: translateX(20px); background: #fff; }
.switch:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.switch:disabled { opacity: 0.7; }

.empty {
    margin: 0;
    padding: 24px 20px;
    text-align: center;
    border-radius: var(--radius);
    border: 1px dashed var(--border);
    color: var(--text-muted);
    font-size: 15px;
}

.link-btn {
    appearance: none;
    display: block;
    margin: 40px auto 0;
    padding: 8px 4px;
    border: 0;
    background: none;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: calc(28px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    margin: 0;
    padding: 12px 18px;
    border-radius: 999px;
    background: var(--surface-raised);
    border: 1px solid var(--accent);
    color: var(--text);
    font-size: 14px;
    max-width: calc(100% - 40px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.toast.is-error { border-color: var(--error); }

/* ---------- Inloggningens textfält (utan JS) ---------- */
.text-input {
    width: 100%;
    padding: 15px 16px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 17px;
}

.text-input:focus { outline: none; border-color: var(--accent); }

/* ---------- Logga in ---------- */
.login-form {
    max-width: 320px;
    margin: 10vh auto 0;
    text-align: center;
}

.login-title {
    margin: 0 0 6px;
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 30px;
}

.pin-prompt {
    margin: 0 0 22px;
    font-size: 15px;
    color: var(--text-muted);
}

/* Med JS: prickar + knappsats. Utan JS: vanligt sifferfält + knapp. */
.pin-input { text-align: center; letter-spacing: 0.4em; margin-bottom: 16px; }
.pin-dots,
.pin-pad { display: none; }
.js .pin-input,
.js .pin-submit { display: none; }
.js .pin-dots { display: flex; }
.js .pin-pad { display: grid; }

.pin-dots {
    justify-content: center;
    gap: 18px;
}

.pin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--text-muted);
    transition: background 0.12s ease, border-color 0.12s ease, transform 0.12s ease;
}

.pin-dot.is-filled {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.08);
}

.pin-dots.is-error { animation: pin-shake 0.4s ease; }
.pin-dots.is-error .pin-dot { border-color: var(--imp-3); }

@keyframes pin-shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-10px); }
    40%, 80% { transform: translateX(10px); }
}

.pin-error {
    min-height: 20px;
    margin: 16px 0 18px;
    font-size: 14px;
    color: var(--warn);
}

.pin-pad {
    grid-template-columns: repeat(3, 76px);
    justify-content: center;
    gap: 16px 24px;
}

.pin-key {
    appearance: none;
    width: 76px;
    height: 76px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 500;
    font-size: 30px;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    touch-action: manipulation; /* ingen dubbeltrycks-zoom vid snabba tryck */
    transition: background 0.1s ease, transform 0.1s ease;
}

.pin-key:active { background: var(--surface-raised); transform: scale(0.94); }
.pin-key:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.pin-key-erase { background: transparent; border-color: transparent; color: var(--text-muted); }
.pin-key-erase svg { width: 28px; height: 28px; }

.is-sending .pin-pad { opacity: 0.5; pointer-events: none; }

@media (max-width: 360px) {
    .pin-pad { grid-template-columns: repeat(3, 68px); gap: 14px 20px; }
    .pin-key { width: 68px; height: 68px; }
}

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

/* ---------- Redundansljus ---------- */
/* Överst på sidan medan lamporna blinkar. */
.alarm-banner {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 20px;
    padding: 14px 14px 14px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--text);
    background: color-mix(in srgb, var(--text) 10%, var(--surface));
}

.alarm-text { flex: 1; margin: 0; display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 15px; }
.alarm-banner .dot { background: var(--text); box-shadow: 0 0 0 4px color-mix(in srgb, var(--text) 22%, transparent); animation: alarm-blink 2s steps(1) infinite; }

@keyframes alarm-blink { 50% { opacity: 0.15; } }

.alarm-btn {
    appearance: none;
    flex-shrink: 0;
    height: 44px;
    padding: 0 20px;
    border: 0;
    border-radius: 999px;
    background: var(--text);
    color: var(--bg);
    font-family: 'Space Grotesk', sans-serif;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
}

.alarm-btn.is-busy { opacity: 0.6; cursor: progress; }
.alarm-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.alarm-btn-card { margin-top: 12px; width: 100%; }

.alarm-times { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.alarm-time {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 14px;
}

.alarm-time input {
    min-width: 108px;
    height: 38px;
    padding: 0 10px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text);
    font: inherit;
    color-scheme: dark;
}

.alarm-time input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
