:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7384;
  --line: #dde2ea;
  --brand: #2456d6;
  --brand-ink: #ffffff;
  --ok: #17794a;
  --ok-bg: #e3f5ec;
  --warn: #9a5b00;
  --warn-bg: #fff3dc;
  --bad: #b42323;
  --bad-bg: #fde7e7;
  --info: #2456d6;
  --info-bg: #e6edfd;
  --wait: #6a3fb5;
  --wait-bg: #efe8fb;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111521;
    --panel: #1a2030;
    --ink: #e8ebf2;
    --muted: #9aa3b5;
    --line: #2c3446;
    --brand: #7b9cff;
    --brand-ink: #0c1222;
    --ok: #6fd39c; --ok-bg: #173325;
    --warn: #f0be6a; --warn-bg: #3a2e16;
    --bad: #ff8a8a; --bad-bg: #3d1d1d;
    --info: #9bb6ff; --info-bg: #1d2a48;
    --wait: #c4a8ff; --wait-bg: #2c2141;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #111521;
  --panel: #1a2030;
  --ink: #e8ebf2;
  --muted: #9aa3b5;
  --line: #2c3446;
  --brand: #7b9cff;
  --brand-ink: #0c1222;
  --ok: #6fd39c; --ok-bg: #173325;
  --warn: #f0be6a; --warn-bg: #3a2e16;
  --bad: #ff8a8a; --bad-bg: #3d1d1d;
  --info: #9bb6ff; --info-bg: #1d2a48;
  --wait: #c4a8ff; --wait-bg: #2c2141;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: .2rem 0 .6rem; }
h2 { font-size: 1.1rem; margin: 0 0 .7rem; }
code, pre { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; }
pre { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; }
[hidden] { display: none !important; }

.wrap { width: 100%; max-width: 1240px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.dim td { opacity: .55; }
.empty { text-align: center; color: var(--muted); padding: 24px !important; }

/* Горна лента */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 650; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 8px;
  background: var(--brand); color: var(--brand-ink); font-weight: 800;
}
.who { color: var(--muted); font-size: 13px; }

.staffnav { background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.navrow { display: flex; gap: 2px; align-items: stretch; }
.staffnav a {
  display: inline-flex; align-items: center; gap: 6px; padding: 11px 12px; color: var(--muted);
  border-bottom: 2px solid transparent; white-space: nowrap; font-size: 14px;
}
.staffnav a:hover { color: var(--ink); text-decoration: none; }
.staffnav a.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.staffnav .logout { margin-left: auto; }
.count {
  display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; font-size: 12px; line-height: 18px;
  text-align: center; background: var(--bad-bg); color: var(--bad); font-weight: 650;
}

main.wrap { padding-top: 22px; padding-bottom: 40px; flex: 1; }
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 18px; border-top: 1px solid var(--line); }

