:root {
  --blue: #1d5aa8;
  --blue-d: #154582;
  --blue-l: #e8f0fb;
  --ink: #15181f;
  --muted: #5d6675;
  --line: #dfe3ea;
  --bg: #f3f5f9;
  --card: #ffffff;
  --red: #c62828;
  --red-l: #fdecec;
  --green: #1f7a3f;
  --green-l: #e7f5ec;
  --amber: #a15c00;
  --amber-l: #fff3df;
  --radius: 12px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); }
body { min-height: 100dvh; padding-bottom: calc(64px + var(--safe-b)); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- app bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 6px;
  padding: calc(8px + var(--safe-t)) 10px 8px 14px;
  background: var(--blue); color: #fff;
  box-shadow: 0 1px 0 rgba(0,0,0,.08);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.logo {
  border: 2px solid #fff; border-radius: 50%; padding: 2px 8px;
  font-weight: 800; font-size: 13px; letter-spacing: .5px;
}
.brand-name, .brand h1 { font-size: 16px; font-weight: 650; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px;
  border: 0; border-radius: 10px; background: transparent; color: inherit; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.16); }
.appbar-actions { display: flex; gap: 2px; }
.sync { position: relative; font-size: 20px; width: 36px; }
.sync[data-state="syncing"] span { display: inline-block; animation: spin 1s linear infinite; }
.sync[data-state="error"], .sync[data-state="signed-out"], .sync[data-state="offline"] { color: #ffd479; }
.sync i { position: absolute; top: 3px; right: 0; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: #ffd479; color: #3a2800; font: 700 10px/16px system-ui; font-style: normal; }

/* ---------- tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 7px; font-size: 11.5px; color: var(--muted); text-decoration: none;
}
.tabbar a.on { color: var(--blue); font-weight: 650; }
.tabbar.hide { display: none; }
body.no-tabs { padding-bottom: calc(84px + var(--safe-b)); }

/* ---------- layout ---------- */
main { padding: 14px 14px 24px; max-width: 760px; margin: 0 auto; outline: none; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.grid2 > *, .grid3 > * { min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.right { text-align: right; }
.mono { font-variant-numeric: tabular-nums; }
h2.section { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 2px 8px; font-weight: 650; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px;
}
.card.tight { padding: 10px 12px; }
a.card, .card.link { display: block; color: inherit; text-decoration: none; }
a.card:active, .card.link:active { background: #f7f9fc; }
.list > * + * { margin-top: 8px; }

.lr { font-weight: 800; color: var(--red); font-variant-numeric: tabular-nums; }
.title-line { font-weight: 650; font-size: 15px; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 650;
  background: var(--blue-l); color: var(--blue-d); white-space: nowrap;
}
.badge.green { background: var(--green-l); color: var(--green); }
.badge.red { background: var(--red-l); color: var(--red); }
.badge.amber { background: var(--amber-l); color: var(--amber); }
.badge.grey { background: #eef0f3; color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.stat b { display: block; font-size: 17px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 11.5px; color: var(--muted); }

/* ---------- forms ---------- */
.field { display: block; }
.field > span { display: block; font-size: 12.5px; color: var(--muted); margin: 0 0 4px 2px; font-weight: 550; }
.input, .field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid #cfd5df; border-radius: 10px; background: #fff;
  font-size: 16px; /* stops iOS zoom */
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  outline: 2px solid var(--blue); outline-offset: -1px; border-color: var(--blue);
}
.field input.filled, .field textarea.filled, .field select.filled { background: #fffbe6; transition: background 1.5s; }
.field input[readonly] { background: #f5f7fa; }
.form-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.form-card > * + * { margin-top: 12px; }
.form-card h3 { margin: 0; font-size: 15px; display: flex; align-items: center; justify-content: space-between; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid #cfd5df; background: #fff; border-radius: 999px;
  padding: 6px 12px; font-size: 13.5px; cursor: pointer;
}
.chip.on { background: var(--blue); border-color: var(--blue); color: #fff; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 16px; border-radius: 12px; border: 1px solid #cfd5df;
  background: #fff; color: var(--ink); font-weight: 650; font-size: 15px; cursor: pointer; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.wa { background: #1fa855; border-color: #1fa855; color: #fff; }
.btn.danger { color: var(--red); border-color: #f0c4c4; }
.btn.block { width: 100%; }
.btn.sm { min-height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn[disabled] { opacity: .55; }
.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: 10px 14px calc(10px + var(--safe-b));
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.savebar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 10px; }
.savebar .btn { flex: 1; }

.quickfill { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quickfill button {
  display: flex; align-items: center; gap: 10px; padding: 12px; min-height: 58px;
  border-radius: 12px; border: 1px dashed #9bb4d9; background: var(--blue-l); color: var(--blue-d);
  font-weight: 650; font-size: 14px; text-align: left; cursor: pointer;
}
.quickfill small { display: block; font-weight: 450; color: var(--muted); font-size: 11.5px; }

.banner { border-radius: 10px; padding: 10px 12px; font-size: 14px; background: var(--amber-l); color: #6a3d00; }
.banner.info { background: var(--blue-l); color: var(--blue-d); }
.banner.ok { background: var(--green-l); color: var(--green); }

.search { position: relative; }
.search input { padding-left: 38px; }
.search svg { position: absolute; left: 11px; top: 11px; width: 20px; height: 20px; color: var(--muted); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: #e6eaf0; border-radius: 10px; padding: 3px; }
.seg button, .seg a { border: 0; background: transparent; padding: 8px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--muted); text-align: center; text-decoration: none; cursor: pointer; }
.seg .on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.fab {
  position: fixed; right: 16px; bottom: calc(76px + var(--safe-b)); z-index: 22;
  display: inline-flex; align-items: center; gap: 8px; height: 54px; padding: 0 20px;
  border-radius: 27px; border: 0; background: var(--blue); color: #fff; font-weight: 700; font-size: 15px;
  box-shadow: 0 6px 18px rgba(29,90,168,.35); cursor: pointer; text-decoration: none;
}

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }

/* bilty preview */
.preview { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px; }
.preview canvas, .preview img { display: block; width: 100%; height: auto; border-radius: 6px; }
.preview-scroll { overflow-x: auto; }

/* expense rows */
.exp-row { display: grid; grid-template-columns: 1.1fr .9fr auto; gap: 8px; align-items: center; }
.exp-row .note { grid-column: 1 / 3; }
.x-btn { width: 40px; height: 40px; border: 0; border-radius: 10px; background: #f3f4f6; color: var(--muted); font-size: 20px; cursor: pointer; }

.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-variant-numeric: tabular-nums; }
.totals .big { font-weight: 800; font-size: 17px; }
.totals .profit { color: var(--green); }
.totals .loss { color: var(--red); }

/* ---------- bottom sheet ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 50; background: rgba(15,20,30,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet[hidden] { display: none; }
.sheet .panel {
  width: 100%; max-width: 640px; background: #fff; border-radius: 18px 18px 0 0;
  padding: 16px 16px calc(16px + var(--safe-b)); max-height: 92dvh; overflow: auto;
  animation: up .18s ease-out;
}
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet h3 { margin: 0 0 4px; font-size: 18px; }
.mic {
  display: grid; place-items: center; width: 92px; height: 92px; margin: 16px auto 8px;
  border-radius: 50%; border: 0; background: var(--blue); color: #fff; cursor: pointer;
  box-shadow: 0 6px 20px rgba(29,90,168,.35);
}
.mic svg { width: 40px; height: 40px; }
.mic.live { background: var(--red); animation: pulse 1.2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(198,40,40,.45); } 100% { box-shadow: 0 0 0 22px rgba(198,40,40,0); } }
.center { text-align: center; }
.vprog { height: 6px; background: #e6eaf0; border-radius: 3px; overflow: hidden; margin-top: 10px; }
.vprog span { display: block; height: 100%; background: var(--blue); transition: width .2s; }
.vq { font-size: 21px; font-weight: 700; line-height: 1.35; margin: 10px 0 8px; }
.vnav { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; margin-top: 10px; }
.vall { margin-top: 12px; font-size: 14px; }
.vall summary { color: var(--blue); cursor: pointer; padding: 6px 0; }
.vall ol { margin: 6px 0 0; padding-left: 22px; }
.vall li { padding: 5px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.vall li span { display: block; color: var(--muted); font-size: 13px; }
.vall li b { font-weight: 600; }
.vall li.on span { color: var(--blue); font-weight: 600; }
.vlist { margin: 6px 0 10px; padding-left: 20px; font-size: 14px; line-height: 1.6; }
.chat { display: flex; flex-direction: column; gap: 10px; padding-bottom: 130px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; font-size: 15.5px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--blue); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg .steps { font-size: 12px; color: var(--muted); margin-top: 6px; }
.askbar { position: fixed; left: 0; right: 0; bottom: calc(58px + var(--safe-b)); z-index: 21; background: rgba(243,245,249,.97); border-top: 1px solid var(--line); padding: 8px 12px; }
.askbar .inner { max-width: 760px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.askbar textarea { flex: 1; min-height: 46px; max-height: 120px; resize: none; padding: 11px 12px; border: 1px solid #cfd5df; border-radius: 12px; font-size: 16px; background: #fff; }
.askbar .icon-btn { width: 46px; height: 46px; background: #fff; border: 1px solid #cfd5df; color: var(--blue); }
.askbar .icon-btn.send { background: var(--blue); color: #fff; border-color: var(--blue); }
.askbar .icon-btn.live { background: var(--red); color: #fff; border-color: var(--red); }
.menu-list button {
  width: 100%; display: flex; gap: 12px; align-items: center; padding: 14px 6px; border: 0; background: none;
  border-bottom: 1px solid var(--line); font-size: 16px; text-align: left; cursor: pointer;
}
.menu-list button:last-child { border-bottom: 0; }
.menu-list svg { color: var(--blue); }

.toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: #1d2430; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%); }

.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
.spinner.dark { border-color: #c9d3e3; border-top-color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }

@media (min-width: 640px) {
  main { padding: 20px; }
}
@media (max-width: 380px) {
  .grid3 { grid-template-columns: 1fr 1fr; }
  .stat b { font-size: 15px; }
  .stat { padding: 8px; }
}
