:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #6b7385;
  --line: #e2e5ec;
  --accent: #7a3e1d;       /* табачно-коричневый */
  --accent-2: #a45a2a;
  --ok: #1f7a4d;
  --warn: #b7791f;
  --danger: #b42318;
  --official: #1d4ed8;
  --unofficial: #9a3412;
  --radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }
small { color: var(--muted); display: block; font-size: 11px; }

/* ---- вход ---- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.brand { font-weight: 800; font-size: 22px; letter-spacing: 2px; color: var(--accent); margin-bottom: 12px; }
.brand span { font-weight: 400; font-size: 12px; letter-spacing: 0; color: #d9c3b5; display: block; }

/* ---- оболочка ---- */
#shell { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: #2b1a10; color: #f3e9e2; padding: 18px 12px; flex-shrink: 0; }
.sidebar .brand { color: #f3e9e2; padding: 0 8px; }
#menu a { display: block; color: #e9d9cd; padding: 8px 10px; border-radius: 6px; margin-bottom: 2px; }
#menu a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
#menu a.active { background: var(--accent-2); color: #fff; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 20px;
  background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.page-title { font-size: 18px; font-weight: 600; }
.me { display: flex; align-items: center; gap: 12px; color: var(--muted); flex-wrap: wrap; }
.view { padding: 20px; }

/* ---- элементы ---- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.narrow { max-width: 420px; }
label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
label input, label select, label textarea { display: block; width: 100%; margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 6px; color: var(--text); }
label.check input { width: auto; margin: 0; display: inline; }
input, select, textarea { font: inherit; padding: 7px 9px; border: 1px solid #cdd2dc; border-radius: 6px; background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid #e6c8b3; border-color: var(--accent-2); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.btn { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid #cdd2dc; background: #fff; cursor: pointer; color: var(--text); white-space: nowrap; }
.btn:hover { background: #f1f2f5; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); border-color: #f0c4bf; }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.link { color: var(--accent); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .search { min-width: 260px; }
.hint { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }
.form-error { color: var(--danger); min-height: 18px; margin: 6px 0; white-space: pre-wrap; }
.empty { padding: 30px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); }
.loading { color: var(--muted); padding: 20px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.actions-left { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 4px 0; }
dl.props { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; background: #eef0f4; font-size: 12px; margin: 1px 4px 1px 0; white-space: nowrap; }
.badge.ok { background: #e3f4ea; color: var(--ok); }
.badge.warn { background: #fdf3dc; color: var(--warn); }
.badge.danger { background: #fde8e6; color: var(--danger); }
.badge.muted { background: #eef0f4; color: var(--muted); }
.badge.official { background: #e0e9ff; color: var(--official); font-weight: 600; }
.badge.unofficial { background: #ffedd5; color: var(--unofficial); font-weight: 600; }

/* ---- таблицы ---- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 16px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: #fafbfc; font-weight: 600; font-size: 12px; color: var(--muted); white-space: nowrap; }
tbody tr:hover { background: #fcfaf8; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.matrix th.role-col, .matrix td.role-col { text-align: center; min-width: 72px; white-space: normal; }
.matrix .perm-col { min-width: 240px; }
.matrix tr.group-row td { background: #f6efe9; font-weight: 600; color: var(--accent); }
.matrix tr.save-row td { background: #fafbfc; }
.city-title { margin: 18px 0 8px; font-size: 15px; font-weight: 600; }
.qty-neg { color: var(--danger); }
.qty-pos { color: var(--ok); }

/* ---- модалка/тост ---- */
.overlay { position: fixed; inset: 0; background: rgba(20, 14, 10, .45); display: flex; align-items: flex-start; justify-content: center;
  padding: 60px 16px; overflow-y: auto; z-index: 50; }
.modal { width: 100%; max-width: 520px; }
.modal.wide { max-width: 760px; }
.field { margin-bottom: 12px; }
.field-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.toast { position: fixed; right: 20px; bottom: 20px; padding: 10px 16px; border-radius: 8px; background: #1d2330; color: #fff; z-index: 100; max-width: 420px; }
.toast.error { background: var(--danger); }
.lines-editor .line { display: flex; gap: 6px; margin-bottom: 6px; }
.lines-editor .line select { flex: 1; min-width: 0; }
.lines-editor .line input { width: 90px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; }
.join-card { max-width: 440px; }

@media (max-width: 760px) {
  #shell { flex-direction: column; }
  .sidebar { width: 100%; }
  #menu { display: flex; flex-wrap: wrap; gap: 4px; }
  dl.props { grid-template-columns: 1fr; }
}
