@font-face { font-family: "PT Sans"; src: url("fonts/PTSans-Regular.ttf"); font-weight: 400; font-display: swap; }
@font-face { font-family: "PT Sans"; src: url("fonts/PTSans-Bold.ttf"); font-weight: 700; font-display: swap; }
@font-face { font-family: "PT Mono"; src: url("fonts/PTMono-Regular.ttf"); font-display: swap; }
@font-face { font-family: "Russo One"; src: url("fonts/RussoOne-Regular.ttf"); font-display: swap; }

:root {
  --bg: #f4f0e6;
  --surface: #fffdf7;
  --surface-2: #f8f4ea;
  --ink: #1d1a16;
  --muted: #6f6656;
  --line: #e4dccb;
  --line-strong: #cfc4ad;
  --accent: #b3261e;
  --accent-ink: #ffffff;
  --accent-soft: #f6e3e0;
  --ok: #2f7a3a;
  --ok-soft: #e3f1e4;
  --warn: #a35f00;
  --warn-soft: #fbefd9;
  --err: #b3261e;
  --err-soft: #f9e2df;
  --blue: #1f4e99;
  --kraft: #d6c194;
  --shadow: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 16px rgba(40, 30, 10, .05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14120f;
    --surface: #1d1a16;
    --surface-2: #24201b;
    --ink: #ece6d8;
    --muted: #a59c89;
    --line: #322d26;
    --line-strong: #463f35;
    --accent: #e0574d;
    --accent-soft: #3a1f1c;
    --ok: #7cc485;
    --ok-soft: #1f2e21;
    --warn: #e2a24a;
    --warn-soft: #332715;
    --err: #ef7a70;
    --err-soft: #3a1f1c;
    --blue: #8cb2f0;
    --kraft: #8a7449;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14120f;
  --surface: #1d1a16;
  --surface-2: #24201b;
  --ink: #ece6d8;
  --muted: #a59c89;
  --line: #322d26;
  --line-strong: #463f35;
  --accent: #e0574d;
  --accent-soft: #3a1f1c;
  --ok: #7cc485;
  --ok-soft: #1f2e21;
  --warn: #e2a24a;
  --warn-soft: #332715;
  --err: #ef7a70;
  --err-soft: #3a1f1c;
  --blue: #8cb2f0;
  --kraft: #8a7449;
  --shadow: none;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 "PT Sans", system-ui, sans-serif; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 26px; }
h2 { font-size: 17px; margin-bottom: 12px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 18px 0 8px; }
h2.inline { display: inline; margin: 0; }
.mono, code, pre { font-family: "PT Mono", ui-monospace, monospace; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
.ok-text { color: var(--ok); } .warn-text { color: var(--warn); } .err-text { color: var(--err); }

/* ---------- шапка ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; padding: 0 20px; height: 56px;
  background: #1d1a16; color: #ece6d8; border-bottom: 3px solid var(--accent); }
.logo { display: flex; align-items: center; gap: 10px; color: #ece6d8; font: 17px "Russo One"; letter-spacing: .04em; white-space: nowrap; }
.logo:hover { text-decoration: none; }
.logo-mark { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 6px; background: #c9a96a; color: #b3261e; font-size: 17px; }
.nav { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; flex: 1; }
.nav::-webkit-scrollbar { display: none; }
.nav a { color: #c9c0ad; padding: 7px 11px; border-radius: 7px; white-space: nowrap; font-size: 14.5px; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav a.on { background: rgba(255,255,255,.12); color: #fff; }
.logout .link { background: none; border: none; color: #a59c89; cursor: pointer; font: inherit; font-size: 14px; }
.logout .link:hover { color: #fff; }

.page { max-width: 1180px; margin: 0 auto; padding: 24px 20px 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.eyebrow { font-size: 12px; letter-spacing: .18em; color: var(--accent); margin-bottom: 4px; }
.head-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 8px; font-size: 14px; }
.lead { margin: -6px 0 18px; max-width: 760px; }

/* ---------- карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card.flush { padding: 0; overflow: hidden; }
.card.narrow { max-width: 760px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin-bottom: 4px; }
.muted-card { background: var(--surface-2); color: var(--muted); box-shadow: none; }
.muted-card h2 { color: var(--ink); }
details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸"; color: var(--muted); margin-right: 8px; display: inline-block; transition: transform .15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.card[open] > summary { margin-bottom: 14px; }
.empty { padding: 28px 20px; text-align: center; color: var(--muted); }

.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; background: var(--ok-soft); color: var(--ok); border: 1px solid color-mix(in srgb, var(--ok) 25%, transparent); }
.flash.error { background: var(--err-soft); color: var(--err); border-color: color-mix(in srgb, var(--err) 25%, transparent); }

.checklist { border-left: 4px solid var(--warn); }
.check-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.check-row:first-of-type { border-top: none; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.stat-value { font: 26px "Russo One"; margin: 6px 0 2px; }
.stat-value.word { font-size: 19px; line-height: 1.3; }
.stat-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 400;
  padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); white-space: nowrap; }
.list td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.list tbody tr { cursor: pointer; }
.list tbody tr:hover td { background: var(--surface-2); }
.list tbody tr:last-child td { border-bottom: none; }
.list .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.list .num, .list th.num { text-align: right; white-space: nowrap; }
table.kv { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.kv th { text-align: left; font-weight: 400; color: var(--muted); width: 34%; padding: 6px 12px 6px 0; vertical-align: top; }
.kv td { padding: 6px 0; vertical-align: top; }
.kv tr + tr th, .kv tr + tr td { border-top: 1px dashed var(--line); }
.kv.compact th, .kv.compact td { padding: 4px 12px 4px 0; font-size: 13.5px; }
.prices { margin-top: 10px; max-width: 520px; }

/* ---------- бейджи ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.st-done, .ch-active { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.st-processing, .st-queued, .ch-pending, .lv-warning { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.st-error, .lv-error { background: var(--err-soft); color: var(--err); border-color: transparent; }
.prio { display: inline-flex; align-items: baseline; gap: 4px; font: 15px "Russo One"; padding: 1px 9px; border-radius: 6px; border: 1.5px solid currentColor; }
.prio small { font: 11px "PT Sans"; opacity: .8; }
.prio-A { color: var(--accent); } .prio-B { color: var(--warn); } .prio-C { color: var(--muted); }
.req, .opt { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.req { background: var(--accent-soft); color: var(--accent); }
.opt { background: var(--surface-2); color: var(--muted); }

/* ---------- кнопки ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 15px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 14.5px; cursor: pointer; text-decoration: none; white-space: nowrap; min-height: 38px; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); }
.btn.small { padding: 5px 11px; font-size: 13.5px; min-height: 32px; }
.btn.wide { width: 100%; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.actions.left { margin: 12px 0; }
td.actions { justify-content: flex-end; }
.row-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form select { flex: 1; min-width: 220px; }

/* ---------- формы ---------- */
.field { margin-bottom: 16px; }
.field > label:not(.switch) { display: block; font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.help { font-size: 13px; color: var(--muted); margin-top: 5px; }
input[type=text], input[type=url], input[type=search], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 15px; min-height: 40px; }
textarea { font-family: "PT Mono", monospace; font-size: 13.5px; line-height: 1.55; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px; border-color: var(--accent); }
.secret { display: flex; gap: 8px; }
.secret input { font-family: "PT Mono", monospace; }
.inline-check { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); margin-top: 6px; font-weight: 400; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.switch { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-weight: 700; font-size: 14px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line-strong); position: relative; transition: background .15s; margin-top: -1px; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.field-bool .help { margin-left: 48px; }
.sticky-save { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 35%); display: flex; justify-content: flex-end; }
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type=search] { flex: 1; min-width: 200px; }
.filters select { width: auto; }

