/* ---------------------------------------------------------------- tokens */

:root {
    color-scheme: light dark;

    --bg: light-dark(#f1f3f6, #14171c);

    --surface: light-dark(#ffffff, #1c2027);
    --surface-sunken: light-dark(#f7f8fa, #171a20);
    --surface-raised: light-dark(#ffffff, #22272f);

    --border: light-dark(#e2e5eb, #2d333d);
    --border-strong: light-dark(#cbd0d9, #3d444f);

    --text: light-dark(#1f2328, #e6e9ee);
    --text-muted: light-dark(#656d76, #9198a1);

    /* Neutral chrome, so the only saturated colours are the four people. */
    --accent: light-dark(#334155, #94a3b8);
    --accent-ink: light-dark(#ffffff, #14171c);
    --weekend: light-dark(#b45309, #dfa74d);

    --shadow-sm: 0 1px 2px light-dark(rgba(27, 31, 36, .05), rgba(0, 0, 0, .3));
    --shadow-md: 0 2px 6px light-dark(rgba(27, 31, 36, .09), rgba(0, 0, 0, .4));

    --r-lg: 12px;
    --r-md: clamp(5px, 1.2vw, 8px);
    --r-sm: 6px;

    --gap: clamp(3px, .75vw, 9px);
    --pad: clamp(3px, .95vw, 9px);
}

:root[data-theme="light"] { color-scheme: only light; }
:root[data-theme="dark"] { color-scheme: only dark; }

/* one fixed colour per person, per scheme */
.user-bojan { --u: light-dark(#d14a4a, #ff6f61); }
.user-toni  { --u: light-dark(#0061f2, #4d9cfa); }
.user-pavle { --u: light-dark(#1b9e4d, #67d68d); }
.user-laste { --u: light-dark(#f57c00, #ffb74d); }

/* ------------------------------------------------------------------ base */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

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

body {
    min-height: 100dvh;
    font-family: 'Segoe UI', system-ui, -apple-system, 'Inter', Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

button, input, select {
    font: inherit;
    color: inherit;
}

:where(button, input, select, a):focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ------------------------------------------------------------------ shell */

.page {
    min-height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: clamp(10px, 3vw, 40px) clamp(8px, 2.5vw, 32px) clamp(24px, 5vw, 48px);
}

.calendar-container {
    width: min(1120px, 100%);
    display: flex;
    flex-direction: column;
    gap: clamp(12px, 2.2vw, 22px);
    padding: clamp(12px, 2.4vw, 26px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-md);
}

/* ---------------------------------------------------------------- app bar */

.app-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.brand {
    display: flex;
    align-items: center;
    gap: clamp(8px, 1.6vw, 13px);
    min-width: 0;
}

.brand-icon {
    display: grid;
    place-items: center;
    flex: none;
    width: clamp(34px, 8vw, 44px);
    aspect-ratio: 1;
    border-radius: var(--r-md);
    color: var(--accent-ink);
    background: var(--accent);
}

.brand-icon svg {
    width: 58%;
}

.brand h1 {
    font-size: clamp(1rem, 3.6vw, 1.3rem);
    font-weight: 600;
    line-height: 1.15;
}

/* ---------------------------------------------------------------- buttons */

.icon-btn,
.arrow-btn {
    display: grid;
    place-items: center;
    flex: none;
    width: clamp(36px, 9vw, 44px);
    aspect-ratio: 1;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface-raised);
    color: var(--text);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background-color .2s ease, border-color .2s ease, transform .15s ease, color .2s ease;
}

.icon-btn svg,
.arrow-btn svg {
    width: 52%;
}

.icon-btn { border-radius: var(--r-md); }

.icon-moon { display: none; }

:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .icon-sun { display: none; }
    :root:not([data-theme="light"]) .icon-moon { display: block; }
}

.mode-switch {
    display: flex;
    gap: 2px;
    padding: 3px;
    margin: 0 auto 12px;
    width: fit-content;
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

.mode-switch button {
    font: inherit;
    font-size: .85rem;
    padding: 6px 14px;
    border: 0;
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
}

.mode-switch button[aria-pressed="true"] {
    background: var(--accent);
    color: var(--accent-ink);
}

.ghost-btn {
    padding: .3em .85em;
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    background: transparent;
    color: var(--text-muted);
    font-size: clamp(.66rem, 2.3vw, .78rem);
    font-weight: 600;
    cursor: pointer;
    transition: background-color .2s ease, color .2s ease, border-color .2s ease;
}

@media (hover: hover) {
    .icon-btn:hover,
    .arrow-btn:hover {
        background: var(--surface-sunken);
        border-color: var(--border-strong);
    }

    .ghost-btn:hover {
        background: var(--surface-sunken);
        border-color: var(--border-strong);
        color: var(--text);
    }
}

.icon-btn:active,
.arrow-btn:active { transform: scale(.94); }

/* --------------------------------------------------------- month switcher */

.calendar-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: clamp(6px, 2vw, 16px);
}

.month-title {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    min-width: 0;
}

.month-title h2 {
    font-size: clamp(1.05rem, 4.4vw, 1.65rem);
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.1;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.ghost-btn.is-current {
    visibility: hidden;
}

/* ----------------------------------------------------------------- grid */

.calendar {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: var(--gap);
    padding: var(--gap);
    background: var(--surface-sunken);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
}

.weekday {
    padding-block: clamp(2px, 1vw, 7px);
    text-align: center;
    font-size: clamp(.6rem, 2.1vw, .78rem);
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.weekday.is-weekend { color: var(--weekend); }

.day {
    display: flex;
    flex-direction: column;
    gap: clamp(2px, .6vw, 5px);
    min-height: clamp(3.5rem, 13.5vw, 6.5rem);
    padding: var(--pad);
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    transition: border-color .15s ease;
}

.day .date {
    align-self: flex-start;
    font-size: clamp(.8rem, 3.1vw, 1.15rem);
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}

.day.weekend {
    background: color-mix(in srgb, var(--weekend) 10%, var(--surface-raised));
    border-color: color-mix(in srgb, var(--weekend) 26%, var(--border));
}

.day.weekend .date { color: var(--weekend); }

.day.today {
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.day.today .date {
    padding: .18em .5em;
    margin: -.1em 0 -.05em -.15em;
    border-radius: 999px;
    background: var(--accent);
    color: var(--accent-ink);
}

.day.blank {
    background: none;
    border-color: transparent;
    min-height: 0;
}

@media (hover: hover) {
    .day:not(.blank):hover {
        border-color: var(--border-strong);
    }
}

/* ----------------------------------------------------------------- chips */

.shifts {
    display: flex;
    flex-direction: column;
    gap: clamp(1px, .4vw, 4px);
    min-width: 0;
}

.shift-chip {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .35em;
    padding: .16em .5em;
    border-radius: var(--r-sm);
    font-size: clamp(.58rem, 2.2vw, .78rem);
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    background: color-mix(in srgb, var(--u, var(--accent)) 14%, transparent);
    color: color-mix(in srgb, var(--u, var(--accent)) 85%, var(--text));
}

.shift-chip .chip-shift {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.chip-abbr,
.weekday .wd-abbr { display: none; }

/* ---------------------------------------------------------------- legend */

.legend {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px clamp(10px, 2.5vw, 18px);
}

.legend li {
    display: inline-flex;
    align-items: center;
    gap: .45em;
    font-size: clamp(.68rem, 2.4vw, .8rem);
    font-weight: 600;
    color: var(--text-muted);
}

.legend .dot {
    width: .62em;
    aspect-ratio: 1;
    border-radius: 50%;
    background: var(--u, var(--accent));
}

/* ------------------------------------------------------------------ form */

.input-container {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: center;
    gap: clamp(8px, 1.6vw, 12px);
    padding-top: clamp(10px, 2vw, 16px);
    border-top: 1px solid var(--border);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    flex: 1 1 130px;
    min-width: 0;
    max-width: 190px;
    text-align: left;
}

.field label {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .07em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.input-container select,
.input-container input {
    width: 100%;
    padding: .62em .8em;
    font-size: clamp(.8rem, 2.6vw, .92rem);
    background: var(--surface-raised);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease;
}

.input-container select {
    appearance: none;
    padding-right: 2em;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: right 1.05em center, right .75em center;
    background-size: .32em .32em, .32em .32em;
    background-repeat: no-repeat;
    cursor: pointer;
}

.input-container select:focus,
.input-container input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}

.input-container button[type="submit"] {
    padding: .68em 1.6em;
    border: none;
    border-radius: var(--r-sm);
    background: var(--accent);
    color: var(--accent-ink);
    font-size: clamp(.8rem, 2.6vw, .92rem);
    font-weight: 700;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: filter .2s ease, transform .15s ease;
}

@media (hover: hover) {
    .input-container button[type="submit"]:hover { filter: brightness(1.1); }
}

.input-container button[type="submit"]:active { transform: scale(.97); }

/* ----------------------------------------------------------- small screens */

@media (max-width: 620px) {
    .chip-name,
    .weekday .wd-full { display: none; }

    .chip-abbr,
    .weekday .wd-abbr { display: inline; }

    .shift-chip {
        justify-content: center;
        gap: .28em;
        padding-inline: .3em;
    }

    .legend {
        gap: 5px 12px;
        padding-inline: 4px;
    }
}

@media (max-width: 400px) {
    .field { max-width: none; flex-basis: 100%; }

    .input-container button[type="submit"] { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        transition-duration: .01ms !important;
        animation-duration: .01ms !important;
    }
}
