/* Light is the base palette. Every colour the app draws with is declared
   here, including ones that used to be written inline further down -- a
   hardcoded #fff or rgba(var(--app-primary-rgb), .1) is invisible to the dark palette
   below and shows up as a white slab or an unreadable tint. Two RGB triples
   (--app-primary-rgb, --app-shade-rgb) exist so translucent tints can be
   themed too, which a hex token cannot express. */
:root {
    color-scheme: light;
    --app-bg: #f5f7fb;
    --app-surface: #ffffff;
    --app-surface-muted: #f8fafc;
    --app-elevated: #ffffff;
    --app-sidebar-bg: #eef2f9;
    --app-topbar-bg: rgba(255, 255, 255, 0.85);
    --app-input-bg: #f1f5f9;
    --app-border: #d9e2ef;
    --app-text: #172033;
    --app-muted: #667085;
    --app-primary: #2563eb;
    --app-primary-dark: #1d4ed8;
    --app-primary-soft: #e8f0ff;
    --app-primary-outline: #b9cdfc;
    --app-on-primary: #ffffff;
    /* Overlay used on top of a primary-filled surface (the active nav badge).
       Must invert with the palette: white-on-blue reads in light mode, but
       dark mode fills with a pale blue whose foreground is near-black. */
    --app-on-primary-soft: rgba(255, 255, 255, 0.28);
    --app-primary-rgb: 37, 99, 235;
    --app-shade-rgb: 15, 23, 42;
    --app-success-soft: #eaf7ef;
    --app-danger-soft: #fff0f0;
    --app-scrollbar: #b7c4d7;
    --app-glow: #eaf1ff;
    --app-glow-alt: #dbeafe;
    --app-guest-bg: #f4f7fb;
    --app-radius: 16px;
    /* Flat means flat: surfaces are separated by border and background
       alone. Kept as tokens rather than deleted so the neumorphic style
       (and anything that opts in later) has one place to reintroduce
       depth. */
    --app-shadow: none;
    --app-shadow-sm: none;
}

/* Explicit choice wins over the system preference, in both directions. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --app-bg: #0f141c;
    --app-surface: #161d29;
    --app-surface-muted: #1b2331;
    --app-elevated: #1e2736;
    --app-sidebar-bg: #131a25;
    --app-topbar-bg: rgba(22, 29, 41, 0.85);
    --app-input-bg: #1b2331;
    --app-border: #2a3547;
    --app-text: #e6ecf5;
    --app-muted: #94a3b8;
    /* Lifted off the light-mode blue: #2563eb on a dark surface is muddy and
       fails contrast for text. These stay in the same hue family. */
    --app-primary: #5b8cf5;
    --app-primary-dark: #7aa3f7;
    --app-primary-soft: #1c2740;
    --app-primary-outline: #33456b;
    --app-on-primary: #0b1220;
    --app-on-primary-soft: rgba(0, 0, 0, 0.22);
    --app-primary-rgb: 91, 140, 245;
    --app-shade-rgb: 0, 0, 0;
    --app-success-soft: #16281d;
    --app-danger-soft: #2c1719;
    --app-scrollbar: #3a4759;
    --app-glow: #17243b;
    --app-glow-alt: #131d31;
    --app-guest-bg: #0f141c;
    --app-shadow: none;
    --app-shadow-sm: none;
}

