/* ============================================================
   Architect AI — Dark Design System v3.0
   "Command Center" — Space-dark, Glassmorphism, Premium
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800;900&family=Inter:wght@400;500;600&display=swap');

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

:root {
    /* Core palette */
    --bg: #020b18;
    --bg-2: #041224;
    --bg-3: #071b35;
    --surface: rgba(255, 255, 255, .05);
    --surface-hover: rgba(255, 255, 255, .08);
    --surface-high: rgba(255, 255, 255, .10);
    --glass: rgba(255, 255, 255, .06);
    --glass-border: rgba(255, 255, 255, .10);
    --glass-hover: rgba(255, 255, 255, .10);

    /* Brand */
    --primary: #1464f6;
    --primary-dim: #0053db;
    --accent: #06b6d4;
    --accent-dim: rgba(6, 182, 212, .15);

    /* Semantic */
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, .12);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, .12);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, .12);

    /* Text */
    --text: rgba(255, 255, 255, .92);
    --text-dim: rgba(255, 255, 255, .55);
    --text-muted: rgba(255, 255, 255, .30);

    /* Borders / shadows */
    --border: rgba(255, 255, 255, .09);
    --border-focus: rgba(20, 100, 246, .6);
    --shadow: 0 8px 32px rgba(0, 0, 0, .45);
    --shadow-lg: 0 20px 60px rgba(0, 0, 0, .55);

    /* Shape */
    --r-sm: 0.375rem;
    --r-md: 0.625rem;
    --r-lg: 1rem;
    --r-xl: 1.25rem;
    --r-2xl: 1.5rem;

    /* Layout */
    --sidebar-w: 220px;
    --font-display: 'Manrope', sans-serif;
    --font-body: 'Inter', sans-serif;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse 80% 60% at -10% 30%, rgba(0, 83, 219, .22) 0%, transparent 60%),
        radial-gradient(ellipse 60% 80% at 110% 70%, rgba(6, 182, 212, .08) 0%, transparent 60%);
    background-attachment: fixed;
}

/* ── SCROLLBAR ───────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, .12);
    border-radius: 100px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, .22);
}

/* ── APP SHELL ───────────────────────────────────────────────── */
.app-shell {
    min-height: 100vh;
}

/* ── SIDEBAR ─────────────────────────────────────────────────── */
.sidebar {
    background: rgba(4, 18, 36, .92);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    display: flex;
    flex-direction: column;
    padding: 24px 14px;
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    height: 100vh;
    overflow-y: auto;
    z-index: 200;
    border-right: 1px solid var(--glass-border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 6px 28px;
}

.sidebar-brand-icon {
    width: 34px;
    height: 34px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--r-md);
    display: grid;
    place-items: center;
    flex-shrink: 0;
    box-shadow: 0 4px 16px rgba(20, 100, 246, .4);
}

.sidebar-brand-icon svg {
    width: 17px;
    height: 17px;
    stroke: white;
    fill: none;
    stroke-width: 2;
}

.sidebar-brand-text strong {
    display: block;
    font-family: var(--font-display);
    font-size: .85rem;
    font-weight: 800;
    letter-spacing: -.2px;
    color: var(--text);
}

.sidebar-brand-text span {
    font-size: .6rem;
    color: var(--text-muted);
    letter-spacing: .1em;
    text-transform: uppercase;
}

.btn-new-cmd {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 10px 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dim));
    border: none;
    border-radius: var(--r-lg);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: .8rem;
    font-weight: 600;
    color: white;
    text-decoration: none;
    margin-bottom: 20px;
    transition: opacity .2s, transform .15s, box-shadow .2s;
    box-shadow: 0 4px 20px rgba(20, 100, 246, .35);
}

.btn-new-cmd:hover {
    opacity: .9;
    transform: translateY(-1px);
    box-shadow: 0 8px 28px rgba(20, 100, 246, .45);
}

.btn-new-cmd svg {
    width: 15px;
    height: 15px;
    stroke: white;
    fill: none;
    stroke-width: 2.5;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-label {
    font-size: .58rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 14px 10px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--r-md);
    color: var(--text-dim);
    font-size: .835rem;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, color .15s;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.nav-item svg {
    width: 17px;
    height: 17px;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
    stroke-width: 1.8;
}

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

.nav-item.active {
    background: rgba(20, 100, 246, .18);
    color: #60a5fa;
    font-weight: 600;
    border: 1px solid rgba(20, 100, 246, .22);
}

.nav-item .badge {
    margin-left: auto;
    background: var(--primary);
    color: white;
    font-size: .6rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 100px;
    min-width: 20px;
    text-align: center;
}

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

/* ── MAIN CONTENT ─────────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

/* ── TOPBAR ───────────────────────────────────────────────────── */
.topbar {
    background: rgba(4, 18, 36, .85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    padding: 0 28px;
    height: 60px;
    gap: 12px;
    border-bottom: 1px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 0 12px;
    height: 36px;
    min-width: 180px;
    max-width: 320px;
    flex: 1;
    transition: border-color .2s;
}

.topbar-search:focus-within {
    border-color: var(--border-focus);
}

.topbar-search svg {
    width: 14px;
    height: 14px;
    stroke: var(--text-muted);
    fill: none;
    flex-shrink: 0;
}

.topbar-search input {
    background: none;
    border: none;
    outline: none;
    font-family: var(--font-body);
    font-size: .835rem;
    color: var(--text);
    width: 100%;
}

.topbar-search input::placeholder {
    color: var(--text-muted);
}

.topbar-tabs {
    display: flex;
    gap: 2px;
    margin-left: 8px;
}

.topbar-tab {
    padding: 6px 14px;
    border-radius: var(--r-md);
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-dim);
    text-decoration: none;
    cursor: pointer;
    transition: background .15s, color .15s;
    border: none;
    background: none;
}

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

.topbar-tab.active {
    background: rgba(20, 100, 246, .18);
    color: #60a5fa;
    font-weight: 600;
}

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

.btn-sync {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 14px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: .8rem;
    font-weight: 600;
    color: var(--text);
    transition: background .15s, border-color .2s, transform .15s;
    white-space: nowrap;
}

.btn-sync:hover {
    background: var(--surface-hover);
    border-color: rgba(20, 100, 246, .4);
    transform: translateY(-1px);
}

.btn-sync svg {
    width: 14px;
    height: 14px;
    stroke: var(--accent);
    fill: none;
    stroke-width: 2;
}

.btn-sync.loading svg {
    animation: spin 1s linear infinite;
}

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

.topbar-icon-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    background: none;
    border: none;
    cursor: pointer;
    display: grid;
    place-items: center;
    color: var(--text-dim);
    transition: background .15s, color .15s;
    position: relative;
}

.topbar-icon-btn:hover {
    background: var(--surface-hover);
    color: var(--text);
}

.topbar-icon-btn svg {
    width: 17px;
    height: 17px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
}

.topbar-icon-btn .notif-dot {
    position: absolute;
    top: 7px;
    right: 8px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--bg-2);
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {

    0%,
    100% {
        transform: scale(1)
    }

    50% {
        transform: scale(1.4)
    }
}

.avatar-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    cursor: pointer;
    display: grid;
    place-items: center;
    color: white;
    font-weight: 700;
    font-size: .75rem;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(20, 100, 246, .35);
}

