/* ==========================================================================
   Webmail — Outlook-inspired original UI
   --------------------------------------------------------------------------
   THEME SYSTEM
   Every colour is a CSS custom property. The six base variables are emitted
   by index.php from the central configuration (and the user's saved
   preferences), so changing the palette never requires editing this file.

   Dark mode is handled by overriding the same variables under
   [data-theme="dark"], so no component needs a dark-specific rule.
   ========================================================================== */

:root {
    /* Injected by PHP: --primary-color, --accent-color, --background-color,
       --surface-color, --text-color, --border-color                       */

    --text-muted:      #5a6273;
    --text-subtle:     #8b93a5;
    --surface-alt:     #f0f3f9;
    --surface-hover:   #e8edf7;
    --selected-bg:     #dde8ff;
    --danger:          #d13438;
    --success:         #107c41;
    --warning:         #b8860b;
    --unread-bg:       #ffffff;
    --read-bg:         #fafbfd;

    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, .10);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --sidebar-w: 240px;
    --list-w:    380px;
    --topbar-h:  56px;

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

    --transition: 140ms ease;
}

[data-theme="dark"] {
    --background-color: #161a22;
    --surface-color:    #1f2430;
    --text-color:       #e6e8ee;
    --border-color:     #2f3644;

    --text-muted:    #aab2c5;
    --text-subtle:   #7b8496;
    --surface-alt:   #252b38;
    --surface-hover: #2c3342;
    --selected-bg:   #2a3550;
    --unread-bg:     #1f2430;
    --read-bg:       #1b202a;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, .5);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .6);
}

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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-color);
    background: var(--background-color);
    -webkit-font-smoothing: antialiased;
}

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

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

:focus-visible {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    font-weight: 600;
    white-space: nowrap;
    transition: background var(--transition), border-color var(--transition),
                opacity var(--transition);
}
.btn:disabled { opacity: .6; cursor: not-allowed; }

.btn-primary { background: var(--primary-color); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); }

.btn-secondary {
    background: var(--surface-color);
    border-color: var(--border-color);
    color: var(--text-color);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text-color); }

.btn-block { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn.danger, .icon-btn.danger { color: var(--danger); }

.btn-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 13px;
    text-decoration: underline;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text-color); }
.icon-btn.active { color: var(--primary-color); }

/* Simple CSS glyphs — no icon font, no external requests. */
.ico { display: inline-block; width: 18px; height: 18px;
       background: currentColor;
       -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
       -webkit-mask-position: center;  mask-position: center;
       -webkit-mask-size: contain;     mask-size: contain; }

