* { box-sizing: border-box; }
:root {
  --bg: #f4f6f9; --panel: #fff; --ink: #1f2733; --muted: #7a8699;
  --line: #e3e8ef; --accent: #2563eb; --accent-ink: #fff;
  --danger: #dc2626; --ok: #16a34a; --sidebar: #111827;
}
body { margin: 0; font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: inherit; text-decoration: none; }

.layout { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--sidebar); color: #cbd5e1; padding: 14px 10px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; flex-shrink: 0; }
.brand { display: block; font-size: 18px; font-weight: 700; color: #fff; padding: 6px 10px 14px; }
.nav-group { text-transform: uppercase; font-size: 11px; letter-spacing: .04em;
  color: #64748b; margin: 14px 10px 4px; }
.nav-link { display: block; padding: 8px 10px; border-radius: 8px; color: #cbd5e1; }
.nav-link:hover { background: #1f2937; color: #fff; }
.nav-link.logout { margin-top: 20px; color: #94a3b8; }

.content { flex: 1; padding: 22px 26px; max-width: 1200px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h3 { margin: 22px 0 8px; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.btn { display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); cursor: pointer; font-size: 14px; }
.btn:hover { border-color: #c3ccd8; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: #f3c2c2; }
.btn.danger:hover { background: #fef2f2; }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 3px 8px; }

.cbcol { width: 38px; text-align: center; }
.actcol { width: 46px; text-align: center; }
.draggable-th { cursor: grab; user-select: none; }
.draggable-th:active { cursor: grabbing; }
tr.selected > td { background: #eaf1ff; }
.bulkbar { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 10px;
  background: var(--sidebar); color: #fff; padding: 10px 14px; border-radius: 10px; margin-bottom: 10px; }
.bulkbar .spacer { flex: 1; }
.bulkbar .btn { padding: 6px 12px; }
.btn.small { padding: 4px 10px; }

.search { display: flex; gap: 8px; margin: 12px 0; }
.search input { flex: 1; max-width: 360px; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th { text-align: left; font-size: 12px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); }
table.grid tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f0f5ff; }
.num { text-align: right; } td.num, th.num { text-align: right; }
.right { text-align: right; }
.muted { color: var(--muted); } .small { font-size: 12px; margin-top: 8px; }

.cards { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px; min-width: 190px; }
.card.mini { text-align: center; min-width: 130px; }
.card-value { font-size: 24px; font-weight: 700; }
.card-value.neg { color: var(--danger); }
.card-label { color: var(--muted); font-size: 13px; margin-top: 4px; }
.card-sub { color: var(--muted); font-size: 12px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.card.acc { min-width: 220px; }
.card.acc:hover { border-color: var(--accent); }
.card.total { background: #f0f5ff; min-width: 180px; }

.form { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.form.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field.wide { grid-column: 1 / -1; }
label { font-size: 13px; color: var(--muted); }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }

.form-actions { margin-top: 16px; display: flex; gap: 10px; }
.danger-zone { margin-top: 22px; }

table.items input, table.items select { padding: 6px 8px; }
table.items td { padding: 6px 8px; }
.download-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 16px; }
.totals-badge { color: var(--muted); margin-left: auto; }

[x-cloak] { display: none !important; }

/* неактивная кнопка (нет изменений для сохранения) */
.btn:disabled, .btn[disabled] { background: #eef1f5; color: #9aa5b4; border-color: var(--line);
  cursor: default; box-shadow: none; opacity: 1; }
.btn.primary:disabled, .btn.primary[disabled] { background: #eef1f5; color: #9aa5b4;
  border-color: var(--line); }
.btn:disabled:hover { border-color: var(--line); }
.toast-ok { position: fixed; top: 16px; right: 16px; z-index: 100;
  background: #16a34a; color: #fff; padding: 12px 18px; border-radius: 10px;
  font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.18); }

/* фильтры по столбцам */
.filter-row th { padding: 4px 6px; background: #fafbfc; border-bottom: 1px solid var(--line); }
.filter-input { width: 100%; padding: 5px 7px; font-size: 12px; border-radius: 6px; }
.btn.ghost.active { border-color: var(--accent); color: var(--accent); }

/* сортировка столбцов */
.draggable-th .sort-ind { color: var(--accent); margin-left: 4px; font-size: 11px; }
.draggable-th:hover { background: #f0f5ff; }

/* загрузка файла (подпись) */
.file-field { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.file-preview { max-height: 70px; max-width: 240px; border: 1px solid var(--line);
  border-radius: 8px; padding: 6px; background: #fff; }
.file-del { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--danger); }
.file-del input { width: auto; }
.file-field input[type=file] { border: none; padding: 0; font-size: 13px; }

/* основание платежа (счёт или договор) */
.basis-block { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fafbfc; }
.basis-switch { display: flex; gap: 18px; margin-bottom: 8px; }
.basis-switch label { display: flex; align-items: center; gap: 6px; color: var(--ink); cursor: pointer; }
.basis-switch input { width: auto; }

/* поле-связь со ссылкой «открыть» */
.rel-with-link { display: flex; gap: 6px; align-items: center; }
.rel-with-link select { flex: 1; }
.rel-with-link .btn { flex-shrink: 0; }

/* combobox с поиском */
.combo { position: relative; }
.combo-input { width: 100%; }
.combo-list { position: absolute; z-index: 30; left: 0; right: 0; top: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; margin-top: 2px;
  max-height: 260px; overflow-y: auto; box-shadow: 0 10px 30px rgba(0,0,0,.12); }
.combo-opt { padding: 8px 10px; cursor: pointer; font-size: 14px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.combo-opt:hover { background: #f0f5ff; }
.combo-opt.muted { color: var(--muted); }
/* чтобы выпадашка услуги не обрезалась таблицей */
.items-wrap { overflow: visible; }

/* карточка документа */
.doc-topbar { display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.doc-title { font-size: 20px; font-weight: 700; }
.doc-title .doc-date { color: var(--muted); font-weight: 400; margin-left: 6px; }
.doc-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.doc-head { margin-bottom: 16px; }

.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 16px; }
.tab { background: transparent; border: none; padding: 10px 18px; cursor: pointer;
  font-size: 14px; color: var(--muted); border-bottom: 2px solid transparent;
  margin-bottom: -2px; border-radius: 8px 8px 0 0; }
.tab:hover { background: #f0f5ff; color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.ro { padding: 8px 0; font-size: 15px; }
.verdict { background: #f0f5ff; border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 16px; font-weight: 600; margin-bottom: 14px; }
tr.opening td { background: #fafbfc; font-style: italic; }

.related { margin-top: 0; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px 18px; }
.related h3 { margin: 0 0 12px; }
.rel-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.rel-title { display: flex; align-items: center; justify-content: space-between;
  font-weight: 600; margin-bottom: 6px; }
.rel-list { list-style: none; margin: 0; padding: 0; }
.rel-list li { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; }
.rel-list li a { color: var(--accent); }
.rel-list li:hover { background: #f0f5ff; }

.error { background: #fef2f2; color: var(--danger); padding: 10px 12px; border-radius: 8px;
  margin-bottom: 12px; }

/* login */
.login-body { display: flex; align-items: center; justify-content: center; height: 100vh; }
.login-card { background: #fff; padding: 30px; border-radius: 14px; border: 1px solid var(--line);
  width: 320px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 10px 40px rgba(0,0,0,.06); }
.login-card h1 { text-align: center; font-size: 20px; margin: 0 0 6px; }
.login-card button { background: var(--accent); color: #fff; border: none; padding: 10px; border-radius: 8px; cursor: pointer; }

/* период работ в позиции документа */
.period-input { font-size: 12px; }

/* ---- документ, открытый в модальном окне ---- */
html.in-modal .sidebar { display: none; }
html.in-modal .layout { display: block; }
html.in-modal .content { padding: 18px 20px; max-width: none; }
html.in-modal body { background: #fff; }

/* ---- модальное окно со списком под ним ---- */
.modal-back { position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.45);
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px; }
.modal-win { background: #fff; border-radius: 14px; width: 100%; max-width: 1180px;
  height: calc(100vh - 48px); display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); background: #f8fafc; }
.modal-head .spacer { flex: 1; }
.modal-frame { flex: 1; border: 0; width: 100%; }
.modal-close { background: transparent; border: none; font-size: 22px; line-height: 1;
  cursor: pointer; color: var(--muted); padding: 2px 8px; border-radius: 8px; }
.modal-close:hover { background: #eef1f5; color: var(--ink); }

/* поле периода с календарём */
.period-cell { position: relative; }
.period-input { font-size: 12px; cursor: pointer; background: #fff; padding-right: 20px; }
.period-input::placeholder { color: #9aa5b4; }
.period-clear { position: absolute; right: 3px; top: 50%; transform: translateY(-50%);
  border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 15px; line-height: 1; padding: 0 3px; }
.period-clear:hover { color: var(--danger); }
.flatpickr-calendar { font-size: 13px; }

/* связанные документы: отвязка и привязка */
.rel-list li { display: flex; align-items: center; gap: 8px; }
.rel-list li a { flex: 1; }
.unlink-btn { border: none; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 13px; line-height: 1; padding: 2px 6px; border-radius: 6px; }
.unlink-btn:hover { background: #fef2f2; color: var(--danger); }
.attach-form { display: flex; gap: 6px; margin-top: 8px; }
.attach-form select { flex: 1; font-size: 12px; padding: 5px 7px; }
.alloc-input { width: 90px; font-size: 12px; padding: 5px 7px; }
