/*
 * Home Manager design system
 * Lightweight, mobile-first, no framework. Colors are tokens on :root with a dark variant.
 */

:root {
    color-scheme: light dark;

    --font-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    --color-bg: #f6f4ef;
    --color-surface: #ffffff;
    --color-surface-muted: #f1eee8;
    --color-surface-sunken: #ebe7df;
    --color-border: #e2ddd3;
    --color-border-strong: #cfc8bb;
    --color-text: #1f2421;
    --color-text-muted: #5b625e;
    --color-text-subtle: #7a807c;

    --color-primary: #0f766e;
    --color-primary-hover: #0b5f58;
    --color-primary-soft: #dff2ef;
    --color-primary-contrast: #ffffff;

    --color-accent: #c2620b;
    --color-accent-soft: #fdf0e1;

    --color-success: #1f7a3d;
    --color-success-soft: #e3f4e8;
    --color-warning: #9a5b00;
    --color-warning-soft: #fff3d6;
    --color-danger: #b42318;
    --color-danger-soft: #fde7e5;
    --color-info: #1d5fa8;
    --color-info-soft: #e5effb;

    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;
    --radius-pill: 999px;

    --shadow-sm: 0 1px 2px rgb(31 36 33 / 6%);
    --shadow: 0 1px 2px rgb(31 36 33 / 6%), 0 4px 16px rgb(31 36 33 / 6%);
    --shadow-lg: 0 10px 40px rgb(31 36 33 / 18%);

    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 24px;
    --space-6: 32px;
    --space-7: 48px;

    --topbar-height: 56px;
    --bottomnav-height: 64px;
    --sidebar-width: 260px;
    --content-width: 1080px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
    --safe-right: env(safe-area-inset-right, 0px);

    --focus-ring: 0 0 0 3px rgb(15 118 110 / 35%);
}

@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #121614;
        --color-surface: #1b201e;
        --color-surface-muted: #222826;
        --color-surface-sunken: #161a18;
        --color-border: #2d3431;
        --color-border-strong: #3d4642;
        --color-text: #ecefed;
        --color-text-muted: #b2bab6;
        --color-text-subtle: #8f9894;

        --color-primary: #3cbfb2;
        --color-primary-hover: #5fd3c7;
        --color-primary-soft: #133a36;
        --color-primary-contrast: #06201d;

        --color-accent: #f0a050;
        --color-accent-soft: #3a2a17;

        --color-success: #5cc983;
        --color-success-soft: #173323;
        --color-warning: #f2c14e;
        --color-warning-soft: #3a2f12;
        --color-danger: #ff8a80;
        --color-danger-soft: #3d1c1a;
        --color-info: #7fb2f0;
        --color-info-soft: #172a40;

        --shadow-sm: 0 1px 2px rgb(0 0 0 / 30%);
        --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 16px rgb(0 0 0 / 25%);
        --shadow-lg: 0 10px 40px rgb(0 0 0 / 50%);
        --focus-ring: 0 0 0 3px rgb(60 191 178 / 45%);
    }
}

/* ---------- Base ---------- */

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

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    min-height: 100dvh;
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.55;
    color: var(--color-text);
    background: var(--color-bg);
    -webkit-font-smoothing: antialiased;
}

img,
svg {
    display: block;
    max-width: 100%;
}

svg.icon,
.icon {
    display: inline-block;
    flex-shrink: 0;
    vertical-align: -0.15em;
}

a {
    color: var(--color-primary);
    text-underline-offset: 3px;
}

a:hover {
    color: var(--color-primary-hover);
}

h1,
h2,
h3,
h4 {
    line-height: 1.25;
    margin: 0 0 var(--space-3);
    font-weight: 700;
    letter-spacing: -0.01em;
}

h1 {
    font-size: clamp(1.5rem, 1.2rem + 1.4vw, 2rem);
}

h2 {
    font-size: 1.25rem;
}

h3 {
    font-size: 1.05rem;
}

p {
    margin: 0 0 var(--space-3);
}

:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: var(--space-3);
    top: -100px;
    z-index: 100;
    padding: var(--space-2) var(--space-4);
    background: var(--color-primary);
    color: var(--color-primary-contrast);
    border-radius: var(--radius-sm);
}

.skip-link:focus {
    top: calc(var(--safe-top) + var(--space-2));
}

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

.small {
    font-size: 0.875rem;
}

[hidden] {
    display: none !important;
}

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