.ico-menu    { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6h18v2H3zM3 11h18v2H3zM3 16h18v2H3z'/%3E%3C/svg%3E");            mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 6h18v2H3zM3 11h18v2H3zM3 16h18v2H3z'/%3E%3C/svg%3E"); }
.ico-search  { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 2a8 8 0 105.3 14l5.4 5.4 1.4-1.4-5.4-5.4A8 8 0 0010 2zm0 2a6 6 0 110 12 6 6 0 010-12z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M10 2a8 8 0 105.3 14l5.4 5.4 1.4-1.4-5.4-5.4A8 8 0 0010 2zm0 2a6 6 0 110 12 6 6 0 010-12z'/%3E%3C/svg%3E"); }
.ico-refresh { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 4V1L8 5l4 4V6a6 6 0 11-6 6H4a8 8 0 108-8z'/%3E%3C/svg%3E");                       mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 4V1L8 5l4 4V6a6 6 0 11-6 6H4a8 8 0 108-8z'/%3E%3C/svg%3E"); }
.ico-gear    { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 8a4 4 0 100 8 4 4 0 000-8zm9 4l-2-1.3.3-2.4-2.3-1-1.6 1.8-2.3-.7L12 6l-1.1 2.4-2.3.7L7 7.3l-2.3 1 .3 2.4L3 12l2 1.3-.3 2.4 2.3 1 1.6-1.8 2.3.7L12 18l1.1-2.4 2.3-.7 1.6 1.8 2.3-1-.3-2.4z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 8a4 4 0 100 8 4 4 0 000-8zm9 4l-2-1.3.3-2.4-2.3-1-1.6 1.8-2.3-.7L12 6l-1.1 2.4-2.3.7L7 7.3l-2.3 1 .3 2.4L3 12l2 1.3-.3 2.4 2.3 1 1.6-1.8 2.3.7L12 18l1.1-2.4 2.3-.7 1.6 1.8 2.3-1-.3-2.4z'/%3E%3C/svg%3E"); }
.ico-plus    { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11 5h2v6h6v2h-6v6h-2v-6H5v-2h6z'/%3E%3C/svg%3E");                                 mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M11 5h2v6h6v2h-6v6h-2v-6H5v-2h6z'/%3E%3C/svg%3E"); }
.ico-star    { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2l3 6.5 7 .9-5 4.8 1.3 7L12 17.8 5.7 21.2 7 14.2 2 9.4l7-.9z'/%3E%3C/svg%3E");     mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12 2l3 6.5 7 .9-5 4.8 1.3 7L12 17.8 5.7 21.2 7 14.2 2 9.4l7-.9z'/%3E%3C/svg%3E"); }
.ico-trash   { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 3h6l1 2h4v2H4V5h4zM6 9h12l-1 12H7z'/%3E%3C/svg%3E");                       mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 3h6l1 2h4v2H4V5h4zM6 9h12l-1 12H7z'/%3E%3C/svg%3E"); }
.ico-archive { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 4h18v4H3zM4 9h16v11H4zm5 3v2h6v-2z'/%3E%3C/svg%3E");                     mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 4h18v4H3zM4 9h16v11H4zm5 3v2h6v-2z'/%3E%3C/svg%3E"); }
.ico-read    { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 4H4a2 2 0 00-2 2v12a2 2 0 002 2h16a2 2 0 002-2V6a2 2 0 00-2-2zm0 4l-8 5-8-5V6l8 5 8-5z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 4H4a2 2 0 00-2 2v12a2 2 0 002 2h16a2 2 0 002-2V6a2 2 0 00-2-2zm0 4l-8 5-8-5V6l8 5 8-5z'/%3E%3C/svg%3E"); }
.ico-unread  { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 4H4a2 2 0 00-2 2v12a2 2 0 002 2h16a2 2 0 002-2V6a2 2 0 00-2-2zm0 2v.5l-8 5-8-5V6z'/%3E%3Ccircle cx='18' cy='6' r='3'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 4H4a2 2 0 00-2 2v12a2 2 0 002 2h16a2 2 0 002-2V6a2 2 0 00-2-2zm0 2v.5l-8 5-8-5V6z'/%3E%3Ccircle cx='18' cy='6' r='3'/%3E%3C/svg%3E"); }
.ico-clip    { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M16.5 6.5v8a4.5 4.5 0 01-9 0V5a3 3 0 016 0v9a1.5 1.5 0 01-3 0V6.5H9V14a3 3 0 006 0V5a4.5 4.5 0 00-9 0v9.5a6 6 0 0012 0v-8z'/%3E%3C/svg%3E"); mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M16.5 6.5v8a4.5 4.5 0 01-9 0V5a3 3 0 016 0v9a1.5 1.5 0 01-3 0V6.5H9V14a3 3 0 006 0V5a4.5 4.5 0 00-9 0v9.5a6 6 0 0012 0v-8z'/%3E%3C/svg%3E"); }
.ico-back    { -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 11H7.8l5.6-5.6L12 4l-8 8 8 8 1.4-1.4L7.8 13H20z'/%3E%3C/svg%3E");           mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M20 11H7.8l5.6-5.6L12 4l-8 8 8 8 1.4-1.4L7.8 13H20z'/%3E%3C/svg%3E"); }

/* Spinner */
.spinner {
    width: 15px; height: 15px;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
.btn-secondary .spinner, .btn-ghost .spinner {
    border-color: var(--border-color);
    border-top-color: var(--primary-color);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   AUTHENTICATION SCREENS
   ========================================================================== */
.auth-shell {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: 20px;
    background:
        radial-gradient(circle at 15% 12%,
            color-mix(in srgb, var(--primary-color) 16%, transparent), transparent 42%),
        radial-gradient(circle at 85% 88%,
            color-mix(in srgb, var(--accent-color) 14%, transparent), transparent 42%),
        var(--background-color);
}

.auth-card {
    width: 100%;
    max-width: 400px;
    padding: 36px 32px;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
}
.auth-brand h1 { margin: 0; font-size: 20px; font-weight: 600; }

.auth-logo {
    width: 36px; height: 36px;
    flex: 0 0 36px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    position: relative;
}
.auth-logo::after {
    content: "";
    position: absolute;
    inset: 10px 8px;
    border: 2px solid #fff;
    border-radius: 2px;
    clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%);
}
.auth-logo.small { width: 26px; height: 26px; flex-basis: 26px; border-radius: 7px; }
.auth-logo.small::after { inset: 7px 6px; border-width: 1.5px; }

.auth-subtitle {
    margin: 0 0 22px;
    color: var(--text-muted);
    font-size: 14px;
}

.field { display: block; margin-bottom: 16px; }
.field-label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.field input, .field textarea,
.compose-row input, .modal input, .modal textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--background-color);
    color: var(--text-color);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.field input:focus, .field textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 18%, transparent);
}

.password-wrap { position: relative; display: block; }
.password-wrap input { padding-right: 62px; }
.password-toggle {
    position: absolute;
    right: 8px; top: 50%;
    transform: translateY(-50%);
    background: none; border: none;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 6px;
}

.auth-error {
    margin-bottom: 14px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: color-mix(in srgb, var(--danger) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
    color: var(--danger);
    font-size: 13px;
}

.auth-footnote {
    margin: 18px 0 0;
    font-size: 12px;
    color: var(--text-subtle);
    text-align: center;
}
.auth-cancel { margin-top: 16px; text-align: center; }

/* Authenticator code inputs */
.code-inputs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 4px 0 18px;
}
.code-inputs input {
    width: 52px; height: 60px;
    padding: 0;
    text-align: center;
    font-size: 24px;
    font-weight: 600;
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--background-color);
    color: var(--text-color);
}
.code-inputs input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary-color) 18%, transparent);
}

.enrol-panel { margin-bottom: 20px; }
.enrol-help { font-size: 13px; color: var(--text-muted); margin: 14px 0 8px; }
.qr-holder {
    display: grid;
    place-items: center;
    padding: 12px;
    background: #fff;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}
.enrol-secret {
    display: block;
    padding: 10px;
    background: var(--surface-alt);
    border-radius: var(--radius-sm);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 13px;
    letter-spacing: 1px;
    word-break: break-all;
    text-align: center;
}

/* ==========================================================================
   APP SHELL
   ========================================================================== */
.app-shell { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

.topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    height: var(--topbar-h);
    padding: 0 14px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    flex: 0 0 var(--topbar-h);
    z-index: 30;
}

.brand { display: flex; align-items: center; gap: 9px; }
.brand-name { font-weight: 600; font-size: 15px; white-space: nowrap; }
.menu-toggle { display: none; }

.search-form {
    flex: 1;
    max-width: 560px;
    margin: 0 auto;
    position: relative;
    display: flex;
    align-items: center;
}
.search-form .ico-search {
    position: absolute; left: 11px;
    color: var(--text-subtle);
    pointer-events: none;
    width: 16px; height: 16px;
}
.search-form input {
    width: 100%;
    padding: 8px 34px 8px 36px;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: var(--surface-alt);
    color: var(--text-color);
}
.search-form input:focus {
    outline: none;
    background: var(--surface-color);
    border-color: var(--primary-color);
}
.search-clear {
    position: absolute; right: 8px;
    background: none; border: none;
    color: var(--text-subtle);
    font-size: 19px;
    cursor: pointer;
    line-height: 1;
}

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

.user-chip { display: flex; align-items: center; gap: 8px; padding-left: 6px; }
.avatar {
    width: 30px; height: 30px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    flex: 0 0 30px;
}
.user-email {
    font-size: 13px;
    color: var(--text-muted);
    max-width: 170px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.logout-form { margin: 0; }

.workspace { display: flex; flex: 1; min-height: 0; }

/* Sidebar ---------------------------------------------------------------- */
.sidebar {
    width: var(--sidebar-w);
    flex: 0 0 var(--sidebar-w);
    padding: 14px 10px;
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.btn-compose { width: 100%; padding: 11px; }

.folder-list { display: flex; flex-direction: column; gap: 1px; }

.folder-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 11px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-color);
    cursor: pointer;
    text-align: left;
    font-size: 14px;
    transition: background var(--transition);
}
.folder-item:hover { background: var(--surface-hover); }
.folder-item.active {
    background: var(--selected-bg);
    color: var(--primary-color);
    font-weight: 600;
}
.folder-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-subtle);
    background: var(--surface-alt);
    padding: 1px 7px;
    border-radius: 10px;
}
.folder-item.active .folder-count { background: var(--primary-color); color: #fff; }

.folder-skeleton { height: 190px; border-radius: var(--radius-sm);
    background: linear-gradient(90deg, var(--surface-alt) 25%, var(--surface-hover) 50%, var(--surface-alt) 75%);
    background-size: 200% 100%; animation: shimmer 1.3s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.sidebar-backdrop { display: none; }

/* Message list ----------------------------------------------------------- */
.list-pane {
    width: var(--list-w);
    flex: 0 0 var(--list-w);
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    min-height: 0;
}

.list-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    flex: 0 0 auto;
    min-height: 50px;
}
.folder-title { margin: 0; font-size: 15px; font-weight: 600; }
.list-count { margin-left: auto; font-size: 12px; color: var(--text-subtle); }
.bulk-actions { display: flex; gap: 2px; }

.checkbox { position: relative; display: inline-flex; cursor: pointer; }
.checkbox input { position: absolute; opacity: 0; width: 0; height: 0; }
.checkmark {
    width: 17px; height: 17px;
    border: 1.5px solid var(--text-subtle);
    border-radius: 3px;
    display: inline-block;
    transition: background var(--transition), border-color var(--transition);
}
.checkbox input:checked + .checkmark {
    background: var(--primary-color);
    border-color: var(--primary-color);
}
.checkbox input:checked + .checkmark::after {
    content: "";
    position: absolute;
    left: 6px; top: 2px;
    width: 4px; height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.checkbox input:focus-visible + .checkmark { outline: 2px solid var(--accent-color); outline-offset: 2px; }

.message-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }

.message-item {
    display: flex;
    gap: 10px;
    padding: 11px 12px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    background: var(--read-bg);
    transition: background var(--transition);
}
.message-item:hover { background: var(--surface-hover); }
.message-item.unread { background: var(--unread-bg); }
.message-item.selected { background: var(--selected-bg); }

.message-item .checkbox { padding-top: 2px; }

.msg-star {
    background: none; border: none; padding: 0;
    color: var(--text-subtle);
    cursor: pointer;
    align-self: flex-start;
    padding-top: 1px;
}
.msg-star.starred { color: #f0a500; }
.msg-star .ico { width: 15px; height: 15px; }

.msg-main { flex: 1; min-width: 0; }
.msg-top { display: flex; align-items: baseline; gap: 8px; }
.msg-sender {
    font-weight: 600;
    font-size: 13.5px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    flex: 1;
}
.message-item.unread .msg-sender { color: var(--text-color); }
.msg-date { font-size: 11.5px; color: var(--text-subtle); flex: 0 0 auto; }

.msg-subject {
    font-size: 13.5px;
    margin-top: 1px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.message-item.unread .msg-subject { font-weight: 600; }

.msg-preview {
    font-size: 12.5px;
    color: var(--text-subtle);
    margin-top: 2px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-badges { display: flex; align-items: center; gap: 5px; margin-top: 3px; }
.msg-badges .ico { width: 13px; height: 13px; color: var(--text-subtle); }

.unread-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--primary-color);
    flex: 0 0 8px;
    align-self: center;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 12px;
    border-top: 1px solid var(--border-color);
    flex: 0 0 auto;
}
.page-info { font-size: 12px; color: var(--text-subtle); }

/* Reading pane ----------------------------------------------------------- */
.reading-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
    min-width: 0;
    min-height: 0;
}

.empty-state {
    flex: 1;
    display: grid;
    place-content: center;
    justify-items: center;
    gap: 12px;
    color: var(--text-subtle);
}
.empty-icon {
    width: 58px; height: 58px;
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-md);
}

.message-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.mv-header { padding: 16px 20px 12px; border-bottom: 1px solid var(--border-color); }
.mv-back { display: none; }
.mv-subject { margin: 0 0 12px; font-size: 19px; font-weight: 600; line-height: 1.3; }

.mv-meta { display: flex; gap: 11px; align-items: flex-start; }
.mv-avatar {
    width: 38px; height: 38px;
    flex: 0 0 38px;
    border-radius: 50%;
    background: var(--accent-color);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 600;
}
.mv-from { flex: 1; min-width: 0; }
.mv-from-name { font-weight: 600; font-size: 14px; }
.mv-from-email, .mv-recipients { font-size: 12.5px; color: var(--text-muted); word-break: break-word; }
.mv-date { font-size: 12px; color: var(--text-subtle); white-space: nowrap; }

.mv-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
}

.mv-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 20px 0;
    padding: 9px 12px;
    background: color-mix(in srgb, var(--warning) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--warning) 35%, transparent);
    border-radius: var(--radius-sm);
    font-size: 12.5px;
}

.mv-body { flex: 1; min-height: 0; }
.mv-frame { width: 100%; height: 100%; border: 0; display: block; background: transparent; }

.mv-attachments {
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    flex: 0 0 auto;
}
.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 11px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
    color: var(--text-color);
    text-decoration: none;
    font-size: 12.5px;
    max-width: 260px;
}
.attachment-chip:hover { background: var(--surface-hover); }
.attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-size { color: var(--text-subtle); flex: 0 0 auto; }

/* ==========================================================================
   COMPOSE
   ========================================================================== */
.compose-overlay {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .45);
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 0 24px 0 0;
    z-index: 60;
}

