/* Палитра — один в один с iOS Obmen (Theme.swift) и десктопной кассой:
   программа, приложение и мини-приложение выглядят одной системой. */
:root {
  --bg: #0E1319;
  --surface: #161D26;
  --surface2: #1E2733;
  --surface3: #28323F;
  --border: #2A3542;
  --border-hi: #3A4757;
  --text: #E8EEF5;
  --muted: #8494A6;
  --faint: #5C6B7D;
  --accent: #3FB950;
  --accent-hi: #4CC85E;
  --on-accent: #08240E;
  --danger: #F0524B;
  --warn: #E3A008;
  --info: #3B8EEA;
  --violet: #8C5FB8;
  --radius: 14px;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  background-image:
    radial-gradient(420px 420px at 18% 12%, rgba(46, 92, 140, .20), transparent 70%),
    radial-gradient(460px 460px at 86% 78%, rgba(96, 52, 128, .16), transparent 70%);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}
#stars { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; }
main { position: relative; z-index: 1; padding: 10px 16px calc(var(--tabs-h) + var(--safe-b) + 24px); max-width: 640px; margin: 0 auto; }
button, input { font: inherit; color: inherit; }
svg { width: 16px; height: 16px; flex: none; }
button { cursor: pointer; border: 0; background: none; padding: 0; }

.money, .num { font-variant-numeric: tabular-nums; font-family: ui-rounded, "SF Pro Rounded", -apple-system, "Segoe UI", Roboto, sans-serif; }
body.hide .money { filter: blur(7px); }

