/* Экран P2P-помощника. Вид — вариант A «Пульт» (docs/decisions.md).
   Цвета — палитра владельца (docs/decisions.md, «палитра „деньги“»); тема Telegram
   выбирает только светлую или тёмную (data-theme из app.js), её цвета не подставляются. */
:root {
  --bg: #f2f0e9;
  --card: #ffffff;
  --nav: #ffffff;
  --text: #0f1a2c;
  --hint: #5b6474;
  --link: #1b3a6b;
  --accent: #8a6800;
  --button: #0f2547;
  --button-text: #f3d98b;
  --pos: #0f7a4a;
  --bar: var(--pos);
  --neg: #b0182c;
  --neg-soft: #fbe7ea;
  --warn: #8f5f00;
  --warn-soft: #fbf1d9;
  --soft: #e9eef7;
  --track: #e1e3e8;
  --line: #e6e2d8;
  --field: #f8f7f3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #050506;
    --card: #11151d;
    --nav: #0b0e14;
    --text: #fbfaf6;
    --hint: #9aa3b2;
    --link: #e2bf55;
    --accent: #d4af37;
    --button: #d4af37;
    --button-text: #0b0b0c;
    --pos: #3ccf7f;
    --bar: var(--pos);
    --neg: #ff5468;
    --neg-soft: #3b0f17;
    --warn: #ffb02e;
    --warn-soft: #36290b;
    --soft: #18243a;
    --track: #252c39;
    --line: #1f2531;
    --field: #0c1017;
  }
}

/* Тема Telegram важнее системной: app.js ставит data-theme по Telegram.WebApp.colorScheme. */
:root[data-theme="light"] {
  --bg: #f2f0e9;
  --card: #ffffff;
  --nav: #ffffff;
  --text: #0f1a2c;
  --hint: #5b6474;
  --link: #1b3a6b;
  --accent: #8a6800;
  --button: #0f2547;
  --button-text: #f3d98b;
  --pos: #0f7a4a;
  --bar: var(--pos);
  --neg: #b0182c;
  --neg-soft: #fbe7ea;
  --warn: #8f5f00;
  --warn-soft: #fbf1d9;
  --soft: #e9eef7;
  --track: #e1e3e8;
  --line: #e6e2d8;
  --field: #f8f7f3;
}
:root[data-theme="dark"] {
  --bg: #050506;
  --card: #11151d;
  --nav: #0b0e14;
  --text: #fbfaf6;
  --hint: #9aa3b2;
  --link: #e2bf55;
  --accent: #d4af37;
  --button: #d4af37;
  --button-text: #0b0b0c;
  --pos: #3ccf7f;
  --bar: var(--pos);
  --neg: #ff5468;
  --neg-soft: #3b0f17;
  --warn: #ffb02e;
  --warn-soft: #36290b;
  --soft: #18243a;
  --track: #252c39;
  --line: #1f2531;
  --field: #0c1017;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
.screen { min-height: 100vh; max-width: 560px; margin: 0 auto; }
.content { padding: 16px 16px calc(88px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
h1 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -0.2px; }
h2 { margin: 0; font-size: 17px; font-weight: 700; }
.card h2 { color: var(--accent); }
p { margin: 0; }
.muted { color: var(--hint); font-size: 13px; }
.pos { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
.nowrap { white-space: nowrap; }

/* Шапка экрана */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar .title { display: flex; flex-direction: column; gap: 2px; }

/* Кнопки и ссылки */
.btn { min-height: 44px; padding: 0 16px; border: 0; border-radius: 12px; background: var(--button); color: var(--button-text); font: inherit; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; text-decoration: none; }
.btn.secondary { background: var(--soft); color: var(--link); }
.btn.danger { background: var(--neg-soft); color: var(--neg); }
.btn.wide { width: 100%; }
.link { color: var(--link); text-decoration: none; display: inline-flex; align-items: center; gap: 2px; min-height: 44px; background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Карточки */
.card { background: var(--card); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat .value { font-size: 22px; font-weight: 700; white-space: nowrap; }
.stat .value.big { font-size: 36px; letter-spacing: -0.5px; }
.divider { height: 1px; background: var(--line); }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

/* Полосы лимитов */
.limit { display: flex; flex-direction: column; gap: 6px; }
.limit-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.limit-name { font-weight: 600; }
.limit-pct { font-weight: 700; white-space: nowrap; }
.bar { height: 8px; border-radius: 4px; background: var(--track); overflow: hidden; }
.bar > span { display: block; height: 100%; max-width: 100%; background: var(--bar); }
.bar.warn > span { background: var(--warn); }
.bar.neg > span { background: var(--neg); }

/* Списки */
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list > li { border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; min-height: 44px; color: inherit; text-decoration: none; width: 100%; background: none; border: 0; font: inherit; text-align: left; cursor: pointer; }
.row .main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; }
.row .name { font-weight: 600; }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 8px; background: var(--soft); color: var(--link); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.neg { background: var(--neg-soft); color: var(--neg); }

/* Формы */
form { display: flex; flex-direction: column; gap: 12px; margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--hint); }
/* 16px: при меньшем шрифте iOS увеличивает страницу при нажатии на поле. */
input, select, textarea { font: inherit; font-size: 16px; color: var(--text); background: var(--field); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; padding: 8px 12px; width: 100%; }
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--link); outline-offset: 1px; }
/* iOS сам задаёт полям даты и времени минимальную ширину и переключает их на content-box,
   поэтому поле на всю ширину вылезало за край карточки. appearance: none выключает это. */
input[type="time"], input[type="date"], input[type="datetime-local"] { -webkit-appearance: none; appearance: none; box-sizing: border-box; width: 100%; max-width: 100%; min-width: 0; }
input::-webkit-date-and-time-value { text-align: left; min-height: 1lh; }
.field, .grid2 > * { min-width: 0; }
select { -webkit-appearance: none; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--hint) 50%), linear-gradient(135deg, var(--hint) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 12px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 32px; }