/* System preference, only while no explicit choice has been made. */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --app-bg: #0f141c;
        --app-surface: #161d29;
        --app-surface-muted: #1b2331;
        --app-elevated: #1e2736;
        --app-sidebar-bg: #131a25;
        --app-topbar-bg: rgba(22, 29, 41, 0.85);
        --app-input-bg: #1b2331;
        --app-border: #2a3547;
        --app-text: #e6ecf5;
        --app-muted: #94a3b8;
        --app-primary: #5b8cf5;
        --app-primary-dark: #7aa3f7;
        --app-primary-soft: #1c2740;
        --app-primary-outline: #33456b;
        --app-on-primary: #0b1220;
        --app-on-primary-soft: rgba(0, 0, 0, 0.22);
        --app-primary-rgb: 91, 140, 245;
        --app-shade-rgb: 0, 0, 0;
        --app-success-soft: #16281d;
        --app-danger-soft: #2c1719;
        --app-scrollbar: #3a4759;
        --app-glow: #17243b;
        --app-glow-alt: #131d31;
        --app-guest-bg: #0f141c;
        --app-shadow: none;
        --app-shadow-sm: none;
    }
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--app-scrollbar) transparent;
}

html {
    min-height: 100%;
}

body {
    min-height: 100%;
    background: radial-gradient(circle at top left, var(--app-glow) 0, transparent 32rem), var(--app-bg);
    color: var(--app-text);
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

/* ===== App Shell ===== */
.app-shell {
    display: flex;
    min-height: 100vh;
    background: var(--app-bg);
}

.app-sidebar {
    width: 264px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--app-sidebar-bg);
    border-right: 1px solid var(--app-border);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    padding: 18px 14px;
}

.app-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 6px 16px;
}

.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--app-text);
}

.app-brand-mark {
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--app-primary), var(--app-primary-dark));
    color: var(--app-on-primary);
}

.app-brand-name {
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.app-compose-btn {
    width: 100%;
    margin-bottom: 18px;
    padding: 12px 18px;
    border-radius: 14px;
    font-weight: 700;
}

.app-nav-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 12px;
    color: var(--app-text);
    text-decoration: none;
    font-weight: 600;
    transition: background-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.app-nav-link i {
    font-size: 1.15rem;
    width: 22px;
    text-align: center;
}

.app-nav-link:hover {
    background: rgba(var(--app-primary-rgb), 0.08);
    color: var(--app-primary-dark);
}

.app-nav-link.active {
    background: var(--app-primary);
    color: var(--app-on-primary);
}

.app-nav-section-label {
    margin: 14px 14px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--app-muted);
}

.app-nav-badge {
    margin-left: auto;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--app-primary);
    color: var(--app-on-primary);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
}

.app-nav-link.active .app-nav-badge {
    background: var(--app-on-primary-soft);
}

.app-sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--app-border);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    height: 64px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 22px;
    background: var(--app-topbar-bg);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--app-border);
    position: sticky;
    top: 0;
    z-index: 1030;
}

.app-topbar-title {
    font-size: 1.05rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.app-topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Bootstrap's .dropdown supplies position:relative for the results menu.
   flex/max-width/margin-left live here rather than on .app-global-search
   because *this* is the topbar's flex child now -- left on the inner box
   they were inert, and the search field visibly changed size. */
.app-global-search-wrap {
    flex: 1;
    max-width: 420px;
    margin-left: 16px;
}

.app-global-search {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--app-input-bg);
    border: 1px solid var(--app-border);
    border-radius: 12px;
    padding: 8px 12px;
    color: var(--app-muted);
}

.app-global-search input {
    border: none;
    outline: none;
    background: transparent;
    flex: 1;
    color: var(--app-text);
    font-size: 0.9rem;
}

.app-global-search kbd {
    background: var(--app-elevated);
    border: 1px solid var(--app-border);
    border-radius: 6px;
    font-size: 11px;
    padding: 2px 6px;
    color: var(--app-muted);
}

.app-global-search:focus-within {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 4px rgba(var(--app-primary-rgb), 0.1);
    background: var(--app-elevated);
}

.app-user-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 999px;
    border-color: var(--app-border);
    padding: 5px 12px 5px 6px;
}

.app-avatar {
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--app-primary);
    color: var(--app-on-primary);
    font-weight: 700;
    font-size: 0.85rem;
}

.app-content {
    flex: 1;
    min-width: 0;
    padding: 22px;
}