.user-info-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 100px;
    padding: 2px 12px 2px 2px;
    cursor: default;
}

.user-email-label {
    font-size: .72rem;
    font-weight: 500;
    color: var(--text-dim);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 767px) {
    .user-email-label {
        display: none;
    }

    .user-info-pill {
        padding: 2px;
        background: none;
        border: none;
    }
}

/* ── PAGE HEADER ─────────────────────────────────────────────── */
.page-header {
    padding: 32px 28px 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.page-header-text {
    flex: 1;
    min-width: 0;
}

.page-header h1 {
    font-family: var(--font-display);
    font-size: clamp(1.4rem, 2.5vw, 1.85rem);
    font-weight: 800;
    letter-spacing: -.4px;
    color: var(--text);
    line-height: 1.2;
}

.page-header .sub {
    font-size: .875rem;
    color: var(--text-dim);
    margin-top: 6px;
    max-width: 520px;
    line-height: 1.5;
}

.node-badge {
    background: rgba(20, 100, 246, .16);
    color: #60a5fa;
    border: 1px solid rgba(20, 100, 246, .28);
    font-size: .58rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    padding: 7px 14px;
    border-radius: 100px;
    white-space: nowrap;
    align-self: flex-start;
    margin-top: 4px;
}

/* ── PAGE BODY ──────────────────────────────────────────────── */
.page-body {
    flex: 1;
    padding: 24px 28px 48px;
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 24px;
    align-items: start;
}

.page-body.full {
    grid-template-columns: 1fr;
}

/* ── STAT CARDS ─────────────────────────────────────────────── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    padding: 20px;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    min-width: 0;
    transition: border-color .2s, transform .2s;
    backdrop-filter: blur(12px);
}

.stat-card:hover {
    border-color: rgba(20, 100, 246, .35);
    transform: translateY(-2px);
}

.stat-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: linear-gradient(to bottom, var(--primary), var(--accent));
    border-radius: 2px 0 0 2px;
}

.stat-label {
    font-size: .58rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.stat-icon {
    width: 36px;
    height: 36px;
    background: var(--accent-dim);
    border-radius: var(--r-md);
    display: grid;
    place-items: center;
    margin-bottom: 12px;
}

.stat-icon svg {
    width: 18px;
    height: 18px;
    stroke: var(--accent);
    fill: none;
    stroke-width: 1.8;
}

.stat-value {
    font-family: var(--font-display);
    font-size: clamp(1.5rem, 2.5vw, 2.1rem);
    font-weight: 800;
    letter-spacing: -.5px;
    color: var(--text);
    line-height: 1;
}

.stat-trend {
    font-size: .78rem;
    color: var(--text-dim);
    margin-top: 8px;
    line-height: 1.4;
}

.stat-trend .up {
    color: var(--success);
    font-weight: 600;
}

.stat-trend .warn {
    color: var(--warning);
    font-weight: 600;
}

/* ── SECTION HEADER ─────────────────────────────────────────── */
.section-hdr {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-hdr h2 {
    font-family: var(--font-display);
    font-size: .9rem;
    font-weight: 700;
    letter-spacing: -.1px;
    color: var(--text);
}

.link-view-all {
    font-size: .78rem;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    transition: color .2s;
}

.link-view-all:hover {
    color: var(--accent);
}

/* ── EMAIL LIST / TABLE ──────────────────────────────────────── */
.email-list {
    border-radius: var(--r-xl);
    overflow: hidden;
    border: 1px solid var(--glass-border);
}

.email-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .835rem;
}

.email-table thead {
    display: none;
}

.email-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background .15s;
}

.email-table tbody tr:last-child {
    border-bottom: none;
}

.email-table tbody tr:hover {
    background: var(--surface-hover);
}

.email-table td {
    padding: 14px 12px;
    vertical-align: middle;
}

.email-table td:first-child {
    padding-left: 20px;
}

.email-table td:last-child {
    padding-right: 20px;
}

/* full page table */
.page-body.full .email-table-wrap {
    overflow-x: auto;
}

.page-body.full .email-table {
    min-width: 600px;
}

.page-body.full .email-table thead {
    display: table-header-group;
}

.page-body.full .email-table thead th {
    padding: 10px 12px;
    text-align: left;
    font-size: .6rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--bg-3);
}

.page-body.full .email-table thead th:first-child {
    padding-left: 20px;
}

.page-body.full .email-table thead th:last-child {
    padding-right: 20px;
}

/* Sender avatar */
.sender-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary-dim), var(--accent));
    display: grid;
    place-items: center;
    font-size: .7rem;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
}

.sender-name {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 2px;
}

.sender-email {
    font-size: .75rem;
    color: var(--text-dim);
}

.date-cell {
    font-size: .75rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Status chips */
.chip {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 100px;
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.chip-replied {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, .25);
}

.chip-pending {
    background: rgba(20, 100, 246, .12);
    color: #60a5fa;
    border: 1px solid rgba(20, 100, 246, .25);
}

.chip-failed {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, .25);
}

.chip-skipped {
    background: rgba(255, 255, 255, .06);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

/* ── EMPTY STATE ─────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 64px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.empty-state svg {
    width: 40px;
    height: 40px;
    stroke: var(--text-muted);
    fill: none;
    stroke-width: 1.5;
}

.empty-state h3 {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-dim);
}

.empty-state p {
    font-size: .875rem;
    color: var(--text-muted);
    max-width: 320px;
}

/* ── METRICS / BOTTOM CARDS ──────────────────────────────────── */
.metrics-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-top: 24px;
}

.metric-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    padding: 20px;
    backdrop-filter: blur(12px);
}

.metric-label {
    font-size: .58rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.metric-value {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text);
    margin-bottom: 6px;
}

.metric-desc {
    font-size: .75rem;
    color: var(--text-dim);
    line-height: 1.5;
}

/* ── RIGHT SIDEBAR ───────────────────────────────────────────── */
.insight-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    padding: 20px;
    margin-bottom: 16px;
    backdrop-filter: blur(12px);
}

.insight-label {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 12px;
}

.insight-label svg {
    width: 12px;
    height: 12px;
}

.insight-card p {
    font-size: .82rem;
    color: var(--text-dim);
    line-height: 1.65;
    margin-bottom: 14px;
}

.insight-card p strong {
    color: var(--text);
}

.btn-optimize {
    display: inline-block;
    padding: 8px 16px;
    border-radius: var(--r-md);
    background: var(--primary);
    color: white;
    font-size: .78rem;
    font-weight: 600;
    text-decoration: none;
    transition: opacity .2s, transform .15s;
}

.btn-optimize:hover {
    opacity: .9;
    transform: translateY(-1px);
}

.compute-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    padding: 20px;
    margin-bottom: 16px;
    backdrop-filter: blur(12px);
}

