/* ==========================================================================
   AiByCode Mailer — Design System
   Brand: cyan (#2EF0FA) → electric blue (#1568FC) → deep blue (#1545FD)
   ========================================================================== */

/* ---------- 1. Tokens ---------------------------------------------------- */

:root {
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                 "Helvetica Neue", Arial, sans-serif;
    --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono",
                 Menlo, Consolas, monospace;

    /* brand — identical in both themes */
    --brand:         #1568fc;
    --brand-hover:   #0b56dd;
    --brand-cyan:    #2ef0fa;
    --brand-deep:    #1545fd;
    --brand-fg:      #ffffff;
    --brand-gradient: linear-gradient(135deg, #2ef0fa 0%, #1568fc 52%, #1545fd 100%);
    --brand-glow:    linear-gradient(135deg, rgba(46,240,250,.16), rgba(21,104,252,.16));

    /* radii */
    --r-xs: 6px;
    --r-sm: 9px;
    --r-md: 12px;
    --r-lg: 16px;
    --r-xl: 22px;
    --r-full: 999px;

    /* motion */
    --ease: cubic-bezier(.32, .72, 0, 1);
    --fast: .14s var(--ease);
    --base: .22s var(--ease);
    --slow: .4s var(--ease);

    --sidebar-w: 258px;
    --topbar-h: 64px;
}

/* light theme */
:root, :root[data-theme="light"] {
    --canvas:        #f4f6fa;
    --canvas-tint:   radial-gradient(1200px 600px at 12% -8%, rgba(46,240,250,.10), transparent 60%),
                     radial-gradient(1000px 520px at 92% 0%, rgba(21,104,252,.09), transparent 62%);
    --surface:       #ffffff;
    --surface-2:     #fafbfd;
    --surface-3:     #f1f3f7;
    --surface-inset: #f7f8fb;

    --border:        #e4e7ee;
    --border-2:      #d3d8e2;
    --border-dash:   #c9d2e4;

    --text:          #0c0f16;
    --text-2:        #545c6b;
    --text-3:        #8b93a3;

    --brand-soft:    rgba(21, 104, 252, .085);
    --brand-soft-2:  rgba(21, 104, 252, .16);
    --brand-text:    #0b56dd;

    --success:       #06925f;
    --success-soft:  rgba(6, 146, 95, .10);
    --success-line:  rgba(6, 146, 95, .24);
    --danger:        #dc2626;
    --danger-soft:   rgba(220, 38, 38, .09);
    --danger-line:   rgba(220, 38, 38, .22);
    --warn:          #c2740a;
    --warn-soft:     rgba(194, 116, 10, .11);
    --warn-line:     rgba(194, 116, 10, .24);

    --ring:          rgba(21, 104, 252, .30);
    --overlay:       rgba(10, 14, 24, .42);

    --shadow-1: 0 1px 2px rgba(12,17,29,.05), 0 1px 3px rgba(12,17,29,.05);
    --shadow-2: 0 2px 6px -2px rgba(12,17,29,.07), 0 8px 20px -6px rgba(12,17,29,.09);
    --shadow-3: 0 8px 16px -8px rgba(12,17,29,.10), 0 28px 56px -16px rgba(12,17,29,.18);
    --shadow-brand: 0 6px 18px -4px rgba(21,104,252,.42);
    --logo-halo: 0 4px 14px -4px rgba(21,104,252,.5);
}

/* dark theme */
:root[data-theme="dark"] {
    --canvas:        #080a0f;
    --canvas-tint:   radial-gradient(1200px 600px at 12% -8%, rgba(46,240,250,.09), transparent 60%),
                     radial-gradient(1000px 520px at 92% 0%, rgba(21,104,252,.12), transparent 62%);
    --surface:       #101320;
    --surface-2:     #141827;
    --surface-3:     #1b2032;
    --surface-inset: #0c0f19;

    --border:        #222739;
    --border-2:      #2f364c;
    --border-dash:   #333a52;

    --text:          #eef1f8;
    --text-2:        #9aa3b8;
    --text-3:        #6b7488;

    --brand:         #3b82ff;
    --brand-hover:   #5b98ff;
    --brand-soft:    rgba(59, 130, 255, .13);
    --brand-soft-2:  rgba(59, 130, 255, .24);
    --brand-text:    #7cb0ff;

    --success:       #2ed08c;
    --success-soft:  rgba(46, 208, 140, .12);
    --success-line:  rgba(46, 208, 140, .26);
    --danger:        #ff6a6a;
    --danger-soft:   rgba(255, 106, 106, .12);
    --danger-line:   rgba(255, 106, 106, .26);
    --warn:          #f0b445;
    --warn-soft:     rgba(240, 180, 69, .12);
    --warn-line:     rgba(240, 180, 69, .26);

    --ring:          rgba(59, 130, 255, .40);
    --overlay:       rgba(2, 4, 10, .68);

    --shadow-1: 0 1px 2px rgba(0,0,0,.5);
    --shadow-2: 0 2px 8px -2px rgba(0,0,0,.5), 0 10px 24px -8px rgba(0,0,0,.55);
    --shadow-3: 0 10px 20px -10px rgba(0,0,0,.6), 0 32px 64px -20px rgba(0,0,0,.7);
    --shadow-brand: 0 6px 20px -4px rgba(21,104,252,.55);
    --logo-halo: 0 4px 18px -4px rgba(46,240,250,.45);
}

/* ---------- 2. Base ------------------------------------------------------ */

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

* { margin: 0; padding: 0; }

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text);
    background-color: var(--canvas);
    background-image: var(--canvas-tint);
    background-attachment: fixed;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { font-weight: 650; letter-spacing: -.018em; line-height: 1.25; }

