/* --- Theme tokens ------------------------------------------------------ */
:root {
    --bg: #f6f7f8;
    --fg: #1c1f23;
    --surface: #ffffff;
    --border: #e1e3e6;
    --muted: #666666;
    --topbar-bg: #1c1f23;
    --topbar-fg: #ffffff;
    --link: #cfe3ff;
    --input-border: #cccccc;
    --input-bg: #ffffff;
    --input-fg: #1c1f23;
    --button-bg: #1c1f23;
    --button-fg: #ffffff;
    --danger: #aa3333;
    --shadow: rgba(0, 0, 0, 0.1);
    --th-bg: #eef0f2;

    --warning-bg: #fff6e5;
    --warning-fg: #4a3600;
    --ok-bg: #d7efd9;
    --ok-fg: #275c2b;
    --holiday-bg: #eef7ee;
    --holiday-fg: #4a6a4a;
    --pending-bg: #fdeee0;
    --pending-fg: #7a3d0a;

    --cal-empty: #fafafa;
    --cal-plain: #999999;
    --cal-ok: #eef7f0;
    --cal-warning: #fff6e5;
    --cal-pending: #fdeee0;
    --cal-holiday: #eef2f7;
    --cal-holiday-fg: #4a5a6a;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #14161a;
        --fg: #e8eaed;
        --surface: #1c1f24;
        --border: #33373d;
        --muted: #9aa0a6;
        --topbar-bg: #0e0f12;
        --topbar-fg: #e8eaed;
        --link: #8ab4f8;
        --input-border: #4a4f57;
        --input-bg: #22252b;
        --input-fg: #e8eaed;
        --button-bg: #3a3f47;
        --button-fg: #ffffff;
        --danger: #e08585;
        --shadow: rgba(0, 0, 0, 0.4);
        --th-bg: #22252b;

        --warning-bg: #4a3b12;
        --warning-fg: #f5d98b;
        --ok-bg: #1f3a22;
        --ok-fg: #9fdba6;
        --holiday-bg: #1c2e20;
        --holiday-fg: #9fc7a6;
        --pending-bg: #3d2a12;
        --pending-fg: #f2b57a;

        --cal-empty: #191b1f;
        --cal-plain: #6b7076;
        --cal-ok: #1c2b1e;
        --cal-warning: #332a11;
        --cal-pending: #33230f;
        --cal-holiday: #1b232b;
        --cal-holiday-fg: #9fc0c7;
    }
}

:root[data-theme="dark"] {
    --bg: #14161a;
    --fg: #e8eaed;
    --surface: #1c1f24;
    --border: #33373d;
    --muted: #9aa0a6;
    --topbar-bg: #0e0f12;
    --topbar-fg: #e8eaed;
    --link: #8ab4f8;
    --input-border: #4a4f57;
    --input-bg: #22252b;
    --input-fg: #e8eaed;
    --button-bg: #3a3f47;
    --button-fg: #ffffff;
    --danger: #e08585;
    --shadow: rgba(0, 0, 0, 0.4);
    --th-bg: #22252b;

    --warning-bg: #4a3b12;
    --warning-fg: #f5d98b;
    --ok-bg: #1f3a22;
    --ok-fg: #9fdba6;
    --holiday-bg: #1c2e20;
    --holiday-fg: #9fc7a6;
    --pending-bg: #3d2a12;
    --pending-fg: #f2b57a;

    --cal-empty: #191b1f;
    --cal-plain: #6b7076;
    --cal-ok: #1c2b1e;
    --cal-warning: #332a11;
    --cal-pending: #33230f;
    --cal-holiday: #1b232b;
    --cal-holiday-fg: #9fc0c7;
}

