:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #111113;
  --muted: #6e6e73;
  --line: rgba(60, 60, 67, .16);
  --fill: rgba(118, 118, 128, .12);
  --accent: #1d5fd1;
  --accent-text: #ffffff;
  --ok: #1f8a4c;
  --warn: #b25b00;
  --bad: #c62828;
  --warn-bg: #fff4e0;
  --bad-bg: #fdecec;
  --ok-bg: #e7f6ec;
  --radius: 14px;
  --tab-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --muted: #98989f;
    --line: rgba(84, 84, 88, .55);
    --fill: rgba(118, 118, 128, .24);
    --accent: #4c8dff;
    --ok: #4cc77a;
    --warn: #ffb547;
    --bad: #ff6b6b;
    --warn-bg: #2d2210;
    --bad-bg: #321515;
    --ok-bg: #12291b;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* ---------- каркас ---------- */
:root { --bar-h: 46px; }
.screen {
  min-height: 100%;
  padding: 0 16px calc(var(--safe-b) + 96px);
  max-width: 640px;
  margin: 0 auto;
}
/* закреплённая верхняя строка разделов */
.topbar {
  position: sticky; top: 0; z-index: 25;
  display: flex; align-items: center;
  height: calc(var(--safe-t) + var(--bar-h)); padding-top: var(--safe-t);
  margin: 0 -16px; padding-left: 16px; padding-right: 16px;
  background: var(--bg);
  border-bottom: .5px solid transparent;
  transition: background .2s, border-color .2s;
}
.topbar.scrolled {
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom-color: var(--line);
}
.topbar-title {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: 12px;
  font-size: 17px; font-weight: 600; opacity: 0; transition: opacity .2s; pointer-events: none;
}
.topbar.scrolled .topbar-title { opacity: 1; }
.back {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: none; color: var(--accent); font-size: 17px;
  padding: 10px 12px 10px 0; margin-left: -2px; position: relative; z-index: 1;
}
.back-ic { display: inline-flex; }