.app {
    min-height: 100dvh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: calc(var(--topbar-height) + var(--safe-top));
    padding: var(--safe-top) calc(var(--space-4) + var(--safe-right)) 0 calc(var(--space-4) + var(--safe-left));
    background: color-mix(in srgb, var(--color-bg) 88%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--color-border);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-weight: 750;
    font-size: 1.05rem;
    color: var(--color-text);
    text-decoration: none;
    margin-right: auto;
}

.brand:hover {
    color: var(--color-text);
}

.brand__logo {
    width: 32px;
    height: 32px;
    border-radius: 9px;
}

.icon-button {
    position: relative;
    display: inline-grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-pill);
    color: var(--color-text-muted);
    background: transparent;
    border: 0;
    cursor: pointer;
    text-decoration: none;
    font-size: 1.35rem;
}

.icon-button:hover,
.icon-button[aria-current="page"] {
    background: var(--color-surface-muted);
    color: var(--color-text);
}

.avatar {
    display: inline-grid;
    place-items: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: var(--radius-pill);
    background: var(--color-primary-soft);
    color: var(--color-primary);
    font-weight: 700;
    font-size: 0.85rem;
    letter-spacing: 0.02em;
}

.avatar--sm {
    width: 26px;
    height: 26px;
    font-size: 0.7rem;
}

.avatar--lg {
    width: 56px;
    height: 56px;
    font-size: 1.2rem;
}

.main {
    padding: var(--space-4) calc(var(--space-4) + var(--safe-right)) calc(var(--bottomnav-height) + var(--safe-bottom) + var(--space-6)) calc(var(--space-4) + var(--safe-left));
    max-width: var(--content-width);
    margin: 0 auto;
}

/* Bottom navigation (mobile) */
.bottomnav {
    position: fixed;
    inset: auto 0 0 0;
    z-index: 30;
    display: grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;
    padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
    background: color-mix(in srgb, var(--color-surface) 92%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-top: 1px solid var(--color-border);
}

.bottomnav__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: var(--bottomnav-height);
    padding: var(--space-1);
    color: var(--color-text-subtle);
    text-decoration: none;
    font-size: 0.72rem;
    font-weight: 600;
}

.bottomnav__link .icon {
    font-size: 1.45rem;
    transition: transform 0.15s ease;
}

.bottomnav__link[aria-current="page"] {
    color: var(--color-primary);
}

.bottomnav__link[aria-current="page"] .icon {
    transform: translateY(-1px) scale(1.06);
}

.bottomnav__link:hover {
    color: var(--color-text);
}

/* Sidebar (desktop) */
.sidebar {
    display: none;
}

@media (min-width: 900px) {
    .app {
        display: grid;
        grid-template-columns: var(--sidebar-width) 1fr;
    }

    .sidebar {
        position: sticky;
        top: 0;
        display: flex;
        flex-direction: column;
        gap: var(--space-1);
        height: 100dvh;
        padding: var(--space-5) var(--space-4);
        background: var(--color-surface);
        border-right: 1px solid var(--color-border);
    }

    .sidebar .brand {
        margin: 0 0 var(--space-5) var(--space-2);
        flex-grow: 0;
    }

    .sidebar__link {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: 10px var(--space-3);
        border-radius: var(--radius-sm);
        color: var(--color-text-muted);
        text-decoration: none;
        font-weight: 600;
    }

    .sidebar__link .icon {
        font-size: 1.25rem;
    }

    .sidebar__link:hover {
        background: var(--color-surface-muted);
        color: var(--color-text);
    }

    .sidebar__link[aria-current="page"] {
        background: var(--color-primary-soft);
        color: var(--color-primary);
    }

    .sidebar__section {
        margin: var(--space-4) var(--space-3) var(--space-1);
        font-size: 0.75rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--color-text-subtle);
    }

    .sidebar__user {
        margin-top: auto;
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: var(--space-3);
        border-radius: var(--radius);
        background: var(--color-surface-muted);
    }

    .sidebar__user-name {
        font-weight: 650;
        line-height: 1.2;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar,
    .bottomnav {
        display: none;
    }

    .main {
        padding: var(--space-6) var(--space-6) var(--space-7);
        width: 100%;
    }
}

/* ---------- Page header ---------- */

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-5);
}

.page-header h1 {
    margin: 0;
}

.page-header__lead {
    margin: var(--space-1) 0 0;
    color: var(--color-text-muted);
}

.page-header__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    margin-bottom: var(--space-3);
    color: var(--color-text-muted);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    min-height: 44px;
}

.section {
    margin-bottom: var(--space-6);
}

.section__header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.section__header h2 {
    margin: 0;
}

.section__link {
    font-weight: 600;
    font-size: 0.95rem;
    text-decoration: none;
    white-space: nowrap;
}

