:root {
  --bg: #f1f4f3;
  --card: #ffffff;
  --text: #1e2a27;
  --muted: #6b7a76;
  --line: #dde4e1;
  --primary: #1f6f5f;
  --primary-dark: #185a4d;
  --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(--card); border-bottom: 1px solid var(--line); }
.topbar__inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand__logo { width: 36px; height: 36px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.brand__name { font-weight: 700; font-size: 17px; }
.brand__org { font-size: 12px; color: var(--muted); }
.nav { display: flex; gap: 6px; flex-wrap: wrap; }
.nav a { padding: 7px 12px; border-radius: 6px; text-decoration: none; color: var(--text); }
.nav a:hover { background: var(--bg); }
.nav a.nav__primary { background: var(--primary); color: #fff; }
.nav a.nav__primary:hover { background: var(--primary-dark); }

.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: 420px; margin: 40px auto; }
.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; }
.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(31, 111, 95, .35); 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"] { min-width: 110px; padding: 5px 7px; font-size: 13px; }
.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; }
}

/* ----- Печать ----- */
@media print {
  body { background: #fff; font-size: 12px; }
  .topbar, .footer, .no-print, .nav, .flash { display: none !important; }
  main.container { padding: 0; max-width: none; }
  .card { border: none; padding: 0; margin-bottom: 10px; break-inside: avoid; }
  .view-grid { grid-template-columns: 1fr 150px; }
  .view-side { position: static; }
  .row-extra[hidden] { display: table-row !important; }
  .qr-card__img { max-width: 140px; border: none; }
  .section__title { font-size: 13px; }
  .table { font-size: 10px; }
  a { color: inherit; text-decoration: none; }
}
