/* ============================================================
   VARIABLES
   ============================================================ */
:root {
    /* ── Accent ──
       Single source of truth for the interactive brand color. Color themes
       (pink/blue/red/…) override just these four; every brand token below and
       the buttons derive their shades from them via color-mix(). */
    --accent: #4DA49C;
    --accent-light: #6BC7BC;
    --accent-hover: #3C8982;
    --accent-strong: #2d736d;

    /* Brand (derived from --accent so a single override recolors the app) */
    --color-primary: var(--accent);
    --color-primary-dark: var(--accent-strong);
    --color-primary-bg: #eeeee4;
    --color-qs-teal: var(--accent);
    --color-qs-teal-light: var(--accent-light);
    --color-qs-coral: #D85A30;
    --color-qs-coral-light: #F1987A;
    --color-qs-blue: #0c447c;
    --color-qs-blue-light: #378ADD;
    --color-qs-teal-hover: var(--accent-hover);
    --color-qs-picker-hover: color-mix(in srgb, var(--accent) 8%, transparent);
    --color-qs-picker-focused: color-mix(in srgb, var(--accent) 22%, transparent);

    /* Surfaces */
    --color-header-bg: #fffdf8;
    --color-sidebar-bg: #ffffff;
    --color-content-bg: #fcfcf9;
    --color-footer-bg: #fffdf8;
    --color-card-bg: #fffdf8;
    --color-card-hover-bg: #f1f0ec;

    /* Borders & text */
    --color-border: #edebe9;
    --color-text: #201f1e;
    --color-text-muted: #605e5c;

    /* Accents */
    --color-accent-dev: #ea6a00;
    --color-danger: #a4262c;
    --color-danger-bg: #fde7e9;

    /* Semantic status — success / info (danger lives above).
       These are the only status colors that need explicit dark variants
       (see the dark blocks); pink/red themes leave them untouched. */
    --color-success: #1f8a4c;
    --color-success-bg: #dcfce7;
    --color-info: var(--color-qs-blue);
    --color-info-bg: #dbeafe;
    --color-warning: #b45309;
    --color-warning-bg: #fef3c7;

    /* ── Compatibility aliases ──
       Module CSS grew a second vocabulary of token names (surface/bg/hover/…).
       Rather than hardcode fallbacks per file, alias them onto the core tokens
       here — because each is `var(--core-token)`, they follow light/dark/theme
       automatically with no per-theme redefinition. */
    --color-surface: var(--color-card-bg);
    --color-surface-alt: var(--color-card-hover-bg);
    --color-bg: var(--color-content-bg);
    --color-bg-alt: var(--color-card-hover-bg);
    --color-hover: var(--color-card-hover-bg);
    --color-text-primary: var(--color-text);
    --color-text-secondary: var(--color-text-muted);
    --color-error: var(--color-danger);
    --color-primary-light: var(--color-primary-bg);
    --color-primary-faint: var(--color-primary-bg);

    /* Layout dimensions */
    --sidebar-width: 200px;
    --sidebar-collapsed-width: 80px;
    --launcher-width: 10vw;
    --header-height: 60px;
    --footer-height: 56px;
    --main-padding: 30px;
    --main-border-radius: 15px;

    /* Typography */
    --font-main: 'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
}

/* ============================================================
   DARK MODE
   Explicit choice (data-theme="dark") always wins. "system" (or no
   preference yet) follows the OS via prefers-color-scheme.
   Brand colors (--color-qs-teal / -teal-light / -coral / -blue / -teal-hover)
   are intentionally left untouched — only surfaces/text/derived tokens change.
   ============================================================ */