/* ---------- Buttons ---------- */

.btn {
    --btn-bg: var(--color-surface);
    --btn-fg: var(--color-text);
    --btn-border: var(--color-border-strong);

    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 44px;
    padding: 10px 18px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--btn-border);
    background: var(--btn-bg);
    color: var(--btn-fg);
    font: inherit;
    font-weight: 650;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
    touch-action: manipulation;
    white-space: nowrap;
}

.btn:hover {
    --btn-bg: var(--color-surface-muted);
    color: var(--btn-fg);
}

.btn:active {
    transform: scale(0.98);
}

.btn .icon {
    font-size: 1.15em;
}

.btn--primary {
    --btn-bg: var(--color-primary);
    --btn-fg: var(--color-primary-contrast);
    --btn-border: var(--color-primary);
}

.btn--primary:hover {
    --btn-bg: var(--color-primary-hover);
    --btn-border: var(--color-primary-hover);
}

.btn--soft {
    --btn-bg: var(--color-primary-soft);
    --btn-fg: var(--color-primary);
    --btn-border: transparent;
}

.btn--soft:hover {
    --btn-bg: color-mix(in srgb, var(--color-primary-soft) 80%, var(--color-primary) 20%);
}

.btn--success {
    --btn-bg: var(--color-success);
    --btn-fg: #fff;
    --btn-border: var(--color-success);
}

.btn--success:hover {
    --btn-bg: color-mix(in srgb, var(--color-success) 85%, #000);
}

.btn--danger {
    --btn-bg: transparent;
    --btn-fg: var(--color-danger);
    --btn-border: color-mix(in srgb, var(--color-danger) 40%, transparent);
}

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

.btn--danger-solid {
    --btn-bg: var(--color-danger);
    --btn-fg: #fff;
    --btn-border: var(--color-danger);
}

.btn--danger-solid:hover {
    --btn-bg: color-mix(in srgb, var(--color-danger) 85%, #000);
}

.btn--ghost {
    --btn-bg: transparent;
    --btn-border: transparent;
    --btn-fg: var(--color-text-muted);
}

.btn--sm {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 0.9rem;
}

.btn--block {
    width: 100%;
}

.btn[disabled],
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}

/* Loading state while Turbo submits a form */
form[aria-busy="true"] .btn[type="submit"],
.btn.is-loading {
    color: transparent !important;
    pointer-events: none;
}

form[aria-busy="true"] .btn[type="submit"]::after,
.btn.is-loading::after {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid var(--btn-fg);
    border-right-color: transparent;
    animation: spin 0.7s linear infinite;
}

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

.button-row {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    align-items: center;
}

.inline-form {
    display: inline;
}

/* Floating action button (mobile) */
.fab {
    position: fixed;
    right: calc(var(--space-4) + var(--safe-right));
    bottom: calc(var(--bottomnav-height) + var(--safe-bottom) + var(--space-4));
    z-index: 25;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 56px;
    padding: 0 22px;
    border-radius: var(--radius-pill);
    background: var(--color-primary);
    color: var(--color-primary-contrast);
    font-weight: 700;
    text-decoration: none;
    box-shadow: var(--shadow-lg);
}

.fab:hover {
    color: var(--color-primary-contrast);
    background: var(--color-primary-hover);
}

.fab .icon {
    font-size: 1.4rem;
}

@media (min-width: 900px) {
    .fab {
        display: none;
    }
}

.hide-mobile {
    display: none !important;
}

@media (min-width: 900px) {
    .hide-mobile {
        display: inline-flex !important;
    }
}

/* ---------- Cards ---------- */

.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: var(--space-4);
}

@media (min-width: 600px) {
    .card {
        padding: var(--space-5);
    }
}

.card--flush {
    padding: 0;
    overflow: hidden;
}

.card--narrow {
    max-width: 560px;
}

.card h2:first-child,
.card h3:first-child {
    margin-top: 0;
}

.stack {
    display: grid;
    gap: var(--space-3);
}

.stack--lg {
    gap: var(--space-5);
}

.grid {
    display: grid;
    gap: var(--space-4);
}

