/* Bold keypad: dark, flat, high contrast. */
:root {
  --bg: #000000;
  --card: #161616;
  --line: #3a3a3a;
  --text: #ffffff;
  --muted: #b5b5b5;
  --accent: #ffb000;
  --on-accent: #241800;
  --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, .sheet-body > h3, .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; }
.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; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pair > * { min-width: 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 .primary { background: var(--accent); }
.card.dim .named { opacity: 0.45; }
.named { display: flex; align-items: center; gap: 10px; }
.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; }

/* ---- Add screen: fits 375 × 667 without scrolling ---- */
.add { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.topbar { flex: none; height: 48px; display: flex; align-items: center; }
.trip-name { display: flex; align-items: center; gap: 8px; max-width: 100%; background: none; border: 0; padding: 0; color: var(--muted); }
.trip-name span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.display { flex: 1; min-height: 76px; display: flex; align-items: center; gap: 10px; }
.figures { flex: 1; min-width: 0; text-align: right; }
.amount { display: block; color: var(--accent); font-size: 60px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amount.long { font-size: 44px; }
.amount small { font-size: 0.55em; margin-right: 2px; }
.converted { color: var(--muted); font-size: 14px; }
.currency {
  flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  width: 64px; height: 64px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); font-size: 18px;
}
.currency .icon { width: 18px; height: 18px; }
.currency.foreign { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.currency.foreign .icon { stroke: var(--on-accent); }
.display.stacked { flex-direction: column; align-items: stretch; justify-content: center; gap: 4px; }
.stacked .currency { flex-direction: row; gap: 8px; align-self: flex-start; width: auto; height: 44px; padding: 0 12px; }
.stacked .figures { flex: none; }
.stacked .amount { letter-spacing: -1px; }

.keypad { flex: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.key { display: grid; place-items: center; height: 56px; 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: 62px; 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) {
  .key { height: 64px; }
  .category { height: 72px; }
}

/* ---- summary ---- */
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 14px; }
.stat.main b { font-size: 44px; color: var(--accent); }
.bar { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; }
.bar > div { grid-column: 1 / -1; height: 8px; background: var(--card); border-radius: var(--radius); }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: var(--radius); }
.entry .what, .entry .money { display: block; min-width: 0; }
.entry .what { flex: 1; overflow-wrap: anywhere; }
.entry .money { text-align: right; }
.entry small { display: block; }

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

/* ---- 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); }

/* ---- 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: 1px solid var(--line); width: 100%; max-width: 520px; margin: 0 auto; }
.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; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { max-width: 100%; overflow-wrap: anywhere; }

.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); }