:root[data-theme="dark"] {
    --color-primary-dark: var(--color-qs-teal-light);
    --color-primary-bg: rgba(77, 164, 156, 0.18);

    /* Elevated surfaces (header/sidebar/cards) sit clearly above the canvas
       so the UI reads as layered rather than dark-on-dark. */
    --color-header-bg: #1a2431;
    --color-sidebar-bg: #1a2431;
    --color-content-bg: #101922;
    --color-footer-bg: #1a2431;
    --color-card-bg: #1a2431;
    --color-card-hover-bg: #253243;

    --color-border: #33414f;
    --color-text: #eef2f6;
    --color-text-muted: #a3b1bf;

    --color-danger: #e5636a;
    --color-danger-bg: rgba(164, 38, 44, 0.22);

    --color-success: #4ade80;
    --color-success-bg: rgba(31, 138, 76, 0.24);
    --color-info: #7fb2e8;
    --color-info-bg: rgba(24, 95, 165, 0.28);
    --color-warning: #e0a13a;
    --color-warning-bg: rgba(180, 83, 9, 0.24);
}

@media (prefers-color-scheme: dark) {

    :root[data-theme="system"],
    :root:not([data-theme]) {
        --color-primary-dark: var(--color-qs-teal-light);
        --color-primary-bg: rgba(77, 164, 156, 0.18);

        --color-header-bg: #1a2431;
        --color-sidebar-bg: #1a2431;
        --color-content-bg: #101922;
        --color-footer-bg: #1a2431;
        --color-card-bg: #1a2431;
        --color-card-hover-bg: #253243;

        --color-border: #33414f;
        --color-text: #eef2f6;
        --color-text-muted: #a3b1bf;

        --color-danger: #e5636a;
        --color-danger-bg: rgba(164, 38, 44, 0.22);

        --color-success: #4ade80;
        --color-success-bg: rgba(31, 138, 76, 0.24);
        --color-info: #7fb2e8;
        --color-info-bg: rgba(24, 95, 165, 0.28);
        --color-warning: #e0a13a;
        --color-warning-bg: rgba(180, 83, 9, 0.24);
    }
}

/* ============================================================
   COLOR THEMES (light, pastel)
   Standalone themes selectable alongside light/dark. Each retints the
   canvas + surfaces softly and overrides the four --accent tokens; all
   interactive brand color and buttons follow automatically.
   ============================================================ */
:root[data-theme="pink"] {
    --accent: #df4a80;
    --accent-light: #f3a0c1;
    --accent-hover: #c93d6d;
    --accent-strong: #a83059;
    /* Pink is red-family, so a red danger would blend with the accent —
       danger uses amber-orange, which stays unmistakably "danger" while
       clearly separating from the rosy accent. */
    --color-danger: #d97706;
    --color-danger-bg: #fbe8d1;
    --color-primary-bg: #f9dae7;
    --color-header-bg: #fff8fb;
    --color-sidebar-bg: #fffafc;
    --color-content-bg: #fcedf4;
    --color-footer-bg: #fff8fb;
    --color-card-bg: #fff8fb;
    --color-card-hover-bg: #fae1ea;
    --color-border: #eecad8;
    --color-text: #2c2226;
    --color-text-muted: #7c6a71;
}

:root[data-theme="blue"] {
    --accent: #2f80d6;
    --accent-light: #85b7e9;
    --accent-hover: #276bb6;
    --accent-strong: #1f5590;
    --color-primary-bg: #d8e7f8;
    --color-header-bg: #f9fcff;
    --color-sidebar-bg: #fbfdff;
    --color-content-bg: #edf4fc;
    --color-footer-bg: #f9fcff;
    --color-card-bg: #f9fcff;
    --color-card-hover-bg: #e3eef9;
    --color-border: #cddef0;
    --color-text: #212832;
    --color-text-muted: #647380;
}

:root[data-theme="red"] {
    --accent: #e23c3c;
    --accent-light: #f19393;
    --accent-hover: #cb3030;
    --accent-strong: #a82727;
    /* Accent is a bright true red, so danger uses amber-orange — the clearest
       "danger" signal that still separates from the red accent. */
    --color-danger: #d97706;
    --color-danger-bg: #fbe8d1;
    --color-primary-bg: #f9d8d8;
    --color-header-bg: #fff8f8;
    --color-sidebar-bg: #fffafa;
    --color-content-bg: #fceded;
    --color-footer-bg: #fff8f8;
    --color-card-bg: #fff8f8;
    --color-card-hover-bg: #fae1e1;
    --color-border: #eecaca;
    --color-text: #2b2221;
    --color-text-muted: #7c6b69;
}

