:root {
  --bg: #faf5f7;
  --surface: #ffffff;
  --surface-2: #f6eef2;
  --text: #2b2228;
  --muted: #7a6a73;
  --border: #eadce3;
  --accent: #b84b75;
  --accent-soft: #f7e3ec;
  --accent-text: #ffffff;
  --ok-bg: #e5f5ea;
  --ok-text: #1f6b3a;
  --err-bg: #fde8e8;
  --err-text: #9b1c1c;
  --warn-bg: #fff3d9;
  --warn-text: #7a4b00;
  --info-bg: #e7f0fd;
  --info-text: #1d4f91;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(60, 20, 40, .06), 0 2px 8px rgba(60, 20, 40, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #19151a;
    --surface: #241e24;
    --surface-2: #2d252d;
    --text: #f2e8ed;
    --muted: #b1a1aa;
    --border: #3b313a;
    --accent: #e48aad;
    --accent-soft: #4a2c3a;
    --accent-text: #1d181b;
    --ok-bg: #173a24;
    --ok-text: #a8e6bb;
    --err-bg: #4a1d1d;
    --err-text: #f7b4b4;
    --warn-bg: #463413;
    --warn-text: #f6d58f;
    --info-bg: #1b2f4a;
    --info-text: #a9c8f5;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Шапка --- */
header.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: center;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
header.top .brand { font-weight: 700; margin-right: 8px; white-space: nowrap; }
header.top nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
header.top nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--text); font-weight: 500;
}
header.top nav a:hover { background: var(--surface-2); text-decoration: none; }
header.top nav a.current { background: var(--accent-soft); color: var(--accent); }
header.top .who { color: var(--muted); font-size: .85rem; }
header.top form { margin: 0; }

main { max-width: 1240px; margin: 0 auto; padding: 22px 20px 60px; }
main.narrow { max-width: 460px; }
h1 { font-size: 1.45rem; margin: 0 0 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
h2 { font-size: 1.05rem; margin: 22px 0 10px; }
.card > h2:first-child, .card > .card-head:first-child h2 { margin-top: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 980px) {
  .grid { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
  .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
}
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.nowrap { white-space: nowrap; }
.right { margin-left: auto; }

/* --- Статистика --- */
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); margin-bottom: 18px; }
.stat {
  display: block; padding: 14px 16px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--border); color: var(--text); box-shadow: var(--shadow);
}
.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat .num { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.stat .label { color: var(--muted); font-size: .85rem; }
.stat.hot .num { color: var(--accent); }

/* --- Таблицы --- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.table-wrap { overflow-x: auto; padding: 4px 6px; }
.sub { display: block; color: var(--muted); font-size: .8rem; }
.ref { font-weight: 600; font-family: ui-monospace, Consolas, monospace; }

/* --- Формы и кнопки --- */
label { display: block; font-weight: 600; margin: 10px 0 4px; font-size: .9rem; }
input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--bg); color: var(--text); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
button, .button {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 15px; border: 1px solid var(--accent);
  border-radius: 9px; background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.button:hover { text-decoration: none; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.secondary, .button.secondary { background: transparent; color: var(--accent); }
button.danger { background: var(--err-text); border-color: var(--err-text); color: var(--surface); }
button.ghost { background: transparent; border-color: var(--border); color: var(--text); }
button.link { background: none; border: none; color: var(--accent); padding: 0; font-weight: 400; }
button.big { padding: 11px 22px; font-size: 1rem; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.inline-form select { width: auto; padding: 6px 8px; }

/* --- Сообщения и метки --- */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--err-bg); color: var(--err-text); }
.flash.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600;
  white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.badge.pending_review { background: var(--warn-bg); color: var(--warn-text); }
.badge.needs_info, .badge.approved, .badge.account_setup { background: var(--info-bg); color: var(--info-text); }
.badge.account_created, .badge.active { background: var(--ok-bg); color: var(--ok-text); }
.badge.provisioning_failed, .badge.rejected, .badge.blocked { background: var(--err-bg); color: var(--err-text); }
.badge.reply { background: var(--accent); color: var(--accent-text); }
.badge.mine { background: var(--accent-soft); color: var(--accent); }

/* --- Фильтры --- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips a {
  padding: 5px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); font-size: .88rem;
}
.chips a:hover { text-decoration: none; border-color: var(--accent); }
.chips a.current { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chips .count { opacity: .7; margin-left: 3px; }
.toolbar form { display: flex; gap: 8px; margin-left: auto; }
.toolbar form input { min-width: 240px; }
.toolbar form select { width: auto; }
.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin-top: 12px; }

/* --- Карточка заявки --- */
.app-head { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-bottom: 14px; }
.app-head h1 { margin: 0; }
.app-head .nav-links { margin-left: auto; display: flex; gap: 8px; }
.decision {
  border: 2px solid var(--accent-soft); background: var(--surface);
}
.decision .row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-start; }
.decision details { flex: 1; min-width: 260px; }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; overflow-wrap: anywhere; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.answer { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }

/* --- Переписка --- */
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 520px; overflow-y: auto; padding: 4px; }
.bubble { max-width: 88%; padding: 8px 12px; border-radius: 12px; }
.bubble.applicant { align-self: flex-start; background: var(--surface-2); border-bottom-left-radius: 4px; }
.bubble.moderator, .bubble.system { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.bubble .meta { font-size: .75rem; color: var(--muted); margin-bottom: 2px; }
.note { border-left: 3px solid var(--warn-text); padding: 4px 10px; margin: 8px 0; background: var(--warn-bg); border-radius: 0 8px 8px 0; color: var(--text); }
.timeline { list-style: none; margin: 0; padding: 0; font-size: .85rem; }
.timeline li { padding: 5px 0; border-bottom: 1px dashed var(--border); }
.timeline li:last-child { border-bottom: none; }
code.copy { display: block; padding: 10px; background: var(--bg); border-radius: 8px; overflow-wrap: anywhere; user-select: all; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

@media (max-width: 640px) {
  header.top { padding: 10px 16px; }
  main { padding: 16px 16px 48px; }
  .toolbar form { margin-left: 0; width: 100%; }
  .toolbar form input { min-width: 0; flex: 1; }
}

label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }
.login-big code { font-size: 1.6rem; font-weight: 700; padding: 6px 12px; background: var(--accent-soft); border-radius: 8px; }
[hidden] { display: none !important; }
