/* ==========================================================================
   Design tokens — OptOut Admin console.
   Every color / spacing / radius / shadow value used below is declared here
   as a variable; component rules should reference the variable, not a raw
   value, so the whole system can be retuned in one place.
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Public+Sans:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
    --font-sans: "Public Sans", system-ui, -apple-system, sans-serif;
    --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;

    /* Surfaces & text */
    --color-bg: #f4f5f7;
    --color-surface: #ffffff;
    --color-border: #e4e7ec;
    --color-border-light: #eef0f3;
    --color-border-lighter: #f2f4f7;
    --color-text: #1b1f24;
    --color-text-secondary: #475467;
    --color-text-muted: #667085;
    --color-text-faint: #98a2b3;
    --color-label: #344054;

    /* Accent (brand) */
    --color-accent: #2749c9;
    --color-accent-hover: #1f3aa8;
    --color-accent-tint: rgba(39, 73, 201, .12);
    --color-accent-soft-bg: #eef2ff;
    --color-accent-soft-text: #3538cd;

    /* Semantic */
    --color-success-bg: #ecfdf3;
    --color-success-text: #087443;
    --color-warning-bg: #fffaeb;
    --color-warning-text: #b54708;
    --color-danger-bg: #fef3f2;
    --color-danger-text: #c0361f;
    --color-danger-border: #f1c7bd;
    --color-info-bg: #e0f2fe;
    --color-info-text: #026aa2;
    --color-neutral-bg: #f2f4f7;
    --color-neutral-text: #475467;

    /* Sidebar (dark, independent of page surfaces) */
    --color-sidebar-bg: #151a21;
    --color-sidebar-border: #252c36;
    --color-sidebar-text: #f2f4f7;
    --color-sidebar-muted: #8b95a5;
    --color-sidebar-active-bg: rgba(255, 255, 255, .08);
    --color-sidebar-hover-bg: rgba(255, 255, 255, .05);
    --color-sidebar-dot: #3a4353;

    /* Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-xl: 12px;
    --radius-pill: 999px;

    /* Shadow */
    --shadow-card: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-card-lg: 0 1px 3px rgba(16, 24, 40, .07);
    --shadow-dialog: 0 20px 48px rgba(16, 24, 40, .25);

    /* Spacing scale */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;

    --sidebar-width: 216px;
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.25;
}

h1 { font-size: 26px; }
h2 { font-size: 21px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }

p { margin: 0 0 var(--space-3); }

a {
    color: var(--color-accent);
    text-decoration: none;
}

img { display: block; max-width: 100%; }

code {
    font-family: var(--font-mono);
    font-size: 0.92em;
}

::placeholder { color: var(--color-text-faint); }

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

.text-muted { color: var(--color-text-muted); }
.text-faint { color: var(--color-text-faint); }
.text-mono { font-family: var(--font-mono); }

/* ==========================================================================
   App shell — sidebar + main content, used by every authenticated page
   ========================================================================== */
.app-shell {
    display: flex;
    align-items: stretch;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--color-sidebar-bg);
    border-right: 1px solid var(--color-sidebar-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 18px 18px 14px;
}

.sidebar-brand-mark {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    background: var(--color-accent);
    flex-shrink: 0;
}

.sidebar-brand-name {
    font-size: 14.5px;
    font-weight: 800;
    color: var(--color-sidebar-text);
}
.sidebar-brand-name span {
    font-weight: 500;
    color: var(--color-sidebar-muted);
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-2) 10px;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: transparent;
    color: var(--color-sidebar-muted);
    border: none;
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    text-align: left;
}
.sidebar-nav-item:hover { background: var(--color-sidebar-hover-bg); }
.sidebar-nav-item.is-active {
    background: var(--color-sidebar-active-bg);
    color: var(--color-sidebar-text);
}
.sidebar-nav-item .dot {
    width: 6px;
    height: 6px;
    border-radius: 2px;
    background: var(--color-sidebar-dot);
    flex-shrink: 0;
}
.sidebar-nav-item.is-active .dot { background: var(--color-accent); }

