/* ===== Tokens ===== */
:root {
    --bg: #f4f6f3;
    --surface: #ffffff;
    --surface-2: #eef2ec;
    --border: #dde3da;
    --text: #1d2420;
    --muted: #65706a;
    --accent: #2f7d4f;
    --accent-strong: #236140;
    --accent-soft: #e2f1e7;
    --water: #2b7bbf;
    --water-soft: #e1eefa;
    --danger: #b3412f;
    --danger-soft: #fbe9e5;
    --warn: #9a6a00;
    --warn-soft: #fdf3d8;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 2px 8px rgba(0, 0, 0, .04);
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121614;
        --surface: #1b211e;
        --surface-2: #232b27;
        --border: #2f3934;
        --text: #e6ece8;
        --muted: #98a39d;
        --accent: #4fae78;
        --accent-strong: #6cc792;
        --accent-soft: #1f3a2a;
        --water: #5aa6e6;
        --water-soft: #1b3042;
        --danger: #e07a68;
        --danger-soft: #3d221d;
        --warn: #e0b354;
        --warn-soft: #3a3020;
        --shadow: none;
        color-scheme: dark;
    }
}

/* ===== Base ===== */
*, *::before, *::after { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; outline: none; }
h2 { font-size: 1.1rem; margin: 1.5rem 0 .75rem; }

a { color: var(--accent); }

code { font-size: .9em; }

.muted { color: var(--muted); }
.small { font-size: .875rem; }

/* ===== Layout ===== */
.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: .4rem;
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--text);
    text-decoration: none;
}

.brand img { width: 30px; height: 30px; }

.auth-logo { display: block; width: 88px; height: 88px; margin: 0 auto .5rem; }

.nav { display: flex; gap: .25rem; margin-left: auto; overflow-x: auto; }

.nav a {
    padding: .4rem .75rem;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    font-size: .95rem;
}

.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }

/* Language box */
.lang-form { margin-left: auto; }
.nav + select.lang, .nav ~ .lang { margin-left: 0; }

select.lang {
    width: auto;
    min-height: 32px;
    padding: .2rem 1.6rem .2rem .55rem;
    border-radius: 8px;
    font-size: .85rem;
    font-weight: 600;
    flex: none;
}

.user {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--surface-2);
    flex: none;
}

.user svg { width: 18px; height: 18px; fill: var(--muted); }
.user:hover svg { fill: var(--text); }

.page { max-width: 760px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: .75rem;
}

.stack { display: flex; flex-direction: column; gap: .75rem; }
.row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1 1 auto; min-width: 0; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    min-height: 40px;
    padding: .45rem 1rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn-water { background: var(--water); border-color: var(--water); color: #fff; }
.btn-water:hover { filter: brightness(.95); background: var(--water); }

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }

.btn-block { width: 100%; }
.btn-sm { min-height: 32px; padding: .25rem .65rem; font-size: .875rem; }

.icon-btn {
    border: 0;
    background: none;
    color: var(--muted);
    cursor: pointer;
    padding: .25rem;
    border-radius: 6px;
    font: inherit;
}

.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ===== Forms ===== */
label { font-weight: 600; font-size: .9rem; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .9rem; }

input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], select {
    width: 100%;
    min-height: 40px;
    padding: .45rem .65rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
}

input:focus, select:focus, .btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }

.check { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; cursor: pointer; }

.validation-message, .field-error { color: var(--danger); font-size: .85rem; }

/* ===== Alerts & badges ===== */
.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.alert-info { background: var(--water-soft); }
.alert-warn { background: var(--warn-soft); color: var(--warn); }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-ok { background: var(--accent-soft); color: var(--accent-strong); }
.alert ul { margin: .25rem 0 0; padding-left: 1.2rem; }

.badge {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .15rem .6rem;
    border-radius: 999px;
    font-size: .8rem;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--muted);
    white-space: nowrap;
}

