:root {
    color-scheme: light;
    --bg: #f6f7fb;
    --surface: #ffffff;
    --border: #e5e7eb;
    --border-strong: #d7dae1;
    --text: #1a1d29;
    --text-muted: #6b7280;
    --text-faint: #9ca3af;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --primary-soft-text: #4338ca;

    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-soft: #fef2f2;
    --danger-soft-text: #b91c1c;

    --success: #16a34a;
    --success-soft: #ecfdf3;
    --success-soft-text: #15803d;

    --warning: #d97706;
    --warning-soft: #fffbeb;
    --warning-soft-text: #b45309;

    --neutral-soft: #f3f4f6;
    --neutral-soft-text: #4b5563;

    --bounced: #7c3aed;
    --bounced-soft: #f5f3ff;
    --bounced-soft-text: #6d28d9;

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
    --sidebar-w: 240px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Helvetica, Arial, sans-serif;
    margin: 0;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1rem; }
p { margin: 0 0 8px; }
a { color: var(--primary); }
code {
    background: var(--neutral-soft);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.85em;
}

/* ---------- App shell / sidebar ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px 20px;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}

.sidebar-brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), #7c73f0);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-brand-mark svg { width: 16px; height: 16px; }

.sidebar-nav {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: background 0.12s ease, color 0.12s ease;
}

.sidebar-nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }

.sidebar-nav a:hover { background: var(--neutral-soft); color: var(--text); }

.sidebar-nav a.active {
    background: var(--primary-soft);
    color: var(--primary-soft-text);
}

.sidebar-nav a.active svg { opacity: 1; }

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding-top: 12px;
    margin-top: 12px;
}

.sidebar-user {
    font-size: 0.78rem;
    color: var(--text-faint);
    padding: 0 10px;
    margin: 0 0 6px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 600;
}

.sidebar-footer form { margin: 0; }

.sidebar-footer button {
    width: 100%;
    justify-content: flex-start;
    display: flex;
    align-items: center;
    gap: 10px;
    background: none;
    color: var(--text-muted);
    border: none;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
}

.sidebar-footer button:hover { background: var(--neutral-soft); color: var(--text); }
.sidebar-footer svg { width: 17px; height: 17px; }

.app-main {
    flex: 1;
    min-width: 0;
    padding: 30px 36px 60px;
}

main { max-width: 1180px; }

/* ---------- Page header ---------- */

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-header .actions { display: flex; gap: 10px; flex-wrap: wrap; }

.page-subtitle { color: var(--text-muted); font-size: 0.88rem; margin-top: -2px; }

/* ---------- Buttons ---------- */

button, .btn {
    background: var(--primary);
    color: #fff;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 550;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
    line-height: 1.3;
}

button:hover, .btn:hover { background: var(--primary-hover); }
button:disabled { opacity: 0.55; cursor: default; }
button:disabled:hover { background: var(--primary); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
}
.btn-secondary:hover { background: var(--neutral-soft); }

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

.btn-ghost {
    background: none;
    color: var(--text-muted);
    border: 1px solid transparent;
    padding: 6px 10px;
}
.btn-ghost:hover { background: var(--neutral-soft); color: var(--text); }

.btn-sm { padding: 4px 10px; font-size: 0.78rem; }

.inline-form { display: inline; }

.row-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ---------- Tables ---------- */

.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

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

.table-card table { margin: 0; }

th, td {
    text-align: left;
    padding: 11px 16px;
    border-bottom: 1px solid var(--border);
    font-size: 0.87rem;
}

thead th {
    background: var(--neutral-soft);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafe; }

table:not(.table-card table) { margin-top: 16px; }

/* ---------- Status pills ---------- */

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--neutral-soft);
    color: var(--neutral-soft-text);
}

.status-pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.status-pending { background: var(--warning-soft); color: var(--warning-soft-text); }
.status-sent { background: var(--success-soft); color: var(--success-soft-text); }
.status-failed { background: var(--danger-soft); color: var(--danger-soft-text); }
.status-bounced { background: var(--bounced-soft); color: var(--bounced-soft-text); }

.status-campaign-running { background: var(--primary-soft); color: var(--primary-soft-text); }
.status-campaign-paused { background: var(--warning-soft); color: var(--warning-soft-text); }
.status-campaign-completed { background: var(--success-soft); color: var(--success-soft-text); }
.status-campaign-canceled { background: var(--neutral-soft); color: var(--neutral-soft-text); }

/* ---------- Progress bar ---------- */

.progress-bar {
    background: var(--neutral-soft);
    border-radius: 999px;
    overflow: hidden;
    height: 10px;
}

.progress-bar-fill {
    background: var(--primary);
    height: 100%;
    border-radius: 999px;
    transition: width 0.4s ease;
}

.progress-bar-sm { height: 6px; min-width: 90px; }
.progress-bar-lg { height: 14px; }

.status-pill.spinning::before {
    animation: pulse 0.9s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.35; transform: scale(1.4); }
}

/* ---------- Toolbar / filters ---------- */

.toolbar {
    display: flex;
    gap: 14px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
}

.toolbar label {
    display: flex;
    flex-direction: column;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    gap: 5px;
}

.toolbar form { display: contents; }

/* ---------- Forms ---------- */