:root[data-theme="green"] {
    --accent: #35a259;
    --accent-light: #8fcc9f;
    --accent-hover: #2c8a48;
    --accent-strong: #236e39;
    --color-primary-bg: #d6eddc;
    --color-header-bg: #f8fdf9;
    --color-sidebar-bg: #fafefb;
    --color-content-bg: #ecf6ef;
    --color-footer-bg: #f8fdf9;
    --color-card-bg: #f8fdf9;
    --color-card-hover-bg: #dfefe5;
    --color-border: #cae4d1;
    --color-text: #202a23;
    --color-text-muted: #64766a;
}

:root[data-theme="yellow"] {
    --accent: #cc9010;
    --accent-light: #ecc95c;
    --accent-hover: #ae7b0b;
    --accent-strong: #8a6108;
    --color-primary-bg: #f6e6bf;
    --color-header-bg: #fffcf1;
    --color-sidebar-bg: #fffdf6;
    --color-content-bg: #fdf5e2;
    --color-footer-bg: #fffcf1;
    --color-card-bg: #fffcf1;
    --color-card-hover-bg: #f6eacd;
    --color-border: #ebdab8;
    --color-text: #2b2618;
    --color-text-muted: #7c7158;
}

/* ============================================================
   RESET & BASE
   ============================================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* The `hidden` attribute must actually hide. The UA rule behind it is weaker
   than any class that sets `display` (e.g. `.alert { display: flex }`), so
   markup written as `<div class="alert" hidden>` stayed visible — and several
   components toggle visibility with `el.hidden`. */
[hidden] {
    display: none !important;
}