.sidebar-user {
    margin-top: auto;
    padding: 14px;
    border-top: 1px solid var(--color-sidebar-border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--color-sidebar-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sidebar-user-role {
    font-size: 11px;
    color: var(--color-sidebar-muted);
}

.sidebar-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
    cursor: pointer;
}
.sidebar-backdrop { display: none; }

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

.app-topbar {
    display: none;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    background: var(--color-surface);
    position: sticky;
    top: 0;
    z-index: 20;
}

.app-content {
    padding: 28px 32px;
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    max-width: 1200px;
    width: 100%;
}
.app-content--narrow { max-width: 1100px; }
.app-content--thread { max-width: 860px; }

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-4);
    flex-wrap: wrap;
}
.page-title {
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.page-title--sm { font-size: 20px; }
.page-subtitle {
    font-size: 13.5px;
    color: var(--color-text-muted);
    margin-top: 2px;
}

.breadcrumb {
    font-size: 12.5px;
    color: var(--color-text-muted);
}
.breadcrumb .sep { color: #c6ccd4; padding: 0 2px; }

/* ==========================================================================
   Auth shell — login page, no sidebar
   ========================================================================== */
.auth-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    padding: var(--space-6);
}
.auth-panel { width: 400px; max-width: 100%; }
.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: center;
    margin-bottom: 28px;
}
.auth-brand-mark {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    background: var(--color-accent);
}
.auth-brand-name {
    font-size: 17px;
    font-weight: 800;
    letter-spacing: -0.02em;
}
.auth-brand-name span { font-weight: 500; color: var(--color-text-muted); }
.auth-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-card-lg);
    padding: var(--space-8);
}
.auth-card-title { font-size: 19px; font-weight: 700; margin-bottom: 4px; }
.auth-card-subtitle { font-size: 13.5px; color: var(--color-text-muted); margin-bottom: var(--space-6); }
.auth-footnote {
    text-align: center;
    margin-top: var(--space-4);
    font-size: 12px;
    color: var(--color-text-faint);
}

/* ==========================================================================
   404 / empty-state shell
   ========================================================================== */
.plain-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg);
    padding: var(--space-6);
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    border-radius: var(--radius-sm);
    padding: 9px 16px;
    cursor: pointer;
    border: 1px solid transparent;
    line-height: 1.2;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn--primary {
    background: var(--color-accent);
    color: #fff;
    border-color: var(--color-accent);
}
.btn--primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }

.btn--secondary {
    background: var(--color-surface);
    border-color: #d0d5dd;
    color: var(--color-label);
}
.btn--secondary:hover { background: var(--color-border-lighter); }

.btn--danger {
    background: var(--color-surface);
    border-color: var(--color-danger-border);
    color: var(--color-danger-text);
}
.btn--danger:hover { background: var(--color-danger-bg); }

.btn--ghost {
    background: none;
    border-color: transparent;
    color: var(--color-accent);
    padding: 6px 4px;
}
.btn--ghost:hover { text-decoration: underline; }

.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--block { width: 100%; }
.btn--icon { width: 36px; height: 36px; padding: 0; }

/* ==========================================================================
   Forms
   ========================================================================== */
.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.field label, label.field-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-label);
}
.field-hint { font-size: 11.5px; color: var(--color-text-faint); }
.field.is-muted { opacity: .5; }

.input, .textarea, .select {
    width: 100%;
    border: 1px solid #d0d5dd;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font: inherit;
    font-size: 13.5px;
    color: var(--color-text);
    background: var(--color-surface);
}
.input:hover, .textarea:hover, .select:hover { border-color: #98a2b3; }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible {
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px var(--color-accent-tint);
    outline: none;
}
.textarea { resize: vertical; line-height: 1.55; }
.input--mono, .textarea--mono { font-family: var(--font-mono); }

.subject-preview {
    border: 1px solid #d0d5dd;
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--color-text);
    background: var(--color-surface);
}

.body-editor .tabs { margin-bottom: 10px; }
.body-editor .body-panel { display: none; }
.body-editor .body-panel.is-active { display: block; }
.body-editor .textarea { margin: 0; }
.form-grid.send-method-panel { display: none; }
.form-grid.send-method-panel.is-active { display: grid; }
.body-preview-alt {
    height: 322px;
    margin: 0;
    padding: 10px 12px;
    border: 1px solid #d0d5dd;
    border-radius: var(--radius-sm);
    background: #fafafa;
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.55;
    color: var(--color-text);
    white-space: pre-wrap;
    overflow-y: auto;
}
.body-preview-html {
    width: 100%;
    height: 322px;
    border: 1px solid #d0d5dd;
    border-radius: var(--radius-sm);
    background: #fff;
}