.compose-window {
    width: 100%;
    max-width: 620px;
    height: 640px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.compose-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--primary-color);
    color: #fff;
}
.compose-header h2 { margin: 0; font-size: 15px; font-weight: 600; }
.compose-header .icon-btn { color: #fff; font-size: 21px; }
.compose-header .icon-btn:hover { background: rgba(255, 255, 255, .18); }

.compose-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }

.compose-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    border-bottom: 1px solid var(--border-color);
}
.compose-label {
    flex: 0 0 54px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-muted);
}
.compose-row input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 2px 0;
}
.compose-row input:focus { outline: none; }
.compose-from { font-size: 13.5px; color: var(--text-muted); }
.cc-toggle { flex: 0 0 auto; }

.editor-toolbar {
    display: flex;
    gap: 2px;
    padding: 6px 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--surface-alt);
}

.compose-editor {
    flex: 1;
    padding: 14px 16px;
    overflow-y: auto;
    outline: none;
    min-height: 140px;
    line-height: 1.6;
}
.compose-editor:empty::before {
    content: "Write your message…";
    color: var(--text-subtle);
}

.attachment-tray {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid var(--border-color);
    max-height: 110px;
    overflow-y: auto;
}
.attachment-tray .attachment-chip { padding-right: 6px; }
.chip-remove {
    background: none; border: none;
    color: var(--text-subtle);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 3px;
}
.chip-remove:hover { color: var(--danger); }