.app-auth {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    border: 1px solid var(--app-border);
    background: var(--app-elevated);
    color: var(--app-text);
}

.app-backdrop {
    display: none;
}

/* Toast container */

/* Guest (logged-out) layout: hide chrome, center content */
body.app-guest .app-sidebar,
body.app-guest .app-topbar {
    display: none;
}

body.app-guest .app-shell {
    min-height: 100vh;
    background: radial-gradient(circle at 20% 0%, var(--app-glow) 0, transparent 45%), radial-gradient(circle at 80% 100%, var(--app-glow-alt) 0, transparent 45%), var(--app-guest-bg);
}

body.app-guest .app-content {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
}

.auth-card-wrap {
    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}

.auth-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

.auth-logo-mark {
    width: 46px;
    height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--app-primary), var(--app-primary-dark));
    color: var(--app-on-primary);
    font-size: 1.4rem;
}

.auth-logo-name {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.03em;
}

.auth-card {
    border-radius: 20px;
}

.auth-input .input-group-text {
    background: var(--app-surface-muted);
    border-color: var(--app-border);
    color: var(--app-muted);
    border-radius: 0 0 0 0;
}

.auth-input .form-control,
.auth-input .btn {
    border-color: var(--app-border);
}

.auth-input .form-control:focus {
    z-index: 3;
}





/* Page header helpers (shared) */
.app-page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.app-page-title {
    margin: 0;
    font-size: clamp(1.5rem, 1.1rem + 1vw, 2rem);
    font-weight: 800;
    letter-spacing: -0.03em;
}

.app-page-subtitle {
    color: var(--app-muted);
    margin: 4px 0 0;
}

/* Responsive shell */
@media (max-width: 991.98px) {
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        height: 100vh;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    .app-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(var(--app-shade-rgb), 0.45);
        z-index: 1040;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }

    .app-backdrop.show {
        opacity: 1;
        pointer-events: auto;
    }

    .app-content {
        padding: 16px;
    }

    .app-topbar {
        padding: 0 14px;
    }
}


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

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

.btn {
    border-radius: 999px;
    font-weight: 600;
}

.btn-primary {
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--app-primary-dark);
    border-color: var(--app-primary-dark);
}

.btn-outline-primary {
    color: var(--app-primary);
    border-color: var(--app-primary-outline);
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.form-control,
.form-select {
    border-color: var(--app-border);
    border-radius: 12px;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 4px rgba(var(--app-primary-rgb), 0.12);
}

.card,
.modal-content,
.list-group-item {
    border-color: var(--app-border);
}

.card,
.modal-content {
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow-sm);
}

.modal-header,
.modal-footer,
.card-header {
    border-color: var(--app-border);
}

/* Bootstrap's default modal padding is tighter than the spacing this app
   uses on its own panels, which made dialogs feel cramped next to the
   pages that open them. */
.modal-header,
.modal-footer {
    padding: 1rem 1.25rem;
}

.modal-body {
    padding: 1.25rem;
}

/* The compose form grows with Cc/Bcc revealed and a 10-row body, which on a
   short viewport pushed Send below the fold. Scroll the form instead, so the
   footer buttons stay reachable at any height. */
.compose-body {
    max-height: min(70vh, 40rem);
    overflow-y: auto;
}

.card-header {
    background: var(--app-surface-muted);
    font-weight: 700;
}

.list-group-item.active {
    background: var(--app-primary);
    border-color: var(--app-primary);
}

.badge {
    border-radius: 999px;
    font-weight: 700;
}

.page-shell {
    width: min(1400px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 40px;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.page-title {
    margin: 0;
    font-size: clamp(1.75rem, 1.35rem + 1.2vw, 2.5rem);
    font-weight: 800;
    letter-spacing: -0.04em;
}

.page-subtitle {
    color: var(--app-muted);
    margin: 6px 0 0;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 8px;
}

.app-panel {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--app-radius);
    box-shadow: var(--app-shadow-sm);
}

.empty-state {
    text-align: center;
    color: var(--app-muted);
    padding: 48px 24px;
}

.empty-state-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    margin-bottom: 12px;
    border-radius: 18px;
    background: var(--app-primary-soft);
    color: var(--app-primary);
    font-size: 1.5rem;
}

