/* Платим · Mini App. Две темы на одних токенах: light = палитра B Paper, dark = палитра A Graphite. */
:root {
  --bg: #F4F4F6; --card: #FFFFFF; --chip: #EFEFF2; --line: #E6E7EB;
  --text: #131416; --muted: #6B7078; --accent: #131416; --accent-text: #FFFFFF;
  --ok: #1F9D5B; --warn: #B8730A; --danger: #C0392B; --ok-bg: #E8F5EE; --warn-bg: #FBF1E0; --danger-bg: #FBE9E7;
  --radius: 18px; --radius-s: 12px; --shadow: none;
  --font: Inter, -apple-system, "SF Pro Text", system-ui, Roboto, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0E0F12; --card: #17191E; --chip: #23262D; --line: #272A31;
  --text: #F4F5F7; --muted: #8B9098; --accent: #F4F5F7; --accent-text: #0E0F12;
  --ok: #3FB77A; --warn: #E0A33B; --danger: #E06C5B; --ok-bg: #16281F; --warn-bg: #2B2416; --danger-bg: #2E1A17;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body { font-family: var(--font); font-size: 15px; line-height: 1.35; -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 0.8; }
input:focus, textarea:focus, select:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input, textarea { outline-offset: 0; }
.field input:focus, .field textarea:focus, .field select:focus { outline: none; }
.field:focus-within { border-color: var(--text); }

#app { min-height: 100vh; display: flex; flex-direction: column; }
.screen { flex: 1; display: flex; flex-direction: column; padding: 0 16px calc(24px + env(safe-area-inset-bottom)); animation: fade .18s ease; }
.screen.with-tabbar { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.boot { padding: 48px 24px; text-align: center; color: var(--muted); }
.boot h2 { color: var(--text); margin: 0 0 8px; font-size: 20px; }

/* шапка экрана */
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px 0 8px; min-height: 60px; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.3px; flex: 1; }
.topbar .sub { font-size: 13px; color: var(--muted); font-weight: 500; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line); background: var(--card); color: var(--text); display: flex; align-items: center; justify-content: center; padding: 0; flex-shrink: 0; }
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn.sm { width: 40px; height: 40px; border-radius: 12px; background: var(--chip); border: 0; }
.icon-btn.sm svg { width: 18px; height: 18px; }

