:root {
    --bg: #f6f8fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #64748b;
    --line: #dbe3ef;
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --green: #067647;
    --red: #b42318;
    --amber: #b54708;
    --soft-blue: #eff6ff;
    --soft-green: #ecfdf3;
    --soft-red: #fff1f0;
    --soft-amber: #fffaeb;
    --shadow: 0 10px 24px rgba(23, 32, 51, .06);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    min-height: 100%;
    color: var(--ink);
    background: var(--bg);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: linear-gradient(180deg, #ffffff 0%, #f1f5fb 100%);
}
.auth-card {
    width: min(440px, 100%);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
}
.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px 1fr;
}
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: #111827;
    color: #e5edf8;
    padding: 18px 14px;
    overflow-y: auto;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    padding: 0 8px 18px;
    color: #fff;
    font-weight: 800;
    letter-spacing: 0;
}
.brand img { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; background: #fff; }
.nav-group { margin: 12px 0; }
.nav-label { padding: 8px; color: #9fb0c8; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.nav-link {
    display: flex;
    align-items: center;
    min-height: 38px;
    padding: 9px 10px;
    border-radius: 7px;
    color: #dbeafe;
    font-weight: 700;
}
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.1); color: #fff; text-decoration: none; }
.main {
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 64px;
    padding: 12px 24px;
    background: rgba(255,255,255,.94);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(8px);
}
.topbar h1 { margin: 0; font-size: 20px; }
.top-actions { display: flex; align-items: center; gap: 12px; color: var(--muted); }
.mobile-menu { display: none; }
.content { padding: 24px; max-width: 1400px; width: 100%; }
.page-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-title h2 { margin: 0; font-size: 24px; }
.help-note {
    margin: 0 0 18px;
    padding: 12px 14px;
    border: 1px solid #c7ddff;
    border-radius: 8px;
    background: var(--soft-blue);
    color: #25436f;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: var(--shadow);
}
.stat { min-height: 104px; }
.stat span { color: var(--muted); font-weight: 700; }
.stat strong { display: block; margin-top: 12px; font-size: 28px; }
.section-title { margin: 26px 0 12px; font-size: 18px; }
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.table-wrap {
    width: 100%;
    overflow-x: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #475569; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; background: #f8fafc; }
tr:last-child td { border-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.email-subject { color: var(--ink); font-weight: 800; }
.unread .email-subject { color: #0f172a; }
.snippet { color: var(--muted); max-width: 520px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}
.badge-success { color: var(--green); background: var(--soft-green); border: 1px solid #abefc6; }
.badge-danger { color: var(--red); background: var(--soft-red); border: 1px solid #fecdca; }
.badge-warning { color: var(--amber); background: var(--soft-amber); border: 1px solid #fedf89; }
.badge-muted { color: #475569; background: #f1f5f9; border: 1px solid #dbe3ef; }
.badge-info { color: #1d4ed8; background: var(--soft-blue); border: 1px solid #c7ddff; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    padding: 9px 13px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: var(--blue);
    color: #fff;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
    font-size: 14px;
}
.btn:hover, button:hover { background: var(--blue-dark); text-decoration: none; }
.btn-secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: #f8fafc; color: var(--ink); }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #8f1b13; }
.btn-warning { background: var(--amber); }
.btn-warning:hover { background: #93370d; }
.btn-small { min-height: 32px; padding: 6px 10px; font-size: 13px; }
form.inline { display: inline-flex; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; margin: 0 0 7px; font-weight: 800; }
input, select, textarea {
    width: 100%;
    min-height: 40px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fff;
    color: var(--ink);
    font: inherit;
}
textarea { min-height: 140px; resize: vertical; }
.check-row { display: flex; align-items: center; gap: 10px; }
.check-row input { width: auto; min-height: auto; }
.flash-list { display: grid; gap: 10px; margin-bottom: 16px; }
.flash {
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
}
.flash-success { color: var(--green); background: var(--soft-green); border-color: #abefc6; }
.flash-danger { color: var(--red); background: var(--soft-red); border-color: #fecdca; }
.flash-warning { color: var(--amber); background: var(--soft-amber); border-color: #fedf89; }
.flash-info { color: #1d4ed8; background: var(--soft-blue); border-color: #c7ddff; }
.message-body {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: #fff;
    overflow-wrap: anywhere;
}
.pagination { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 14px; }
.empty {
    background: #fff;
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 24px;
    color: var(--muted);
    text-align: center;
}
.hidden { display: none !important; }
.smart-alert-stack {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 60;
    display: grid;
    gap: 12px;
    width: min(380px, calc(100vw - 36px));
}
.smart-alert {
    background: #fff;
    border: 1px solid var(--line);
    border-left: 4px solid var(--blue);
    border-radius: 8px;
    padding: 14px;
    box-shadow: 0 16px 34px rgba(23, 32, 51, .16);
}
.smart-alert-warning { border-left-color: var(--amber); }
.smart-alert-danger { border-left-color: var(--red); }
.smart-alert-success { border-left-color: var(--green); }
.smart-alert-title {
    margin: 0 0 7px;
    font-weight: 900;
}
.smart-alert-body {
    margin: 0 0 12px;
    color: var(--muted);
    white-space: pre-line;
}
.smart-alert-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.alert-test-actions {
    margin-top: 18px;
}

@media (max-width: 960px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform .18s ease;
        z-index: 20;
    }
    body.menu-open .sidebar { transform: translateX(0); }
    .mobile-menu { display: inline-flex; }
    .content { padding: 18px; }
    .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
    .page-title { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 620px) {
    .topbar { padding: 10px 14px; }
    .top-actions .muted { display: none; }
    .auth-card { padding: 22px; }
    .actions { width: 100%; }
    .btn, button { width: 100%; }
    form.inline { width: 100%; }
    .pagination { justify-content: stretch; flex-wrap: wrap; }
    .smart-alert-actions .btn,
    .smart-alert-actions button {
        width: auto;
    }
}