.compute-label {
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.compute-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.compute-row-label {
    font-size: .78rem;
    color: var(--text-dim);
    min-width: 90px;
}

.compute-bar {
    flex: 1;
    height: 4px;
    background: var(--surface-high);
    border-radius: 100px;
    overflow: hidden;
}

.compute-fill {
    height: 100%;
    border-radius: 100px;
    background: linear-gradient(to right, var(--primary), var(--accent));
}

.compute-row-pct {
    font-size: .72rem;
    font-weight: 600;
    color: var(--text-dim);
    min-width: 30px;
    text-align: right;
}

/* ── MODAL ───────────────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(2, 11, 24, .75);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-overlay.open {
    display: flex;
    animation: fadeIn .2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0
    }

    to {
        opacity: 1
    }
}

.modal {
    background: rgba(7, 27, 53, .95);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-2xl);
    width: 100%;
    max-width: 620px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: slideUp .25s cubic-bezier(.22, 1, .36, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0
    }

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

.modal-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 24px 24px 0;
}

.sender-big-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: grid;
    place-items: center;
    font-size: .85rem;
    font-weight: 700;
    color: white;
}

.modal-title {
    flex: 1;
    min-width: 0;
}

.modal-title h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
    word-break: break-word;
}

.modal-title .meta {
    font-size: .78rem;
    color: var(--text-dim);
}

.modal-close {
    width: 30px;
    height: 30px;
    border-radius: var(--r-sm);
    background: var(--surface);
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    cursor: pointer;
    color: var(--text-dim);
    transition: background .15s;
    flex-shrink: 0;
}

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

.modal-close svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
}

.email-original {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
    font-size: .835rem;
    color: var(--text-dim);
    line-height: 1.7;
    white-space: pre-wrap;
    margin-bottom: 20px;
}

.ai-reply-section h4 {
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 10px;
}

.ai-reply-textarea {
    width: 100%;
    min-height: 140px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px;
    font-family: var(--font-body);
    font-size: .835rem;
    color: var(--text);
    resize: vertical;
    outline: none;
    transition: border-color .2s;
    line-height: 1.65;
}

.ai-reply-textarea:focus {
    border-color: var(--border-focus);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
}

/* ── BUTTONS ─────────────────────────────────────────────────── */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--r-md);
    background: linear-gradient(135deg, var(--primary), var(--primary-dim));
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: .835rem;
    font-weight: 600;
    color: white;
    transition: opacity .2s, transform .15s, box-shadow .2s;
    box-shadow: 0 4px 16px rgba(20, 100, 246, .35);
    text-decoration: none;
}

.btn-primary:hover {
    opacity: .92;
    transform: translateY(-1px);
    box-shadow: 0 8px 24px rgba(20, 100, 246, .45);
}

.btn-primary svg {
    width: 14px;
    height: 14px;
    stroke: white;
    fill: none;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: .835rem;
    font-weight: 600;
    color: var(--text-dim);
    transition: background .15s, color .15s, border-color .15s;
    text-decoration: none;
}

.btn-secondary:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: rgba(255, 255, 255, .18);
}

/* ── TOAST ───────────────────────────────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: var(--r-lg);
    font-size: .835rem;
    font-weight: 500;
    background: rgba(7, 27, 53, .95);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(20px);
    box-shadow: var(--shadow);
    animation: toastIn .3s cubic-bezier(.22, 1, .36, 1);
    transition: opacity .3s;
    min-width: 240px;
    max-width: 360px;
    color: #e6edf3;
}

@keyframes toastIn {
    from { transform: translateX(40px); opacity: 0 }
    to   { transform: translateX(0);   opacity: 1 }
}

/* Dark mode — original colored borders */
.toast.success { border-color: rgba(16, 185, 129, .4); }
.toast.error   { border-color: rgba(239, 68, 68, .4); }
.toast.info    { border-color: rgba(99, 179, 237, .4); }

