:root {
    color-scheme: light;
    --sidebar-width: 232px;
    --topbar-height: 60px;

    --bg-body: #f5f6f8;
    --bg-surface: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-subtle: #f8f9fb;
    --border: #e5e7eb;
    --border-strong: #d1d5db;

    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;

    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-subtle: #eff6ff;
    --accent-text: #1d4ed8;

    --danger: #dc2626;
    --danger-subtle: #fef2f2;
    --success: #16a34a;
    --success-subtle: #f0fdf4;
    --neutral-subtle: #f3f4f6;

    --radius-sm: 6px;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.04);
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

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

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

h1, h2, h3 { font-weight: 600; line-height: 1.25; margin-top: 0; color: var(--text-primary); }
h1 { font-size: 1.375rem; margin-bottom: 1.25rem; }
h2 { font-size: 1.05rem; margin-bottom: 0.75rem; }
h3 { font-size: 0.95rem; margin-bottom: 0.5rem; }

/* --- App shell: fixed sidebar + topbar, scrolling content --- */

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

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

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1.1rem 1.25rem;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
}

.sidebar-brand .mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
}

.sidebar-nav {
    padding: 0.75rem 0.75rem;
    flex: 1;
}

.sidebar-section-label {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.9rem 0.6rem 0.4rem;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-weight: 500;
    text-decoration: none;
    margin-bottom: 0.1rem;
}

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

.sidebar-nav a.active {
    background: var(--accent-subtle);
    color: var(--accent-text);
    font-weight: 600;
}

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

.topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 1.25rem;
    padding: 0 1.75rem;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

main.content {
    max-width: 1040px;
    width: 100%;
    margin: 0 auto;
    padding: 1.75rem;
}

/* --- Cards / surfaces --- */

.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
}

/* --- Tables --- */

table {
    border-collapse: collapse;
    width: 100%;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

table th, table td {
    text-align: left;
    padding: 0.65rem 0.9rem;
    border-bottom: 1px solid var(--border);
}

table th {
    background: var(--bg-subtle);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-secondary);
}

table tbody tr:last-child td { border-bottom: none; }
table tbody tr:hover { background: var(--bg-subtle); }

/* --- Forms --- */

label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
    margin-top: 0.9rem;
    color: var(--text-primary);
}

input[type=text], input[type=email], input[type=password], input[type=number], input[type=url],
input[type=file], select, textarea {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font);
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color 0.15s, box-shadow 0.15s;
}

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

textarea { min-height: 6rem; font-family: inherit; resize: vertical; }

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

/* --- Buttons --- */

button, .btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    line-height: 1.2;
    transition: background 0.15s, border-color 0.15s;
}

button:hover, .btn:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; text-decoration: none; }

button.secondary, .btn.secondary {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

button.secondary:hover, .btn.secondary:hover { background: var(--bg-subtle); color: var(--text-primary); border-color: var(--border-strong); }

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

button.danger:hover, .btn.danger:hover { background: var(--danger-subtle); color: var(--danger); border-color: var(--danger); }

/* --- Badges --- */

.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge.Sent, .badge.Completed, .badge.Success { background: var(--success-subtle); color: var(--success); }
.badge.Failed, .badge.Cancelled { background: var(--danger-subtle); color: var(--danger); }
.badge.Pending, .badge.Draft, .badge.Queued, .badge.Sending { background: var(--neutral-subtle); color: var(--text-secondary); }

/* --- Alerts / validation --- */

.validation-summary-errors ul { margin: 0; padding-left: 1.1rem; }
.validation-summary-errors, .text-danger { color: var(--danger); font-size: 0.85rem; }
.field-validation-error { color: var(--danger); font-size: 0.8rem; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.1rem;
    font-size: 0.88rem;
    border: 1px solid transparent;
}

.alert-success { background: var(--success-subtle); color: #14532d; border-color: #bbf7d0; }
.alert-error { background: var(--danger-subtle); color: #7f1d1d; border-color: #fecaca; }

.muted { color: var(--text-secondary); font-size: 0.85rem; }

/* --- Select2 overrides to match the theme --- */

.select2-container .select2-selection--single {
    height: 38px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    padding: 0 0.65rem;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    color: var(--text-primary);
    line-height: normal;
    padding: 0;
    font-size: 0.9rem;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
    right: 8px;
}

.select2-container--default.select2-container--focus .select2-selection--single,
.select2-container--default.select2-container--open .select2-selection--single {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.select2-dropdown {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
}

.select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: var(--accent);
}

.select2-search--dropdown .select2-search__field {
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.5rem;
}

.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: var(--text-muted);
}
