:root {
  --bg: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f0efe9;
  --text: #1d2320;
  --muted: #66706b;
  --line: #dedcd3;
  --accent: #0f6b5c;
  --accent-hover: #0c594c;
  --accent-soft: #e2f0ec;
  --ok: #1d7a46;
  --ok-soft: #e3f3e8;
  --warn: #9a6200;
  --warn-soft: #fbf0d9;
  --err: #b3261e;
  --err-soft: #fbe5e3;
  --info: #25589c;
  --info-soft: #e5edf8;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 5%), 0 4px 16px rgb(0 0 0 / 4%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --surface: #1c211f;
    --surface-2: #232927;
    --text: #e7ebe9;
    --muted: #9aa5a0;
    --line: #333b38;
    --accent: #3fb39c;
    --accent-hover: #5cc4ae;
    --accent-soft: #1d3632;
    --ok: #5cc486;
    --ok-soft: #1c3226;
    --warn: #e0a940;
    --warn-soft: #3a2f18;
    --err: #f07b72;
    --err-soft: #3d2120;
    --info: #7fa9e6;
    --info-soft: #1e2a3b;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 26px; line-height: 1.25; margin: 8px 0 6px; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0 0 10px; }
code { font: 13px/1.4 ui-monospace, Consolas, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small, small { font-size: 13px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }
.empty { color: var(--muted); padding: 28px 0; text-align: center; }
.err { color: var(--err); margin: 6px 0; min-height: 0; }
.err:empty { display: none; }
.ok-text { color: var(--ok); }
.danger-text { color: var(--err) !important; }

/* Кнопки и поля */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  background: var(--accent); color: #fff; border: 1px solid var(--accent);
  border-radius: 8px; padding: 9px 16px; min-height: 40px;
}
button:hover, .button:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost, .button.ghost { background: transparent; color: var(--accent); border-color: var(--line); }
button.ghost:hover, .button.ghost:hover { background: var(--accent-soft); }
button.danger { background: var(--err); border-color: var(--err); }
button.small, .button.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
button.tab { background: transparent; color: var(--muted); border: 0; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 4px; min-height: 36px; white-space: nowrap; }
button.tab:hover { background: transparent; color: var(--text); }
button.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.count { font-weight: 500; font-size: 12px; background: var(--surface-2); color: var(--muted); border-radius: 10px; padding: 0 7px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); margin: 0 0 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-height: 40px; width: 100%;
}
textarea { resize: vertical; }
input[readonly] { background: var(--surface-2); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input.code { font-size: 22px; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.req { color: var(--err); font-style: normal; }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }

/* Шапка */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand small { display: block; color: var(--muted); font-size: 12px; line-height: 1.1; }
.brand b { display: block; line-height: 1.2; }
.brand.big { justify-content: center; margin-bottom: 18px; font-size: 18px; }
.logo {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 13px; letter-spacing: .02em;
}
.top nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.top nav a { color: var(--muted); text-decoration: none; padding: 7px 12px; border-radius: 8px; white-space: nowrap; font-weight: 500; }
.top nav a:hover { color: var(--text); background: var(--surface-2); }
.top nav a.on { color: var(--accent); background: var(--accent-soft); }
.who { display: flex; align-items: center; gap: 12px; }
.who > span { text-align: right; line-height: 1.2; }
.who small { display: block; color: var(--muted); }

main { max-width: 1120px; margin: 0 auto; padding: 18px 24px 60px; }
main.center { max-width: 460px; padding-top: 8vh; }
.sub { color: var(--muted); margin: 0 0 18px; max-width: 760px; }
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 0 0 16px; }
.back { margin-left: auto; text-decoration: none; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.narrow { max-width: 420px; margin: 0 auto; }
section { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.cols > section { margin-bottom: 16px; }

.badge { display: inline-block; font-size: 12.5px; font-weight: 600; padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
.badge.grey { background: var(--surface-2); color: var(--muted); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }

.note { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; background: var(--surface-2); border: 1px solid var(--line); }
.note.info { background: var(--info-soft); border-color: transparent; }
.note.ok { background: var(--ok-soft); border-color: transparent; }
.note.warn { background: var(--warn-soft); border-color: transparent; }
.note.err { background: var(--err-soft); border-color: transparent; color: var(--err); }
.note p { margin: 4px 0 10px; }

.tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--line); margin-bottom: 12px; flex-wrap: wrap; }
.row.between > .tabs { margin-bottom: 0; flex: 1; }
.row.between { margin-bottom: 14px; }

/* Таблицы */
table.list { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th { text-align: left; font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 10px 12px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
table.list td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr[tabindex] { cursor: pointer; }
table.list tbody tr[tabindex]:hover { background: var(--accent-soft); }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Заявка */
.docs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.doc { border: 1px dashed var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.doc.has { border-style: solid; }
.doc-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.doc-head span { font-size: 12.5px; }
.files { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.files li { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }
.files a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.doc label.button { margin: auto 0 0; flex-direction: row; color: var(--accent); }

.fields { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0 18px; }
.fields fieldset { border: 0; padding: 0; margin: 0 0 6px; }
.fields legend { font-weight: 600; margin-bottom: 8px; font-size: 14px; }
.fields > .row { grid-column: 1 / -1; }

.checks { list-style: none; margin: 0; padding: 0; }
.checks li { display: flex; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.checks li:last-child { border-bottom: 0; }
.checks small { display: block; color: var(--muted); }
.checks .ic { flex: 0 0 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.checks .ok .ic { background: var(--ok-soft); color: var(--ok); }
.checks .fail .ic { background: var(--err-soft); color: var(--err); }
.checks .fail small { color: var(--err); }
.checks .wait .ic { background: var(--surface-2); color: var(--muted); }

.draft { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; margin: 0 0 10px; }
.draft dt { color: var(--muted); font-size: 13px; }
.draft dd { margin: 0; word-break: break-word; font-variant-numeric: tabular-nums; }

.history { list-style: none; padding: 0; margin: 0; font-size: 13.5px; }
.history li { padding: 5px 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }
.history small { display: block; color: var(--muted); margin-left: 2px; }

.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 200px; gap: 0 12px; }

/* Банк, сроки, чек возврата */
.bankbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font-size: 14px; }
.attention { display: block; margin-top: 4px; color: var(--warn); font-weight: 600; }
.overdue { color: var(--err); font-weight: 600; }
section.task { border-color: var(--warn); box-shadow: 0 0 0 1px var(--warn) inset; }
.note .row { margin-top: 10px; }
.grid-payer { display: grid; grid-template-columns: 2fr 1fr 1.4fr 1fr 1.4fr; gap: 0 12px; }
h2.mt { margin-top: 22px; }
@media (max-width: 820px) { .grid-payer { grid-template-columns: 1fr; } }

/* Переписка */
.mails { list-style: none; margin: 0 0 14px; padding: 0; }
.mails > li { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
.mails > li.in { background: var(--info-soft); border-color: transparent; }
.mails summary { cursor: pointer; margin-top: 4px; }
.mailtext { white-space: pre-wrap; margin: 6px 0 0; font-size: 14px; max-height: 320px; overflow: auto; }
.mails select { width: auto; min-height: 30px; padding: 2px 6px; font-size: 13px; }
.compose textarea { margin-bottom: 8px; }
label.inline { flex-direction: row; align-items: center; margin: 0; }
label.inline input { width: auto; min-height: 0; border: 0; padding: 0; }
input.no { width: 80px; }
details.tpl-letter { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; }
details.tpl-letter summary { cursor: pointer; font-weight: 600; }
details.tpl-letter label { margin-top: 10px; }

/* Выбор вида заявки, шаблоны */
.choices { display: flex; flex-direction: column; gap: 10px; margin: 12px 0 16px; }
button.choice { flex-direction: column; align-items: flex-start; text-align: left; gap: 2px; background: var(--surface); color: var(--text); border-color: var(--line); padding: 12px 14px; }
button.choice:hover { background: var(--accent-soft); border-color: var(--accent); }
button.choice small { color: var(--muted); font-weight: 400; }
.tpl { margin-bottom: 16px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.tpl label { width: 100%; font-weight: 600; color: var(--text); font-size: 14px; }

/* Окно и уведомления */
dialog { border: 0; border-radius: 14px; padding: 22px; width: min(440px, calc(100vw - 32px)); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgb(0 0 0 / 25%); }
dialog::backdrop { background: rgb(0 0 0 / 40%); }
dialog textarea, dialog input { margin: 8px 0 4px; }
#toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 20; width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--text); color: var(--bg); box-shadow: 0 6px 20px rgb(0 0 0 / 20%); font-size: 14px; }
.toast.err { background: var(--err); color: #fff; }
.toast.info { background: var(--info); color: #fff; }

/* Телефон */
@media (max-width: 820px) {
  .top { padding: 10px 16px; gap: 10px; }
  .top nav { order: 3; flex-basis: 100%; }
  .who { margin-left: auto; }
  main { padding: 14px 16px 60px; }
  h1 { font-size: 22px; }
  .cols, .docs, .fields, .grid3 { grid-template-columns: 1fr; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; gap: 14px; }
  .row.between > .tabs { flex-basis: 100%; }
  .row.between > button { width: 100%; }
  .badge { white-space: normal; }
  .meta .back { margin-left: 0; }
  section { padding: 14px; }
  .draft { grid-template-columns: 1fr; }
  .draft dd { margin-bottom: 6px; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list thead { display: none; }
  table.list tr { border-bottom: 1px solid var(--line); padding: 8px 0; }
  table.list td { border: 0; padding: 3px 12px; display: flex; gap: 10px; }
  table.list td[data-l]::before { content: attr(data-l); color: var(--muted); font-size: 12.5px; min-width: 96px; }
}