body {
    font-family: var(--font-main);
    background: var(--color-content-bg);
    color: var(--color-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

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

/* ============================================================
   APP SHELL — GRID LAYOUT
   ============================================================ */
.app-shell {
    display: grid;
    grid-template-rows: auto 1fr auto;
    grid-template-columns: 1fr;
    grid-template-areas:
        "header"
        "main"
        "footer";
    height: 100vh;
    overflow: hidden;
}

/* ============================================================
   HEADER — three separate pieces
   ============================================================ */
.app-header {
    grid-area: header;
    background: var(--color-content-bg);
    display: flex;
    align-items: stretch;
    height: var(--header-height);
    padding: 10px 30px 0px 30px;
    gap: 30px;
    z-index: 100;
    min-width: 0;
    height: 64px;
}

/* Shared "piece" card look */
.app-launcher,
.app-subheader-piece,
.app-actions {
    background: var(--color-header-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--main-border-radius);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

/* ── Piece 1 : launcher (logo + square toggle) ── */
.app-launcher {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 0 25px 0 15px;
    flex-shrink: 0;
    width: var(--launcher-width);
    min-width: 235px;
    transition: border-radius 0.16s ease;
}

.app-launcher__logo {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.app-launcher__logo img {
    width: 40px;
    height: 40px;
    object-fit: contain;
}

.app-launcher__toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--color-text-muted);
    transition: background 0.12s, color 0.12s;
}

.app-launcher__toggle:hover {
    background: var(--color-content-bg);
    color: var(--color-text);
}

/* 2×2 grid of dots; each dot rotates 45° on itself when the drawer is open */
.app-launcher__grid {
    display: grid;
    grid-template-columns: repeat(2, 10px);
    grid-template-rows: repeat(2, 10px);
    gap: 3px;
    place-items: center;
}

.app-launcher__dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    border: solid 2px var(--color-qs-teal);
    transition: transform 0.2s ease;
}

.app-launcher__dot:nth-child(1) {
    border-color: var(--color-qs-teal);
}

.app-launcher__dot:nth-child(2) {
    border-color: var(--color-qs-teal-light);
}

.app-launcher__dot:nth-child(3) {
    border-color: var(--color-qs-blue);
}

.app-launcher__dot:nth-child(4) {
    border-color: var(--color-qs-coral);
}

.app-launcher.open .app-launcher__dot {
    transform: rotate(-45deg);
}

/* Decorative toggle (auth pages): same rotation, driven by a transient class on
   the button instead of the drawer's open state — see app.js initHeaderMenu. */
.app-launcher__toggle.spin .app-launcher__dot {
    transform: rotate(-45deg);
}

.app-launcher__env {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 3px;
    background: var(--color-accent-dev);
    color: white;
    letter-spacing: 0.04em;
    text-transform: lowercase;
    flex-shrink: 0;
}

/* ── The sidebar drawer that drops out of piece 1 ── */
.app-drawer {
    position: absolute;
    top: 100%;
    left: -1px;
    width: var(--launcher-width);
    min-width: 235px;
    max-height: calc(100vh - var(--header-height) - var(--footer-height) - 16px);
    background: var(--color-header-bg);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 15px 15px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
    padding: 8px;
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
    gap: 6px;
}

.app-launcher.open {
    border-radius: var(--main-border-radius) 15px 0 0;
}

.app-launcher.open .app-drawer {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* ── Public header (unauthenticated pages: scheduling respond, etc.) ── */
.app-header--public .app-launcher {
    width: auto;
}

.app-header--public__icon {
    object-fit: contain;
    cursor: default;
    pointer-events: none;
}

/* ============================================================
   SUBHEADER — piece 2
   ============================================================ */
.app-subheader-piece {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
}

/* Burger toggle — hidden on wide screens, shown when the subheader collapses */
.app-subheader__burger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    margin-left: auto;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    color: var(--color-qs-teal);
    transition: background 0.12s, color 0.12s;
    flex-shrink: 0;
}

.app-subheader__burger:hover {
    color: var(--color-qs-teal-hover);
}

.app-subheader__burger .ti {
    font-size: 20px;
}

/* Rectangle placeholder for the current module's icon */
.app-subheader__module-icon {
    width: 35px;
    height: 35px;
}

.app-subheader {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-width: 0;
    flex: 1;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    padding-right: calc(max(var(--launcher-width), 150px) - 56px);
}

.app-subheader::-webkit-scrollbar {
    display: none;
}

.subheader-tab {
    display: inline-flex;
    align-items: center;
    height: 34px;
    padding: 0 14px;
    font-size: 16px;
    font-weight: 400;
    color: var(--color-text-muted);
    transition: color 0.12s, background 0.12s;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    position: relative;
}

.subheader-tab::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    width: 0;
    height: 2px;
    background: var(--color-text-muted);
    transform: translateX(-50%);
    transition: width 0.2s ease, background 0.12s;
}

.subheader-tab:hover {
    color: var(--color-text);
    background-color: var(--color-content-bg);
}

.subheader-tab:hover::after {
    width: 80%;
    background: var(--color-text-muted);
}

.subheader-tab.active {
    color: var(--color-qs-teal);
    font-weight: 600;
}

.subheader-tab.active::after {
    width: 100%;
    background: var(--color-qs-teal);
}

/* ── Collapsed subheader: tabs become a burger dropdown ──
   The ".collapsed" class is toggled by JS (updateSubheaderMode in app.js)
   when the inline tabs no longer fit the available width — or below 768px,
   whichever is reached first. The same #app-subheader element is restyled
   into the dropdown menu, so the tabs are never duplicated. */
.app-subheader-piece.collapsed .app-subheader__burger {
    display: inline-flex;
}

/* Burger icon morphs into a cross while the dropdown is open */
.app-subheader__burger-icon--close {
    display: none;
}

.app-subheader-piece.open .app-subheader__burger-icon--menu {
    display: none;
}

.app-subheader-piece.open .app-subheader__burger-icon--close {
    display: inline-block;
}

.app-subheader-piece.collapsed.open {
    border-radius: var(--main-border-radius) 15px 0 0;
}

/* Turn the tab row into a dropdown that drops out of the piece */
.app-subheader-piece.collapsed .app-subheader {
    position: absolute;
    top: 100%;
    left: -1px;
    right: -1px;
    flex: none;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 4px;
    height: auto;
    max-height: calc(100vh - var(--header-height) - var(--footer-height) - 16px);
    padding: 8px;
    background: var(--color-header-bg);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 15px 15px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    overflow-y: auto;
    z-index: 300;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.16s ease, transform 0.16s ease, visibility 0.16s;
}

