:root {
    --bg: #0a0d12;
    --surface: #11161e;
    --surface-2: #171e28;
    --border: #26303d;
    --text: #f3f6f9;
    --muted: #8d9aaa;
    --accent: #5ee0a0;
    --accent-strong: #22b978;
    --danger: #ff6b7a;
    --sidebar: 248px;
    color-scheme: dark;
    font-family: Inter, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { min-height: 100vh; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: #98f3c6; }
button, input, select, textarea { font: inherit; }

.app-shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; }
.admin-shell { --accent: #5ee0a0; --accent-strong: #22b978; --workspace-tint: rgba(45, 194, 126, .08); }
.mail-shell { --accent: #72b7ff; --accent-strong: #398fdc; --workspace-tint: rgba(56, 137, 214, .1); }
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar); padding: 28px 18px; background: linear-gradient(180deg, var(--workspace-tint, transparent), #0d1117 180px); border-right: 1px solid var(--border); overflow-y: auto; }
.main-content { grid-column: 2; min-width: 0; }
.topbar { height: 72px; padding: 0 38px; display: flex; align-items: center; justify-content: flex-end; gap: 18px; border-bottom: 1px solid var(--border); background: rgba(10, 13, 18, .86); backdrop-filter: blur(14px); position: sticky; top: 0; z-index: 10; }
.admin-shell .topbar { box-shadow: inset 0 -2px rgba(94, 224, 160, .12); }
.mail-shell .topbar { box-shadow: inset 0 -2px rgba(114, 183, 255, .16); }
.mail-shell .main-content { background: radial-gradient(circle at 85% 0, rgba(45, 112, 180, .08), transparent 35%); }
.content { max-width: 1440px; margin: 0 auto; padding: 46px 42px 80px; }

.brand { display: flex; align-items: center; gap: 12px; margin: 0 8px 38px; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; color: #06140e; font-weight: 900; background: linear-gradient(145deg, #8ff4c5, #2bc582); box-shadow: 0 0 34px rgba(60, 220, 145, .18); }
.mail-shell .brand-mark { color: #07111c; background: linear-gradient(145deg, #9ed2ff, #448fd8); box-shadow: 0 0 34px rgba(67, 145, 220, .2); }
.brand strong, .brand small { display: block; }
.brand strong { letter-spacing: -.02em; font-size: 1.05rem; }
.brand small { margin-top: 2px; color: var(--muted); font-size: .72rem; }
.nav-menu h2 { margin: 26px 12px 8px; color: #5f6d7d; font-size: .67rem; letter-spacing: .16em; text-transform: uppercase; }
.nav-menu a { display: block; padding: 10px 12px; border-radius: 8px; color: #aab4c0; font-size: .91rem; transition: .16s ease; }
.nav-menu a:hover { background: #151c25; color: #fff; }
.nav-menu a.active { background: rgba(62, 213, 145, .1); color: var(--accent); box-shadow: inset 2px 0 var(--accent); }

.server-indicator { margin-right: auto; color: var(--muted); font-size: .82rem; }
.workspace-indicator { margin-right: auto; color: var(--accent); font-size: .72rem; font-weight: 750; letter-spacing: .12em; text-transform: uppercase; }
.server-indicator i, .status-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 10px rgba(94, 224, 160, .8); }
.account-name { color: var(--muted); font-size: .85rem; }
.topbar form { margin: 0; }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.eyebrow { color: var(--accent); font-size: .72rem; font-weight: 700; letter-spacing: .16em; text-transform: uppercase; }
h1 { margin: 5px 0 7px; font-size: clamp(2rem, 4vw, 3.15rem); line-height: 1; letter-spacing: -.055em; }
h1[tabindex="-1"]:focus { outline: none; }
h2 { margin: 0 0 20px; font-size: 1.05rem; letter-spacing: -.02em; }
.page-heading p, .panel p { color: var(--muted); }
.page-heading p { margin: 0; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.metric-grid.compact { grid-template-columns: repeat(2, minmax(0, 280px)); }
.metric-card, .panel { background: linear-gradient(155deg, var(--surface-2), var(--surface)); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 14px 50px rgba(0, 0, 0, .15); }
.metric-card { min-height: 134px; padding: 23px; display: flex; flex-direction: column; justify-content: space-between; }
.metric-card span { color: var(--muted); font-size: .83rem; }
.metric-card strong { font-size: 2.25rem; letter-spacing: -.05em; }
.action-card:hover { border-color: var(--accent-strong); transform: translateY(-2px); }
.action-card strong { color: var(--accent); font-size: 1.3rem; }
.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.panel { padding: 26px; margin-bottom: 20px; }
.stats-list, .status-list, .message-view dl, .dns-card dl { margin: 0; }
.stats-list div, .status-list div, .message-view dl div, .dns-card dl div { display: flex; justify-content: space-between; gap: 20px; padding: 13px 0; border-bottom: 1px solid var(--border); }
dl div:last-child { border: 0; }
dt { color: var(--muted); font-weight: 400; }
dd { margin: 0; }
.stats-list dd { font-weight: 700; }
.danger { color: var(--danger); }

.status-pill { display: inline-flex; align-items: center; width: max-content; padding: 5px 9px; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); font-size: .72rem; }
.status-ok { color: var(--accent); border-color: rgba(94, 224, 160, .25); background: rgba(94, 224, 160, .07); }
.status-failed { color: #ffb3bb; border-color: rgba(255, 107, 122, .28); background: rgba(255, 107, 122, .07); }
.status-muted { color: var(--muted); }
.button { display: inline-flex; align-items: center; justify-content: center; min-height: 36px; padding: 8px 13px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; color: var(--text); background: var(--surface-2); transition: .15s ease; }
.button:hover { border-color: #465468; color: #fff; }
.button-primary { color: #07150f; border-color: var(--accent); background: var(--accent); font-weight: 700; }
.button-primary:hover { color: #06110d; background: #7ceab3; }
.button-subtle { background: transparent; }
.button-danger { color: #ff9ca6; border-color: rgba(255, 107, 122, .24); background: rgba(255, 107, 122, .07); }
.button:disabled { opacity: .55; cursor: wait; }

.form-panel { max-width: 920px; }
.edit-panel { border-color: color-mix(in srgb, var(--accent) 38%, var(--border)); }
.account-panel { max-width: 680px; }
.page-alert { max-width: 920px; margin: 0 0 20px; }
.inline-form { display: flex; gap: 10px; }
.inline-form input { flex: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.stack-form { display: grid; gap: 17px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 12px; }
.section-heading h2 { margin: 5px 0 0; font-size: 1.45rem; }
.relay-panel { max-width: 920px; }
.relay-form { display: grid; gap: 17px; margin-top: 24px; }
.relay-credentials { margin: 0; }
.relay-test-mail { display: grid; gap: 14px; margin-top: 28px; padding-top: 24px; border-top: 1px solid var(--border); }
.relay-test-mail h2 { margin: 5px 0 0; }
.relay-test-mail p { margin: 0; }
.check-row { display: flex; align-items: center; gap: 10px; width: max-content; color: var(--text); font-size: .88rem; cursor: pointer; }
.check-row input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); }
.check-row:has(input:disabled) { cursor: default; opacity: .55; }
label { display: grid; gap: 7px; color: #b9c3cf; font-size: .79rem; font-weight: 600; }
input, select, textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 8px; outline: none; color: var(--text); background: #0d1219; }
input:focus, select:focus, textarea:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(43, 197, 130, .09); }
textarea { resize: vertical; line-height: 1.55; }

.table-panel { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 18px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: #778596; font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; }
td { color: #b6c0cb; font-size: .84rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(255, 255, 255, .016); }
tbody tr.selected-row { background: var(--workspace-tint, rgba(255, 255, 255, .03)); }
tr.unread td { color: #fff; font-weight: 650; }
.actions { display: flex; gap: 7px; justify-content: flex-end; }
.error-cell { max-width: 320px; color: #e997a0; }
code { color: #8ce5ba; }

.alert { margin-top: 16px; padding: 13px 15px; border: 1px solid #354153; border-radius: 8px; color: #abb7c4; background: #121923; }
.alert-error { color: #ffb3bb; border-color: rgba(255, 107, 122, .28); background: rgba(255, 107, 122, .07); }
.alert-success { color: #a8f5ce; border-color: rgba(94, 224, 160, .28); background: rgba(94, 224, 160, .07); }
.diagnostic-report { max-width: 920px; margin: 20px 0; padding: 20px; border: 1px solid var(--border); border-radius: 12px; background: rgba(17, 22, 30, .72); }
.diagnostic-report .section-heading { align-items: center; margin-bottom: 14px; }
.diagnostic-report h2 { margin: 0; }
.diagnostic-checks { display: grid; gap: 8px; }
.diagnostic-check { display: grid; grid-template-columns: 28px 1fr; gap: 10px; align-items: start; padding: 11px 12px; border-radius: 8px; background: rgba(255, 255, 255, .025); }
.diagnostic-check div { display: grid; gap: 3px; }
.diagnostic-check strong { font-size: .86rem; }
.diagnostic-check span { color: var(--muted); font-size: .8rem; line-height: 1.45; }
.diagnostic-icon { display: grid; place-items: center; width: 23px; height: 23px; border: 1px solid currentColor; border-radius: 50%; font-weight: 800; }
.diagnostic-passed .diagnostic-icon { color: var(--accent); }
.diagnostic-warning .diagnostic-icon { color: #f4c66d; }
.diagnostic-failed .diagnostic-icon { color: var(--danger); }
.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 50% 10%, #17261f 0, var(--bg) 42%); }
.login-card { width: min(440px, 100%); padding: 38px; border: 1px solid var(--border); border-radius: 18px; background: rgba(17, 22, 30, .95); box-shadow: 0 30px 100px rgba(0, 0, 0, .45); }
.login-brand { margin: 0 0 34px; }
.login-card h1 { font-size: 2.35rem; }
.login-card > p { margin: 0 0 26px; color: var(--muted); }
.setup-callout { display: grid; gap: 8px; margin: 0 0 22px; }
.setup-callout span { color: var(--muted); font-size: .86rem; }
.compose-panel { max-width: 920px; }
.message-view { max-width: 1000px; }
.message-view h1 { font-size: 2.2rem; }
.message-view dl { margin-top: 24px; }
.message-actions { display: flex; gap: 8px; margin: 20px 0; }
.message-body { padding: 25px 0; border-top: 1px solid var(--border); white-space: pre-wrap; font-family: inherit; line-height: 1.65; color: #dce3ea; }
.attachments { border-top: 1px solid var(--border); padding-top: 22px; }
.attachment { display: inline-flex; flex-direction: column; margin: 0 8px 8px 0; padding: 11px 14px; border: 1px solid var(--border); border-radius: 8px; }
.attachment small { margin-top: 3px; color: var(--muted); }
.dns-card { max-width: 1000px; }
.dns-card dd { text-align: right; max-width: 70%; }
.dkim-record { display: grid; gap: 9px; margin-top: 18px; padding: 16px; border: 1px solid rgba(94, 224, 160, .2); border-radius: 8px; background: rgba(94, 224, 160, .04); }
.dkim-record code { overflow-wrap: anywhere; }
.prose { max-width: 850px; line-height: 1.7; }
.empty-state { padding: 80px 20px; text-align: center; }
.empty-state.compact { padding: 45px 20px; }

#blazor-error-ui { display: none; position: fixed; inset: auto 0 0; padding: 12px 20px; z-index: 1000; color: #fff; background: #7a2630; }
#blazor-error-ui .dismiss { float: right; cursor: pointer; }

@media (max-width: 900px) {
    :root { --sidebar: 190px; }
    .content { padding: 32px 24px 60px; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .panel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 650px) {
    .app-shell { display: block; }
    .sidebar { position: static; width: 100%; padding: 18px; border-right: 0; border-bottom: 1px solid var(--border); }
    .brand { margin-bottom: 14px; }
    .nav-menu { display: flex; gap: 5px; overflow-x: auto; }
    .nav-menu h2 { display: none; }
    .nav-menu a { white-space: nowrap; }
    .main-content { width: 100%; }
    .topbar { height: 62px; padding: 0 18px; }
    .content { padding: 28px 16px 50px; }
    .page-heading { flex-direction: column; }
    .metric-grid, .metric-grid.compact, .form-grid { grid-template-columns: 1fr; }
    h1 { font-size: 2.15rem; }
}