.compose-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 11px 16px;
    border-top: 1px solid var(--border-color);
    flex: 0 0 auto;
}
.attach-btn { cursor: pointer; }
.compose-status { margin-left: auto; font-size: 12px; color: var(--text-subtle); }

/* ==========================================================================
   MODAL / TOASTS
   ========================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .45);
    display: grid;
    place-items: center;
    padding: 20px;
    z-index: 70;
}
.modal {
    width: 100%;
    max-width: 460px;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border-color);
}
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; overflow-y: auto; }

.setting-group { border: none; padding: 0; margin: 0 0 20px; }
.setting-group legend {
    padding: 0;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-subtle);
    margin-bottom: 10px;
}
.theme-options { display: flex; gap: 8px; }
.theme-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
}
.theme-option:has(input:checked) {
    border-color: var(--primary-color);
    background: color-mix(in srgb, var(--primary-color) 10%, transparent);
    color: var(--primary-color);
    font-weight: 600;
}
.theme-option input { margin: 0; }

.field-inline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 13.5px;
}
.field-inline input[type="color"] {
    width: 46px; height: 30px;
    padding: 2px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: none;
    cursor: pointer;
}
.field-inline input[type="number"] { width: 90px; }

.modal-footer { display: flex; align-items: center; gap: 10px; padding-top: 6px; }
.settings-status { font-size: 12px; color: var(--success); }

.toast-stack {
    position: fixed;
    bottom: 20px; left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 90;
    pointer-events: none;
}
.toast {
    padding: 11px 18px;
    border-radius: var(--radius-md);
    background: #262c38;
    color: #fff;
    font-size: 13.5px;
    box-shadow: var(--shadow-md);
    animation: toast-in 200ms ease;
    max-width: 90vw;
}
.toast.error   { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: none; }
}

.list-loading, .list-empty {
    padding: 34px 20px;
    text-align: center;
    color: var(--text-subtle);
    font-size: 13.5px;
}

/* ==========================================================================
   RESPONSIVE — tablet
   Mobile is a genuinely different layout, not a shrunken desktop:
   the three panes become a navigable stack.
   ========================================================================== */