/* Карти и форми */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px;
}
.card.narrow { max-width: 620px; margin-left: auto; margin-right: auto; }
.card-inner { padding: 0; }
.table-card { padding: 0; overflow-x: auto; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.head h1 { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 12px; }
.inline { display: inline; margin: 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 4px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; margin-bottom: 10px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
label.check input { width: 16px; height: 16px; }
.field > span { font-weight: 600; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 11px; min-height: 40px; width: 100%; max-width: 100%;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
input[readonly], output { background: var(--bg); }
output { display: block; padding: 8px 11px; border-radius: 8px; border: 1px dashed var(--line); min-height: 40px; }
input[type="checkbox"], input[type="file"] { width: auto; min-height: 0; }
.narrow-input { width: 90px !important; }

.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 18px; }
@media (min-width: 720px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span2 { grid-column: 1 / -1; }
  .form-grid .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
}
.form-grid .row { display: grid; grid-template-columns: 1fr; gap: 0 14px; }
.form-grid fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin: 0 0 12px; }
.form-grid legend { font-weight: 650; padding: 0 6px; }
.form-grid h2 { margin-bottom: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 40px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); font: inherit; font-weight: 550;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn-primary:hover { filter: brightness(1.06); border-color: var(--brand); }
.btn-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ghost { background: transparent; }
.btn-lg { min-height: 46px; padding: 10px 20px; font-size: 16px; }
button.link { background: none; border: 0; padding: 0; color: var(--brand); font: inherit; cursor: pointer; }

/* Таблици */
.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th, .grid td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid th { color: var(--muted); font-weight: 600; font-size: 12.5px; text-transform: uppercase; letter-spacing: .03em; background: var(--bg); position: sticky; top: 0; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: color-mix(in srgb, var(--brand) 4%, transparent); }
.grid.compact td, .grid.compact th { padding: 7px 8px; }
.grid td.subj a { font-weight: 600; color: var(--ink); }
.grid input { min-height: 34px; padding: 5px 9px; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 14px; }
.tabs a:hover { color: var(--ink); text-decoration: none; }
.tabs a.on { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { width: auto; min-width: 150px; min-height: 36px; padding: 6px 9px; }
.filters .search { min-width: 280px; flex: 1; }

.pager { display: flex; gap: 14px; justify-content: center; align-items: center; margin: 14px 0; color: var(--muted); }

/* Значки */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; line-height: 20px;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.pill-ok { background: var(--ok-bg); color: var(--ok); }
.pill-warn { background: var(--warn-bg); color: var(--warn); }
.pill-bad { background: var(--bad-bg); color: var(--bad); }
.pill-info { background: var(--info-bg); color: var(--info); }
.pill-wait { background: var(--wait-bg); color: var(--wait); }
.pill-muted { background: var(--bg); color: var(--muted); }
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }

/* Съобщения */
.flash { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.flash-ok { background: var(--ok-bg); color: var(--ok); }
.flash-warn { background: var(--warn-bg); color: var(--warn); }
.flash-bad { background: var(--bad-bg); color: var(--bad); }
.flash-box { border-color: var(--ok); }
.info-line { color: var(--muted); font-size: 14px; }

/* Тикет */
.ticket-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.ticket-head h1 { margin: 0; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-start; }
.ticket-grid { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 980px) { .ticket-grid { grid-template-columns: minmax(0, 1fr) 380px; } }
.props-form { position: sticky; top: 12px; max-height: calc(100vh - 24px); overflow-y: auto; }
.props-form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.props-form .field { min-width: 0; }
.props-form input, .props-form select { font-size: 14px; min-height: 36px; padding: 6px 9px; }
.body { white-space: normal; padding: 4px 0 8px; }
.meta-line { color: var(--muted); font-size: 13.5px; margin-bottom: 8px; }
.timeline { display: flex; flex-direction: column; gap: 10px; }
.entry { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; background: var(--panel); }
.entry.internal { background: var(--warn-bg); border-color: transparent; }
.entry.ev { background: var(--bg); }
.entry.pub { border-left: 3px solid var(--brand); }
.entry-head { font-size: 13px; margin-bottom: 4px; }
.entry-body { white-space: normal; }
.tag { font-size: 12px; color: var(--muted); }
.files { margin: 8px 0 0; padding-left: 18px; font-size: 14px; }
.reply { padding: 0; border: 0; }
.reply textarea { margin-bottom: 8px; }
.reply .row { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.reply select { width: auto; }
.danger-zone { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--line); }

/* Публична част */
.hero { max-width: 760px; margin: 8px auto 18px; }
.hero h1 { font-size: 1.75rem; }
.hp { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.captcha { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; grid-column: 1 / -1; }
.captcha img { border-radius: 8px; border: 1px solid var(--line); }
.captcha label { flex: 1; min-width: 200px; }
.captcha-input { letter-spacing: .15em; text-transform: uppercase; }
.faq details { border-bottom: 1px solid var(--line); padding: 10px 0; }
.faq details:last-child { border-bottom: 0; }
.faq summary { cursor: pointer; font-weight: 600; }
.faq p { margin: 8px 0 0; color: var(--muted); }
.track-form { display: grid; gap: 4px; }
.login { margin-top: 30px; }

.manual h2 { margin-top: 26px; padding-top: 4px; border-top: 1px solid var(--line); }
.manual h2:first-child { border-top: 0; margin-top: 0; }
.manual ul, .manual ol { padding-left: 22px; }
.manual li { margin: 3px 0; }
.manual h3 { font-size: 1rem; }
.danger-zone .btn { margin-top: 4px; }

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; }
  .who { display: none; }
  .wrap { padding: 0 12px; }
  .filters .search { min-width: 100%; }
  .filters select, .filters input { flex: 1 1 140px; }
  .props-form { position: static; max-height: none; }
  .props-form .row { grid-template-columns: 1fr; }
}

/* ---- Меню (служители) и общи подобрения ---- */
.userbox { display: flex; align-items: center; gap: 12px; }
.userbox .who { display: flex; flex-direction: column; line-height: 1.2; text-align: right; }
.userbox .who small { color: var(--muted); font-size: 12px; }
.btn-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }
.shell { display: flex; align-items: stretch; min-height: calc(100vh - 110px); }
.side {
  width: 236px; flex: 0 0 236px; background: var(--panel); border-right: 1px solid var(--line);
  padding: 14px 10px; position: sticky; top: 0; align-self: flex-start; height: 100vh; overflow-y: auto;
}
.side nav { display: flex; flex-direction: column; gap: 16px; }
.navtitle { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 10px 6px; font-weight: 650; }
.side a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 8px;
  color: var(--ink); font-size: 14px; text-decoration: none;
}
.side a:hover { background: color-mix(in srgb, var(--brand) 8%, transparent); text-decoration: none; }
.side a.on { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); font-weight: 650; }
.content { flex: 1; min-width: 0; padding: 22px 26px 40px; }
.content .grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .content .grid-2 { grid-template-columns: 1fr 1fr; } }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }
.count { margin-left: auto; }
.home-grid { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 960px) { .home-grid { grid-template-columns: minmax(0, 1fr) 320px; } }
.home-side .card { margin-bottom: 14px; }
.tfa { margin-top: 24px; }
.qr { display: flex; justify-content: center; margin: 12px 0; }
.qr img { width: 220px; height: 220px; image-rendering: pixelated; border-radius: 8px; border: 1px solid var(--line); background: #fff; }
.secret { font-size: 15px; letter-spacing: .08em; word-break: break-all; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; list-style: none; padding: 0; }
.codes li { background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 8px; text-align: center; }
.code-input { font-size: 22px; letter-spacing: .2em; text-align: center; }
@media (max-width: 899px) {
  .shell { flex-direction: column; }
  .side { width: 100%; flex: none; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--line); }
  .side nav { flex-direction: row; flex-wrap: wrap; gap: 8px 14px; }
  .navgroup { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
  .navtitle { width: 100%; padding: 4px 0 0; }
  .content { padding: 16px 12px 40px; }
  .userbox .who { display: none; }
}
