/* Mobile-first: крупные кнопки (минимум 48px), читаемо на солнце и ночью */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #14181f;
  --muted: #5b6573;
  --line: #dde2e8;
  --brand: #0b63c5;
  --brand-ink: #ffffff;
  --ok: #137a3a;
  --warn: #9a5b00;
  --danger: #b3261e;
  --radius: 12px;
  --tap: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --card: #181c22;
    --text: #e8ecf1;
    --muted: #9aa5b3;
    --line: #2a3038;
    --brand: #4c9bf0;
    --brand-ink: #071421;
    --ok: #4cc27a;
    --warn: #e0a440;
    --danger: #ef6a5f;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 20px; color: var(--brand); text-decoration: none; }
.who { margin-left: auto; text-align: right; font-weight: 600; line-height: 1.2; }
.who .role { display: block; font-size: 13px; font-weight: 400; color: var(--muted); }

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom));
}
h1 { font-size: 24px; margin: 4px 0 16px; }
h2 { font-size: 19px; margin: 20px 0 10px; }
p { margin: 0 0 10px; }
p:last-child { margin-bottom: 0; }
.muted { color: var(--muted); }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
}
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--tap);
  padding: 10px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--brand);
  color: var(--brand-ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn-secondary { background: transparent; color: var(--brand); border: 2px solid var(--brand); }
.btn:disabled { opacity: 0.55; }
.btn-link {
  min-height: var(--tap);
  padding: 8px;
  border: 0;
  background: none;
  color: var(--brand);
  font: inherit;
  cursor: pointer;
}

label { display: block; margin: 14px 0 6px; font-weight: 600; }
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: inherit;
  font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 3px solid var(--brand); outline-offset: 1px; }
.form-actions { margin-top: 20px; }
.errorlist { list-style: none; margin: 6px 0 0; padding: 0; color: var(--danger); font-size: 15px; }
.helptext { display: block; margin-top: 4px; color: var(--muted); font-size: 14px; }
.helptext ul { margin: 4px 0 0; padding-left: 18px; }

.messages { list-style: none; margin: 0 0 12px; padding: 0; }
.msg { margin-bottom: 8px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); }
.msg-success { border-color: var(--ok); }
.msg-warning { border-color: var(--warn); }
.msg-error { border-color: var(--danger); }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li + li { margin-top: 10px; }

/* ---------- этап 1: навигация, карточки, формы ---------- */
body.has-nav .page { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line);
}
.bottom-nav a {
  display: flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 56px; padding: 6px 2px; color: var(--muted); text-decoration: none; font-size: 15px; font-weight: 600;
}
.bottom-nav a.active { color: var(--brand); }
.bottom-nav .nav-add { color: var(--brand-ink); background: var(--brand); margin: 6px; border-radius: var(--radius); }
.count { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff; font-size: 12px; line-height: 20px; text-align: center; }

a { color: var(--brand); }
.btn + .btn, .actions > * + * { margin-top: 10px; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-link.big { font-size: 30px; line-height: 1; padding: 4px 12px; text-decoration: none; }

.day-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.day-nav h1 { margin: 0; text-align: center; font-size: 22px; }
.chips-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0; }
.chips-row input[type=date], .chips-row input[type=number] { flex: 1 1 140px; width: auto; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 8px 14px;
  border: 1px solid var(--line); border-radius: 22px; background: var(--card); color: var(--text);
  font: inherit; text-decoration: none; cursor: pointer; margin: 0;
}
.chip input { width: auto; min-height: 0; margin: 0; }
/* Два правила, а не одно: браузер без :has() отбросил бы и .chip-on */
.chip-on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--card)); font-weight: 600; }
.chip:has(input:checked) { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 14%, var(--card)); font-weight: 600; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 400; }
.check input { width: 22px; min-height: 22px; }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.search-row { display: flex; gap: 8px; }
.search-row .btn { width: auto; flex: 0 0 auto; }

.group-head { margin-top: 22px; }
.order-row, .client-row { display: block; color: inherit; text-decoration: none; }
.row-top { display: flex; align-items: baseline; gap: 10px; }
.row-top .client { flex: 1; }
.row-top .time { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 48px; }
.row-top .sum { font-weight: 700; white-space: nowrap; }
.row-sub { margin-top: 2px; }
.client-row .muted { display: block; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.tag { padding: 2px 8px; border-radius: 8px; background: var(--bg); font-size: 14px; }
.tag-strong { font-weight: 700; }
.badge { padding: 2px 8px; border-radius: 8px; font-size: 14px; border: 1px solid var(--line); }
.badge-planned { border-color: var(--brand); color: var(--brand); }
.badge-delivered, .badge-ok { border-color: var(--ok); color: var(--ok); }
.badge-cancelled { border-color: var(--muted); color: var(--muted); }
.badge-warn { border-color: var(--warn); color: var(--warn); }
.badge-info { border-color: var(--brand); color: var(--brand); }
.is-cancelled { opacity: 0.6; }
.is-cancelled .client, .is-cancelled strong { text-decoration: line-through; }
.text-warn { color: var(--warn); }
.text-ok { color: var(--ok); }
.card.warn { border-color: var(--warn); }

details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
details.card > summary { margin: -4px 0; }
.close-box > summary { list-style: none; justify-content: center; margin-top: 10px; }
.close-box > summary::-webkit-details-marker { display: none; }
.close-box[open] > summary { opacity: 0.6; }
.close-box form { margin-top: 10px; }
.delivery .two-cols { margin-top: 10px; }
.delivery.is-done { opacity: 0.75; }
.done-line { margin-top: 10px; font-weight: 600; color: var(--ok); }
.note { margin-top: 6px; padding: 8px 10px; border-left: 3px solid var(--warn); background: var(--bg); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 12px; margin: 8px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.price-box { display: grid; gap: 4px; margin: 14px 0; padding: 12px; border-radius: 10px; background: var(--bg); }
.price-total { font-size: 20px; font-weight: 700; }
.journal .changes { margin: 6px 0 0; padding-left: 18px; }
.journal .is-new { border-color: var(--brand); }

/* ---------- изменение №1: заказ одним экраном ---------- */
.lookup { margin-top: 8px; }
.lookup .chips-row { margin: 6px 0 0; }
.confirm-box p { margin: 10px 0 6px; }
.confirm-box .check { margin: 8px 0; align-items: flex-start; }
.confirm-box .check input { flex: 0 0 auto; margin-top: 2px; }
.note-line { display: block; font-size: 14px; }
.confirm-items { margin: 0 0 6px; padding-left: 18px; }
.date-other { display: flex; align-items: center; gap: 8px; }
.date-other input { flex: 1; width: auto; }
.week-chips .chip { min-width: 72px; justify-content: center; }

/* ---------- этап 2: деньги ---------- */
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.btn-grid.three { grid-template-columns: repeat(3, 1fr); }
.btn-grid > .btn, .btn-grid > form > .btn { margin-top: 0; }
.btn-grid > form { margin: 0; }
.cash-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; color: inherit; text-decoration: none; }
.cash-row .who-name { flex: 1; font-weight: 600; }
.cash-row .sum { font-weight: 700; white-space: nowrap; }
.cash-row .note-line { flex-basis: 100%; }
.to-check .check-item + .check-item { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.list-gap { margin-top: 12px; }
.startup .share-line { display: flex; justify-content: space-between; gap: 10px; }
.total-line { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