/* Лимиты по банкам в настройках */
.bank-row { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.bank-row:last-child { border-bottom: 0; }
.bank-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.bank-head .name { font-weight: 600; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 0; }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.seg label { display: flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 10px; background: var(--field); border: 1px solid var(--line); cursor: pointer; font-weight: 600; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg input:checked + span { color: var(--button-text); }
.seg label:has(input:checked) { background: var(--button); border-color: var(--button); color: var(--button-text); }
details > summary { cursor: pointer; color: var(--link); min-height: 44px; display: flex; align-items: center; }
.stack { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.seg4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; background: var(--card); border-radius: 12px; padding: 4px; }
.seg4 button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: var(--text); font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; }
.seg4 button.on { background: var(--button); color: var(--button-text); }

/* Выбор карты в форме сделки */
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); min-height: 44px; cursor: pointer; }
.pick:last-child { border-bottom: 0; }
.pick input { width: 22px; height: 22px; min-height: 0; flex-shrink: 0; }
.pick .main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pick.short .muted { color: var(--warn); }

/* Факты о сделке */
.facts { margin: 0; display: grid; gap: 8px; }
.facts > div { display: flex; justify-content: space-between; gap: 12px; }
.facts dt { color: var(--hint); }
.facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; }

/* Сообщения */
#flash { position: sticky; top: 0; z-index: 5; padding: 0 16px; }
#flash:empty { display: none; }
.flash { margin-top: 12px; padding: 12px 14px; border-radius: 12px; display: flex; flex-direction: column; gap: 10px; }
.flash.error { background: var(--neg-soft); color: var(--neg); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.ok { background: var(--soft); color: var(--link); }
button.flash { border: 0; font: inherit; text-align: left; cursor: pointer; width: 100%; min-height: 44px; }
.content > .flash { margin-top: 0; }

/* Нижняя навигация */
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: calc(64px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--nav); border-top: 1px solid var(--line); z-index: 10; }
.nav a { color: var(--hint); text-decoration: none; font-size: 11px; font-weight: 500; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
svg.i { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
svg.i.s { width: 18px; height: 18px; stroke-width: 2.2; }
.htmx-request.btn { opacity: 0.6; }