@media (min-width: 640px) {
    .grid--2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 640px) {
    .grid--3 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (min-width: 1100px) {
    .grid--3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* ---------- Greeting / dashboard ---------- */

.hero {
    position: relative;
    overflow: hidden;
    padding: var(--space-5);
    margin-bottom: var(--space-5);
    border-radius: var(--radius-lg);
    /* Fixed dark colors in both themes so the white text keeps its contrast. */
    background:
        radial-gradient(circle at 100% 0%, rgb(242 160 80 / 24%) 0, transparent 45%),
        linear-gradient(135deg, #0f766e 0%, #0b4f80 100%);
    color: #fff;
}

.hero h1 {
    margin-bottom: var(--space-1);
    color: #fff;
}

.hero p {
    margin: 0;
    color: rgb(255 255 255 / 88%);
}

.hero__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-4);
}

.hero .btn {
    --btn-bg: rgb(255 255 255 / 16%);
    --btn-fg: #fff;
    --btn-border: rgb(255 255 255 / 28%);
}

.hero .btn:hover {
    --btn-bg: rgb(255 255 255 / 26%);
}

.hero .btn--light {
    --btn-bg: #fff;
    --btn-fg: #0b4f4a;
    --btn-border: #fff;
}

.hero .btn--light:hover {
    --btn-bg: #f0faf8;
}

.stat-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-2);
    margin-bottom: var(--space-5);
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-3);
    border-radius: var(--radius);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    text-decoration: none;
    color: var(--color-text);
}

.stat:hover {
    border-color: var(--color-border-strong);
    color: var(--color-text);
}

.stat__value {
    font-size: 1.6rem;
    font-weight: 750;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat__label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    font-weight: 600;
}

/* ---------- Notices / banners ---------- */

.notice {
    display: flex;
    gap: var(--space-3);
    align-items: flex-start;
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    background: var(--color-info-soft);
    color: var(--color-text);
    border: 1px solid color-mix(in srgb, var(--color-info) 25%, transparent);
}

.notice > .icon {
    font-size: 1.4rem;
    color: var(--color-info);
    margin-top: 2px;
}

.notice__body {
    flex: 1;
    min-width: 0;
}

.notice__title {
    font-weight: 700;
    margin: 0 0 2px;
}

.notice p:last-child {
    margin-bottom: 0;
}

.notice__actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.notice--warning {
    background: var(--color-warning-soft);
    border-color: color-mix(in srgb, var(--color-warning) 30%, transparent);
}

.notice--warning > .icon {
    color: var(--color-warning);
}

.notice--success {
    background: var(--color-success-soft);
    border-color: color-mix(in srgb, var(--color-success) 30%, transparent);
}

.notice--success > .icon {
    color: var(--color-success);
}

.notice--accent {
    background: var(--color-accent-soft);
    border-color: color-mix(in srgb, var(--color-accent) 25%, transparent);
}

.notice--accent > .icon {
    color: var(--color-accent);
}

/* ---------- Flash messages ---------- */

.flash-stack {
    position: fixed;
    z-index: 60;
    left: 50%;
    top: calc(var(--safe-top) + var(--topbar-height) + var(--space-2));
    transform: translateX(-50%);
    display: grid;
    gap: var(--space-2);
    width: min(560px, calc(100vw - 2 * var(--space-4)));
    pointer-events: none;
}

@media (min-width: 900px) {
    .flash-stack {
        top: var(--space-4);
        left: calc(50% + var(--sidebar-width) / 2);
    }
}

.flash {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-left: 5px solid var(--flash-color, var(--color-info));
    box-shadow: var(--shadow-lg);
    pointer-events: auto;
    animation: flash-in 0.25s ease-out;
}

.flash > .icon {
    font-size: 1.3rem;
    color: var(--flash-color, var(--color-info));
    margin-top: 1px;
}

.flash__message {
    flex: 1;
    font-weight: 550;
}

.flash__close {
    width: 32px;
    height: 32px;
    margin: -4px -4px -4px 0;
    font-size: 1.1rem;
}

.flash--success {
    --flash-color: var(--color-success);
}

.flash--warning {
    --flash-color: var(--color-warning);
}

.flash--error {
    --flash-color: var(--color-danger);
}

