/* Budget PWA — white theme with Mission Control's brand orange accent
   (#e07a56), so it reads as a sibling of the Quick Dump app while being the
   light-background version Paul asked for. Same Inter typography, same radii. */
:root {
  --bg: #ffffff;
  --surface: #ffffff;
  --surface-alt: #faf8f6;
  --border: #e7e2dc;
  --border-strong: #d8d1c8;
  --text: #1a1916;
  --text-secondary: #6b645d;
  --text-muted: #928b83;
  --accent: #e07a56;
  --accent-hover: #d06a46;
  --accent-tint: #fbeee8;
  --progress: #4C25E1;
  --success: #3f9d63;
  --success-tint: #eaf6ee;
  --error: #d64545;
  --warning: #c98a2e;
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 18px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  overflow-x: hidden;
  touch-action: pan-y;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* Header */
header {
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 0 8px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.header-inner {
  max-width: 520px;
  width: 100%;
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}
header h1 { font-size: 19px; font-weight: 700; letter-spacing: -0.3px; }
header .logo {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
header .logo img { width: 32px; height: 32px; display: block; object-fit: contain; }
.settings-btn {
  margin-left: auto;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-family: var(--font);
  font-size: 13px; font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.settings-btn:active { background: var(--border); }
#refreshBtn { margin-left: auto; font-size: 17px; padding: 8px 13px; }
#settingsBtn { margin-left: 8px; }

/* Main / screens */
main {
  flex: 1; min-height: 0;
  width: 100%; max-width: 520px;
  margin: 0 auto;
  padding: 16px 20px calc(env(safe-area-inset-bottom, 0px) + 72px);
  overflow-y: auto;
  display: flex; flex-direction: column;
}
.screen { display: flex; flex-direction: column; flex: 1; min-height: 0; }
[hidden] { display: none !important; }

#ptr { height: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 12px; font-weight: 600; transition: height 0.2s ease; }
#ptr::after { content: '↓  Pull to refresh'; }
#ptr.ready::after { content: '↑  Release to refresh'; color: var(--accent); }
#ptr.refreshing::after { content: 'Refreshing…'; color: var(--accent); }

@keyframes slideFromRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes slideFromLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes slideFromBottom { from { transform: translateY(100%); } to { transform: translateY(0); } }
.screen.anim-right { animation: slideFromRight 0.24s cubic-bezier(0.2,0,0,1); }
.screen.anim-left { animation: slideFromLeft 0.24s cubic-bezier(0.2,0,0,1); }
.screen.anim-up { animation: slideFromBottom 0.26s cubic-bezier(0.2,0,0,1); }

.week-label {
  font-size: 13px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* Category cards */
.cards { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  transition: border-color 0.12s, transform 0.08s;
}
.card:active { transform: scale(0.99); border-color: var(--accent); }
.card.dragging { opacity: 0.92; transform: scale(1.03); box-shadow: 0 10px 28px rgba(0,0,0,0.16); border-color: var(--accent); position: relative; z-index: 5; }
@keyframes cardPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(224,122,86,0); border-color: var(--border); }
  50% { box-shadow: 0 0 16px 2px rgba(224,122,86,0.55); border-color: var(--accent); }
}
.card.card-updated { animation: cardPulse 0.85s ease-in-out 2; }
.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.card-name { font-size: 16px; font-weight: 700; letter-spacing: -0.2px; }
.card-remaining { font-size: 20px; font-weight: 800; letter-spacing: -0.4px; font-variant-numeric: tabular-nums; }
.card-remaining.over { color: var(--error); }
.card-sub { margin-top: 3px; font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.card-sub .over-label { color: var(--error); font-weight: 600; }
.bar { margin-top: 12px; height: 7px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; transition: width 0.25s; }
.bar-fill.over { background: var(--error); }

/* Recent list */
.recent { margin-top: 22px; padding-bottom: 24px; }
.recent-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); margin-bottom: 8px; }
.recent-list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
/* Swipe-to-delete rows (iOS style) — shared by Recent + Settings categories */
.swipe-row { position: relative; overflow: hidden; border-radius: var(--radius-sm); }
.swipe-content { position: relative; z-index: 2; transition: transform 0.2s ease; }
.swipe-del {
  position: absolute; top: 0; right: 0; bottom: 0; width: 76px;
  border: none; background: var(--error); color: #fff;
  display: flex; align-items: center; justify-content: center;
  z-index: 1; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.swipe-del svg { width: 22px; height: 22px; }
.swipe-row.open .swipe-content { transform: translateX(-76px); }

.recent-item { list-style: none; border: 1px solid var(--border); font-size: 13.5px; }
.ri-inner {
  background: var(--surface-alt);
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 4px;
  cursor: pointer;
}
.ri-inner:active { background: var(--border); }
.ri-main { display: flex; align-items: center; gap: 10px; }
.ri-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.ri-cat { color: var(--text-secondary); }
.ri-sub { color: var(--text-muted); font-size: 12px; }
.ri-noteicon svg { width: 13px; height: 13px; vertical-align: -2px; color: var(--accent); }

/* Entry pad */
.back-btn {
  align-self: flex-start;
  background: none; border: none;
  color: var(--accent); font-family: var(--font);
  font-size: 15px; font-weight: 600; cursor: pointer;
  padding: 4px 0; margin-bottom: 8px;
  -webkit-tap-highlight-color: transparent;
}
.pad-category { font-size: 15px; font-weight: 600; color: var(--text-secondary); text-align: center; }
.pad-amount {
  font-size: 52px; font-weight: 800; text-align: center;
  letter-spacing: -1px; font-variant-numeric: tabular-nums;
  margin: 14px 0 20px; color: var(--text);
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.keypad button {
  font-family: var(--font);
  font-size: 26px; font-weight: 600;
  padding: 18px 0;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.06s, background 0.1s;
}
.keypad button:active { transform: scale(0.96); background: var(--border); }
.keypad button.key-alt { font-size: 20px; color: var(--text-secondary); }
.pad-note { margin-top: 2px; }
.dm-meta { font-size: 13.5px; color: var(--text-secondary); margin-bottom: 6px; }
.dm-note-wrap { margin: 6px 0 14px; }
.dm-note { margin-top: 6px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; font-size: 15px; line-height: 1.5; white-space: pre-wrap; }

/* Category history modal */
.modal-tall { max-height: 82vh; display: flex; flex-direction: column; }
.hm-body { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; margin: 8px 0 14px; }
.hm-loading { color: var(--text-muted); text-align: center; padding: 22px 0; }
.hm-week { padding: 14px 0; }
.hm-week.hm-divider { border-top: 1px solid var(--border); }
.hm-week-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.hm-week-label { font-weight: 700; font-size: 14px; }
.hm-week-fig { font-size: 12.5px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.hm-bar { margin: 9px 0 5px; height: 8px; background: var(--surface-alt); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.hm-bar-fill { height: 100%; border-radius: 6px; transition: width 0.25s; }
.hm-bar-fill.under { background: var(--success); }
.hm-bar-fill.near { background: var(--warning); }
.hm-bar-fill.over { background: var(--error); }
.hm-diff { font-size: 12px; font-weight: 600; }
.hm-diff.good { color: var(--success); }
.hm-diff.bad { color: var(--error); }
.hm-txns { list-style: none; margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.hm-txn { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; }
.hm-txn-amt { font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 8px; }
.hm-txn-meta { color: var(--text-muted); font-size: 12px; }
.hm-txn-note { margin-top: 4px; color: var(--text-secondary); font-size: 12.5px; }

/* Send / save buttons */
.send-btn {
  margin-top: auto;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius);
  font-family: var(--font); font-size: 17px; font-weight: 700;
  padding: 17px; width: 100%; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, transform 0.08s;
}
.send-btn:active { transform: scale(0.98); }
.send-btn:disabled { background: var(--border-strong); color: #fff; }
.send-btn.ok { background: var(--success); }
.send-btn.err { background: var(--error); }

/* Settings */
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin: 18px 0 10px; }
.settings-cats { display: flex; flex-direction: column; gap: 12px; }
#screen-settings .send-btn { margin-top: 16px; }
.settings-bottom-spacer { height: 60px; flex: none; }
.set-cat { border: 1px solid var(--border); }
.sc-inner {
  background: var(--surface-alt);
  padding: 10px 12px;
  display: flex; align-items: center; gap: 8px;
}
.sc-inner .sc-name { flex: 3; min-width: 0; }
.sc-budget-wrap { flex: 1; min-width: 0; position: relative; }
.sc-budget-prefix { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-muted); font-weight: 600; pointer-events: none; }
.sc-inner .sc-budget { width: 100%; padding-left: 24px; text-align: right; }
.add-cat-btn { margin-top: 12px; width: 100%; background: var(--accent-tint); color: var(--accent); border: 1px dashed var(--accent); border-radius: var(--radius); font-family: var(--font); font-size: 15px; font-weight: 700; padding: 13px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.add-cat-btn:active { background: #f6ddd2; }

input[type="url"], input[type="text"], input[type="number"], input[inputmode] {
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px; /* 16px avoids iOS focus-zoom */
  padding: 12px 13px;
  width: 100%;
  outline: none;
  transition: border-color 0.12s;
  -webkit-appearance: none;
}
input:focus { border-color: var(--accent); }
input::placeholder { color: var(--text-muted); }
.modal-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.modal-label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }

/* Setup modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(26, 25, 22, 0.45);
  display: flex; align-items: flex-end;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.modal-backdrop.open { opacity: 1; }
.modal {
  background: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 24px 22px calc(env(safe-area-inset-bottom, 0px) + 22px);
  width: 100%; max-width: 520px; margin: 0 auto;
  box-shadow: 0 -8px 40px rgba(0,0,0,0.18);
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.2,0,0,1);
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.modal p { font-size: 13.5px; color: var(--text-secondary); margin-bottom: 16px; }
.modal-save-btn {
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 16px; font-weight: 700;
  padding: 15px; width: 100%; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 22px);
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff;
  border-radius: var(--radius); padding: 12px 18px;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  z-index: 9999;
  animation: toast-in 0.18s ease;
}
.toast.ok { background: var(--success); }
.toast.warn { background: var(--warning); }
.toast.err { background: var(--error); }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(8px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
