:root {
  --bg: #f5f6f8; --card: #ffffff; --text: #14161a; --muted: #6b7280; --line: #e5e7eb;
  --accent: #3b6cf6; --accent-text: #fff; --green: #16a34a; --yellow: #d97706; --red: #dc2626;
  --green-bg: #dcfce7; --yellow-bg: #fef3c7; --red-bg: #fee2e2; --chip: #eef1f6;
  --radius: 14px; --tabs-h: 62px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #181b21; --text: #eef0f3; --muted: #9aa1ad; --line: #272b33;
    --accent: #5b87ff; --green: #22c55e; --yellow: #f59e0b; --red: #f87171;
    --green-bg: #12301f; --yellow-bg: #33270d; --red-bg: #3a1717; --chip: #23272f;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) 0 calc(var(--tabs-h) + env(safe-area-inset-bottom)) 0;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.top h1 { margin: 0; font-size: 26px; font-weight: 750; letter-spacing: -0.02em; }
.icon { border: 0; background: var(--chip); border-radius: 50%; width: 38px; height: 38px; font-size: 18px; }

main { padding: 4px 14px 24px; max-width: 640px; margin: 0 auto; }
.pad { padding: 24px 0; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; }
.row > .grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }

.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin: 10px 0; box-shadow: 0 1px 2px rgb(0 0 0 / 5%); }
.card h2 { margin: 0 0 8px; font-size: 17px; font-weight: 650; }
.card h2 .count { color: var(--muted); font-weight: 500; }
.section-title { margin: 18px 4px 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }

.hero { padding: 18px 16px; }
.hero .label { color: var(--muted); font-size: 14px; }
.hero .big { font-size: 40px; font-weight: 780; letter-spacing: -0.03em; line-height: 1.1; margin: 2px 0 4px; }
.hero.ok .big { color: var(--green); }
.hero.tight .big { color: var(--yellow); }
.hero.over .big { color: var(--red); }

.verdict { border-radius: 12px; padding: 10px 12px; margin-top: 10px; }
.verdict.green { background: var(--green-bg); }
.verdict.yellow { background: var(--yellow-bg); }
.verdict.red { background: var(--red-bg); }
.verdict.unknown { background: var(--chip); }
.verdict b { display: block; margin-bottom: 2px; }

input[type=text], input[type=number], input[type=password], input[type=date], input[type=time], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 10px 12px; font-size: 16px; min-height: 44px; }
textarea { min-height: 80px; resize: vertical; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.btn { border: 0; border-radius: 10px; padding: 10px 14px; min-height: 44px; background: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.secondary { background: var(--chip); color: var(--text); }
.btn.danger { background: var(--red-bg); color: var(--red); }
.btn.block { width: 100%; margin-top: 12px; }
.btn:disabled { opacity: 0.5; }
.link { border: 0; background: none; color: var(--accent); padding: 6px 0; font-weight: 600; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; }
.list .main { flex: 1; min-width: 0; }
.list .title { overflow-wrap: anywhere; }
.list .sub { font-size: 13px; color: var(--muted); }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 600; }
.amount.in { color: var(--green); }
.check { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--muted); background: none; flex: none; font-size: 15px; line-height: 1; }
.check.done { background: var(--green); border-color: var(--green); color: #fff; }
.mini { border: 0; background: var(--chip); border-radius: 8px; padding: 6px 9px; font-size: 13px; flex: none; }
.chip { display: inline-block; background: var(--chip); border-radius: 999px; padding: 2px 9px; font-size: 12px; color: var(--muted); }
.chip.main { background: var(--accent); color: #fff; }
.chip.warn { background: var(--yellow-bg); color: var(--yellow); }
.chip.bad { background: var(--red-bg); color: var(--red); }

.bar { height: 8px; background: var(--chip); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.bar.warn > i { background: var(--yellow); }
.bar.over > i { background: var(--red); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: var(--chip); border-radius: 12px; padding: 10px; }
.stat .v { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .k { font-size: 12px; color: var(--muted); }

.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px;
  color: var(--muted); text-decoration: none; font-weight: 600; }
.tabs a span { font-size: 21px; filter: grayscale(1); opacity: 0.7; }
.tabs a.active { color: var(--accent); }
.tabs a.active span { filter: none; opacity: 1; }

.sheet { position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / 40%); display: flex; align-items: flex-end; }
.sheet-body { background: var(--card); width: 100%; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; animation: up 0.18s ease-out; }
.sheet-body h3 { margin: 0 0 6px; font-size: 19px; }
@keyframes up { from { transform: translateY(40px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.pick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.pick button { border: 1px solid var(--line); background: var(--bg); border-radius: 999px; padding: 8px 12px; }
.pick button.sel { background: var(--accent); color: #fff; border-color: var(--accent); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 14px + env(safe-area-inset-bottom)); z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 12px; max-width: 92vw; font-size: 14px; box-shadow: 0 4px 18px rgb(0 0 0 / 25%); }

.chat { display: flex; flex-direction: column; gap: 8px; padding-bottom: 76px; }
.msg { max-width: 86%; padding: 9px 12px; border-radius: 16px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border-bottom-left-radius: 4px; }
.msg.thinking { color: var(--muted); font-style: italic; }
.composer { position: fixed; left: 0; right: 0; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); z-index: 9; padding: 8px 12px;
  background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.composer form { display: flex; gap: 8px; max-width: 640px; margin: 0 auto; }

.token { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--chip); padding: 10px; border-radius: 10px; overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; }
ol.steps { padding-left: 20px; margin: 6px 0; }
ol.steps li { margin: 6px 0; }
.login { max-width: 380px; margin: 8vh auto 0; }
.login .logo { width: 84px; height: 84px; border-radius: 20px; display: block; margin: 0 auto 12px; }