.app-subheader-piece.collapsed.open .app-subheader {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.app-subheader-piece.collapsed .subheader-tab {
    height: 40px;
    width: 100%;
    justify-content: flex-start;
}

/* ============================================================
   ACTIONS — piece 3 (profile + notifications)
   ============================================================ */
.app-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    flex-shrink: 0;
}

.qs-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-content-bg);
    color: var(--color-qs-teal);
    cursor: pointer;
    position: relative;
    transition: background 0.15s, color 0.15s;
}

.qs-icon-btn-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-content-bg);
    color: var(--color-danger);
    cursor: pointer;
    position: relative;
    transition: background 0.15s, color 0.15s;
}

.qs-icon-btn:hover {
    background: var(--color-border);
    color: var(--color-qs-teal-hover);
}

.qs-icon-btn:disabled,
.qs-icon-btn[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
    background: var(--color-content-bg);
    color: var(--color-text-muted);
}

.qs-icon-btn .ti {
    font-size: 18px;
}

.qs-icon-btn--danger:hover {
    color: var(--color-danger);
    background: var(--color-danger-bg);
    border-color: var(--color-danger);
}

/* ============================================================
   DRAWER NAV ITEMS
   ============================================================ */
.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 16px;
    font-weight: 400;
    color: var(--color-text);
    transition: background 0.1s, color 0.1s;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
}

.nav-item:hover {
    background: var(--color-border);
    color: var(--color-primary);
}

.nav-item.active {
    background: var(--color-primary-bg);
    color: var(--color-text);
    font-weight: 700;
}

/* Rectangle placeholder icon (custom per-module icons added later) */
.nav-item__icon-ph {
    width: 18px;
    height: 18px;
    border-radius: 4px;
    background: var(--color-primary-bg);
    border: 1px solid var(--color-primary);
    flex-shrink: 0;
}

.nav-item.active .nav-item__icon-ph {
    background: var(--color-primary);
}

.nav-item__icon {
    width: 25px;
    height: 25px;
    border-radius: 4px;
    flex-shrink: 0;
    object-fit: contain;
}

.app-subheader__module-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.nav-spacer {
    flex: 1;
    min-height: 8px;
}

.nav-spacer+.nav-item--bottom {
    border-top: 1px solid var(--color-border);
    margin-top: 4px;
    padding-top: 8px;
}

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.app-main {
    grid-area: main;
    padding: var(--main-padding);
    overflow-y: auto;
    min-width: 0;
    min-height: 0;
    transition: opacity 0.15s ease-out;
}

/* Gentle fade-in on HTMX module swaps. The incoming #app-main briefly carries
   HTMX's swap classes; starting it transparent and letting them drop transitions
   it up to full opacity for a fluid transition between modules (styles are
   already loaded in <head>, so there is no unstyled flash). */
.app-main.htmx-added,
.app-main.htmx-settling {
    opacity: 0;
}

@media (prefers-reduced-motion: reduce) {
    .app-main {
        transition: none;
    }

    .app-main.htmx-added,
    .app-main.htmx-settling {
        opacity: 1;
    }
}

/* ============================================================
   FOOTER
   ============================================================ */
.app-footer {
    grid-area: footer;
    background: var(--color-header-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--main-border-radius);
    margin: 4px 30px 8px 30px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    min-height: var(--footer-height);
    flex-shrink: 0;
    font-size: 13px;
    color: var(--color-text-muted);
}

/* .page / .page__header / .page__title / .page__subtitle / .page__content live
   in components.css, next to the make_page macro they style. They were declared
   in both files; the cascade is per-property, so the copy here was NOT dead —
   `align-items`, `flex-direction` and `text-align` were only set here and were
   folded into the components.css rules when this duplicate was removed. */

/* ============================================================
   QS-RADIO-BUTTON — a selectable OPTION rendered as a bordered row/pill.
   Wrap a real <input class="qs-radio" type="radio|checkbox"> plus a
   <span> label inside a <label class="qs-radio-button">; the input stays
   the accessible control while the whole row is the click target and shows
   selection state via :has(). Consistent with the app accent (teal).
   ============================================================ */

