/* ================================================================
   AI Email Warmup — Design System & Styles  v3.0
   Single source of truth. Flat monochrome surfaces, one chromatic
   accent, and three reserved status hues that must stay chromatic
   because they carry meaning (delivered / at-risk / failed).
   ================================================================ */

/* ---- CSS Custom Properties ---- */
:root {
    /* Neutral ramp */
    --color-obsidian: #050505;
    --color-charcoal: #151515;
    --color-graphite: #1e1e1e;
    --color-slate: #2f2f2f;
    --color-stone: #8f8f8f;
    --color-ash: #b4b4b4;
    --color-pearl: #d4d4d4;
    --color-silver: #e5e5e5;
    --color-paper: #fdfdfd;

    /* Surfaces */
    --bg-primary: var(--color-obsidian);
    --bg-secondary: var(--color-obsidian);
    --bg-surface: var(--color-charcoal);
    --bg-surface-solid: var(--color-charcoal);
    --bg-surface-hover: var(--color-graphite);
    --bg-surface-elevated: var(--color-graphite);
    --bg-glass: var(--color-charcoal);
    --bg-glass-border: rgba(229, 229, 229, 0.12);

    /* Text — every value below is >= 4.5:1 on --color-obsidian */
    --text-primary: var(--color-paper);
    --text-secondary: var(--color-pearl);
    --text-muted: var(--color-stone);
    --text-accent: var(--color-paper);

    --border-color: rgba(229, 229, 229, 0.12);
    --border-hover: rgba(229, 229, 229, 0.24);
    --border-glow: rgba(253, 253, 253, 0.3);

    /* Brand accent */
    --color-primary: #4d6bff;
    --color-primary-hover: #6b83ff;
    --color-primary-glow: transparent;
    --color-primary-subtle: rgba(77, 107, 255, 0.16);

    /* Status hues — reserved. Never flatten these to grey: they are
       the only signal separating "delivered" from "spam". */
    --color-success: #34d399;
    --color-success-subtle: rgba(52, 211, 153, 0.14);
    --color-success-glow: transparent;

    --color-warning: #fbbf24;
    --color-warning-subtle: rgba(251, 191, 36, 0.14);

    --color-danger: #f87171;
    --color-danger-subtle: rgba(248, 113, 113, 0.14);

    --color-info: #38bdf8;
    --color-info-subtle: rgba(56, 189, 248, 0.14);

    --color-muted: var(--color-stone);

    /* Flat fills — kept as tokens so existing rules keep resolving */
    --gradient-primary: var(--color-primary);
    --gradient-success: var(--color-success);
    --gradient-info: var(--color-info);
    --gradient-warning: var(--color-warning);

    /* Spacing — 4pt scale */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Border Radius — a real scale, not one value repeated */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;
    --radius-full: 9999px;

    /* Font */
    --font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* Shadows — flat system, kept as tokens for compatibility */
    --shadow-sm: none;
    --shadow-md: none;
    --shadow-lg: none;
    --shadow-glow: none;
    --shadow-glow-lg: none;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition: var(--transition-fast);

    /* Focus */
    --color-focus: var(--color-paper);

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 72px;
    --topbar-height: 64px;
}

/* ---- Reset & Base ---- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    background: var(--bg-primary);
    overflow-x: clip;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    letter-spacing: 0.16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: clip;
}

a {
    color: inherit;
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--text-accent);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* ---- Focus ----
   One visible ring for the whole product. Never remove this without
   replacing it: it is the only thing telling a keyboard user where
   they are. */
:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
    border-radius: 2px;
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ---- Skip link ---- */
.skip-link {
    position: absolute;
    left: var(--space-md);
    top: -100px;
    z-index: 200;
    padding: 10px 18px;
    background: var(--color-paper);
    color: var(--color-obsidian);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    transition: top var(--transition-fast);
}

.skip-link:focus-visible {
    top: var(--space-md);
    color: var(--color-obsidian);
    text-decoration: none;
}

/* ---- Custom Scrollbar ---- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--color-slate);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-stone);
}

/* Firefox */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-slate) transparent;
}

