/* D&J Webmail — Outlook-inspired design system (U5) */
:root {
    /* Surfaces & text (Fluent / Outlook Web light) */
    --color-bg: #faf9f8;
    --color-surface: #ffffff;
    --color-surface-alt: #f3f2f1;
    --color-border: #edebe9;
    --color-border-subtle: #f3f2f1;
    --color-text: #242424;
    --color-text-secondary: #605e5c;
    --color-text-muted: #8a8886;

    /* Brand & actions */
    --color-primary: #0078d4;
    --color-primary-hover: #106ebe;
    --color-primary-pressed: #005a9e;
    --color-primary-light: #deecf9;
    --color-primary-subtle: #c7e0f4;
    --color-focus-ring: rgba(0, 120, 212, 0.45);
    --color-danger: #d13438;
    --color-danger-hover: #a4262c;
    --color-unread-accent: #0078d4;
    --mail-unread-bar-width: 5px;

    /* Mail list — read vs unread text. Read rows fade top→bottom: sender
       darkest (scannable), subject medium, snippet lightest. */
    --color-mail-read-from: var(--color-text);
    --color-mail-read-subject: var(--color-text-secondary);
    --color-mail-read-date: var(--color-text-muted);
    --color-mail-unread-bg: #f3f2f1;
    --color-mail-unread-bg-hover: #edebe9;

    /* Chrome */
    --color-header: #ffffff;
    --color-header-text: #242424;

    /* Elevation (minimal — Outlook uses dividers) */
    --shadow-xs: 0 0.3px 0.9px rgba(0, 0, 0, 0.07);
    --shadow-sm: 0 1.6px 3.6px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 3.2px 7.2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 6.4px 14.4px rgba(0, 0, 0, 0.12);

    /* Shape */
    --radius: 4px;
    --radius-sm: 2px;
    --radius-lg: 6px;

    /* Layout */
    --sidebar-width: 250px;
    --header-height: 48px;

    /* Typography — Segoe UI first (Outlook native) */
    --font: "Segoe UI", "Segoe UI Web (West European)", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;

    /* 8px spacing grid */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;

    /* Scrollbars (thin — match sidebar folder list) */
    --scrollbar-size: 6px;
    --scrollbar-thumb: var(--color-border);
    --scrollbar-thumb-hover: var(--color-text-muted);
}

*,
*::before,
*::after {
    box-sizing: border-box;
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

html {
    -webkit-text-size-adjust: 100%;
}

/* Thin scrollbars app-wide (WebKit / Blink) */
*::-webkit-scrollbar {
    width: var(--scrollbar-size);
    height: var(--scrollbar-size);
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
    background: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

/* Known scroll regions — reinforce thin bars (Firefox + WebKit) */
.sidebar-scroll,
.sidebar-groups,
.mail-list-scroller,
.mail-list-mobile,
.mail-list-desktop,
.reading-pane-body,
.compose-panel-body,
.compose-panel-inner,
.context-submenu-scroll,
.folder-picker-list,
.mail-body-html,
.table-wrap,
.rich-editor,
textarea,
select,
.app-modal-body {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) transparent;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 0.875rem;
    line-height: 1.4286;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.sidebar-open {
    overflow: hidden;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Loading overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.35);
    backdrop-filter: blur(2px);
}

.loading-overlay[hidden] {
    display: none !important;
}

.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    padding: 2rem 2.5rem;
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.loading-ring {
    width: 40px;
    height: 40px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.loading-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Header */
.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--color-header);
    color: var(--color-header-text);
    border-bottom: 1px solid var(--color-border);
    box-shadow: none;
}

.header-inner {
    margin: 0 auto;
    min-height: var(--header-height);
    padding: 0 var(--space-4);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(12rem, 28rem) minmax(0, 1fr);
    align-items: center;
    gap: var(--space-3);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    justify-self: start;
}

.site-title {
    margin: 0;
    font-size: 1.0625rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    line-height: 1;
    display: flex;
    align-items: center;
}

.site-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    color: inherit;
    text-decoration: none;
    line-height: 1;
}

.site-brand:hover {
    text-decoration: none;
}

.site-brand-icon {
    display: inline-block;
    flex-shrink: 0;
    width: 1.75rem;
    height: 1.75rem;
    background-color: var(--color-primary);
    -webkit-mask-image: url('../img/logo.png');
    mask-image: url('../img/logo.png');
    -webkit-mask-size: contain;
    mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    mask-repeat: no-repeat;
    -webkit-mask-position: center;
    mask-position: center;
}

.site-brand-text {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
    font-size: 1.0625rem;
    line-height: 1;
}

.site-brand-name {
    color: var(--color-header-text);
    font-weight: 700;
    line-height: 1;
}

.site-brand-suffix {
    color: var(--color-primary);
    font-weight: 700;
    line-height: 1;
}

.site-brand:hover .site-brand-name {
    color: var(--color-text);
}

.header-center {
    justify-self: center;
    width: 100%;
    min-width: 0;
    max-width: 28rem;
}

.search-field--header {
    width: 100%;
    min-width: 0;
    max-width: none;
    min-height: 2rem;
    padding: 0 0.6rem 0 0.7rem;
    border-radius: var(--radius-md, 6px);
    background: var(--color-bg, #fafafa);
    border-color: var(--color-border-subtle);
    box-shadow: none;
}

.search-field--header:focus-within {
    background: var(--color-surface);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 1px var(--color-primary), 0 0 0 3px var(--color-focus-ring);
}

.search-field--header .search-field-input {
    min-width: 0;
    padding: 0.4rem 0.35rem !important;
    font-size: 0.8125rem;
}

.site-title-link {
    color: var(--color-header-text);
    text-decoration: none;
}

.site-title-link:hover {
    color: var(--color-primary);
    text-decoration: none;
}

.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    cursor: pointer;
}

.menu-toggle span {
    display: block;
    width: 16px;
    height: 2px;
    margin: 0 auto;
    background: var(--color-text-secondary);
    border-radius: 1px;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-shrink: 0;
    justify-self: end;
}

.header-user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.user-name {
    color: var(--color-text);
    font-size: 0.875rem;
    font-weight: 500;
    display: none;
}

.header-divider {
    width: 1px;
    height: 24px;
    background: var(--color-border);
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.header-nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: background 0.12s, color 0.12s;
}

.header-nav-icon {
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
}

.header-user .role-badge {
    display: none;
}

.header-nav-link:hover {
    background: var(--color-bg);
    color: var(--color-text);
    text-decoration: none;
}

.header-nav-link--logout:hover {
    background: var(--color-danger-light, rgba(209, 52, 56, 0.1));
    color: var(--color-danger);
}

/* Icon-only account buttons on narrow screens; label returns at ≥640px. */
.header-nav-text {
    display: none;
}

@media (min-width: 640px) {
    .header-nav-text {
        display: inline;
    }
}

@media (max-width: 639px) {
    .header-nav-link {
        width: 2.25rem;
        height: 2.25rem;
        padding: 0;
    }
}

.role-badge {
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.15rem 0.45rem;
    border-radius: 999px;
    background: var(--color-bg);
    color: var(--color-text-muted);
    border: 1px solid var(--color-border);
}

.role-badge.role-admin {
    background: var(--color-primary-light);
    color: var(--color-primary);
    border-color: var(--color-primary-subtle);
}

/* App shell */
.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    gap: 0;
    min-height: calc(100vh - var(--header-height));
    position: relative;
}

/* Draggable divider between the sidebar and the main content. */
.sidebar-resizer {
    position: absolute;
    top: 0;
    bottom: 0;
    left: var(--sidebar-width);
    width: 11px;
    transform: translateX(-5px);
    z-index: 40;
    cursor: col-resize;
    background: transparent;
    touch-action: none;
}

.sidebar-resizer::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    background: var(--color-border);
    transition: background 0.12s ease, width 0.12s ease;
}

.sidebar-resizer:hover::before,
.sidebar-resizer.is-dragging::before {
    width: 4px;
    background: var(--color-primary);
}

body.is-resizing-sidebar {
    cursor: col-resize;
    user-select: none;
}

@media (max-width: 899px) {
    .sidebar-resizer {
        display: none;
    }
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--header-height);
    z-index: 89;
    background: rgba(15, 23, 42, 0.4);
}

.sidebar-backdrop[hidden] {
    display: none !important;
}