.item-row {
    transition: background-color 0.15s ease, transform 0.15s ease;
}

.item-row:hover {
    background: var(--app-surface-muted);
}

.app-sidebar-card {
    position: sticky;
    top: 16px;
}

@media (max-width: 768px) {
    .page-shell {
        width: min(100% - 20px, 1400px);
        padding-top: 18px;
    }

    .page-header {
        flex-direction: column;
    }

    .page-actions {
        width: 100%;
        justify-content: flex-start;
    }

    .page-actions .btn,
    .page-actions label.btn {
        flex: 1 1 auto;
    }

    .app-sidebar-card {
        position: static;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        scroll-behavior: auto !important;
        transition-duration: 0.001ms !important;
    }
}

/* ===== Theme toggle ===== */
.app-theme-toggle i {
    font-size: 1.05rem;
    line-height: 1;
}

/* One icon per theme, swapped by CSS rather than JS: the no-flash script in
   base.html.twig sets the theme before first paint, so letting JS pick the
   icon afterwards produces a visible flip on every page load. */
.app-theme-toggle .theme-icon-dark { display: none; }
:root[data-theme="dark"] .app-theme-toggle .theme-icon-dark { display: inline-block; }
:root[data-theme="dark"] .app-theme-toggle .theme-icon-light { display: none; }

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

/* ===== Polish ===== */

/* Keyboard focus was relying on Bootstrap's per-component styles, so several
   custom elements (nav links, icon buttons, the brand) had no visible focus
   at all. :focus-visible keeps it off mouse clicks. */
.app-nav-link:focus-visible,
.app-brand:focus-visible,
.btn-icon:focus-visible,
.app-theme-toggle:focus-visible,
.item-row a:focus-visible {
    outline: 2px solid var(--app-primary);
    outline-offset: 2px;
    border-radius: 10px;
}

/* Switching palettes repaints the whole page at once; without this the
   change lands as a hard flash. Deliberately limited to colour properties
   so it never animates layout, and the reduced-motion block below still
   overrides it. */