/* ---------- ключи ---------- */
.key-state { font-size: 14px; color: var(--muted); }
.key-state .dot { margin-right: 6px; vertical-align: 1px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); } .dot.err { background: var(--err); }
.key-row { border-top: 1px solid var(--line); padding-top: 16px; margin-bottom: 8px; }
.key-row:first-of-type { border-top: none; padding-top: 0; }
.test { font-size: 13.5px; } .test.ok { color: var(--ok); } .test.err { color: var(--err); }
.howto { margin-top: 14px; font-size: 14px; color: var(--muted); }
.howto summary { cursor: pointer; color: var(--blue); }

/* ---------- досье ---------- */
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
.two-col > .card { margin-bottom: 16px; }
.pdf-card { display: flex; flex-direction: column; }
.pdf-card iframe { flex: 1; width: 100%; min-height: 640px; border: 1px solid var(--line); border-radius: 8px; background: var(--kraft); }
.working { display: flex; align-items: center; gap: 14px; border-left: 4px solid var(--warn); }
.spinner { flex: none; width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line-strong); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
.error-card { background: var(--err-soft); color: var(--err); border-color: transparent; padding: 14px 16px; border-radius: 8px; }
.prose { line-height: 1.6; overflow-wrap: anywhere; }
.prose p { margin: 0 0 10px; }
.prose table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 14px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 9px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); }
.prose blockquote { margin: 10px 0; padding: 4px 14px; border-left: 3px solid var(--accent); color: var(--muted); }
.paper { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 16px 20px; }
.proposal { border-top: 1px solid var(--line); padding: 12px 0; }
.proposal:first-of-type { border-top: none; }
.proposal summary { cursor: pointer; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
pre.code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; max-height: 420px; font-size: 12.5px; white-space: pre-wrap; word-break: break-word; }
ul.log { font-size: 13.5px; color: var(--muted); padding-left: 18px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border-radius: 999px; color: var(--muted); border: 1px solid var(--line); background: var(--surface); font-size: 14px; }
.tabs a.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.pager { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 12px; }
.pager a { padding: 5px 11px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface); }
.pager a.on { background: var(--ink); color: var(--bg); }

