:root {
  --bg: #f4f1ea; --card: #fffdf8; --ink: #1b1c18; --mute: #66675f; --line: #e3dfd3;
  --acc: #1f7a4d; --acc-ink: #fff; --sel: #e6f3ea; --warn: #9a5b00;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #121310; --card: #1c1d19; --ink: #eeece4; --mute: #a3a297; --line: #2f302a;
    --acc: #3fbf7f; --acc-ink: #0d140f; --sel: #1d3226; --warn: #f0b04a; color-scheme: dark; }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 Manrope, system-ui, sans-serif;
  padding-bottom: calc(62px + env(safe-area-inset-bottom)); overflow-x: hidden; }
h1, h2 { font-family: Onest, Manrope, sans-serif; margin: 0 0 6px; line-height: 1.2; }
h1 { font-size: 26px; } h2 { font-size: 19px; }
button, .btn { font: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px; max-width: 640px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none;
  font: 800 19px Onest, sans-serif; }
.top-act { display: flex; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 999px;
  padding: 8px 14px; min-height: 40px; font-weight: 700; cursor: pointer; }

main { max-width: 640px; margin: 0 auto; padding: 0 16px; display: grid; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 18px 16px; }
.hint { color: var(--mute); margin: 0 0 4px; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin: 14px 0; }
.thumbs:empty { display: none; }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb b { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.65); color: #fff; border-radius: 999px;
  font-size: 13px; min-width: 22px; text-align: center; padding: 1px 6px; }
.thumb button { position: absolute; right: 4px; top: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.65); color: #fff; font-size: 20px; line-height: 1; cursor: pointer; }

.row-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 14px 0 10px; }
.btn { display: flex; align-items: center; justify-content: center; text-align: center; min-height: 50px; padding: 10px 14px;
  border-radius: 14px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font-weight: 700; cursor: pointer; }
.btn.primary { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.wide { width: 100%; }
.status { margin: 10px 0 0; color: var(--mute); white-space: pre-line; min-height: 1em; }
.status.err { color: var(--warn); }
.busy::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px;
  border: 2px solid var(--line); border-top-color: var(--acc); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.bill-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 6px; }
.bill-head h2 { overflow-wrap: break-word; }
.items { list-style: none; margin: 0; padding: 0; }
.item { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 10px 8px;
  border-bottom: 1px solid var(--line); border-radius: 10px; }