.qs-radio-button {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-header-bg);
    cursor: pointer;
    font-size: 14px;
    line-height: 1.35;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.qs-radio-button:hover {
    border-color: var(--color-primary);
}

.qs-radio-button:has(input:checked) {
    border-color: var(--color-primary);
    background: var(--color-primary-bg);
}

.qs-radio-button:has(input:focus-visible) {
    box-shadow: 0 0 0 2px var(--color-primary-bg);
}

.qs-radio-button>span {
    flex: 1;
}

.qs-checkbox {
    display: inline-block;
    position: relative;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--color-border);
    border-radius: 3px;
    background: var(--color-header-bg);
    vertical-align: middle;
    flex-shrink: 0;
    transition: border-color 0.15s, background 0.15s;
    box-sizing: border-box;
}

.qs-checkbox:hover {
    border-color: var(--color-qs-teal);
}

.qs-checkbox.checked {
    background: var(--color-qs-teal);
    border-color: var(--color-qs-teal);
}

.qs-checkbox.checked::after {
    content: '';
    position: absolute;
    top: 1px;
    left: 4px;
    width: 5px;
    height: 9px;
    border: 2px solid #ffffff;
    border-top: none;
    border-left: none;
    transform: rotate(45deg);
}

.qs-checkbox.indeterminate {
    background: var(--color-qs-teal);
    border-color: var(--color-qs-teal);
}

.qs-checkbox.indeterminate::after {
    content: '';
    position: absolute;
    top: 6px;
    left: 3px;
    width: 8px;
    height: 2px;
    background: #ffffff;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.htmx-indicator {
    opacity: 0;
    transition: opacity 0.2s;
}

.htmx-request .htmx-indicator {
    opacity: 1;
}

/* ============================================================
   NOTIFICATION BELL — global (header piece 3)
   ============================================================ */
.cdnc-notif-bell {
    position: relative;
    display: inline-flex;
}

/* .cdnc-notif-bell__btn uses .qs-icon-btn */

.cdnc-notif-bell__badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 17px;
    height: 17px;
    border-radius: 999px;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--color-header-bg, #fff);
    box-sizing: border-box;
}

.cdnc-notif-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: 360px;
    max-width: calc(100vw - 24px);
    background: var(--color-header-bg);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
    z-index: 320;
    overflow: hidden;
    animation: cdnc-slide-down 0.18s ease;
}

@keyframes cdnc-slide-down {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cdnc-notif-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-content-bg);
    font-size: 13px;
    font-weight: 700;
    color: var(--color-text);
}

.cdnc-notif-panel__body {
    max-height: min(440px, calc(100vh - 140px));
    overflow-y: auto;
}

.cdnc-notif-panel__empty {
    padding: 28px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 12px;
}

.cdnc-notif-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 11px 16px;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background 0.1s;
}

.cdnc-notif-item:last-child {
    border-bottom: none;
}

.cdnc-notif-item:hover {
    background: var(--color-content-bg);
}

.cdnc-notif-item--unread {
    background: rgba(59, 130, 246, 0.06);
}

.cdnc-notif-item__icon {
    flex: none;
    font-size: 16px;
    color: var(--color-text-muted);
    margin-top: 1px;
}