@media (max-width: 1100px) {
    :root { --list-w: 320px; --sidebar-w: 210px; }
    .user-email { display: none; }
}

@media (max-width: 860px) {
    .menu-toggle { display: inline-flex; }

    /* Sidebar becomes an off-canvas drawer. */
    .sidebar {
        position: fixed;
        top: var(--topbar-h);
        left: 0;
        bottom: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 200ms ease;
        box-shadow: var(--shadow-lg);
        width: 270px;
        flex-basis: 270px;
    }
    .app-shell.sidebar-open .sidebar { transform: none; }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: var(--topbar-h) 0 0 0;
        background: rgba(16, 24, 40, .45);
        z-index: 40;
    }

    /* List and reading pane become alternating full-width views. */
    .list-pane {
        width: 100%;
        flex: 1 1 100%;
        border-right: none;
    }
    .reading-pane { display: none; }

    .app-shell.reading .list-pane   { display: none; }
    .app-shell.reading .reading-pane { display: flex; }

    .mv-back { display: inline-flex; margin-bottom: 10px; }

    .brand-name { display: none; }
    .search-form { max-width: none; }

    /* Compose goes full-screen on mobile. */
    .compose-overlay { padding: 0; align-items: stretch; }
    .compose-window {
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
    }
}

@media (max-width: 560px) {
    .topbar { gap: 8px; padding: 0 8px; }
    .user-chip { padding-left: 0; }
    .logout-form { display: none; }
    .mv-subject { font-size: 17px; }
    .mv-header, .mv-actions, .mv-attachments { padding-left: 14px; padding-right: 14px; }
    .code-inputs input { width: 46px; height: 54px; font-size: 21px; }
    .auth-card { padding: 26px 20px; }
    .compose-footer { flex-wrap: wrap; }
    .compose-status { width: 100%; margin-left: 0; }
}

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