.toast svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
}
.toast.success svg { stroke: #34d399; }
.toast.error   svg { stroke: #f87171; }
.toast.info    svg { stroke: #67e8f9; }
.toast-msg { flex: 1; }

/* ── LIGHT MODE overrides (dark mode unchanged above) ── */
[data-theme="light"] .toast {
    background: #ffffff;
    border: 1.5px solid #e2e8f0;
    border-left: 4px solid #64748b;
    box-shadow: 0 8px 32px rgba(0,0,0,.12), 0 2px 8px rgba(0,0,0,.08);
    color: #1e293b;
    backdrop-filter: none;
}
[data-theme="light"] .toast.success {
    background: #f0fdf4;
    border-color: #86efac;
    border-left-color: #16a34a;
    color: #14532d;
}
[data-theme="light"] .toast.success svg { stroke: #16a34a; }

[data-theme="light"] .toast.error {
    background: #fef2f2;
    border-color: #fca5a5;
    border-left-color: #dc2626;
    color: #7f1d1d;
}
[data-theme="light"] .toast.error svg { stroke: #dc2626; }

[data-theme="light"] .toast.info {
    background: #eff6ff;
    border-color: #93c5fd;
    border-left-color: #2563eb;
    color: #1e3a8a;
}
[data-theme="light"] .toast.info svg { stroke: #2563eb; }


@keyframes toastIn {
    from { transform: translateX(40px); opacity: 0 }
    to   { transform: translateX(0);   opacity: 1 }
}

.toast.success {
    background: #f0fdf4;
    border-color: #86efac;
    border-left-color: #16a34a;
    color: #14532d;
}

.toast.error {
    background: #fef2f2;
    border-color: #fca5a5;
    border-left-color: #dc2626;
    color: #7f1d1d;
}

.toast.info {
    background: #eff6ff;
    border-color: #93c5fd;
    border-left-color: #2563eb;
    color: #1e3a8a;
}

/* Dark mode overrides */
[data-theme="dark"] .toast.success, .dark .toast.success {
    background: rgba(16,185,129,.12);
    border-color: rgba(16,185,129,.25);
    border-left-color: #10b981;
    color: #a7f3d0;
}

[data-theme="dark"] .toast.error, .dark .toast.error {
    background: rgba(239,68,68,.12);
    border-color: rgba(239,68,68,.25);
    border-left-color: #ef4444;
    color: #fca5a5;
}

[data-theme="dark"] .toast.info, .dark .toast.info {
    background: rgba(37,99,235,.12);
    border-color: rgba(37,99,235,.25);
    border-left-color: #3b82f6;
    color: #93c5fd;
}

/* If no data-theme (dark-only app) keep fallback dark toast readable */
.toast:not(.success):not(.error):not(.info) {
    background: var(--surface);
    color: var(--text);
}

.toast svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    flex-shrink: 0;
    opacity: .85;
}

.toast-msg { flex: 1; }

/* ── SIDEBAR OVERLAY (mobile) ────────────────────────────────── */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 190;
    background: rgba(2, 11, 24, .55);
    /* NO backdrop-filter here — it causes blur freeze on mobile */
    cursor: pointer;
}

.sidebar-overlay.open {
    display: block;
}

.mobile-menu-btn {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    place-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.mobile-menu-btn svg {
    width: 18px;
    height: 18px;
    stroke: var(--text);
    fill: none;
    stroke-width: 2;
}

/* ── SETTINGS ────────────────────────────────────────────────── */
.settings-grid {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 24px;
    align-items: start;
}

.settings-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-2xl);
    padding: 24px;
    margin-bottom: 16px;
    backdrop-filter: blur(12px);
}

.settings-card-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 20px;
}

.settings-card-icon {
    width: 40px;
    height: 40px;
    background: var(--accent-dim);
    border-radius: var(--r-md);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.settings-card-icon svg {
    width: 20px;
    height: 20px;
    stroke: var(--accent);
    fill: none;
    stroke-width: 1.8;
}

.settings-card-title {
    font-family: var(--font-display);
    font-size: .95rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.settings-card-subtitle {
    font-size: .8rem;
    color: var(--text-dim);
    line-height: 1.5;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-label {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.form-input,
.form-textarea,
.form-select {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 10px 12px;
    font-family: var(--font-body);
    font-size: .835rem;
    color: var(--text);
    outline: none;
    transition: border-color .2s;
    width: 100%;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    border-color: var(--border-focus);
}

.form-textarea {
    resize: vertical;
    line-height: 1.6;
}

.form-select {
    cursor: pointer;
    appearance: none;
}

.form-select option {
    background: #071b35;
    color: var(--text);
}

.form-hint {
    font-size: .72rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.form-input-wrap {
    position: relative;
    display: flex;
}

.form-input-wrap .form-input {
    flex: 1;
    padding-right: 44px;
}

.toggle-viz {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 40px;
    background: none;
    border: none;
    cursor: pointer;
    display: grid;
    place-items: center;
    color: var(--text-muted);
    transition: color .15s;
}

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

.toggle-viz svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px;
    margin-top: 16px;
}

.toggle-row-title {
    font-size: .875rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.toggle-row-subtitle {
    font-size: .775rem;
    color: var(--text-dim);
    line-height: 1.5;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--surface-high);
    border-radius: 100px;
    cursor: pointer;
    transition: background .25s;
    border: 1px solid var(--border);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--text-muted);
    top: 3px;
    left: 3px;
    transition: transform .25s, background .25s;
}

.toggle-switch input:checked+.toggle-slider {
    background: rgba(20, 100, 246, .3);
    border-color: rgba(20, 100, 246, .4);
}

.toggle-switch input:checked+.toggle-slider::before {
    transform: translateX(20px);
    background: var(--primary);
    box-shadow: 0 2px 8px rgba(20, 100, 246, .5);
}

/* Settings right sidebar */
.health-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    padding: 20px;
    margin-bottom: 16px;
    backdrop-filter: blur(12px);
}

.health-label {
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.health-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: .82rem;
    color: var(--text-dim);
}

.health-row:last-of-type {
    border-bottom: none;
}

.health-chip {
    font-size: .58rem;
    font-weight: 700;
    letter-spacing: .08em;
    padding: 3px 9px;
    border-radius: 100px;
}

.health-chip.active {
    background: var(--success-bg);
    color: var(--success);
}

.health-chip.verified {
    background: rgba(20, 100, 246, .12);
    color: #60a5fa;
}

.health-chip.error {
    background: var(--error-bg);
    color: var(--error);
}

.persona-card {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    padding: 20px;
    margin-bottom: 16px;
    backdrop-filter: blur(12px);
}

.persona-label {
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--accent);
    margin-bottom: 12px;
}

.persona-bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px;
    font-size: .8rem;
    color: var(--text-dim);
    line-height: 1.65;
    font-style: italic;
}

.persona-bubble strong {
    color: var(--text);
    font-style: normal;
    display: block;
    margin-bottom: 6px;
}

/* ── EMAIL COMPOSE PANEL (if used) ───────────────────────────── */
.compose-panel {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-2xl);
    padding: 24px;
    margin-bottom: 16px;
    backdrop-filter: blur(12px);
}

/* ── PAGINATION ──────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 20px 0 8px;
}

.pagination a,
.pagination span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    border-radius: var(--r-md);
    font-size: .8rem;
    font-weight: 600;
    text-decoration: none;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-dim);
    transition: background .15s, border-color .15s, color .15s;
    padding: 0 8px;
}

.pagination a:hover {
    background: var(--surface-hover);
    color: var(--text);
    border-color: rgba(255, 255, 255, .18);
}

.pagination span.active {
    background: rgba(20, 100, 246, .2);
    border-color: rgba(20, 100, 246, .35);
    color: #60a5fa;
}

.pagination span.dots {
    background: none;
    border: none;
    color: var(--text-muted);
}

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .metrics-row {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-w: 260px;
    }

    /* Prevent horizontal scroll globally */
    html,
    body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    .app-shell,
    .main-content {
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform .3s cubic-bezier(.22, 1, .36, 1);
    }

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

    .mobile-menu-btn {
        display: grid;
    }

    .main-content {
        margin-left: 0;
    }

    .page-body {
        grid-template-columns: 1fr;
        padding: 14px 14px 40px;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .page-body>aside {
        display: none;
    }

    .page-header {
        padding: 16px 14px 0;
        width: 100%;
        box-sizing: border-box;
    }

    /* Hide Inbox/Pending/Replied tabs in topbar on mobile */
    .topbar-tabs {
        display: none !important;
    }

    .topbar {
        padding: 0 12px;
        gap: 8px;
        height: 54px;
    }

    .stats-row {
        grid-template-columns: 1fr 1fr;
        width: 100%;
        box-sizing: border-box;
    }

    .metrics-row {
        grid-template-columns: 1fr;
    }

    .topbar-search {
        display: none;
    }
}

@media (max-width: 480px) {
    .stats-row {
        grid-template-columns: 1fr;
    }
}

/* ══════════════════════════════════════════════════════════════
   COMMAND CENTER — EMAILS PAGE
   ══════════════════════════════════════════════════════════════ */

/* page-body.full = single-column, full-width content */
.page-body.full {
    display: block;
    padding: 24px 32px 48px;
    max-width: 1400px;
}

/* ── COMPOSE BUTTON ─────────────────────────────────────────── */
.btn-compose {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--r-lg);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: .85rem;
    font-weight: 700;
    color: #fff;
    letter-spacing: .02em;
    box-shadow: 0 4px 20px rgba(20, 100, 246, .35);
    transition: transform .2s cubic-bezier(.22, 1, .36, 1), box-shadow .2s;
    white-space: nowrap;
}

.btn-compose:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(20, 100, 246, .5);
}

.btn-compose svg {
    width: 15px;
    height: 15px;
    stroke: #fff;
    fill: none;
    stroke-width: 2.5;
    flex-shrink: 0;
}

/* ── FILTER ROW ─────────────────────────────────────────────── */
.filter-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.filter-btn {
    display: inline-flex;
    align-items: center;
    padding: 6px 16px;
    border-radius: 100px;
    font-size: .78rem;
    font-weight: 600;
    color: var(--text-dim);
    background: var(--glass);
    border: 1px solid var(--glass-border);
    text-decoration: none;
    transition: background .15s, color .15s, border-color .15s, transform .15s;
    white-space: nowrap;
}

.filter-btn:hover {
    background: var(--glass-hover);
    color: var(--text);
    border-color: rgba(255, 255, 255, .2);
    transform: translateY(-1px);
}

.filter-btn.active {
    background: rgba(20, 100, 246, .18);
    color: #60a5fa;
    border-color: rgba(20, 100, 246, .45);
}

.filter-btn sup {
    font-size: .65rem;
    margin-left: 2px;
    opacity: .7;
}

/* ── EMAIL LIST CONTAINER ───────────────────────────────────── */
.email-list {
    background: var(--glass);
    border: 1px solid var(--glass-border);
    border-radius: var(--r-xl);
    backdrop-filter: blur(12px);
    overflow: hidden;
}

/* ── EMAIL TABLE ────────────────────────────────────────────── */
.email-table {
    width: 100%;
    border-collapse: collapse;
}

.email-table thead tr {
    border-bottom: 1px solid var(--border);
}