.checkbox {
    width: 15px;
    height: 15px;
    accent-color: var(--color-accent);
    cursor: pointer;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3);
}
.form-grid--2 { grid-template-columns: repeat(2, 1fr); }
.form-grid--4 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.4fr); }

.form-section { display: flex; flex-direction: column; gap: var(--space-3); }
.form-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.form-section-title { font-size: 13px; font-weight: 700; }
.form-section > .form-section-title + .form-grid { margin-top: var(--space-1); }

.repeat-row { display: flex; gap: var(--space-2); }
.repeat-list { display: flex; flex-direction: column; gap: var(--space-2); }

.address-block {
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    background: #fbfcfd;
}
.address-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.address-block-label {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

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

/* ==========================================================================
   Cards
   ========================================================================== */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
}
.card-pad { padding: var(--space-5); }
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--color-border-light);
}
.card-title { font-size: 14px; font-weight: 700; }
.card-title--sm { font-size: 13px; font-weight: 700; margin-bottom: var(--space-3); }

.card-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-3);
    align-items: start;
}
.card-grid--lead {
    grid-template-columns: 1.4fr 1fr;
}

.list-row--top { align-items: flex-start; }
.list-row-text { font-size: 12.5px; color: var(--color-label); line-height: 1.45; }
.list-row-time { font-size: 11px; margin-top: 2px; }
.list-row-date { font-size: 12px; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
}
.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 18px 20px;
    box-shadow: var(--shadow-card);
}
.stat-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .03em;
}
.stat-value {
    font-size: 26px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-top: 6px;
}
.stat-delta { font-size: 12px; font-weight: 600; margin-top: 4px; }
.stat-delta--positive { color: var(--color-success-text); }
.stat-delta--warning { color: var(--color-warning-text); }

.list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--color-border-lighter);
}
.list-row:last-child { border-bottom: none; }
.list-row-title { font-size: 13.5px; font-weight: 600; }
.list-row-meta { font-size: 12px; color: var(--color-text-muted); }

.activity-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-top: 5px;
    flex-shrink: 0;
}
.activity-dot--brand { background: var(--color-accent); }
.activity-dot--warning { background: var(--color-warning-text); }
.activity-dot--success { background: var(--color-success-text); }
.activity-dot--neutral { background: var(--color-text-faint); }

/* ==========================================================================
   Badges (status pills) & tags
   ========================================================================== */
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: var(--radius-pill);
    padding: 3px 10px;
    font-size: 11.5px;
    font-weight: 600;
}
.badge--brand { background: var(--color-accent-soft-bg); color: var(--color-accent-soft-text); }
.badge--success { background: var(--color-success-bg); color: var(--color-success-text); }
.badge--warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge--info { background: var(--color-info-bg); color: var(--color-info-text); }
.badge--neutral { background: var(--color-neutral-bg); color: var(--color-neutral-text); }
.badge--danger { background: var(--color-danger-bg); color: var(--color-danger-text); }

.badge-count {
    background: var(--color-accent-soft-bg);
    color: var(--color-accent-soft-text);
    border-radius: var(--radius-pill);
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 700;
    margin-left: 4px;
}

.tag {
    display: inline-flex;
    align-items: center;
    background: var(--color-border-lighter);
    color: var(--color-text-secondary);
    border-radius: var(--radius-sm);
    padding: 2px 8px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: var(--color-accent);
    color: #fff;
    font-weight: 700;
    flex-shrink: 0;
}
.avatar--lg { width: 52px; height: 52px; font-size: 18px; }
.avatar--sm { width: 32px; height: 32px; font-size: 12px; }

/* ==========================================================================
   Alerts / flash messages
   ========================================================================== */
.alert {
    border-radius: var(--radius-md);
    padding: var(--space-3) var(--space-4);
    font-size: 13.5px;
    font-weight: 600;
    border: 1px solid transparent;
}
.alert--success { background: var(--color-success-bg); color: var(--color-success-text); }
.alert--warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.alert--error { background: var(--color-danger-bg); color: var(--color-danger-text); border-color: var(--color-danger-border); }
.alert--info { background: var(--color-info-bg); color: var(--color-info-text); }
.alert-stack { display: flex; flex-direction: column; gap: var(--space-2); }