::selection { background: var(--brand-soft-2); }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: var(--r-xs);
}

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
    background: var(--border-2);
    border-radius: var(--r-full);
    border: 3px solid transparent;
    background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: content-box; }

/* ---------- 3. Typography helpers ---------------------------------------- */

.mono { font-family: var(--font-mono); font-size: .92em; letter-spacing: -.01em; }
.muted { color: var(--text-2); }
.dim { color: var(--text-3); }
.eyebrow {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-3);
}
.num { font-variant-numeric: tabular-nums; }

/* ---------- 4. App shell -------------------------------------------------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 18px 14px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    transition: transform var(--base);
}

.brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 6px 8px 16px;
}

.brand-mark {
    width: 36px; height: 36px;
    flex: 0 0 36px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: var(--brand-glow);
    border: 1px solid var(--border);
    box-shadow: var(--logo-halo);
}
.brand-mark img { width: 22px; height: 22px; object-fit: contain; }

.brand-name {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.2;
}
.brand-sub {
    font-size: 11px;
    color: var(--text-3);
    letter-spacing: .01em;
}

.nav { display: flex; flex-direction: column; gap: 3px; }
.nav-label {
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: .11em;
    text-transform: uppercase;
    color: var(--text-3);
    padding: 14px 10px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 9px 11px;
    border-radius: var(--r-sm);
    font-size: 13.5px;
    font-weight: 550;
    color: var(--text-2);
    text-align: left;
    position: relative;
    transition: background var(--fast), color var(--fast);
}
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item svg { width: 17px; height: 17px; flex: none; stroke-width: 1.75; }
.nav-item.active {
    background: var(--brand-soft);
    color: var(--brand-text);
    font-weight: 650;
}
.nav-item.active::before {
    content: "";
    position: absolute;
    left: -14px; top: 50%;
    transform: translateY(-50%);
    width: 3px; height: 20px;
    border-radius: 0 3px 3px 0;
    background: var(--brand);
}
.nav-item .count {
    margin-left: auto;
    font-size: 11px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    padding: 1px 7px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    color: var(--text-2);
}
.nav-item.active .count { background: var(--brand-soft-2); color: var(--brand-text); }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }

.senders-card {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    background: var(--surface-2);
    padding: 12px;
}
.senders-card .eyebrow { margin-bottom: 9px; }
.sender-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 0;
    font-size: 11.5px;
    color: var(--text-2);
}
.sender-row .mono { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex: none;
    background: var(--text-3);
}
.dot.idle { background: var(--success); }
.dot.busy { background: var(--brand); animation: pulse 1.8s var(--ease) infinite; }

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 var(--brand-soft-2); }
    50%      { box-shadow: 0 0 0 5px transparent; }
}

.signout {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 11px;
    border-radius: var(--r-sm);
    font-size: 13px;
    font-weight: 550;
    color: var(--text-2);
    transition: background var(--fast), color var(--fast);
}
.signout:hover { background: var(--danger-soft); color: var(--danger); text-decoration: none; }
.signout svg { width: 16px; height: 16px; stroke-width: 1.75; }

/* main column */
.shell {
    flex: 1;
    min-width: 0;
    margin-left: var(--sidebar-w);
    display: flex;
    flex-direction: column;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 26px;
    background: color-mix(in srgb, var(--canvas) 82%, transparent);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid var(--border);
}
.topbar h2 { font-size: 16.5px; }
.topbar .page-sub { font-size: 12px; color: var(--text-3); margin-top: -1px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }

