/* ---------- темы ---------- */
:root, :root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f5f7; --card: #ffffff; --card-2: #fafbfc; --hover: #f5f6ff;
  --text: #1d2330; --muted: #6b7385; --line: #e3e6eb; --input-bg: #ffffff; --input-line: #d3d7df;
  --top-bg: #1d2330; --top-text: #c9cede; --top-hover: #2d3446; --top-on: #3b4358; --top-muted: #9aa2b6;
  --accent: #4f46e5; --accent-hover: #4338ca; --accent-soft: #eef0ff; --on-accent: #ffffff;
  --red: #d93a3a; --red-soft: #fde8e8; --red-text: #8b1d1d;
  --amber: #b7791f; --amber-soft: #fff4dc; --amber-line: #e5b45c;
  --green: #1f8a4c; --green-soft: #e3f6ea;
  --blue: #2563eb; --blue-soft: #e6efff;
  --grey-soft: #eceef2; --grey-text: #555d70;
  --plan: #f3f0ff; --work: #f0f7ff; --stats: #f2faf4;
  --ban-bg: #2b2b2b; --ban-text: #ffffff; --ban-input: #3a3a3a; --ban-line: #555555;
  --problem-bg: #ffd9d9;
  --warn-card-bg: #fffdf7; --warn-card-line: #f2d49b;
  --shadow: 0 6px 20px rgba(0, 0, 0, .18);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1218; --card: #171b23; --card-2: #1c212b; --hover: #1f2531;
  --text: #e4e7ee; --muted: #8f97a9; --line: #2a303c; --input-bg: #11151c; --input-line: #343b49;
  --top-bg: #0a0c10; --top-text: #aeb5c6; --top-hover: #1c212b; --top-on: #262c38; --top-muted: #7d8598;
  --accent: #8b8cf8; --accent-hover: #a5a6fb; --accent-soft: #262a4d; --on-accent: #0f1218;
  --red: #f06a6a; --red-soft: #3a1d20; --red-text: #ffb3b3;
  --amber: #e8b25a; --amber-soft: #3a2e14; --amber-line: #8a6a2c;
  --green: #4cc584; --green-soft: #15301f;
  --blue: #6ea2ff; --blue-soft: #18264a;
  --grey-soft: #252b36; --grey-text: #aab1c1;
  --plan: #1d1a2e; --work: #16202e; --stats: #15231b;
  --ban-bg: #000000; --ban-text: #e9e9e9; --ban-input: #161616; --ban-line: #333333;
  --problem-bg: #4a1f24;
  --warn-card-bg: #1f1b12; --warn-card-line: #5a4721;
  --shadow: 0 6px 20px rgba(0, 0, 0, .5);
}

/* ---------- база ---------- */
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-line; }
.text-red { color: var(--red); }
.faded { opacity: .55; }