.bulk-bar {
    display: none;
    align-items: center;
    gap: var(--space-3);
    background: var(--color-accent-soft-bg);
    border: 1px solid #d3dbf8;
    border-radius: var(--radius-md);
    padding: 10px 14px;
}
.bulk-bar.is-visible { display: flex; }
.bulk-bar-label { font-size: 13px; font-weight: 600; color: var(--color-accent-soft-text); }
.bulk-bar-spacer { flex: 1; }

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--color-border);
}
.tab {
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-muted);
    padding: 10px 14px;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: -1px;
}
.tab:hover { color: var(--color-text); }
.tab.is-active { border-bottom-color: var(--color-accent); color: var(--color-text); }

/* ==========================================================================
   Table + pagination
   ========================================================================== */
.table-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border-light);
}
.table-toolbar .input { flex: 1; max-width: 380px; }
.table-toolbar-count { font-size: 12.5px; color: var(--color-text-muted); white-space: nowrap; }

.table-wrap { overflow-x: auto; }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
    min-width: 640px;
}
.table th {
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 10px 16px;
    border-bottom: 1px solid var(--color-border-light);
}
.table td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--color-border-lighter);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f9fafb; }
.table .cell-primary { font-weight: 600; }
.table .cell-meta { font-size: 11.5px; color: var(--color-text-faint); font-family: var(--font-mono); }
.table .cell-actions { display: flex; gap: 6px; justify-content: flex-end; }
.table td.al-right, .table th.al-right { text-align: right; }

.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
}
.pagination-controls { display: flex; gap: 6px; }
.pagination-label { font-size: 12.5px; color: var(--color-text-muted); }

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty-state {
    text-align: center;
    padding: var(--space-10) var(--space-6);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
}
.empty-state-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--color-border-lighter);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: var(--space-2);
    color: var(--color-text-faint);
}
.empty-state-title { font-size: 15px; font-weight: 700; }
.empty-state-text { font-size: 13.5px; color: var(--color-text-muted); max-width: 40ch; }

/* ==========================================================================
   Loading state (skeleton)
   ========================================================================== */
.skeleton {
    background: linear-gradient(90deg, var(--color-border-lighter) 25%, var(--color-border-light) 37%, var(--color-border-lighter) 63%);
    background-size: 400% 100%;
    animation: skeleton-shine 1.4s ease infinite;
    border-radius: var(--radius-sm);
}
@keyframes skeleton-shine {
    0% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
.skeleton-line { height: 12px; margin-bottom: var(--space-2); }
.skeleton-row { height: 44px; margin-bottom: var(--space-2); border-radius: var(--radius-md); }

/* ==========================================================================
   Key/value grids (profile detail)
   ========================================================================== */
.detail-head { flex-wrap: wrap; }
.detail-id-line { font-size: 12.5px; margin-top: 2px; }
.card-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.card-title-row .card-title--sm { margin-bottom: 0; }
.removal-row { display: flex; align-items: center; gap: var(--space-3); }
.removal-target { flex: 1; font-size: 13.5px; font-weight: 600; }
.removal-date { font-size: 12px; }

.kv-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 20px;
}
.kv-label {
    font-size: 11px;
    font-weight: 700;
    color: var(--color-text-faint);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.kv-value { font-size: 13.5px; color: var(--color-text); margin-top: 3px; }

.contact-row { display: flex; align-items: center; gap: 10px; }
.contact-kind {
    background: var(--color-border-lighter);
    color: var(--color-text-secondary);
    border-radius: 5px;
    padding: 2px 8px;
    font-size: 10.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    width: 52px;
    text-align: center;
    flex-shrink: 0;
}
.contact-value { font-size: 13.5px; color: var(--color-label); font-family: var(--font-mono); }

.address-row { display: flex; gap: 12px; }
.address-num {
    background: var(--color-border-lighter);
    color: var(--color-text-secondary);
    border-radius: 5px;
    padding: 2px 8px;
    font-size: 10.5px;
    font-weight: 700;
    height: fit-content;
    flex-shrink: 0;
}
.address-lines { font-size: 13.5px; color: var(--color-label); line-height: 1.5; }

/* ==========================================================================
   Mail thread
   ========================================================================== */
.thread-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border-lighter);
    cursor: pointer;
}
.thread-row:last-child { border-bottom: none; }
.thread-row:hover { background: #f9fafb; }
.thread-row-profile { width: 160px; flex-shrink: 0; overflow: hidden; }
.thread-row-profile-name { font-size: 13px; font-weight: 600; }
.thread-row-msg-count { font-size: 11.5px; color: var(--color-text-faint); }
.thread-row-body { flex: 1; min-width: 0; }
.thread-row-subject {
    font-size: 13.5px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.thread-row-snippet {
    font-size: 12.5px;
    color: var(--color-text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.thread-row-time {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--color-text-faint);
    flex-shrink: 0;
}
.thread-unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-accent);
    flex-shrink: 0;
}
.thread-read-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-border);
    flex-shrink: 0;
}