/* ---------- заголовок экрана ---------- */
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin: 6px 0 14px; }
.head h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -.2px; }
.head p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.icon-btn { width: 38px; height: 38px; border-radius: 50%; background: var(--surface2); border: 1px solid var(--border); display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn svg { width: 18px; height: 18px; }
/* ↑ ↓ — порядок валют в «Курсах» */
.move { display: flex; flex-direction: column; gap: 4px; }
.move .icon-btn { width: 26px; height: 22px; border-radius: 7px; font-size: 13px; line-height: 1; }
.move .icon-btn:disabled { opacity: .3; }

/* ---------- карточки ---------- */
.card { background: rgba(22, 29, 38, .82); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 8px; }
.card.accent { border-color: rgba(63, 185, 80, .55); }
.cap { font-size: 11px; font-weight: 600; letter-spacing: .6px; text-transform: uppercase; color: var(--faint); }
.big { font-size: 32px; font-weight: 700; margin-top: 6px; display: flex; align-items: baseline; gap: 6px; }
.big small { font-size: 19px; font-weight: 500; color: var(--muted); }
.section { display: flex; justify-content: space-between; align-items: center; margin: 18px 2px 8px; }
.section .cap { letter-spacing: .7px; }
.section button { color: var(--accent); font-size: 13px; font-weight: 500; }
.stack > * + * { margin-top: 8px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.row .l { min-width: 0; }
.row .r { text-align: right; flex: none; }
.code { font-size: 16px; font-weight: 600; }
.sub { font-size: 12px; color: var(--faint); margin-top: 3px; }
.amt { font-size: 19px; font-weight: 600; }
.neg { color: var(--danger); }
.card.zero { opacity: .55; }
.pos { color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); margin: 8px 2px; }
.empty { text-align: center; color: var(--muted); padding: 34px 0; font-size: 14px; }
.empty b { display: block; font-size: 30px; font-weight: 300; color: var(--faint); margin-bottom: 8px; }

/* ---------- кнопки ---------- */
.btn { display: block; width: 100%; padding: 15px; border-radius: 12px; background: var(--accent); color: var(--on-accent); font-size: 17px; font-weight: 600; text-align: center; }
.btn:active { background: var(--accent-hi); }
.btn:disabled { background: var(--surface3); color: var(--faint); }
.ghost { display: flex; align-items: center; justify-content: center; gap: 7px; width: 100%; padding: 12px; border-radius: 11px; background: var(--surface2); border: 1px solid var(--border); font-size: 15px; font-weight: 500; }
.ghost:active { background: var(--surface3); }
.start-row { display: grid; grid-template-columns: 84px minmax(0, 1fr) minmax(0, 1fr); gap: 8px; align-items: center; margin-top: 8px; }
.start-row .input input { width: 100%; }
.start-cur { display: flex; flex-direction: column; line-height: 1.2; }
.start-cur span { font-size: 12px; color: var(--muted); }
.daybar { display: grid; grid-template-columns: 38px 1fr 38px; gap: 8px; align-items: center; margin-bottom: 12px; }
.daybtn { display: flex; align-items: center; justify-content: center; gap: 8px; height: 38px; border-radius: 12px; background: var(--surface2); border: 1px solid var(--border); font-size: 15px; }
.daybtn span { color: var(--muted); font-size: 13px; }
.daybtn:active { background: var(--surface3); }
.cal-head { display: grid; grid-template-columns: 38px 1fr 38px; align-items: center; text-align: center; margin-bottom: 10px; font-size: 16px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-w { text-align: center; font-size: 11px; color: var(--faint); padding: 2px 0 4px; }
.cal-d { aspect-ratio: 1; max-width: 100%; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 15px; color: var(--text); background: var(--surface); border: 1px solid transparent; }
.cal-d small { font-size: 10px; line-height: 1; opacity: .85; }
.cal-d.has { background: rgba(63, 185, 80, .16); color: var(--accent); font-weight: 600; }
.cal-d.today { border-color: var(--accent); }
.cal-d.sel { background: var(--accent); color: var(--on-accent); }
.cal-d:disabled { opacity: .25; }
.post { margin: 0; white-space: pre-wrap; font: 15px/1.5 -apple-system, system-ui, sans-serif; color: var(--text); user-select: text; -webkit-user-select: text; }
.ghost svg { width: 15px; height: 15px; }
.ghost.danger { color: var(--danger); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hintbtn svg { width: 13px; height: 13px; }
.op-head svg { width: 12px; height: 12px; align-self: center; }
.hintbtn { display: flex; align-items: center; gap: 8px; width: 100%; padding: 11px 14px; border-radius: 10px; background: var(--surface2); border: 1px solid var(--border); color: var(--accent); font-size: 14px; font-weight: 500; text-align: left; margin-top: 8px; }

/* ---------- переключатели и чипы ---------- */
.seg { display: flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 9px 6px; border-radius: 8px; color: var(--muted); font-size: 14px; font-weight: 600; }
.seg button.on { background: var(--surface3); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 1px; }
.chip { flex: none; padding: 10px 18px; border-radius: 10px; background: var(--surface2); border: 1px solid var(--border); font-size: 15px; font-weight: 600; }
.chip.on { background: var(--accent); border-color: transparent; color: var(--on-accent); }

/* ---------- выдвижной список контрагентов ---------- */
.dd-btn { flex: none; width: 34px; height: 34px; margin-right: -6px; border-radius: 8px; color: var(--muted); font-size: 16px; transition: transform .15s; }
.dd.open .dd-btn { transform: rotate(180deg); color: var(--accent); }
.dd.open .input { border-color: var(--border-hi); border-bottom-left-radius: 4px; border-bottom-right-radius: 4px; }
.dd-list { display: none; margin-top: 4px; max-height: 260px; overflow-y: auto; background: var(--surface2); border: 1px solid var(--border-hi); border-radius: 4px 4px 11px 11px; }
.dd.open .dd-list { display: block; animation: fade .12s ease; }
.dd-item { display: flex; justify-content: space-between; align-items: center; width: 100%; padding: 13px 14px; text-align: left; font-size: 16px; font-weight: 500; border-bottom: 1px solid var(--border); }
.dd-item:last-child { border-bottom: 0; }
.dd-item:active, .dd-item.on { background: var(--surface3); }
.dd-item.on { color: var(--accent); }
.dd-tag { font-size: 11px; color: var(--muted); background: var(--surface); border-radius: 6px; padding: 2px 7px; }
.dd-new { padding: 12px 14px; color: var(--muted); font-size: 14px; }

/* ---------- поля ---------- */
.field { margin-top: 14px; }
.field label { display: block; margin-bottom: 7px; }
.input { display: flex; align-items: center; gap: 8px; padding: 0 14px; background: var(--surface2); border: 1px solid var(--border); border-radius: 11px; }
.input:focus-within { border-color: var(--border-hi); }
.input input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; padding: 13px 0; font-size: 20px; font-weight: 600; }
.input input::placeholder { color: var(--faint); font-weight: 500; }
.input .suf { color: var(--muted); font-weight: 600; font-size: 15px; }
.factor { display: flex; gap: 6px; }
.factor button { flex: none; width: 46px; height: 50px; border-radius: 11px; background: var(--surface2); border: 1px solid var(--border); color: var(--muted); font-size: 19px; font-weight: 600; }
.factor button.on { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.factor .input { flex: 1; }

/* ---------- история ---------- */
.op-head { display: flex; align-items: baseline; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase; }
.op-head .id { color: var(--faint); font-weight: 400; letter-spacing: 0; }
.op-head .t { margin-left: auto; color: var(--faint); font-weight: 400; font-size: 12px; text-transform: none; }
.op-body { margin-top: 8px; }
.op-main { font-size: 19px; font-weight: 700; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.op-main .x { font-size: 12px; color: var(--faint); font-weight: 400; }
.op-main .tot { margin-left: auto; font-size: 15px; color: var(--muted); font-weight: 600; }
.op-leg { font-size: 14px; margin-top: 4px; color: var(--text); }
.op-leg i { color: var(--faint); font-style: normal; margin-right: 4px; }
.op-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 9px; font-size: 12px; color: var(--faint); }
.op-foot .profit { color: var(--accent); font-size: 13px; font-weight: 600; }
.undone { opacity: .5; }
.undone .op-main { text-decoration: line-through; }
.tag { font-size: 11px; color: var(--danger); margin-left: 6px; }
.undo { color: var(--danger); font-size: 13px; font-weight: 500; }
.c-buy { color: var(--accent); } .c-sell { color: var(--info); } .c-cross { color: var(--violet); } .c-cash { color: var(--warn); }

/* ---------- чек / подтверждение ---------- */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; font-size: 14px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { text-align: right; font-weight: 600; }
.kv.total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 12px; }
.kv.total span:last-child { font-size: 20px; color: var(--accent); }
.warn-box { border: 1px solid rgba(227, 160, 8, .5); background: rgba(227, 160, 8, .08); border-radius: var(--radius); padding: 14px; margin-bottom: 8px; }
.warn-box b { color: var(--warn); }

/* ---------- нижние вкладки ---------- */
#tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; justify-content: space-around; padding: 6px 4px calc(6px + var(--safe-b)); background: rgba(14, 19, 25, .92); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--border); }
#tabs:empty { display: none; }
/* Приложение на iPhone: страница на весь экран — сверху место под часы и «чёлку» */
html.native main { padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
html.native .sheet { max-height: calc(92vh - env(safe-area-inset-top, 0px)); }
#tabs button { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 0; color: var(--faint); font-size: 10px; font-weight: 500; }
#tabs button svg { width: 22px; height: 22px; }
#tabs button.on { color: var(--accent); }

/* ---------- лист снизу ---------- */
#sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-end; animation: fade .18s ease; }
#sheet[hidden] { display: none; }
.sheet { width: 100%; max-width: 640px; margin: 0 auto; max-height: 92vh; overflow-y: auto; background: var(--bg); border: 1px solid var(--border); border-bottom: 0; border-radius: 18px 18px 0 0; padding: 8px 16px calc(18px + var(--safe-b)); animation: up .22s cubic-bezier(.2, .8, .2, 1); }
.sheet .grab { width: 38px; height: 5px; border-radius: 3px; background: var(--surface3); margin: 4px auto 10px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.sheet-head h2 { margin: 0; font-size: 17px; }
.sheet-head button { color: var(--muted); font-size: 15px; }
.sheet .btn { margin-top: 16px; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- тост и ошибка ---------- */
#toast { position: fixed; left: 50%; bottom: calc(var(--tabs-h) + var(--safe-b) + 14px); z-index: 20; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; transition: .25s; padding: 11px 18px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 14px; font-weight: 600; white-space: nowrap; max-width: 92vw; overflow: hidden; text-overflow: ellipsis; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); color: #fff; }
.error { background: var(--danger); color: #fff; border-radius: 12px; padding: 11px 14px; font-size: 13px; font-weight: 500; margin-bottom: 10px; }
.loading { text-align: center; color: var(--muted); padding-top: 40vh; }

/* ---------- экран «открой через Telegram» ---------- */
.gate { min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 14px; }
.gate .logo { width: 64px; height: 64px; border-radius: 18px; background: var(--surface); border: 1px solid var(--border); display: grid; place-items: center; }
.gate .logo svg { width: 34px; height: 34px; color: var(--accent); }
.gate h1 { margin: 0; font-size: 22px; }
.gate p { margin: 0; color: var(--muted); max-width: 300px; }

.switch { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.switch input { width: 46px; height: 28px; appearance: none; background: var(--surface3); border-radius: 14px; position: relative; transition: .2s; cursor: pointer; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: var(--text); transition: .2s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { left: 21px; }

/* Коды: компактный список — строка на код, нажал — кнопки под ней */
.codes-box { background: rgba(22, 29, 38, .82); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 10px; }
.code-row { padding: 11px 14px; border-top: 1px solid var(--border); cursor: pointer; }
.code-row:first-child { border-top: 0; }
.code-row.open { background: var(--surface2); }
.code-row .l1, .code-row .l2 { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.code-row .no { font-weight: 600; font-size: 15px; white-space: nowrap; }
.code-row .no i { font-style: normal; font-size: 12px; margin-right: 6px; }
.code-row .sum { font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; text-align: right; }
.code-row .l2 { font-size: 12px; color: var(--faint); margin-top: 3px; }
.code-row .l2 span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.code-row .l2 span:last-child { white-space: nowrap; }
.code-row .acts { display: flex; gap: 8px; margin-top: 10px; white-space: nowrap; }
.code-row .acts .ghost { padding: 9px 8px; font-size: 14px; flex: 1; }
.code-row .acts .ghost.x { flex: 0 0 52px; width: 52px; }
.codes-stat { display: flex; gap: 8px; margin-top: 10px; }
.codes-stat span { flex: 1; text-align: center; padding: 8px; border-radius: 11px; background: var(--surface2); border: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.codes-stat b { color: var(--text); font-size: 15px; margin-left: 4px; }.sheet.still { animation: none; }