body,
.app-sidebar,
.app-topbar,
.app-panel,
.card,
.modal-content,
.btn-icon,
.form-control,
.form-select {
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* Dark mode separates panels from the page with a hairline highlight along
   the top edge instead of a drop shadow -- borders alone read weakly when
   panel and page luminance are close. */
:root[data-theme="dark"] .app-panel,
:root[data-theme="dark"] .card,
:root[data-theme="dark"] .modal-content {
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

/* Bootstrap paints its own surfaces from --bs-* variables. data-bs-theme on
   <html> handles most of it, but these three follow the app palette so
   modals and tables match the panels around them instead of drifting. */
.modal-content,
.dropdown-menu,
.offcanvas {
    background-color: var(--app-surface);
    color: var(--app-text);
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--app-text);
    --bs-table-border-color: var(--app-border);
}

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

/* Bootstrap's .bg-white / .bg-light / .text-bg-light are fixed light values
   that data-bs-theme does NOT flip -- they are the white slabs left in dark
   mode (the mail search addon, count badges, the error pages' full-height
   background, the notes card footer). Rather than editing markup across six
   templates, they are pointed at tokens here. In light mode these resolve to
   #ffffff / #f8fafc, which is what Bootstrap drew anyway, so nothing changes
   visually; in dark mode they follow the palette. */
.bg-white {
    background-color: var(--app-elevated) !important;
}

.bg-light {
    background-color: var(--app-surface-muted) !important;
}

.text-bg-light {
    background-color: var(--app-surface-muted) !important;
    color: var(--app-text) !important;
}

/* Same problem, opposite direction: fixed-dark text utilities on a dark
   surface. */
.text-dark {
    color: var(--app-text) !important;
}

/* Bootstrap fills .form-control/.form-select from --bs-body-bg, which
   data-bs-theme does handle -- but the app draws inputs on --app-surface
   panels, so they need to match those rather than the page background. */
.form-control,
.form-select {
    background-color: var(--app-elevated);
    color: var(--app-text);
}

.form-control::placeholder {
    color: var(--app-muted);
    opacity: 1;
}

/* Inputs inside a modal sit on --app-surface, which in light mode is the
   same white the rule above fills them with -- so the field and the sheet
   behind it were the same colour, separated only by a 1px #d9e2ef border
   that barely registers. The compose window read as unfinished because of
   it. --app-input-bg is the token that already existed for exactly this and
   was going unused; in dark mode the surface is already darker than the
   input fill, so this changes nothing there. */
.modal-content .form-control,
.modal-content .form-select {
    background-color: var(--app-input-bg);
}

.modal-content .form-control:focus,
.modal-content .form-select:focus {
    background-color: var(--app-elevated);
}

.input-group-text {
    background-color: var(--app-surface-muted);
    border-color: var(--app-border);
    color: var(--app-muted);
}

/* Rendered email bodies are author-styled HTML that usually assumes a white
   page. Forcing a dark background behind dark text is unreadable, so the
   message body keeps a light surface in both themes and gets an explicit
   dark foreground rather than inheriting the app's light-on-dark text. */
/* ============================================================
   Elevated surface style  ([data-surface="elevated"])
   ============================================================
   Stripe-flavoured: crisp high-contrast cards lifted by a single
   *directional* shadow, a saturated accent, tighter radii and tighter
   heading tracking, with a gradient wash for brand surfaces.

   Deliberately NOT neumorphism. Soft-UI matches the card to the page and
   reads the edge from a two-sided light source, which costs most of the
   edge contrast. This does the opposite: the card stays lighter than the
   page, keeps a hairline border, and casts down. That is why it stays
   legible for long sessions, which is what a mail client is.

   Opt-in and orthogonal to light/dark, same as before. */
:root[data-surface="elevated"] {
    --app-bg: #f6f9fc;
    --app-surface: #ffffff;
    --app-surface-muted: #f6f9fc;
    --app-elevated: #ffffff;
    --app-sidebar-bg: #ffffff;
    --app-topbar-bg: rgba(255, 255, 255, 0.9);
    --app-input-bg: #ffffff;
    --app-border: #e3e8ee;
    --app-text: #0a2540;
    --app-muted: #64748b;
    /* Stripe's shadows are two stacked layers: a wide soft one tinted with
       the brand's blue-slate rather than neutral grey, and a tight dark one
       for the contact edge. The tint is what stops them looking muddy. */
    --el-shadow: 0 6px 12px -2px rgba(50, 50, 93, 0.15), 0 3px 7px -3px rgba(0, 0, 0, 0.2);
    --el-shadow-lg: 0 13px 27px -5px rgba(50, 50, 93, 0.2), 0 8px 16px -8px rgba(0, 0, 0, 0.25);
    --el-shadow-btn: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
    --el-radius: 10px;
    --el-accent-grad: linear-gradient(101deg, #6772e5 0%, #4f8ef7 45%, #21c1d6 100%);
}

/* Dark shadow values. The system-preference variant MUST live inside the
   media query below: :root:not([data-theme="light"]) also matches plain
   light mode (no attribute set), so declaring it here would paint
   near-black shadows over the light palette. */
:root[data-surface="elevated"][data-theme="dark"] {
    --el-shadow: 0 6px 12px -2px rgba(0, 0, 0, 0.45), 0 3px 7px -3px rgba(0, 0, 0, 0.5);
    --el-shadow-lg: 0 13px 27px -5px rgba(0, 0, 0, 0.5), 0 8px 16px -8px rgba(0, 0, 0, 0.6);
    --el-shadow-btn: 0 4px 6px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
}

@media (prefers-color-scheme: dark) {
    :root[data-surface="elevated"]:not([data-theme="light"]) {
        --el-shadow: 0 6px 12px -2px rgba(0, 0, 0, 0.45), 0 3px 7px -3px rgba(0, 0, 0, 0.5);
        --el-shadow-lg: 0 13px 27px -5px rgba(0, 0, 0, 0.5), 0 8px 16px -8px rgba(0, 0, 0, 0.6);
        --el-shadow-btn: 0 4px 6px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
    }
}

@media (prefers-color-scheme: dark) {
    :root[data-surface="elevated"]:not([data-theme="light"]) {
        --app-bg: #0c1220;
        --app-surface: #141c2b;
        --app-surface-muted: #101827;
        --app-elevated: #141c2b;
        --app-sidebar-bg: #0f1626;
        --app-topbar-bg: rgba(20, 28, 43, 0.9);
        --app-input-bg: #101827;
        --app-border: #24304a;
        --app-text: #e8eef8;
    }
}

:root[data-surface="elevated"][data-theme="dark"] {
    --app-bg: #0c1220;
    --app-surface: #141c2b;
    --app-surface-muted: #101827;
    --app-elevated: #141c2b;
    --app-sidebar-bg: #0f1626;
    --app-topbar-bg: rgba(20, 28, 43, 0.9);
    --app-input-bg: #101827;
    --app-border: #24304a;
    --app-text: #e8eef8;
}

:root[data-surface="elevated"] body {
    background: var(--app-bg);
}

/* Cards sit above the page and cast downward -- one light source, overhead. */
:root[data-surface="elevated"] .app-panel,
:root[data-surface="elevated"] .card,
:root[data-surface="elevated"] .settings-section,
:root[data-surface="elevated"] .settings-nav,
:root[data-surface="elevated"] .mini-calendar {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--el-radius);
    box-shadow: var(--el-shadow);
}

:root[data-surface="elevated"] .modal-content,
:root[data-surface="elevated"] .dropdown-menu,
:root[data-surface="elevated"] .toast {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--el-radius);
    box-shadow: var(--el-shadow-lg);
}