.icon-btn {
    width: 34px; height: 34px;
    display: grid;
    place-items: center;
    border-radius: var(--r-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-2);
    transition: all var(--fast);
}
.icon-btn:hover { color: var(--text); border-color: var(--border-2); background: var(--surface-3); }
.icon-btn svg { width: 16px; height: 16px; stroke-width: 1.8; }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.ghost:hover { background: var(--surface-3); }

.theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: block; }
:root[data-theme="dark"] .theme-toggle .moon { display: none; }

.menu-btn { display: none; }

.content { padding: 24px 26px 72px; max-width: 1560px; width: 100%; }

/* ---------- 5. Cards & panels -------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
}
.card-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 18px;
    border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 14px; font-weight: 650; }
.card-head .sub { font-size: 12px; color: var(--text-3); margin-top: 1px; }
.card-head .spacer { margin-left: auto; }
.card-body { padding: 18px; }
.card-body + .card-foot { border-top: 1px solid var(--border); }
.card-foot {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--surface-2);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
}

.head-ico {
    width: 30px; height: 30px;
    flex: none;
    display: grid;
    place-items: center;
    border-radius: var(--r-sm);
    background: var(--brand-soft);
    color: var(--brand-text);
}
.head-ico svg { width: 15px; height: 15px; stroke-width: 1.9; }

/* ---------- 6. Buttons ---------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 38px;
    padding: 0 16px;
    border-radius: var(--r-sm);
    border: 1px solid transparent;
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -.005em;
    white-space: nowrap;
    transition: transform var(--fast), background var(--fast),
                border-color var(--fast), box-shadow var(--fast), opacity var(--fast);
}
.btn svg { width: 15px; height: 15px; stroke-width: 2; flex: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn:hover { text-decoration: none; }

.btn-primary {
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow-brand);
}
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }

.btn-brand {
    background: var(--brand-gradient);
    color: #fff;
    box-shadow: var(--shadow-brand);
    position: relative;
    overflow: hidden;
}
.btn-brand::after {
    content: "";
    position: absolute; inset: 0;
    background: linear-gradient(180deg, rgba(255,255,255,.18), transparent 60%);
    opacity: 0;
    transition: opacity var(--fast);
}
.btn-brand:hover:not(:disabled)::after { opacity: 1; }

.btn-secondary {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
    box-shadow: var(--shadow-1);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-2); }

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

.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-line); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; border-radius: var(--r-xs); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { height: 44px; padding: 0 22px; font-size: 14.5px; border-radius: var(--r-md); }
.btn-block { width: 100%; }

.btn .spinner { display: none; }
.btn.loading .spinner { display: block; }
.btn.loading .btn-label, .btn.loading > svg:not(.spinner) { opacity: .55; }

.spinner {
    width: 15px; height: 15px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-top-color: transparent;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 7. Forms ------------------------------------------------------ */

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }

.field label, .lbl {
    display: block;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}
.lbl-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.lbl-row label, .lbl-row .lbl { margin-bottom: 0; }
.lbl-row .spacer { margin-left: auto; }
.hint { font-size: 12px; color: var(--text-3); margin-top: 6px; line-height: 1.5; }
.hint strong, .hint code {
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 500;
    color: var(--brand-text);
    background: var(--brand-soft);
    padding: 1px 5px;
    border-radius: var(--r-xs);
}