/* ---------- вход ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-page .flash { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); }
.login-card { position: relative; width: 100%; max-width: 380px; background: var(--kraft); padding: 46px 28px 26px; border-radius: 4px 12px 12px 12px; box-shadow: var(--shadow); color: #1d1a16; }
.login-card h1 { font: 28px "Russo One"; letter-spacing: .12em; }
.login-card .muted, .login-card .help { color: #4a3f29; }
.login-card input { background: #fbf7ec; color: #1d1a16; border-color: #a68d57; }
.login-tab { position: absolute; top: -22px; left: 0; background: var(--kraft); padding: 4px 16px; border-radius: 8px 8px 0 0; font: 12px "PT Mono"; letter-spacing: .15em; color: #4a3f29; }

/* ---------- мобильные ---------- */
@media (max-width: 860px) {
  .two-col, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .pdf-card iframe { min-height: 480px; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; padding: 8px 16px 0; gap: 8px 12px; }
  .nav { order: 3; flex-basis: 100%; padding-bottom: 6px; }
  .logout { margin-left: auto; }
  .page { padding: 16px 16px 80px; }
  h1 { font-size: 22px; }
  .card { padding: 16px; }
  .check-row { flex-direction: column; align-items: flex-start; }
  .list th, .list td { padding: 9px 10px; }
  .kv th { width: 40%; }
  .filters select { flex: 1; }
}

/* ---------- Mini App ---------- */
.dot.warn { background: var(--warn); }
.status-list { list-style: none; padding: 0; margin: 6px 0 0; display: grid; gap: 8px; font-size: 14px; color: var(--muted); }
.status-list li { position: relative; padding-left: 18px; }
.status-list .dot { position: absolute; left: 0; top: 6px; }
.tg-splash-page { min-height: 100vh; display: grid; place-items: center; }
.tg-splash { text-align: center; color: var(--muted); padding: 20px; }
.logo-mark.big { width: 64px; height: 64px; font-size: 34px; border-radius: 14px; margin: 0 auto 14px; font-family: "Russo One"; }
body[data-tg] .topbar { position: static; }
body[data-tg] .logo span:last-child { display: none; }
.full-text { max-height: none; }