/* ---------- шапка ---------- */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 20px; padding: 0 20px; height: 54px; background: var(--top-bg); color: #fff; border-bottom: 1px solid var(--line); }
.top .brand { color: #fff; font-weight: 700; font-size: 16px; white-space: nowrap; }
.top nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.top nav a { color: var(--top-text); padding: 7px 12px; border-radius: 8px; white-space: nowrap; }
.top nav a:hover { background: var(--top-hover); color: #fff; text-decoration: none; }
.top nav a.on { background: var(--top-on); color: #fff; }
.top .me { display: flex; align-items: center; gap: 12px; white-space: nowrap; font-size: 13px; }
.top .me .muted { color: var(--top-muted); }
button.link { background: none; border: 0; color: var(--top-text); cursor: pointer; font: inherit; padding: 0; }
button.link:hover { color: #fff; text-decoration: underline; }

.theme-toggle { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--top-on); background: transparent; color: var(--top-text); cursor: pointer; font-size: 16px; line-height: 1; display: inline-grid; place-items: center; }
.theme-toggle:hover { background: var(--top-hover); color: #fff; }
.login .theme-toggle { border-color: var(--line); color: var(--muted); }
.login .theme-toggle:hover { background: var(--hover); color: var(--text); }
:root[data-theme="dark"] .theme-toggle .i-moon, :root:not([data-theme="dark"]) .theme-toggle .i-sun { display: none; }

main { max-width: 1200px; margin: 0 auto; padding: 22px 20px 60px; }
main.wide { max-width: none; }
main.center { min-height: 100vh; display: grid; place-items: center; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; margin-bottom: 18px; }
.warn-card { border-color: var(--warn-card-line); background: var(--warn-card-bg); }
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.bar h1 { margin: 0; }
.daynav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.daynav h1 { margin: 0 0 0 8px; text-transform: capitalize; }
.stats-line { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 0 0 14px; color: var(--muted); }
.stats-line b { color: var(--text); }
.empty { color: var(--muted); padding: 20px; text-align: center; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 860px) {
  .cols, .grid3 { grid-template-columns: 1fr; }
  .top { gap: 10px; padding: 0 10px; }
  .top .me > span { display: none; }
  main { padding: 16px 16px 48px; }
}

/* ---------- кнопки и поля ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--text); font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--hover); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--accent); }
.btn.danger { color: var(--red); border-color: var(--red-soft); background: transparent; }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.wide { width: 100%; }
input, select, textarea { font: inherit; color: var(--text); border: 1px solid var(--input-line); border-radius: 7px; padding: 6px 8px; background: var(--input-bg); max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled { background: transparent; border-color: transparent; color: var(--text); -webkit-text-fill-color: var(--text); opacity: 1; }
select:disabled { appearance: none; }
textarea { resize: vertical; }
input[type=checkbox] { accent-color: var(--accent); }
.w-num { width: 80px; }
.w-sm { width: 78px; }
.w-xs { width: 58px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters.inline, form.inline { margin: 0; display: inline-flex; }
.row-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin-top: 10px; }
.row-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
label.check { display: inline-flex; align-items: center; gap: 6px; }
.checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card-2); max-height: 340px; overflow-y: auto; margin-bottom: 14px; }
.link-box { background: var(--accent-soft); border-radius: 8px; padding: 12px 14px 2px; margin-bottom: 16px; }
.link-box .field { margin-bottom: 8px; }
.link-status { min-height: 18px; margin: -2px 0 10px; }
.link-status.ok { color: var(--green); font-weight: 600; }
.chip { display: inline-block; padding: 1px 8px; margin: 0 4px 4px 0; border-radius: 6px; background: var(--grey-soft); color: var(--text); font-size: 12px; }

/* ---------- формы ---------- */
.form .field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.form .field > span { font-weight: 600; font-size: 13px; }
.form .field input:not([type=checkbox]), .form .field select, .form .field textarea { width: 100%; }
.form .field.check { flex-direction: row; align-items: center; gap: 8px; }
.form .field.has-err input, .form .field.has-err select { border-color: var(--red); }
.form h2 { margin-top: 8px; }
.form.narrow { max-width: 560px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.err { color: var(--red); font-size: 12px; }
.role-help { background: var(--card-2); border-radius: 8px; padding: 10px 12px; margin: 4px 0 14px; }

.login { width: min(380px, 92vw); }
.login .bar { margin-bottom: 4px; }
.login label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; font-weight: 600; }
.login input { width: 100%; height: 40px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--blue-soft); color: var(--text); }
.flash.success { background: var(--green-soft); }
.flash.error { background: var(--red-soft); color: var(--red-text); }

/* ---------- таблицы ---------- */
.scroll { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
table { border-collapse: collapse; width: 100%; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--card-2); }
.grid tbody tr:hover { background: var(--hover); }
.grid.num td, .grid.num th { text-align: right; }
.grid.num td.txt, .grid.num th:first-child { text-align: left; }
.grid tfoot td { font-weight: 700; border-top: 2px solid var(--line); }
.grid.edit td { padding: 6px; }
.grid.edit input:not([type=checkbox]), .grid.edit select { width: 100%; min-width: 70px; }

.sheet { font-size: 13px; }
.sheet th { position: sticky; top: 0; background: var(--card-2); font-size: 11px; color: var(--muted); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.sheet tr.groups th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-bottom: 0; }
.sheet td { padding: 4px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.sheet .g-plan { background: var(--plan); }
.sheet .g-work { background: var(--work); }
.sheet .g-stats { background: var(--stats); }
.sheet td.acc { min-width: 120px; padding-left: 8px; }
.sheet textarea { width: 170px; min-height: 32px; }
.sheet select { max-width: 170px; }
.sheet td.pay { font-weight: 600; white-space: nowrap; padding: 0 8px; }
.sheet td.need { background: var(--amber-soft); }
.sheet td.need input, .sheet td.need select { border-color: var(--amber-line); }
.sheet tr.saving { opacity: .6; }
.sheet tr.saved td.acc { box-shadow: inset 3px 0 0 var(--green); }
.sheet tr.failed td.acc { box-shadow: inset 3px 0 0 var(--red); }
.sheet input.bad, .sheet select.bad { border-color: var(--red); background: var(--red-soft); }

tr.row-ban td, tr.row-ban td.g-plan, tr.row-ban td.g-work, tr.row-ban td.g-stats { background: var(--ban-bg) !important; color: var(--ban-text); }
tr.row-ban a { color: #c7d2ff; }
tr.row-ban input, tr.row-ban select, tr.row-ban textarea { background: var(--ban-input); color: var(--ban-text); -webkit-text-fill-color: var(--ban-text); border-color: var(--ban-line); }
tr.row-ban .muted { color: #b5b5b5; }
tr.row-problem td, tr.row-problem td.g-plan, tr.row-problem td.g-work, tr.row-problem td.g-stats { background: var(--problem-bg) !important; }
tr.row-signal td.acc { box-shadow: inset 4px 0 0 var(--red); }

/* ---------- метки ---------- */
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; line-height: 18px; }
.pill.red { background: var(--red); color: #fff; }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.blue { background: var(--blue-soft); color: var(--blue); }
.pill.grey { background: var(--grey-soft); color: var(--grey-text); }
.st { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--grey-soft); }
.st-warming { background: var(--amber-soft); color: var(--amber); }
.st-active { background: var(--green-soft); color: var(--green); }
.st-paused { background: var(--grey-soft); color: var(--grey-text); }
.st-problem { background: var(--red-soft); color: var(--red); }
.st-banned { background: var(--ban-bg); color: var(--ban-text); }
.st-archived { background: var(--grey-soft); color: var(--muted); }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.tabs > a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs > a.on { color: var(--text); border-color: var(--accent); font-weight: 600; }
.tabs > a:hover { text-decoration: none; color: var(--text); }
.tabs form { margin-left: auto; padding-bottom: 6px; gap: 10px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; margin-bottom: 18px; }
.kpis > div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.kpis span { display: block; font-size: 12px; color: var(--muted); }
.kpis b { font-size: 20px; }

dl.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 12px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; word-break: break-all; }
.secret { cursor: pointer; border-bottom: 1px dashed var(--muted); }
.secret.shown { font-family: ui-monospace, Consolas, monospace; }
ul.plain { margin: 0; padding-left: 18px; }

.toast { position: fixed; right: 18px; bottom: 18px; background: var(--top-bg); color: #fff; padding: 10px 14px; border-radius: 8px; z-index: 50; max-width: 360px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.toast.error { background: var(--red); border-color: var(--red); }