/* --- Base --------------------------------------------------------------- */
* { box-sizing: border-box; }
body {
    font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--fg);
}
.topbar {
    background: var(--topbar-bg);
    color: var(--topbar-fg);
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar a { color: var(--link); text-decoration: none; }
.topbar a:hover { text-decoration: underline; }
.who { font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

main {
    max-width: 900px;
    margin: 24px auto;
    padding: 0 16px 48px;
}
section { margin-bottom: 40px; }
h2 { font-size: 16px; margin-bottom: 4px; }
.muted { color: var(--muted); font-size: 13px; }

table.rota, table.fairness {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    margin-top: 12px;
}
table.rota th, table.rota td,
table.fairness th, table.fairness td {
    border: 1px solid var(--border);
    padding: 8px 10px;
    text-align: left;
    font-size: 14px;
    vertical-align: middle;
}
table.rota th, table.fairness th { background: var(--th-bg); }
tr.warning { background: var(--warning-bg); }
tr.holiday { background: var(--holiday-bg); color: var(--holiday-fg); }

.badge { padding: 2px 8px; border-radius: 10px; font-size: 12px; }
.badge-warning { background: var(--warning-bg); color: var(--warning-fg); }
.badge-ok { background: var(--ok-bg); color: var(--ok-fg); }

.inline-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form input[type="text"] { padding: 4px 6px; font-size: 13px; }
.inline-form button, .stacked-form button, form button {
    background: var(--button-bg);
    color: var(--button-fg);
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
.link-button {
    background: none;
    color: var(--danger);
    border: none;
    padding: 0;
    text-decoration: underline;
    cursor: pointer;
    font-size: 13px;
}

.stacked-form {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: 6px;
}
.stacked-form label, form label {
    display: flex;
    flex-direction: column;
    font-size: 13px;
    gap: 4px;
}
.stacked-form input, .stacked-form select,
form input, form select {
    padding: 6px 8px;
    font-size: 14px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--input-fg);
}

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
}
.login-box {
    background: var(--surface);
    padding: 32px;
    border-radius: 8px;
    box-shadow: 0 2px 12px var(--shadow);
    width: 300px;
}
.login-box h1 { font-size: 18px; margin-top: 0; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-box label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; }
.login-box input { padding: 8px; font-size: 14px; border: 1px solid var(--input-border); border-radius: 4px; background: var(--input-bg); color: var(--input-fg); }
.login-box .theme-switch-row { justify-content: center; margin-top: 4px; }
.error { color: var(--danger); font-size: 13px; }

/* --- Theme switch -------------------------------------------------------- */
.theme-switch-row {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}
.theme-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}
.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}
.theme-switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #888;
    border-radius: 20px;
    transition: background 0.15s;
}
.theme-switch .slider::before {
    content: "";
    position: absolute;
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.15s;
}
.theme-switch input:checked + .slider {
    background: #4a7fd6;
}
.theme-switch input:checked + .slider::before {
    transform: translateX(16px);
}

/* --- Calendar view -------------------------------------------------------- */
.cal-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    font-size: 14px;
}
.cal-nav a { color: var(--fg); text-decoration: none; }
.cal-nav a:hover { text-decoration: underline; }

table.calendar {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    background: var(--surface);
}
table.calendar th {
    background: var(--th-bg);
    padding: 6px;
    font-size: 12px;
    text-align: left;
}
table.calendar td {
    border: 1px solid var(--border);
    height: 90px;
    vertical-align: top;
    padding: 6px;
    font-size: 12px;
}
.cal-empty { background: var(--cal-empty); }
.cal-plain { color: var(--cal-plain); }
.cal-daynum { font-weight: 600; margin-bottom: 4px; }
.cal-detail { font-size: 11px; line-height: 1.4; }

.cal-friday.cal-ok { background: var(--cal-ok); }
.cal-friday.cal-warning { background: var(--cal-warning); }
.cal-friday.cal-pending { background: var(--cal-pending); }
.cal-friday.cal-holiday { background: var(--cal-holiday); color: var(--cal-holiday-fg); }
.cal-friday.cal-inactive { background: var(--cal-empty); color: var(--cal-plain); }

.cal-legend { display: flex; align-items: center; gap: 6px; margin-top: 12px; }
.legend-swatch {
    display: inline-block;
    width: 12px; height: 12px;
    border: 1px solid var(--border);
    border-radius: 2px;
    margin-left: 10px;
}
.legend-swatch.cal-ok { background: var(--cal-ok); }
.legend-swatch.cal-warning { background: var(--cal-warning); }
.legend-swatch.cal-pending { background: var(--cal-pending); }
.legend-swatch.cal-holiday { background: var(--cal-holiday); }

/* --- Mark out/in modal --------------------------------------------------- */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-backdrop:not([hidden]) {
    display: flex;
}
.modal {
    background: var(--surface);
    color: var(--fg);
    border-radius: 8px;
    padding: 24px;
    width: 320px;
    box-shadow: 0 4px 24px var(--shadow);
}
.modal h3 { margin-top: 0; font-size: 16px; }
.modal form { display: flex; flex-direction: column; gap: 14px; }
.modal label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; }
.modal input, .modal select {
    padding: 8px;
    font-size: 14px;
    border: 1px solid var(--input-border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--input-fg);
}
.modal-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
}