.email-table th {
    padding: 12px 16px;
    font-size: .62rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
    text-align: left;
    white-space: nowrap;
}

.email-table tbody tr {
    border-bottom: 1px solid rgba(255, 255, 255, .04);
    transition: background .15s;
}

.email-table tbody tr:last-child {
    border-bottom: none;
}

.email-table tbody tr:hover {
    background: rgba(255, 255, 255, .04);
}

.email-table td {
    padding: 14px 16px;
    font-size: .85rem;
    color: var(--text);
    vertical-align: middle;
}

/* Date cell */
.date-cell {
    font-size: .73rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Sender cell */
.sender-cell {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 160px;
}

.sender-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: grid;
    place-items: center;
    font-size: .72rem;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    letter-spacing: -.5px;
}

.sender-name {
    font-size: .83rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
}

.sender-email {
    font-size: .72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

/* Subject cell */
.subject-cell {
    max-width: 300px;
}

.subj {
    font-size: .85rem;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* AI category chip */
.chip-ai {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 100px;
    font-size: .6rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    background: rgba(6, 182, 212, .12);
    color: var(--accent);
    border: 1px solid rgba(6, 182, 212, .25);
    margin-top: 4px;
}

/* Confidence bar */
.confidence-cell {
    white-space: nowrap;
}

.conf-bar {
    width: 70px;
    height: 4px;
    border-radius: 100px;
    background: rgba(255, 255, 255, .08);
    overflow: hidden;
    display: inline-block;
    vertical-align: middle;
}

.conf-fill {
    height: 100%;
    border-radius: 100px;
    background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
    transition: width .4s cubic-bezier(.22, 1, .36, 1);
}

.conf-pct {
    display: inline-block;
    margin-left: 8px;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-dim);
    vertical-align: middle;
}

/* Action buttons */
.action-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--r-md);
    background: rgba(255, 255, 255, .05);
    border: 1px solid var(--border);
    cursor: pointer;
    display: grid;
    place-items: center;
    color: var(--text-dim);
    transition: background .15s, color .15s, border-color .15s, transform .15s;
    padding: 0;
}

.action-btn:hover {
    background: rgba(20, 100, 246, .18);
    color: #60a5fa;
    border-color: rgba(20, 100, 246, .4);
    transform: translateY(-1px);
}

.action-btn svg {
    width: 13px;
    height: 13px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
}

/* ── PAGINATION ─────────────────────────────────────────────── */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

.pagination-info {
    font-size: .78rem;
    color: var(--text-muted);
    font-weight: 500;
}

.pagination-btns {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.pagination-btn {
    min-width: 34px;
    height: 34px;
    padding: 0 10px;
    border-radius: var(--r-md);
    background: var(--glass);
    border: 1px solid var(--glass-border);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .8rem;
    font-weight: 600;
    color: var(--text-dim);
    text-decoration: none;
    transition: background .15s, color .15s, border-color .15s, transform .15s;
    cursor: pointer;
}

.pagination-btn:hover {
    background: rgba(20, 100, 246, .12);
    color: #60a5fa;
    border-color: rgba(20, 100, 246, .3);
    transform: translateY(-1px);
}

.pagination-btn.active {
    background: rgba(20, 100, 246, .22);
    color: #93c5fd;
    border-color: rgba(20, 100, 246, .5);
    font-weight: 700;
}

.pagination-btn svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.5;
}

/* ── EMAIL MODAL ─────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .75);
    backdrop-filter: blur(6px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadeOverlay .2s ease;
}

.modal-overlay.open {
    display: flex;
}

@keyframes fadeOverlay {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.modal {
    background: #0a1628;
    border: 1px solid var(--glass-border);
    border-radius: var(--r-2xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideModal .3s cubic-bezier(.22, 1, .36, 1);
}

@keyframes slideModal {
    from {
        transform: translateY(24px);
        opacity: 0;
    }

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

.modal-header {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 24px 24px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sender-big-avatar {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    display: grid;
    place-items: center;
    font-size: .9rem;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
}

.modal-title {
    flex: 1;
    min-width: 0;
}

.modal-title h3 {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.modal-title .meta {
    font-size: .78rem;
    color: var(--text-muted);
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
    display: grid;
    place-items: center;
    color: var(--text-dim);
    flex-shrink: 0;
    transition: background .15s, color .15s;
}

.modal-close:hover {
    background: var(--error-bg);
    color: var(--error);
}

.modal-close svg {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2.5;
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-section-title {
    font-size: .6rem;
    font-weight: 700;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.modal-body-text {
    font-size: .88rem;
    line-height: 1.75;
    color: var(--text-dim);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px 16px;
    white-space: pre-wrap;
    word-break: break-word;
}

.modal-textarea {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 14px 16px;
    font-family: var(--font-body);
    font-size: .88rem;
    color: var(--text);
    line-height: 1.75;
    resize: vertical;
    min-height: 120px;
    outline: none;
    transition: border-color .15s;
}

.modal-textarea:focus {
    border-color: var(--border-focus);
}

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

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}

.modal-chip-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    flex-wrap: wrap;
}

/* Compose drawer */
.compose-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    align-items: flex-end;
    justify-content: flex-end;
    padding: 24px;
}

.compose-overlay.open {
    display: flex;
}

.compose-panel {
    background: #081323;
    border: 1px solid var(--glass-border);
    border-radius: var(--r-2xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    animation: slideModal .3s cubic-bezier(.22, 1, .36, 1);
}

.compose-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.compose-header h3 {
    font-family: var(--font-display);
    font-size: .95rem;
    font-weight: 700;
    color: var(--text);
}

.compose-form {
    padding: 16px 20px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.compose-label {
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .09em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: block;
}

.compose-input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 10px 14px;
    font-family: var(--font-body);
    font-size: .875rem;
    color: var(--text);
    outline: none;
    transition: border-color .15s;
}

.compose-input:focus {
    border-color: var(--border-focus);
}

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

.compose-textarea {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    padding: 12px 14px;
    font-family: var(--font-body);
    font-size: .875rem;
    color: var(--text);
    line-height: 1.7;
    resize: vertical;
    min-height: 140px;
    outline: none;
    transition: border-color .15s;
}

.compose-textarea:focus {
    border-color: var(--border-focus);
}

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

.compose-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding-top: 4px;
}

/* Shared action buttons in modals/compose */
.btn-primary {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 20px;
    border-radius: var(--r-lg);
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border: none;
    cursor: pointer;
    font-family: var(--font-body);
    font-size: .82rem;
    font-weight: 700;
    color: #fff;
    box-shadow: 0 4px 16px rgba(20, 100, 246, .3);
    transition: transform .2s, box-shadow .2s;
    white-space: nowrap;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 22px rgba(20, 100, 246, .45);
}