/* ---- App Layout ---- */
.app-layout {
    display: flex;
    min-height: 100vh;
    background: var(--bg-primary);
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-primary);
    border-right: 1px solid var(--color-slate);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform var(--transition-base);
}

.sidebar-header {
    padding: var(--space-lg) var(--space-lg);
    border-bottom: 1px solid var(--color-slate);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.logo-icon {
    width: 28px;
    height: 28px;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-paper);
    position: relative;
    overflow: hidden;
}

.logo-text {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.logo-name {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

.logo-badge {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-hover);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-md) 0;
    overflow-y: auto;
}

.sidebar-nav ul {
    list-style: none;
}

.nav-section-title {
    padding: var(--space-lg) var(--space-lg) var(--space-xs);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 12px var(--space-lg);
    margin: 2px var(--space-sm);
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: background var(--transition-fast), color var(--transition-fast);
    position: relative;
}

.nav-link:hover {
    background: var(--color-charcoal);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-link.active {
    background: var(--color-charcoal);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.nav-link svg {
    opacity: 0.6;
    flex-shrink: 0;
    transition: opacity var(--transition-fast);
}

.nav-link:hover svg {
    opacity: 0.85;
}

.nav-link.active svg {
    opacity: 1;
}

.sidebar-footer {
    padding: var(--space-md) var(--space-lg) var(--space-lg);
    border-top: 1px solid var(--color-slate);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.engine-status {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 8px var(--space-md);
    background: var(--color-charcoal);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.status-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--color-success);
    flex-shrink: 0;
}

.status-dot.pulse {
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* ---- Sidebar user block ---- */
.user-profile {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
}

.user-avatar {
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--color-graphite);
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1;
}

.user-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-name {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role {
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-muted);
    line-height: 1.3;
}

.logout-link {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    color: var(--text-muted);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.logout-link:hover {
    background: var(--color-graphite);
    color: var(--text-primary);
}

/* ---- Main Content ---- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.top-bar {
    position: sticky;
    top: 0;
    min-height: var(--topbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--color-slate);
    display: flex;
    align-items: center;
    padding: var(--space-sm) var(--space-xl);
    gap: var(--space-md);
    z-index: 50;
}

.menu-toggle {
    display: none;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-full);
    transition: background var(--transition-fast), color var(--transition-fast);
}

.menu-toggle:hover {
    background: var(--color-charcoal);
    color: var(--text-primary);
}

.page-title {
    font-size: 1.25rem;
    font-weight: 500;
    letter-spacing: -0.02em;
    flex: 1;
    min-width: 0;
    color: var(--text-primary);
}

.top-bar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.content-area {
    flex: 1;
    padding: var(--space-xl);
}

/* ---- Messages / Alerts ---- */
.messages-container {
    padding: var(--space-md) var(--space-xl) 0;
}

.alert {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-lg);
    margin-bottom: var(--space-sm);
    font-size: 0.875rem;
    font-weight: 500;
    animation: slideDown 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.alert-success { background: var(--color-success-subtle); color: var(--color-success); border: 1px solid var(--color-success-subtle); }
.alert-info { background: var(--color-info-subtle); color: var(--color-info); border: 1px solid var(--color-info-subtle); }
.alert-warning { background: var(--color-warning-subtle); color: var(--color-warning); border: 1px solid var(--color-warning-subtle); }
.alert-error { background: var(--color-danger-subtle); color: var(--color-danger); border: 1px solid var(--color-danger-subtle); }

.alert-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: inherit;
    font-size: 1.125rem;
    line-height: 1;
    cursor: pointer;
    opacity: 0.7;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    border-radius: var(--radius-full);
    transition: opacity var(--transition-fast);
}

.alert-close:hover {
    opacity: 1;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---- Stats Grid ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: var(--space-lg);
    margin-bottom: var(--space-xl);
}

.stats-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    transition: background var(--transition-base), border-color var(--transition-base);
    position: relative;
    overflow: hidden;
}

/* The 2px rule is the only thing distinguishing the four metrics.
   Do not remove it without giving the modifiers another difference. */
.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--color-slate);
}