.input, .select, .textarea {
    width: 100%;
    background: var(--surface-inset);
    border: 1px solid var(--border);
    border-radius: var(--r-sm);
    padding: 9px 12px;
    font-size: 13.5px;
    color: var(--text);
    transition: border-color var(--fast), box-shadow var(--fast), background var(--fast);
}
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:hover:not(:disabled), .select:hover:not(:disabled), .textarea:hover:not(:disabled) {
    border-color: var(--border-2);
}
.input:focus, .select:focus, .textarea:focus {
    outline: none;
    background: var(--surface);
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--ring);
}
.input:disabled, .textarea:disabled, .select:disabled {
    background: var(--surface-3);
    color: var(--text-2);
    cursor: not-allowed;
}
.input.invalid, .textarea.invalid { border-color: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

.textarea { resize: vertical; min-height: 120px; line-height: 1.65; }
.textarea.mono { font-family: var(--font-mono); font-size: 12.5px; }

.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b93a3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 11px center;
    background-size: 15px;
    padding-right: 34px;
    cursor: pointer;
}

.search-wrap { position: relative; flex: 1; min-width: 160px; }
.search-wrap svg {
    position: absolute;
    left: 11px; top: 50%;
    transform: translateY(-50%);
    width: 15px; height: 15px;
    stroke: var(--text-3);
    stroke-width: 2;
    fill: none;
    pointer-events: none;
}
.search-wrap .input { padding-left: 34px; }

/* token chips */
.tokens { display: flex; flex-wrap: wrap; gap: 6px; }
.token {
    font-family: var(--font-mono);
    font-size: 11.5px;
    font-weight: 500;
    padding: 3px 9px;
    border-radius: var(--r-full);
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text-2);
    transition: all var(--fast);
}
.token:hover { border-color: var(--brand); color: var(--brand-text); background: var(--brand-soft); }

/* dropzone */
.dropzone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px 20px;
    text-align: center;
    border: 1.5px dashed var(--border-dash);
    border-radius: var(--r-md);
    background: var(--surface-2);
    cursor: pointer;
    transition: all var(--base);
}
.dropzone:hover { border-color: var(--brand); background: var(--brand-soft); }
.dropzone.dragging {
    border-color: var(--brand);
    background: var(--brand-soft);
    transform: scale(1.008);
    box-shadow: 0 0 0 4px var(--ring);
}
.dropzone input[type="file"] {
    position: absolute; inset: 0;
    opacity: 0;
    cursor: pointer;
}
.dz-ico {
    width: 42px; height: 42px;
    display: grid; place-items: center;
    border-radius: var(--r-md);
    background: var(--brand-soft);
    color: var(--brand-text);
}
.dz-ico svg { width: 20px; height: 20px; stroke-width: 1.8; }
.dz-title { font-size: 13.5px; font-weight: 600; }
.dz-sub { font-size: 12px; color: var(--text-3); }

.file-chip {
    display: none;
    align-items: center;
    gap: 11px;
    padding: 12px 14px;
    border: 1px solid var(--success-line);
    background: var(--success-soft);
    border-radius: var(--r-md);
}
.file-chip.show { display: flex; }
.file-chip .fc-ico {
    width: 34px; height: 34px;
    flex: none;
    display: grid; place-items: center;
    border-radius: var(--r-sm);
    background: var(--success);
    color: #fff;
}
.file-chip .fc-ico svg { width: 17px; height: 17px; stroke-width: 2; }
.file-chip .fc-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .fc-meta { font-size: 11.5px; color: var(--text-2); }
.file-chip .fc-x { margin-left: auto; }

/* checkbox */
.check {
    appearance: none;
    width: 16px; height: 16px;
    flex: none;
    border: 1.5px solid var(--border-2);
    border-radius: 5px;
    background: var(--surface);
    cursor: pointer;
    display: grid;
    place-items: center;
    transition: all var(--fast);
}
.check:hover { border-color: var(--brand); }
.check:checked { background: var(--brand); border-color: var(--brand); }
.check:checked::after {
    content: "";
    width: 9px; height: 9px;
    background: #fff;
    clip-path: polygon(14% 47%, 0 61%, 39% 100%, 100% 22%, 85% 8%, 38% 71%);
}
.check-line { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 550; cursor: pointer; white-space: nowrap; }