/* ---------- главный экран с плитками ---------- */
/* Главный экран целиком помещается на экран любого iPhone: размеры зависят от высоты экрана (dvh) */
.home {
  min-height: 100vh; min-height: 100dvh;
  max-width: 520px; margin: 0 auto;
  padding: calc(var(--safe-t) + clamp(10px, 2.5dvh, 24px)) 20px calc(var(--safe-b) + clamp(8px, 2dvh, 24px));
  display: flex; flex-direction: column; justify-content: center;
}
.home-head { text-align: center; margin: 0 4px clamp(12px, 3.2dvh, 30px); }
.brand-logo { display: block; width: clamp(140px, 27dvh, 220px); max-width: 70%; height: auto; margin: 0 auto; }
@media (prefers-color-scheme: dark) { .brand-logo { filter: invert(1); } } /* чёрный логотип — белым в тёмной теме */
.home-hello { font-size: clamp(18px, 2.8dvh, 22px); font-weight: 600; letter-spacing: -.01em; margin-top: clamp(8px, 2.6dvh, 22px); }
.home-foot { margin-top: clamp(10px, 3dvh, 36px); color: var(--muted); font-size: 14px; text-align: center; }
.login-logo { width: 240px; margin-bottom: 24px; }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: clamp(10px, 1.7dvh, 14px); }
.tile {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: clamp(8px, 1.6dvh, 14px);
  min-height: clamp(96px, 18dvh, 150px); padding: 12px; border: 0; border-radius: 22px; text-align: center;
  background: var(--card); color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 6px 20px rgba(0, 0, 0, .05);
  transition: transform .12s ease;
}
.tile:active { transform: scale(.97); }
.tile.wide { grid-column: 1 / -1; }
@media (max-height: 720px) { /* невысокие экраны: iPhone SE, Safari с панелями */
  .tile-ic, .tile.wide .tile-ic { width: 46px; height: 46px; border-radius: 13px; }
  .tile-ic svg, .tile.wide .tile-ic svg { width: 26px; height: 26px; }
  .tile-label, .tile.wide .tile-label { font-size: 18px; }
  .tile-sub { font-size: 13px; }
}
@media (max-height: 600px) { /* совсем низкие: iPhone SE в Safari с панелями */
  .tile { min-height: 84px; gap: 6px; padding: 10px; }
  .tile-sub { display: none; }
  .home-hello { font-size: 17px; }
}
.tile-ic {
  width: 58px; height: 58px; border-radius: 16px; display: grid; place-items: center; flex-shrink: 0;
  color: #fff; background: var(--tile);
}
.tile.wide .tile-ic { width: 68px; height: 68px; border-radius: 18px; }
.tile-ic svg { width: 32px; height: 32px; }
.tile.wide .tile-ic svg { width: 38px; height: 38px; }
.tile-text { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.tile-label { font-size: 21px; font-weight: 700; letter-spacing: -.01em; }
.tile.wide .tile-label { font-size: 24px; }
.tile-sub { font-size: 14px; color: var(--muted); }
.tile-blue { --tile: #1d5fd1; }
.tile-green { --tile: #1f9d55; }
.tile-orange { --tile: #e8730c; }
.tile-amber { --tile: #c99400; }
.tile-purple { --tile: #7a4fd6; }
@media (prefers-color-scheme: dark) {
  .tile { box-shadow: none; }
  .tile-blue { --tile: #3b7cf0; }
  .tile-green { --tile: #2fb36a; }
  .tile-orange { --tile: #f08a2c; }
  .tile-amber { --tile: #d9a514; }
  .tile-purple { --tile: #9068ea; }
}
.title { font-size: 32px; font-weight: 700; letter-spacing: -.02em; margin: 14px 4px 14px; }
.subtitle { color: var(--muted); font-size: 15px; margin: -8px 4px 14px; }
.section-h { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .03em; margin: 22px 16px 7px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: center;
  padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--card) 85%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: .5px solid var(--line);
}
.tabbar-in { display: flex; width: 100%; max-width: 640px; }
.tab {
  flex: 1; height: var(--tab-h); border: 0; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: 11px; font-weight: 500;
}
.tab svg { width: 26px; height: 26px; }
.tab.on { color: var(--accent); }

/* ---------- списки ---------- */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  min-height: 48px; padding: 11px 16px; border: 0; background: none; text-align: left;
  position: relative;
}
.row + .row::before {
  content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: .5px solid var(--line);
}
button.row:active { background: var(--fill); }
.row-main { flex: 1; min-width: 0; }
.row-title { overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 14px; margin-top: 2px; }
.row-end { color: var(--muted); font-size: 15px; text-align: right; flex-shrink: 0; }
.chev { color: var(--muted); opacity: .6; flex-shrink: 0; }
.empty { color: var(--muted); text-align: center; padding: 28px 16px; font-size: 15px; }

/* ---------- поля ---------- */
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--fill); border-radius: 11px; padding: 0 12px; height: 40px; margin-bottom: 12px;
}
.search svg { width: 18px; height: 18px; color: var(--muted); flex-shrink: 0; }
.search input { flex: 1; border: 0; background: none; outline: none; height: 100%; min-width: 0; font-size: 17px; }
.search input::placeholder { color: var(--muted); }
.field {
  width: 100%; border: 0; outline: none; background: var(--card); border-radius: var(--radius);
  padding: 13px 16px; font-size: 17px;
}
textarea.field { min-height: 120px; resize: vertical; line-height: 1.4; }

/* ---------- кнопки ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 50px; border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-text); font-weight: 600; font-size: 17px;
  text-decoration: none;
}
.btn svg { width: 22px; height: 22px; flex-shrink: 0; }
.btn:active { opacity: .8; }
.btn:disabled { opacity: .45; }
.btn.secondary { background: var(--card); color: var(--accent); }
.btn.plain { background: none; color: var(--accent); font-weight: 500; height: 44px; }
.btn.danger { background: none; color: var(--bad); font-weight: 500; height: 44px; }
.btn + .btn { margin-top: 10px; }
.link { border: 0; background: none; color: var(--accent); font-size: 17px; padding: 6px 4px; }

.dock {
  position: fixed; left: 0; right: 0; z-index: 15;
  bottom: 0;
  padding: 10px 16px calc(var(--safe-b) + 10px);
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.dock-in { max-width: 608px; margin: 0 auto; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 0; background: var(--card); border-radius: 999px; padding: 9px 15px; font-size: 16px;
  font-variant-numeric: tabular-nums;
}
.chip.on { background: var(--accent); color: var(--accent-text); }
.chip:active { opacity: .7; }

/* ---------- карточки ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 16px; }
.card + .card { margin-top: 12px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; font-variant-numeric: tabular-nums; }
.kv .k { color: var(--muted); }
.big { font-size: 28px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.note { border-radius: 12px; padding: 11px 14px; font-size: 15px; margin-top: 12px; }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.bad { background: var(--bad-bg); color: var(--bad); }
.note.ok { background: var(--ok-bg); color: var(--ok); }
.pill { display: inline-block; font-size: 13px; padding: 2px 8px; border-radius: 999px; background: var(--fill); color: var(--muted); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 15px; line-height: 1.45; }

/* ---------- позиции счёта ---------- */
.line-del {
  border: 0; background: none; color: var(--bad); width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; flex-shrink: 0;
}
.line-del svg { width: 22px; height: 22px; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px; }

/* ---------- количество ---------- */
.stepper { display: flex; align-items: center; gap: 10px; }
.stepper button {
  width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--fill); font-size: 24px; line-height: 1;
}
.stepper input { flex: 1; text-align: center; font-size: 22px; font-weight: 600; height: 44px; }

/* ---------- лист снизу ---------- */
.sheet-bg {
  position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .35);
  animation: fade .2s ease;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  top: calc(var(--safe-t) + 24px); /* лист на всю высоту: клавиатура iPhone не закрывает результаты */
  background: var(--bg); border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column;
  animation: up .28s cubic-bezier(.2, .9, .3, 1);
  max-width: 640px; margin: 0 auto;
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 12px 8px 16px; flex-shrink: 0;
}
.sheet-head h2 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; text-align: center; }
.sheet-head .link { min-width: 72px; }
.sheet-body { overflow-y: auto; padding: 4px 16px calc(var(--safe-b) + 20px); -webkit-overflow-scrolling: touch; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- прочее ---------- */
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2.5px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite; display: inline-block;
}
.loading { display: flex; justify-content: center; padding: 28px; color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; left: 50%; top: calc(var(--safe-t) + 12px); transform: translateX(-50%);
  z-index: 60; background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 15px; max-width: calc(100% - 32px); text-align: center;
  animation: fade .2s ease;
}

.done-mark {
  width: 64px; height: 64px; border-radius: 50%; background: var(--ok-bg); color: var(--ok);
  display: grid; place-items: center; margin: 24px auto 12px;
}
.done-mark svg { width: 34px; height: 34px; }
.center { text-align: center; }

.login { max-width: 380px; margin: 0 auto; padding: calc(var(--safe-t) + 15vh) 24px 40px; }
.login .logo {
  width: 76px; height: 76px; border-radius: 18px; display: block; margin: 0 auto 18px;
}
.login .field + .field { margin-top: 1px; border-top-left-radius: 0; border-top-right-radius: 0; }
.login .field:first-of-type { border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.err { color: var(--bad); font-size: 15px; margin: 12px 4px 0; min-height: 20px; }

/* ---------- просмотр PDF внутри приложения ---------- */
.pdfv {
  position: fixed; inset: 0; z-index: 70; background: var(--bg);
  display: flex; flex-direction: column; animation: up .25s cubic-bezier(.2, .9, .3, 1);
}
.pdfv-bar {
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
  padding: calc(var(--safe-t) + 6px) 12px 8px;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: .5px solid var(--line);
}
.pdfv-bar .link { min-width: 96px; font-weight: 600; padding: 10px 4px; }
.pdfv-title { flex: 1; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdfv-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 12px calc(var(--safe-b) + 16px); }
.pdfv-pages { max-width: 820px; margin: 0 auto; }
.pdfv-page { display: block; width: 100%; height: auto; background: #fff; border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12); margin-bottom: 12px; }

/* ---------- поля с подписью ---------- */
.fl { display: block; margin-top: 14px; }
.fl > span { display: block; color: var(--muted); font-size: 13px; margin: 0 4px 5px; }

/* ---------- весь список клиентов по алфавиту ---------- */
.picker { padding-right: 14px; } /* место под буквы справа */
.letter-h {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg); color: var(--muted);
  font-size: 15px; font-weight: 600; padding: 12px 16px 6px;
}
.screen .letter-h { top: calc(var(--safe-t) + var(--bar-h)); } /* буква группы — под закреплённой строкой */
.az {
  position: fixed; right: 0; top: 50%; transform: translateY(-50%); z-index: 12;
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 3px; touch-action: none; user-select: none; -webkit-user-select: none;
}
.az.in-sheet { z-index: 42; top: calc(50% + 12px); }
.az span {
  color: var(--accent); font-size: 11px; font-weight: 600; line-height: 1; padding: 1.5px 4px;
  cursor: pointer;
}
@media (max-height: 640px) { .az span { font-size: 9px; padding: 1px 4px; } }

.head-row { display: flex; align-items: center; justify-content: space-between; }
.head-row .title { margin-right: 8px; }