.message-thread { display: flex; flex-direction: column; gap: 14px; }
.message-row { display: flex; flex-direction: column; }
.message-row--out { align-items: flex-end; }
.message-row--in { align-items: flex-start; }
.message-bubble {
    max-width: 78%;
    border-radius: var(--radius-lg);
    padding: 14px 16px;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
    border: 1px solid var(--color-border);
    background: var(--color-surface);
}
.message-bubble--out {
    background: var(--color-accent-soft-bg);
    border-color: #d3dbf8;
}
.message-meta {
    display: flex;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}
.message-from { font-size: 12.5px; font-weight: 700; }
.message-to { font-size: 11px; color: var(--color-text-faint); }
.message-date { font-size: 11px; color: var(--color-text-faint); font-family: var(--font-mono); margin-left: auto; }

/* Sanitized email HTML (see MailFormatter::render) — style the tags it allows through. */
.message-body { font-size: 13.5px; color: var(--color-label); line-height: 1.6; word-wrap: break-word; overflow-wrap: anywhere; }
.message-body > *:first-child { margin-top: 0; }
.message-body > *:last-child { margin-bottom: 0; }
.message-body p { margin: 0 0 10px; }
.message-body ul, .message-body ol { margin: 0 0 10px; padding-left: 20px; }
.message-body li { margin-bottom: 2px; }
.message-body a { color: var(--color-accent); text-decoration: underline; }
.message-body a:hover { color: var(--color-accent-hover); }
.message-body h1, .message-body h2, .message-body h3,
.message-body h4, .message-body h5, .message-body h6 { font-size: 13.5px; font-weight: 700; margin: 0 0 8px; }
.message-body hr { border: none; border-top: 1px solid var(--color-border-lighter); margin: 12px 0; }
.message-body pre, .message-body code {
    font-family: var(--font-mono);
    font-size: 12.5px;
    background: var(--color-bg);
    border-radius: 4px;
}
.message-body code { padding: 1px 5px; }
.message-body pre { padding: 8px 10px; overflow-x: auto; margin: 0 0 10px; }
.message-body table { border-collapse: collapse; max-width: 100%; margin: 0 0 10px; }
.message-body td, .message-body th { padding: 4px 8px; border: 1px solid var(--color-border-lighter); font-size: 12.5px; text-align: left; }
.message-body blockquote {
    margin: 10px 0;
    padding-left: 12px;
    border-left: 2px solid var(--color-border);
    color: var(--color-text-muted);
}

/* Trailing quoted history (previous message in the chain), collapsed by default —
   see MailFormatter::wrap_quote() and the "mail-thread" JS controller. */
.message-quote { display: none; margin-top: 10px; padding-left: 12px; border-left: 2px solid var(--color-border); color: var(--color-text-faint); }
.message-quote.is-open { display: block; }
.message-quote-toggle {
    display: inline-flex;
    align-items: center;
    margin-top: 8px;
    padding: 2px 10px;
    border-radius: 999px;
    background: var(--color-bg);
    border: 1px solid var(--color-border-lighter);
    color: var(--color-text-faint);
    font-size: 12px;
    line-height: 1.8;
    cursor: pointer;
}
.message-quote-toggle:hover { background: var(--color-border-lighter); color: var(--color-label); }

.reply-box {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.reply-box .textarea { min-height: 84px; }
.reply-actions { display: flex; justify-content: flex-end; }

/* ==========================================================================
   Dialog (overlay) — rendered statelessly: present in markup only when the
   relevant GET param is set; closed by linking back without that param.
   ========================================================================== */
.dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(16, 24, 40, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-6);
    z-index: 50;
}
.dialog {
    background: var(--color-surface);
    border-radius: var(--radius-xl);
    width: 640px;
    max-width: 100%;
    max-height: 88vh;
    overflow: auto;
    box-shadow: var(--shadow-dialog);
}
.dialog--sm { width: 420px; }
.dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--color-border-light);
}
.dialog-title { font-size: 15px; font-weight: 700; }
.dialog-eyebrow { font-size: 11.5px; color: var(--color-text-faint); font-family: var(--font-mono); margin-top: 2px; }
.dialog-body { padding: 20px 24px; display: flex; flex-direction: column; gap: 14px; }
.dialog-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-top: 1px solid var(--color-border-light);
}
.dialog-kv { grid-template-columns: 64px 1fr; font-size: 13px; }
.dialog-block {
    background: var(--color-bg);
    border: 1px solid var(--color-border-light);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    font-size: 13px;
    line-height: 1.7;
    color: var(--color-label);
    white-space: pre-line;
}
.th-check { width: 36px; }