/* ---------- 8. Badges, pills, tags --------------------------------------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: var(--r-full);
    font-size: 11px;
    font-weight: 650;
    letter-spacing: .02em;
    border: 1px solid transparent;
    white-space: nowrap;
}
.badge .dot { width: 5px; height: 5px; }
.badge-running   { background: var(--brand-soft);   color: var(--brand-text); border-color: var(--brand-soft-2); }
.badge-running .dot { background: var(--brand); animation: blink 1.4s ease-in-out infinite; }
.badge-completed { background: var(--success-soft); color: var(--success);   border-color: var(--success-line); }
.badge-completed .dot { background: var(--success); }
.badge-stopped   { background: var(--warn-soft);    color: var(--warn);      border-color: var(--warn-line); }
.badge-stopped .dot { background: var(--warn); }
.badge-sent      { background: var(--success-soft); color: var(--success);   border-color: var(--success-line); }
.badge-failed    { background: var(--danger-soft);  color: var(--danger);    border-color: var(--danger-line); }
.badge-pending   { background: var(--surface-3);    color: var(--text-2);    border-color: var(--border); }
.badge-neutral   { background: var(--surface-3);    color: var(--text-2);    border-color: var(--border); }

@keyframes blink { 0%,100% { opacity: 1; } 50% { opacity: .3; } }

.tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    border: 1px solid var(--border);
    font-size: 11.5px;
    font-weight: 550;
    color: var(--text-2);
}

/* filter chips */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
    padding: 5px 13px;
    border-radius: var(--r-full);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-2);
    transition: all var(--fast);
}
.chip:hover { border-color: var(--border-2); color: var(--text); }
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; box-shadow: var(--shadow-brand); }
.chip .n { opacity: .65; font-variant-numeric: tabular-nums; }
.chip-sm { padding: 3px 10px; font-size: 11.5px; }