/* карточки и списки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.card + .card, .section + .section { margin-top: 12px; }
.section { margin-top: 20px; }
.section-title { display: flex; align-items: center; justify-content: space-between; font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.section-title a, .section-title button { font-size: 13px; font-weight: 500; color: var(--muted); background: none; border: 0; padding: 0; }
.label { font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 8px; display: block; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.45; }
.hint.center { text-align: center; }
.muted { color: var(--muted); }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-bottom: 1px solid var(--line); background: none; border-left: 0; border-right: 0; border-top: 0; width: 100%; text-align: left; }
.row:last-child { border-bottom: 0; }
.row .ico { width: 38px; height: 38px; border-radius: 12px; background: var(--chip); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.row .ico svg { width: 18px; height: 18px; }
.row .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .title { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.row .amount { font-size: 14px; font-weight: 600; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); font-size: 14px; }

.status { font-size: 11px; font-weight: 600; }
.status.ok { color: var(--ok); } .status.warn { color: var(--warn); } .status.bad { color: var(--danger); } .status.muted { color: var(--muted); }
.badge { display: inline-flex; align-items: center; padding: 4px 9px; border-radius: 8px; font-size: 12px; font-weight: 600; background: var(--chip); }
.badge.ok { background: var(--ok-bg); color: var(--ok); } .badge.warn { background: var(--warn-bg); color: var(--warn); } .badge.bad { background: var(--danger-bg); color: var(--danger); }

/* баланс */
.balance-card { background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 22px 20px 18px; display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.balance-card .big { display: flex; align-items: baseline; gap: 8px; }
.balance-card .big b { font-size: 38px; font-weight: 700; letter-spacing: -1px; line-height: 1; }
.balance-card .big span { font-size: 18px; font-weight: 600; color: var(--muted); }
.balance-card .actions { display: flex; gap: 10px; margin-top: 14px; }

/* кнопки */
.btn { height: 48px; border-radius: 14px; border: 0; padding: 0 16px; font-size: 15px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px; background: var(--chip); color: var(--text); flex: 1; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.lg { height: 56px; border-radius: 16px; font-size: 16px; width: 100%; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.sm { height: 36px; border-radius: 10px; padding: 0 14px; font-size: 13px; flex: none; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.btn-row { display: flex; gap: 8px; }
.cta { margin-top: auto; padding-top: 16px; display: flex; flex-direction: column; gap: 12px; }

/* плитки операций */
.tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.tile { height: 92px; border-radius: 18px; background: var(--card); border: 1px solid var(--line); color: var(--text); display: flex; flex-direction: column; justify-content: space-between; padding: 14px; text-align: left; position: relative; }
.tile svg { width: 22px; height: 22px; }
.tile span { font-size: 13px; font-weight: 600; }
.tile .soon { position: absolute; top: 10px; right: 10px; font-size: 10px; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; color: var(--muted); background: var(--chip); padding: 3px 6px; border-radius: 6px; }
.tile.disabled { opacity: .55; }

/* чипы реквизитов и пресеты */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; height: 44px; padding: 0 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); color: var(--text); display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 1px; }
.chip.selected { border: 1.5px solid var(--accent); }
.chip.new { border-style: dashed; background: var(--bg); color: var(--muted); flex-direction: row; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.chip small { font-size: 11px; font-weight: 600; color: var(--muted); }
.chip b { font-size: 13px; font-weight: 600; }
.presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.presets button { height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--text); font-size: 14px; font-weight: 600; padding: 0; }
.presets button.selected { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.segmented { display: grid; gap: 6px; background: var(--chip); padding: 4px; border-radius: 14px; }
.segmented button { height: 38px; border: 0; border-radius: 11px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; padding: 0; }
.segmented button.selected { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.06); }

/* поля */
.field { display: flex; align-items: center; min-height: 54px; padding: 0 16px; border-radius: 16px; background: var(--card); border: 1px solid var(--line); gap: 10px; }
.field input, .field select, .field textarea { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 17px; font-weight: 500; padding: 14px 0; }
.field select { appearance: none; -webkit-appearance: none; }
.field textarea { resize: vertical; min-height: 120px; font-size: 15px; line-height: 1.4; }
.field .addon { font-size: 12px; font-weight: 600; padding: 5px 9px; border-radius: 8px; background: var(--chip); }
.field > svg { width: 18px; height: 18px; flex: 0 0 auto; color: var(--muted); pointer-events: none; }
/* стрелка у select рисуется CSS, а не SVG: иконка без размера на iOS растягивалась на всё поле */
.select-field { position: relative; }
.select-field select { padding-right: 28px; height: 52px; }
.select-field::after { content: ""; position: absolute; right: 18px; top: 50%; width: 9px; height: 9px; margin-top: -7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); pointer-events: none; }
.amount { display: flex; align-items: baseline; gap: 6px; padding: 10px 2px 0; }
.amount input { width: 60%; border: 0; background: transparent; font-size: 36px; font-weight: 700; letter-spacing: -1px; padding: 0; }
.amount span { font-size: 22px; font-weight: 600; color: var(--muted); }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* расчёт */
.quote { display: flex; flex-direction: column; gap: 10px; }
.quote .line { display: flex; justify-content: space-between; font-size: 14px; }
.quote .line .k { color: var(--muted); }
.quote .line.total { font-size: 15px; } .quote .line.total .k { color: var(--text); font-weight: 600; } .quote .line.total .v { font-weight: 700; }
.quote .line.rest { font-size: 13px; } .quote .line.rest .v { color: var(--muted); }
.quote hr { border: 0; border-top: 1px solid var(--line); margin: 0; }
.quote.pending { opacity: .6; }

/* результат */
.result { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 36px 8px 16px; gap: 10px; }
.result .mark { width: 72px; height: 72px; border-radius: 36px; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.result .mark.ok { background: var(--ok-bg); color: var(--ok); } .result .mark.warn { background: var(--warn-bg); color: var(--warn); } .result .mark.bad { background: var(--danger-bg); color: var(--danger); }
.result .mark svg { width: 34px; height: 34px; }
.result h2 { margin: 0; font-size: 22px; }
.result p { margin: 0; color: var(--muted); font-size: 14px; }
.result .sum { font-size: 32px; font-weight: 700; letter-spacing: -1px; }

/* таббар */
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); padding: 8px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--bg); z-index: 5; }
.tabbar a { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 0; color: var(--muted); font-size: 11px; font-weight: 500; }
.tabbar a.active { color: var(--text); font-weight: 600; }
.tabbar svg { width: 22px; height: 22px; }

/* тост и листы */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(96px + env(safe-area-inset-bottom)); background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-size: 14px; font-weight: 500; z-index: 20; animation: fade .18s ease; text-align: center; }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 15; display: flex; align-items: flex-end; }
.sheet { width: 100%; background: var(--bg); border-radius: 24px 24px 0 0; padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); max-height: 85vh; overflow: auto; }
.sheet .grip { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 14px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv .k { color: var(--muted); } .kv .v { text-align: right; font-weight: 500; word-break: break-all; }

/* настройки */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px; }
.setting .t { font-size: 15px; font-weight: 500; } .setting .d { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* админ */
.admin-tabs { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 8px 0 14px; }
.admin-tabs::-webkit-scrollbar { display: none; }
.admin-tabs button { flex-shrink: 0; height: 38px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: 13px; font-weight: 600; }
.admin-tabs button.selected { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.order-card { display: flex; flex-direction: column; gap: 8px; }
.order-card .head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.order-card .head b { font-size: 15px; }
.order-card .meta { font-size: 13px; color: var(--muted); }
.order-card code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--chip); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.order-card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.html-block { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.html-block code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: var(--chip); padding: 1px 5px; border-radius: 5px; }
.setting-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .name { font-size: 13px; color: var(--muted); }
.setting-row input, .setting-row select { width: 120px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); padding: 0 10px; font-size: 14px; }
.skeleton { background: linear-gradient(90deg, var(--chip) 25%, var(--line) 37%, var(--chip) 63%); background-size: 400% 100%; animation: shimmer 1.2s infinite; border-radius: 12px; min-height: 18px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
