/* Таро CRM. Одна колонка шириной с телефон, нижняя панель вкладок как в приложении;
   на десктопе — та же колонка по центру. Системный шрифт — как у Mini App в Telegram.
   Макет утверждён 2026-09-30: https://claude.ai/artifact/ERErnBrURwf29F898pA8zT */
:root {
  --bg: #f3f1f7;
  --surface: #ffffff;
  --surface-2: #ece8f4;
  --fg: #1c1729;
  --muted: #6b6480;
  --line: #e2ddec;
  --accent: #5a45a8;
  --accent-fg: #ffffff;
  --accent-soft: #e9e4f7;
  --gold: #9a7534;
  --ok: #257a4a;   --ok-bg: #e2f2e8;
  --new: #9a6512;  --new-bg: #fbefd9;
  --off: #6f6983;  --off-bg: #eceaf1;
  --bad: #b8372f;  --bad-bg: #fae4e2;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15121d; --surface: #211c2d; --surface-2: #2b253b; --fg: #ece6f7; --muted: #a39bb7;
    --line: #342d47; --accent: #b6a4ff; --accent-fg: #1a1330; --accent-soft: #2f2750; --gold: #e3c688;
    --ok: #74d39f; --ok-bg: #1b3526; --new: #f0c46b; --new-bg: #3a2f18; --off: #a39bb7; --off-bg: #2a2536;
    --bad: #ff8d84; --bad-bg: #40201e; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15121d; --surface: #211c2d; --surface-2: #2b253b; --fg: #ece6f7; --muted: #a39bb7;
  --line: #342d47; --accent: #b6a4ff; --accent-fg: #1a1330; --accent-soft: #2f2750; --gold: #e3c688;
  --ok: #74d39f; --ok-bg: #1b3526; --new: #f0c46b; --new-bg: #3a2f18; --off: #a39bb7; --off-bg: #2a2536;
  --bad: #ff8d84; --bad-bg: #40201e; color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
/* Рывок вниз у верхнего края сворачивает Mini App — гасим «пружину» страницы. */
html, body { overscroll-behavior: none; }
:root { padding-top: env(safe-area-inset-top, 0px); }
img, svg { max-width: 100%; }
body { background: var(--bg); color: var(--fg); font-family: var(--font); font-size: 16px; line-height: 1.4; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }

.app { max-width: 440px; margin: 0 auto; min-height: 100%; display: flex; flex-direction: column; padding-inline: 16px; padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }

header.top { padding-block: 14px 6px; display: flex; flex-direction: column; gap: 2px; }
header.top h1 { font-size: 28px; line-height: 1.15; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
header.top .sub { color: var(--muted); font-size: 14px; }
.back { align-self: flex-start; background: none; border: 0; color: var(--accent); padding: 6px 0; font-size: 16px; display: inline-flex; align-items: center; gap: 4px; min-height: 40px; }

.search { width: 100%; box-sizing: border-box; border: 0; background: var(--surface-2); border-radius: 12px; padding: 11px 14px; font-size: 16px; margin-top: 8px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-block: 12px 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 7px 13px; font-size: 14px; white-space: nowrap; min-height: 36px; }
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.chip .n { opacity: .7; margin-left: 4px; }

.day { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 4px 8px; }
.list { background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; width: 100%; text-align: left; background: none; border: 0; padding: 12px 14px; border-top: 1px solid var(--line); min-height: 64px; }
.row:first-child { border-top: 0; }
.row:active { background: var(--surface-2); }
.row .who { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .what { color: var(--muted); font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .right { text-align: right; font-size: 14px; color: var(--muted); }
.row .amount { color: var(--fg); font-weight: 600; font-size: 15px; }
.row .meta { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: 12.5px; font-weight: 600; line-height: 1.5; }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-NEW { color: var(--new); background: var(--new-bg); }
.s-WORK { color: var(--accent); background: var(--accent-soft); }
.s-PAID { color: var(--ok); background: var(--ok-bg); }
.s-CANCELLED { color: var(--off); background: var(--off-bg); }
.s-SPAM { color: var(--bad); background: var(--bad-bg); }
.src { font-size: 12.5px; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 2px 9px; line-height: 1.5; }
.src.ad { color: var(--accent); background: var(--accent-soft); }
.tag-repeat { font-size: 12.5px; color: var(--gold); border: 1px solid currentColor; border-radius: 999px; padding: 1px 8px; }

.card { background: var(--surface); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }

.seg { display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg.three { grid-template-columns: repeat(3, 1fr); }
.seg button { border: 0; background: none; border-radius: 9px; padding: 7px 2px; font-size: 12.5px; min-height: 44px; line-height: 1.15; }
.seg.three button { font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--surface); box-shadow: 0 1px 3px rgb(0 0 0 / .12); font-weight: 600; }

.amounts { display: flex; flex-wrap: wrap; gap: 8px; }
.amounts .chip { font-variant-numeric: tabular-nums; }
.field { width: 100%; box-sizing: border-box; border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 13px; font-size: 16px; }
textarea.field { min-height: 72px; resize: vertical; }
label.lbl { font-size: 14px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }

.btn { border: 0; border-radius: 12px; padding: 13px 16px; font-size: 16px; font-weight: 600; min-height: 48px; }
.btn.primary { background: var(--accent); color: var(--accent-fg); }
.btn.ghost { background: var(--accent-soft); color: var(--accent); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.timeline li { display: grid; grid-template-columns: 58px 1fr; gap: 10px; font-size: 14.5px; }
.timeline time { color: var(--muted); font-size: 13px; padding-top: 1px; }
.timeline .by { color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--muted); }

.money { font-size: 34px; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.vs { font-size: 14px; color: var(--muted); }
.bar { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: inherit; }
.link { background: none; border: 0; color: var(--accent); padding: 0; font-size: 15px; align-self: flex-start; min-height: 32px; }

.steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.steps li { display: grid; grid-template-columns: 1fr auto; align-items: baseline; gap: 12px; padding-block: 9px; border-top: 1px solid var(--line); }
.steps li:first-child { border-top: 0; }
.steps .v { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.steps .d { grid-column: 1 / -1; font-size: 13px; color: var(--muted); margin-top: -4px; }
.steps .paid .v { color: var(--ok); }

.tbl { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px 14px; font-size: 14.5px; align-items: baseline; }
.tbl .h { font-size: 12.5px; color: var(--muted); }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; }

svg.chart { width: 100%; height: auto; display: block; }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
svg.chart .tick { fill: var(--muted); font-size: 10px; font-family: var(--font); }
svg.chart .b { fill: var(--accent); }
svg.chart .b.partial { fill: var(--accent); opacity: .45; }
svg.chart .mark { stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 3 3; }
svg.chart .mark-t { fill: var(--gold); font-size: 10px; font-family: var(--font); }

nav.tabbar { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); z-index: 5; }
nav.tabbar .inner { max-width: 440px; margin: 0 auto; display: grid; grid-template-columns: repeat(3, 1fr); }
nav.tabbar button { background: none; border: 0; padding: 8px 4px 10px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 11.5px; color: var(--muted); min-height: 56px; }
nav.tabbar button[aria-current="page"] { color: var(--accent); font-weight: 600; }
nav.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.badge { background: var(--new); color: var(--surface); border-radius: 999px; font-size: 10.5px; padding: 0 5px; margin-left: 2px; font-weight: 700; }

.scrim { position: fixed; inset: 0; background: rgb(10 6 20 / .45); z-index: 9; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; }
.sheet .panel { max-width: 440px; margin: 0 auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px)); display: flex; flex-direction: column; gap: 12px; max-height: 88vh; max-height: 88dvh; overscroll-behavior: contain; overflow-y: auto; box-sizing: border-box; }
.sheet .grab { width: 38px; height: 5px; border-radius: 999px; background: var(--line); align-self: center; }
.sheet h3 { margin: 0; font-size: 20px; }

.toast { position: fixed; left: 50%; top: calc(env(safe-area-inset-top, 0px) + 12px); transform: translate(-50%, -8px); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14.5px; z-index: 20; max-width: calc(100% - 32px); opacity: 0; pointer-events: none; transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.login { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; padding-block: 40px; }
.login .mark { width: 56px; height: 56px; border-radius: 16px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font-size: 26px; font-weight: 700; }
.login h1 { margin: 0; font-size: 26px; }
.login p { margin: 0; color: var(--muted); }
.ok-box { background: var(--ok-bg); color: var(--ok); border-radius: 12px; padding: 12px 14px; font-size: 15px; }

@media (prefers-reduced-motion: no-preference) {
  .sheet .panel { animation: up .22s ease-out; }
  @keyframes up { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
}

/* ── Дополнения к макету: загрузка, ошибки, удаление ─────────────────── */
.loading { color: var(--muted); padding-block: 40px; text-align: center; }
.muted { color: var(--muted); }
.error-box { background: var(--bad-bg); color: var(--bad); border-radius: 12px; padding: 12px 14px; font-size: 15px; }
.warn-box { background: var(--new-bg); color: var(--new); border-radius: 12px; padding: 10px 14px; font-size: 14.5px; }
.btn.danger { background: var(--bad-bg); color: var(--bad); }
.link.danger { color: var(--bad); }
.row.static { cursor: default; }
.row.static:active { background: none; }
.row-actions { grid-column: 1 / -1; display: flex; gap: 14px; justify-content: flex-end; }
.skeleton { height: 14px; border-radius: 6px; background: var(--surface-2); }
header.top.head-row { flex-direction: row; align-items: flex-end; justify-content: space-between; gap: 12px; }
.head-row > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.head-row .btn { padding: 9px 14px; min-height: 40px; font-size: 15px; }
.sheet .panel .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tbl.two { grid-template-columns: 1fr auto auto; }
.center { text-align: center; }
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
/* Пока печатают, нижняя панель прячется: клавиатура iOS не сжимает экран. */
body.typing nav.tabbar { display: none; }
.btn[disabled] { opacity: .5; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