.item.on { background: var(--sel); }
.item .nm { font-weight: 700; overflow-wrap: break-word; }
.item .pr { color: var(--mute); font-size: 14px; }
.item .pr em { font-style: normal; color: var(--ink); font-weight: 700; }
.ctr { display: flex; align-items: center; gap: 4px; grid-row: span 2; }
.ctr button { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  color: var(--ink); font-size: 24px; font-weight: 700; line-height: 1; cursor: pointer; touch-action: manipulation; }
.ctr button.plus { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
.ctr button:disabled { opacity: .35; cursor: default; }
.ctr output { min-width: 30px; text-align: center; font: 800 20px Onest, sans-serif; }
.check { color: var(--mute); font-size: 14px; white-space: pre-line; margin: 12px 0; }
.check.warn { color: var(--warn); }

.share { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; }
.share img { width: 150px; height: 150px; border-radius: 10px; background: #fff; padding: 8px; }
.url { font-weight: 800; margin: 6px 0 0; overflow-wrap: break-word; }
@media (max-width: 420px) {
  .share { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .share img { width: 190px; height: 190px; }
}

.due { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; align-items: stretch; min-height: calc(46px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); background: var(--acc); color: var(--acc-ink); box-shadow: 0 -4px 14px rgba(0,0,0,.15); }
.due button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
.due-sum { flex: 1; display: flex; align-items: baseline; gap: 8px; padding: 0 16px; text-align: left; min-width: 0; align-self: center; }
.due-l { font-weight: 700; font-size: 14px; }
.due-sum strong { font: 800 20px Onest, sans-serif; white-space: nowrap; }
.due-n { font-size: 12px; opacity: .85; }
.due-menu { padding: 0 16px; font-weight: 800; border-left: 1px solid rgba(255,255,255,.25) !important; text-align: center; }
.due-how { display: none; flex: 1; align-items: center; justify-content: center; gap: 10px; font-weight: 800; font-size: 16px; padding: 0 16px; }
.due-how svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
.due.nobill .due-how { display: flex; }
.due.nobill .due-sum, .due.nobill .due-vid { display: none; }
.due.nobill .due-menu.empty { display: none; }

.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 88vh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--card); border-radius: 20px 20px 0 0; padding: 8px 16px calc(18px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(30px); opacity: .5; } }
.sheet-head { display: flex; justify-content: center; position: relative; min-height: 40px; align-items: center; }
.sheet-head .chip { position: absolute; right: 0; top: 2px; font-size: 20px; padding: 4px 12px; }
.grip { width: 44px; height: 5px; border-radius: 3px; background: var(--line); }
#shareBox[hidden] + #histBox { margin-top: 0; }
#histBox { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 8px; }

/* споделена сметка, споделяне, история */
.kicker { margin: 0; color: var(--acc); font-weight: 800; text-transform: uppercase; font-size: 13px; letter-spacing: .06em; }
.lines { list-style: none; margin: 12px 0; padding: 0; }
.lines li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.lines .nm { font-weight: 700; overflow-wrap: break-word; }
.lines .q { color: var(--mute); font-size: 14px; grid-column: 1; }
.lines .s { font-weight: 800; grid-row: span 2; align-self: center; white-space: nowrap; }
.sum { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin: 6px 0; font-weight: 700; }
.sum strong { font: 800 26px Onest, sans-serif; }
.btn.viber { background: #7360f2; color: #fff; border-color: #7360f2; text-decoration: none; }
.billqr { display: grid; grid-template-columns: 150px 1fr; gap: 16px; align-items: center; margin-top: 16px; }
.qrbox { width: 150px; height: 150px; background: #fff; border-radius: 10px; padding: 8px; }
.qrbox svg { width: 100%; height: 100%; display: block; }
a.url { display: block; color: var(--acc); text-decoration: none; margin: 2px 0 6px; }
@media (max-width: 420px) {
  .billqr { grid-template-columns: 1fr; justify-items: center; text-align: center; }
  .qrbox { width: 200px; height: 200px; }
}
.fold summary { list-style: none; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 40px; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary h2 { margin: 0; }
.fold summary::after { content: "▾"; color: var(--mute); font-size: 18px; transition: transform .2s; }
.fold[open] summary::after { transform: rotate(180deg); }
.fold summary .hint { margin: 0 0 0 auto; }
.hist { list-style: none; margin: 10px 0 0; padding: 0; }
.hist li { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); }
.hist li.cur { background: var(--sel); border-radius: 10px; }
.hist .open { text-align: left; background: none; border: 0; color: var(--ink); padding: 10px 8px; cursor: pointer; min-height: 52px; }
.hist .open b { display: block; overflow-wrap: break-word; }
.hist .open span { color: var(--mute); font-size: 14px; }
.hist .del { width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--warn);
  font-size: 20px; cursor: pointer; }

.btn.rev { background: #0666eb; color: #fff; border-color: #0666eb; text-decoration: none; }
.pay { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin: 12px 0; }
.field { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); margin: 10px 0; overflow: hidden; }
.field span { padding: 0 4px 0 12px; color: var(--mute); white-space: nowrap; }
.field input { flex: 1; min-width: 0; border: 0; background: none; color: var(--ink); font: inherit; font-weight: 700; padding: 12px 12px 12px 0; min-height: 48px; outline: none; }
#revBox { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 8px; }
.inst { margin-top: 12px; }
.inst-help { white-space: pre-line; margin-top: 8px; text-align: left; }
.inst-row { margin-top: 14px; }
.standalone .inst, .standalone .inst-row { display: none !important; }
.due-vid { display: flex; align-items: center; gap: 6px; padding: 0 14px; font-weight: 800; border-left: 1px solid rgba(255,255,255,.25) !important; text-align: center; }
.due-vid svg { width: 18px; height: 18px; fill: currentColor; }
.vid { position: fixed; inset: 0; z-index: 12; display: grid; place-items: center; }
.vid-box { position: relative; height: min(88vh, 177vw); aspect-ratio: 9 / 16; max-width: 92vw; }
.vid-box video { width: 100%; height: 100%; border-radius: 18px; background: #000; display: block; }
.vid-x { position: absolute; right: 8px; top: 8px; z-index: 1; font-size: 20px; padding: 4px 12px; }
@media (max-width: 360px) { .due-vid span { display: none; } }
#due { transition: opacity .14s ease, transform .14s ease; display: inline-block; }
#due.fade { opacity: 0; transform: translateY(3px); }
.qrwrap { position: relative; }
.rmark { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 22%; aspect-ratio: 1; border-radius: 22%;
  background: #0666eb; color: #fff; border: 4px solid #fff; display: grid; place-items: center; font: 800 26px/1 Onest, sans-serif; }
@media (max-width: 420px) { .rmark { font-size: 32px; } }
@media (prefers-reduced-motion: reduce) { #due { transition: none; } }
.btn.wa { background: #25d366; color: #0b1f12; border-color: #25d366; text-decoration: none; }
a.btn { text-decoration: none; }
.btn.ven { background: #008cff; color: #fff; border-color: #008cff; text-decoration: none; }
.vmark { background: #008cff; }
#venBox { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 8px; }
.pay { grid-template-columns: 1fr; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--bg); border: 1px solid var(--line); margin: 8px 0 4px; }
.seg button { min-height: 44px; border: 0; border-radius: 10px; background: none; color: var(--ink); font: inherit; font-weight: 700; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--acc); color: var(--acc-ink); }
.hist .hsh { min-height: 44px; padding: 0 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); color: var(--acc); font: inherit; font-weight: 700; cursor: pointer; }
/* текстът минава на нов ред, вместо да се реже или цепи по средата на думата */
h1, h2, h4, .hint, .btn, .nm, .check, .status { text-wrap: pretty; overflow-wrap: break-word; }
.due-sum { flex-wrap: wrap; row-gap: 0; padding-top: 6px; padding-bottom: 6px; }
.due-how { padding-top: 8px; padding-bottom: 8px; text-align: center; }
.btn { line-height: 1.25; }
.snt { display: inline-block; }   /* изречение: цялото минава на нов ред, ако не се побира */
.merged { color: var(--acc); font-weight: 700; margin: 0 0 6px; }
@media (max-width: 420px) { .due-n { display: none; } }
.offline { position: sticky; top: 0; z-index: 8; background: #9a5b00; color: #fff; padding: calc(8px + env(safe-area-inset-top)) 16px 8px; text-align: center; font-weight: 700; font-size: 14px; }
.vid-off { position: absolute; left: 12px; right: 12px; top: 50%; transform: translateY(-50%); margin: 0; text-align: center; color: #fff; font-weight: 700;
  background: rgba(0,0,0,.6); padding: 14px; border-radius: 14px; }
