:root {
    --brand-50: #eef5ff;
    --brand-100: #d9e8ff;
    --brand-500: #1d6fd8;
    --brand-600: #1558b0;
    --brand-700: #0f447f;
    --ink: #142033;
    --muted: #6b7a90;
    --line: #e6ecf4;
    --surface: #f5f8fc;
    --panel: #ffffff;
    --shadow: 0 10px 30px rgba(20, 32, 51, 0.06);
    --radius: 14px;
    --sidebar-width: 270px;
    --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--surface);
}

a { text-decoration: none; }

.admin-shell {
    min-height: 100vh;
    display: flex;
    background:
        radial-gradient(circle at top right, rgba(29, 111, 216, 0.08), transparent 28%),
        linear-gradient(180deg, #f7faff 0%, #f3f6fb 100%);
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #0f2f57 0%, #123f73 55%, #1558b0 100%);
    color: #fff;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1040;
    display: flex;
    flex-direction: column;
    padding: 1.25rem 1rem;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    gap: .9rem;
    align-items: center;
    padding: .5rem .65rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,.12);
    margin-bottom: 1rem;
}

.brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,.14);
    color: #fff;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.brand-mark-lg {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    margin: 0 auto 1rem;
    background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
}

.brand-title {
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
}

.brand-tagline {
    font-size: .75rem;
    opacity: .72;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    overflow-y: auto;
    flex: 1;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: .8rem;
    color: rgba(255,255,255,.82);
    padding: .7rem .85rem;
    border-radius: 10px;
    font-size: .92rem;
    font-weight: 500;
    transition: background .15s ease, color .15s ease;
}

.sidebar-nav .nav-link i {
    font-size: 1.05rem;
    width: 1.2rem;
    text-align: center;
}

.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,.1);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: rgba(255,255,255,.18);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

.sidebar-footer {
    padding: .85rem;
    border-top: 1px solid rgba(255,255,255,.12);
    margin-top: 1rem;
}

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    z-index: 1035;
}

.main-panel {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.15rem 1.5rem;
    background: rgba(255,255,255,.82);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ink);
}

.page-subtitle {
    color: var(--muted);
    font-size: .84rem;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.btn-icon {
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 10px;
    display: grid;
    place-items: center;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .35rem .65rem .35rem .35rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #fff;
}

.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: var(--brand-100);
    color: var(--brand-700);
    display: grid;
    place-items: center;
    font-weight: 700;
}

.user-name {
    font-size: .85rem;
    font-weight: 600;
    line-height: 1.1;
}

.user-email {
    font-size: .72rem;
    color: var(--muted);
}

.content-area {
    padding: 1.35rem 1.5rem 2rem;
}