.btn-primary:disabled {
    opacity: .5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary svg {
    width: 14px;
    height: 14px;
    stroke: #fff;
    fill: none;
    stroke-width: 2.5;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 18px;
    border-radius: var(--r-lg);
    background: var(--glass);
    border: 1px solid var(--glass-border);
    cursor: pointer;
    font-family: var(--font-body);
    font-size: .82rem;
    font-weight: 600;
    color: var(--text-dim);
    transition: background .15s, color .15s, border-color .15s;
    white-space: nowrap;
}

.btn-secondary:hover {
    background: var(--glass-hover);
    color: var(--text);
    border-color: rgba(255, 255, 255, .2);
}

/* ── RESPONSIVE — EMAILS ────────────────────────────────────── */
@media (max-width: 768px) {
    .page-body.full {
        padding: 16px 16px 40px;
    }

    .email-table .confidence-cell {
        display: none;
    }

    .sender-name {
        max-width: 100px;
    }

    .subj {
        white-space: normal;
    }

    .modal {
        max-width: 100%;
        border-radius: var(--r-xl) var(--r-xl) 0 0;
        max-height: 95vh;
    }

    .compose-panel {
        max-width: 100%;
        border-radius: var(--r-xl) var(--r-xl) 0 0;
    }

    .compose-overlay {
        padding: 0;
    }
}

/* ══════════════════════════════════════════════════════════════
   LIGHT MODE  —  [data-theme="light"]
   Matches the original light dashboard screenshots exactly.
   ══════════════════════════════════════════════════════════════ */

[data-theme="light"] {
    --bg: #f0f4f8;
    --bg-2: #ffffff;
    --bg-3: #e8edf5;
    --surface: rgba(255, 255, 255, 1);
    --surface-hover: rgba(0, 0, 0, 0.04);
    --surface-high: rgba(0, 0, 0, 0.06);
    --glass: rgba(255, 255, 255, 0.95);
    --glass-border: rgba(0, 0, 0, 0.09);
    --glass-hover: rgba(0, 0, 0, 0.04);
    --text: #111827;
    --text-dim: #4b5563;
    --text-muted: #9ca3af;
    --border: rgba(0, 0, 0, 0.09);
    --border-focus: rgba(20, 100, 246, 0.5);
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.14);
}

/* ── Body background (no space-dark radial gradients in light mode) ── */
[data-theme="light"] body {
    background: #f0f4f8;
    background-image: none;
}

/* Remove the fixed three.js canvas in light mode */
[data-theme="light"] #app-bg-canvas {
    display: none;
}

/* ── Sidebar ─────────────────────────────────────── */
[data-theme="light"] .sidebar {
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

[data-theme="light"] .sidebar-brand-text strong {
    color: #111827;
}

[data-theme="light"] .sidebar-brand-text span {
    color: #9ca3af;
}

[data-theme="light"] .nav-label {
    color: #9ca3af;
}

[data-theme="light"] .nav-item {
    color: #6b7280;
}

[data-theme="light"] .nav-item:hover {
    background: #f3f4f6;
    color: #111827;
}

[data-theme="light"] .nav-item.active {
    background: rgba(20, 100, 246, .1);
    color: var(--primary);
    border-color: rgba(20, 100, 246, .2);
}

[data-theme="light"] .sidebar-bottom {
    border-top-color: #e5e7eb;
}

/* ── Topbar ──────────────────────────────────────── */
[data-theme="light"] .topbar {
    background: rgba(255, 255, 255, 0.97);
    border-bottom: 1px solid #e5e7eb;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
}

[data-theme="light"] .topbar-search {
    background: #f3f4f6;
    border-color: #e5e7eb;
}

[data-theme="light"] .topbar-search input {
    color: #111827;
}

[data-theme="light"] .topbar-search svg {
    stroke: #9ca3af;
}

[data-theme="light"] .topbar-icon-btn {
    color: #6b7280;
}

[data-theme="light"] .topbar-icon-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

[data-theme="light"] .btn-sync {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #374151;
}

[data-theme="light"] .btn-sync:hover {
    background: #e5e7eb;
    border-color: #d1d5db;
}

[data-theme="light"] .btn-sync svg {
    stroke: var(--primary);
}

[data-theme="light"] .user-info-pill {
    background: #f3f4f6;
    border-color: #e5e7eb;
}

[data-theme="light"] .user-email-label {
    color: #4b5563;
}

/* ── Page titles ─────────────────────────────────── */
[data-theme="light"] .page-header h1 {
    color: #111827;
}

[data-theme="light"] .page-header .sub {
    color: #6b7280;
}

[data-theme="light"] .node-badge {
    background: rgba(20, 100, 246, .08);
    color: var(--primary);
    border-color: rgba(20, 100, 246, .2);
}

/* ── Stat cards ──────────────────────────────────── */
[data-theme="light"] .stat-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    backdrop-filter: none;
}

[data-theme="light"] .stat-card:hover {
    border-color: rgba(20, 100, 246, .3);
}

[data-theme="light"] .stat-label {
    color: #9ca3af;
}

[data-theme="light"] .stat-val {
    color: #111827;
}

[data-theme="light"] .stat-sub {
    color: #6b7280;
}

[data-theme="light"] .stat-icon {
    background: #f0f4f8;
    border-color: #e5e7eb;
}

[data-theme="light"] .stat-icon svg {
    stroke: var(--primary);
}

[data-theme="light"] .stat-trend-up {
    color: var(--success);
}

[data-theme="light"] .stat-trend-stable {
    color: var(--warning);
}

/* ── Section headings ────────────────────────────── */
[data-theme="light"] .section-title {
    color: #111827;
}

[data-theme="light"] .section-link {
    color: var(--primary);
}

/* ── Email list / table ──────────────────────────── */
[data-theme="light"] .email-list {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    backdrop-filter: none;
}

[data-theme="light"] .email-table th {
    color: #9ca3af;
}

[data-theme="light"] .email-table tbody tr {
    border-bottom-color: #f3f4f6;
}

[data-theme="light"] .email-table tbody tr:hover {
    background: #f9fafb;
}

[data-theme="light"] .email-table td {
    color: #111827;
}

[data-theme="light"] .date-cell {
    color: #9ca3af;
}

[data-theme="light"] .sender-name {
    color: #111827;
}

[data-theme="light"] .sender-email {
    color: #9ca3af;
}

[data-theme="light"] .subj {
    color: #374151;
}

[data-theme="light"] .sender-avatar {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    color: var(--primary);
}

[data-theme="light"] .conf-bar {
    background: #e5e7eb;
}

[data-theme="light"] .conf-pct {
    color: #374151;
}

[data-theme="light"] .action-btn {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #6b7280;
}

[data-theme="light"] .action-btn:hover {
    background: #dbeafe;
    color: var(--primary);
    border-color: rgba(20, 100, 246, .3);
}

/* ── Filter buttons ──────────────────────────────── */
[data-theme="light"] .filter-btn {
    background: #ffffff;
    border-color: #d1d5db;
    color: #6b7280;
}

[data-theme="light"] .filter-btn:hover {
    background: #f3f4f6;
    color: #111827;
    border-color: #9ca3af;
}

[data-theme="light"] .filter-btn.active {
    background: rgba(20, 100, 246, .08);
    color: var(--primary);
    border-color: rgba(20, 100, 246, .3);
}

/* ── Chips ───────────────────────────────────────── */
[data-theme="light"] .chip-replied {
    background: rgba(16, 185, 129, .08);
    color: #059669;
    border-color: rgba(16, 185, 129, .2);
}

[data-theme="light"] .chip-pending {
    background: rgba(139, 92, 246, .08);
    color: #7c3aed;
    border-color: rgba(139, 92, 246, .2);
}

[data-theme="light"] .chip-failed {
    background: rgba(239, 68, 68, .08);
    color: #dc2626;
    border-color: rgba(239, 68, 68, .2);
}

