:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #16202e;
  --muted: #6b7b8f;
  --line: #dde4ec;
  --brand: #16528a;
  --brand-ink: #ffffff;
  --ok: #1c7c4a;
  --warn: #a86a00;
  --danger: #b3261e;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 48, .06), 0 4px 14px rgba(16, 32, 48, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #10161f; --panel: #182231; --ink: #e6edf6; --muted: #8fa2b8;
    --line: #27354a; --brand: #4f9bd8; --brand-ink: #06121e;
    --ok: #4cc38a; --warn: #e0a33a; --danger: #f2726a;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 6px 20px rgba(0,0,0,.25);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 21px; margin: 18px 0 14px; }
h2 { font-size: 15px; margin: 0 0 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
main { max-width: 1560px; margin: 0 auto; padding: 0 20px 60px; }
.muted { color: var(--muted); }
.note { font-size: 12.5px; margin: 8px 0 0; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------- шапка ---- */
.topbar {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand { font-weight: 700; font-size: 15px; color: var(--ink); }
.brand span { color: var(--muted); font-weight: 400; }
.topbar nav { display: flex; gap: 4px; margin-right: auto; }
.topbar nav a {
  padding: 6px 11px; border-radius: 7px; color: var(--ink); font-weight: 500;
}
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.topbar nav a.on { background: var(--brand); color: var(--brand-ink); }
.me { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.me .who { font-weight: 600; }

.role {
  font-size: 11px; padding: 2px 8px; border-radius: 20px; font-weight: 600;
  border: 1px solid var(--line); color: var(--muted); white-space: nowrap;
}
.role-filler    { color: #1b6ea8; border-color: #9dc6e6; background: #eaf4fc; }
.role-processor { color: #7a5200; border-color: #e3c98a; background: #fcf5e5; }
.role-admin     { color: #7a2a86; border-color: #d9aee0; background: #f9eefb; }
@media (prefers-color-scheme: dark) {
  .role-filler    { background: #12283b; border-color: #24486a; color: #7fbdea; }
  .role-processor { background: #33280d; border-color: #5c4a18; color: #e3bd64; }
  .role-admin     { background: #2c1633; border-color: #4d2a58; color: #d19be0; }
}

/* -------------------------------------------------------------- блоки ---- */
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px;
}
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; align-items: start; }
.crumbs { padding-top: 14px; font-size: 13px; }

.alert { padding: 10px 14px; border-radius: 8px; margin: 14px 0; font-weight: 500; }
.alert.ok  { background: #e7f6ed; color: #14603a; border: 1px solid #b5e0c7; }
.alert.err { background: #fdecea; color: #8c1d18; border: 1px solid #f2b8b5; }
@media (prefers-color-scheme: dark) {
  .alert.ok  { background: #10301f; color: #7ddba8; border-color: #1e5c3b; }
  .alert.err { background: #331614; color: #f2a19b; border-color: #6b2a26; }
}

/* -------------------------------------------------------------- формы ---- */
label { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); }
label.check input { width: auto; }
input, select, textarea, button {
  font: inherit; color: var(--ink);
}
input[type=text], input:not([type]), input[type=password], input[type=date], select, textarea {
  width: 100%; margin-top: 5px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); font-weight: 400;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent); outline-offset: 1px;
  border-color: var(--brand);
}
textarea { resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0; }
fieldset[disabled] { opacity: .72; }
.hint { display: block; font-weight: 400; font-size: 12px; color: var(--muted); margin-top: 4px; }

button, .btn {
  display: inline-block; padding: 8px 14px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--panel); color: var(--ink);
  cursor: pointer; font-size: 13px; font-weight: 600; line-height: 1.2;
}
button:hover, .btn:hover { background: var(--bg); text-decoration: none; }
button.primary, .btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.08); }
button.danger, .btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
button.link {
  border: 0; background: none; color: var(--brand); padding: 4px 2px; font-weight: 500;
}
button.link.danger { color: var(--danger); }
.btn.ghost { background: none; }
.row-form { display: inline-flex; gap: 6px; align-items: center; margin: 6px 6px 6px 0; }
.row-form input, .row-form select { margin-top: 0; width: auto; min-width: 170px; }
form.right { margin-left: auto; }

/* -------------------------------------------------------------- вход ---- */
.login-wrap { display: grid; place-items: center; min-height: 100vh; }
.login { width: 340px; }
.login h1 { margin: 0 0 4px; }
.login p { margin: 0 0 18px; font-size: 13px; }
.login button { width: 100%; margin-top: 6px; }

/* ------------------------------------------------------------ фильтры ---- */
.filters { margin-top: 16px; }
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-row .search { margin-top: 0; flex: 1; font-size: 15px; padding: 10px 12px; }
.search-row button, .search-row .btn { padding-inline: 18px; }
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-row select, .filter-row input { margin-top: 0; width: auto; min-width: 130px; }

.toolbar { display: flex; align-items: center; gap: 14px; margin: 14px 0 10px; flex-wrap: wrap; }
.toolbar .count { font-size: 14px; }
.toolbar .actions { margin-left: auto; display: flex; gap: 8px; }

/* ------------------------------------------------------------ таблицы ---- */
/* Реестр прокручивается внутри карточки — шапка таблицы остаётся на виду.
   Сама .table-wrap является контейнером прокрутки, поэтому sticky-шапке нужен
   top: 0 (отступ на высоту topbar здесь дал бы наезд на первую строку). */
.table-wrap { padding: 0; overflow: auto; max-height: calc(100vh - 250px); }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  text-align: left; padding: 9px 10px; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); border-bottom: 1px solid var(--line);
  background: var(--panel); position: sticky; top: 0; z-index: 1;
  box-shadow: inset 0 -1px 0 var(--line);
}
table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.grid tbody tr:hover { background: color-mix(in srgb, var(--brand) 6%, transparent); cursor: pointer; }
table.grid tr.inactive { opacity: .55; }
table.grid.small { font-size: 12.5px; }
table.grid.small th { position: static; }
.empty { text-align: center; color: var(--muted); padding: 26px !important; cursor: default; }

.c-id { width: 56px; color: var(--muted); font-variant-numeric: tabular-nums; }
.c-date { width: 120px; white-space: nowrap; font-variant-numeric: tabular-nums; color: var(--muted); }
.c-file { width: 54px; text-align: center; }
.c-acc { font-weight: 600; max-width: 210px; overflow-wrap: anywhere; }
.c-link { max-width: 330px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-dda { max-width: 300px; }
.c-small { font-size: 12px; max-width: 170px; }
.ellipsis { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
/* Обрезка длинного текста прямо в ячейке — без display:inline-block,
   иначе ячейка выпадает из табличной раскладки. */
td.clip { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chip {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px;
  font-weight: 600; background: var(--bg); border: 1px solid var(--line); color: var(--muted);
  white-space: nowrap;
}
.chip.ok { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--line)); }
.net-tiktok    { color: #c2185b; border-color: #f0b6cc; }
.net-instagram { color: #a1348c; border-color: #e6b9dd; }
.net-facebook  { color: #1b5fbe; border-color: #b3c9ec; }
.net-youtube   { color: #c62828; border-color: #f0b9b9; }
.net-telegram  { color: #1976a8; border-color: #aed4e8; }
.net-threads   { color: #444c56; }

.status-draft     { color: var(--muted); }
.status-filled    { color: #1b6ea8; border-color: #9dc6e6; }
.status-sent      { color: var(--warn); border-color: #e3c98a; }
.status-expertise { color: #7a2a86; border-color: #d9aee0; }
.status-answered  { color: var(--ok); border-color: #b5e0c7; }
.status-closed    { color: var(--muted); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--line); }
.dda-bar { background: var(--danger); }
.dda-zhoq { background: var(--ok); }
.dda-unknown { background: var(--line); }

.badge {
  display: inline-block; min-width: 20px; padding: 1px 6px; border-radius: 20px;
  background: var(--brand); color: var(--brand-ink); font-size: 11px; font-weight: 700;
}

table.files, table.history { width: 100%; border-collapse: collapse; font-size: 13px; }
table.files td, table.history td { padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.files small { display: block; font-size: 11.5px; }
table.history { font-size: 12.5px; }
table.history td:last-child { max-width: 280px; }

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin: 18px 0; }

/* ------------------------------------------------------------- сводка ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px 16px; display: flex; flex-direction: column; gap: 2px;
}
.tile .num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tile .cap { font-size: 12px; color: var(--muted); }
.barcell { width: 55%; }
.bar { display: block; height: 8px; border-radius: 4px; background: var(--brand); min-width: 2px; }

/* ------------------------------------------------ просмотр документа ---- */
/* Белый «лист» с содержимым .docx — читается так же, как в Word. */
.doc-page {
  background: #fff; color: #16202e;
  max-width: 850px; margin: 0 auto 40px; padding: 48px 56px;
  border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 2px 6px rgba(16,32,48,.08), 0 12px 40px rgba(16,32,48,.10);
  font-family: "Times New Roman", Georgia, serif; font-size: 16px; line-height: 1.5;
}
.doc-page p { margin: 0 0 10px; }
.doc-page h1, .doc-page h2, .doc-page h3 { font-family: inherit; color: inherit;
  text-transform: none; letter-spacing: 0; margin: 18px 0 10px; }
.doc-page h1 { font-size: 22px; } .doc-page h2 { font-size: 19px; } .doc-page h3 { font-size: 17px; }
.doc-page table { border-collapse: collapse; width: 100%; margin: 12px 0; }
.doc-page td, .doc-page th { border: 1px solid #9aa7b6; padding: 6px 9px; vertical-align: top; }
.doc-page img { max-width: 100%; height: auto; display: block; margin: 12px 0;
  border: 1px solid var(--line); border-radius: 4px; }
.doc-page ul, .doc-page ol { margin: 0 0 10px; padding-left: 26px; }
.doc-page a { color: #16528a; }
@media (prefers-color-scheme: dark) {
  .doc-page { background: #f7f9fc; }   /* лист остаётся светлым — это документ */
}
.alert.warn { background: #fdf4e3; color: #7a5200; border: 1px solid #e3c98a; }
@media (prefers-color-scheme: dark) {
  .alert.warn { background: #33280d; color: #e3bd64; border-color: #5c4a18; }
}
.btn.tiny { padding: 2px 7px; font-size: 12px; }
@media print {
  .topbar, .crumbs, .rec-head .actions, .alert { display: none !important; }
  body { background: #fff; }
  .doc-page { box-shadow: none; border: 0; margin: 0; padding: 0; max-width: none; }
}

.rec-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.rec-head .actions { display: flex; gap: 8px; align-items: center; }
.rec-head h1 { margin: 14px 0; }
code.pw { font-size: 15px; background: var(--bg); padding: 2px 8px; border-radius: 6px; user-select: all; }
td.ok { color: var(--ok); font-weight: 600; }
td.no { color: var(--muted); }

@media (max-width: 860px) {
  .cols { grid-template-columns: 1fr; }
  table.grid th { position: static; }
}
