/* ============================================================
   Договоры — оформление
   Светлый фон, белые карточки со скруглением, боковое меню,
   синий акцент. Внешних ресурсов нет: шрифты системные, иконки
   инлайновые — интерфейс должен открываться и без интернета.
   ============================================================ */

:root {
  --bg: #eef1f8;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --ink: #101828;
  --ink-soft: #344054;
  --muted: #667085;
  --line: #e9edf5;
  --accent: #3b5bfd;
  --accent-hover: #2f4ae0;
  --accent-soft: #eef1ff;
  --ok: #08875d;
  --ok-soft: #e7f7ef;
  --bad: #d92d20;
  --bad-soft: #fef3f2;
  --warn: #b54708;
  --warn-soft: #fff8eb;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-soft: 0 1px 2px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.55 Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------- каркас */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; align-self: flex-start;
  width: 244px; flex: 0 0 244px; height: 100vh;
  padding: 22px 16px; display: flex; flex-direction: column; gap: 26px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: 0 0 34px;
  background: linear-gradient(135deg, var(--accent), #7b5bfd);
  display: grid; place-items: center; color: #fff;
}
.brand-name { font-size: 16px; font-weight: 700; letter-spacing: -.01em; color: var(--ink); }
.brand-note { font-size: 11px; color: var(--muted); }
.brand a, .brand a:hover { text-decoration: none; }

.menu { display: flex; flex-direction: column; gap: 2px; }
.menu-title {
  padding: 0 12px 6px; font-size: 11px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: #98a2b3;
}
.menu a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-weight: 500; text-decoration: none;
}
.menu a svg { flex: 0 0 18px; opacity: .7; }
.menu a:hover { background: #e5eaf5; text-decoration: none; }
.menu a.active { background: var(--accent); color: #fff; box-shadow: var(--shadow-soft); }
.menu a.active svg { opacity: 1; }

.side-user {
  margin-top: auto; padding: 12px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow-soft);
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 36px; height: 36px; flex: 0 0 36px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.side-user-name { font-weight: 600; font-size: 13px; line-height: 1.3; }
.side-user-scope { font-size: 11px; color: var(--muted); }
.side-user a { font-size: 11px; }

.content { flex: 1; min-width: 0; padding: 22px 26px 40px 6px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-title { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin: 0; }
.page-sub { color: var(--muted); margin: 3px 0 0; }
.page-actions { display: flex; align-items: center; gap: 10px; }

/* ---------------------------------------------------------- карточки */

.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}
.card h2 { font-size: 16px; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.card-note { color: var(--muted); font-size: 13px; margin: -6px 0 14px; }

.tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px; margin-bottom: 18px;
}
.tile {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 18px;
}
.tile-label {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 12px; font-weight: 500;
}
.tile-value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 8px; }
.tile-foot { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.accent {
  background: linear-gradient(135deg, var(--accent), #6f5bfd); color: #fff;
}
.tile.accent .tile-label, .tile.accent .tile-foot { color: rgba(255, 255, 255, .8); }
.tile.debt .tile-value { color: var(--bad); }
.tile.paid .tile-value { color: var(--ok); }

/* ---------------------------------------------------------- формы */

label { display: block; margin-bottom: 14px; }
.field-label,
label > span.label { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }

input, select, textarea {
  display: block; width: 100%; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); font: inherit; color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input:disabled, select:disabled { background: var(--surface-soft); color: var(--muted); }
textarea { resize: vertical; }

.cols { display: flex; gap: 14px; flex-wrap: wrap; }
.cols > * { flex: 1 1 190px; min-width: 0; }

fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend {
  padding: 0; margin-bottom: 12px; font-size: 12px; font-weight: 600;
  letter-spacing: .06em; text-transform: uppercase; color: #98a2b3;
}

label.checkbox {
  display: flex; align-items: center; gap: 8px;
  color: var(--ink-soft); font-size: 13px;
}
label.checkbox input { width: auto; }
label.checkbox.inline { display: inline-flex; margin: 0; white-space: nowrap; }

/* ---------------------------------------------------------- кнопки */

button, .button {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-soft);
  font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: background .12s, border-color .12s, color .12s;
}
button:hover, .button:hover {
  background: var(--surface-soft); border-color: #d6dcea;
  color: var(--ink); text-decoration: none;
}
button.primary, .button.primary {
  background: var(--accent); border-color: var(--accent); color: #fff;
  box-shadow: 0 1px 2px rgba(59, 91, 253, .3);
}
button.primary:hover, .button.primary:hover {
  background: var(--accent-hover); border-color: var(--accent-hover); color: #fff;
}
button.link {
  border: 0; background: none; padding: 0; color: var(--muted);
  font-weight: 500; font-size: 13px;
}
button.link:hover { background: none; color: var(--bad); text-decoration: underline; }
button.small, .button.small { padding: 6px 11px; font-size: 13px; }

/* ---------------------------------------------------------- панель фильтров */

.filters {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 12px 14px; margin-bottom: 16px;
}
.filters label { margin: 0; }
.search-box { position: relative; flex: 1 1 260px; min-width: 200px; }
.search-box svg { position: absolute; left: 12px; top: 50%; margin-top: -9px; color: var(--muted); }
.search-box input { padding-left: 36px; }
.filters select { width: auto; min-width: 150px; }

/* ---------------------------------------------------------- таблицы */

.table-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-scroll { overflow-x: auto; }

table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  padding: 11px 16px; text-align: left; font-size: 11px; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase; color: #98a2b3;
  background: var(--surface-soft); border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.grid td {
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover { background: #fafbff; }
table.grid tfoot td {
  padding: 13px 16px; font-weight: 650;
  background: var(--surface-soft); border-top: 1px solid var(--line);
}
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tick { width: 44px; text-align: center; }
.tick input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.empty { color: var(--muted); text-align: center; padding: 42px 16px; }

.person { display: flex; align-items: center; gap: 10px; }
.person-name { font-weight: 600; color: var(--ink); }
.person-name:hover { color: var(--accent); }
.person-sub { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------- метки */

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.neutral { background: var(--surface-soft); color: var(--muted); }
.pill.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--surface-soft); border: 1px solid var(--line);
  border-radius: 7px; padding: 3px 9px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
}
.chip.bad { background: var(--bad-soft); border-color: #fecdc9; color: var(--bad); }

.muted { color: var(--muted); }
.ok { color: var(--ok); }
.bad { color: var(--bad); font-weight: 600; }
.over { color: var(--warn); }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  background: var(--surface-soft); padding: 1px 5px; border-radius: 5px;
}

/* ---------------------------------------------------------- сообщения */

.flash, .error {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 15px; border-radius: var(--radius-sm); margin-bottom: 16px;
  font-size: 13px; line-height: 1.5;
}
.flash { background: var(--accent-soft); color: #23368f; }
.error { background: var(--bad-soft); color: var(--bad); }

/* ---------------------------------------------------------- файлы */

.files { display: flex; gap: 6px; flex-wrap: wrap; }
.file-link {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 9px; border-radius: 7px; background: var(--surface-soft);
  border: 1px solid var(--line); color: var(--ink-soft);
  font-size: 12px; font-weight: 500;
}
.file-link:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* ---------------------------------------------------------- две колонки */

.split { display: flex; gap: 18px; align-items: flex-start; }
.split-main { flex: 1 1 560px; min-width: 0; }
.split-side { flex: 0 0 350px; max-width: 350px; }

.summary-row {
  display: flex; align-items: baseline; justify-content: space-between;
  padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.summary-row:last-child { border-bottom: 0; }
.summary-row .value { font-weight: 650; font-variant-numeric: tabular-nums; }
.summary-row.total .value { font-size: 17px; }

.pay-list { list-style: none; margin: 0 0 14px; padding: 0; }
.pay-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.pay-item:last-child { border-bottom: 0; }
.pay-icon {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 9px;
  background: var(--ok-soft); color: var(--ok); display: grid; place-items: center;
}
.pay-main { flex: 1; min-width: 0; }
.pay-amount { font-weight: 650; font-variant-numeric: tabular-nums; }
.pay-meta { font-size: 12px; color: var(--muted); }

/* ---------------------------------------------------------- вход */

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border-radius: 20px; box-shadow: var(--shadow); padding: 32px;
}
.login-card .brand { justify-content: center; margin-bottom: 22px; padding: 0; }

/* ---------------------------------------------------------- строчные формы */

.inline-form { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }
.inline-form label { margin: 0; }
.inline-form input, .inline-form select { width: auto; padding: 6px 10px; font-size: 13px; }
.inline-form button { padding: 6px 11px; font-size: 13px; }

/* ---------------------------------------------------------- узкие экраны */

@media (max-width: 1000px) {
  .layout { flex-direction: column; }

  /* Боковое меню становится верхней панелью. min-width: 0 и max-width: 100%
     обязательны: без них строка меню растягивает всю страницу вбок, потому
     что элемент флекс-строки по умолчанию не сжимается меньше содержимого. */
  .sidebar {
    position: static; width: auto; max-width: 100%; min-width: 0;
    flex: none; height: auto; padding: 12px 14px; gap: 10px;
    background: var(--surface); box-shadow: var(--shadow-soft);
    display: flex; flex-direction: row; flex-wrap: wrap; align-items: center;
  }
  .sidebar .menu { flex-direction: row; flex-wrap: wrap; gap: 6px; flex: 1 1 100%; }
  .menu a { padding: 7px 11px; font-size: 13px; }
  .menu-title, .brand-note, .side-user-scope { display: none; }
  .side-user {
    margin: 0 0 0 auto; padding: 0; background: none; box-shadow: none;
    order: -1; gap: 8px;
  }
  .brand { order: -2; padding: 0; }
  .content { padding: 16px; }
  .split { flex-direction: column; }
  .split-side { flex: 1 1 auto; max-width: none; width: 100%; }
}

@media (max-width: 700px) {
  .page-title { font-size: 20px; }
  .page-head { gap: 10px; }
  .page-actions, .page-actions .button { width: 100%; justify-content: center; }
  .filters { padding: 12px; }
  .filters button, .filters select, .search-box { flex: 1 1 100%; }
  .cols > * { flex: 1 1 100%; }
  .card { padding: 16px; }

  /* Таблица списка превращается в карточки: 11 столбцов на телефоне
     означают бесконечный свайп вбок. Подписи берутся из data-label. */
  table.grid.stacked thead { display: none; }
  table.grid.stacked, table.grid.stacked tbody,
  table.grid.stacked tr, table.grid.stacked td { display: block; width: 100%; }
  table.grid.stacked tr {
    padding: 12px 14px; border-bottom: 1px solid var(--line);
  }
  table.grid.stacked tbody tr:last-child { border-bottom: 0; }
  table.grid.stacked td {
    border: 0; padding: 4px 0; text-align: left;
    display: flex; align-items: center; justify-content: space-between; gap: 14px;
  }
  table.grid.stacked td::before {
    content: attr(data-label);
    flex: 0 0 auto; color: var(--muted); font-size: 12px;
  }
  table.grid.stacked td[data-label=""]::before { content: none; }
  table.grid.stacked td.tick { width: auto; justify-content: flex-start; }
  table.grid.stacked td.num { justify-content: space-between; }
  table.grid.stacked .person { min-width: 0; }
  table.grid.stacked tfoot tr { background: var(--surface-soft); }
  .table-scroll:has(table.stacked) { overflow-x: visible; }
}

/* ---------------------------------------------------------- сводка */

.bar { height: 7px; border-radius: 999px; background: var(--surface-soft); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; background: var(--accent); }

.chart {
  display: flex; align-items: flex-end; gap: 10px;
  height: 190px; padding-top: 8px;
}
.chart-col {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: flex-end; gap: 6px; height: 100%; min-width: 0;
}
.chart-value { font-size: 12px; font-weight: 600; color: var(--muted); }
.chart-bar {
  width: 100%; max-width: 46px; min-height: 4px; border-radius: 8px 8px 4px 4px;
  background: linear-gradient(180deg, var(--accent), #8f7bff);
}
.chart-col:hover .chart-bar { filter: brightness(1.08); }
.chart-label { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* --- плотность таблицы списка: ФИО не должно рваться на три строки --- */
table.grid th, table.grid td { padding-left: 12px; padding-right: 12px; }
table.grid td .person { min-width: 215px; }
.person-name { display: block; }
table.grid td:nth-child(1) { padding-right: 0; }
.content { padding-left: 10px; }

/* ---------------------------------------------------------- публичная анкета */

body.public { background: var(--bg); }
.public-wrap { max-width: 760px; margin: 0 auto; padding: 28px 20px 60px; }
.public-head { display: flex; align-items: center; gap: 11px; margin-bottom: 20px; }
.public-card { padding: 28px; }
.public-card .page-title { margin-bottom: 6px; }
.public-card .page-sub { margin-bottom: 22px; }
.public-foot {
  margin-top: 18px; text-align: center; color: var(--muted); font-size: 12px;
}

.price-box {
  padding: 9px 12px; border: 1px dashed var(--line); border-radius: var(--radius-sm);
  color: var(--muted); background: var(--surface-soft); font-size: 14px;
}
.price-box.filled {
  border-style: solid; border-color: var(--accent);
  background: var(--accent-soft); color: var(--accent); font-weight: 650;
}

input.invalid, select.invalid {
  border-color: var(--bad); background: var(--bad-soft);
}
.field-error { display: block; margin-top: 5px; font-size: 12px; color: var(--bad); }
label.checkbox.invalid-box { color: var(--bad); }

/* поле-ловушка: убрано из потока, но не display:none — иначе боты его узнают */
.trap {
  position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden;
}

.done { text-align: center; }
.done .summary-row { text-align: left; }
.done-mark {
  width: 62px; height: 62px; margin: 0 auto 16px; border-radius: 50%;
  background: var(--ok-soft); color: var(--ok); display: grid; place-items: center;
}

/* ---------------------------------------------------------- вложения */

.file-list { list-style: none; margin: 0 0 14px; padding: 0; }
.file-item {
  display: flex; align-items: flex-start; gap: 11px;
  padding: 11px 0; border-bottom: 1px solid var(--line);
}
.file-item:last-child { border-bottom: 0; }
.file-thumb {
  width: 46px; height: 46px; flex: 0 0 46px; border-radius: 9px;
  background: var(--surface-soft); border: 1px solid var(--line);
  display: grid; place-items: center; overflow: hidden; color: var(--muted);
}
.file-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-main { flex: 1; min-width: 0; }
.file-main .person-name { display: block; word-break: break-word; }
.file-item select { max-width: 100%; }

.reading {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  margin-top: 6px; padding: 6px 9px; border-radius: 8px;
  background: var(--ok-soft); color: var(--ok); font-size: 13px;
}
.reading b { font-variant-numeric: tabular-nums; }
.reading form { margin-left: auto; }
.reading button { padding: 3px 9px; font-size: 12px; }

/* ---------------------------------------------------------- метки групп */

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 6px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.tag-blue   { background: #eef2ff; color: #3538cd; border-color: #c7d0fe; }
.tag-green  { background: #e7f7ef; color: #08875d; border-color: #b9e6d0; }
.tag-amber  { background: #fff8eb; color: #b54708; border-color: #fedf9a; }
.tag-red    { background: #fef3f2; color: #b42318; border-color: #fecdc9; }
.tag-violet { background: #f5f0ff; color: #6927da; border-color: #ddd0fe; }
.tag-teal   { background: #eaf7f7; color: #0e7090; border-color: #b9e4ed; }
.tag-pink   { background: #fdf2fa; color: #c11574; border-color: #fbcfe8; }
.tag-slate  { background: #f2f4f7; color: #475467; border-color: #d0d5dd; }