.flash.is-leaving {
    opacity: 0;
    transform: translateY(-6px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

@keyframes flash-in {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
}

/* ---------- Badges ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 9px;
    border-radius: var(--radius-pill);
    font-size: 0.78rem;
    font-weight: 650;
    line-height: 1.6;
    background: var(--color-surface-muted);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.badge .icon {
    font-size: 0.95em;
}

.badge--open {
    background: var(--color-info-soft);
    color: var(--color-info);
}

.badge--claimed {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.badge--completed {
    background: var(--color-success-soft);
    color: var(--color-success);
}

.badge--cancelled {
    background: var(--color-surface-muted);
    color: var(--color-text-subtle);
}

.badge--overdue {
    background: var(--color-danger-soft);
    color: var(--color-danger);
}

.badge--soon {
    background: var(--color-warning-soft);
    color: var(--color-warning);
}

.badge--high {
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.badge--admin {
    background: var(--color-accent-soft);
    color: var(--color-accent);
}

.count {
    display: inline-grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: var(--radius-pill);
    background: var(--color-surface-sunken);
    color: var(--color-text-muted);
    font-size: 0.75rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ---------- Tabs (segmented filter) ---------- */

.tabs {
    display: flex;
    gap: var(--space-1);
    padding: 4px;
    margin-bottom: var(--space-4);
    overflow-x: auto;
    scrollbar-width: none;
    background: var(--color-surface-sunken);
    border-radius: var(--radius-pill);
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tabs__tab {
    display: inline-flex;
    flex: 1 0 auto;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 6px 14px;
    border-radius: var(--radius-pill);
    color: var(--color-text-muted);
    text-decoration: none;
    font-weight: 650;
    font-size: 0.92rem;
    white-space: nowrap;
}

.tabs__tab:hover {
    color: var(--color-text);
}

.tabs__tab[aria-current="page"] {
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
}

.tabs__tab[aria-current="page"] .count {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

/* ---------- Task cards ---------- */

.task-list {
    display: grid;
    gap: var(--space-3);
    margin: 0;
    padding: 0;
    list-style: none;
}

.task {
    position: relative;
    display: grid;
    gap: var(--space-2);
    padding: var(--space-4);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: border-color 0.2s ease;
}

.task--overdue {
    border-left: 4px solid var(--color-danger);
}

.task--soon {
    border-left: 4px solid var(--color-warning);
}

.task--done {
    background: var(--color-surface-muted);
}

.task--done .task__title {
    color: var(--color-text-muted);
}

.task--completed .task__title {
    text-decoration: line-through;
    text-decoration-color: color-mix(in srgb, var(--color-text-muted) 60%, transparent);
}

.task__head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

.task__title {
    flex: 1;
    margin: 0;
    font-size: 1.05rem;
    font-weight: 650;
    overflow-wrap: anywhere;
}

.task__title a {
    color: inherit;
    text-decoration: none;
}

.task__title a::after {
    /* whole card clickable, actions stay above */
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
}

.task__title a:focus-visible {
    box-shadow: none;
}

.task__title a:focus-visible::after {
    box-shadow: var(--focus-ring);
}

.task__meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.task__meta-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.task__description {
    margin: 0;
    color: var(--color-text-muted);
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.task__description--clamp {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.task__actions {
    position: relative;
    z-index: 1;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-1);
}

.task__claimer {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 600;
    color: var(--color-primary);
}

.task-detail .task {
    padding: var(--space-5);
}

.task-detail .task__title {
    font-size: 1.4rem;
}

.task-detail .task__description {
    color: var(--color-text);
    font-size: 1.02rem;
}

.task-highlight {
    animation: highlight 1.2s ease-out;
}

@keyframes highlight {
    from {
        box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-primary) 40%, transparent);
    }
}

/* ---------- Handbook ---------- */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.search-field {
    position: relative;
    flex: 1 1 260px;
}

.search-field .icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-subtle);
    font-size: 1.15rem;
    pointer-events: none;
}

.search-field .input {
    padding-left: 42px;
    border-radius: var(--radius-pill);
}

.toolbar .select {
    flex: 0 1 auto;
    width: auto;
    border-radius: var(--radius-pill);
}

.page-cards {
    display: grid;
    gap: var(--space-3);
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
}

.page-card {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.page-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
    border-color: var(--color-border-strong);
}

.page-card__cover {
    aspect-ratio: 16 / 9;
    width: 100%;
    object-fit: cover;
    background: var(--color-surface-muted);
}

.page-card__placeholder {
    display: grid;
    place-items: center;
    aspect-ratio: 16 / 9;
    background:
        linear-gradient(135deg, var(--color-primary-soft), color-mix(in srgb, var(--color-accent-soft) 70%, var(--color-primary-soft)));
    color: var(--color-primary);
    font-size: 2.4rem;
}

.page-card__body {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-4);
    flex: 1;
}

.page-card__title {
    margin: 0;
    font-size: 1.05rem;
}

.page-card__title a {
    color: var(--color-text);
    text-decoration: none;
}

.page-card__title a::after {
    content: "";
    position: absolute;
    inset: 0;
}

.page-card__excerpt {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.92rem;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.page-card__meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-top: auto;
    padding-top: var(--space-2);
    color: var(--color-text-subtle);
    font-size: 0.82rem;
}