.cdnc-notif-item--unread .cdnc-notif-item__icon {
    color: var(--color-qs-teal, #0ea5a4);
}

.cdnc-notif-item__main {
    flex: 1;
    min-width: 0;
}

.cdnc-notif-item__title {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.4;
}

.cdnc-notif-item__msg {
    font-size: 12px;
    color: var(--color-text-muted);
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cdnc-notif-item__meta {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 10px;
    color: var(--color-text-muted);
    margin-top: 4px;
}

.cdnc-notif-item__del {
    flex: none;
    border: none;
    background: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 2px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.1s, background 0.1s, color 0.1s;
}

.cdnc-notif-item:hover .cdnc-notif-item__del {
    opacity: 1;
}

.cdnc-notif-item__del:hover {
    background: var(--color-border);
    color: var(--color-text);
}

/* Announcement composer — folds out of the panel header for a sender who has
   the `announcements` module (see cadence/partials/notification_bell.html). */
.cdnc-notif-panel__actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.cdnc-announce {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-content-bg);
}

.cdnc-announce__label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.cdnc-announce__input {
    height: 34px;
    font-size: 12px;
    border-radius: 8px;
}

.cdnc-announce__textarea {
    height: auto;
    padding: 8px 10px;
    resize: vertical;
    line-height: 1.5;
}

.cdnc-announce__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.cdnc-announce__hint {
    font-size: 11px;
    color: var(--color-text-muted);
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.cdnc-announce__hint--error {
    color: var(--color-danger, #dc2626);
}

/* Grouped notifications (multiple from the same person → one expandable row). */
.cdnc-notif-group {
    border-bottom: 1px solid var(--color-border);
}

.cdnc-notif-group:last-child {
    border-bottom: none;
}

.cdnc-notif-group__head {
    border-bottom: none;
}

.cdnc-notif-group__chevron {
    flex: none;
    font-size: 16px;
    color: var(--color-text-muted);
    margin-top: 1px;
    transition: transform 0.15s;
}

.cdnc-notif-group--open .cdnc-notif-group__chevron {
    transform: rotate(90deg);
}

.cdnc-notif-count {
    flex: none;
    align-self: center;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--color-qs-teal, #0ea5a4);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}

.cdnc-notif-group__body {
    display: none;
}

.cdnc-notif-group--open .cdnc-notif-group__body {
    display: block;
}

.cdnc-notif-group__body .cdnc-notif-item {
    padding-left: 38px;
    background: rgba(0, 0, 0, 0.02);
}

.cdnc-notif-group__body .cdnc-notif-item:last-child {
    border-bottom: none;
}

/* ── shared corner animation (qs-button + qs-button-ghost) ── */
.qs-button,
.qs-button-ghost {
    border: none;
    position: relative;
    gap: 8px;
}

.qs-button::before,
.qs-button::after,
.qs-button-ghost::before,
.qs-button-ghost::after {
    content: '';
    position: absolute;
    width: 25%;
    height: 25%;
    border-style: solid;
    border-color: var(--corner-color);
    pointer-events: none;
    transition: width 0.22s ease, height 0.22s ease, border-color 0.15s, border-radius 0.22s ease;
}

.qs-button::before,
.qs-button-ghost::before {
    top: 0;
    right: 0;
    border-width: 2px 2px 0 0;
    border-radius: 0 12px 0 0;
}

.qs-button::after,
.qs-button-ghost::after {
    bottom: 0;
    left: 0;
    border-width: 0 0 2px 2px;
    border-radius: 0 0 0 12px;
}

.qs-button:hover::before,
.qs-button:hover::after,
.qs-button-ghost:hover::before,
.qs-button-ghost:hover::after {
    width: 50%;
    height: 50%;
    border-color: var(--corner-hover-color);
}

.qs-button:active::before,
.qs-button-ghost:active::before {
    width: 100%;
    height: 100%;
    border-color: var(--corner-active-color);
    border-radius: 12px 12px 12px 0;
}

.qs-button:active::after,
.qs-button-ghost:active::after {
    width: 100%;
    height: 100%;
    border-color: var(--corner-active-color);
    border-radius: 12px 0 12px 12px;
}

.qs-button:disabled::before,
.qs-button-ghost:disabled::before {
    top: 0;
    left: 0;
    right: auto;
    width: 25%;
    height: 25%;
    border-width: 2px 0 0 2px;
    border-radius: 12px 0 0 0;
    border-color: var(--corner-disabled-color);
}

.qs-button:disabled::after,
.qs-button-ghost:disabled::after {
    bottom: 0;
    right: 0;
    left: auto;
    width: 25%;
    height: 25%;
    border-width: 0 2px 2px 0;
    border-radius: 0 0 12px 0;
    border-color: var(--corner-disabled-color);
}

/* ── qs-button (solid) ── */
.qs-button {
    --corner-color: color-mix(in srgb, var(--accent) 72%, #000);
    --corner-hover-color: color-mix(in srgb, var(--accent) 52%, #000);
    --corner-active-color: color-mix(in srgb, var(--accent) 52%, #000);
    --corner-disabled-color: var(--color-border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 28px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    user-select: none;
    white-space: nowrap;
    background: var(--accent);
    color: #fff;
}

.qs-button:hover {
    background: var(--accent-hover);
}

.qs-button:active {
    background: var(--accent-strong);
    transform: translateY(2px);
}

.qs-button:disabled {
    background: color-mix(in srgb, var(--accent) 22%, var(--color-card-bg));
    color: color-mix(in srgb, var(--accent) 45%, var(--color-text-muted));
    cursor: not-allowed;
    transform: none;
}

/* ── qs-button-ghost ── */
.qs-button-ghost {
    --corner-color: var(--accent);
    --corner-hover-color: color-mix(in srgb, var(--accent) 72%, #000);
    --corner-active-color: color-mix(in srgb, var(--accent) 55%, #000);
    --corner-disabled-color: var(--color-border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 28px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: color 0.15s, background 0.15s, transform 0.1s;
    user-select: none;
    white-space: nowrap;
    background: color-mix(in srgb, var(--accent) 7%, transparent);
    color: color-mix(in srgb, var(--accent) 78%, #000);
}

.qs-button-ghost:hover {
    color: color-mix(in srgb, var(--accent) 62%, #000);
    background: color-mix(in srgb, var(--accent) 11%, transparent);
}

.qs-button-ghost:active {
    color: color-mix(in srgb, var(--accent) 48%, #000);
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    transform: translateY(1px);
}

.qs-button-ghost:disabled {
    color: var(--color-text-muted);
    background: transparent;
    cursor: not-allowed;
    transform: none;
}

/* ── qs-button--danger modifier (works on both solid + ghost) ── */
.qs-button--danger,
.qs-button-ghost--danger {
    --corner-color: color-mix(in srgb, var(--color-danger) 72%, #000);
    --corner-hover-color: color-mix(in srgb, var(--color-danger) 55%, #000);
    --corner-active-color: color-mix(in srgb, var(--color-danger) 55%, #000);
    --corner-disabled-color: var(--color-border);
    background: var(--color-danger-bg);
}

.qs-button.qs-button--danger {
    background: var(--color-danger);
}

.qs-button.qs-button--danger:hover {
    background: color-mix(in srgb, var(--color-danger) 80%, #000);
}

.qs-button.qs-button--danger:active {
    background: color-mix(in srgb, var(--color-danger) 64%, #000);
}

.qs-button-ghost.qs-button-ghost--danger {
    color: var(--color-danger);
}

.qs-button-ghost.qs-button-ghost--danger:hover {
    color: var(--color-danger);
    background: var(--color-danger-bg);
}

.qs-button-ghost.qs-button-ghost--danger:active {
    color: color-mix(in srgb, var(--color-danger) 64%, #000);
    background: var(--color-danger-bg);
}

/* ── qs-button--sm modifier (works on both solid + ghost) ── */
.qs-button--sm,
.qs-button-ghost--sm {
    gap: 6px;
    padding: 4px 14px;
    font-size: 13px;
    border-radius: 8px;
}

.qs-button--sm::before,
.qs-button-ghost--sm::before {
    border-radius: 0 8px 0 0;
}

.qs-button--sm::after,
.qs-button-ghost--sm::after {
    border-radius: 0 0 0 8px;
}

.qs-button--sm:active::before,
.qs-button-ghost--sm:active::before {
    border-radius: 8px 8px 8px 0;
}

.qs-button--sm:active::after,
.qs-button-ghost--sm:active::after {
    border-radius: 8px 0 8px 8px;
}

.qs-button--sm:disabled::before,
.qs-button-ghost--sm:disabled::before {
    border-radius: 8px 0 0 0;
}

.qs-button--sm:disabled::after,
.qs-button-ghost--sm:disabled::after {
    border-radius: 0 0 8px 0;
}