:root {
  --fb-bg: #ffffff; --fb-text: #111111; --fb-hint: #8a8f98; --fb-link: #2481cc;
  --fb-btn: #2481cc; --fb-btn-text: #ffffff; --fb-sec: #f0f2f5;
  --bg: var(--tg-theme-bg-color, var(--fb-bg));
  --text: var(--tg-theme-text-color, var(--fb-text));
  --hint: var(--tg-theme-hint-color, var(--fb-hint));
  --link: var(--tg-theme-link-color, var(--fb-link));
  --btn: var(--tg-theme-button-color, var(--fb-btn));
  --btn-text: var(--tg-theme-button-text-color, var(--fb-btn-text));
  --sec: var(--tg-theme-secondary-bg-color, var(--fb-sec));
  --line: color-mix(in srgb, var(--hint) 28%, transparent);
  --ok: #2e9e4f; --warn: #d98a00; --bad: #d33a3a;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fb-bg: #17212b; --fb-text: #f5f5f5; --fb-hint: #7d8b99; --fb-link: #6ab3f3;
    --fb-btn: #5288c1; --fb-btn-text: #ffffff; --fb-sec: #232e3c;
    --ok: #4cc26d; --warn: #f0b429; --bad: #ff6b6b;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--sec); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden; padding-bottom: calc(76px + env(safe-area-inset-bottom));
  word-break: break-word;
}
body.has-main { padding-bottom: calc(140px + env(safe-area-inset-bottom)); }
body.no-tabs { padding-bottom: 24px; }
body.no-tabs.has-main { padding-bottom: 90px; }
button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
a { color: var(--link); }
.hint { color: var(--hint); font-size: 13px; }
.screen { padding: 12px; max-width: 640px; margin: 0 auto; }
.center { text-align: center; }
.loading, .empty { text-align: center; color: var(--hint); padding: 36px 12px; }
.stub { padding: 64px 24px; text-align: center; }
.stub .big { font-size: 52px; margin-bottom: 12px; }

#topbar { position: sticky; top: 0; z-index: 20; background: var(--bg); border-bottom: 1px solid var(--line); padding: 6px 8px; }
#backbtn { background: none; border: 0; color: var(--link); font-size: 16px; padding: 6px 8px; cursor: pointer; }

.card { background: var(--bg); border-radius: var(--radius); padding: 12px; margin-bottom: 10px; }
.card.click { cursor: pointer; }
.card.click:active { opacity: .7; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-title { font-weight: 600; }
.price { font-weight: 700; white-space: nowrap; }
.sub { color: var(--hint); font-size: 13px; margin-top: 2px; }
.sec-title { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--hint); margin: 16px 4px 6px; }
.sec-title:first-child { margin-top: 4px; }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; }
.kv .k { color: var(--hint); }
.kv .v { text-align: right; font-weight: 500; }
.kv.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; font-size: 17px; font-weight: 700; }
.kv.discount .v { color: var(--ok); }
.note { background: var(--sec); border-radius: 10px; padding: 8px 10px; font-size: 13px; color: var(--hint); margin-top: 8px; }
.note.warn { color: var(--text); border-left: 3px solid var(--warn); }