.page-list {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

.page-list__item {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.page-list__item:last-child {
    border-bottom: 0;
}

.page-list__item:hover {
    background: var(--color-surface-muted);
}

.page-list__thumb {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    border-radius: 10px;
    object-fit: cover;
    background: var(--color-primary-soft);
    color: var(--color-primary);
    font-size: 1.3rem;
}

.page-list__title {
    font-weight: 650;
    color: var(--color-text);
    text-decoration: none;
}

.page-list__title::after {
    content: "";
    position: absolute;
    inset: 0;
}

.page-list__meta {
    font-size: 0.82rem;
    color: var(--color-text-subtle);
}

/* Article (rendered handbook content) */
.article {
    max-width: 720px;
}

.article__header {
    margin-bottom: var(--space-5);
}

.article__title {
    font-size: clamp(1.7rem, 1.3rem + 1.8vw, 2.4rem);
    margin-bottom: var(--space-3);
}

.article__byline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-3);
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.prose {
    font-size: 1.075rem;
    line-height: 1.7;
    overflow-wrap: break-word;
}

.prose > :first-child {
    margin-top: 0;
}

.prose p,
.prose ul,
.prose ol,
.prose blockquote {
    margin: 0 0 1em;
}

.prose h2 {
    font-size: 1.4rem;
    margin: 1.6em 0 0.6em;
}

.prose h3 {
    font-size: 1.18rem;
    margin: 1.4em 0 0.5em;
}

.prose h4 {
    font-size: 1.05rem;
    margin: 1.2em 0 0.4em;
}

.prose ul,
.prose ol {
    padding-left: 1.4em;
}

.prose li {
    margin: 0.25em 0;
}

.prose li > p {
    margin: 0;
}

.prose blockquote {
    padding: var(--space-3) var(--space-4);
    border-left: 4px solid var(--color-accent);
    background: var(--color-accent-soft);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.prose blockquote > :last-child {
    margin-bottom: 0;
}

.prose img {
    height: auto;
    margin: 1.2em 0;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.prose hr {
    border: 0;
    border-top: 1px solid var(--color-border);
    margin: 2em 0;
}

.prose a {
    font-weight: 550;
}

/* ---------- Editor ---------- */

.editor {
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius);
    background: var(--color-surface);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.editor:focus-within {
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
}

.editor.is-invalid {
    border-color: var(--color-danger);
}

.editor__toolbar {
    position: sticky;
    top: calc(var(--topbar-height) + var(--safe-top));
    z-index: 5;
    display: flex;
    gap: 2px;
    padding: 6px;
    overflow-x: auto;
    scrollbar-width: none;
    background: var(--color-surface-muted);
    border-bottom: 1px solid var(--color-border);
    border-radius: var(--radius) var(--radius) 0 0;
}

.editor__toolbar::-webkit-scrollbar {
    display: none;
}

@media (min-width: 900px) {
    .editor__toolbar {
        top: 0;
        flex-wrap: wrap;
    }
}

.editor__button {
    display: inline-grid;
    place-items: center;
    flex-shrink: 0;
    min-width: 42px;
    height: 42px;
    padding: 0 8px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    font: inherit;
    font-weight: 700;
    font-size: 1.15rem;
    cursor: pointer;
    touch-action: manipulation;
}

.editor__button:hover {
    background: var(--color-surface);
    color: var(--color-text);
}

.editor__button.is-active {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.editor__button:disabled {
    opacity: 0.4;
    cursor: default;
}

.editor__separator {
    width: 1px;
    margin: 6px 4px;
    flex-shrink: 0;
    background: var(--color-border-strong);
}

.editor__content {
    min-height: 280px;
    padding: var(--space-4);
}

.editor__content .tiptap {
    min-height: 260px;
    outline: none;
    box-shadow: none;
}

.editor__content .tiptap p.is-editor-empty:first-child::before {
    content: attr(data-placeholder);
    float: left;
    height: 0;
    color: var(--color-text-subtle);
    pointer-events: none;
}

.editor__content .tiptap img.ProseMirror-selectednode {
    outline: 3px solid var(--color-primary);
}

.editor__status {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-height: 0;
    padding: 0 var(--space-4);
    font-size: 0.875rem;
    color: var(--color-text-muted);
}

.editor__status:not(:empty) {
    padding: var(--space-2) var(--space-4);
    border-top: 1px solid var(--color-border);
}

.editor__status--error {
    color: var(--color-danger);
}

.editor__fallback {
    width: 100%;
}

.link-popover {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface-muted);
}

.link-popover .input {
    flex: 1 1 220px;
}

/* ---------- Forms ---------- */

.form {
    display: grid;
    gap: var(--space-4);
}

.field {
    display: grid;
    gap: 6px;
}

.field__label,
.form-label {
    font-weight: 650;
    font-size: 0.95rem;
}

.field__label .required-mark {
    color: var(--color-text-subtle);
    font-weight: 500;
}

.field__help {
    margin: 0;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.field__errors {
    margin: 0;
    padding: 0;
    list-style: none;
    color: var(--color-danger);
    font-size: 0.875rem;
    font-weight: 600;
}

.field__errors li {
    display: flex;
    gap: 6px;
    align-items: center;
}

.input,
.select,
.textarea {
    width: 100%;
    min-height: 48px;
    padding: 11px 14px;
    border: 1px solid var(--color-border-strong);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font: inherit;
    font-size: 1rem; /* >= 16px avoids iOS zoom on focus */
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    appearance: none;
}

.textarea {
    min-height: 120px;
    resize: vertical;
}

.select {
    padding-right: 40px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a807c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 18px;
}

.input:focus,
.select:focus,
.textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
}

.input[aria-invalid="true"],
.select[aria-invalid="true"],
.textarea[aria-invalid="true"] {
    border-color: var(--color-danger);
}

.input::placeholder,
.textarea::placeholder {
    color: var(--color-text-subtle);
}

.password-field {
    position: relative;
}

.password-field .input {
    padding-right: 52px;
}

.password-field__toggle {
    position: absolute;
    right: 2px;
    top: 50%;
    transform: translateY(-50%);
}

/* Switch style checkbox */
.switch-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3) 0;
}

.switch-row + .switch-row {
    border-top: 1px solid var(--color-border);
}

.switch-row__text {
    display: grid;
    gap: 2px;
}

.switch-row__label {
    font-weight: 650;
    cursor: pointer;
}

.switch {
    position: relative;
    flex-shrink: 0;
    width: 52px;
    height: 32px;
    margin: 0;
    border-radius: var(--radius-pill);
    background: var(--color-border-strong);
    appearance: none;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.switch::before {
    content: "";
    position: absolute;
    top: 3px;
    left: 3px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgb(0 0 0 / 25%);
    transition: transform 0.2s ease;
}

.switch:checked {
    background: var(--color-primary);
}

.switch:checked::before {
    transform: translateX(20px);
}

.switch:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Segmented radio choices (priority) */
.segmented {
    display: flex;
    gap: 4px;
    padding: 4px;
    border-radius: var(--radius-pill);
    background: var(--color-surface-sunken);
    border: 0;
    margin: 0;
}

.segmented__option {
    position: relative;
    flex: 1;
}

.segmented__option input {
    position: absolute;
    opacity: 0;
    inset: 0;
    cursor: pointer;
}

.segmented__option label {
    display: grid;
    place-items: center;
    min-height: 40px;
    border-radius: var(--radius-pill);
    font-weight: 650;
    font-size: 0.92rem;
    color: var(--color-text-muted);
    cursor: pointer;
}

.segmented__option input:checked + label {
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-sm);
}

.segmented__option input:focus-visible + label {
    box-shadow: var(--focus-ring);
}

.form-actions {
    display: flex;
    flex-wrap: wrap-reverse;
    gap: var(--space-2);
    justify-content: flex-end;
    padding-top: var(--space-2);
}

@media (max-width: 599px) {
    .form-actions .btn {
        flex: 1 1 100%;
    }
}

.form-errors {
    margin: 0;
}

/* ---------- Empty states ---------- */

.empty-state {
    display: grid;
    justify-items: center;
    gap: var(--space-2);
    padding: var(--space-6) var(--space-4);
    text-align: center;
    background: var(--color-surface);
    border: 1px dashed var(--color-border-strong);
    border-radius: var(--radius);
}

.empty-state__icon {
    display: grid;
    place-items: center;
    width: 64px;
    height: 64px;
    margin-bottom: var(--space-2);
    border-radius: 50%;
    background: var(--color-primary-soft);
    color: var(--color-primary);
    font-size: 1.9rem;
}

.empty-state__title {
    margin: 0;
    font-size: 1.1rem;
}

.empty-state__text {
    max-width: 420px;
    margin: 0;
    color: var(--color-text-muted);
}

.empty-state .btn {
    margin-top: var(--space-3);
}

/* ---------- Tables (admin) ---------- */

.member-list {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

.member {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
}

.member:last-child {
    border-bottom: 0;
}

.member--inactive {
    opacity: 0.65;
}

.member__name {
    font-weight: 700;
}

.member__email {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.member__badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.member__actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

@media (min-width: 760px) {
    .member {
        grid-template-columns: auto 1fr auto;
    }

    .member__actions {
        grid-column: auto;
        justify-content: flex-end;
    }
}

/* ---------- Settings list ---------- */

.menu-list {
    display: grid;
    margin: 0;
    padding: 0;
    list-style: none;
}

.menu-list__item + .menu-list__item {
    border-top: 1px solid var(--color-border);
}

.menu-list__link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    width: 100%;
    min-height: 56px;
    padding: var(--space-3) var(--space-4);
    color: var(--color-text);
    text-decoration: none;
    font: inherit;
    font-weight: 600;
    background: none;
    border: 0;
    cursor: pointer;
    text-align: left;
}

.menu-list__link:hover {
    background: var(--color-surface-muted);
    color: var(--color-text);
}

.menu-list__link > .icon:first-child {
    font-size: 1.3rem;
    color: var(--color-primary);
}

.menu-list__link > .icon:last-child {
    margin-left: auto;
    color: var(--color-text-subtle);
}

.menu-list__link--danger,
.menu-list__link--danger > .icon:first-child {
    color: var(--color-danger);
}

.device {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) 0;
}

.device + .device {
    border-top: 1px solid var(--color-border);
}

.device > .icon {
    font-size: 1.4rem;
    color: var(--color-text-muted);
}

.device__body {
    flex: 1;
    min-width: 0;
}

.device__name {
    font-weight: 650;
}

/* ---------- Auth pages ---------- */

.auth {
    display: grid;
    place-items: center;
    min-height: 100dvh;
    padding: calc(var(--space-5) + var(--safe-top)) var(--space-4) calc(var(--space-5) + var(--safe-bottom));
    background:
        radial-gradient(circle at 10% 0%, color-mix(in srgb, var(--color-primary) 18%, transparent) 0, transparent 40%),
        radial-gradient(circle at 90% 100%, color-mix(in srgb, var(--color-accent) 16%, transparent) 0, transparent 40%),
        var(--color-bg);
}

.auth__card {
    width: 100%;
    max-width: 420px;
    padding: var(--space-6) var(--space-5);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.auth__logo {
    width: 64px;
    height: 64px;
    margin: 0 auto var(--space-4);
    border-radius: 18px;
    box-shadow: var(--shadow);
}

.auth__title {
    text-align: center;
    margin-bottom: var(--space-1);
}

.auth__lead {
    text-align: center;
    color: var(--color-text-muted);
    margin-bottom: var(--space-5);
}

.checkbox-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.95rem;
}

.checkbox-row input {
    width: 20px;
    height: 20px;
    accent-color: var(--color-primary);
}

/* ---------- Confirm dialog ---------- */

.dialog {
    width: min(420px, calc(100vw - 2 * var(--space-4)));
    padding: 0;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
    background: rgb(15 20 18 / 45%);
    backdrop-filter: blur(2px);
}

.dialog[open] {
    animation: dialog-in 0.18s ease-out;
}

@keyframes dialog-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
}

