:root {
  --bg: #f4f2f2;
  --card: #ffffff;
  --text: #262222;
  --muted: #7a6f6f;
  --line: #e3dddd;
  --primary: #a8323a;
  --primary-dark: #8a262d;
  --danger: #b4312c;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); }
a:hover { color: var(--primary-dark); }

.container { max-width: 1240px; margin: 0 auto; padding: 0 16px; }
main.container { padding-top: 20px; padding-bottom: 40px; }

/* ----- Шапка ----- */
.topbar { background: var(--primary); color: #fff; }
.topbar__inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; }
.brand:hover, .brand:hover .brand__name { color: #fff; }
.brand:hover .brand__logo { box-shadow: 0 0 0 2px rgba(255, 255, 255, .35); }
.brand__logo { width: 38px; height: 38px; background: #fff; border-radius: 9px; padding: 3px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.brand__name { font-weight: 700; font-size: 20px; letter-spacing: .2px; }
.brand__org { font-size: 12px; color: rgba(255, 255, 255, .8); }
.nav { display: flex; gap: 0; flex-wrap: wrap; align-self: stretch; }
.nav a { display: flex; align-items: center; padding: 0 16px; text-decoration: none; color: #fff; border-left: 1px solid rgba(255, 255, 255, .18); }
.nav a:hover { background: rgba(0, 0, 0, .14); color: #fff; }
.nav a.nav__primary { background: rgba(0, 0, 0, .18); font-weight: 600; }
.nav a.nav__primary:hover { background: rgba(0, 0, 0, .3); }

.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; padding: 16px 0; }

/* ----- Общие элементы ----- */
.h1 { font-size: 22px; margin: 0; font-weight: 700; }
.muted { color: var(--muted); font-weight: 400; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.strong { font-weight: 600; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 20px; margin-bottom: 16px; }
.card--narrow { max-width: 480px; margin: 40px auto; }

/* ----- Вход ----- */
.page-login .topbar { display: none; }
.page-login main.container { min-height: calc(100vh - 60px); display: flex; align-items: center; justify-content: center; padding: 40px 16px; }
.login { width: 100%; max-width: 400px; }
.login__brand { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 20px; }
.login__logo { width: 56px; height: 56px; }
.login__site { font-size: 20px; font-weight: 700; }
.login__card { padding: 28px 28px 24px; margin: 0; box-shadow: 0 6px 24px rgba(30, 42, 39, .06); }
.login__title { font-size: 19px; font-weight: 700; margin: 0 0 4px; }
.login__hint { margin: 0 0 20px; color: var(--muted); font-size: 13px; }
.login__form { display: flex; flex-direction: column; gap: 16px; }
.login__form .field { gap: 6px; }
.login__form .field__label { font-size: 13px; color: var(--text); font-weight: 500; }
.login__form input { padding: 11px 12px; font-size: 15px; }
.login__form .btn--block { margin-top: 6px; padding: 11px 16px; font-size: 15px; }
.btn--block { display: block; width: 100%; text-align: center; }
.settings-form { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }
.settings-form .field__label { font-size: 13px; color: var(--text); font-weight: 500; }
.flash { background: #e3f3ec; border: 1px solid #b8dfcd; color: #184d3f; padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.error { background: #fbe9e8; border: 1px solid #f0c3c0; color: #7a1f1a; padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search { display: flex; gap: 6px; flex: 1; max-width: 520px; }
.search input { flex: 1; }

.btn {
  display: inline-block; padding: 8px 14px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: var(--bg); color: var(--text); }
.btn--primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); color: #fff; }
.btn--danger { color: var(--danger); border-color: #e7b9b7; }
.btn--danger:hover { background: #fbe9e8; color: var(--danger); }
.btn--link { border-color: transparent; background: transparent; color: var(--primary); }
.btn--sm { padding: 4px 9px; font-size: 13px; }
.inline { display: inline; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge--ok { background: #e3f3ec; color: #184d3f; }
.badge--done { background: #e8eef5; color: #2f4a66; }
.badge--bad { background: #fbe9e8; color: #7a1f1a; }
.badge--draft { background: #fff4d6; color: #6b4e00; }
.badge--neutral { background: #eee; color: #444; }

/* ----- Таблицы ----- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
.table th { background: #f6f8f7; font-weight: 600; }
.table tbody tr:nth-child(even) td { background: #fafbfb; }
.table__actions { white-space: nowrap; }
.table__actions .btn { margin-right: 2px; }
.cell-clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ----- Просмотр документа ----- */
.view-grid { display: grid; grid-template-columns: 1fr 260px; gap: 16px; align-items: start; }
.view-side { position: sticky; top: 16px; }
.view-grid--single { grid-template-columns: 1fr; }
.section__title { font-size: 16px; margin: 0 0 12px; padding-bottom: 8px; border-bottom: 2px solid var(--primary); }
.props { display: grid; grid-template-columns: minmax(220px, 34%) 1fr; gap: 0; margin: 0; }
.props dt { padding: 6px 8px 6px 0; color: var(--muted); border-bottom: 1px solid var(--line); }
.props dd { margin: 0; padding: 6px 0; border-bottom: 1px solid var(--line); word-break: break-word; }
.props dt:last-of-type, .props dd:last-of-type { border-bottom: none; }
.toggle-row { margin: 6px 0; }
.qr-card { text-align: center; }
.qr-card__img { width: 100%; max-width: 220px; height: auto; border: 1px solid var(--line); border-radius: 6px; }
.qr-card__caption { margin-top: 8px; color: var(--muted); font-size: 12px; }
.qr-card__url { margin-top: 6px; font-size: 12px; word-break: break-all; }
.qr-card__actions { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }

/* ----- Формы ----- */
input[type="text"], input[type="search"], input[type="password"], select, textarea {
  width: 100%; padding: 7px 9px; border: 1px solid #c9d2ce; border-radius: 6px; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(168, 50, 58, .3); border-color: var(--primary); }
textarea { resize: vertical; min-height: 64px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field__label { font-size: 12px; color: var(--muted); }
.field__hint { font-size: 11px; color: var(--muted); }
.input--readonly { background: #f3f5f4; color: var(--muted); }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px 16px; }
.field--wide { grid-column: 1 / -1; }
.form .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }
.actions--sticky { position: sticky; bottom: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 16px; }

.table--edit input[type="text"], .table--edit input[type="date"], .table--edit select { min-width: 110px; padding: 5px 7px; font-size: 13px; }
.table--edit select { min-width: 120px; }
.table--edit input[type="date"] { min-width: 140px; }
input[type="date"], input[type="datetime-local"] { width: 100%; padding: 6px 9px; border: 1px solid #c9d2ce; border-radius: 6px; font: inherit; background: #fff; color: var(--text); }
.daterange { display: flex; align-items: center; gap: 6px; }
.daterange input[type="date"] { flex: 1; min-width: 0; }
.daterange__sep { color: var(--muted); }
.table--edit td { padding: 3px 4px; }
.list-row__num { width: 36px; text-align: center; color: var(--muted); }
.list-row__tools { white-space: nowrap; width: 64px; }
.icon-btn { border: 1px solid var(--line); background: #fff; border-radius: 4px; cursor: pointer; width: 26px; height: 26px; font-size: 14px; line-height: 1; margin-left: 2px; }
.icon-btn:hover { background: var(--bg); }
.icon-btn--danger { color: var(--danger); }
.list-editor__actions { margin-top: 10px; display: flex; gap: 8px; }

/* ----- Модальное окно ----- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal[hidden] { display: none; }
.modal__box { background: #fff; border-radius: var(--radius); width: 100%; max-width: 420px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal__head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal__close { border: 0; background: none; font-size: 22px; cursor: pointer; color: var(--muted); }
.modal__body { padding: 16px; }
.modal__foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }

/* ----- Адаптив ----- */
@media (max-width: 900px) {
  .view-grid { grid-template-columns: 1fr; }
  .view-side { position: static; }
  .props { grid-template-columns: 1fr; }
  .props dt { border-bottom: none; padding-bottom: 0; }
}

/* QR для печати: на экране не показывается */
.print-qr { display: none; }

/* ----- Печать ----- */
@page { size: A4 portrait; margin: 10mm 10mm 12mm; }
@media print {
  html, body { background: #fff; color: #000; font-size: 10.5pt; }
  .topbar, .footer, .no-print, .nav, .flash, .view-side, .toggle-row, .page-head__actions { display: none !important; }
  main.container { padding: 0; max-width: none; width: 100%; }
  .container { padding: 0; }
  .page-head { margin-bottom: 6mm; display: flex; justify-content: space-between; align-items: flex-start; }
  .print-qr { display: block; text-align: center; width: 30mm; flex: none; }
  .print-qr__img { width: 30mm; height: 30mm; display: block; }
  .print-qr__caption { font-size: 7pt; color: #333; margin-top: 1mm; }
  .h1 { font-size: 14pt; }
  .badge { border: 1px solid #000; background: none !important; color: #000 !important; padding: 0 4px; }
  .view-grid { display: block; }
  .view-main { width: 100%; }
  .card { border: none; border-radius: 0; padding: 0; margin: 0 0 4mm; break-inside: auto; box-shadow: none; }
  .section__title { font-size: 11pt; margin: 0 0 2mm; padding-bottom: 1mm; border-bottom: 1.5px solid #000; break-after: avoid; }
  .props { grid-template-columns: 34% 1fr; }
  .props dt, .props dd { padding: 1mm 2mm 1mm 0; border-bottom: 1px solid #bbb; font-size: 9.5pt; color: #000; }
  .props dt { color: #333; }
  .table-wrap { overflow: visible !important; }
  .table { width: 100% !important; table-layout: auto; font-size: 7.5pt; line-height: 1.25; border-collapse: collapse; }
  .table th { font-size: 7pt; }
  .table th, .table td {
    border: 1px solid #000; padding: 1px 2px; vertical-align: top;
    overflow-wrap: break-word; word-break: normal; hyphens: manual; white-space: normal;
  }
  .table th { background: #eee !important; font-weight: 600; }
  .table tbody tr:nth-child(even) td { background: none; }
  .table tr { break-inside: avoid; }
  .table thead { display: table-header-group; }
  .row-extra[hidden] { display: table-row !important; }
  a { color: inherit; text-decoration: none; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
