:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #e1e4ea;
  --text: #1b1f27;
  --muted: #667085;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --accent-soft: #e8efff;
  --ok: #138a4b;
  --ok-soft: #e3f6ec;
  --warn: #a15c00;
  --warn-soft: #fff3df;
  --bad: #c62f3d;
  --bad-soft: #fde8ea;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --panel: #171b23;
    --panel-2: #1e232d;
    --border: #2a303c;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --accent: #5b8cff;
    --accent-ink: #0b1020;
    --accent-soft: #1d2a4a;
    --ok: #3ccf83;
    --ok-soft: #12291d;
    --warn: #f0b04d;
    --warn-soft: #2e2412;
    --bad: #ff6b78;
    --bad-soft: #321619;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
.muted { color: var(--muted); }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 4px 10px 18px; }
.brand img { width: 26px; height: 26px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--text);
}
.nav a:hover { background: var(--panel-2); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .section { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
.sidebar .spacer { flex: 1; }
.sidebar .who { padding: 10px; border-top: 1px solid var(--border); font-size: 13px; }
.sidebar .who .name { font-weight: 600; word-break: break-all; }

.main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Cards */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
td.wrap { word-break: break-all; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* Badges */
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 8px; background: var(--bad); }
.dot.ok { background: var(--ok); }

/* Quota bar */
.quota { min-width: 140px; }
.quota .bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; margin-top: 4px; }
.quota .bar > span { display: block; height: 100%; background: var(--accent); }
.quota .bar > span.warn { background: var(--warn); }
.quota .bar > span.bad { background: var(--bad); }
.quota .txt { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Buttons & forms */
button, .btn {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 7px 14px;
  border: 1px solid var(--border); background: var(--panel); color: var(--text);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
button:hover, .btn:hover { background: var(--panel-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.primary:hover { filter: brightness(1.07); }
button.danger { color: var(--bad); }
button.small { padding: 3px 10px; font-size: 12.5px; }
button:disabled { opacity: .55; cursor: default; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { min-height: 84px; resize: vertical; font-family: var(--mono); font-size: 13px; }
input[type=checkbox] { width: auto; }
.toolbar input, .toolbar select { width: auto; min-width: 200px; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
label.field small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
label.check { display: flex; gap: 8px; align-items: center; margin-bottom: 14px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.inline { display: flex; align-items: center; gap: 6px; }
.inline input { flex: 1; }

/* Dialog */
dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 0; width: min(560px, 94vw);
  background: var(--panel); color: var(--text); box-shadow: 0 20px 50px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(10, 14, 22, .45); }
dialog header { padding: 18px 20px 0; font-weight: 650; font-size: 16px; }
dialog .body { padding: 18px 20px 4px; max-height: 70vh; overflow-y: auto; }
dialog footer { padding: 14px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
.error-box { background: var(--bad-soft); color: var(--bad); border-radius: 8px; padding: 8px 12px; margin-bottom: 14px; }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: min(380px, 100%); }
.login .brand { justify-content: center; padding-bottom: 6px; font-size: 20px; }
.login .host { text-align: center; color: var(--muted); margin-bottom: 22px; }
.login button.primary { width: 100%; justify-content: center; padding: 10px; }

/* DNS records */
.copy { display: flex; gap: 6px; align-items: flex-start; }
.copy code { flex: 1; word-break: break-all; background: var(--panel-2); padding: 4px 8px; border-radius: 6px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* Toasts */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 420px; }
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .brand { padding: 4px 10px; width: 100%; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav .section, .sidebar .spacer { display: none; }
  .sidebar .who { border: 0; width: 100%; display: flex; justify-content: space-between; align-items: center; }
  .main { padding: 18px 16px 50px; }
  .row { grid-template-columns: 1fr; }
}
button.primary.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
td.name { min-width: 240px; width: 32%; }
.qr { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.qr img { width: 180px; height: 180px; background: #fff; border-radius: 8px; }
.qr .secret { display: block; margin-top: 4px; word-break: break-all; }
pre.codes { font-family: var(--mono); background: var(--panel-2); padding: 12px 16px; border-radius: 8px; columns: 2; line-height: 1.9; }
input.otp { font-family: var(--mono); font-size: 20px; letter-spacing: .25em; text-align: center; }
.section-head { margin-top: 24px; margin-bottom: 12px; }

/* ---------- webmail ---------- */
.muted.pad { padding: 26px 32px; }
.main.full { padding: 0; height: 100vh; overflow: hidden; }
.mail { display: grid; grid-template-columns: 210px minmax(300px, 400px) 1fr; height: 100%; background: var(--panel); }
.mf { border-right: 1px solid var(--border); padding: 14px 10px; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; background: var(--bg); }
.mf-compose { justify-content: center; margin-bottom: 10px; padding: 9px; }
.mf-items { display: flex; flex-direction: column; gap: 2px; }
.mf-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; border: 0; background: none; padding: 7px 10px; border-radius: 8px; text-align: left; }
.mf-item:hover { background: var(--panel-2); }
.mf-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.mf-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mf-count { font-size: 12px; font-weight: 700; color: var(--accent); }
.mf-count.muted { color: var(--muted); font-weight: 500; }
.mf-new { margin: 8px 10px; align-self: flex-start; font-size: 13px; }
.ml { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.ml-head { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.ml-head input[type=checkbox] { margin: 0 2px; }
.ml-search { flex: 1; min-width: 0; padding: 6px 10px; }
.ml-meta, .ml-bulk { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 6px 12px; border-bottom: 1px solid var(--border); font-size: 12.5px; min-height: 38px; }
.ml-meta { justify-content: space-between; }
.ml-rows { flex: 1; overflow-y: auto; }
.ml-pager { display: flex; gap: 10px; justify-content: center; align-items: center; padding: 8px; border-top: 1px solid var(--border); }
.mrow { display: grid; grid-template-columns: auto auto 1fr; gap: 8px; align-items: start; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.mrow:hover { background: var(--panel-2); }
.mrow.active { background: var(--accent-soft); }
.mrow input { margin-top: 3px; }
.mrow-main { min-width: 0; }
.mrow-top { display: flex; justify-content: space-between; gap: 8px; }
.mrow-who, .mrow-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mrow-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.mrow-subject { color: var(--muted); font-size: 13px; }
.mrow.unread { box-shadow: inset 3px 0 0 var(--accent); }
.mrow.unread .mrow-who, .mrow.unread .mrow-subject { font-weight: 700; color: var(--text); }
button.star { border: 0; background: none; padding: 0 3px; color: var(--muted); font-size: 15px; line-height: 1.2; }
button.star:hover { background: none; color: #e8a317; }
button.star.on { color: #e8a317; }
.mv { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.mv-empty { margin: auto; }
.mv-toolbar { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--border); align-items: center; }
.mv-head { padding: 16px 20px 10px; }
.mv-subject { font-size: 19px; margin-bottom: 8px; overflow-wrap: anywhere; }
.mv-from { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.mv-date { margin-left: auto; font-size: 12.5px; }
.mv-people { font-size: 13px; overflow-wrap: anywhere; margin-top: 2px; }
.mv-banner { margin: 0 20px 10px; padding: 8px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.mv-atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 12px; }
.att { display: inline-flex; gap: 8px; align-items: center; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; font-size: 13px; color: var(--text); max-width: 100%; }
.att:hover { background: var(--panel-2); text-decoration: none; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.mv-frame { flex: 1; width: 100%; border: 0; border-top: 1px solid var(--border); background: #fff; min-height: 300px; }
.mv-text { flex: 1; overflow-y: auto; padding: 16px 20px; white-space: pre-wrap; overflow-wrap: anywhere; border-top: 1px solid var(--border); }
select.small-select { width: auto; padding: 3px 8px; font-size: 12.5px; }
.mobile-only { display: none; }
.thresholds .page-head { margin-bottom: 8px; align-items: flex-start; }

dialog.compose { width: min(860px, 96vw); }
.compose .body { display: flex; flex-direction: column; }
.crow { display: grid; grid-template-columns: 64px 1fr auto; gap: 8px; align-items: center; border-bottom: 1px solid var(--border); padding: 2px 0; }
.crow[hidden] { display: none; }
.crow > span { color: var(--muted); font-size: 13px; }
.crow input, .crow select { border: 0; border-radius: 0; padding: 8px 4px; background: transparent; }
.crow input:focus, .crow select:focus { outline: none; }
.compose-body { min-height: 300px; border: 0; border-radius: 0; margin-top: 8px; padding: 6px 4px; font-family: inherit; font-size: 14px; resize: vertical; }
.compose-body:focus { outline: none; }
.compose-atts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: inline-flex; gap: 4px; align-items: center; background: var(--panel-2); border-radius: 99px; padding: 3px 10px; font-size: 12.5px; }
.chip button { border: 0; background: none; padding: 0 2px 0 4px; }
.compose footer { justify-content: space-between; flex-wrap: wrap; }

@media (max-width: 1100px) {
  .mail { grid-template-columns: 180px minmax(260px, 340px) 1fr; }
}
@media (max-width: 860px) {
  .main.full { height: calc(100dvh - 112px); }
  .mail { grid-template-columns: 1fr; position: relative; }
  .mail .mv, .mail .mf { display: none; }
  .mail.reading .mv { display: flex; }
  .mail.reading .ml { display: none; }
  .mail.folders-open .mf { display: flex; position: absolute; inset: 0 25% 0 0; z-index: 5; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
  .mobile-only { display: inline-flex; }
  .crow { grid-template-columns: 52px 1fr auto; }
}
.card + h2 { margin-top: 22px; }
.settings-section { margin: 26px 0 12px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