.badge-ok { background: var(--accent-soft); color: var(--accent-strong); }
.badge-water { background: var(--water-soft); color: var(--water); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ===== Dashboard ===== */
.summary { margin-bottom: .75rem; min-height: 32px; }

.channel { display: flex; flex-direction: column; gap: .6rem; border-left: 4px solid var(--border); }
.channel.on { border-left-color: var(--water); }

.channel-name { font-weight: 650; font-size: 1.05rem; overflow-wrap: anywhere; }

.name-row { gap: .45rem; flex-wrap: nowrap; }

/* Channel number next to every channel name */
.ch-no {
    flex: none;
    min-width: 1.4em;
    padding: 0 .3em;
    border-radius: 6px;
    background: var(--surface-2);
    color: var(--muted);
    font-size: .85em;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.chip .ch-no { margin-right: .35em; background: var(--surface); }

/* Drag to reorder */
.drag-handle {
    flex: none;
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    margin: -.25rem 0 -.25rem -.4rem;
    border: 0;
    border-radius: 8px;
    background: none;
    color: var(--muted);
    cursor: grab;
    touch-action: none;
}

.drag-handle:hover { background: var(--surface-2); color: var(--text); }
.drag-handle:active { cursor: grabbing; }

.channels.sorting { user-select: none; }
.channels.sorting > .channel:not(.dragging) { transition: transform .15s ease; }
.channel.dragging { position: relative; z-index: 5; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); }

.progress { height: 6px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > div { height: 100%; background: var(--water); border-radius: inherit; transition: width 1s linear; }

.controls { row-gap: .5rem; }

.run { gap: .35rem; flex-wrap: nowrap; }
.run input[type=number] { width: 5.5rem; min-height: 32px; padding: .25rem .5rem; text-align: right; }

/* ===== Programs ===== */
.empty { text-align: center; padding: 2rem 1rem; }
.empty p { margin: 0 0 .5rem; }

.program { display: flex; flex-direction: column; gap: .5rem; }
.program.disabled { opacity: .6; }
.program-name { font-weight: 650; font-size: 1.05rem; color: var(--text); text-decoration: none; overflow-wrap: anywhere; }
.program-name:hover { text-decoration: underline; }
.time { font-weight: 700; font-variant-numeric: tabular-nums; }

.steps-summary { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { padding: .15rem .55rem; border-radius: 999px; background: var(--surface-2); font-size: .8rem; white-space: nowrap; }

/* Toggle switch */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background .15s; pointer-events: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Editor */
.label { font-weight: 600; font-size: .9rem; }

.days { display: flex; gap: .3rem; flex-wrap: wrap; }
.day {
    min-width: 44px;
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
    font: inherit;
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
}
.day.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.link-btn { border: 0; background: none; padding: 0; color: var(--accent); font: inherit; cursor: pointer; text-decoration: underline; }

.step { display: grid; grid-template-columns: auto 1fr; gap: .5rem .75rem; align-items: center; }
.step-no { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--water-soft); color: var(--water); font-weight: 700; font-size: .85rem; }
.step .duration, .step .step-actions { grid-column: 2; }
.step .duration { gap: .35rem; flex-wrap: nowrap; }
.step .duration input { width: 4.5rem; text-align: right; }
.step .step-actions { justify-content: flex-end; }

@media (min-width: 600px) {
    .step { grid-template-columns: auto 1fr auto auto; }
    .step .duration, .step .step-actions { grid-column: auto; }
}

.form-actions { margin-top: 1.25rem; }

/* ===== Users ===== */
.user-row { display: flex; flex-direction: column; gap: .4rem; }
.user-email { font-weight: 600; overflow-wrap: anywhere; }

.invite-link { display: flex; gap: .5rem; }
.invite-link input { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }
.invite { padding-top: .5rem; border-top: 1px solid var(--border); flex-wrap: nowrap; }

/* ===== Auth pages ===== */
.auth { max-width: 400px; margin: 2rem auto; }
.auth .card { padding: 1.5rem; }
.prose { max-width: 640px; margin: 1rem auto; }
.prose li { margin-bottom: .4rem; }

.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .85rem; margin: 1rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ===== Blazor error UI ===== */
#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: .75rem 1rem;
    background: var(--warn-soft);
    color: var(--warn);
    z-index: 1000;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 1rem; }