[data-theme="light"] .chip-skipped {
    background: #f3f4f6;
    color: #9ca3af;
    border-color: #e5e7eb;
}

[data-theme="light"] .chip-ai {
    background: rgba(6, 182, 212, .08);
    color: #0891b2;
    border-color: rgba(6, 182, 212, .2);
}

/* ── Pagination ──────────────────────────────────── */
[data-theme="light"] .pagination {
    border-top-color: #e5e7eb;
}

[data-theme="light"] .pagination-info {
    color: #9ca3af;
}

[data-theme="light"] .pagination-btn {
    background: #ffffff;
    border-color: #e5e7eb;
    color: #6b7280;
}

[data-theme="light"] .pagination-btn:hover {
    background: #dbeafe;
    color: var(--primary);
    border-color: rgba(20, 100, 246, .3);
}

[data-theme="light"] .pagination-btn.active {
    background: rgba(20, 100, 246, .1);
    color: var(--primary);
    border-color: rgba(20, 100, 246, .4);
}

/* ── Metrics / bottom cards ──────────────────────── */
/* Metrics row inherits correctly from variable overrides */

[data-theme="light"] .metric-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    backdrop-filter: none;
}

[data-theme="light"] .metric-label {
    color: #9ca3af;
}

[data-theme="light"] .metric-value {
    color: #111827;
}

[data-theme="light"] .metric-desc {
    color: #6b7280;
}

/* ── Recent emails table (dashboard) ────────────── */
[data-theme="light"] .table-container {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    backdrop-filter: none;
}

[data-theme="light"] thead th {
    color: #9ca3af;
    border-bottom-color: #f3f4f6;
}

[data-theme="light"] tbody td {
    color: #374151;
    border-bottom-color: #f9fafb;
}

[data-theme="light"] tbody tr:hover {
    background: #f9fafb;
}

/* ── Insight card ────────────────────────────────── */
[data-theme="light"] .insight-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
}

[data-theme="light"] .insight-label {
    color: var(--primary);
}

[data-theme="light"] .insight-text {
    color: #374151;
}

/* ── Side panel cards (dashboard right column) ───── */
[data-theme="light"] .side-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    backdrop-filter: none;
}

[data-theme="light"] .side-card-title {
    color: #9ca3af;
}

[data-theme="light"] .progress-label {
    color: #374151;
}

[data-theme="light"] .progress-pct {
    color: #111827;
}

[data-theme="light"] .progress-track {
    background: #e5e7eb;
}

[data-theme="light"] .global-card {
    background: linear-gradient(135deg, rgba(20, 100, 246, .08), rgba(6, 182, 212, .05));
    border: 1px solid rgba(20, 100, 246, .18);
}

[data-theme="light"] .global-label {
    color: #6b7280;
}

[data-theme="light"] .global-heading {
    color: #111827;
}

[data-theme="light"] .global-icon {
    background: var(--primary);
}

/* ── Settings page ───────────────────────────────── */
[data-theme="light"] .settings-section {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    backdrop-filter: none;
}

[data-theme="light"] .settings-section-title {
    color: #111827;
}

[data-theme="light"] .settings-section-sub {
    color: #6b7280;
}

[data-theme="light"] .settings-icon-wrap {
    background: #f0f4f8;
    border-color: #e5e7eb;
}

[data-theme="light"] .settings-icon-wrap svg {
    stroke: var(--primary);
}

[data-theme="light"] .form-label {
    color: #9ca3af;
}

[data-theme="light"] .form-input,
[data-theme="light"] .form-textarea,
[data-theme="light"] .form-select {
    background: #f9fafb;
    border-color: #e5e7eb;
    color: #111827;
}

[data-theme="light"] .form-input:focus,
[data-theme="light"] .form-textarea:focus,
[data-theme="light"] .form-select:focus {
    border-color: rgba(20, 100, 246, .5);
    background: #ffffff;
}

[data-theme="light"] .form-input::placeholder,
[data-theme="light"] .form-textarea::placeholder {
    color: #d1d5db;
}

[data-theme="light"] .form-hint {
    color: #9ca3af;
}

[data-theme="light"] .code-block {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #374151;
}

[data-theme="light"] .toggle-label {
    color: #374151;
}

[data-theme="light"] .toggle-desc {
    color: #9ca3af;
}

/* health chips on settings right panel */
/* Health row inherits correctly from variable overrides */

[data-theme="light"] .health-label {
    color: #374151;
}

[data-theme="light"] .chip-not-linked {
    background: rgba(239, 68, 68, .08);
    color: #dc2626;
    border-color: rgba(239, 68, 68, .2);
}

[data-theme="light"] .chip-not-set {
    background: rgba(245, 158, 11, .08);
    color: #d97706;
    border-color: rgba(245, 158, 11, .2);
}

[data-theme="light"] .chip-on {
    background: rgba(16, 185, 129, .08);
    color: #059669;
    border-color: rgba(16, 185, 129, .2);
}

[data-theme="light"] .persona-preview {
    background: #f9fafb;
    border-color: #e5e7eb;
}

[data-theme="light"] .persona-preview-title {
    color: #111827;
}

[data-theme="light"] .persona-preview-text {
    color: #6b7280;
}

[data-theme="light"] .help-card {
    background: #1a1a2e;
    color: #ffffff;
}

[data-theme="light"] .help-title {
    color: #ffffff;
}

[data-theme="light"] .help-text {
    color: rgba(255, 255, 255, .7);
}

[data-theme="light"] .help-link {
    color: var(--accent);
}

/* ── Scrollbar in light mode ─────────────────────── */
[data-theme="light"] ::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, .15);
}

[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, .25);
}

/* ── Modals ──────────────────────────────────────── */
[data-theme="light"] .modal {
    background: #ffffff;
    border-color: #e5e7eb;
}

[data-theme="light"] .modal-header {
    border-bottom-color: #f3f4f6;
}

[data-theme="light"] .modal-title h3 {
    color: #111827;
}

[data-theme="light"] .modal-title .meta {
    color: #9ca3af;
}

[data-theme="light"] .modal-close {
    background: #f3f4f6;
    border-color: #e5e7eb;
    color: #6b7280;
}

[data-theme="light"] .modal-body-text {
    background: #f9fafb;
    border-color: #e5e7eb;
    color: #374151;
}

[data-theme="light"] .modal-footer {
    border-top-color: #f3f4f6;
}

[data-theme="light"] .modal-textarea {
    background: #f9fafb;
    border-color: #e5e7eb;
    color: #111827;
}

[data-theme="light"] .modal-textarea::placeholder {
    color: #d1d5db;
}

/* ── Empty state ─────────────────────────────────── */
[data-theme="light"] .empty-state h3 {
    color: #6b7280;
}

[data-theme="light"] .empty-state p {
    color: #9ca3af;
}

[data-theme="light"] .empty-state svg {
    stroke: #d1d5db;
}

/* ══════════════════════════════════════════════════════════════
   THEME TOGGLE BUTTON
   ══════════════════════════════════════════════════════════════ */
.theme-toggle {
    width: 36px;
    height: 36px;
    border-radius: var(--r-md);
    background: none;
    border: none;
    cursor: pointer;
    display: grid;
    place-items: center;
    color: var(--text-dim);
    transition: background .15s, color .15s;
    flex-shrink: 0;
}

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

