:root {
    --ms-bg: #f5f7fb;
    --ms-surface: #ffffff;
    --ms-surface-soft: #f8fafc;
    --ms-text: #172033;
    --ms-muted: #667085;
    --ms-border: #e4e8f0;
    --ms-border-strong: #d5dbe7;
    --ms-primary: #4f46e5;
    --ms-primary-dark: #3730a3;
    --ms-primary-soft: #eef2ff;
    --ms-success: #14804a;
    --ms-success-soft: #e9f8f0;
    --ms-warning: #b76e00;
    --ms-warning-soft: #fff6df;
    --ms-danger: #c2413d;
    --ms-danger-soft: #fff0ef;
    --ms-info: #0369a1;
    --ms-info-soft: #eaf6ff;
    --ms-shadow: 0 18px 45px rgba(15, 23, 42, .07);
    --ms-radius: 8px;
    --ms-sidebar: 264px;
}

* { letter-spacing: 0; }

body {
    margin: 0;
    background: var(--ms-bg);
    color: var(--ms-text);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
}

a { color: var(--ms-primary); }
a:hover { color: var(--ms-primary-dark); }

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

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--ms-sidebar);
    background: #0f172a;
    color: #dbe4f3;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    transition: transform .2s ease;
}

.sidebar-brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 22px 20px 18px;
}

.brand-mark {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-weight: 800;
}