.sidebar {
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    padding: var(--space-3) var(--space-2);
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.btn-compose {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    flex-shrink: 0;
    margin: 0 var(--space-1) var(--space-3);
    padding: var(--space-2) var(--space-3);
    font-weight: 600;
    font-size: 0.8125rem;
    border-radius: var(--radius);
    box-shadow: none;
    letter-spacing: -0.01em;
}

.btn-compose:hover {
    box-shadow: none;
}

.sidebar-scroll,
.sidebar-groups {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0 0.25rem 0.5rem;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.sidebar-primary-folders {
    display: flex;
    flex-direction: column;
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 0.35rem 0.25rem 0.65rem;
    margin-top: auto;
    border-top: 1px solid var(--color-border-subtle);
}

.sidebar-footer.sidebar-folder-tree {
    padding-top: 0.4rem;
}

.sidebar-label {
    margin: 1rem 0 0.35rem;
    padding: 0 0.75rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-text-muted);
}

.sidebar-label:first-child {
    margin-top: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    min-height: 2.25rem;
    padding: 0.35rem var(--space-3);
    margin: 1px 0;
    border-radius: var(--radius-sm);
    border-left: 3px solid transparent;
    color: var(--color-text-secondary);
    font-size: 0.8125rem;
    font-weight: 400;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.sidebar-link:hover {
    background: var(--color-surface-alt);
    color: var(--color-text);
    text-decoration: none;
}

.sidebar-link.active {
    background: var(--color-primary-light);
    color: var(--color-text);
    font-weight: 600;
    border-left-color: var(--color-primary);
}

.sidebar-link.active:hover {
    background: var(--color-primary-subtle);
}

.sidebar-link-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    opacity: 0.82;
    background: currentColor;
    mask-size: contain;
    mask-repeat: no-repeat;
    mask-position: center;
    -webkit-mask-size: contain;
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
}

.sidebar-link.active .folder-icon {
    opacity: 1;
    color: var(--color-primary);
}

/* Lucide-style sidebar icons */
.folder-icon-inbox { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='22 12 16 12 14 15 10 15 8 12 2 12'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='22 12 16 12 14 15 10 15 8 12 2 12'/%3E%3Cpath d='M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z'/%3E%3C/svg%3E"); }
.folder-icon-sent { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m22 2-7 20-4-9-9-4z'/%3E%3Cpath d='M22 2 11 13'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m22 2-7 20-4-9-9-4z'/%3E%3Cpath d='M22 2 11 13'/%3E%3C/svg%3E"); }
.folder-icon-draft { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 20h9'/%3E%3Cpath d='M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4z'/%3E%3C/svg%3E"); }
.folder-icon-archive { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='4' width='20' height='5' rx='1'/%3E%3Cpath d='M4 9v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9'/%3E%3Cpath d='M10 13h4'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='2' y='4' width='20' height='5' rx='1'/%3E%3Cpath d='M4 9v9a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9'/%3E%3Cpath d='M10 13h4'/%3E%3C/svg%3E"); }
.folder-icon-junk { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m4.9 4.9 14.2 14.2'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m4.9 4.9 14.2 14.2'/%3E%3C/svg%3E"); }
.folder-icon-spam { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3Cpath d='M12 8v4'/%3E%3Cpath d='M12 16h.01'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3Cpath d='M12 8v4'/%3E%3Cpath d='M12 16h.01'/%3E%3C/svg%3E"); }
.folder-icon-trash { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'/%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6'/%3E%3Cpath d='M10 11v6'/%3E%3Cpath d='M14 11v6'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 6h18'/%3E%3Cpath d='M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2'/%3E%3Cpath d='M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6'/%3E%3Cpath d='M10 11v6'/%3E%3Cpath d='M14 11v6'/%3E%3C/svg%3E"); }
.folder-icon-folder { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7l-2-2H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7l-2-2H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2z'/%3E%3C/svg%3E"); }
.folder-icon-admin-section { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3C/svg%3E"); }
.folder-icon-admin { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='9' rx='1'/%3E%3Crect x='14' y='3' width='7' height='5' rx='1'/%3E%3Crect x='14' y='12' width='7' height='9' rx='1'/%3E%3Crect x='3' y='16' width='7' height='5' rx='1'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='9' rx='1'/%3E%3Crect x='14' y='3' width='7' height='5' rx='1'/%3E%3Crect x='14' y='12' width='7' height='9' rx='1'/%3E%3Crect x='3' y='16' width='7' height='5' rx='1'/%3E%3C/svg%3E"); }
.folder-icon-connection { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 12h-4l-3 9L9 3 7 12H2'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 12h-4l-3 9L9 3 7 12H2'/%3E%3C/svg%3E"); }
.folder-icon-status { mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3C/svg%3E"); -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z'/%3E%3C/svg%3E"); }

.main-content {
    min-width: 0;
    padding: var(--space-5) var(--space-6);
}

/* Page header */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h2 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.25;
}

.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.page-header-left {
    min-width: 0;
}

.page-title-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.page-header-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0 0.5rem;
    border-radius: 999px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.text-muted {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

.error-detail {
    font-size: 0.875rem;
    word-break: break-word;
}

/* Cards */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    box-shadow: none;
}

.card-muted {
    background: var(--color-surface-alt);
}

.card h3 {
    margin: 0 0 0.75rem;
    font-size: 1rem;
    font-weight: 600;
}

.card-flush {
    padding: 0;
    overflow: hidden;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--color-text-muted);
}

.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
    opacity: 0.6;
}

/* Toasts */
.toast-stack {
    position: fixed;
    top: calc(var(--header-height) + 0.75rem);
    right: 1.25rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-width: min(420px, calc(100vw - 2rem));
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    box-shadow: var(--shadow-md);
    pointer-events: auto;
    animation: toast-in 0.25s ease-out;
    transition: opacity 0.3s, transform 0.3s;
}

.toast.is-leaving {
    opacity: 0;
    transform: translateX(0.75rem);
}

.toast-success {
    background: #dff6dd;
    color: #0b6a0b;
    border: 1px solid #9fd89f;
}

.toast-error {
    background: #fde7e9;
    color: #a4262c;
    border: 1px solid #f1bbbc;
}

/* Stateful op toast: sticky "Moving to Trash…" with a spinner until the deferred
   server work completes, then swapped for the ✓/error toast. */
.toast-progress {
    background: #f3f2f1;
    color: #323130;
    border: 1px solid #d2d0ce;
}

.toast-spinner {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    margin-top: 0.1rem;
    border: 2px solid rgba(0, 0, 0, 0.15);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Compose attachment list: file rows with a remove (×) button. */
.file-upload-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0;
    font-size: 0.8125rem;
    color: var(--color-text);
}

.file-upload-item-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-upload-item-size {
    flex-shrink: 0;
    color: var(--color-text-secondary);
    font-size: 0.75rem;
}

.file-upload-remove {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    margin-left: 0.15rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

.file-upload-remove:hover {
    background: var(--color-surface-alt);
    color: #a4262c;
}

.compose-draft-attach-chip .file-upload-remove {
    margin-left: 0.1rem;
}

/* Gmail-style conversation count after the subject: "Subject (3)". */
/* Conversation size badge — a prominent pill so it's obvious a row holds more
   than one message (acting on it acts on the whole conversation). */
.mail-row-thread-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2rem;
    margin-right: 0.4rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: var(--color-accent-soft, #e8f0fe);
    color: var(--color-accent, #1a73e8);
    font-weight: 700;
    font-size: 0.6875rem;
    line-height: 1.45;
    vertical-align: middle;
    flex-shrink: 0;
}

.mail-unread .mail-row-thread-count {
    background: var(--color-accent, #1a73e8);
    color: #fff;
    font-weight: 700;
}

/* Searching state: the magnifier in the header search box becomes a spinner
   while the search request is in flight. */
.header-search-form.is-searching .search-field-icon svg {
    display: none;
}

.header-search-form.is-searching .search-field-icon::after {
    content: '';
    display: block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

/* Search results: match highlighting, result count, clear link, empty state. */
mark.search-hit {
    background: #fff2a8;
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

[data-theme="dark"] mark.search-hit {
    background: #8a6d00;
    color: #fff;
}

.search-result-count {
    margin: 0.2rem 0 0;
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

.search-result-scope {
    opacity: 0.85;
}

.search-clear-link {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    margin-left: auto;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-primary);
    text-decoration: none;
    white-space: nowrap;
}

.search-clear-link:hover {
    text-decoration: underline;
}

.empty-state--search .empty-state-hint {
    max-width: 340px;
    margin: 0.35rem auto 0.9rem;
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

/* Optimistic list rows (message still syncing to the server): visible but
   clearly "in transit" — dimmed, non-selectable, checkbox disabled. */
.mail-row--optimistic {
    opacity: 0.62;
    cursor: default;
}

.mail-row--optimistic .mail-row-check,
.mail-row--optimistic .mail-kebab {
    pointer-events: none;
    opacity: 0.35;
}

.toast-close {
    flex-shrink: 0;
    margin-left: auto;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
    font-size: 1.125rem;
    line-height: 1;
}

.toast-close:hover {
    opacity: 1;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(0.75rem);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

[data-theme="dark"] .toast-success {
    background: #0b3a0b;
    color: #9fd89f;
    border-color: #0b6a0b;
}

[data-theme="dark"] .toast-error {
    background: #442726;
    color: #f1bbbc;
    border-color: #a4262c;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    min-height: 2rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-size: 0.8125rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
    white-space: nowrap;
}

.btn:active {
    transform: none;
}

.btn:focus-visible {
    outline: 2px solid var(--color-focus-ring);
    outline-offset: 1px;
}

.btn.is-loading {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    cursor: wait;
    pointer-events: none;
}

.btn-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.65s linear infinite;
    flex-shrink: 0;
    opacity: 0.9;
}

.btn-primary.is-loading .btn-spinner {
    border-color: rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
}

.btn-danger.is-loading .btn-spinner {
    border-color: rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
}

.mail-cmd-btn.is-loading,
.mail-action-btn.is-loading {
    position: relative;
    cursor: wait;
    pointer-events: none;
    opacity: 0.85;
}

.mail-cmd-btn.is-loading .mail-cmd-label,
.mail-action-btn.is-loading .mail-action-label {
    visibility: hidden;
    width: 0;
    overflow: hidden;
}

.mail-cmd-btn.is-loading svg:not(.btn-spinner),
.mail-action-btn.is-loading svg:not(.btn-spinner) {
    visibility: hidden;
}

.mail-cmd-btn.is-loading .btn-spinner,
.mail-action-btn.is-loading .btn-spinner {
    position: absolute;
    left: 50%;
    top: 50%;
    margin: -7px 0 0 -7px;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
    box-shadow: none;
}

.btn-primary:hover {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    text-decoration: none;
    color: #fff;
}

.btn-primary:active {
    background: var(--color-primary-pressed);
    border-color: var(--color-primary-pressed);
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-surface-alt);
    border-color: #c8c6c4;
    color: var(--color-text);
    text-decoration: none;
}

.btn-outline {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: #8a8886;
}

.btn-outline:hover {
    background: var(--color-surface-alt);
    border-color: #605e5c;
    color: var(--color-text);
    text-decoration: none;
}

[data-theme="dark"] .btn-secondary {
    background: var(--color-surface-alt);
    color: var(--color-text);
    border-color: var(--color-border);
}

[data-theme="dark"] .btn-secondary:hover {
    background: #3b3a39;
    color: #fff;
}

[data-theme="dark"] .btn-outline {
    background: transparent;
    color: var(--color-text-secondary);
    border-color: #8a8886;
}

[data-theme="dark"] .btn-outline:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: #c8c6c4;
    color: var(--color-text);
}

.btn-danger {
    background: var(--color-danger);
    color: #fff;
}

.btn-danger:hover {
    background: var(--color-danger-hover);
    text-decoration: none;
    color: #fff;
}

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
    padding: 0.35rem 0.65rem;
    font-size: 0.8125rem;
}

.btn-ghost:hover {
    color: var(--color-text);
    background: var(--color-bg);
    text-decoration: none;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.8125rem;
}

.btn-block {
    width: 100%;
}

/* Mail table (desktop) */
.mail-list-mobile {
    display: none;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
}

.data-table th {
    background: transparent;
    font-weight: 500;
    font-size: 0.75rem;
    text-transform: none;
    letter-spacing: 0;
    color: var(--color-text-muted);
    padding-top: 0.875rem;
    padding-bottom: 0.875rem;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background: var(--color-bg);
}

.data-table td a:not(.btn) {
    font-weight: 500;
    font-size: 0.8125rem;
    color: var(--color-primary);
    text-decoration: none;
}

.data-table td a:not(.btn):hover {
    text-decoration: underline;
}

.mail-table .mail-row {
    cursor: pointer;
    transition: background 0.12s;
}

.mail-table .mail-row:hover {
    background: var(--color-bg);
}

.mail-list-card.is-syncing {
    opacity: 0.92;
    transition: opacity 0.2s ease;
}

.mail-unread .col-from,
.mail-unread .col-subject,
.mail-unread .mail-row-from,
.mail-unread .mail-row-subject,
.mail-unread .mail-card-from,
.mail-unread .mail-card-subject {
    font-weight: 600;
    color: var(--color-text);
}

.mail-unread .mail-card-date,
.mail-unread .mail-row-date {
    color: var(--color-text-secondary);
    font-weight: 500;
}

.unread-dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary-subtle);
}

.col-status {
    width: 2rem;
}

.col-date {
    width: 110px;
    white-space: nowrap;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.col-from {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.col-subject {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text-secondary);
}

/* Mail cards (mobile) */
.mail-card {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border-subtle);
    border-left: var(--mail-unread-bar-width) solid transparent;
    color: inherit;
    text-decoration: none;
    transition: background 0.12s;
    cursor: pointer;
}

.mail-card-check {
    flex-shrink: 0;
    width: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mail-card .mail-check {
    width: 1.0625rem;
    height: 1.0625rem;
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.mail-card.is-checked,
.mail-card.is-checked:hover,
.mail-card.is-checked:focus-visible {
    background: var(--color-primary-subtle, rgba(0, 120, 212, 0.08));
}

.mail-card.mail-unread.is-checked,
.mail-card.mail-unread.is-checked:hover,
.mail-card.mail-unread.is-checked:focus-visible {
    background: var(--color-primary-subtle, rgba(0, 120, 212, 0.08));
}

.mail-card:hover,
.mail-card:focus-visible {
    background: var(--color-surface-alt);
    text-decoration: none;
}

.mail-card.mail-unread {
    background: var(--color-mail-unread-bg);
    border-left-color: var(--color-unread-accent);
}

.mail-card.mail-unread:hover,
.mail-card.mail-unread:focus-visible {
    background: var(--color-mail-unread-bg-hover);
}

.mail-card:last-child {
    border-bottom: none;
}

.mail-card-avatar {
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.02em;
}

.mail-card-body {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.mail-card-line1 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.15rem;
}

.mail-card-from {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-mail-read-from, var(--color-text-secondary));
    font-weight: 500;
}

.mail-card-date {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    flex-shrink: 0;
    line-height: 1;
    white-space: nowrap;
}

.mail-card-subject {
    font-size: 0.8125rem;
    color: var(--color-mail-read-subject, var(--color-text-muted));
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.35;
}

.mail-card:not(.mail-unread) .mail-card-date {
    color: var(--color-mail-read-date, var(--color-text-muted));
}

.mail-card .mail-kebab {
    flex-shrink: 0;
    align-self: center;
    opacity: 0.55;
}

.mail-card:hover .mail-kebab,
.mail-card:focus-within .mail-kebab {
    opacity: 1;
}

.mail-row-new {
    animation: mailRowHighlight 3s ease-out;
}

@keyframes mailRowHighlight {
    0% { background: var(--color-primary-light); }
    100% { background: transparent; }
}

/* Pagination */
.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
    padding: 0.625rem 1rem;
    border-top: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
}

.pagination-nav {
    display: inline-flex;
    align-items: center;
    gap: 0.125rem;
    flex-shrink: 0;
}

.pagination-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
    color: var(--color-text-muted);
    text-decoration: none;
    transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.pagination-nav-btn:hover:not(.is-disabled) {
    background: var(--color-surface-alt, #f3f2f1);
    border-color: var(--color-border);
    color: var(--color-text);
    text-decoration: none;
}

.pagination-nav-btn.is-disabled {
    opacity: 0.35;
    pointer-events: none;
}

.pagination-summary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    flex: 1 1 auto;
    min-width: 0;
    text-align: center;
}

.pagination-range {
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text);
    white-space: nowrap;
}

.pagination-page-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    white-space: nowrap;
}

.pagination-pages {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

.pagination-page {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    height: 1.75rem;
    padding: 0 0.35rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text);
    text-decoration: none;
    border: 1px solid transparent;
}

.pagination-page:hover {
    background: var(--color-primary-light);
    text-decoration: none;
}

.pagination-page.is-current {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.pagination-ellipsis {
    padding: 0 0.25rem;
    color: var(--color-text-muted);
    font-size: 0.75rem;
}

.pagination-btn.is-disabled {
    opacity: 0.45;
    pointer-events: none;
}

.page-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.page-header-actions .btn-outline {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.pagination-info {
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
}

.pagination-per-page {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.pagination-per-page-label {
    font-size: 0.75rem;
    color: var(--color-text-muted);
    font-weight: 500;
    white-space: nowrap;
}

.pagination-per-page .select-field-compact select,
.pagination-per-page .per-page-select {
    width: auto;
    min-width: 3.25rem;
    max-width: 4.5rem;
    min-height: 2rem;
    font-size: 0.75rem;
    padding: 0.2rem 1.75rem 0.2rem 0.5rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border-subtle);
    background-color: var(--color-surface);
    text-align: center;
    text-align-last: center;
}

.pagination-per-page .select-field-inline,
.pagination-per-page .select-field-compact {
    width: auto;
    min-width: 0;
    max-width: none;
}

.pagination-per-page .select-field {
    width: auto;
}

.select-field-compact {
    min-width: 4.5rem;
}

.select-field-compact select {
    padding: 0.35rem 1.75rem 0.35rem 0.65rem;
    font-size: 0.8125rem;
}

/* Read view */
.breadcrumb {
    margin: 0 0 0.75rem;
}

.back-nav {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.9rem 0.45rem 0.65rem;
    border: 1px solid var(--color-border-subtle);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-text-secondary);
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1;
    text-decoration: none;
    box-shadow: var(--shadow-xs);
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

.back-nav:hover,
.back-nav:focus-visible {
    background: var(--color-surface-alt);
    border-color: var(--color-border);
    color: var(--color-text);
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    outline: none;
}

.back-nav-icon {
    flex-shrink: 0;
    opacity: 0.9;
}

.back-nav-label {
    white-space: nowrap;
}

.back-nav--header {
    margin: 0;
    padding: 0.4rem 0.75rem 0.4rem 0.55rem;
}

.page-header--read {
    margin-bottom: 1rem;
}

.page-header--read .read-subject-title {
    margin: 0;
    font-size: 1.125rem;
    line-height: 1.35;
    word-break: break-word;
}

.breadcrumb a:not(.back-nav) {
    color: var(--color-text-muted);
    font-weight: 500;
}

.mail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.mail-read-card {
    padding: 0;
    overflow: hidden;
}

.mail-read-card > .mail-actions {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
}

.mail-action-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 0.45rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 4px);
    background: transparent;
    color: var(--color-text-secondary, var(--color-text-muted));
    font-size: 0.8125rem;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    flex-shrink: 0;
}

.mail-action-btn:hover,
.mail-action-btn:focus-visible {
    background: var(--color-surface);
    border-color: var(--color-border-subtle);
    color: var(--color-text);
    text-decoration: none;
    box-shadow: var(--shadow-xs, 0 1px 2px rgba(0, 0, 0, 0.04));
}

.mail-action-btn--primary {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.mail-action-btn--primary:hover,
.mail-action-btn--primary:focus-visible {
    background: var(--color-primary-hover, #106ebe);
    border-color: var(--color-primary-hover, #106ebe);
    color: #fff;
}

.mail-action-btn--danger:hover,
.mail-action-btn--danger:focus-visible {
    color: var(--color-danger, #c62828);
    border-color: rgba(198, 40, 40, 0.25);
    background: rgba(198, 40, 40, 0.06);
}

.mail-action-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.mail-action-label {
    display: none;
}

.mail-action-divider {
    width: 1px;
    height: 1.25rem;
    background: var(--color-border-subtle);
    flex-shrink: 0;
    margin: 0 0.15rem;
}

.mail-action-move {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm, 4px);
    background: var(--color-surface);
    overflow: hidden;
    flex-shrink: 0;
}

.mail-action-move-select-wrap,
.mail-cmd-move-select-wrap {
    position: relative;
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
}

.mail-action-move-select-wrap::after,
.mail-cmd-move-select-wrap::after {
    content: "";
    position: absolute;
    right: 0.45rem;
    top: 50%;
    width: 0.4rem;
    height: 0.4rem;
    border-right: 1.5px solid var(--color-text-muted);
    border-bottom: 1.5px solid var(--color-text-muted);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

.mail-cmd-move-select,
.mail-action-move-select {
    width: 100%;
    min-width: 7.5rem;
    max-width: 13rem;
    font-size: 0.75rem;
    padding: 0.35rem 1.5rem 0.35rem 0.5rem;
    border: none;
    border-right: 1px solid var(--color-border-subtle);
    border-radius: 0;
    background: var(--color-surface-alt, var(--color-surface));
    color: var(--color-text);
    text-overflow: ellipsis;
    font-family: inherit;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

.mail-action-move-select {
    min-height: 2.25rem;
}

.mail-action-btn--move {
    border: none;
    border-radius: 0;
    min-width: 2.25rem;
    height: 2.25rem;
    justify-content: center;
    padding: 0;
}

.mail-action-btn--flag[aria-pressed="true"] {
    color: var(--color-primary);
}

.mail-action-btn--flag .mail-action-icon--unflag {
    display: none;
}

.mail-action-btn--flag[aria-pressed="true"] .mail-action-icon--flag {
    display: none;
}

.mail-action-btn--flag[aria-pressed="true"] .mail-action-icon--unflag {
    display: block;
}

@media (min-width: 900px) {
    .mail-action-label {
        display: inline;
    }

    .mail-action-btn {
        min-width: auto;
        height: 2rem;
        padding: 0 0.55rem;
    }
}

.inline-form {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.move-form select {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
}

.detail-list {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 0.5rem 1rem;
    margin: 0 0 1rem;
    font-size: 0.875rem;
}

.detail-list dt {
    color: var(--color-text-muted);
    font-weight: 500;
}

.detail-list dd {
    margin: 0;
    word-break: break-word;
}

.detail-list dd code {
    font-size: 0.8125rem;
    padding: 0.15rem 0.4rem;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border-subtle);
    border-radius: 4px;
    color: var(--color-text);
}

.attachments {
    margin-top: 0;
    margin-bottom: 0;
    padding: 0.75rem 1rem;
    background: var(--color-surface-alt);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    color: var(--color-text);
}

.attachments--message {
    margin: 0;
    border: none;
    border-top: 1px solid var(--color-border-subtle);
    border-radius: 0;
    background: var(--color-surface);
    padding: 0.875rem 1.25rem 1rem;
}

.attachments strong {
    display: block;
    margin-bottom: 0.35rem;
    color: var(--color-text);
    font-weight: 600;
}

.attachments ul {
    margin: 0;
    padding-left: 1.25rem;
    list-style: disc;
}

.attachments li {
    color: var(--color-text-secondary);
    line-height: 1.5;
}

.attachments a {
    color: var(--color-primary);
    text-decoration: none;
}

.attachments a:hover {
    text-decoration: underline;
}

.attachments .attachment-preview {
    list-style: none;
    margin-left: -1.25rem;
}

/* Gmail-style attachment cards: image thumbnails / file-type tiles with a
   name+size footer and a hover download button. */
.attachments--cards {
    margin: 0;
    border: none;
    border-top: 1px solid var(--color-border-subtle);
    border-radius: 0;
    background: var(--color-surface);
    padding: 0.875rem 1.25rem 1.125rem;
}

.attachments-cards-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.65rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}

.attachment-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.attachment-card {
    position: relative;
    width: 182px;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--color-surface);
    transition: box-shadow 0.15s, border-color 0.15s;
}

.attachment-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--color-border);
}

.attachment-card-open {
    display: block;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
}

.attachment-card-thumb {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    height: 108px;
    background: var(--color-surface-alt);
    color: var(--color-text-secondary);
    overflow: hidden;
}

.attachment-card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.attachment-card-ext {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    color: var(--color-text-secondary);
}

.attachment-card--pdf .attachment-card-thumb { color: #c5221f; }
.attachment-card--pdf .attachment-card-ext { color: #c5221f; }
.attachment-card--doc .attachment-card-thumb { color: #1a73e8; }
.attachment-card--doc .attachment-card-ext { color: #1a73e8; }
.attachment-card--sheet .attachment-card-thumb { color: #188038; }
.attachment-card--sheet .attachment-card-ext { color: #188038; }
.attachment-card--zip .attachment-card-thumb { color: #b06000; }
.attachment-card--zip .attachment-card-ext { color: #b06000; }

.attachment-card-footer {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    padding: 0.5rem 0.625rem;
    border-top: 1px solid var(--color-border-subtle);
    min-width: 0;
}

.attachment-card-name {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-card-size {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.attachment-card-download {
    position: absolute;
    top: 0.45rem;
    right: 0.45rem;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--color-surface);
    color: var(--color-text);
    box-shadow: var(--shadow-md);
    opacity: 0;
    transform: translateY(-2px);
    transition: opacity 0.15s, transform 0.15s;
    text-decoration: none;
}

.attachment-card:hover .attachment-card-download,
.attachment-card-download:focus-visible {
    opacity: 1;
    transform: translateY(0);
}

.attachment-card-download:hover {
    background: var(--color-surface-alt);
}

@media (max-width: 640px) {
    .attachment-card {
        width: calc(50% - 0.375rem);
    }
    .attachment-card-download {
        opacity: 1;
        transform: none;
    }
}

.mail-read-content {
    min-width: 0;
    background: var(--color-bg);
}

.mail-read-subject-bar {
    background: var(--color-surface);
    padding: 0.875rem 1.25rem 1.125rem;
    border-bottom: 1px solid var(--color-border);
}

.mail-read-subject-bar--expandable {
    cursor: pointer;
    transition: background 0.12s;
}

.mail-read-subject-bar--expandable:hover,
.mail-read-subject-bar--expandable:focus-visible {
    background: var(--color-surface-alt);
    outline: none;
}

.mail-read-content.is-compose-focus:not(.is-thread-expanded) .mail-message-card:not(.mail-message-card--latest) {
    display: none;
}

.is-compose-locked .compose-panel-link,
.is-compose-locked .mail-cmd-compose,
.is-compose-locked #compose-link,
.is-compose-locked .btn-compose {
    opacity: 0.45;
    pointer-events: none;
    cursor: not-allowed;
}

.mail-thread {
    padding-top: 0.875rem;
}

.mail-thread-history-wrap {
    margin-top: 0.75rem;
}

.mail-thread-inline-history {
    max-height: none;
    padding: 0.5rem 0.875rem 0.75rem;
    background: var(--color-surface);
    border-color: var(--color-border-subtle);
}

.mail-thread-inline-sep {
    margin: 0 0 0.75rem;
    border: none;
    border-top: 1px solid var(--color-border);
}

.mail-thread-inline-meta {
    margin-bottom: 0.625rem;
    font-size: 0.8125rem;
    line-height: 1.55;
    color: var(--color-text-secondary);
}

.mail-thread-inline-meta strong {
    color: var(--color-text);
    font-weight: 600;
}

.mail-thread-inline-body {
    margin: 0;
}

.mail-read-subject {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: -0.02em;
    color: var(--color-text);
    word-break: break-word;
}

.mail-message-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin: 0 1rem 0.75rem;
    overflow: hidden;
}

.mail-thread .mail-message-card:last-child {
    margin-bottom: 1rem;
}

.mail-message-compose-slot:empty {
    display: none;
}

.mail-message-compose-slot .mail-inline-compose {
    margin: 0;
    border: none;
    border-radius: 0;
    box-shadow: none;
    border-top: 1px solid var(--color-border-subtle);
}

.mail-message-card--collapsed:not(.is-expanded) > .mail-message-expanded {
    display: none !important;
}

.mail-message-card--collapsed.is-expanded > .mail-message-collapsed {
    display: none;
}

.mail-message-card--collapsed {
    cursor: pointer;
    transition: background 0.12s, box-shadow 0.12s;
}

.mail-message-card--collapsed:hover,
.mail-message-card--collapsed:focus-visible {
    background: var(--color-surface-alt);
    box-shadow: var(--shadow-md);
    outline: none;
}

.mail-message-card--collapsed.is-expanded {
    cursor: default;
}

.mail-message-collapsed {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
}

.mail-message-collapsed .mail-message-avatar {
    width: 2.25rem;
    height: 2.25rem;
    font-size: 0.75rem;
}

.mail-message-collapsed-main {
    flex: 1;
    min-width: 0;
}

.mail-message-collapsed-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
}

.mail-message-snippet {
    margin: 0.2rem 0 0;
    font-size: 0.8125rem;
    line-height: 1.45;
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-message-card--latest {
    box-shadow: var(--shadow-md);
}

.mail-message-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border-subtle);
}

.mail-message-avatar {
    flex-shrink: 0;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.02em;
}

.mail-message-sender {
    flex: 1;
    min-width: 0;
}

.mail-message-sender-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.mail-message-from {
    min-width: 0;
    line-height: 1.45;
}

.mail-message-from-name {
    color: var(--color-primary);
    font-weight: 600;
    font-size: 0.9375rem;
}

.mail-message-from-email {
    color: var(--color-text-secondary);
    font-size: 0.8125rem;
    font-weight: 400;
    margin-left: 0.2rem;
}

.mail-message-date {
    flex-shrink: 0;
    margin: 0;
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--color-text-secondary);
    white-space: nowrap;
    text-align: right;
}

.mail-message-recipients {
    margin-top: 0.2rem;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--color-text-secondary);
}

.mail-message-body {
    padding: 1rem 1.25rem 1.25rem;
    min-width: 0;
}

.mail-body-html {
    overflow-x: auto;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.mail-body-plain {
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    font-family: inherit;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.mail-quoted-wrap {
    margin-top: 0.75rem;
}

.mail-body-html--quoted {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

/* Dark theme: keep the dark background, but force email/reply body text to a
   light color. Reply bodies (and many emails) carry inline black text authored
   for a white background, which is unreadable on dark — override it. Inline
   backgrounds are cleared to transparent so an email that sets a white/light
   background can't hide the now-light text. Links keep a readable blue. The
   quoted/history box keeps its own muted styling (handled last). */
[data-theme="dark"] .mail-body-html,
[data-theme="dark"] .mail-body-html *,
[data-theme="dark"] .mail-body-plain,
[data-theme="dark"] .mail-body-plain * {
    color: #e8eaed !important;
    background-color: transparent !important;
}

[data-theme="dark"] .mail-body-html a,
[data-theme="dark"] .mail-body-html a * {
    color: #8ab4f8 !important;
}

[data-theme="dark"] .mail-body-html--quoted,
[data-theme="dark"] .mail-body-html--quoted * {
    color: #9aa0a6 !important;
}

/* Forms */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.card-form {
    max-width: 560px;
}

.compose-form textarea,
.compose-form select,
.select-field select,
.form-group input:not([type="checkbox"]):not([type="radio"]):not(.file-upload-input),
.login-form input {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.compose-form textarea:focus,
.compose-form select:focus,
.form-group input:not([type="checkbox"]):not([type="radio"]):focus,
.login-form input:focus,
.select-field select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 1px var(--color-primary), 0 0 0 3px var(--color-focus-ring);
}

.compose-form textarea {
    resize: vertical;
    min-height: 200px;
}

.form-group {
    margin-bottom: 1.1rem;
}

.form-group > label:not(.form-check-label) {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--color-text);
}

.form-check {
    margin-bottom: 1rem;
}

.form-check-label {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.875rem;
    user-select: none;
}

.form-check-input {
    width: 1.05rem;
    height: 1.05rem;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.form-static-value {
    margin: 0;
    font-size: 0.9375rem;
}

.compose-cc-toggle {
    margin: -0.35rem 0 0.75rem;
}

.compose-cc-toggle .btn-link-muted {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.8125rem;
    cursor: pointer;
    font-family: inherit;
    color: var(--color-primary);
}

.compose-cc-toggle .btn-link-muted:hover {
    text-decoration: underline;
}

.cc-bcc-fields {
    margin-bottom: 0.25rem;
}

/* Gmail-style recipient chips */
.compose-recipients {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    overflow: visible;
    margin-bottom: 1.1rem;
    background: var(--color-surface);
    position: relative;
    z-index: 1;
}

.compose-recipients.is-suggest-open {
    z-index: 30;
}

.compose-recipient-row {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.3rem 0.75rem;
    border-bottom: 1px solid var(--color-border-subtle);
    min-height: 2.75rem;
}

.compose-recipient-row:last-child {
    border-bottom: none;
}

.compose-recipient-row[hidden] {
    display: none;
}

.compose-recipient-label {
    flex: 0 0 2.25rem;
    padding-top: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: pointer;
}

.recipient-field {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0;
    position: relative;
}

.recipient-suggest {
    position: fixed;
    z-index: 200;
    margin: 0;
    padding: 0.35rem;
    list-style: none;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg, 0 12px 32px rgba(15, 23, 42, 0.12));
    max-height: 14rem;
    overflow-y: auto;
    min-width: 17.5rem;
}

.recipient-suggest--pane {
    z-index: 1200;
}

.recipient-suggest[hidden] {
    display: none;
}

.recipient-suggest-label {
    padding: 0.35rem 0.5rem 0.2rem;
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.recipient-suggest-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.5rem 0.55rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.recipient-suggest-item:hover,
.recipient-suggest-item.is-active {
    background: var(--color-primary-soft, rgba(59, 130, 246, 0.1));
}

.recipient-suggest-avatar {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
    text-transform: uppercase;
}

.recipient-suggest-avatar--domain {
    background: var(--color-bg);
    color: var(--color-primary);
    border: 1px solid var(--color-border);
    font-size: 0.875rem;
    font-weight: 700;
}

.recipient-suggest-text {
    min-width: 0;
    flex: 1;
}

.recipient-suggest-name {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recipient-suggest-email {
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    line-height: 1.25;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recipient-suggest-kbd {
    flex-shrink: 0;
    font-size: 0.6875rem;
    color: var(--color-text-muted);
    padding: 0.15rem 0.35rem;
    border: 1px solid var(--color-border);
    border-radius: 0.25rem;
    background: var(--color-bg);
}

.recipient-input {
    flex: 1 1 8rem;
    min-width: 6rem;
    width: auto;
    padding: 0.4rem 0;
    border: none;
    outline: none;
    font-size: 0.875rem;
    font-family: inherit;
    background: transparent;
    color: var(--color-text);
    box-shadow: none;
}

.recipient-input:focus {
    border: none;
    box-shadow: none;
    outline: none;
}

.recipient-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: min(100%, 18rem);
    padding: 0.15rem 0.3rem 0.15rem 0.15rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    font-size: 0.8125rem;
    line-height: 1.2;
}

.recipient-chip.is-invalid {
    border-color: var(--color-danger);
    background: rgba(220, 38, 38, 0.06);
}

.recipient-chip-avatar {
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 600;
    flex-shrink: 0;
    text-transform: uppercase;
}

.recipient-chip-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text);
}

.recipient-chip-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0;
    font-size: 1rem;
    line-height: 1;
    border-radius: 50%;
    flex-shrink: 0;
}

.recipient-chip-remove:hover {
    background: var(--color-border-subtle);
    color: var(--color-text);
}

.compose-recipient-meta {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding-top: 0.45rem;
}

.compose-recipient-meta button {
    border: none;
    background: none;
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    padding: 0;
    font-family: inherit;
}

.compose-recipient-meta button:hover {
    color: var(--color-primary);
}

.compose-recipient-meta button.is-active {
    color: var(--color-primary);
}

.compose-subject-group input {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

.form-section {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--color-border);
}

.form-section-title {
    margin: 0 0 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-top: 0.25rem;
    padding-top: 0.5rem;
}

/* Status */
.status {
    margin: 0;
    font-weight: 600;
}

.status-ok {
    color: #059669;
}

.status-error {
    color: var(--color-danger);
}

.status-meta {
    margin: 0.75rem 0 0;
    font-size: 0.875rem;
}

.status-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem;
    margin-top: 1rem;
}

.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.card-header-row h3 {
    margin: 0;
}

.data-table code {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

/* Login — matches app chrome */
.login-body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
}

.login-header {
    flex-shrink: 0;
    background: var(--color-header);
    border-bottom: 1px solid var(--color-border);
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 var(--space-4);
}

.login-brand {
    text-decoration: none;
}

.login-brand:hover {
    text-decoration: none;
}

.login-page {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: none;
    padding: var(--space-6) var(--space-4);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-6) var(--space-5);
    box-shadow: var(--shadow-sm);
}

.login-card h2 {
    margin: 0 0 var(--space-1);
    font-weight: 600;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.login-form .form-group {
    margin-bottom: 1rem;
}

.login-form .form-group label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 500;
    font-size: 0.875rem;
}

.login-form .btn {
    margin-top: 0.75rem;
    min-height: 0;
    padding-top: 0.65rem;
    padding-bottom: 0.65rem;
    font-size: 0.9375rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

.login-form .btn-block + .btn-block {
    margin-top: var(--space-2);
}

.error-card {
    text-align: center;
}

.error-card .error-code {
    font-size: 2.5rem;
    font-weight: 600;
    color: var(--color-primary);
    line-height: 1;
    margin-bottom: var(--space-2);
}

.error-card h2 {
    margin: 0 0 var(--space-2);
}

/* Admin */
.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1.5rem;
    padding: 0.35rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

.admin-nav-link {
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-secondary);
    background: transparent;
    border: 1px solid transparent;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.admin-nav-link:hover {
    color: var(--color-text);
    background: var(--color-bg);
    text-decoration: none;
}

.admin-nav-link.active {
    color: var(--color-primary);
    background: var(--color-primary-light);
    border-color: var(--color-primary-subtle);
    font-weight: 600;
}

.admin-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.admin-stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: none;
}

.admin-stat-value {
    display: block;
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-primary);
}

.admin-stat-label {
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    background: #f1f5f9;
    color: #475569;
}

.badge-admin { background: #eef2ff; color: #4338ca; }
.badge-employee { background: #ecfdf5; color: #047857; }
.badge-spam { background: #fef2f2; color: #b91c1c; }
.badge-client { background: #fff7ed; color: #c2410c; }
.badge-company { background: #f0f9ff; color: #0369a1; }
.badge-inbox, .badge-trash, .badge-sent, .badge-other { background: #f1f5f9; color: #64748b; }
.badge-active { background: #ecfdf5; color: #047857; }
.badge-inactive { background: #f1f5f9; color: #64748b; }

.data-table td.admin-actions,
.data-table td.table-actions {
    vertical-align: middle;
    white-space: nowrap;
}

/* Lay actions out inline so the <td> stays a real table cell. Applying
   display:flex directly to a <td> removes it from the table formatting context
   and breaks the column/row borders. */
.admin-actions > *,
.table-actions > * {
    display: inline-block;
    vertical-align: middle;
    margin: 0;
    padding: 0;
    border: 0;
}

.admin-actions > * + *,
.table-actions > * + * {
    margin-left: 0.85rem;
}

.admin-folders-page .admin-nav {
    margin-bottom: 0.5rem;
}

.admin-folders-page .card {
    margin-bottom: 0;
}

/* Admin folder tree */
.admin-folder-tree-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--color-border-subtle);
}

.admin-folder-search {
    flex: 1 1 14rem;
    max-width: 22rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.875rem;
}

.admin-folder-tree-actions {
    display: flex;
    gap: 0.5rem;
}

.admin-folder-tree-head,
.admin-folder-tree-row {
    display: grid;
    grid-template-columns: minmax(14rem, 2.2fr) 9rem 6rem 3.25rem 3.75rem 5.75rem;
    gap: 0.65rem;
    align-items: center;
}

.admin-folder-tree-head {
    padding: 0.5rem 1rem 0.5rem calc(1rem + 1.125rem + 0.2rem + 18px);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-surface-elevated);
}

.admin-folder-tree {
    padding: 0.25rem 0;
}

.admin-folder-tree-row {
    padding: 0.2rem 1rem;
    min-height: 2.25rem;
    border-bottom: 1px solid var(--color-border-subtle);
    transition: background 0.1s ease;
}

.admin-folder-tree-row:hover {
    background: var(--color-surface-alt);
}

.admin-folder-tree-col-name {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 0;
    padding-left: calc(var(--tree-depth, 0) * 1.125rem);
}

.admin-folder-branch-toggle,
.admin-folder-branch-spacer {
    flex: 0 0 1.125rem;
    width: 1.125rem;
    height: 1.125rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.admin-folder-branch-toggle {
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    border-radius: 3px;
    cursor: pointer;
    padding: 0;
}

.admin-folder-branch-toggle:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--color-text);
}

.admin-folder-branch-chevron {
    transition: transform 0.15s ease;
    display: block;
}

.admin-folder-branch.is-open > .admin-folder-tree-row .admin-folder-branch-toggle .admin-folder-branch-chevron {
    transform: rotate(90deg);
}

.admin-folder-tree-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.88;
}

.admin-folder-tree-label {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.05rem;
    line-height: 1.3;
}

.admin-folder-tree-display {
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--color-text);
}

.admin-folder-tree-path {
    font-size: 0.6875rem;
    color: var(--color-text-muted);
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.admin-folder-tree-col-type,
.admin-folder-tree-col-user,
.admin-folder-tree-col-status {
    font-size: 0.8125rem;
}

.admin-folder-tree-col-user {
    color: var(--color-text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-folder-tree-col-actions {
    font-size: 0.8125rem;
}

.admin-folder-tree-col-action {
    font-size: 0.8125rem;
    white-space: nowrap;
}

.admin-folder-tree-col-action .admin-action-form {
    margin: 0;
}

.admin-folder-action-empty {
    color: var(--color-text-muted);
}

/* User-owned (employee mailbox) folders are locked in the folder list — they can
   only be removed by deleting the user. */
.admin-folder-lock {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--color-text-muted);
    cursor: help;
    white-space: nowrap;
}

.admin-folder-lock svg {
    flex: 0 0 auto;
    opacity: 0.7;
}

.admin-folder-tree-divider {
    height: 1px;
    margin: 0.35rem 1rem;
    background: var(--color-border-subtle);
}

.admin-folder-branch-children {
    margin: 0;
    padding: 0;
    border: none;
}

.admin-folder-branch--leaf > .admin-folder-tree-row {
    border-bottom: 1px solid var(--color-border-subtle);
}

.admin-folder-tree-empty {
    padding: 1.25rem 1rem;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* Sidebar folder tree (Thunderbird-style) */
.sidebar-folder-tree {
    padding: 0.15rem 0.25rem;
}

/* Collapsible section divider — a hairline rule with a toggle at its end. */
.sidebar-section-divider {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    box-sizing: border-box;
    padding: 0.15rem 0.55rem;
    margin: 0.1rem 0;
    user-select: none;
}

.sidebar-section-divider-line {
    flex: 1 1 0%;
    min-width: 0;
    height: 1px;
    background: var(--color-border);
}

.sidebar-section-badge {
    flex: 0 0 auto;
    min-width: 1.125rem;
    height: 1.125rem;
    padding: 0 0.35rem;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.125rem;
    text-align: center;
    color: var(--color-primary);
    background: var(--color-primary-light);
    border-radius: 999px;
}

.sidebar-section-badge[hidden] {
    display: none;
}

.sidebar-section-toggle {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.4rem;
    height: 1.4rem;
    padding: 0;
    border: 1px solid var(--color-border);
    border-radius: 6px;
    background: var(--color-surface);
    color: var(--color-text-muted, #64748b);
    cursor: pointer;
    transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.sidebar-section-toggle:hover,
.sidebar-section-toggle:focus-visible {
    background: var(--color-primary-light);
    color: var(--color-primary);
    border-color: var(--color-primary);
    outline: none;
}

.sidebar-section-chevron {
    display: block;
    transition: transform 0.18s ease;
}

/* Collapsed: chevron flips up and the section is hidden. */
.sidebar-section-divider.is-collapsed .sidebar-section-chevron {
    transform: rotate(180deg);
}

.sidebar-section-content[hidden] {
    display: none;
}

.sidebar-tree-row {
    display: flex;
    align-items: center;
    gap: 0;
    min-height: 1.75rem;
    padding: 0.125rem 0.25rem 0.125rem calc(0.25rem + var(--tree-depth, 0) * 0.85rem);
    margin: 0;
    border-radius: 4px;
    transition: background 0.1s ease;
}

.sidebar-tree-row:hover {
    background: var(--color-surface-alt);
}

.sidebar-tree-row:has(.sidebar-tree-link.active) {
    background: var(--color-primary-light);
}

.sidebar-tree-toggle,
.sidebar-tree-toggle-spacer {
    flex: 0 0 1.125rem;
    width: 1.125rem;
    height: 1.125rem;
    margin-right: 0.2rem;
    flex-shrink: 0;
}

.sidebar-tree-toggle {
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 3px;
    padding: 0;
}

.sidebar-tree-toggle:hover {
    color: var(--color-text);
    background: rgba(0, 0, 0, 0.06);
}

.sidebar-tree-chevron {
    transition: transform 0.15s ease;
    display: block;
}

.sidebar-folder-branch.is-open > .sidebar-tree-row .sidebar-tree-chevron {
    transform: rotate(90deg);
}

.sidebar-tree-link {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
    min-height: 1.625rem;
    padding: 0.15rem 0.25rem;
    margin: 0;
    border: none;
    border-left: none;
    border-radius: 0;
    background: transparent;
    font-size: 0.875rem;
    line-height: 1.35;
}

.sidebar-tree-link:hover {
    background: transparent;
    text-decoration: none;
}

.sidebar-tree-row:hover .sidebar-tree-link {
    color: var(--color-text);
}

.sidebar-tree-link.active {
    background: transparent;
    font-weight: 600;
    color: var(--color-primary);
    border-left: none;
}

.sidebar-tree-link.active .folder-icon {
    opacity: 1;
    color: var(--color-primary);
}

.sidebar-tree-link .sidebar-link-text {
    flex: 1;
    min-width: 0;
}

.sidebar-tree-link .folder-badge {
    margin-left: auto;
    flex-shrink: 0;
}

.sidebar-tree-link .folder-icon {
    width: 18px;
    height: 18px;
    opacity: 0.88;
}

.sidebar-folder-branch-children {
    margin: 0;
    padding: 0;
    border: none;
}

.sidebar-link--employee .sidebar-link-text {
    font-weight: 500;
}

.sidebar-primary-folders--tree > .sidebar-folder-branch,
.sidebar-primary-folders--tree > .sidebar-tree-row {
    margin-bottom: 0;
}

.sidebar-group-items--tree,
.sidebar-primary-folders--tree {
    padding: 0.15rem 0.25rem;
}

.admin-action-link {
    display: inline;
    padding: 0;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-primary);
    text-decoration: none;
    cursor: pointer;
}

.admin-action-link:hover {
    text-decoration: underline;
}

.admin-action-link-danger {
    color: var(--color-danger);
}

.admin-action-link-muted {
    color: var(--color-text-muted);
}

.admin-action-form,
.admin-actions form,
.table-actions form {
    display: inline;
}

.btn-link-danger,
.btn-link-muted {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.8125rem;
    cursor: pointer;
    font-family: inherit;
}

.btn-link-danger { color: var(--color-danger); }
.btn-link-muted { color: var(--color-text-muted); }

.btn-link-danger:hover,
.btn-link-muted:hover {
    text-decoration: underline;
}

/* Responsive */
@media (min-width: 640px) {
    .user-name {
        display: inline;
    }
}

@media (max-width: 899px) {
    .menu-toggle {
        display: flex;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        top: var(--header-height);
        left: 0;
        z-index: 90;
        width: min(var(--sidebar-width), 85vw);
        height: calc(100vh - var(--header-height));
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: var(--shadow-md);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .sidebar {
        padding: 0.5rem 0.35rem;
    }

    .sidebar-backdrop:not([hidden]) {
        display: block;
    }

    .main-content {
        padding: 1rem;
    }

    .mail-list-desktop,
    .mail-list-scroller,
    .mail-list-header {
        display: none !important;
    }

    .mail-list-mobile {
        display: block;
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }

    .mail-list-column .mail-list-card {
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .page-header-row {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .search-field {
        min-width: 100%;
    }

    .header-divider {
        display: none;
    }

    /* Compact mobile header: brand + account on the top row, search on its own
       full-width row below. The old fixed 3-column grid forced everything onto
       one line and overlapped on narrow screens. Because the header is now two
       rows tall, bump --header-height so the fixed sidebar drawer, sticky
       offsets and the content area all start below the real header height
       (otherwise the sidebar's Compose button hides under the header). */
    :root {
        --header-height: 6rem;
    }

    .header-inner {
        display: flex;
        flex-wrap: wrap;
        align-content: center;
        align-items: center;
        column-gap: 0.6rem;
        row-gap: 0.5rem;
        min-height: var(--header-height);
        padding-top: 0.35rem;
        padding-bottom: 0.35rem;
    }

    /* The login screen keeps a single-row header, so don't let the taller
       app-shell --header-height stretch it. */
    .login-header {
        min-height: 3.5rem;
    }

    .header-left {
        flex: 0 1 auto;
        min-width: 0;
    }

    .site-title,
    .site-brand-text {
        white-space: nowrap;
        overflow: hidden;
    }

    .header-user {
        margin-left: auto;
        flex: 0 0 auto;
    }

    .header-center {
        order: 1;
        flex: 1 1 100%;
        max-width: none;
    }

    .search-field--header {
        max-width: none;
    }

    .header-user .role-badge {
        display: none;
    }

    .page-header h2 {
        font-size: 1.25rem;
    }

    .mail-actions {
        flex-wrap: nowrap;
        overflow: visible;
        justify-content: stretch;
        gap: 0.125rem;
        margin-bottom: 0.75rem;
        padding-bottom: 0.75rem;
    }

    .mail-actions::-webkit-scrollbar {
        display: none;
    }

    .mail-action-btn {
        flex: 1 1 0;
        min-width: 0;
        width: auto;
        height: 2.125rem;
        padding: 0;
    }

    .mail-action-btn--primary {
        flex: 1 1 0;
        min-width: 0;
    }

    .mail-action-divider {
        display: none;
    }

    .mail-action-move {
        flex: 1 1 0;
        min-width: 0;
    }

    .inline-form {
        flex-wrap: wrap;
    }

    .mail-message-sender-row {
        flex-direction: column;
        gap: 0.35rem;
    }

    .mail-message-date {
        align-self: flex-end;
    }

    .mail-read-subject {
        font-size: 1.125rem;
    }

    .mail-message-card {
        margin-left: 0.75rem;
        margin-right: 0.75rem;
    }
}

@media (max-width: 480px) {
    .header-user .user-name {
        display: none;
    }

    .role-badge {
        display: none;
    }

    /* Drop the "Webmail" suffix on very narrow screens so the brand + account
       row always fits without clipping. */
    .site-brand-suffix {
        display: none;
    }
}

/* Dark theme — Outlook dark grays */
[data-theme="dark"] {
    color-scheme: dark;
    --scrollbar-thumb: #3b3a39;
    --scrollbar-thumb-hover: #a19f9d;
    --color-bg: #1b1a19;
    --color-surface: #252423;
    --color-surface-alt: #2d2c2b;
    --color-border: #3b3a39;
    --color-border-subtle: #323130;
    --color-text: #ffffff;
    --color-text-secondary: #d2d0ce;
    --color-text-muted: #a19f9d;
    --color-primary: #479ef5;
    --color-primary-hover: #62aef7;
    --color-primary-pressed: #2886de;
    --color-primary-light: rgba(71, 158, 245, 0.16);
    --color-primary-subtle: rgba(71, 158, 245, 0.28);
    --color-focus-ring: rgba(71, 158, 245, 0.45);
    --color-danger: #f1707b;
    --color-danger-hover: #ff99a4;
    --color-unread-accent: #479ef5;
    --color-mail-read-from: #f3f2f1;
    --color-mail-read-subject: #edebe9;
    --color-mail-read-date: #d6d4d1;
    --color-mail-unread-bg: #1f1e1d;
    --color-mail-unread-bg-hover: #2a2928;
    --color-header: #252423;
    --color-header-text: #ffffff;
    --shadow-xs: none;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.folder-badge {
    margin-left: auto;
    min-width: 1.125rem;
    height: 1.125rem;
    padding: 0 0.35rem;
    font-size: 0.6875rem;
    font-weight: 600;
    line-height: 1.125rem;
    text-align: center;
    color: var(--color-primary);
    background: var(--color-primary-light);
    border-radius: 999px;
}

.sidebar-link.active .folder-badge {
    color: #fff;
    background: var(--color-primary);
}

.sidebar-group-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    opacity: 0.85;
}

.mail-search-form {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.mail-search-form input[type="search"] {
    min-width: 220px;
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
}

.bulk-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
    padding: 0.625rem 1rem;
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-bg);
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

.col-check {
    width: 2rem;
}

.rich-toolbar {
    display: flex;
    gap: 0.25rem;
    padding: 0.35rem;
    border: 1px solid var(--color-border);
    border-bottom: none;
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    background: var(--color-bg);
}

.rich-toolbar button {
    min-width: 2rem;
    padding: 0.25rem 0.5rem;
    border: none;
    border-radius: 4px;
    background: transparent;
    cursor: pointer;
    color: var(--color-text);
}

.rich-editor {
    min-height: 200px;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    outline: none;
}

/* New message: pin the signature to the BOTTOM of the message box with a roomy
   writing area above it. The editor is a flex column; the writing block grows to
   fill the box (so a click anywhere above the signature lands the caret there)
   and the signature stays at the bottom. As the message grows the box scrolls and
   the signature rides below the text — like every mail client. */
.rich-editor--sig-bottom {
    display: flex;
    flex-direction: column;
}
.rich-editor--sig-bottom > .compose-body-write {
    /* flex-shrink 0: the writing area grows with the message (the box scrolls)
       instead of shrinking to fit — which used to squeeze the text and strand the
       signature in the MIDDLE. Short message → it fills the box so the signature
       sits at the bottom; long message → it grows and the box scrolls, signature
       after the content. */
    flex: 1 0 auto;
    min-height: 1.5rem;
}
.rich-editor--sig-bottom > .compose-body-sig {
    flex: 0 0 auto;
    margin-top: auto;
    /* A little breathing room between the message and the signature. */
    padding-top: 1rem;
}
/* When a saved draft is reopened its editor is a plain .rich-editor (not
   --sig-bottom, so no flex push), but the serialized body still carries the
   .compose-body-sig block. Give it the same breathing room from the message so
   the signature isn't jammed against the content — matching fresh compose. */
.rich-editor:not(.rich-editor--sig-bottom) .compose-body-sig {
    padding-top: 1rem;
}
/* Signature spacing inside a received/sent message shown in the reading pane.
   Messages we composed carry the signature in a .compose-body-sig block; give
   it breathing room from the content so it isn't jammed against it. */
.mail-body-html .compose-body-sig {
    margin-top: 1rem;
}
/* Newer messages/drafts bake a REAL blank line (.compose-sig-gap) before the
   signature at send/save time, so the separation survives into the sent mail
   and the recipient's client. Where that spacer is present, drop the
   display-only padding/margin so the gap isn't doubled. */
.compose-sig-gap + .compose-body-sig {
    margin-top: 0;
    padding-top: 0;
}

/* Compose formatting ribbon: pinned at the top of the compose panel and
   revealed only once the message body gains focus (Outlook-style). Hidden
   otherwise so the panel stays clean. */
.compose-format-toolbar {
    display: none;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.1rem;
    row-gap: 0.2rem;
    flex-shrink: 0;
    padding: 0.35rem 0.4rem;
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
}

.compose-form.is-editing-body .compose-format-toolbar {
    display: flex;
}

/* Scoped under .compose-format-toolbar so these win over the generic
   ".compose-form select { width: 100% }" rule (otherwise every dropdown
   stretches full-width and wraps onto its own row). */
.compose-format-toolbar .compose-format-select {
    height: 1.9rem;
    flex: 0 0 auto;
    padding: 0 1.4rem 0 0.4rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.78rem;
    cursor: pointer;
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

.compose-format-toolbar .compose-format-font { width: 7rem; }
.compose-format-toolbar .compose-format-size { width: 4.75rem; }

/* Icon dropdowns (alignment, line spacing). */
.compose-format-menu {
    position: relative;
    display: inline-flex;
}

.compose-format-menu-btn {
    width: auto;
    min-width: 2.3rem;
    padding: 0 0.25rem;
    gap: 0.05rem;
}

.compose-format-caret {
    opacity: 0.65;
    flex-shrink: 0;
}

.compose-format-menu-icon {
    display: none;
    align-items: center;
}

.compose-format-menu[data-menu="lineHeight"] .compose-format-menu-icon,
.compose-format-menu-btn[data-align="justifyLeft"] .icon-justifyLeft,
.compose-format-menu-btn[data-align="justifyCenter"] .icon-justifyCenter,
.compose-format-menu-btn[data-align="justifyRight"] .icon-justifyRight,
.compose-format-menu-btn[data-align="justifyFull"] .icon-justifyFull {
    display: inline-flex;
}

.compose-format-menu-pop {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 60;
    display: flex;
    padding: 0.2rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
}

.compose-format-menu-pop[hidden] { display: none; }
.compose-format-menu-pop--align { flex-direction: row; gap: 0.1rem; }
.compose-format-menu-pop--spacing { flex-direction: column; gap: 0.05rem; min-width: 4rem; }

.compose-format-menu-item {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    height: 1.9rem;
    padding: 0 0.55rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    font-size: 0.8rem;
    cursor: pointer;
}

.compose-format-menu-item:hover { background: var(--color-bg); }
.compose-format-menu-pop--spacing .compose-format-menu-item { justify-content: flex-start; }

.compose-format-color {
    width: 1.9rem;
    height: 1.9rem;
    padding: 2px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    cursor: pointer;
    vertical-align: middle;
}

.compose-format-color::-webkit-color-swatch-wrapper { padding: 0; }
.compose-format-color::-webkit-color-swatch { border: none; border-radius: 3px; }
.compose-format-color::-moz-color-swatch { border: none; border-radius: 3px; }

.compose-format-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.9rem;
    height: 1.9rem;
    padding: 0 0.45rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text);
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
    transition: background 0.12s;
}

.compose-format-btn:hover {
    background: var(--color-bg);
}

.compose-format-btn:active {
    background: var(--color-border-subtle);
}

/* Grey "pressed" state so the user can see which formatting is applied to the
   current selection (bold, italic, alignment, ...). */
.compose-format-btn.is-active,
.compose-format-btn.is-active:hover {
    background: rgba(0, 0, 0, 0.12);
    color: var(--color-text);
}

[data-theme="dark"] .compose-format-btn.is-active,
[data-theme="dark"] .compose-format-btn.is-active:hover {
    background: rgba(255, 255, 255, 0.18);
}

.compose-format-sep {
    width: 1px;
    height: 1.15rem;
    margin: 0 0.25rem;
    background: var(--color-border);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.rule-type-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.rule-type-tabs a {
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-sm);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    text-decoration: none;
    color: var(--color-text);
}

.rule-type-tabs a.active {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.drag-handle {
    cursor: grab;
    color: var(--color-text-muted);
    user-select: none;
}

tr.is-dragging {
    opacity: 0.5;
}

.attachment-preview img {
    max-width: 100%;
    max-height: 320px;
    margin-top: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
}

.error-body {
    background: var(--color-bg);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.error-page {
    text-align: center;
    padding: 2rem;
}

.error-code {
    font-size: 4rem;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1;
}

/* Confirm / alert dialog */
body.modal-open {
    overflow: hidden;
    overscroll-behavior: none;
}

.app-modal {
    position: fixed;
    inset: 0;
    z-index: 9500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.app-modal[hidden] {
    display: none !important;
}

.app-modal-backdrop {
    position: absolute;
    inset: 0;
    z-index: 0;
    background: rgba(0, 0, 0, 0.32);
    backdrop-filter: blur(1px);
}

.app-modal-dialog {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 420px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 20px 48px rgba(15, 23, 42, 0.18), 0 4px 12px rgba(15, 23, 42, 0.08);
    animation: app-modal-in 0.18s ease-out;
    overflow: hidden;
}

.app-modal-dialog--danger {
    border-color: rgba(198, 40, 40, 0.22);
}

@keyframes app-modal-in {
    from {
        opacity: 0;
        transform: translateY(-8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@media (prefers-reduced-motion: reduce) {
    .app-modal-dialog {
        animation: none;
    }
}

.app-modal-body {
    display: flex;
    gap: 1rem;
    padding: 1.35rem 1.35rem 1rem;
}

.app-modal-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
}

.app-modal-icon.is-danger {
    background: rgba(198, 40, 40, 0.12);
    color: var(--color-danger, #c62828);
}

.app-modal-icon.is-info {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

.app-modal-icon[hidden] {
    display: none;
}

.app-modal-content {
    flex: 1;
    min-width: 0;
}

.app-modal-title {
    margin: 0 0 0.35rem;
    font-size: 1.0625rem;
    font-weight: 600;
    line-height: 1.35;
    color: var(--color-text);
    letter-spacing: -0.01em;
}

.app-modal-message {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--color-text-secondary);
}

.app-modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.85rem 1.35rem 1.25rem;
    border-top: 1px solid var(--color-border-subtle);
    background: var(--color-surface-alt, var(--color-bg));
}

.app-modal-actions .btn {
    min-width: 5.5rem;
}

.app-modal-dialog--busy .app-modal-actions {
    pointer-events: none;
}

.app-modal-dialog--busy .app-modal-actions .btn.is-loading {
    pointer-events: none;
}

.app-modal-dialog--busy .app-modal-actions #confirm-modal-cancel {
    pointer-events: auto;
}

[data-theme="dark"] .app-modal-backdrop {
    background: rgba(0, 0, 0, 0.55);
}

[data-theme="dark"] .app-modal-dialog {
    box-shadow: 0 24px 56px rgba(0, 0, 0, 0.55), 0 4px 16px rgba(0, 0, 0, 0.35);
}

.app-busy-overlay {
    position: fixed;
    inset: 0;
    z-index: 12000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(3px);
}

.app-busy-overlay[hidden] {
    display: none !important;
}

.app-busy-overlay-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.85rem;
    min-width: 12rem;
    padding: 1.35rem 1.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
}

.app-busy-overlay-message {
    font-size: 0.9375rem;
    font-weight: 500;
    color: var(--color-text);
    text-align: center;
}

.app-busy-overlay-spinner {
    width: 1.75rem;
    height: 1.75rem;
}

body.app-is-busy {
    overflow: hidden;
}

[data-theme="dark"] .app-busy-overlay {
    background: rgba(15, 23, 42, 0.72);
}

[data-theme="dark"] .app-busy-overlay-panel {
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .app-modal-actions {
    background: var(--color-surface-alt);
}

/* Folder picker (mobile sheet + desktop dialog) */
.folder-picker-modal {
    z-index: 9600;
    --folder-picker-inset-x: 1.15rem;
    overflow: hidden;
}

.folder-picker-modal .app-modal-dialog--sheet {
    width: 100%;
    max-width: 420px;
    min-width: 0;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr);
    min-height: 0;
    flex-shrink: 1;
    overflow: hidden;
    max-height: min(520px, calc(100svh - 2.5rem));
    max-height: min(520px, calc(100dvh - 2.5rem));
}

.folder-picker-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 1rem var(--folder-picker-inset-x) 0.65rem;
    border-bottom: 1px solid var(--color-border-subtle);
}

.folder-picker-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--color-text);
}

.folder-picker-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.folder-picker-close:hover,
.folder-picker-close:focus-visible {
    background: var(--color-surface-alt);
    color: var(--color-text);
    outline: none;
}

.folder-picker-search-wrap {
    flex-shrink: 0;
    padding: 0.65rem var(--folder-picker-inset-x) 0.5rem;
    border-bottom: 1px solid var(--color-border-subtle);
}

.folder-picker-search {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border-subtle);
    border-radius: 8px;
    background: var(--color-surface-alt, var(--color-surface));
    color: var(--color-text);
    font-size: 0.875rem;
    font-family: inherit;
}

.folder-picker-search:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
    border-color: var(--color-primary);
}

.folder-picker-list {
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    padding: 0.35rem var(--folder-picker-inset-x);
}

.folder-picker-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    min-height: 2.75rem;
    padding: 0.55rem 0.75rem;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.folder-picker-item:hover,
.folder-picker-item:focus-visible {
    background: var(--color-primary-light);
    color: var(--color-primary);
    outline: none;
}

.folder-picker-item .ctx-folder-icon {
    width: 18px;
    min-width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.85;
    background: currentColor;
    mask-size: contain;
    mask-repeat: no-repeat;
    mask-position: center;
}

.folder-picker-item:hover .ctx-folder-icon,
.folder-picker-item:focus-visible .ctx-folder-icon {
    opacity: 1;
}

.folder-picker-item-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.folder-picker-empty {
    padding: 1.25rem 0.75rem;
    text-align: center;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

@media (max-width: 1023px) {
    .folder-picker-modal {
        align-items: flex-end;
        justify-content: center;
        padding-top: max(0.85rem, env(safe-area-inset-top, 0px));
        padding-left: max(0.85rem, env(safe-area-inset-left, 0px));
        padding-right: max(0.85rem, env(safe-area-inset-right, 0px));
        padding-bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
        --folder-picker-inset-x: 1.15rem;
    }

    .folder-picker-modal .app-modal-backdrop {
        background: rgba(0, 0, 0, 0.45);
    }

    .folder-picker-modal .app-modal-dialog--sheet {
        width: 100%;
        max-width: 100%;
        max-height: min(85svh, 100%);
        max-height: min(85dvh, 100%);
        border-radius: 16px;
        border: 1px solid var(--color-border);
        box-shadow: 0 20px 48px rgba(15, 23, 42, 0.28), 0 6px 16px rgba(15, 23, 42, 0.12);
        animation: folder-sheet-in 0.22s ease-out;
    }

    .folder-picker-list {
        padding: 0.25rem var(--folder-picker-inset-x) 0.85rem;
    }

    @keyframes folder-sheet-in {
        from {
            opacity: 0;
            transform: translateY(1.25rem) scale(0.98);
        }
        to {
            opacity: 1;
            transform: translateY(0) scale(1);
        }
    }
}

[data-theme="dark"] .folder-picker-modal .app-modal-dialog--sheet {
    box-shadow: 0 24px 56px rgba(0, 0, 0, 0.55), 0 6px 16px rgba(0, 0, 0, 0.35);
}

@media (max-width: 900px) {
    .folder-picker-modal {
        padding-top: max(1rem, env(safe-area-inset-top, 0px));
        padding-left: max(1rem, env(safe-area-inset-left, 0px));
        padding-right: max(1rem, env(safe-area-inset-right, 0px));
        padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    }

    .folder-picker-modal .app-modal-dialog--sheet {
        max-height: min(82svh, 100%);
        max-height: min(82dvh, 100%);
    }
}

@media (prefers-reduced-motion: reduce) {
    .folder-picker-modal .app-modal-dialog--sheet {
        animation: none;
    }
}

[data-theme="dark"] .folder-picker-search {
    background: var(--color-surface);
}

.mail-row.is-focused {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.filter-bar {
    padding: 1rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

@media print {
    .site-header,
    .sidebar,
    .mail-actions,
    .breadcrumb,
    .no-print,
    .flash-messages {
        display: none !important;
    }

    .main-content {
        padding: 0;
    }
}

/* Styled select */
.select-field {
    position: relative;
    width: 100%;
}

.select-field select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2.25rem;
    cursor: pointer;
}

.select-field::after {
    content: "";
    position: absolute;
    right: 0.85rem;
    top: 50%;
    width: 0.5rem;
    height: 0.5rem;
    border-right: 2px solid var(--color-text-muted);
    border-bottom: 2px solid var(--color-text-muted);
    transform: translateY(-65%) rotate(45deg);
    pointer-events: none;
}

.select-field-inline {
    width: auto;
    min-width: 180px;
}

.select-field-inline select {
    width: 100%;
}

/* Search field */
.search-field {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
    padding: 0.25rem 0.35rem 0.25rem 0.875rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    box-shadow: var(--shadow-xs);
    min-width: min(100%, 380px);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.search-field--mail {
    width: 100%;
    min-width: 0;
    max-width: none;
    padding: 0 0.65rem 0 0.75rem;
    min-height: 2.25rem;
    border-radius: var(--radius-md, 6px);
    background: var(--color-bg, #fafafa);
    border-color: var(--color-border-subtle);
    box-shadow: none;
}

.search-field--mail:focus-within {
    background: var(--color-surface);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 1px var(--color-primary), 0 0 0 3px var(--color-focus-ring);
}

.search-field--mail .search-field-input {
    min-width: 0;
    padding: 0.5rem 0.35rem !important;
    font-size: 0.8125rem;
}

.search-field-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
    color: var(--color-text-muted);
    text-decoration: none;
    transition: background 0.12s, color 0.12s;
}

.search-field-clear:hover {
    background: var(--color-surface-alt, #eee);
    color: var(--color-text);
    text-decoration: none;
}

.search-field:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-focus-ring);
}

.search-field-icon {
    display: flex;
    color: var(--color-text-muted);
    flex-shrink: 0;
}

.search-field-input {
    flex: 1;
    min-width: 140px;
    border: none !important;
    background: transparent !important;
    padding: 0.45rem 0.25rem !important;
    box-shadow: none !important;
    font-size: 0.9rem;
}

.search-field-input:focus {
    outline: none;
    box-shadow: none !important;
}

.search-field-btn {
    flex-shrink: 0;
    border-radius: 999px;
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Filter bar */
.filter-bar-modern {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-bg);
}

.filter-bar-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-muted);
    white-space: nowrap;
}

/* File upload */
.file-upload {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    transition: border-color 0.15s, background 0.15s;
}

.file-upload:hover,
.file-upload.is-dragover {
    border-color: var(--color-primary);
    background: var(--color-primary-light);
}

.file-upload-input {
    position: absolute;
    width: 0.1px;
    height: 0.1px;
    opacity: 0;
    overflow: hidden;
    z-index: -1;
}

.file-upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 1.5rem 1rem;
    cursor: pointer;
    text-align: center;
}

.file-upload-icon {
    color: var(--color-primary);
}

.file-upload-text {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--color-text);
}

.file-upload-hint {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.file-upload-list {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin: 0;
    padding: 0 0.875rem 0.875rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

/* With files attached, the dropzone header shrinks to a compact strip so the
   chips get the space. */
.file-upload.has-files .file-upload-label {
    flex-direction: row;
    justify-content: center;
    padding: 0.6rem 1rem;
    gap: 0.5rem;
}

.file-upload.has-files .file-upload-icon svg {
    width: 16px;
    height: 16px;
}

.file-upload.has-files .file-upload-hint {
    margin-left: 0.25rem;
}

/* Attachment chips (compose): pill per file with type-coloured icon, size and
   a remove button — mirrors the received-attachment cards. */
.attach-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    max-width: 260px;
    padding: 0.35rem 0.45rem 0.35rem 0.6rem;
    border: 1px solid var(--color-border-subtle);
    border-radius: 999px;
    background: var(--color-surface);
    color: var(--color-text);
    transition: box-shadow 0.15s, border-color 0.15s;
}

.attach-chip:hover {
    border-color: var(--color-border);
    box-shadow: var(--shadow-sm, 0 1px 3px rgba(0, 0, 0, 0.08));
}

.attach-chip-icon {
    display: inline-flex;
    flex-shrink: 0;
    color: var(--color-text-secondary);
}

.attach-chip--image .attach-chip-icon { color: #7b1fa2; }
.attach-chip--pdf .attach-chip-icon { color: #c5221f; }
.attach-chip--doc .attach-chip-icon { color: #1a73e8; }
.attach-chip--sheet .attach-chip-icon { color: #188038; }
.attach-chip--zip .attach-chip-icon { color: #b06000; }

.attach-chip-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
    color: var(--color-text);
}

.attach-chip-size {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--color-text-secondary);
}

.attach-chip .file-upload-remove {
    width: 22px;
    height: 22px;
    margin-left: 0;
}

/* Sidebar collapse groups */
.sidebar-group {
    margin-bottom: 0.2rem;
}

.sidebar-group-toggle {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    width: 100%;
    min-height: 2.25rem;
    padding: 0.4rem 0.65rem;
    margin: 0.35rem 0 0.2rem;
    border: none;
    background: transparent;
    color: var(--color-text-secondary);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
    cursor: pointer;
    border-radius: var(--radius-sm);
    font-family: inherit;
    transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-group-toggle:hover {
    background: var(--color-surface-alt);
    color: var(--color-text);
    box-shadow: none;
}

.sidebar-group-toggle:focus-visible {
    outline: 2px solid var(--color-primary-subtle);
    outline-offset: 1px;
}

.sidebar-group-chevron-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    flex-shrink: 0;
    border-radius: 5px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    color: var(--color-text-muted);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.2s ease;
}

.sidebar-group-toggle:hover .sidebar-group-chevron-btn {
    border-color: var(--color-primary-subtle);
    color: var(--color-primary);
}

.sidebar-group-chevron-icon {
    display: block;
    transition: transform 0.2s ease;
}

.sidebar-group.is-open .sidebar-group-chevron-icon {
    transform: rotate(90deg);
}

.sidebar-group-title {
    flex: 1;
    text-align: left;
    min-width: 0;
}

/* Manual display-group ("Show under"): the heading reuses the folder-tree row
   styling so its icon lines up with Inbox/Sent, and the expand chevron sits at
   the end (back) of the folder name. Display-only — no mailbox is moved. */
.sidebar-group--folder {
    margin-bottom: 0;
}

.sidebar-group--folder .sidebar-group-toggle {
    flex: 1;
    width: auto;
    min-width: 0;
    min-height: 1.625rem;
    gap: 0.45rem;
    padding: 0.15rem 0.25rem;
    margin: 0;
    font-size: 0.875rem;
    font-weight: 400;
    letter-spacing: normal;
    line-height: 1.35;
    color: inherit;
    border-radius: 0;
}

.sidebar-group--folder .sidebar-group-toggle:hover {
    background: transparent;
    color: inherit;
}

.sidebar-group--folder .sidebar-group-toggle .folder-icon {
    width: 18px;
    height: 18px;
    opacity: 0.88;
    flex-shrink: 0;
}

.sidebar-group--folder .sidebar-group-toggle .sidebar-link-text {
    flex: 1;
    min-width: 0;
    text-align: left;
}

.sidebar-group--folder .folder-badge-sm {
    flex-shrink: 0;
    margin-left: 0.25rem;
}

.sidebar-group--folder .sidebar-group-caret {
    order: 1;
    flex-shrink: 0;
    margin-left: 0.25rem;
    color: var(--color-text-muted);
    transition: transform 0.15s ease;
}

.sidebar-group--folder.is-open .sidebar-group-caret {
    transform: rotate(180deg);
}

/* Children reuse the folder-tree rows; drop the generic group-items indent so
   the tree-depth handles the nesting consistently with the rest of the tree. */
.sidebar-group--folder .sidebar-group-items {
    padding: 0;
}

.sidebar-group--folder.is-collapsible .sidebar-group-items .sidebar-link {
    padding-left: 0.25rem;
}

.sidebar-group-items {
    display: none;
    padding: 0.15rem 0 0.35rem 0.35rem;
}

/* Child combinator so an open parent group only reveals its own items — a
   nested group keeps controlling its own collapse independently. */
.sidebar-group.is-open > .sidebar-group-items,
.sidebar-group.is-fixed > .sidebar-group-items {
    display: block;
}

.sidebar-group.is-fixed {
    margin-bottom: 0;
}

.sidebar-group.is-collapsible .sidebar-group-items .sidebar-link {
    padding-left: 0.65rem;
}

.sidebar-group.is-collapsible .sidebar-group-items .sidebar-link.is-nested {
    padding-left: calc(0.65rem + var(--folder-depth, 0) * 0.95rem);
}

.sidebar-divider {
    height: 1px;
    margin: 0.5rem 0.75rem;
    background: var(--color-border-subtle);
}

.folder-badge-sm {
    font-size: 0.625rem;
    min-width: 1rem;
    padding: 0 0.3rem;
}

/* Standalone pages (settings, change password) — same header chrome */
.standalone-body {
    background: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.standalone-header {
    flex-shrink: 0;
    min-height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    background: var(--color-header);
    border-bottom: 1px solid var(--color-border);
}

.standalone-header-brand {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-header-text);
    text-decoration: none;
}

.standalone-header-brand:hover {
    color: var(--color-primary);
    text-decoration: none;
}

.standalone-back {
    font-weight: 400;
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    text-decoration: none;
}

.standalone-back:hover {
    color: var(--color-primary);
    text-decoration: none;
}

/* legacy alias — use .back-nav in standalone header */
.standalone-header .back-nav {
    margin: 0;
}

.standalone-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.btn-ghost-standalone {
    padding: var(--space-1) var(--space-3);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 0.8125rem;
    font-family: inherit;
    cursor: pointer;
}

.btn-ghost-standalone:hover {
    background: var(--color-surface-alt);
    color: var(--color-text);
}

.standalone-main {
    flex: 1;
    max-width: 640px;
    width: 100%;
    margin: 0 auto;
    padding: var(--space-5) var(--space-4);
}

.standalone-card {
    box-shadow: none;
    margin-bottom: var(--space-3);
}

.standalone-page-header h2 {
    margin: 0 0 var(--space-1);
}

[data-theme="dark"] .pagination {
    background: var(--color-surface);
}

[data-theme="dark"] .bulk-toolbar {
    background: rgba(129, 140, 248, 0.08);
}

[data-theme="dark"] .search-field {
    background: var(--color-surface);
}

[data-theme="dark"] .search-field--mail {
    background: var(--color-bg);
}

[data-theme="dark"] .search-field--mail:focus-within {
    background: var(--color-surface);
}

[data-theme="dark"] .mail-command-bar {
    background: linear-gradient(to bottom, var(--color-surface) 0%, var(--color-bg) 100%);
}

[data-theme="dark"] .pagination-nav-btn {
    background: var(--color-surface);
    border-color: var(--color-border);
}

[data-theme="dark"] .rich-editor {
    background: var(--color-surface);
    color: var(--color-text);
}

/* Important / flagged indicator */
.flag-dot {
    color: #f59e0b;
    font-size: 0.85rem;
    line-height: 1;
    margin-left: 0.15rem;
}

.mail-row-meta .flag-dot.mail-row-flag,
.mail-card-meta .flag-dot.mail-row-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.125rem;
    height: 1.125rem;
    margin-left: 0;
    font-size: 1.0625rem;
}

.mail-row.mail-flagged .col-subject,
.mail-row.mail-flagged .mail-row-subject,
.mail-card.mail-flagged .mail-card-subject {
    font-weight: 600;
}

/* Right-click context menu */
.context-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1999;
    background: rgba(15, 23, 42, 0.42);
}

.context-menu-backdrop[hidden] {
    display: none !important;
}

.context-menu {
    position: fixed;
    z-index: 2000;
    min-width: 224px;
    overflow: visible;
    padding: 0.4rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 12px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22);
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    position: relative;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.7rem;
    border: none;
    background: transparent;
    color: var(--color-text);
    font-size: 0.875rem;
    line-height: 1.2;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
}

.context-menu-item:hover,
.context-menu-item:focus-visible {
    background: var(--color-primary-light);
    color: var(--color-primary);
    outline: none;
}

.context-menu-item .ctx-ico {
    flex: 0 0 auto;
    color: var(--color-text-muted);
    transition: color 0.1s ease;
}

.context-menu-item:hover > .ctx-ico,
.context-menu-item:focus-within > .ctx-ico {
    color: var(--color-primary);
}

.context-menu-item .ctx-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
}

.context-menu-item .ctx-chevron {
    flex: 0 0 auto;
    margin-left: auto;
    color: var(--color-text-muted);
}

.context-menu-item.is-danger {
    color: var(--color-danger);
}

.context-menu-item.is-danger .ctx-ico {
    color: var(--color-danger);
}

.context-menu-item.is-danger:hover {
    background: rgba(220, 38, 38, 0.08);
    color: var(--color-danger);
}

.context-menu-item.is-danger:hover > .ctx-ico {
    color: var(--color-danger);
}

.context-menu-sep {
    height: 1px;
    margin: 0.35rem 0.3rem;
    background: var(--color-border-subtle);
}

.context-menu-item--cancel {
    justify-content: center;
    color: var(--color-text-muted);
    font-weight: 500;
}

.context-menu-item--cancel:hover,
.context-menu-item--cancel:focus-visible {
    background: var(--color-surface-alt);
    color: var(--color-text);
}

.context-menu-item--cancel .ctx-ico {
    display: none;
}

@media (max-width: 900px) {
    body.context-menu-open {
        overflow: hidden;
    }

    .context-menu {
        min-width: min(280px, calc(100vw - 24px));
        max-height: min(70vh, calc(100vh - 2rem));
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

.context-menu-header {
    padding: 0.4rem 0.7rem 0.2rem;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

/* Hover-expand submenu (e.g. "Move to") */
.context-submenu {
    position: absolute;
    top: -0.35rem;
    left: calc(100% - 3px);
    margin-left: 0;
    display: flex;
    flex-direction: column;
    min-width: 212px;
    max-width: 260px;
    max-height: min(320px, calc(100vh - 20px));
    overflow: hidden;
    padding: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
    opacity: 0;
    visibility: hidden;
    transform: translateX(-4px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s ease;
    pointer-events: none;
    z-index: 2001;
}

.context-submenu-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.25rem 0.3rem 0.35rem;
}

.context-submenu::after {
    content: "";
    position: absolute;
    left: 0;
    right: 6px;
    bottom: 0;
    height: 18px;
    border-radius: 0 0 10px 10px;
    background: linear-gradient(to top, var(--color-surface) 30%, transparent);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.context-submenu.has-scroll:not(.is-scrolled-end)::after {
    opacity: 1;
}

.context-submenu-header {
    flex-shrink: 0;
    padding: 0.5rem 0.75rem 0.4rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    background: var(--color-surface-alt, var(--color-surface));
    border-bottom: 1px solid var(--color-border-subtle);
    border-radius: 10px 10px 0 0;
}

.context-submenu .context-submenu-item {
    padding: 0.45rem 0.6rem;
    gap: 0.65rem;
    font-size: 0.8125rem;
    border-radius: 6px;
}

.context-submenu .ctx-folder-icon {
    width: 18px;
    min-width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.8;
    background: currentColor;
    mask-size: contain;
    mask-repeat: no-repeat;
    mask-position: center;
}

.context-submenu .context-submenu-item .ctx-label {
    flex: 1 1 auto;
    min-width: 0;
    font-weight: 500;
}

.context-submenu .context-submenu-item:hover .ctx-folder-icon,
.context-submenu .context-submenu-item:focus-visible .ctx-folder-icon {
    opacity: 1;
    color: var(--color-primary);
}

.context-submenu .context-submenu-item:hover,
.context-submenu .context-submenu-item:focus-visible {
    background: var(--color-primary-light);
    color: var(--color-primary);
    outline: none;
}

/* Invisible bridge so the cursor can cross the gap without closing the flyout */
.context-submenu::before {
    content: "";
    position: absolute;
    top: 0;
    left: -14px;
    width: 16px;
    height: 100%;
}

.context-submenu.flip-left::before {
    left: auto;
    right: -14px;
    width: 16px;
}

.context-menu-item.has-submenu:hover > .context-submenu,
.context-menu-item.has-submenu.is-submenu-open > .context-submenu,
.context-menu-item.has-submenu:focus-within > .context-submenu {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    pointer-events: auto;
}

.context-submenu.flip-left {
    left: auto;
    right: calc(100% - 3px);
    margin-left: 0;
    margin-right: 0;
    transform: translateX(6px);
}

.context-submenu.flip-below {
    top: 100%;
    left: 0;
    right: auto;
    margin-left: 0;
    margin-top: 4px;
    margin-right: 0;
    transform: translateY(-4px);
}

.context-submenu.flip-below::before {
    top: -12px;
    left: 0;
    width: 100%;
    height: 12px;
}

.context-menu-item.has-submenu:hover > .context-submenu.flip-below,
.context-menu-item.has-submenu.is-submenu-open > .context-submenu.flip-below,
.context-menu-item.has-submenu:focus-within > .context-submenu.flip-below {
    transform: translateY(0);
}

.context-menu-item.has-submenu:hover > .context-submenu.flip-left,
.context-menu-item.has-submenu.is-submenu-open > .context-submenu.flip-left,
.context-menu-item.has-submenu:focus-within > .context-submenu.flip-left {
    transform: translateX(0);
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Per-row actions (kebab) menu trigger */
.col-date {
    position: relative;
    white-space: nowrap;
}

.mail-kebab {
    border: none;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.15rem 0.35rem;
    border-radius: 6px;
    opacity: 0;
    transition: opacity 0.12s ease, background 0.12s ease;
    margin-left: 0.25rem;
}

.mail-row:hover .mail-kebab,
.mail-kebab:focus-visible {
    opacity: 1;
}

.mail-kebab:hover {
    background: var(--color-border-subtle);
    color: var(--color-text);
}

.mail-card-top .mail-kebab {
    opacity: 0.7;
    margin-left: 0.35rem;
}

.mail-row-removing {
    opacity: 0;
    transition: opacity 0.18s ease;
}

@media (max-width: 900px) {
    .mail-kebab {
        opacity: 0.7;
    }

    .mail-row,
    .mail-card {
        -webkit-touch-callout: none;
    }
}

/* Logout button styled as a header nav link */
.header-nav-form {
    display: inline;
    margin: 0;
}

.header-nav-button {
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

/* Inline table actions layout is defined alongside .admin-actions above. */

/* Admin dashboard action row */
.admin-action-row {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    align-items: center;
}

.admin-action-row form {
    margin: 0;
}

/* Forwarded attachments list in compose */
.forwarded-attachments {
    margin: 0 0 0.25rem;
    padding-left: 1.1rem;
    list-style: disc;
    color: var(--color-text-secondary);
    font-size: 0.875rem;
}

/* ── U2: Three-pane mail workspace (desktop) ── */
html:has(.mail-workspace) {
    overflow: hidden;
    height: 100%;
}

body:has(.mail-workspace) {
    overflow: hidden;
    height: 100%;
    min-height: 0;
}

.app-shell:has(.mail-workspace) {
    height: calc(100vh - var(--header-height));
    min-height: 0;
    max-height: calc(100vh - var(--header-height));
    overflow: hidden;
}

.main-content:has(.mail-workspace) {
    padding: 0;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.mail-workspace {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.mail-list-column {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.mail-list-column .page-header--compact {
    flex-shrink: 0;
    margin-bottom: 0;
    padding: 0.75rem 0.875rem 0.625rem;
    border-bottom: 1px solid var(--color-border-subtle);
}

.page-header--mail {
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
}

.page-header-subtitle {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mail-row-folder {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    max-width: 6rem;
    padding: 0.1rem 0.4rem;
    margin-right: 0.25rem;
    border-radius: 999px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--color-primary);
    background: var(--color-primary-light);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.page-header--mail .page-title-row h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.page-header--mail .page-header-count {
    min-width: 1.5rem;
    height: 1.5rem;
    font-size: 0.6875rem;
}

.page-header-count--unread {
    color: #fff;
    background: var(--color-primary);
    border-color: var(--color-primary);
}

/* All-read folders: a quiet "12 messages" label instead of a pill, so the
   header is always informative without shouting. */
.page-header--mail .page-header-count--muted {
    min-width: 0;
    height: auto;
    padding: 0;
    border: none;
    background: none;
    border-radius: 0;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--color-text-muted);
}

.page-header-count--hidden {
    display: none !important;
}

.mail-list-column .page-header--compact .page-header-row {
    flex-wrap: wrap;
    gap: 0.75rem;
}

.mail-list-column .page-header--compact .mail-search-form {
    width: 100%;
    flex: 1 1 100%;
    min-width: 0;
    max-width: none;
}

.mail-list-column .mail-list-card {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    border: none;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
}

.mail-list-column .mail-list-scroller {
    flex: 1;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.mail-list-column .pagination {
    flex-shrink: 0;
    max-width: 100%;
    overflow-x: hidden;
    flex-wrap: nowrap;
    padding: 0.45rem 0.75rem;
    min-height: 2.75rem;
}

.mail-list-column .pagination-pages {
    display: none;
}

.mail-list-column .pagination-page-label {
    display: none;
}

.mail-list-column .pagination-summary {
    justify-content: flex-start;
    text-align: left;
    padding-left: 0.25rem;
}

.mail-list-column .pagination-per-page {
    margin-left: auto;
    flex-shrink: 0;
}

.mail-list-column .pagination-per-page .select-field::after {
    right: 0.55rem;
}

@media (max-width: 899px) {
    .mail-list-column .pagination {
        flex-wrap: nowrap;
        gap: 0.35rem 0.5rem;
        padding: 0.5rem 0.65rem;
    }

    .mail-list-column .pagination-summary {
        flex: 1 1 auto;
        min-width: 0;
        overflow: hidden;
    }

    .mail-list-column .pagination-range {
        font-size: 0.75rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .mail-list-column .pagination-per-page {
        margin-left: 0;
        flex: 0 0 auto;
    }

    .mail-list-column .pagination-per-page .per-page-select {
        min-width: 3rem;
        max-width: 3.75rem;
        min-height: 2.25rem;
        padding: 0.25rem 1.5rem 0.25rem 0.4rem;
    }

    .pagination-per-page .per-page-select--native-hidden {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
        opacity: 0;
        pointer-events: none;
    }

    .pagination-per-page .per-page-trigger {
        width: auto;
        min-width: 3rem;
        max-width: 3.75rem;
        min-height: 2.25rem;
        font-size: 0.75rem;
        padding: 0.25rem 1.5rem 0.25rem 0.4rem;
        border-radius: var(--radius-sm);
        border: 1px solid var(--color-border-subtle);
        background-color: var(--color-surface);
        color: var(--color-text);
        text-align: center;
        cursor: pointer;
        font-family: inherit;
        font-weight: 500;
        line-height: 1.2;
    }

    .pagination-per-page .per-page-trigger:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: 2px;
    }
}

.per-page-menu {
    position: fixed;
    z-index: 9700;
    background: var(--color-surface);
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.16);
    padding: 0.35rem 0;
    min-width: 3.5rem;
}

.per-page-menu-item {
    display: block;
    width: 100%;
    padding: 0.5rem 1.25rem;
    border: none;
    background: transparent;
    color: var(--color-text);
    font-size: 0.875rem;
    font-weight: 500;
    text-align: center;
    cursor: pointer;
    font-family: inherit;
}

.per-page-menu-item.is-selected {
    color: var(--color-primary);
    font-weight: 600;
}

.per-page-menu-item:hover,
.per-page-menu-item:focus-visible {
    background: var(--color-primary-light);
    color: var(--color-primary);
    outline: none;
}

.mail-list-column .search-field-input {
    min-width: 0;
}

.mail-list-column .bulk-toolbar {
    flex-shrink: 0;
    max-width: 100%;
    overflow-x: hidden;
}

/* Outlook-style command bar */
.mail-command-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.35rem 0.5rem;
    padding: 0.35rem 0.75rem;
    border-bottom: 1px solid var(--color-border-subtle);
    background: linear-gradient(to bottom, var(--color-surface) 0%, var(--color-bg, #fafafa) 100%);
    flex-shrink: 0;
    min-width: 0;
}

.mail-command-bar-row--main,
.mail-command-bar-row--selection {
    display: contents;
}

.mail-command-bar-main-end {
    display: contents;
}

.mail-cmd-btn--compose-action,
.mail-cmd-btn--refresh-mobile {
    display: none;
}

.mail-cmd-btn--refresh-desktop {
    display: inline-flex;
}

.mail-command-bar-primary {
    flex-shrink: 0;
}

.mail-cmd-compose {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8125rem;
    padding: 0.35rem 0.75rem;
}

@media (min-width: 1024px) {
    .mail-cmd-compose {
        display: none;
    }
}

.mail-command-bar-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.15rem;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.mail-command-bar-actions::-webkit-scrollbar {
    display: none;
}

/* The command-bar buttons set an explicit display, which would override the
   browser's [hidden] rule — restore the hidden behaviour so JS-toggled buttons
   (e.g. the Trash-only Restore) actually stay hidden. */
.mail-cmd-btn[hidden] {
    display: none !important;
}

.mail-cmd-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.3rem;
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.45rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 4px);
    background: transparent;
    color: var(--color-text-secondary, var(--color-text-muted));
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
}

.mail-cmd-btn:hover:not(:disabled),
.mail-cmd-btn:focus-visible:not(:disabled) {
    background: var(--color-surface);
    border-color: var(--color-border-subtle);
    color: var(--color-text);
    box-shadow: var(--shadow-xs, 0 1px 2px rgba(0, 0, 0, 0.04));
}

.mail-cmd-btn--danger:hover:not(:disabled),
.mail-cmd-btn--danger:focus-visible:not(:disabled) {
    color: var(--color-danger, #c62828);
    border-color: rgba(198, 40, 40, 0.25);
    background: rgba(198, 40, 40, 0.06);
}

.mail-cmd-btn:disabled {
    opacity: 0.32;
    cursor: not-allowed;
}

.mail-cmd-btn:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.mail-cmd-label {
    display: none;
}

.mail-command-bar .mail-cmd-label {
    display: none !important;
}

.mail-cmd-btn--flag[aria-pressed="true"] {
    color: var(--color-primary);
}

.mail-cmd-btn--flag .mail-cmd-icon--unflag {
    display: none;
}

.mail-cmd-btn--flag[aria-pressed="true"] .mail-cmd-icon--flag {
    display: none;
}

.mail-cmd-btn--flag[aria-pressed="true"] .mail-cmd-icon--unflag {
    display: block;
}

.mail-command-divider {
    width: 1px;
    height: 1.25rem;
    background: var(--color-border-subtle);
    flex-shrink: 0;
}

.mail-cmd-btn--mobile-only,
.mail-command-divider--mobile-only {
    display: none !important;
}

@media (min-width: 1024px) {
    .mail-command-bar {
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
        gap: 0.35rem 0.5rem;
        padding: 0.35rem 0.75rem;
    }

    .mail-command-bar-row--main,
    .mail-command-bar-row--selection,
    .mail-command-bar-main-end {
        display: contents;
    }

    .mail-command-bar-primary,
    .mail-cmd-btn--refresh-mobile,
    .mail-cmd-btn--compose-action {
        display: none !important;
    }

    .mail-cmd-btn--refresh-desktop {
        display: inline-flex !important;
    }

    .mail-command-bar-actions {
        order: 1;
        flex: 1 1 auto;
        min-width: 0;
    }

    .mail-command-bar-meta {
        order: 2;
        margin-left: auto;
        flex-shrink: 0;
    }

    .mail-command-bar:not(.mail-command-bar--has-selection) .mail-command-bar-actions .mail-cmd-btn:disabled,
    .mail-command-bar:not(.mail-command-bar--has-selection) .mail-command-divider,
    .mail-command-bar:not(.mail-command-bar--has-selection) .mail-cmd-move {
        display: none;
    }

    .mail-command-bar--has-selection .mail-command-bar-actions .mail-cmd-btn:not(:disabled),
    .mail-command-bar--has-selection .mail-command-bar-actions .mail-cmd-move {
        display: inline-flex !important;
    }

    .mail-command-bar--has-selection .mail-command-bar-actions .mail-command-divider {
        display: inline-block;
    }
}

.mail-cmd-move {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm, 4px);
    background: var(--color-surface);
    overflow: hidden;
}

.mail-cmd-move-select-wrap {
    flex: 1 1 auto;
    min-width: 0;
}

.mail-cmd-move-select {
    min-height: 2rem;
}

.mail-cmd-move-select:disabled {
    opacity: 0.38;
    cursor: not-allowed;
}

.mail-cmd-move-select option,
.mail-action-move-select option,
.move-form select option,
.compose-form select option,
.select-field select option {
    background: var(--color-surface);
    color: var(--color-text);
}

.mail-cmd-btn--move {
    border: none;
    border-radius: 0;
    min-width: 2rem;
    height: 2rem;
}

.mail-cmd-move:has(.mail-cmd-move-select:disabled) {
    opacity: 0.55;
}

.mail-command-bar-meta {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    margin-left: auto;
    flex-shrink: 0;
}

.mail-list-select-all--toolbar {
    font-size: 0.75rem;
}

.mail-select-all-banner {
    padding: 0.5rem 0.75rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    background: var(--color-surface-alt, #f5f6f8);
    border-bottom: 1px solid var(--color-border-subtle);
    text-align: center;
}

.mail-select-all-banner button {
    background: none;
    border: none;
    padding: 0;
    font: inherit;
    color: var(--color-primary, #2563eb);
    cursor: pointer;
    text-decoration: underline;
}

.mail-select-all-banner button:hover {
    color: var(--color-primary-hover, #1d4ed8);
}

[data-theme="dark"] .mail-select-all-banner {
    background: var(--color-surface-alt, #2d2d2d);
}

[data-theme="dark"] .mail-cmd-btn:hover:not(:disabled),
[data-theme="dark"] .mail-cmd-btn:focus-visible:not(:disabled) {
    background: var(--color-surface-alt, #2d2d2d);
}

[data-theme="dark"] .context-menu {
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

[data-theme="dark"] .context-submenu {
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .mail-cmd-move-select,
[data-theme="dark"] .mail-action-move-select {
    background: var(--color-surface-alt);
}

[data-theme="dark"] .mail-cmd-move-select:focus,
[data-theme="dark"] .mail-action-move-select:focus {
    outline: none;
    box-shadow: inset 0 0 0 1px var(--color-primary-subtle);
}

/* Outlook-style message rows (desktop list) */
.mail-list-header {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.75rem 0.35rem 0.5rem;
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
    flex-shrink: 0;
}

.mail-list-select-all {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    cursor: pointer;
    user-select: none;
}

.mail-list-rows {
    min-width: 0;
}

.mail-row--outlook {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    padding: 0.5rem 0.5rem 0.5rem 0.25rem;
    border-bottom: 1px solid var(--color-border-subtle);
    cursor: pointer;
    transition: background 0.12s;
    border-left: var(--mail-unread-bar-width) solid transparent;
}

.mail-row--outlook:hover {
    background: var(--color-surface-alt, #f3f2f1);
}

.mail-row--outlook.mail-unread {
    background: var(--color-mail-unread-bg);
    border-left-color: var(--color-unread-accent);
}

.mail-row--outlook.mail-unread:hover,
.mail-row--outlook.mail-unread:focus-within {
    background: var(--color-mail-unread-bg-hover);
}

.mail-row--outlook.mail-unread.is-checked,
.mail-row--outlook.mail-unread.is-checked:hover,
.mail-row--outlook.mail-unread.is-checked:focus-within {
    background: var(--color-primary-subtle, rgba(0, 120, 212, 0.08));
}

.mail-row--outlook.mail-unread .mail-row-from,
.mail-row--outlook.mail-unread .mail-row-subject {
    font-weight: 600;
    color: var(--color-text);
}

.mail-row--outlook.mail-unread .mail-row-date {
    color: var(--color-text-secondary);
    font-weight: 500;
}

.mail-row-check {
    flex-shrink: 0;
    width: 1.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mail-row--outlook .mail-check {
    opacity: 0;
    transition: opacity 0.12s;
}

.mail-row--outlook:hover .mail-check,
.mail-row--outlook .mail-check:focus-visible,
.mail-row--outlook .mail-check:checked,
.mail-row--outlook.is-checked .mail-check,
.mail-row--outlook.is-selected .mail-check,
.mail-row--outlook.is-focused .mail-check,
.mail-list-card:has(.mail-check:checked) .mail-row--outlook .mail-check {
    opacity: 1;
}

.mail-row--outlook:focus-within {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
}

.mail-row--outlook.is-checked {
    background: var(--color-primary-subtle, rgba(0, 120, 212, 0.08));
}

.mail-row--outlook.is-checked:hover,
.mail-row--outlook.is-checked:focus-within {
    background: var(--color-primary-subtle, rgba(0, 120, 212, 0.08));
}

.mail-row-avatar {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #fff;
    letter-spacing: -0.02em;
}

.mail-row-body {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mail-row-text {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.mail-row-line1 {
    display: flex;
    align-items: center;
    min-width: 0;
}

.mail-row-from {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.8125rem;
    color: var(--color-mail-read-from, var(--color-text-secondary));
    font-weight: 500;
}

.mail-row--outlook:not(.mail-unread) .mail-row-date {
    color: var(--color-mail-read-date, var(--color-text-muted));
}

.mail-row-meta {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    align-self: center;
    max-width: 42%;
}

.mail-row-date {
    display: inline-flex;
    align-items: center;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    line-height: 1;
}

.mail-row-attach {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.125rem;
    height: 1.125rem;
    color: var(--color-text-muted);
}

.mail-row-attach svg {
    display: block;
    width: 14px;
    height: 14px;
}

.mail-card-meta {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    height: 1.125rem;
}

.mail-row-subject {
    margin-top: 0.125rem;
    font-size: 0.8125rem;
    color: var(--color-mail-read-subject, var(--color-text-secondary));
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.35;
}

.mail-row-snippet {
    margin-top: 0.125rem;
    min-height: 1.1rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted, var(--color-text-secondary));
    font-weight: 400;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.35;
}

.mail-row-snippet:empty {
    margin-top: 0.125rem;
}

.mail-row-draft-badge {
    flex-shrink: 0;
    margin-right: 0.35rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #ef4444;
    letter-spacing: 0.01em;
}

.mail-unread .mail-row-snippet {
    color: var(--color-text-secondary);
}

.mail-row--outlook.mail-unread .mail-row-snippet {
    color: var(--color-text);
    opacity: 0.72;
}

.mail-row--outlook .mail-kebab {
    flex-shrink: 0;
    opacity: 0;
}

.mail-row--outlook:hover .mail-kebab,
.mail-row--outlook .mail-kebab:focus-visible {
    opacity: 1;
}

.mail-row--outlook.is-selected {
    background: var(--color-primary-light);
    border-left-color: var(--color-primary);
}

.mail-row--outlook.is-selected:hover {
    background: var(--color-primary-subtle);
}

.mail-row-flag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 1.125rem;
    height: 1.125rem;
    font-size: 1.0625rem;
    line-height: 1;
    margin-left: 0;
    color: #f59e0b;
}

.reading-pane {
    display: none;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    position: relative;
}

.reading-pane.is-compose-open .reading-pane-viewport {
    display: none;
}

/* Fail-safe: the compose panel and the reading-pane viewport (empty state /
   open message) must never share the pane. Hiding the viewport is normally
   driven by the .is-compose-open class, but a state race (a folder refresh or
   pane render landing while compose is opening) can drop that class while the
   panel stays visible — which split the pane in half. Key the hide off the
   panel's ACTUAL visibility too so the two can never show at once. */
.reading-pane:has(> .compose-panel:not([hidden])) .reading-pane-viewport {
    display: none !important;
}

.compose-panel {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: var(--color-surface);
}

.compose-panel[hidden] {
    display: none !important;
}

.compose-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
    flex-shrink: 0;
}

.compose-panel-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.compose-panel-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}

.compose-panel-close:hover,
.compose-panel-close:focus-visible {
    background: var(--color-surface-alt, #f3f2f1);
    color: var(--color-text);
}

.compose-panel-body {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 1rem 0;
}

.compose-panel-inner {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.compose-panel-inner .compose-form {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 0.65rem;
}

.compose-panel-inner .form-group {
    margin-bottom: 0;
    flex-shrink: 0;
}

/* Message row fills the form's middle (flex:1, 0 basis). Clip a squeezed editor
   to its track so it can never overlap the rows below (the editor scrolls
   internally). */
.compose-panel-inner .compose-form > .form-group:has(.rich-editor) {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.compose-panel-inner .compose-form > .form-group:has(.rich-editor) > label {
    flex-shrink: 0;
    margin-bottom: 0.35rem;
}

.compose-panel-inner .rich-toolbar {
    flex-shrink: 0;
}

.compose-panel-inner .rich-editor {
    /* Fill the middle of the form. `flex: 1` (a 0 basis) reliably fills the space,
       unlike flex-basis:auto which sizes to content and left dead space below the
       Send row. The editor scrolls internally when the message is long, and keeps
       a usable min-height when the panel is short. */
    flex: 1;
    min-height: 6rem;
    max-height: none;
    overflow-y: auto;
    overflow-x: hidden;
    overflow-wrap: anywhere;
    overscroll-behavior: contain;
    padding-bottom: 1rem;
}

/* New message: the fixed rows (toolbar + Send as + To/Cc/Bcc + Subject +
   Attachments + Send) plus a usable message box can be taller than the panel.
   Let the whole form scroll in that case instead of squeezing the message box to
   nothing or overlapping the rows below it. The form is natural height but at
   least fills the panel, so the Send row still sits at the bottom when there's
   room. */
.compose-panel-inner--compose {
    overflow-y: auto;
    overscroll-behavior: contain;
}

.compose-panel-inner--compose .compose-form {
    /* Fill the panel (flex:1, 0 basis) so the editor fills the space and the Send
       row sits at the very bottom — no dead space below it. The editor scrolls
       internally for long messages, so the form never needs to overflow. */
    flex: 1;
    min-height: 0;
}

.compose-panel-inner .file-upload-label {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    padding: 0.6rem 0.75rem;
    gap: 0.45rem;
}

.compose-panel-inner .file-upload-icon svg {
    width: 20px;
    height: 20px;
}

.compose-panel-inner .file-upload-text {
    font-size: 0.8125rem;
}

.compose-panel-inner .file-upload-hint {
    font-size: 0.75rem;
    width: 100%;
    text-align: center;
}

.compose-panel-inner .compose-form-actions {
    position: static;
    flex-shrink: 0;
    z-index: 2;
    margin: 0;
    padding: 0.65rem 0 1rem;
    background: var(--color-surface);
    border-top: 1px solid var(--color-border-subtle);
}

/* Compose action buttons: icon + label, square corners (no radius). */
.compose-form-actions .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border-radius: 0;
}

.compose-form-actions .btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.mail-list-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 10rem;
    padding: 2rem 1rem;
    color: var(--color-text-muted);
}

.compose-panel-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    min-height: 12rem;
    color: var(--color-text-muted);
}

.compose-panel-flash {
    margin: 0 0 0.75rem;
}

/* Single viewport — only one pane state visible at a time (overlays). */
.reading-pane-viewport {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.reading-pane-empty,
.reading-pane-loading,
.reading-pane-body {
    position: absolute;
    inset: 0;
}

.reading-pane-empty[hidden],
.reading-pane-loading[hidden],
.reading-pane-body[hidden] {
    display: none !important;
}

.reading-pane-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    color: var(--color-text-muted);
    text-align: center;
    background: var(--color-surface);
}

.reading-pane-empty-inner p {
    margin: 0.75rem 0 0;
    font-size: 0.9375rem;
}

.reading-pane-empty-icon {
    opacity: 0.35;
}

.reading-pane-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--color-text-muted);
    background: var(--color-surface);
}

.reading-pane-spinner {
    width: 28px;
    height: 28px;
    border: 2px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

.reading-pane-body {
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    background: var(--color-bg);
}

.reading-pane-inner {
    display: flex;
    flex-direction: column;
    min-height: 100%;
}

.mail-read-card--pane {
    border: none;
    border-radius: 0;
    box-shadow: none;
    margin: 0;
    background: transparent;
    padding: 0;
}

.mail-read-card--pane > .mail-actions {
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    flex-wrap: wrap;
    gap: 0.25rem;
}

.mail-read-card--pane .mail-read-subject-bar {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}

.mail-read-card--pane .mail-message-card {
    margin-left: 1rem;
    margin-right: 1rem;
}

.reading-pane.is-compose-open .compose-panel {
    background: var(--color-bg);
}

.reading-pane.is-compose-open .compose-panel-header {
    background: var(--color-surface);
}

.reading-pane.is-compose-open .compose-panel-body {
    padding: 0.75rem 1rem 1rem;
    background: var(--color-bg);
}

.compose-panel-inner--reply,
.compose-panel-inner--reply-all,
.compose-panel-inner--forward {
    background: transparent;
}

.compose-panel-inner--reply .compose-form,
.compose-panel-inner--reply-all .compose-form,
.compose-panel-inner--forward .compose-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 0.75rem 1rem 1rem;
    gap: 0.75rem;
}

.compose-outlook-header {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--color-border-subtle);
    margin-bottom: 0.25rem;
}

.compose-outlook-avatar {
    flex-shrink: 0;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: #fff;
}

.compose-outlook-meta {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
}

.compose-outlook-meta strong {
    color: var(--color-text);
    font-weight: 600;
}

.compose-panel-inner--reply .compose-subject-group,
.compose-panel-inner--reply-all .compose-subject-group {
    margin-top: 0;
}

.compose-panel-inner--reply .compose-form > .form-group:has(#from_email),
.compose-panel-inner--reply-all .compose-form > .form-group:has(#from_email) {
    display: none;
}

.compose-form--outlook-inline .compose-quoted-wrap {
    padding: 0;
}

.compose-outlook-card--reply .compose-quoted-toggle {
    margin: 0;
}

.compose-quoted-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.75rem;
    height: 1.5rem;
    margin: 0.25rem 0 0;
    padding: 0 0.65rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface-alt);
    color: var(--color-text-secondary);
    font-size: 1rem;
    line-height: 1;
    letter-spacing: 0.15em;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}

.compose-quoted-toggle:hover,
.compose-quoted-toggle:focus-visible {
    background: var(--color-surface);
    border-color: var(--color-text-muted);
    color: var(--color-text);
}

.compose-quoted-toggle-dots {
    transform: translateY(-1px);
}

.compose-quoted-body {
    margin-top: 0.5rem;
    padding: 0.75rem 0.875rem;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    background: var(--color-surface-alt);
    max-height: 16rem;
    overflow: auto;
}

.compose-quoted-text {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: inherit;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--color-text-secondary);
}

/* Outlook inline reply / forward at bottom of conversation thread */
.mail-inline-compose {
    margin: 0 1rem 1rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.mail-inline-compose .compose-form--outlook-inline {
    margin: 0;
}

.mail-inline-compose .compose-outlook-card {
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
    overflow: visible;
}

.compose-outlook-card--reply .compose-outlook-header {
    padding: 0;
    border-bottom: 1px solid var(--color-border-subtle);
}

.compose-outlook-header {
    display: flex;
    flex-direction: column;
    gap: 0;
    padding: 0;
    position: relative;
}

.compose-outlook-header-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem 0.75rem 1rem;
}

.compose-outlook-avatar {
    flex-shrink: 0;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6875rem;
    font-weight: 600;
    color: #fff;
}

.compose-outlook-to-summary[data-to-summary-toggle] {
    display: flex;
    align-items: center;
    flex: 1;
    min-width: 0;
    min-height: 2rem;
    margin: 0;
    padding: 0.2rem 0.4rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    font: inherit;
    text-align: left;
    cursor: pointer;
    color: var(--color-text);
    transition: background 0.12s;
}

.compose-outlook-recipients-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.35rem 1.5rem;
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    line-height: 1.5;
    overflow: hidden;
}

.compose-outlook-summary-part {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.compose-outlook-summary-label {
    margin-right: 0.35rem;
    color: var(--color-text);
}

.compose-outlook-to-summary[data-to-summary-toggle]:hover,
.compose-outlook-to-summary[data-to-summary-toggle]:focus-visible {
    background: var(--color-surface-alt);
    outline: none;
}

.compose-outlook-card--recipients-expanded .compose-outlook-header {
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
}

.compose-outlook-card--recipients-expanded .compose-outlook-header-row {
    flex: 0 0 auto;
    padding: 0;
    align-self: flex-start;
}

.compose-outlook-card--recipients-expanded .compose-outlook-to-summary {
    display: none;
}

.compose-outlook-recipients-panel {
    padding: 0;
    width: 100%;
    box-sizing: border-box;
}

.compose-outlook-card--recipients-expanded .compose-outlook-recipients-panel {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
}

.compose-outlook-to-prefix {
    flex-shrink: 0;
    color: var(--color-text);
    font-weight: 400;
    font-size: 0.875rem;
}

.compose-outlook-to-prefix::after {
    content: ':';
}

.compose-outlook-to-names {
    flex: 1;
    min-width: 0;
    font-size: 0.875rem;
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.compose-recipients--outlook-expanded {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin: 0;
    width: 100%;
    background: var(--color-surface);
    box-sizing: border-box;
}

.compose-recipients--outlook-expanded .compose-recipient-row {
    min-height: 2.5rem;
}

.compose-recipients--outlook-expanded .compose-recipient-label {
    flex: 0 0 2rem;
    padding-top: 0.45rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.compose-recipients--outlook-expanded .recipient-chip {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    padding: 0.12rem 0.28rem 0.12rem 0.12rem;
    max-width: min(100%, 24rem);
    gap: 0.3rem;
}

.compose-recipients--outlook-expanded .recipient-chip-avatar {
    display: inline-flex;
    width: 1.35rem;
    height: 1.35rem;
    font-size: 0.625rem;
}

.compose-recipients--outlook-expanded .recipient-chip-label {
    font-size: 0.8125rem;
}

.compose-recipients--outlook-expanded .recipient-chip-remove {
    opacity: 1;
    width: 1.1rem;
}

.compose-recipients--outlook-expanded .compose-recipient-meta {
    padding-top: 0.35rem;
}

.compose-recipients--outlook-expanded .compose-recipient-meta button {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
    padding: 0.15rem 0.35rem;
}

.compose-recipients--outlook-expanded .compose-recipient-meta button:hover,
.compose-recipients--outlook-expanded .compose-recipient-meta button.is-active {
    color: var(--color-primary);
}

.compose-outlook-header-actions {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex-shrink: 0;
}

.compose-outlook-header-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0;
}

.compose-outlook-header-btn:hover,
.compose-outlook-header-btn:focus-visible {
    background: var(--color-surface-alt);
    color: var(--color-text);
    outline: none;
}

.compose-outlook-subject-row {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--color-border-subtle);
    font-size: 0.875rem;
}

.compose-outlook-subject-input {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    font-size: 0.875rem;
    padding: 0.15rem 0;
    color: var(--color-text);
}

.compose-outlook-subject-input:focus {
    outline: none;
}

.compose-send-as-static {
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-sm);
    background: var(--color-surface-muted, #f8f9fa);
    color: var(--color-text);
    font-size: 0.9375rem;
    line-height: 1.4;
}

.compose-outlook-from-wrap {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.compose-outlook-editor-wrap {
    position: relative;
    padding: 0;
}

.compose-outlook-card--reply .compose-outlook-editor-wrap {
    border-top: none;
}

.compose-form--outlook-inline .rich-toolbar--minimal {
    border: none;
    border-bottom: 1px solid var(--color-border-subtle);
    padding: 0.35rem 1rem;
    margin-bottom: 0;
    background: transparent;
}

.compose-outlook-editor {
    min-height: 7.5rem;
    max-height: 18rem;
    overflow-y: auto;
    border: none;
    border-radius: 0;
    padding: 0.75rem 1rem 2.25rem;
    box-shadow: none;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.compose-outlook-card--expanded .compose-outlook-editor {
    min-height: 16rem;
    max-height: 32rem;
}

.compose-outlook-card--reply .compose-quoted-wrap {
    position: absolute;
    left: 1rem;
    bottom: 0.65rem;
    padding: 0;
    z-index: 2;
}

.compose-outlook-card--reply .compose-quoted-wrap:has(.compose-quoted-body:not([hidden])) {
    position: static;
    left: auto;
    bottom: auto;
    padding: 0 1rem 0.75rem;
}

.compose-outlook-card--reply .compose-quoted-body:not([hidden]) {
    position: static;
    margin: 0.5rem 0 0;
}

.compose-outlook-forwarded {
    padding: 0.5rem 1rem 0;
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
}

.file-upload--compact {
    border: none;
    background: transparent;
}

.compose-outlook-attach {
    padding: 0.35rem 1rem 0.5rem;
}

.compose-form--outlook-inline .file-upload-label--compact {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0;
    border: none;
    background: transparent;
    color: var(--color-primary);
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
}

.compose-form--outlook-inline .file-upload-label--compact:hover {
    text-decoration: underline;
}

.compose-outlook-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    padding: 0.65rem 1rem 0.85rem;
    border-top: 1px solid var(--color-border-subtle);
}

.compose-outlook-send {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.95rem;
    border: none;
    border-radius: var(--radius);
    background: var(--color-primary);
    color: #fff;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    line-height: 1.25;
    transition: background 0.12s;
}

.compose-outlook-send:hover,
.compose-outlook-send:focus-visible {
    background: var(--color-primary-hover);
}

.compose-outlook-send.is-loading {
    cursor: wait;
    pointer-events: none;
    opacity: 0.92;
}

.compose-outlook-send.is-loading .btn-spinner {
    border-color: rgba(255, 255, 255, 0.35);
    border-top-color: #fff;
}

.compose-outlook-discard:disabled,
.compose-outlook-discard[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
    pointer-events: none;
}

.compose-outlook-discard {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.95rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    line-height: 1.25;
    transition: background 0.12s, border-color 0.12s;
}

.compose-outlook-discard:hover,
.compose-outlook-discard:focus-visible {
    background: var(--color-surface-alt);
    border-color: var(--color-text-muted);
}

.reading-pane.is-inline-compose-open .reading-pane-viewport {
    display: flex;
}

.mail-row.is-selected,
.mail-card.is-selected {
    background: var(--color-primary-light);
    border-left-color: var(--color-primary);
}

.mail-row.is-selected.is-checked,
.mail-card.is-selected.is-checked,
.mail-row.is-selected.is-checked:hover,
.mail-card.is-selected.is-checked:hover,
.mail-row.is-selected.is-checked:focus-within,
.mail-card.is-selected.is-checked:focus-visible {
    background: var(--color-primary-light);
}

.mail-row.is-selected:hover,
.mail-card.is-selected:hover {
    background: var(--color-primary-subtle);
}

@media (min-width: 1024px) {
    .mail-workspace {
        flex-direction: row;
    }

    .mail-list-column {
        flex: 0 0 42%;
        width: 42%;
        min-width: 340px;
        max-width: 560px;
        border-right: 1px solid var(--color-border);
    }

    .reading-pane {
        display: flex;
        flex: 1;
        min-width: 360px;
    }
}

@media (max-width: 1023px) {
    .reading-pane {
        display: none !important;
    }
}

/* U5 — admin & utility pages (lighter pass, inherits tokens) */
.admin-shell .card,
.standalone-page .card {
    border-radius: var(--radius);
    box-shadow: none;
}

.admin-shell .page-header h2,
.standalone-page-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.admin-shell table th {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    text-transform: none;
    letter-spacing: 0;
}

.mail-read-card--pane .mail-actions {
    gap: var(--space-1);
}

.mail-read-card--pane .mail-actions .btn {
    min-height: 1.75rem;
    padding: 0.2rem 0.55rem;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Desktop reading pane: keep the toolbar focused on Reply / Reply-all /
   Forward / Print. Unread, Flag, Spam, Delete and Move are all reachable from
   the right-click menu on the list row (and the bulk command bar), so they're
   redundant clutter here. The mobile full-page read view (.mail-read-card,
   without --pane) keeps them, since it has no hover/right-click affordance. */
.mail-read-card--pane .mail-actions [data-mail-action="mark-read"],
.mail-read-card--pane .mail-actions [data-mail-action="mark-unread"],
.mail-read-card--pane .mail-actions [data-mail-action="flag-toggle"],
.mail-read-card--pane .mail-actions [data-mail-action="spam"],
.mail-read-card--pane .mail-actions [data-mail-action="trash"],
.mail-read-card--pane .mail-actions .mail-action-move,
.mail-read-card--pane .mail-actions .mail-action-divider {
    display: none;
}

/* U6 — performance, a11y, mobile */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.mail-list-column.is-loading {
    opacity: 0.72;
    pointer-events: none;
}

.reading-pane-viewport.is-pane-loading .reading-pane-body {
    opacity: 0.45;
    pointer-events: none;
}

.reading-pane-skeleton {
    position: absolute;
    inset: 0;
    z-index: 4;
    padding: 1rem 1.25rem;
    background: var(--color-surface);
    overflow: hidden;
}

.pane-preview-from {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.35rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pane-preview-subject {
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 1rem;
    line-height: 1.35;
}

.pane-preview-body {
    min-height: 8rem;
}

.pane-preview-shimmer {
    display: block;
    height: 0.75rem;
    width: 92%;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--color-surface-alt) 25%, var(--color-border-subtle) 50%, var(--color-surface-alt) 75%);
    background-size: 200% 100%;
    animation: pane-shimmer 1.2s ease-in-out infinite;
}

.pane-skeleton-toolbar {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.pane-skeleton-block {
    display: block;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--color-surface-alt) 25%, var(--color-border-subtle) 50%, var(--color-surface-alt) 75%);
    background-size: 200% 100%;
    animation: pane-shimmer 1.2s ease-in-out infinite;
}

.pane-skeleton-block--btn {
    width: 4.5rem;
    height: 1.75rem;
}

.pane-skeleton-subject {
    height: 1.25rem;
    width: 70%;
    margin-bottom: var(--space-3);
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--color-surface-alt) 25%, var(--color-border-subtle) 50%, var(--color-surface-alt) 75%);
    background-size: 200% 100%;
    animation: pane-shimmer 1.2s ease-in-out infinite;
}

.pane-skeleton-meta {
    height: 0.875rem;
    width: 45%;
    margin-bottom: var(--space-5);
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--color-surface-alt) 25%, var(--color-border-subtle) 50%, var(--color-surface-alt) 75%);
    background-size: 200% 100%;
    animation: pane-shimmer 1.2s ease-in-out infinite;
}

.pane-skeleton-lines {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.pane-skeleton-line {
    display: block;
    height: 0.75rem;
    width: 100%;
    border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--color-surface-alt) 25%, var(--color-border-subtle) 50%, var(--color-surface-alt) 75%);
    background-size: 200% 100%;
    animation: pane-shimmer 1.2s ease-in-out infinite;
}

.pane-skeleton-line--short {
    width: 62%;
}

@keyframes pane-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.mail-list-card.is-syncing {
    /* Poll updates rows in place — no flash */
}

@media (max-width: 1023px) {
    .sidebar-link {
        min-height: 2.125rem;
        padding: 0.3rem 0.6rem;
        gap: 0.5rem;
        margin: 0;
        font-size: 0.78125rem;
    }

    .sidebar-primary-folders .sidebar-link,
    .sidebar-group-items .sidebar-link {
        min-height: 2.125rem;
        padding: 0.3rem 0.6rem;
    }

    .sidebar-footer .sidebar-tree-row {
        min-height: 1.75rem;
    }

    .sidebar .folder-icon {
        width: 17px;
        height: 17px;
        opacity: 0.88;
    }

    .sidebar-groups {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        padding: 0 0.15rem 0.35rem;
    }

    .sidebar-divider {
        margin: 0.3rem 0.45rem;
    }

    .sidebar-group-toggle {
        min-height: 2.125rem;
        padding: 0.3rem 0.5rem;
        margin: 0.15rem 0 0.05rem;
        gap: 0.5rem;
        font-size: 0.78125rem;
    }

    .sidebar-group-chevron-btn {
        width: 1.2rem;
        height: 1.2rem;
    }

    .sidebar-group {
        margin-bottom: 0;
    }

    .sidebar-group-items {
        padding: 0.1rem 0 0.2rem 0.3rem;
    }

    .sidebar-group.is-collapsible .sidebar-group-items .sidebar-link {
        padding-left: 0.55rem;
    }

    .sidebar-group.is-collapsible .sidebar-group-items .sidebar-link.is-nested {
        padding-left: calc(0.55rem + var(--folder-depth, 0) * 0.85rem);
    }

    .sidebar-footer {
        flex-shrink: 0;
        padding: 0.35rem 0.25rem 0.5rem;
        margin-top: auto;
    }

    .btn-compose {
        min-height: 2.25rem;
        margin-bottom: 0.4rem;
        padding: 0.35rem 0.65rem;
        font-size: 0.78125rem;
    }

    .mail-list-mobile {
        background: var(--color-surface);
    }

    .mail-card {
        min-height: 3.25rem;
        padding: 0.8rem 0.875rem;
    }

    .mail-card.mail-unread .mail-card-from,
    .mail-card.mail-unread .mail-card-subject {
        font-weight: 600;
        color: var(--color-text);
    }

    .mail-card.is-focused {
        outline: 2px solid var(--color-primary);
        outline-offset: -2px;
    }

    .mail-kebab {
        display: none !important;
    }

    .mail-action-move {
        border: none;
        background: transparent;
        overflow: visible;
    }

    .mail-action-move-select-wrap {
        display: none !important;
    }

    .mail-action-btn--move {
        width: 100%;
        min-width: 0;
        height: 2.125rem;
        border: 1px solid transparent;
        border-radius: var(--radius-sm);
    }

    .mail-cmd-btn--refresh-mobile {
        display: inline-flex;
    }

    .mail-cmd-btn--refresh-desktop {
        display: none !important;
    }

    .mail-command-divider--desktop {
        display: none;
    }

    .mail-command-bar-actions [data-cmd="reply"] { order: 1; }
    .mail-command-bar-actions [data-cmd="reply-all"] { order: 2; }
    .mail-command-bar-actions [data-cmd="forward"] { order: 3; }
    .mail-command-bar-actions [data-cmd="mark-read"] { order: 4; }
    .mail-command-bar-actions [data-cmd="mark-unread"] { order: 5; }
    .mail-command-bar-actions [data-cmd="flag-toggle"] { order: 6; }
    .mail-command-bar-actions .mail-cmd-move { order: 7; }
    .mail-command-bar-actions [data-cmd="delete"] { order: 8; }

    .mail-command-bar {
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: 0;
    }

    .mail-command-bar-row--main,
    .mail-command-bar-row--selection {
        display: block;
    }

    .mail-command-bar-main-end {
        display: flex;
        align-items: center;
        gap: 0.65rem;
        margin-left: auto;
        flex-shrink: 0;
    }

    .mail-command-bar-row--main {
        display: flex;
        align-items: center;
        gap: 0.35rem;
        padding: 0.45rem 0.65rem;
        border-bottom: 1px solid var(--color-border-subtle);
    }

    .mail-command-bar-row--selection {
        display: none;
        padding: 0.35rem 0.65rem;
        border-bottom: 1px solid var(--color-border-subtle);
        background: var(--color-surface);
    }

    .mail-command-bar--has-selection .mail-command-bar-row--selection {
        display: block;
    }

    .mail-command-bar-row--selection .mail-command-bar-actions {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        gap: 0.15rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        min-width: 0;
    }

    .mail-command-bar-row--selection .mail-command-bar-actions::-webkit-scrollbar {
        display: none;
    }

    .mail-command-bar--has-selection .mail-cmd-btn--compose-action:not([hidden]) {
        display: inline-flex !important;
    }

    .mail-command-bar-row--selection .mail-cmd-btn {
        min-width: 2.5rem;
        min-height: 2.5rem;
        padding: 0 0.35rem;
        color: var(--color-text);
        flex-shrink: 0;
    }

    .mail-command-bar-row--selection .mail-cmd-btn:not(:disabled) {
        opacity: 1;
    }

    .mail-command-bar-row--selection .mail-cmd-btn--danger:not(:disabled) {
        color: var(--color-danger);
    }

    .mail-command-bar-row--selection .mail-cmd-move {
        display: inline-flex !important;
        align-items: center;
        border: none;
        background: transparent;
        overflow: visible;
        opacity: 1;
        flex-shrink: 0;
    }

    .mail-command-bar-row--selection .mail-cmd-move .mail-cmd-btn--move {
        display: inline-flex !important;
        min-width: 2.5rem;
        min-height: 2.5rem;
        opacity: 1;
    }

    .mail-command-bar-row--selection .mail-cmd-move-select-wrap {
        display: none;
    }

    .mail-command-bar:not(.mail-command-bar--has-selection) .mail-command-bar-row--selection {
        display: none !important;
    }
}

/* Print — must stay last so it overrides reading-pane layout rules above */
#print-message-root {
    display: none;
}

@media print {
    .site-header,
    .sidebar,
    .sidebar-backdrop,
    .mail-actions,
    .breadcrumb,
    .no-print,
    .flash-messages,
    .mail-list-column,
    .compose-panel,
    .reading-pane-empty,
    .reading-pane-loading,
    .reading-pane-skeleton,
    .page-header--read,
    .page-header--mail,
    .mail-toolbar,
    .mail-select-all-banner,
    .pagination,
    #toast-stack,
    #confirm-modal,
    #folder-picker-modal,
    .menu-toggle {
        display: none !important;
    }

    body.is-printing-message > *:not(#print-message-root) {
        display: none !important;
    }

    body.is-printing-message #print-message-root {
        display: block !important;
        position: static !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        color: #000 !important;
    }

    body.is-printing-message #print-message-root,
    body.is-printing-message #print-message-root * {
        visibility: visible !important;
        opacity: 1 !important;
        overflow: visible !important;
        height: auto !important;
        max-height: none !important;
        min-height: 0 !important;
        position: static !important;
        inset: auto !important;
        flex: none !important;
        color: #000 !important;
        box-shadow: none !important;
        border-color: #ccc !important;
    }

    body.is-printing-message #print-message-root {
        background: #fff !important;
    }

    body.is-printing-message #print-message-root .mail-read-subject {
        font-size: 1.25rem !important;
        margin: 0 0 0.75rem !important;
    }

    html,
    html:has(.mail-workspace),
    body,
    body:has(.mail-workspace) {
        overflow: visible !important;
        height: auto !important;
        min-height: 0 !important;
        background: #fff !important;
        color: #000 !important;
    }

    .app-shell,
    .app-shell:has(.mail-workspace) {
        display: block !important;
        grid-template-columns: none !important;
        height: auto !important;
        max-height: none !important;
        min-height: 0 !important;
        overflow: visible !important;
    }

    .main-content,
    .main-content:has(.mail-workspace),
    .mail-workspace,
    .reading-pane,
    .reading-pane-viewport,
    .reading-pane-body,
    .reading-pane-inner,
    .mail-read-card,
    .mail-message-card,
    .mail-message-body,
    .mail-body-html,
    .mail-body-plain,
    .print-area {
        display: block !important;
        position: static !important;
        inset: auto !important;
        overflow: visible !important;
        height: auto !important;
        max-height: none !important;
        min-height: 0 !important;
        width: 100% !important;
        max-width: none !important;
        flex: none !important;
        background: #fff !important;
        color: #000 !important;
        box-shadow: none !important;
        border: none !important;
    }

    .reading-pane-body[hidden] {
        display: none !important;
    }

    .mail-read-subject,
    .mail-message-from-name,
    .mail-message-from-email,
    .mail-message-date,
    .mail-message-recipients,
    .mail-message-body,
    .mail-body-html,
    .mail-body-plain,
    .mail-body-html * {
        color: #000 !important;
    }

    .mail-body-html img,
    .attachments .attachment-preview img {
        max-width: 100% !important;
        height: auto !important;
        page-break-inside: avoid;
    }

    .mail-message-body,
    .attachments--message {
        page-break-inside: auto;
    }

    a {
        color: #000 !important;
        text-decoration: underline;
    }

    * {
        scrollbar-width: none !important;
    }

    *::-webkit-scrollbar {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
    }
}

/* Draft editor (reading pane) */
.reading-pane-inner--draft {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    background: var(--color-surface);
}

.draft-editor-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: auto;
}

.compose-form--draft {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    margin: 0;
}

.compose-draft-card {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    background: var(--color-surface);
}

.compose-draft-header {
    padding: 1.125rem 1.25rem 0.875rem;
    border-bottom: 1px solid var(--color-border-subtle);
    background: linear-gradient(180deg, var(--color-surface-alt) 0%, var(--color-surface) 100%);
}

.compose-draft-header-main {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
}

.compose-draft-badge {
    flex-shrink: 0;
    margin-top: 0.2rem;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    background: var(--color-accent-soft);
    color: var(--color-accent);
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.compose-draft-title {
    margin: 0;
    font-size: 1.1875rem;
    font-weight: 600;
    line-height: 1.35;
    letter-spacing: -0.02em;
    color: var(--color-text);
    word-break: break-word;
}

.compose-draft-hint {
    margin: 0.5rem 0 0;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.compose-draft-fields {
    border-bottom: 1px solid var(--color-border-subtle);
}

.compose-send-as--draft {
    display: grid;
    grid-template-columns: 4.75rem 1fr;
    gap: 0.5rem 0.875rem;
    align-items: center;
    margin: 0;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--color-border-subtle);
}

.compose-send-as--draft .compose-send-as-label {
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--color-text-secondary);
}

.compose-send-as-identity {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    padding: 0;
    /* Gmail-style: a light inline chip, not a boxed field. */
    border: none;
    background: transparent;
}

.compose-send-as-avatar {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 999px;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.compose-send-as-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
}

.compose-send-as-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text);
    line-height: 1.25;
}

.compose-send-as-email {
    font-size: 0.8125rem;
    color: var(--color-text-secondary);
    line-height: 1.25;
    word-break: break-all;
}

.compose-send-as--draft .compose-send-as-control {
    min-width: 0;
}

.compose-send-as--draft .select-field--compose select {
    width: 100%;
    min-height: 2.5rem;
    padding: 0.5rem 2rem 0.5rem 0.75rem;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: var(--color-surface-alt);
    font-size: 0.875rem;
    color: var(--color-text);
}

.compose-draft-recipients-box {
    padding: 0.75rem 1.25rem 0;
}

.compose-draft-recipients-box .compose-recipients--draft {
    margin: 0;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    overflow: visible;
    background: var(--color-surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.compose-recipients--draft .compose-recipient-row {
    padding-left: 0.875rem;
    padding-right: 0.875rem;
}

.compose-draft-subject-row {
    display: grid;
    grid-template-columns: 4.75rem 1fr;
    gap: 0.5rem 0.875rem;
    align-items: center;
    padding: 0.75rem 1.25rem;
}

.compose-draft-subject-input {
    width: 100%;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    background: var(--color-surface);
    font-size: 0.9375rem;
    color: var(--color-text);
    padding: 0.55rem 0.75rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.compose-draft-subject-input::placeholder {
    color: var(--color-text-muted);
}

.compose-draft-subject-input:focus {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-soft);
}

.compose-draft-editor-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 12rem;
    margin: 0.875rem 1.25rem 0;
    border: 1px solid var(--color-border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--color-surface);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.compose-draft-editor {
    flex: 1;
    min-height: 10rem;
    padding: 0.875rem 1rem;
    border: none;
    font-size: 0.9375rem;
    line-height: 1.6;
    /* Scroll long drafts inside the box instead of clipping them (the wrapper is
       overflow:hidden, so without this the overflow was unreachable). */
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
}

.compose-draft-editor:focus {
    outline: none;
}

.compose-draft-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-shrink: 0;
    min-height: 3.25rem;
    padding: 0.5rem 1rem 0.625rem;
    margin-top: auto;
    border-top: 1px solid var(--color-border-subtle);
    background: var(--color-surface);
    box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.04);
}

.compose-draft-toolbar-attach {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
    min-height: 2.25rem;
    border: none;
    background: transparent;
    overflow: hidden;
}

.compose-draft-toolbar-attach.file-upload--draft-bar {
    border: none;
    border-radius: 0;
}

.compose-draft-toolbar-attach.is-dragover {
    border-radius: var(--radius-sm);
    background: var(--color-primary-light);
    outline: 1px dashed var(--color-primary);
    outline-offset: -1px;
}

.compose-draft-attach-btn {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    margin: 0;
    padding: 0;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-secondary);
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.compose-draft-attach-btn:hover,
.compose-draft-attach-btn:focus-visible {
    color: var(--color-accent);
    background: var(--color-accent-soft);
    outline: none;
}

.compose-draft-attach-list {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 0.375rem;
    min-width: 0;
    margin: 0;
    padding: 0;
    list-style: none;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
}

.compose-draft-attach-list[hidden] {
    display: none;
}

.compose-draft-attach-chip {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.3rem;
    max-width: 12rem;
    height: 1.875rem;
    padding: 0 0.5rem 0 0.35rem;
    border: 1px solid var(--color-border-subtle);
    border-radius: 999px;
    background: var(--color-surface-alt);
    font-size: 0.75rem;
    line-height: 1;
    color: var(--color-text-secondary);
}

.compose-draft-attach-chip-icon {
    display: inline-flex;
    flex-shrink: 0;
    color: var(--color-text-muted);
}

.compose-draft-attach-chip-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--color-text);
    font-weight: 500;
}

.compose-draft-attach-chip-size {
    flex-shrink: 0;
    color: var(--color-text-muted);
    font-size: 0.6875rem;
}

.compose-draft-toolbar-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.375rem;
    padding-left: 0.75rem;
    border-left: 1px solid var(--color-border-subtle);
}

.compose-draft-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-height: 2.25rem;
    padding: 0 0.875rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    font-family: inherit;
    font-size: 0.8125rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.compose-draft-action--discard {
    color: var(--color-text-muted);
}

.compose-draft-action--discard:hover,
.compose-draft-action--discard:focus-visible {
    color: var(--color-danger, #dc2626);
    background: rgba(220, 38, 38, 0.06);
    outline: none;
}

.compose-draft-action--save {
    border-color: var(--color-border-subtle);
    background: var(--color-surface);
    color: var(--color-text);
}

.compose-draft-action--save:hover,
.compose-draft-action--save:focus-visible {
    border-color: var(--color-border);
    background: var(--color-surface-alt);
    outline: none;
}

.compose-draft-action--send {
    min-width: 5.5rem;
    padding: 0 1rem;
    border-color: var(--color-primary);
    background: var(--color-primary);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.compose-draft-action--send:hover,
.compose-draft-action--send:focus-visible {
    border-color: var(--color-primary-hover);
    background: var(--color-primary-hover);
    outline: none;
}

.compose-draft-action--send.is-loading {
    cursor: wait;
    opacity: 0.92;
    pointer-events: none;
}

.compose-draft-action svg {
    flex-shrink: 0;
}

/* ── Gmail-style minimal — new-message compose panel ─────────────────────────
   Turn the boxed fields into one light stack: hairline dividers instead of
   borders, a compact inline send-as chip, and subtle fixed-width labels so the
   whole form reads airy and professional. Scoped to the new-message panel, so
   replies / forwards / drafts are untouched. */
.compose-panel-inner--compose .compose-form {
    gap: 0;
}

/* Send-as + Subject become label|field rows with a hairline divider under each,
   matching the recipient rows. */
.compose-panel-inner--compose .compose-send-as,
.compose-panel-inner--compose .compose-subject-group {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 0;
    padding: 0.55rem 0.15rem;
    border-bottom: 1px solid var(--color-border-subtle);
}

/* One subtle, fixed-width label column so To / Cc / Bcc / Subject / Send as all
   line up. */
.compose-panel-inner--compose .compose-send-as-label,
.compose-panel-inner--compose .compose-subject-group > label,
.compose-panel-inner--compose .compose-recipient-label {
    flex: 0 0 4rem;
    padding: 0;
    margin: 0;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

/* Compact inline send-as chip. */
.compose-panel-inner--compose .compose-send-as-avatar {
    width: 1.5rem;
    height: 1.5rem;
    font-size: 0.625rem;
}
.compose-panel-inner--compose .compose-send-as-text {
    flex-direction: row;
    align-items: baseline;
    gap: 0.4rem;
    flex-wrap: wrap;
}
.compose-panel-inner--compose .compose-send-as-email {
    color: var(--color-text-muted);
}
.compose-panel-inner--compose .compose-send-as-control {
    flex: 1;
    min-width: 0;
}
.compose-panel-inner--compose .compose-send-as-control select {
    border: none;
    background: transparent;
    padding: 0.2rem 1.5rem 0.2rem 0;
    min-height: auto;
    font-size: 0.875rem;
}

/* Recipient stack: drop the surrounding box, keep hairline dividers. */
.compose-panel-inner--compose .compose-recipients {
    border: none;
    border-radius: 0;
    margin: 0;
    background: transparent;
}
.compose-panel-inner--compose .compose-recipient-row {
    padding: 0.45rem 0.15rem;
    gap: 0.75rem;
    min-height: 2.4rem;
    align-items: center;
}
.compose-panel-inner--compose .compose-recipient-row:last-child {
    border-bottom: 1px solid var(--color-border-subtle);
}
.compose-panel-inner--compose .compose-recipient-label {
    padding-top: 0;
}

/* Subject input: borderless, sits inline in its row. */
.compose-panel-inner--compose .compose-subject-group input {
    flex: 1;
    min-width: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    padding: 0.2rem 0;
    min-height: auto;
    box-shadow: none;
    font-size: 0.9375rem;
}
.compose-panel-inner--compose .compose-subject-group input:focus {
    outline: none;
    box-shadow: none;
}

/* Message label + a little breathing room after the subject divider. */
.compose-panel-inner--compose .compose-form > .form-group:has(.rich-editor) {
    padding-top: 0.6rem;
}
.compose-panel-inner--compose .compose-form > .form-group:has(.rich-editor) > label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.reading-pane-body:has(.draft-editor-pane) {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.reading-pane-body:has(.draft-editor-pane) .reading-pane-inner--draft {
    flex: 1;
}

@media (max-width: 720px) {
    .compose-send-as--draft,
    .compose-draft-subject-row {
        grid-template-columns: 1fr;
        gap: 0.35rem;
    }

    .compose-draft-toolbar {
        flex-wrap: wrap;
        gap: 0.625rem;
        padding: 0.625rem 0.875rem 0.75rem;
    }

    .compose-draft-toolbar-attach {
        flex: 1 1 100%;
        order: 2;
    }

    .compose-draft-toolbar-actions {
        flex: 1 1 100%;
        order: 1;
        justify-content: flex-end;
        padding-left: 0;
        border-left: none;
    }

    .compose-draft-attach-chip {
        max-width: 9rem;
    }

    .compose-draft-action--discard {
        margin-right: auto;
    }
}

/* --- Move-to control → custom folder picker (icons + folder tree) --- */
/* Native <select> can't show icons or nesting; hide it (kept only as the
   picker's data source). The trigger is a plain icon button, identical to the
   other toolbar commands (Delete, Read, Flag). */
.mail-cmd-move-select-wrap,
.mail-action-move-select-wrap {
    display: none !important;
}
.mail-cmd-move {
    border: none;
    background: transparent;
    overflow: visible;
}
/* Reset the button back to a plain toolbar icon button (an older rule squared it
   off and dropped its border because it used to be fused to the select). */
.mail-cmd-btn--move {
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 4px);
    min-width: 2rem;
    height: 2rem;
    padding: 0 0.45rem;
}

/* Professional folder picker (Move to… + right-click submenu) */
.folder-picker-item {
    border-radius: 7px;
    gap: 0.55rem;
    transition: background 0.12s ease, color 0.12s ease;
}
.folder-picker-item:hover,
.folder-picker-item:focus-visible {
    background: var(--color-accent-soft, var(--color-surface-alt, rgba(0, 0, 0, 0.05)));
}
.folder-picker-item .ctx-folder-icon { opacity: 0.8; flex: 0 0 auto; }
.folder-picker-item-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Password show/hide (eye) toggle — added to every password field by app.js. */
.password-field {
    position: relative;
    display: block;
}
.password-field > input {
    width: 100%;
    padding-right: 2.75rem;
}
.password-toggle {
    position: absolute;
    top: 50%;
    right: 0.4rem;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--color-text-muted);
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.password-toggle:hover,
.password-toggle:focus-visible {
    color: var(--color-text);
    background: var(--color-surface-alt, rgba(0, 0, 0, 0.06));
    outline: none;
}
.password-toggle svg {
    width: 18px;
    height: 18px;
    display: block;
}