select, input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="file"], textarea {
    padding: 8px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-family: inherit;
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

select:focus, input:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

textarea { width: 100%; min-height: 220px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.83rem; }

input[type="checkbox"] { width: auto; accent-color: var(--primary); }

form.stacked label {
    display: block;
    margin-bottom: 14px;
}

form.stacked label > span {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 5px;
}

form.stacked input[type="text"],
form.stacked input[type="email"],
form.stacked input[type="password"],
form.stacked input[type="number"],
form.stacked select { width: 100%; }

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
    margin-bottom: 6px !important;
    color: var(--text);
}

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

.error {
    color: var(--danger-soft-text);
    background: var(--danger-soft);
    border: 1px solid #fecaca;
    padding: 9px 13px;
    border-radius: var(--radius-sm);
    font-size: 0.87rem;
    margin-bottom: 12px;
}

/* ---------- Cards / layout helpers ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.form-card { max-width: 520px; }
.form-card--narrow { max-width: 400px; }

.split { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
.split > * { flex: 1 1 320px; min-width: 0; }

.preview-box {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    background: var(--bg);
}

.preview-box + .preview-box { margin-top: 10px; }

.mt-lg { margin-top: 24px; }

.danger-zone {
    border-color: #fecaca;
    background: var(--danger-soft);
}

.danger-zone h2 { color: var(--danger-soft-text); }
.danger-zone input[type="text"] { max-width: 200px; }

.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
}

.badge-count {
    display: inline-block;
    background: var(--neutral-soft);
    color: var(--neutral-soft-text);
    border-radius: 999px;
    padding: 0 8px;
    font-size: 0.78rem;
    font-weight: 600;
}

/* ---------- Auth page ---------- */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(180deg, #f6f7fb 0%, #eef0f9 100%);
}

.auth-card {
    width: 340px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 32px 28px;
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 22px;
}

.auth-brand .sidebar-brand-mark { width: 34px; height: 34px; border-radius: 10px; }
.auth-brand span { font-weight: 700; font-size: 1.1rem; }

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form label { display: block; }
.auth-form label > span { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; }
.auth-form input { width: 100%; }
.auth-form button { width: 100%; justify-content: center; margin-top: 4px; padding: 9px 14px; }

/* ---------- Misc ---------- */

/* ---------- Send dashboard ---------- */

.dashboard-card { padding: 20px 22px 16px; }

.dashboard-kpis {
    display: flex;
    gap: 32px;
    flex-wrap: wrap;
    padding-bottom: 18px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border);
}

.kpi-group { min-width: 220px; }
.kpi-group h2 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 10px; }

.kpi-row { display: flex; gap: 24px; }

.kpi { display: flex; flex-direction: column; }
.kpi-value { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 0.78rem; color: var(--text-muted); margin-top: 2px; }

.kpi-sent { color: var(--success-soft-text); }
.kpi-failed { color: var(--danger-soft-text); }
.kpi-bounced { color: var(--bounced-soft-text); }

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.chart-header h2 { font-size: 0.85rem; margin: 0; }

.chart-legend {
    list-style: none;
    display: flex;
    gap: 14px;
    margin: 0;
    padding: 0;
    font-size: 0.78rem;
    color: var(--text-muted);
}

.chart-legend li { display: flex; align-items: center; gap: 5px; }

.legend-dot { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.legend-sent { background: var(--success); }
.legend-failed { background: var(--danger); }
.legend-bounced { background: var(--bounced); }

.chart-row {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 130px;
    padding-top: 4px;
}

.chart-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    min-width: 0;
}

.chart-bar {
    width: 100%;
    max-width: 12px;
    height: 120px;
    display: flex;
    flex-direction: column-reverse;
    border-radius: 3px 3px 1px 1px;
    overflow: hidden;
    background: var(--neutral-soft);
    cursor: default;
}

.chart-seg { width: 100%; flex-shrink: 0; }
.chart-seg-sent { background: var(--success); }
.chart-seg-failed { background: var(--danger); }
.chart-seg-bounced { background: var(--bounced); }

.chart-daylabel {
    font-size: 0.68rem;
    color: var(--text-faint);
    margin-top: 6px;
    font-variant-numeric: tabular-nums;
}

/* ---------- Activity log ---------- */

#activity-log {
    max-height: 260px;
    overflow-y: auto;
}

.log-entry {
    display: flex;
    align-items: baseline;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.83rem;
}

.log-entry:last-child { border-bottom: none; }

.log-time {
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    width: 68px;
}

.log-email { flex-shrink: 0; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.log-detail { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Sortable table headers ---------- */

th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

th.sortable:hover { color: var(--text); }

.sort-caret {
    display: inline-block;
    margin-left: 4px;
    opacity: 0.35;
}

.sort-caret::after { content: "\2195"; }

th.sortable.sort-asc .sort-caret,
th.sortable.sort-desc .sort-caret { opacity: 1; color: var(--primary); }

th.sortable.sort-asc .sort-caret::after { content: "\2191"; }
th.sortable.sort-desc .sort-caret::after { content: "\2193"; }

.hidden { display: none !important; }

/* ---------- Alerts / notifications ---------- */

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.87rem;
    margin-bottom: 16px;
    border: 1px solid;
}

.alert-success {
    color: var(--success-soft-text);
    background: var(--success-soft);
    border-color: #bbf7d0;
}

.alert-error {
    color: var(--danger-soft-text);
    background: var(--danger-soft);
    border-color: #fecaca;
}

/* ---------- Settings sections ---------- */

.settings-section {
    margin-bottom: 36px;
}

.settings-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.settings-section-header h2 {
    font-size: 0.95rem;
    font-weight: 650;
    color: var(--text);
    margin: 0;
}

.settings-section-header .section-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary-soft-text);
}