.brand-name { font-size: 17px; font-weight: 800; color: #fff; line-height: 1.1; }
.brand-caption { font-size: 12px; color: #94a3b8; margin-top: 3px; }

.sidebar-nav { padding: 10px 12px; flex: 1; }
.sidebar-nav .nav-link,
.sidebar-footer .nav-link {
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 42px;
    padding: 10px 12px;
    margin-bottom: 4px;
    color: #b6c2d6;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 600;
}
.sidebar-nav .nav-link i,
.sidebar-footer .nav-link i { font-size: 17px; width: 20px; text-align: center; }
.sidebar-nav .nav-link:hover,
.sidebar-footer .nav-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-nav .nav-link.active {
    background: rgba(99, 102, 241, .18);
    color: #fff;
    box-shadow: inset 3px 0 0 #818cf8;
}
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.logout-link { color: #fecaca !important; }

.app-main {
    flex: 1;
    min-width: 0;
    margin-left: var(--ms-sidebar);
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    height: 76px;
    display: flex;
    align-items: center;
    gap: 16px;
    justify-content: space-between;
    padding: 0 30px;
    background: rgba(245, 247, 251, .9);
    border-bottom: 1px solid var(--ms-border);
    backdrop-filter: blur(14px);
}

.topbar-title { min-width: 0; margin-right: auto; }
.topbar-title h1 { margin: 0; font-size: 22px; font-weight: 800; line-height: 1.2; }
.topbar-kicker { color: var(--ms-muted); font-size: 12px; font-weight: 700; text-transform: uppercase; margin-bottom: 3px; }

.topbar-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-avatar {
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--ms-primary-soft);
    color: var(--ms-primary-dark);
    font-weight: 800;
}
.user-meta { display: flex; flex-direction: column; line-height: 1.15; max-width: 220px; }
.user-meta span { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-meta small { color: var(--ms-muted); margin-top: 3px; }

.content-wrap { padding: 28px 30px 36px; max-width: 1440px; margin: 0 auto; }
.app-footer { padding: 0 30px 26px; color: var(--ms-muted); font-size: 12px; text-align: center; }
.flash-stack { margin-bottom: 18px; }

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 20px;
}
.page-header h2 { margin: 0; font-size: 24px; font-weight: 800; }
.page-header p { margin: 6px 0 0; color: var(--ms-muted); }
.page-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.card,
.panel {
    background: var(--ms-surface);
    border: 1px solid var(--ms-border);
    border-radius: var(--ms-radius);
    box-shadow: var(--ms-shadow);
}
.card { overflow: hidden; }
.card-header {
    background: var(--ms-surface);
    border-bottom: 1px solid var(--ms-border);
    padding: 16px 18px;
    font-weight: 800;
}
.card-body { padding: 18px; }

.metric-card { padding: 18px; height: 100%; }
.metric-card .metric-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 8px;
    background: var(--ms-primary-soft);
    color: var(--ms-primary);
    font-size: 18px;
    margin-bottom: 14px;
}
.metric-label { color: var(--ms-muted); font-weight: 700; font-size: 12px; text-transform: uppercase; }
.metric-value { font-size: 28px; font-weight: 800; line-height: 1.1; margin-top: 6px; }
.metric-note { color: var(--ms-muted); font-size: 12px; margin-top: 8px; }

.usage-row { margin-bottom: 16px; }
.usage-row:last-child { margin-bottom: 0; }
.usage-label { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; color: var(--ms-muted); font-weight: 700; }
.progress { height: 9px; background: #edf1f7; border-radius: 99px; overflow: hidden; }
.progress-bar { background: linear-gradient(90deg, var(--ms-primary), #7c3aed); }

.table-card { overflow: hidden; }
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--ms-border);
}

.bulk-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 18px;
    background: var(--ms-surface);
    border: 1px solid var(--ms-border);
    border-radius: var(--ms-radius);
}
.bulk-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.table { margin: 0; color: var(--ms-text); }
.table thead th {
    background: var(--ms-surface-soft);
    color: #475467;
    border-bottom: 1px solid var(--ms-border);
    font-size: 12px;
    text-transform: uppercase;
    font-weight: 800;
    padding: 12px 16px;
}
.table tbody td {
    padding: 13px 16px;
    border-color: var(--ms-border);
    vertical-align: middle;
}
.table tbody tr:hover { background: #fbfcff; }
.table-actions { text-align: right; white-space: nowrap; }

.badge {
    border-radius: 999px;
    padding: 6px 9px;
    font-weight: 800;
    font-size: 11px;
    text-transform: capitalize;
}
.status-badge { background: #eef2f7; color: #475467; }
.status-active,
.status-ready,
.status-sent,
.status-enabled,
.status-opened,
.status-clicked,
.status-completed { background: var(--ms-success-soft); color: var(--ms-success); }
.status-running,
.status-draft,
.status-queued { background: var(--ms-info-soft); color: var(--ms-info); }
.status-paused,
.status-skipped,
.status-suspicious,
.status-manual { background: var(--ms-warning-soft); color: var(--ms-warning); }
.status-failed,
.status-stopped,
.status-invalid,
.status-unsubscribed,
.status-bounced,
.status-complaint,
.status-disabled,
.status-inactive { background: var(--ms-danger-soft); color: var(--ms-danger); }

.btn { border-radius: 8px; font-weight: 800; font-size: 13px; padding: 9px 13px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-primary { background: var(--ms-primary); border-color: var(--ms-primary); }
.btn-primary:hover { background: var(--ms-primary-dark); border-color: var(--ms-primary-dark); }
.btn-outline-primary { color: var(--ms-primary); border-color: #c7d2fe; }
.btn-outline-primary:hover { background: var(--ms-primary); border-color: var(--ms-primary); }

.form-control,
.form-select {
    border-color: var(--ms-border-strong);
    border-radius: 8px;
    font-size: 14px;
    min-height: 42px;
}
.form-control:focus,
.form-select:focus {
    border-color: #a5b4fc;
    box-shadow: 0 0 0 .2rem rgba(79, 70, 229, .12);
}
.form-label,
label { color: #344054; font-weight: 700; margin-bottom: 7px; }
.form-help { color: var(--ms-muted); font-size: 12px; margin-top: 6px; }

.empty-state {
    text-align: center;
    padding: 46px 20px;
    color: var(--ms-muted);
}
.empty-state i { font-size: 34px; color: #98a2b3; display: block; margin-bottom: 12px; }
.empty-state h3 { font-size: 17px; color: var(--ms-text); font-weight: 800; margin-bottom: 6px; }

.onboarding-list { display: grid; gap: 10px; }
.onboarding-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px;
    border: 1px solid var(--ms-border);
    border-radius: 8px;
    background: var(--ms-surface-soft);
}
.onboarding-item strong { display: block; }
.onboarding-item span { color: var(--ms-muted); font-size: 13px; }

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(79,70,229,.16), transparent 32%),
        linear-gradient(135deg, #f8fafc 0%, #eef2ff 100%);
}
.auth-card {
    width: min(100%, 430px);
    background: #fff;
    border: 1px solid var(--ms-border);
    border-radius: 12px;
    box-shadow: 0 28px 80px rgba(15, 23, 42, .13);
    padding: 34px;
}
.auth-logo { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 22px; }
.auth-title { font-size: 26px; font-weight: 800; text-align: center; margin: 0; }
.auth-subtitle { color: var(--ms-muted); text-align: center; margin: 8px 0 24px; }
.auth-flashes { position: fixed; top: 16px; width: min(430px, calc(100% - 32px)); }

.email-preview-frame {
    background: #eef2f7;
    border: 1px solid var(--ms-border);
    border-radius: 12px;
    padding: 22px;
}
.email-preview-paper {
    max-width: 760px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid var(--ms-border);
    border-radius: 8px;
    box-shadow: 0 16px 42px rgba(15, 23, 42, .08);
    overflow: hidden;
}
.email-preview-subject { padding: 16px 20px; border-bottom: 1px solid var(--ms-border); font-weight: 800; }
.email-preview-body { padding: 24px; }

.metadata-cell { max-width: 360px; color: var(--ms-muted); font-size: 12px; word-break: break-word; }
.icon-button {
    border: 1px solid var(--ms-border);
    background: #fff;
    color: var(--ms-text);
    width: 40px;
    height: 40px;
    border-radius: 8px;
}

@media (max-width: 991.98px) {
    .app-sidebar { transform: translateX(-100%); }
    body.sidebar-open .app-sidebar { transform: translateX(0); }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 1030;
        background: rgba(15, 23, 42, .42);
    }
    body.sidebar-open .sidebar-backdrop { display: block; }
    .app-main { margin-left: 0; }
    .app-topbar { padding: 0 18px; height: 68px; }
    .content-wrap { padding: 22px 16px 30px; }
    .user-meta { display: none; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-actions { justify-content: flex-start; }
    .table-responsive { border: 0; }
}

@media (max-width: 575.98px) {
    .bulk-toolbar {
        flex-direction: column;
        align-items: stretch;
    .topbar-title h1 { font-size: 18px; }
    .topbar-kicker { display: none; }
    .auth-card { padding: 26px 20px; }
    .metric-value { font-size: 24px; }
    .table-toolbar { flex-direction: column; align-items: stretch; }
    .bulk-toolbar { flex-direction: column; align-items: stretch; }
    .btn { width: 100%; }
    .bulk-toolbar .btn { width: auto; }
    .page-actions .btn,
    .table-actions .btn,
    form.d-inline .btn { width: auto; }
}
