:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1b1f24;
  --muted: #5f6b7a;
  --accent: #2f5bea;
  --accent-hover: #2349c9;
  --accent-soft: #e8eefe;
  --danger: #c62f3a;
  --danger-soft: #fdecee;
  --ok: #1f8a4c;
  --ok-soft: #e5f5ec;
  --warn: #9a6400;
  --warn-soft: #fff4dd;
  --radius: 8px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 18%);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #191d23;
    --surface-2: #20252c;
    --border: #2d333c;
    --text: #e6e9ed;
    --muted: #97a1ad;
    --accent: #6d8dff;
    --accent-hover: #86a0ff;
    --accent-soft: #1f2a4a;
    --danger: #ff6b76;
    --danger-soft: #3a1c20;
    --ok: #4cc98a;
    --ok-soft: #173326;
    --warn: #f0b64d;
    --warn-soft: #3a2d14;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 50%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
.boot { padding: 48px; color: var(--muted); text-align: center; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
p { margin: 0; }
a { color: var(--accent); }
code, .mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

/* ---------- Кнопки и поля ---------- */
button, .btn {
  font: inherit;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
}
button:hover { background: var(--surface-2); }
button:disabled { opacity: .55; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { background: var(--accent-hover); }
button.danger { color: var(--danger); }
button.danger:hover { background: var(--danger-soft); }
button.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.sm { min-height: 28px; padding: 0 10px; font-size: 13px; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

label.field { display: grid; gap: 6px; }
label.field > span { font-weight: 500; font-size: 13px; }
input, select {
  font: inherit;
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
input:focus, select:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox] { width: 16px; min-height: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.input-group { display: flex; }
.input-group input { flex: 1; min-width: 0; border-radius: var(--radius) 0 0 var(--radius); }
.input-group > * + * { border-radius: 0; border-left: 0; }
.input-group > :last-child:not(:first-child) { border-radius: 0 var(--radius) var(--radius) 0; }
.input-suffix {
  display: inline-flex; align-items: center; padding: 0 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  white-space: nowrap; max-width: 55%; overflow: hidden; text-overflow: ellipsis;
}
.hint { font-size: 12px; color: var(--muted); }
.form { display: grid; gap: 14px; }
.form-error { color: var(--danger); background: var(--danger-soft); padding: 8px 12px; border-radius: var(--radius); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* ---------- Каркас ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px;
  height: 56px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; }
.brand img { width: 26px; height: 26px; }
.nav { display: flex; gap: 4px; }
.nav a {
  padding: 6px 12px; border-radius: var(--radius);
  color: var(--muted); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.user-chip { display: flex; align-items: center; gap: 10px; color: var(--muted); }

main { max-width: 1280px; margin: 0 auto; padding: 24px 20px 48px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }

/* ---------- Почта ---------- */
.mail-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 16px; align-items: start; }
.domain-list { position: sticky; top: 72px; max-height: calc(100vh - 96px); display: flex; flex-direction: column; }
.domain-list .search { padding: 12px; border-bottom: 1px solid var(--border); }
.domain-list ul { list-style: none; margin: 0; padding: 6px; overflow: auto; }
.domain-list li button {
  width: 100%; justify-content: space-between; border: 0; background: transparent;
  text-align: left; padding: 0 10px; min-height: 34px;
}
.domain-list li button span:first-child { overflow: hidden; text-overflow: ellipsis; }
.domain-list li button.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.domain-list .empty { padding: 16px; color: var(--muted); }

.toolbar { display: flex; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 280px; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, transparent); }
td.actions { text-align: right; white-space: nowrap; }
td.actions button + button { margin-left: 4px; }
.table-wrap { overflow-x: auto; }
.empty-state { padding: 40px 16px; text-align: center; color: var(--muted); }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; background: var(--surface-2); color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.accent { background: var(--accent-soft); color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

.progress { width: 90px; height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.progress > div { height: 100%; background: var(--accent); }

/* ---------- Авторизация ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .brand { justify-content: center; margin-bottom: 20px; font-size: 18px; }
.auth-card h1 { margin-bottom: 6px; }
.auth-card .lead { color: var(--muted); margin-bottom: 18px; }
.qr { display: grid; place-items: center; padding: 12px; background: #fff; border-radius: var(--radius); border: 1px solid var(--border); }
.qr img { width: 200px; height: 200px; }
.steps { display: flex; gap: 6px; margin-bottom: 16px; }
.steps span { flex: 1; height: 4px; border-radius: 4px; background: var(--surface-2); }
.steps span.done { background: var(--accent); }

/* ---------- Диалоги ---------- */
dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 0; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
dialog.wide { width: min(720px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(15 20 30 / 45%); }
.dialog-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.dialog-body { padding: 20px; display: grid; gap: 14px; max-height: calc(100vh - 200px); overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

.kv { display: grid; grid-template-columns: 150px 1fr; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.kv > div { padding: 8px 12px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; min-width: 0; }
.kv > div:nth-last-child(-n+2) { border-bottom: 0; }
.kv > div:nth-child(odd) { background: var(--surface-2); color: var(--muted); font-size: 13px; }
.kv .value { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; flex: 1; }
.section-title { font-weight: 600; margin-top: 4px; display: flex; align-items: center; gap: 8px; }

.secret-box {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--warn-soft); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent);
}
.secret-box .value { font-family: var(--mono); font-size: 15px; flex: 1; overflow-wrap: anywhere; }
.notice { padding: 10px 12px; border-radius: var(--radius); background: var(--accent-soft); color: var(--text); font-size: 13px; }
.notice.warn { background: var(--warn-soft); }

.check-list { border: 1px solid var(--border); border-radius: var(--radius); max-height: 260px; overflow: auto; }
.check-list label { display: flex; align-items: center; gap: 10px; padding: 7px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.check-list label:last-child { border-bottom: 0; }
.check-list label:hover { background: var(--surface-2); }

/* ---------- Уведомления ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 100; }
.toast {
  min-width: 240px; max-width: 420px; padding: 10px 14px;
  border-radius: var(--radius); background: var(--text); color: var(--bg);
  box-shadow: var(--shadow-lg); animation: toast-in .18s ease-out;
}
.toast.error { background: var(--danger); color: #fff; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  .mail-layout { grid-template-columns: minmax(0, 1fr); }
  .domain-list { position: static; max-height: 280px; }
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .nav { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 16px; }
  th, td { padding: 8px 10px; }
  .kv { grid-template-columns: 1fr; }
  .kv > div:nth-child(odd) { border-bottom: 0; padding-bottom: 0; background: transparent; }
}