/* ---------- 9. Stats ------------------------------------------------------ */

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stat {
    position: relative;
    overflow: hidden;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    padding: 16px 18px;
    box-shadow: var(--shadow-1);
    transition: border-color var(--base), box-shadow var(--base), transform var(--base);
}
.stat:hover { border-color: var(--border-2); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.stat::after {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 2px;
    background: var(--brand-gradient);
    opacity: 0;
    transition: opacity var(--base);
}
.stat:hover::after { opacity: 1; }

.stat-top { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.stat-ico {
    width: 28px; height: 28px;
    display: grid; place-items: center;
    border-radius: var(--r-xs);
    background: var(--brand-soft);
    color: var(--brand-text);
}
.stat-ico svg { width: 14px; height: 14px; stroke-width: 2; }
.stat-ico.ok { background: var(--success-soft); color: var(--success); }
.stat-ico.warn { background: var(--warn-soft); color: var(--warn); }
.stat-ico.bad { background: var(--danger-soft); color: var(--danger); }
.stat-label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.stat-value {
    font-size: 27px;
    font-weight: 700;
    letter-spacing: -.03em;
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
}
.stat-foot { font-size: 11.5px; color: var(--text-3); margin-top: 4px; }

/* ---------- 10. Progress -------------------------------------------------- */

.bar {
    position: relative;
    height: 7px;
    border-radius: var(--r-full);
    background: var(--surface-3);
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    border-radius: var(--r-full);
    background: var(--brand-gradient);
    transition: width .6s var(--ease);
    position: relative;
}
.bar-fill.live::after {
    content: "";
    position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.45), transparent);
    animation: shimmer 1.6s linear infinite;
}
@keyframes shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.bar-fill.ok  { background: linear-gradient(90deg, var(--success), #34d399); }
.bar-fill.bad { background: linear-gradient(90deg, var(--danger), #f87171); }

/* ---------- 11. Campaign cards ------------------------------------------- */

.campaign-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(390px, 1fr));
    gap: 16px;
}

.campaign {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
    overflow: hidden;
    transition: border-color var(--base), box-shadow var(--base), transform var(--base);
    animation: rise .34s var(--ease) both;
}
.campaign:hover { border-color: var(--border-2); box-shadow: var(--shadow-2); transform: translateY(-2px); }
.campaign.is-live { border-color: var(--brand-soft-2); }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.c-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 18px 12px; }
.c-avatar {
    width: 38px; height: 38px;
    flex: none;
    display: grid; place-items: center;
    border-radius: var(--r-sm);
    background: var(--brand-glow);
    border: 1px solid var(--border);
    font-size: 14px;
    font-weight: 700;
    color: var(--brand-text);
    text-transform: uppercase;
}
.c-title {
    font-size: 14.5px;
    font-weight: 650;
    letter-spacing: -.015em;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.c-subject {
    font-size: 12.5px;
    color: var(--text-2);
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.c-meta {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    margin-top: 6px;
    font-size: 11.5px;
    color: var(--text-3);
}
.c-meta > span + span::before {
    content: "·";
    margin-right: 7px;
    opacity: .45;
}

.c-progress { padding: 4px 18px 14px; margin-top: auto; }
.c-progress-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 7px;
}
.c-pct { font-size: 17px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.c-count { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }

.c-legend {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-top: 1px solid var(--border);
    background: var(--surface-2);
}
.c-leg {
    padding: 10px 12px;
    text-align: center;
    border-right: 1px solid var(--border);
}
.c-leg:last-child { border-right: none; }
.c-leg-v { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.c-leg-l { font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); margin-top: 1px; }
.c-leg.ok  .c-leg-v { color: var(--success); }
.c-leg.bad .c-leg-v { color: var(--danger); }

.c-actions {
    display: flex;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
}
.c-actions .btn { flex: 1; }

/* ---------- 12. Recipient list ------------------------------------------- */

.list-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
}

.rlist {
    max-height: 480px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.recipient {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    transition: background var(--fast);
}
.recipient:last-child { border-bottom: none; }
.recipient:hover { background: var(--surface-2); }
.r-email {
    flex: 1;
    min-width: 0;
    font-family: var(--font-mono);
    font-size: 12.5px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.r-name {
    width: 150px;
    flex: none;
    color: var(--text-2);
    font-size: 12.5px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.r-status { flex: none; text-transform: capitalize; min-width: 62px; justify-content: center; }

.list-foot {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    font-size: 12.5px;
    color: var(--text-2);
    border-radius: 0 0 var(--r-lg) var(--r-lg);
}

/* ---------- 13. Email preview -------------------------------------------- */

.mail-preview {
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    overflow: hidden;
    background: var(--surface-inset);
}
.mp-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 13px;
    background: var(--surface-3);
    border-bottom: 1px solid var(--border);
}
.mp-bar .tl { width: 9px; height: 9px; border-radius: 50%; background: var(--border-2); }
.mp-bar .tl:nth-child(1) { background: #ff5f57; }
.mp-bar .tl:nth-child(2) { background: #febc2e; }
.mp-bar .tl:nth-child(3) { background: #28c840; }
.mp-bar span { margin-left: 8px; font-size: 11px; color: var(--text-3); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }

.mp-head { padding: 13px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.mp-row { display: flex; gap: 10px; font-size: 12.5px; padding: 2px 0; }
.mp-row .k { width: 52px; flex: none; color: var(--text-3); font-weight: 600; }
.mp-row .v { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-row .v.subject { font-weight: 650; color: var(--text); }

.mp-body {
    padding: 16px;
    background: var(--surface);
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 340px;
    overflow-y: auto;
    color: var(--text-2);
}
.mp-body:empty::before { content: "Your message preview will appear here…"; color: var(--text-3); font-style: italic; }
.mail-preview mark {
    background: var(--brand-soft);
    color: var(--brand-text);
    padding: 0 3px;
    border-radius: 4px;
    font-weight: 600;
}

/* ---------- 14. Stepper ---------------------------------------------------- */

.stepper {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.step {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px 6px 7px;
    border-radius: var(--r-full);
    border: 1px solid var(--border);
    background: var(--surface);
    font-size: 12.5px;
    font-weight: 600;
    color: var(--text-3);
}
.step .n {
    width: 20px; height: 20px;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--surface-3);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-2);
}
.step.active { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-text); }
.step.active .n { background: var(--brand); color: #fff; }
.step.done { color: var(--success); border-color: var(--success-line); background: var(--success-soft); }
.step.done .n { background: var(--success); color: #fff; }
.step-line { flex: 0 0 18px; height: 1px; background: var(--border-2); }

/* ---------- 15. Empty & skeleton ------------------------------------------ */

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
    padding: 64px 24px;
    background: var(--surface);
    border: 1px dashed var(--border-dash);
    border-radius: var(--r-lg);
}
.empty-ico {
    width: 58px; height: 58px;
    display: grid; place-items: center;
    border-radius: var(--r-lg);
    background: var(--brand-soft);
    color: var(--brand-text);
    margin-bottom: 8px;
}
.empty-ico svg { width: 26px; height: 26px; stroke-width: 1.6; }
.empty h3 { font-size: 15px; }
.empty p { font-size: 13px; color: var(--text-2); max-width: 380px; }
.empty .btn { margin-top: 12px; }

.skeleton {
    background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
    background-size: 200% 100%;
    animation: sweep 1.3s linear infinite;
    border-radius: var(--r-xs);
}
@keyframes sweep { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.sk-card { height: 210px; border-radius: var(--r-lg); }
.sk-stat { height: 96px; border-radius: var(--r-lg); }

/* ---------- 16. Toasts ---------------------------------------------------- */

.toasts {
    position: fixed;
    top: 18px; right: 18px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(370px, calc(100vw - 36px));
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: flex-start;
    gap: 11px;
    padding: 13px 14px;
    border-radius: var(--r-md);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-3);
    pointer-events: auto;
    animation: toast-in .34s var(--ease) both;
}
.toast.out { animation: toast-out .24s var(--ease) both; }
@keyframes toast-in  { from { opacity: 0; transform: translateX(24px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(24px) scale(.97); } }

.toast .t-ico {
    width: 26px; height: 26px;
    flex: none;
    display: grid; place-items: center;
    border-radius: var(--r-xs);
}
.toast .t-ico svg { width: 14px; height: 14px; stroke-width: 2.2; }
.toast.success .t-ico { background: var(--success-soft); color: var(--success); }
.toast.error   .t-ico { background: var(--danger-soft);  color: var(--danger); }
.toast.info    .t-ico { background: var(--brand-soft);   color: var(--brand-text); }
.toast .t-title { font-size: 13px; font-weight: 650; }
.toast .t-msg { font-size: 12.5px; color: var(--text-2); margin-top: 1px; word-break: break-word; }
.toast .t-x { margin-left: auto; color: var(--text-3); flex: none; }
.toast .t-x:hover { color: var(--text); }
.toast .t-x svg { width: 14px; height: 14px; stroke-width: 2; }

/* ---------- 17. Layout grids ---------------------------------------------- */

.grid-2 {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}
.grid-split {
    display: grid;
    grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr);
    gap: 18px;
    align-items: start;
}
.sticky-col { position: sticky; top: calc(var(--topbar-h) + 22px); }
.stack { display: flex; flex-direction: column; gap: 18px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row .spacer { margin-left: auto; }

.page-head {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}
.page-head h2 { font-size: 19px; letter-spacing: -.025em; }
.page-head p { font-size: 13px; color: var(--text-2); margin-top: 2px; }

/* ---------- 18. Responsive ------------------------------------------------ */

@media (max-width: 1180px) {
    .grid-2, .grid-split { grid-template-columns: minmax(0, 1fr); }
    .sticky-col { position: static; }
}

@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-3); }
    .sidebar.open { transform: none; }
    .shell { margin-left: 0; }
    .menu-btn { display: grid; }
    .scrim {
        position: fixed; inset: 0;
        background: var(--overlay);
        backdrop-filter: blur(2px);
        z-index: 50;
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--base), visibility var(--base);
    }
    .scrim.show { opacity: 1; visibility: visible; }
}

@media (max-width: 720px) {
    .content { padding: 18px 14px 60px; }
    .topbar { padding: 0 14px; gap: 10px; }
    .topbar .page-sub { display: none; }
    .campaign-grid { grid-template-columns: 1fr; }
    .stats { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
    .stat { padding: 13px 14px; }
    .stat-value { font-size: 22px; }
    .r-name { display: none; }
    .card-body { padding: 15px; }
    .c-actions { flex-direction: column; }
}

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