.dialog__body {
    padding: var(--space-5) var(--space-5) var(--space-3);
}

.dialog__title {
    margin: 0 0 var(--space-2);
    font-size: 1.15rem;
}

.dialog__message {
    margin: 0;
    color: var(--color-text-muted);
}

.dialog__actions {
    display: flex;
    flex-wrap: wrap-reverse;
    gap: var(--space-2);
    justify-content: flex-end;
    padding: var(--space-3) var(--space-5) var(--space-5);
}

@media (max-width: 480px) {
    .dialog__actions .btn {
        flex: 1;
    }
}

/* ---------- Pagination ---------- */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-3);
    margin-top: var(--space-5);
}

/* ---------- Turbo ---------- */

.turbo-progress-bar {
    height: 3px;
    background-color: var(--color-accent);
}

turbo-frame[aria-busy="true"] {
    opacity: 0.6;
    transition: opacity 0.2s ease 0.15s;
}

turbo-frame {
    display: block;
}

/* ---------- Error pages ---------- */

.error-page {
    display: grid;
    justify-items: center;
    gap: var(--space-3);
    padding: var(--space-7) var(--space-4);
    text-align: center;
}

.error-page__code {
    font-size: 3.5rem;
    font-weight: 800;
    line-height: 1;
    color: var(--color-primary);
}

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

/* Dashboard hints (push prompt, install hint): no gap when all of them are hidden. */
.hints {
    margin-bottom: var(--space-5);
}

.hints:not(:has(> :not([hidden]))) {
    display: none;
}