.btn {
  display: inline-block; border: 0; border-radius: 10px; padding: 9px 14px; cursor: pointer;
  background: var(--sec); color: var(--link); font-weight: 600; text-align: center;
}
.btn:active { opacity: .7; }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--btn); color: var(--btn-text); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.block { display: block; width: 100%; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 20px; background: var(--sec); color: var(--hint); white-space: nowrap; }
.chip.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 15%, transparent); }
.chip.warn { color: var(--warn); background: color-mix(in srgb, var(--warn) 17%, transparent); }
.chip.bad { color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, transparent); }
.stars { color: #f5b301; letter-spacing: 1px; }

.amount-box { text-align: center; padding: 14px 8px; }
.amount { font-size: 32px; font-weight: 800; margin: 4px 0 8px; }
.copy-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.copy-row:first-child { border-top: 0; }
.copy-row .lbl { color: var(--hint); font-size: 12px; }
.copy-row .val { font-weight: 600; }
.countdown { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.pre { white-space: pre-wrap; word-break: break-all; background: var(--sec); border-radius: 8px; padding: 8px 10px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.good { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.good .pre { flex: 1; min-width: 0; }

input[type=text], input[type=number], input[type=url], input[type=search], textarea, select {
  width: 100%; background: var(--sec); border: 1px solid transparent; border-radius: 10px; padding: 9px 11px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--btn); }
textarea { resize: vertical; min-height: 80px; }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 13px; color: var(--hint); margin-bottom: 4px; }
.counter { text-align: right; font-size: 12px; color: var(--hint); margin-top: 2px; }
.counter.bad { color: var(--bad); }
.form-err { color: var(--bad); font-size: 13px; min-height: 18px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.check input { width: 20px; height: 20px; flex: none; }

.qty { display: inline-flex; align-items: center; gap: 4px; background: var(--sec); border-radius: 12px; }
.qty-btn { width: 40px; height: 38px; border: 0; background: none; font-size: 22px; color: var(--link); cursor: pointer; }
.qty-btn:disabled { opacity: .3; }
.qty-val { min-width: 32px; text-align: center; font-weight: 700; font-size: 17px; }

.star-pick { display: flex; gap: 2px; margin-bottom: 8px; }
.star-pick button { background: none; border: 0; font-size: 32px; line-height: 1; color: var(--hint); cursor: pointer; padding: 0 3px; }
.star-pick button.on { color: #f5b301; }

.review { padding: 8px 0; border-top: 1px solid var(--line); }
.review:first-child { border-top: 0; }

.seg { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 10px; padding-bottom: 2px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: none; border: 0; border-radius: 20px; padding: 7px 13px; background: var(--bg); color: var(--text); cursor: pointer; font-weight: 500; }
.seg button.on { background: var(--btn); color: var(--btn-text); }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 10px; }
.tile { background: var(--bg); border-radius: var(--radius); padding: 12px; }
.tile .n { font-size: 20px; font-weight: 700; }
.tile .l { color: var(--hint); font-size: 12px; }
.stats4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 8px; text-align: center; }
.stats4 .n { font-weight: 700; font-size: 14px; }
.stats4 .l { color: var(--hint); font-size: 11px; }
.diff { margin-top: 6px; }
.diff .row { padding: 3px 0; font-size: 14px; }
.diff .old { color: var(--bad); text-decoration: line-through; }
.diff .new { color: var(--ok); }

#tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: var(--bg); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
#tabbar[hidden] { display: none; }
.tab { flex: 1; min-width: 0; border: 0; background: none; padding: 7px 2px 6px; color: var(--hint); cursor: pointer; position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.tab .ic { font-size: 20px; line-height: 1.1; }
.tab .tx { font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.tab.on { color: var(--btn); }
.badge { position: absolute; top: 3px; left: calc(50% + 6px); background: var(--bad); color: #fff; border-radius: 10px; font-size: 11px; line-height: 1; padding: 3px 5px; min-width: 16px; text-align: center; }
.badge.inline { position: static; display: inline-block; margin-left: 6px; }

#mainbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
#mainbar[hidden] { display: none; }
#mainbtn { width: 100%; border: 0; border-radius: 12px; padding: 13px; background: var(--btn); color: var(--btn-text); font-weight: 700; font-size: 16px; cursor: pointer; }
#mainbtn:disabled { opacity: .5; }

#toasts { position: fixed; left: 12px; right: 12px; top: 12px; z-index: 100; display: flex; flex-direction: column; gap: 6px; pointer-events: none; align-items: center; }
.toast { background: #222; color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; max-width: 100%; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); }
.toast.ok { background: var(--ok); }

.modal-back { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 14px; }
.modal { background: var(--bg); border-radius: 16px; padding: 16px; width: 100%; max-width: 440px; max-height: 88vh; overflow-y: auto; }
.modal h2 { margin-bottom: 6px; }
.modal .btns { justify-content: flex-end; }

.chat { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.bubble { max-width: 82%; padding: 7px 11px; border-radius: 14px; background: var(--bg); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.mine { align-self: flex-end; background: var(--btn); color: var(--btn-text); border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.bubble .who { font-size: 12px; font-weight: 600; color: var(--link); margin-bottom: 1px; }
.bubble .tx { white-space: pre-wrap; }
.bubble .tm { font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.composer { position: sticky; bottom: 0; display: flex; gap: 8px; align-items: flex-end; background: var(--sec); padding: 8px 0 calc(8px + env(safe-area-inset-bottom)); }
.composer textarea { min-height: 40px; max-height: 120px; flex: 1; }
.composer textarea { background: var(--bg); border: 1.5px solid color-mix(in srgb, var(--hint) 60%, transparent); border-radius: 12px; }
.composer textarea::placeholder { color: var(--hint); opacity: .85; }
.composer textarea:focus { border-color: var(--btn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--btn) 22%, transparent); }
