/* Buckets — tuned for Galaxy Z Fold: narrow cover screen + near-square inner screen */
:root {
  --bg: #0b0f14;
  --surface: #131a22;
  --surface-2: #19222c;
  --line: #243140;
  --text: #e6edf3;
  --muted: #8b98a5;
  --accent: #5eead4;
  --accent-ink: #04241f;
  --warn: #fbbf24;
  --danger: #f87171;
  --good: #4ade80;
  --radius: 16px;
  --gutter: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8; --surface: #ffffff; --surface-2: #eef1f4; --line: #d8dee5;
    --text: #0f1720; --muted: #5b6774; --accent: #0d9488; --accent-ink: #ffffff;
    --warn: #b45309; --danger: #dc2626; --good: #15803d;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, "Samsung Sans", sans-serif;
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: contain;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
input, select {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; width: 100%; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.muted { color: var(--muted); }
.neg { color: var(--danger); }
.pos { color: var(--good); }
.hidden { display: none !important; }

/* ---------- shell ---------- */
#app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) var(--gutter) 8px;
  position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.brand { font-weight: 700; letter-spacing: .2px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }
.spacer { flex: 1; }
.ready-pill {
  display: flex; flex-direction: column; align-items: flex-end;
  padding: 6px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line);
}
.ready-pill small { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.ready-pill b { font-size: 15px; }
.ready-pill.has-money { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.ready-pill.has-money b { color: var(--accent); }
.ready-pill.over b { color: var(--danger); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: var(--surface); border: 1px solid var(--line); font-size: 18px;
}
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #0b0f14; font-size: 14px; }

main { flex: 1; padding: 0 var(--gutter) calc(84px + var(--safe-b)); }

/* ---------- bottom nav (cover screen) ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.bottom-nav button { padding: 9px 0 10px; display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11.5px; }
.bottom-nav button .ico { font-size: 20px; line-height: 1; }
.bottom-nav button.on { color: var(--accent); }

/* ---------- quick add ---------- */
.qa { display: flex; flex-direction: column; gap: 10px; }
.qa-amount {
  display: flex; align-items: baseline; justify-content: center; gap: 4px;
  padding: 6px 0 2px; min-height: 64px;
}
.qa-amount .cur { font-size: 26px; color: var(--muted); }
.qa-amount .num { font-size: 46px; font-weight: 700; letter-spacing: -1px; }
.qa-amount.empty .num { color: var(--muted); }
.qa-amount.refund .num { color: var(--good); }
.qa-meta { display: flex; gap: 8px; }
.qa-meta input { flex: 1; padding: 9px 12px; }
.chip-btn {
  white-space: nowrap; padding: 8px 12px; border-radius: 12px; background: var(--surface);
  border: 1px solid var(--line); font-size: 13px; color: var(--muted);
}
.chip-btn.on { color: var(--good); border-color: var(--good); }
.date-wrap { position: relative; }
.date-wrap input[type=date] { position: absolute; inset: 0; opacity: 0; }

.bucket-picker { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
.pick {
  position: relative; overflow: hidden; text-align: left;
  border-radius: 12px; padding: 8px 9px 7px; background: var(--surface); border: 1.5px solid var(--line);
  min-height: 58px; display: flex; flex-direction: column; justify-content: space-between;
}
.pick .fill { position: absolute; left: 0; right: 0; bottom: 0; opacity: .22; pointer-events: none; transition: height .4s ease; }
.pick .nm { position: relative; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pick .bal { position: relative; font-size: 12px; color: var(--muted); }
.pick.low .bal { color: var(--warn); }
.pick.neg .bal { color: var(--danger); }
.pick.sel { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent) inset; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }
.keypad button {
  height: 52px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  font-size: 22px; font-weight: 600;
}
.keypad button:active { background: var(--surface-2); transform: scale(.97); }
.keypad .k-sub { font-size: 18px; color: var(--muted); }
.primary {
  height: 54px; border-radius: 14px; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; font-size: 17px; width: 100%;
}
.primary:disabled { opacity: .35; }
.secondary {
  height: 48px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line);
  font-weight: 600; width: 100%;
}
.danger-btn { height: 48px; border-radius: 14px; width: 100%; color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 50%, transparent); font-weight: 600; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

/* ---------- bucket tanks (dashboard) ---------- */
.section-h { display: flex; align-items: center; justify-content: space-between; margin: 14px 2px 8px; }
.section-h h2 { margin: 0; font-size: 13px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 600; }
.section-h button { color: var(--accent); font-size: 13.5px; font-weight: 600; padding: 4px; }
.tanks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tank {
  position: relative; overflow: hidden; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); padding: 12px 12px 11px; text-align: left; min-height: 124px;
  display: flex; flex-direction: column; gap: 3px;
}
.tank .liquid {
  position: absolute; left: 0; right: 0; bottom: 0; pointer-events: none;
  transition: height .5s cubic-bezier(.2,.8,.2,1);
}
.tank .liquid::before { content: ""; position: absolute; inset: 0; background: var(--c); opacity: .2; }
.tank .liquid::after { content: ""; position: absolute; left: 0; right: 0; top: 0; height: 2px; background: var(--c); opacity: .85; }
.tank > *:not(.liquid) { position: relative; }
.tank .em { font-size: 22px; line-height: 1; }
.tank .nm { font-weight: 650; font-size: 14.5px; margin-top: 4px; }
.tank .bal { font-size: 22px; font-weight: 700; letter-spacing: -.4px; margin-top: auto; }
.tank .sub { font-size: 11.5px; color: var(--muted); }
.tank.low { border-color: color-mix(in srgb, var(--warn) 55%, transparent); }
.tank.low .bal { color: var(--warn); }
.tank.neg { border-color: color-mix(in srgb, var(--danger) 60%, transparent); }
.tank.neg .bal { color: var(--danger); }
.tank .flag { position: absolute; top: 10px; right: 10px; font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.tank.low .flag { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }
.tank.neg .flag { background: color-mix(in srgb, var(--danger) 20%, transparent); color: var(--danger); }

.add-tank { border-style: dashed; align-items: center; justify-content: center; color: var(--muted); font-weight: 600; }

/* ---------- activity ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-top: 1px solid var(--line); width: 100%; text-align: left; }
.item:first-child { border-top: 0; }
.item .em { font-size: 20px; width: 28px; text-align: center; }
.item .mid { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t2 { font-size: 12px; color: var(--muted); }
.item .amt { font-weight: 700; }
.who-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: 1px; }
.empty { padding: 22px; text-align: center; color: var(--muted); }

/* ---------- inner screen (unfolded) ---------- */
.wide-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.side { position: sticky; top: 64px; display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.panel .qa-amount { min-height: 54px; }
.panel .qa-amount .num { font-size: 40px; }
.panel .bucket-picker { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.panel .keypad button { height: 46px; }
.wide-actions { display: flex; gap: 8px; }
.wide-actions button { flex: 1; }
.summary-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 4px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; }
.stat small { display: block; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
.stat b { font-size: 19px; }

body.wide main { padding-bottom: 24px; }
body.wide .bottom-nav { display: none; }

/* ---------- sheets ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s ease; }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow: auto; background: var(--bg);
  border: 1px solid var(--line); border-bottom: 0; border-radius: 22px 22px 0 0;
  padding: 8px var(--gutter) calc(18px + var(--safe-b)); animation: up .2s cubic-bezier(.2,.8,.2,1);
}
body.wide .sheet-backdrop { align-items: center; }
body.wide .sheet { border-radius: 22px; border-bottom: 1px solid var(--line); max-height: 86vh; }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 4px auto 10px; }
.sheet h3 { margin: 2px 0 12px; font-size: 19px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 11px; }
.field label { font-size: 12.5px; color: var(--muted); }
.fund-row { display: grid; grid-template-columns: 1fr 120px; gap: 8px; align-items: center; padding: 7px 0; border-top: 1px solid var(--line); }
.fund-row .lbl { min-width: 0; }
.fund-row .lbl b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fund-row .lbl small { color: var(--muted); font-size: 12px; }
.fund-row input { text-align: right; padding: 9px 10px; }
.sticky-foot { position: sticky; bottom: calc(-18px - var(--safe-b)); background: var(--bg); padding: 10px 0 4px; display: flex; flex-direction: column; gap: 8px; }
.emoji-row { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-row button { width: 40px; height: 40px; border-radius: 10px; background: var(--surface); border: 1px solid var(--line); font-size: 20px; }
.emoji-row button.on { border-color: var(--accent); }
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.preset-row .chip-btn { padding: 6px 10px; font-size: 12.5px; }
.color-row { display: flex; gap: 8px; flex-wrap: wrap; }
.color-row button { width: 32px; height: 32px; border-radius: 50%; border: 2px solid transparent; }
.color-row button.on { border-color: var(--text); }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-b)); z-index: 30;
  background: var(--text); color: var(--bg); border-radius: 14px; padding: 11px 14px; font-weight: 600;
  display: flex; gap: 14px; align-items: center; max-width: calc(100% - 28px); box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
body.wide #toast { bottom: 24px; }
#toast[hidden] { display: none; }
#toast button { color: var(--accent); font-weight: 800; filter: brightness(.8); }
@media (prefers-color-scheme: light) { #toast button { filter: none; color: #5eead4; } }

/* ---------- login ---------- */
.login { max-width: 360px; margin: 14vh auto 0; padding: 0 var(--gutter); display: flex; flex-direction: column; gap: 12px; }
.login h1 { margin: 0 0 6px; display: flex; gap: 10px; align-items: center; }
.err { color: var(--danger); font-size: 13.5px; min-height: 18px; }
.offline { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); text-align: center; font-size: 12.5px; padding: 5px; }

@keyframes up { from { transform: translateY(30px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

/* very narrow (folded cover screen) tweaks */
@media (max-width: 380px) {
  .qa-amount .num { font-size: 42px; }
  .keypad button { height: 48px; }
  .bucket-picker { gap: 6px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- bank sync ---------- */
.bank-banner {
  display: flex; align-items: center; gap: 8px; width: 100%; margin: 4px 0 10px; padding: 11px 14px; border-radius: 14px;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent);
  font-size: 14px; text-align: left;
}
.bank-banner span { margin-left: auto; color: var(--accent); font-weight: 700; }
.badge { display: inline-grid; place-items: center; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; position: relative; top: -8px; margin-left: -4px; }
.badge.inline { top: -1px; margin-left: 4px; }
.cleared { color: var(--good); font-weight: 600; }
textarea { background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; width: 100%;
  outline: none; font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; color: inherit; resize: vertical; word-break: break-all; }
textarea:focus { border-color: var(--accent); }
.steps { padding-left: 20px; margin: 0 0 12px; font-size: 13.5px; }
.steps li { margin-bottom: 4px; }
.badge.corner { position: absolute; top: -5px; right: -5px; margin: 0; }

/* ---------- plan UI ---------- */
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 600; font-size: 13.5px; }
.seg button.on { background: var(--surface-2); color: var(--text); box-shadow: 0 0 0 1px var(--line) inset; }
.qa-info { text-align: center; font-size: 13.5px; color: var(--muted); min-height: 18px; margin-top: -4px; }
.qa-info b { color: var(--text); }
.qa-info.neg b:last-child { color: var(--danger); }
.more-btn { width: 100%; padding: 8px; border-radius: 12px; color: var(--muted); font-size: 13px; border: 1px dashed var(--line); }
.pick-group { font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); margin: 6px 2px -2px; }
.tank .flag.next { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.stat[role=button] { cursor: pointer; }
.log { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px; font: 11px/1.45 ui-monospace, Menlo, monospace; max-height: 45vh; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0 0 8px; }
