/* Bold keypad: dark, flat, high contrast. */
:root {
  --bg: #000000;
  --card: #161616;
  --line: #3a3a3a;
  --text: #ffffff;
  --muted: #b5b5b5;
  --accent: #2fd9d9;
  --on-accent: #002323;
  --over: #ff5252;
  --radius: 6px;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; overflow: hidden; background: var(--bg); }
body {
  color: var(--text);
  font: 16px/1.35 system-ui, -apple-system, sans-serif;
  -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
button:disabled { opacity: 0.3; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
main { flex: 1; min-height: 0; max-width: 520px; width: 100%; margin: 0 auto; }
.screen { height: 100%; padding: 0 12px; }
.scroll { overflow-y: auto; padding-bottom: 24px; }
.scroll > *, .sheet-body > *, form > *, .empty > * { margin-top: 8px; }

h1 { font-size: 24px; margin-top: 12px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; color: var(--muted); }
.scroll > h2, .scroll > h3 { margin-top: 20px; }
.muted { color: var(--muted); }
.warning { border-left: 3px solid var(--accent); padding-left: 10px; }
.icon { width: 24px; height: 24px; flex: none; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- buttons and fields ---- */
.btn {
  min-height: 44px;
  min-width: 44px;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.btn:active, .key:active { background: var(--line); }
.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.primary:active { background: var(--accent); opacity: 0.8; }
.primary .icon { stroke: var(--on-accent); }
.danger { color: var(--over); }
.wide { display: block; width: 100%; }
.square { display: grid; place-items: center; padding: 0; width: 48px; }

input, select {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  font-size: 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  -webkit-appearance: none;
  appearance: none;
}
.field { display: block; }
.field > span, .field > small { display: block; margin: 4px 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card > .btn, .card > .field { margin-top: 8px; }
.card input, .card select, .card .btn { background: var(--bg); }
.card.dim .named { opacity: 0.45; }
.named { display: flex; align-items: center; gap: 10px; }
.dot { flex: none; width: 18px; height: 18px; border-radius: 50%; background: var(--who, var(--accent)); }
.member { border-left: 5px solid var(--who); }
.actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

.row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; text-align: left; }
.row > b:first-child { min-width: 44px; }
.row > small { margin-left: auto; text-align: right; }
.row.selected { border-color: var(--accent); border-width: 2px; }
.list > * { margin-bottom: 8px; }

/* ---- For buttons, used on Add and in the edit form ---- */
.for { display: grid; grid-template-columns: repeat(var(--across, 3), minmax(0, 1fr)); gap: 6px; }
.who { min-width: 0; height: 44px; padding: 0 4px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-weight: 600; border-bottom: 5px solid var(--who, var(--accent)); }
.who.on { background: var(--who, var(--accent)); border-color: var(--who, var(--accent)); color: #000; font-weight: 700; }
.who.on:active { background: var(--who, var(--accent)); opacity: 0.8; }
.percent { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; line-height: 1.05; }
.percent b { font-size: 17px; }
.percent small { font-size: 11px; }

/* ---- Add screen: fits 375 × 667 without scrolling ---- */
.add { display: flex; flex-direction: column; gap: 6px; padding-bottom: 6px; overflow-y: auto; }
.month { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 46px; padding-top: 2px; }
.month > div { min-width: 0; }
.month p { line-height: 1.2; font-size: 14px; white-space: nowrap; }
.spent { font-size: 22px; font-variant-numeric: tabular-nums; }
.datepick {
  position: relative; flex: none; display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 10px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); font-size: 14px; white-space: nowrap;
}
.datepick .icon { width: 18px; height: 18px; }
.datepick input { position: absolute; inset: 0; min-height: 0; height: 100%; opacity: 0; cursor: pointer; }
.datepick.past { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 700; }
.datepick.past .icon { stroke: var(--on-accent); }
.datepick:focus-within { outline: 2px solid var(--text); }
.add .for { flex: none; }

.display { flex: 1 0 90px; display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 10px; }
.pickers { display: flex; flex-direction: column; gap: 6px; }
.pickers .btn { width: 60px; min-width: 0; height: 42px; min-height: 42px; padding: 0; }
.currency { display: flex; align-items: center; justify-content: center; gap: 3px; font-size: 15px; }
.currency .icon { width: 14px; height: 14px; }
.figures { min-width: 0; text-align: right; }
.amount { display: block; color: var(--accent); font-size: 50px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.long { font-size: 36px; }
.amount small { font-size: 0.55em; margin-right: 2px; }
.shares { font-size: 13px; line-height: 1.25; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; }
.converted { color: var(--muted); font-size: 12px; line-height: 1.2; }

.keypad { flex: 4 0 210px; max-height: 280px; display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: 1fr; gap: 6px; }
.key { display: grid; place-items: center; min-height: 48px; font-size: 24px; font-weight: 600; background: var(--card); border: 0; border-radius: var(--radius); }
.key .icon { width: 30px; height: 30px; }

.categories { flex: none; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.category { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; height: 56px; padding: 2px; }
.category span { font-size: 12px; line-height: 1.1; text-align: center; overflow: hidden; max-height: 2.2em; overflow-wrap: anywhere; }

@media (min-height: 760px) {
  .category { height: 72px; }
}

/* ---- summary ---- */
.months { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.months h1 { margin: 0; text-align: center; font-size: 22px; }
.stat b { display: block; font-size: 44px; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat > span { display: block; }
.entry .what, .entry .money { display: block; min-width: 0; }
.entry .what { flex: 1; overflow-wrap: anywhere; }
.entry .money { text-align: right; white-space: nowrap; }
.entry small { display: block; }

.empty { display: flex; flex-direction: column; justify-content: center; text-align: center; }

/* ---- edit form and percentages ---- */
.who-edit { display: grid; gap: 6px; }
.who-edit .percent { width: 100%; }
.shared p { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; }
.shared p:first-child:not(.muted) { border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-bottom: 3px; }
.shared b { font-variant-numeric: tabular-nums; }
.sharer { display: grid; grid-template-columns: minmax(0, 1fr) 110px; gap: 8px; align-items: center; }
.sharer b { overflow-wrap: anywhere; min-width: 0; }
.card.total { font-weight: 700; }
.card.total.bad { color: var(--over); border-color: var(--over); }

/* ---- settings ---- */
.section { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.link { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; text-align: left; font-weight: 600; border-left: 4px solid var(--accent); }
.link span { flex: 1; min-width: 0; }
.link .icon:last-child { width: 18px; height: 18px; }

/* ---- tabs ---- */
.tabbar { flex: none; display: flex; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabbar .btn { flex: 1; display: flex; flex-direction: column; align-items: center; height: 54px; padding: 5px; background: none; border: 0; border-radius: 0; color: var(--muted); font-size: 12px; }
.tabbar .icon { stroke: var(--muted); }
.tabbar .on { color: var(--accent); font-weight: 700; }
.tabbar .on .icon { stroke: var(--accent); }
.tabbar .update { position: relative; }
.tabbar .update::after { content: ""; position: absolute; top: 5px; left: calc(50% + 10px); width: 10px; height: 10px; border-radius: 50%; background: var(--over); }

/* ---- sheets and toast ---- */
.sheet {
  position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}
.sheet-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 12px; border-bottom: 4px solid var(--accent); width: 100%; max-width: 520px; margin: 0 auto; }
.sheet-head h2 { color: var(--accent); }
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; width: 100%; max-width: 520px; margin: 0 auto; padding: 4px 12px calc(24px + env(safe-area-inset-bottom)); }
.sheet-body .categories { margin-top: 12px; }

.toast {
  position: fixed; z-index: 20; top: calc(env(safe-area-inset-top) + 4px); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; width: calc(100% - 16px); max-width: 504px; padding: 6px 6px 6px 12px;
  background: var(--card); border: 2px solid var(--accent); border-radius: var(--radius);
}
.toast span { flex: 1; min-width: 0; min-height: 44px; display: flex; align-items: center; font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.toast .btn { flex: none; padding: 8px 10px; font-size: 15px; }
.toast.error { border-color: var(--over); }
/* Add screen: placed by script. Message on top, its buttons underneath. */
.toast.low { transform: none; max-width: none; flex-wrap: wrap; justify-content: flex-end; align-content: center; gap: 4px 8px; padding: 4px 4px 4px 8px; }
.toast.low span { flex: 1 0 100%; }
.toast.low span:not(:only-child) { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; min-height: 0; font-size: 14px; line-height: 1.25; }