/* Buttons lift on hover and settle on press. Small movement, fast easing --
   the whole effect is "responsive", not "animated". */
:root[data-surface="elevated"] .btn {
    border-radius: 6px;
    letter-spacing: 0.01em;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background-color 0.12s ease;
}

:root[data-surface="elevated"] .btn-primary,
:root[data-surface="elevated"] .btn-outline-primary:hover {
    box-shadow: var(--el-shadow-btn);
}

:root[data-surface="elevated"] .btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--el-shadow);
}

:root[data-surface="elevated"] .btn-primary:active {
    transform: translateY(0);
    box-shadow: var(--el-shadow-btn);
}

/* Inputs stay crisp and bordered; focus is a tight ring, not a glow. */
:root[data-surface="elevated"] .form-control,
:root[data-surface="elevated"] .form-select,
:root[data-surface="elevated"] .app-global-search {
    border: 1px solid var(--app-border);
    border-radius: 6px;
    background: var(--app-input-bg);
    box-shadow: none;
}

:root[data-surface="elevated"] .form-control:focus,
:root[data-surface="elevated"] .form-select:focus,
:root[data-surface="elevated"] .app-global-search:focus-within {
    border-color: var(--app-primary);
    box-shadow: 0 0 0 3px rgba(var(--app-primary-rgb), 0.25);
}

/* Gradient reserved for brand surfaces only. Used everywhere it stops
   meaning anything. */
:root[data-surface="elevated"] .app-brand-mark,
:root[data-surface="elevated"] .auth-logo-mark,
:root[data-surface="elevated"] .empty-state-icon {
    background: var(--el-accent-grad);
    color: #ffffff;
}