.stat-card,
.panel-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.15rem 1.2rem;
    height: 100%;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.bg-primary-soft { background: #e8f1ff; color: var(--brand-600); }
.bg-success-soft { background: #e8f8ef; color: #1f8a4c; }
.bg-warning-soft { background: #fff5e6; color: #c27803; }
.bg-info-soft { background: #e8f7fb; color: #0b7ea4; }

.stat-label {
    color: var(--muted);
    font-size: .82rem;
    margin-bottom: .15rem;
}

.stat-value {
    font-size: 1.55rem;
    font-weight: 700;
    line-height: 1;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.15rem 1.25rem;
    border-bottom: 1px solid var(--line);
}

.panel-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
}

.panel-subtitle {
    color: var(--muted);
    font-size: .82rem;
}

.admin-table {
    margin: 0;
}

.admin-table thead th {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    background: #f8fbff;
    border-bottom: 1px solid var(--line);
    padding: .85rem 1.15rem;
    white-space: nowrap;
}

.admin-table tbody td {
    padding: .95rem 1.15rem;
    border-bottom: 1px solid #eef2f7;
    font-size: .92rem;
}

.badge-soft-success,
.badge-soft-warning,
.badge-soft-info,
.badge-soft-secondary,
.badge-soft-primary,
.badge-soft-danger {
    font-weight: 600;
    border-radius: 999px;
    padding: .4em .7em;
    font-size: .75rem;
}

.badge-soft-success { background: #e7f7ee; color: #18794a; }
.badge-soft-warning { background: #fff4df; color: #9a6700; }
.badge-soft-info { background: #e7f5fb; color: #0b6e99; }
.badge-soft-secondary { background: #eef1f5; color: #526074; }
.badge-soft-primary { background: #e8f1ff; color: #1558b0; }
.badge-soft-danger { background: #fdeCEC; color: #b42318; }

.page-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    flex-wrap: wrap;
}

.section-heading {
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
}

.filter-bar .form-label {
    font-size: .78rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: .25rem;
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    background: var(--brand-100);
    color: var(--brand-700);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.profile-label {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    margin-bottom: .2rem;
}

.profile-value {
    font-size: .95rem;
    font-weight: 500;
    color: var(--ink);
}

.notes-box {
    background: #f8fbff;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: .85rem 1rem;
    white-space: pre-wrap;
}

.csv-headers {
    background: #f8fbff;
    border: 1px solid var(--line);
    font-size: .78rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.pagination .page-link {
    color: var(--brand-600);
    border-color: var(--line);
}

.pagination .page-item.active .page-link {
    background: var(--brand-500);
    border-color: var(--brand-500);
}

.activity-list {
    padding: .5rem .4rem 1rem;
}

.activity-item {
    display: flex;
    gap: .85rem;
    padding: .85rem 1rem;
}

.activity-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.tone-primary { background: #e8f1ff; color: var(--brand-600); }
.tone-success { background: #e8f8ef; color: #1f8a4c; }
.tone-info { background: #e8f7fb; color: #0b7ea4; }
.tone-warning { background: #fff5e6; color: #c27803; }

.activity-title {
    font-size: .9rem;
    font-weight: 600;
    margin-bottom: .15rem;
}

.activity-time {
    font-size: .78rem;
    color: var(--muted);
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--muted);
}

.empty-state.compact { padding: 2rem 1rem; }

.empty-state i {
    font-size: 2rem;
    color: var(--brand-500);
    margin-bottom: .75rem;
    display: block;
}

.empty-state h3 {
    font-size: 1.05rem;
    color: var(--ink);
    margin-bottom: .35rem;
}

.empty-state p { margin: 0; font-size: .9rem; }

.btn-primary {
    background: var(--brand-500);
    border-color: var(--brand-500);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--brand-600);
    border-color: var(--brand-600);
}

.btn-outline-primary {
    color: var(--brand-600);
    border-color: #b9d2f5;
}

.btn-outline-primary:hover {
    background: var(--brand-50);
    border-color: var(--brand-500);
    color: var(--brand-700);
}

/* Auth */
.auth-body {
    min-height: 100vh;
    background:
        radial-gradient(circle at top left, rgba(29,111,216,.18), transparent 32%),
        radial-gradient(circle at bottom right, rgba(15,68,127,.12), transparent 30%),
        linear-gradient(160deg, #f4f8ff 0%, #eaf1fb 45%, #f7f9fc 100%);
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-panel {
    width: 100%;
    max-width: 430px;
    background: rgba(255,255,255,.96);
    border: 1px solid rgba(214,225,240,.9);
    border-radius: 20px;
    box-shadow: 0 24px 60px rgba(20, 48, 92, 0.12);
    padding: 2rem 1.75rem;
}

.auth-brand { text-align: center; }

.auth-title {
    font-size: 1.45rem;
    font-weight: 750;
    margin-bottom: .35rem;
}

.auth-subtitle {
    color: var(--muted);
    font-size: .9rem;
    margin-bottom: 0;
}

.auth-form .form-label {
    font-weight: 600;
    font-size: .86rem;
}

.auth-form .form-control,
.auth-form .input-group-text {
    border-color: #d7e1ef;
    min-height: 46px;
}

.auth-form .form-control:focus {
    border-color: var(--brand-500);
    box-shadow: 0 0 0 .2rem rgba(29,111,216,.15);
}

.btn-login {
    min-height: 46px;
    font-weight: 600;
}

/* Template editor */
.editor-mode-tabs .nav-link {
    font-size: .82rem;
    padding: .35rem .75rem;
    color: var(--brand-600);
}

.editor-mode-tabs .nav-link.active {
    background: var(--brand-500);
    color: #fff;
}

.visual-editor,
.html-source-editor {
    min-height: 420px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.visual-editor {
    padding: 1rem;
    overflow: auto;
    outline: none;
}

.html-source-editor {
    font-family: Consolas, "Courier New", monospace;
    font-size: .82rem;
    line-height: 1.45;
}

.variables-grid {
    display: grid;
    gap: .65rem;
}

.variable-chip {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .55rem .7rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #f8fbff;
}

.variable-chip code {
    flex: 1;
    font-size: .82rem;
    color: var(--brand-700);
}

.sticky-preview {
    position: sticky;
    top: 88px;
}

.preview-chrome {
    background: linear-gradient(180deg, #f8fbff 0%, #fff 40%);
}

.email-meta {
    font-size: .88rem;
    color: var(--ink);
    padding: .75rem 1rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.meta-label {
    color: var(--muted);
    font-weight: 600;
    margin-right: .35rem;
}

.preview-frame-wrap {
    margin: 0 auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #eef2f7;
    padding: 12px;
    transition: max-width .2s ease;
}

.preview-frame-wrap.desktop {
    max-width: 680px;
}

.preview-frame-wrap.mobile {
    max-width: 375px;
}

.email-preview-frame {
    width: 100%;
    min-height: 520px;
    border: 0;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 24px rgba(20, 32, 51, .08);
}

.email-client-bar {
    display: flex;
    align-items: center;
}

.email-client-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #d0d7e2;
    margin-right: 6px;
}

@media (max-width: 1199.98px) {
    .sticky-preview {
        position: static;
    }
}

@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-105%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-backdrop.show {
        display: block;
    }

    .main-panel {
        margin-left: 0;
        width: 100%;
    }

    .content-area {
        padding: 1rem;
    }

    .topbar {
        padding: 1rem;
    }

    .visual-editor,
    .html-source-editor {
        min-height: 320px;
    }

    .email-preview-frame {
        min-height: 400px;
    }
}