.theme-toggle svg {
    width: 17px;
    height: 17px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.8;
    transition: transform .4s cubic-bezier(.22, 1, .36, 1);
}

.theme-toggle:hover svg {
    transform: rotate(20deg);
}

/* Sun icon = shown in dark mode (click to go light) */
.icon-sun {
    display: block;
}

.icon-moon {
    display: none;
}

[data-theme="light"] .icon-sun {
    display: none;
}

[data-theme="light"] .icon-moon {
    display: block;
}

[data-theme="light"] .theme-toggle {
    color: #6b7280;
}

[data-theme="light"] .theme-toggle:hover {
    background: #f3f4f6;
    color: #111827;
}

/* ══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE — DASHBOARD & EMAILS (max-width: 768px)
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

    /* ── Prevent any horizontal scroll on the whole page ── */
    html,
    body {
        overflow-x: hidden;
        max-width: 100vw;
    }

    .app-shell,
    .main-content {
        overflow-x: hidden;
        width: 100%;
        max-width: 100vw;
    }

    /* ── Hide topbar tabs (Inbox / Pending / Replied) on mobile ── */
    .topbar-tabs {
        display: none !important;
    }

    /* ── Page header: stack title + action vertically ── */
    .page-header {
        padding: 16px 14px 0;
        gap: 10px;
        width: 100%;
        box-sizing: border-box;
    }

    .page-header h1 {
        font-size: 1.35rem;
    }

    .page-header .sub {
        font-size: .8rem;
        margin-top: 3px;
    }

    .page-body {
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }

    .page-body.full {
        padding: 14px 14px 40px;
        width: 100%;
        box-sizing: border-box;
    }

    /* ── Compose button compact ── */
    .btn-compose {
        padding: 9px 14px;
        font-size: .78rem;
        flex-shrink: 0;
    }

    /* ── Filter row: shrink, allow scroll ── */
    .filter-row {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        gap: 6px;
        padding-bottom: 4px;
        margin-bottom: 12px;
        width: 100%;
        box-sizing: border-box;
    }

    .filter-row::-webkit-scrollbar {
        display: none;
    }

    .filter-row>span {
        /* "total" info text */
        flex-shrink: 0;
        font-size: .72rem;
        margin-left: 0 !important;
    }

    .filter-btn {
        flex-shrink: 0;
        padding: 5px 13px;
        font-size: .74rem;
    }

    /* ══ EMAILS TABLE → CARD LAYOUT ══════════════════════════ */
    .email-list {
        border-radius: var(--r-xl);
        overflow: hidden;
    }

    /* Hide the <thead> completely on mobile — force override */
    .email-list .email-table thead,
    .email-table thead,
    .email-table>thead {
        display: none !important;
    }

    /* Each <tbody> row becomes a flex card */
    .email-table tbody tr {
        display: flex;
        flex-direction: column;
        gap: 0;
        padding: 14px 14px 12px;
        border-bottom: 1px solid var(--border);
        position: relative;
        cursor: pointer;
    }

    .email-table tbody tr:last-child {
        border-bottom: none;
    }

    .email-table tbody tr:hover {
        background: var(--surface-hover);
    }

    /* Reset td to block/flex */
    .email-table td {
        display: block;
        padding: 0;
        border: none;
    }

    /* Date — small top-right absolute */
    .email-table .date-cell {
        position: absolute;
        top: 14px;
        right: 14px;
        font-size: .7rem;
        color: var(--text-muted);
        text-align: right;
    }

    /* Sender cell — row with avatar */
    .email-table .sender-cell {
        display: flex;
        align-items: center;
        gap: 10px;
        margin-bottom: 6px;
        padding-right: 70px;
        /* room for date */
    }

    .sender-avatar {
        width: 34px;
        height: 34px;
        font-size: .72rem;
        flex-shrink: 0;
    }

    .sender-name {
        font-size: .85rem;
        font-weight: 600;
    }

    .sender-email {
        font-size: .72rem;
    }

    /* Subject cell */
    .email-table .subject-cell {
        padding-left: 44px;
        /* align under sender text */
        margin-bottom: 8px;
    }

    .subj {
        font-size: .82rem;
        line-height: 1.35;
        white-space: normal;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        line-clamp: 2;
        -webkit-box-orient: vertical;
    }

    .chip {
        font-size: .58rem;
        padding: 3px 8px;
    }

    /* Status + Actions row — horizontal flex */
    .email-table td:nth-child(4) {
        /* status */
        display: inline-flex;
        padding-left: 44px;
        margin-bottom: 0;
    }

    .email-table .confidence-cell {
        display: none;
    }

    /* hide confidence bar */
    .email-table td:last-child {
        /* actions */
        display: inline-flex;
        position: absolute;
        bottom: 12px;
        right: 12px;
    }

    .action-btn {
        width: 28px;
        height: 28px;
    }

    .action-btn svg {
        width: 13px;
        height: 13px;
    }

    /* ── Pagination compact ── */
    .pagination {
        padding: 10px 14px;
        flex-wrap: wrap;
        gap: 6px;
    }

    .pagination-info {
        font-size: .72rem;
    }

    .pagination-btn {
        width: 30px;
        height: 30px;
        font-size: .75rem;
    }

    /* ══ DASHBOARD — Recent Logs table ═══════════════════════ */
    /* dashboard.php uses a simpler table — convert to cards too */
    .email-list table.email-table tbody tr {
        padding-right: 14px;
    }

    /* ── Bottom metrics row ── */
    .metrics-row {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    .metric-card {
        padding: 16px;
    }

    .metric-value {
        font-size: 1.6rem;
    }

    .metric-label {
        font-size: .68rem;
    }

    .metric-desc {
        font-size: .75rem;
    }

    /* ── Stat cards: 1 col on very small, 2 col otherwise ── */
    .stats-row {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card {
        padding: 16px 14px;
    }

    .stat-value {
        font-size: 1.6rem;
    }

    /* ── Side panel right column (dashboard) ── */
    .page-body>aside,
    .page-body>div:last-child:not(:first-child) {
        display: none;
        /* hide right panel on mobile */
    }

    /* ── Topbar: tighter on mobile ── */
    .topbar {
        padding: 0 12px;
        gap: 8px;
        height: 54px;
    }

    .btn-sync span {
        display: none;
    }

    /* hide "Sync Now" text, keep icon */
    .btn-sync {
        padding: 6px 10px;
        min-width: 36px;
    }

    .topbar-icon-btn {
        width: 32px;
        height: 32px;
    }

    .theme-toggle {
        width: 32px;
        height: 32px;
    }

    .avatar-btn {
        width: 30px;
        height: 30px;
        font-size: .7rem;
    }

    /* Node badge hide on mobile */
    .node-badge {
        display: none;
    }

    /* Section header */
    .section-hdr {
        flex-wrap: wrap;
        gap: 4px;
        margin-bottom: 10px;
    }

    .section-hdr h2 {
        font-size: 1rem;
    }
}

/* Extra-small phones */
@media (max-width: 400px) {
    .stats-row {
        grid-template-columns: 1fr;
    }

    .page-header h1 {
        font-size: 1.2rem;
    }

    .email-table .subject-cell {
        padding-left: 0;
    }

    .email-table td:nth-child(4) {
        padding-left: 0;
    }
}