:root[data-surface="elevated"] body.app-guest .app-shell {
    background:
        radial-gradient(ellipse at 15% -10%, rgba(103, 114, 229, 0.18) 0, transparent 55%),
        radial-gradient(ellipse at 90% 0%, rgba(33, 193, 214, 0.16) 0, transparent 50%),
        var(--app-bg);
}

/* Type: Stripe's hierarchy comes from size and tracking, not weight alone. */
:root[data-surface="elevated"] .app-page-title,
:root[data-surface="elevated"] .page-title {
    letter-spacing: -0.035em;
}

:root[data-surface="elevated"] .app-nav-link {
    border-radius: 6px;
    font-weight: 500;
}

:root[data-surface="elevated"] .app-nav-link.active {
    background: rgba(var(--app-primary-rgb), 0.1);
    color: var(--app-primary);
    font-weight: 600;
    box-shadow: none;
}

:root[data-surface="elevated"] .app-sidebar {
    border-right: 1px solid var(--app-border);
}

:root[data-surface="elevated"] .item-row:hover {
    background: var(--app-surface-muted);
}

/* ===== In-flight state ===== */
/* A button that has fired a request but still looks idle invites a second
   click, and nine pages had no in-flight handling at all -- double-clicking
   Create genuinely created two records. appBusy() (base.html.twig) toggles
   this: the spinner is CSS-only so no markup has to be swapped in and out. */
.btn.is-busy {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn.is-busy::after {
    content: '';
    position: absolute;
    inset: 0;
    margin: auto;
    width: 1em;
    height: 1em;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    color: var(--app-on-primary);
    animation: app-spin 0.6s linear infinite;
}

.btn-outline-primary.is-busy::after,
.btn-outline-secondary.is-busy::after,
.btn-light.is-busy::after,
.btn-secondary.is-busy::after {
    color: var(--app-text);
}

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

@media (prefers-reduced-motion: reduce) {
    .btn.is-busy::after { animation-duration: 1.6s; }
}

/* The message body is the mail's PLAIN TEXT part (ImapClient::getTextBody),
   escaped before insertion -- this app never renders sender HTML. So it
   needs no light "paper" treatment: it is our own text and themes like
   everything else. It is still inset as a card to separate the message from
   the header and attachments around it. */
.mail-message .msg-sheet {
    background: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: 10px;
    padding: 22px 24px;
}

/* ===== Overflow containment ===== */
/* Nothing in the stylesheet previously stopped wide content from pushing the
   page sideways, and this app routinely renders strings that cannot break:
   DKIM public keys (~400 chars), long email addresses, URLs in received
   mail. On a phone that turned into a horizontally scrolling page rather
   than content that wraps or scrolls within its own box. */
img,
svg,
video,
iframe {
    max-width: 100%;
}

img,
video {
    height: auto;
}

/* Break anywhere rather than overflow: these are opaque tokens, so there is
   no "good" break point to preserve. */
code,
kbd,
samp {
    overflow-wrap: anywhere;
}

pre {
    overflow-x: auto;
    max-width: 100%;
}

/* Wide tables scroll inside themselves. Bootstrap's .table-responsive does
   this where it is applied; this catches tables that are not wrapped. */
.app-panel > table,
.card-body > table {
    display: block;
    overflow-x: auto;
    max-width: 100%;
}

/* Flex and grid children default to min-width:auto, which refuses to shrink
   below their content -- the usual reason a "responsive" layout still
   overflows. */
.app-main,
.app-content,
.mail-messages,
.mail-message {
    min-width: 0;
}

/* Received mail is author-styled HTML that frequently assumes a desktop
   width; it must scroll inside the reading pane rather than widen the app. */
.mail-message .msg-sheet {
    overflow-x: auto;
}

/* Shared pager, used by any list that pages (mail has its own, styled to sit
   flush inside the message column). */

