:root {
    --bg: #f5f7fa;
    --sidebar: #17202c;
    --sidebar-text: #d9e2ef;
    --panel: #fff;
    --line: #d8dee8;
    --text: #202733;
    --muted: #647184;
    --primary: #176b87;
    --primary-dark: #0f5268;
    --danger: #b42318;
    --ok: #067647;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
a { color: inherit; }
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 24px; }
.app { min-height: 100vh; display: grid; grid-template-columns: 252px minmax(0, 1fr); }
.sidebar { background: var(--sidebar); color: var(--sidebar-text); padding: 20px 16px; display: flex; flex-direction: column; gap: 18px; }
.brand { color: #fff; font-size: 18px; font-weight: 700; padding: 4px 8px 14px; border-bottom: 1px solid rgba(255, 255, 255, .12); }
.nav { display: grid; gap: 6px; }
.nav a { border-radius: 6px; color: var(--sidebar-text); display: block; padding: 10px 12px; text-decoration: none; }
.nav a.active, .nav a:hover { background: rgba(255, 255, 255, .11); color: #fff; }
.sidebar-footer { margin-top: auto; font-size: 13px; color: #9dadc2; padding: 10px 8px 0; }
.content { padding: 24px; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
h1 { margin: 0; font-size: 22px; }
h2 { margin: 0 0 14px; font-size: 17px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.stat strong { display: block; font-size: 24px; }
.stat span, .hint { color: var(--muted); font-size: 13px; }
label { display: block; font-weight: 650; margin: 0 0 6px; }
input, textarea, select { width: 100%; border: 1px solid #c8d0dc; border-radius: 6px; color: var(--text); background: #fff; padding: 10px 12px; font: inherit; }
textarea { min-height: 180px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace; }
.field { margin-bottom: 14px; }
.span { grid-column: 1 / -1; }
.editor { background: #fff; }
.editor .ql-toolbar { border-color: #c8d0dc; border-radius: 6px 6px 0 0; }
.editor .ql-container { border-color: #c8d0dc; border-radius: 0 0 6px 6px; font: inherit; min-height: 240px; }
.editor .ql-editor { min-height: 240px; }
button, .button { display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 6px; background: var(--primary); color: #fff; padding: 10px 16px; font: inherit; font-weight: 650; cursor: pointer; text-decoration: none; }
button:hover, .button:hover { background: var(--primary-dark); }
.alert { border-radius: 6px; padding: 12px 14px; margin-bottom: 16px; border: 1px solid; }
.alert.ok { color: var(--ok); background: #ecfdf3; border-color: #abefc6; }
.alert.err { color: var(--danger); background: #fef3f2; border-color: #fecdca; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); padding: 10px 8px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-weight: 650; }
.badge { display: inline-flex; border-radius: 999px; padding: 3px 8px; font-size: 12px; background: #edf2f7; }
.success { color: var(--ok); }
.error { color: var(--danger); }

.nav-logout-form { margin: 0; }
.nav-logout-button,
.nav-logout-button:hover {
    width: 100%;
    justify-content: flex-start;
    background: transparent;
    color: inherit;
    padding: 10px 12px;
}
.mt-6 { margin-top: 6px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.inline-form { display: inline; }
.inline-reset-form { display: inline-flex; gap: 6px; margin-top: 6px; }
.email-preview-frame { width: 100%; min-height: 360px; border: 1px solid var(--line); border-radius: 6px; margin-top: 16px; background: #fff; }
.prewrap-panel { margin-top: 16px; white-space: pre-wrap; }
.unread-row { font-weight: 700; }

@media (max-width: 900px) {
    .app { grid-template-columns: 1fr; }
    .cards, .grid { grid-template-columns: 1fr; }
    .content { padding: 16px; }
}