/* ==========================================================================
   Template picker layout
   ========================================================================== */
.template-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 14px;
    align-items: start;
}
.template-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border-light);
}
.template-toolbar .input { width: 100%; }
.template-toolbar-count {
    padding: 8px 16px;
    font-size: 11.5px;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border-lighter);
}
.template-group + .template-group { border-top: 1px solid var(--color-border-lighter); }
.template-group-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    color: var(--color-text-faint);
    text-transform: uppercase;
    letter-spacing: .04em;
    background: #fafafa;
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.template-group-header::-webkit-details-marker { display: none; }
.template-group-header::before {
    content: "▸";
    font-size: 9px;
    transition: transform .12s ease;
}
.template-group[open] > .template-group-header::before { transform: rotate(90deg); }
.template-group-header:hover { background: #f2f2f2; }
.template-group-count {
    margin-left: auto;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    color: var(--color-text-faint);
}
.template-sidebar {
    max-height: calc(100vh - 160px);
    overflow-y: auto;
    position: sticky;
    top: 14px;
}
.region-row {
    display: block;
    border-left: 3px solid transparent;
    border-bottom: 1px solid var(--color-border-lighter);
    padding: 11px 16px;
    font-size: 13.5px;
    font-weight: 600;
    color: var(--color-text);
    text-decoration: none;
}
.region-row:hover { background: #f9fafb; }
.region-row.is-current { background: #f9fafb; border-left-color: var(--color-accent); }
.region-row-chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.chip {
    display: inline-block;
    border: 1px solid var(--color-border);
    background: var(--color-border-lighter);
    color: var(--color-text-secondary);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 11.5px;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}
.chip:hover { background: var(--color-border-light); }
.chip.is-current { background: var(--color-accent); border-color: var(--color-accent); color: #fff; }
.chip--empty { background: transparent; border-style: dashed; color: var(--color-text-faint); }
.chip--empty.is-current { background: var(--color-accent-soft-bg); border-style: dashed; color: var(--color-accent-soft-text); }
.chip--inactive { color: var(--color-text-faint); text-decoration: line-through; }

.template-preview-bar { display: flex; flex-direction: column; gap: 4px; }
.template-preview-bar .input[type="search"] { width: 180px; }

.merge-tags { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.merge-tags-label {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--color-text-faint);
    text-transform: uppercase;
    letter-spacing: .04em;
}
.merge-tag {
    background: var(--color-border-lighter);
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
    border-radius: 5px;
    padding: 3px 8px;
    font-size: 11.5px;
    font-family: var(--font-mono);
}

/* ==========================================================================
   Utility
   ========================================================================== */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.flex-1 { flex: 1; }
.min-w-0 { min-width: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.fs-12 { font-size: 12px; }
.fs-13 { font-size: 13px; }
.no-wrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .card-grid { grid-template-columns: 1fr; }
    .template-layout { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform .18s ease;
    }
    .sidebar.is-open { transform: translateX(0); }
    .sidebar-backdrop.is-open {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(16, 24, 40, .4);
        z-index: 30;
    }
    .sidebar-toggle { display: inline-flex; }
    .app-topbar { display: flex; }
    .app-content { padding: 20px; gap: var(--space-4); }
    .stat-grid { grid-template-columns: 1fr; }
    .form-grid, .form-grid--2 { grid-template-columns: 1fr; }
    .form-grid--4 { grid-template-columns: 1fr 1fr; }
    .page-header { align-items: flex-start; flex-direction: column; }
    .table-toolbar { flex-wrap: wrap; }
    .table-toolbar .input { max-width: none; width: 100%; }
    .thread-row-profile { width: 96px; }
}

@media (max-width: 480px) {
    .auth-card { padding: var(--space-5); }
    .dialog-footer { flex-direction: column; align-items: stretch; gap: var(--space-2); }
    .dialog-footer .btn { width: 100%; }
}