.stat-card:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-hover);
}

.stat-card--primary::before { background: var(--color-primary); }
.stat-card--success::before { background: var(--color-success); }
.stat-card--info::before { background: var(--color-info); }
.stat-card--warning::before { background: var(--color-warning); }

.stat-card__icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-graphite);
    color: var(--text-primary);
}

.stat-card--primary .stat-card__icon { background: var(--color-primary-subtle); color: var(--color-primary-hover); }
.stat-card--success .stat-card__icon { background: var(--color-success-subtle); color: var(--color-success); }
.stat-card--info .stat-card__icon { background: var(--color-info-subtle); color: var(--color-info); }
.stat-card--warning .stat-card__icon { background: var(--color-warning-subtle); color: var(--color-warning); }

.stat-card__content {
    display: flex;
    flex-direction: column;
}

.stat-card__value {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

.stat-card__label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    margin-top: 2px;
    letter-spacing: 0.01em;
}

.stat-card__trend {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.trend-value {
    color: var(--text-muted);
}

/* ---- Cards ---- */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    overflow: hidden;
    transition: border-color var(--transition-base);
}

.card:hover {
    border-color: var(--border-hover);
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.card__title {
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

.card__subtitle {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

.card__action {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
    transition: color var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-height: 32px;
    padding: 0 var(--space-xs);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.card__action:hover {
    color: var(--text-primary);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.card__body {
    padding: var(--space-lg);
}

.chart-card {
    margin-bottom: var(--space-xl);
}

.chart-card .card__body {
    height: clamp(220px, 38vw, 320px);
    padding: var(--space-md) var(--space-lg);
}

/* ---- Two Column Layout ---- */
.two-column {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: var(--space-lg);
}

/* ---- Health List ---- */
.health-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.health-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.health-item:hover {
    background: var(--bg-surface-hover);
}

.health-item__info {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.health-item__avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    background: var(--color-graphite);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
    flex-shrink: 0;
}

.health-item__email {
    font-size: 0.875rem;
    font-weight: 500;
}

.health-item__status {
    margin-top: 2px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: capitalize;
}

.health-item__score {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

/* ---- Status Badges ----
   These are the product's only state signal. Each variant MUST keep a
   distinct hue: "delivered" and "spam" looking alike is a data bug. */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--color-graphite);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

/* Non-colour redundancy: a leading glyph so the state survives
   greyscale, low vision, and colour-blind viewing. */
.status-badge::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: currentColor;
    flex-shrink: 0;
}

.status-active { background: var(--color-success-subtle); color: var(--color-success); border-color: var(--color-success-subtle); }
.status-warming { background: var(--color-primary-subtle); color: var(--color-primary-hover); border-color: var(--color-primary-subtle); }
.status-paused { background: var(--color-warning-subtle); color: var(--color-warning); border-color: var(--color-warning-subtle); }
.status-error { background: var(--color-danger-subtle); color: var(--color-danger); border-color: var(--color-danger-subtle); }
.status-sent { background: var(--color-graphite); color: var(--text-secondary); border-color: var(--border-color); }
.status-delivered { background: var(--color-success-subtle); color: var(--color-success); border-color: var(--color-success-subtle); }
.status-spam { background: var(--color-danger-subtle); color: var(--color-danger); border-color: var(--color-danger-subtle); }
.status-replied { background: var(--color-info-subtle); color: var(--color-info); border-color: var(--color-info-subtle); }
.status-rescued { background: var(--color-warning-subtle); color: var(--color-warning); border-color: var(--color-warning-subtle); }
.status-completed { background: var(--color-success-subtle); color: var(--color-success); border-color: var(--color-success-subtle); }

/* Shape is the second, non-colour channel. */
.status-spam::before,
.status-error::before { border-radius: 0; }
.status-rescued::before,
.status-paused::before { border-radius: 0; transform: rotate(45deg); }

/* ---- Reputation Bar ---- */
.reputation-bar {
    width: 80px;
    height: 6px;
    background: var(--color-graphite);
    border-radius: var(--radius-full);
    overflow: hidden;
    flex-shrink: 0;
}

.reputation-bar__fill {
    height: 100%;
    border-radius: var(--radius-full);
    background: var(--color-stone);
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

.reputation-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: var(--space-xs);
}

.reputation-value {
    font-size: 0.8125rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.rep-excellent, .rep-excellent .reputation-bar__fill { color: var(--color-success); background: var(--color-success); }
.rep-good, .rep-good .reputation-bar__fill { color: var(--color-info); background: var(--color-info); }
.rep-moderate, .rep-moderate .reputation-bar__fill { color: var(--color-warning); background: var(--color-warning); }
.rep-low, .rep-low .reputation-bar__fill { color: #fb923c; background: #fb923c; }
.rep-critical, .rep-critical .reputation-bar__fill { color: var(--color-danger); background: var(--color-danger); }

/* Fix: reputation-value should only affect text color */
.reputation-value.rep-excellent,
.reputation-value.rep-good,
.reputation-value.rep-moderate,
.reputation-value.rep-low,
.reputation-value.rep-critical { background: transparent; }

/* ---- Activity List ---- */
.activity-list {
    display: flex;
    flex-direction: column;
}

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm) 0;
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}

.activity-item:hover {
    background: var(--bg-surface-hover);
}

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

.activity-item__icon {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    background: var(--color-graphite);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 2px;
}

.activity-item__content {
    flex: 1;
    min-width: 0;
}

.activity-item__title {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.activity-item__subject {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.activity-item__meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    flex-shrink: 0;
}

.activity-item__time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    min-height: 40px;
    padding: 9px 18px;
    border-radius: var(--radius-full);
    font-family: var(--font-family);
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
    white-space: nowrap;
    text-decoration: none;
}

.btn:hover {
    text-decoration: none;
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn--primary:hover {
    background: var(--color-silver);
    border-color: var(--color-silver);
    color: var(--color-obsidian);
}

.btn--success {
    background: var(--color-success);
    color: var(--color-obsidian);
    border-color: var(--color-success);
}

.btn--success:hover {
    background: var(--color-success);
    color: var(--color-obsidian);
    filter: brightness(1.08);
}

.btn--danger {
    background: var(--color-danger);
    color: var(--color-obsidian);
    border-color: var(--color-danger);
}

.btn--danger:hover {
    color: var(--color-obsidian);
    filter: brightness(1.08);
}

.btn--ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}

.btn--ghost:hover {
    background: var(--color-charcoal);
    color: var(--text-primary);
}

.btn--outline {
    background: transparent;
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.btn--outline:hover {
    background: var(--color-charcoal);
    color: var(--text-primary);
    border-color: var(--color-stone);
}

.btn--sm {
    min-height: 36px;
    padding: 7px 14px;
    font-size: 0.8125rem;
}

.btn--lg {
    min-height: 48px;
    padding: 11px 24px;
    font-size: 0.9375rem;
    border-radius: var(--radius-full);
}

.btn--danger-text {
    color: var(--color-danger);
}

.btn--danger-text:hover {
    background: var(--color-danger-subtle);
    color: var(--color-danger);
}

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

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

/* ---- Forms ---- */
/* Base for any control not carrying a .form-* class (auth pages, tools). */
input,
select,
textarea {
    font-family: var(--font-family);
    font-size: 0.9375rem;
    color: var(--text-primary);
}

input::placeholder,
textarea::placeholder {
    color: var(--text-muted);
}

textarea {
    background: var(--color-graphite);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 11px 14px;
    width: 100%;
    resize: vertical;
}

.form-page {
    max-width: 800px;
    margin: 0 auto;
}

.form-card .card__header {
    padding: var(--space-xl) var(--space-xl) var(--space-lg);
}

.form-card .card__body {
    padding: 0 var(--space-xl) var(--space-xl);
}

.form-section {
    margin-bottom: var(--space-xl);
}

.form-section__title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-color);
}

.form-grid {
    display: grid;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

.form-grid--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.form-group--wide {
    grid-column: 1 / -1;
}

.form-group--checkbox {
    flex-direction: row;
    align-items: center;
    gap: var(--space-sm);
    min-height: 40px;
}

.form-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-secondary);
    letter-spacing: 0.01em;
}

/* The label is the real touch target here: a 20px box alone is below the
   comfortable minimum, so the label absorbs the rest of the row height. */
.form-label--checkbox {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.form-input,
.form-select {
    background: var(--color-graphite);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 11px 14px;
    min-height: 42px;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 0.9375rem;
    transition: border-color var(--transition-fast), background var(--transition-fast);
    width: 100%;
}

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

/* Do NOT add `outline: none` here. The global :focus-visible ring is the
   only visible focus indicator these controls have. */
.form-input:focus,
.form-select:focus {
    border-color: var(--color-stone);
    background: var(--bg-surface-hover);
}

.form-input[aria-invalid="true"] {
    border-color: var(--color-danger);
}

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

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238f8f8f' viewBox='0 0 16 16'%3e%3cpath d='M8 11L3 6h10l-5 5z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-select option {
    background: var(--color-charcoal);
    color: var(--text-primary);
}

.form-checkbox {
    width: 20px;
    height: 20px;
    accent-color: var(--color-paper);
    cursor: pointer;
    flex-shrink: 0;
}

.form-hint {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.form-error {
    display: block;
    margin-top: 6px;
    font-size: 0.8125rem;
    color: var(--color-danger);
    /* Server hostnames and provider error codes are long unbroken tokens. */
    overflow-wrap: anywhere;
}

/* Colour alone cannot carry "this is an error". */
.form-error::before {
    content: "\26A0";
    margin-right: 6px;
}

/* Summary of every error, rendered at the top of the form so a failed
   submit is visible without scrolling. */
.form-error-summary {
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
    background: var(--color-danger-subtle);
    border: 1px solid var(--color-danger);
    border-radius: var(--radius-md);
}

.form-error-summary:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

.form-error-summary__title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 var(--space-sm);
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--color-danger);
}

.form-error-summary__list {
    margin: 0;
    padding-left: 1.25rem;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.form-error-summary__list li {
    margin-top: 4px;
    overflow-wrap: anywhere;
}

.form-error-summary__list a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-color);
}

.inline-form {
    display: inline;
}

/* ---- Accounts Grid ---- */
.accounts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: var(--space-lg);
}

.account-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    transition: background var(--transition-base), border-color var(--transition-base);
    position: relative;
    overflow: hidden;
}

.account-card:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-hover);
}

.account-card--error {
    border-color: var(--color-danger-subtle);
}

.account-card__header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.account-card__avatar {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-full);
    background: var(--color-graphite);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    flex-shrink: 0;
}

.account-card__info {
    flex: 1;
    min-width: 0;
}

.account-card__email {
    font-size: 0.9375rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-card__provider {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.account-card__stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
    padding: var(--space-md);
    background: var(--color-graphite);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.account-stat {
    text-align: center;
}

.account-stat__value {
    display: block;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.account-stat__label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.account-card__reputation {
    margin-bottom: var(--space-md);
}

.account-card__reputation .reputation-bar {
    width: 100%;
}

.account-card__error {
    display: flex;
    align-items: flex-start;
    gap: var(--space-xs);
    padding: var(--space-sm);
    background: var(--color-danger-subtle);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    font-size: 0.8125rem;
    color: var(--color-danger);
    border: 1px solid var(--color-danger-subtle);
    /* Provider errors contain long unbroken tokens such as
       [AUTHENTICATIONFAILED]; without this they widen the grid track. */
    min-width: 0;
    overflow-wrap: anywhere;
}

.account-card__error svg {
    flex-shrink: 0;
    margin-top: 2px;
}

.account-card__error-headline {
    display: block;
    font-weight: 600;
}

/* What to do about it, in plain language. This is the line that actually
   resolves the failure, so it outranks the provider's raw string. */
.account-card__error-hint {
    display: block;
    margin-top: 4px;
    color: var(--text-primary);
    font-size: 0.8125rem;
    line-height: 1.55;
}

/* The actual reason the connection failed. Previously this lived only in a
   hover tooltip, so it was unreachable on touch and invisible at a glance. */
.account-card__error-detail {
    display: block;
    margin-top: 2px;
    color: var(--text-secondary);
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
    font-size: 0.75rem;
    line-height: 1.5;
}

.account-card__actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

/* ---- Data Table ---- */
.table-responsive {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table thead th {
    padding: var(--space-md) var(--space-lg);
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
    background: var(--color-graphite);
}

.data-table tbody td {
    padding: var(--space-md) var(--space-lg);
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

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

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

.campaign-pair {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.campaign-email {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 500;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

.deliverability {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.deliverability__value {
    font-weight: 600;
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

.mini-bar {
    width: 60px;
    height: 4px;
    background: var(--color-graphite);
    border-radius: var(--radius-full);
    overflow: hidden;
    flex-shrink: 0;
}

.mini-bar__fill {
    height: 100%;
    background: var(--color-success);
    border-radius: var(--radius-full);
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.email-cell {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

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

.empty-cell {
    text-align: center;
    color: var(--text-muted);
    padding: var(--space-2xl) !important;
}

/* ---- Email List (Campaign Detail) ---- */
.email-list {
    display: flex;
    flex-direction: column;
}

.email-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}

.email-item:hover {
    background: var(--bg-surface-hover);
}

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

.email-item__content {
    flex: 1;
    min-width: 0;
}

.email-item__header {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.email-item__subject {
    font-size: 0.9375rem;
    font-weight: 500;
    margin-top: 2px;
}

.email-item__preview {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.email-item__time {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-muted);
}

.empty-state p {
    margin: var(--space-sm) 0 var(--space-md);
}

.empty-state--large {
    padding: var(--space-2xl) var(--space-xl);
    max-width: 500px;
    margin: var(--space-2xl) auto;
}

.empty-state--large h3 {
    font-size: 1.25rem;
    color: var(--text-primary);
    margin-top: var(--space-md);
}

.empty-state--large p {
    color: var(--text-muted);
    line-height: 1.6;
}

.empty-state__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: var(--color-graphite);
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

/* ---- Spinner ---- */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--color-slate);
    border-radius: 50%;
    border-top-color: currentColor;
    animation: spin 0.6s linear infinite;
}

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

/* ---- Tooltip ---- */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::before {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(4px);
    padding: 6px 12px;
    background: var(--color-graphite);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-hover);
    /* Was `nowrap`, which let a long provider error render as a single
       unbreakable line that escaped the card and the viewport. */
    white-space: normal;
    width: max-content;
    max-width: min(280px, 80vw);
    text-align: center;
    overflow-wrap: anywhere;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-fast), visibility var(--transition-fast), transform var(--transition-fast);
    pointer-events: none;
    z-index: 1000;
}

[data-tooltip]:hover::before,
[data-tooltip]:focus-visible::before {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .two-column {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 768px) {
    /* `visibility` is what actually removes the closed drawer from the
       tab order and the a11y tree — transform alone does not. */
    .sidebar {
        transform: translateX(-100%);
        visibility: hidden;
        transition: transform var(--transition-base), visibility var(--transition-base);
    }

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

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

    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .top-bar {
        padding: var(--space-sm) var(--space-md);
    }

    .messages-container {
        padding: var(--space-md) var(--space-md) 0;
    }

    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .accounts-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .form-grid--2,
    .form-grid--3 {
        grid-template-columns: minmax(0, 1fr);
    }

    .content-area {
        padding: var(--space-lg) var(--space-md);
    }

    .form-card .card__header {
        padding: var(--space-lg) var(--space-md) var(--space-md);
    }

    .form-card .card__body {
        padding: 0 var(--space-md) var(--space-lg);
    }

    .data-table thead th,
    .data-table tbody td {
        padding: var(--space-sm) var(--space-md);
    }

    /* Mobile overlay when sidebar is open */
    .sidebar.open + .main-content::before {
        content: '';
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 40;
        animation: fadeIn 0.2s ease;
    }
}

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

    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .btn {
        width: 100%;
    }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ---- Selection ---- */
::selection {
    background: var(--color-paper);
    color: var(--color-obsidian);
}

/* ---- Page Wrappers ---- */
.accounts-page,
.campaigns-page,
.log-page,
.campaign-detail {
    animation: fadeInUp 0.35s ease-out;
}

/* ---- Icon Buttons ---- */
.btn--icon {
    width: 36px;
    height: 36px;
    min-height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.btn--icon svg {
    width: 16px;
    height: 16px;
}

/* ---- Table Card ---- */
.table-card {
    overflow: hidden;
}

.table-card .card__body {
    padding: 0;
}

.table-card .data-table {
    border-radius: 0;
}

/* ---- Form Errors List ---- */
.form-errors {
    list-style: none;
    padding: 0;
    margin: 0 0 var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.form-errors li {
    background: var(--color-danger-subtle);
    border: 1px solid var(--color-danger-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    color: var(--color-danger);
    font-size: 0.875rem;
}

/* ---- Card Badges ---- */
.card-badges {
    display: flex;
    gap: var(--space-xs);
    flex-wrap: wrap;
}

.card-badges .status-badge {
    font-size: 0.75rem;
    padding: 2px 8px;
}

/* ---- History List (Campaign Detail) ---- */
.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    background: var(--color-graphite);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: background var(--transition);
}

.history-item:hover {
    background: var(--color-slate);
}

/* ---- Keyframe Animations ---- */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes alertProgress {
    from { width: 100%; }
    to { width: 0; }
}

/* ---- Onboarding Banner ---- */
.onboarding-banner {
    background: var(--bg-surface);
    border: 1px solid var(--border-hover);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    display: flex;
    align-items: flex-start;
    gap: var(--space-lg);
}

.onboarding-banner__icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: var(--radius-full);
    background: var(--color-graphite);
    color: var(--text-primary);
    flex-shrink: 0;
}

.onboarding-banner__content h3 {
    margin: 0 0 var(--space-xs);
    font-size: 1.125rem;
    color: var(--text-primary);
}

.onboarding-banner__content p {
    margin: 0 0 var(--space-md);
    color: var(--text-secondary);
    font-size: 0.9375rem;
    line-height: 1.6;
}

.onboarding-steps {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.onboarding-step {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 6px var(--space-md);
    background: var(--color-graphite);
    border-radius: var(--radius-full);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.onboarding-step--done {
    color: var(--color-success);
}

.onboarding-step__number {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--color-slate);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    flex-shrink: 0;
}

.onboarding-step--done .onboarding-step__number {
    background: var(--color-success-subtle);
    color: var(--color-success);
}

/* ---- Alert Progress Bar ---- */
.alert {
    position: relative;
    overflow: hidden;
}

.alert[data-auto-dismiss]::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: currentColor;
    opacity: 0.3;
    animation: alertProgress 8s linear forwards;
}

/* Auto-dismiss is a timed action; pausing on hover/focus lets a slow
   reader keep the message on screen. Paired with app.js. */
.alert:hover[data-auto-dismiss]::after,
.alert:focus-within[data-auto-dismiss]::after {
    animation-play-state: paused;
}

/* ---- Improved Empty State ---- */
.empty-state {
    text-align: center;
    padding: var(--space-xl) var(--space-lg);
}

.empty-state__title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: var(--space-md) 0 var(--space-xs);
}

.empty-state__description {
    color: var(--text-muted);
    font-size: 0.9375rem;
    line-height: 1.6;
    max-width: 400px;
    margin: 0 auto var(--space-lg);
}

/* ---- Stat Card Trend Indicator ---- */
.stat-trend-up {
    color: var(--color-success);
}

.stat-trend-down {
    color: var(--color-danger);
}

.stat-trend-neutral {
    color: var(--text-muted);
}
