/* Penny Pincher — mobile-first, works great on desktop too. */

:root {
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-2: #eef1ec;
  --text: #14201a;
  --text-muted: #687a70;
  --border: #e4e8e0;
  --brand: #16a34a;
  --brand-strong: #15803d;
  --brand-soft: #dcfce7;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --shadow: 0 1px 2px rgba(16, 32, 24, 0.06), 0 8px 24px rgba(16, 32, 24, 0.05);
  --radius: 16px;
  --radius-sm: 11px;
  --maxw: 560px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0f0d;
    --surface: #161b17;
    --surface-2: #1f261f;
    --text: #e9efe9;
    --text-muted: #92a398;
    --border: rgba(255, 255, 255, 0.09);
    --brand: #22c55e;
    --brand-strong: #16a34a;
    --brand-soft: rgba(34, 197, 94, 0.16);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.16);
    --warn: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-strong); text-decoration: none; }

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -0.01em; }

/* ---------- Web top bar (hidden inside the native app) ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  width: min(100% - 32px, var(--maxw));
  margin-inline: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.brand { display: inline-flex; align-items: center; gap: 9px; color: var(--text); font-weight: 700; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 28px; height: 28px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
}
.brand-name { font-size: 16px; }
.topnav { display: flex; gap: 4px; }
.topnav-link {
  padding: 7px 12px;
  border-radius: 9px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
}
.topnav-link.active { color: var(--text); background: var(--surface-2); }

/* ---------- Page shell ---------- */
.page {
  width: min(100% - 32px, var(--maxw));
  margin-inline: auto;
  /* The `native-inset` class already adds the device safe-area insets in the
     app, so this is just fixed breathing room. Don't re-add env() here or the
     top/bottom insets double up. */
  padding-top: 18px;
  padding-bottom: 44px;
}

.screen-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}
.screen-head.with-back { gap: 6px; }
.screen-title { font-size: 26px; }
.eyebrow {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--brand-strong);
}
.back-link {
  font-weight: 600;
  color: var(--text-muted);
  font-size: 15px;
  padding: 4px 2px;
}
.screen-head.with-back .screen-title { font-size: 20px; }

.block { margin-top: 22px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; }
.block-title { font-size: 15px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; margin-bottom: 10px; }
.block-action { font-size: 14px; font-weight: 600; }
.footnote { margin-top: 22px; color: var(--text-muted); font-size: 13px; text-align: center; }

/* ---------- Cards & rows ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card.list, .card.cat-list { padding: 4px 16px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  width: 100%;
  text-align: left;
}
.row:last-child { border-bottom: 0; }
.row-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-note { color: var(--text-muted); font-weight: 500; }
.row-sub { color: var(--text-muted); font-size: 13px; }
.row-amount { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.row-emoji, .cat-emoji {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border-radius: 11px;
  font-size: 19px;
  background: color-mix(in srgb, var(--chip-color, var(--brand)) 16%, var(--surface));
  flex-shrink: 0;
}

/* ---------- Summary card ---------- */
.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 15px;
}
.summary-card-head { display: flex; align-items: center; justify-content: space-between; }
.summary-card-title { font-size: 13px; font-weight: 700; color: var(--text-muted); }
.summary-card-pct { font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-strong); }
.summary-card-pct.close { background: #fef3c7; color: #b45309; }
.summary-card-pct.over { background: var(--danger-soft); color: var(--danger); }
.summary-card-amount { font-size: 27px; font-weight: 800; letter-spacing: -0.02em; margin-top: 10px; font-variant-numeric: tabular-nums; }
.summary-card-sub { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; }
.summary-card-foot { font-size: 13px; font-weight: 600; color: var(--brand-strong); margin-top: 9px; }
.summary-card-foot.over { color: var(--danger); }

/* ---------- Progress bars ---------- */
.bar { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--bar-color, var(--brand));
  transition: width 0.3s ease;
}
.bar-fill.close { background: var(--warn); }
.bar-fill.over { background: var(--danger); }

/* ---------- Category progress (home) ---------- */
.cat-progress { display: block; padding: 13px 0; border-bottom: 1px solid var(--border); }
.cat-progress:last-child { border-bottom: 0; }
.cat-progress-head { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.cat-name { font-weight: 600; font-size: 15px; flex: 1; }
.cat-amount { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 14px; }
.cat-amount.over { color: var(--danger); }
.cat-budget { color: var(--text-muted); font-weight: 500; }

/* ---------- History ---------- */
.period-row { padding: 14px 0; border-bottom: 1px solid var(--border); }
.period-row:last-child { border-bottom: 0; }
.period-row.is-current .period-label { color: var(--brand-strong); }
.period-head { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 9px; gap: 10px; }
.period-labels { display: flex; flex-direction: column; }
.period-label { font-weight: 700; font-size: 15px; }
.period-sub { color: var(--text-muted); font-size: 13px; }
.period-chip { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.period-chip.under { background: var(--brand-soft); color: var(--brand-strong); }
.period-chip.over { background: var(--danger-soft); color: var(--danger); }
.period-chip.neutral { background: var(--surface-2); color: var(--text-muted); }
.period-foot { color: var(--text-muted); font-size: 13px; margin-top: 7px; font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid transparent;
  border-radius: 13px;
  padding: 13px 18px;
  font-size: 16px;
  font-weight: 650;
  cursor: pointer;
  font-family: inherit;
  line-height: 1;
  transition: filter 0.15s ease, background 0.15s ease;
}
.btn:active { filter: brightness(0.95); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn-block { display: flex; width: 100%; margin-top: 16px; }
.signout { margin-top: 12px; color: var(--danger); }

/* ---------- Floating add button (web) ---------- */
.fab-web {
  position: fixed;
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(22px + env(safe-area-inset-bottom));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 14px 20px;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(22, 163, 74, 0.4);
}
.fab-plus { font-size: 20px; line-height: 1; }

/* ---------- Forms ---------- */
.form .field { margin-bottom: 15px; }
.field-row { display: flex; gap: 12px; }
.field-grow { flex: 1; }
.field-emoji { width: 84px; }
label, .field-label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field-hint, .amount-hint { color: var(--text-muted); font-size: 13px; margin: 6px 0 0; }

input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"] {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  -webkit-appearance: none;
  appearance: none;
}
input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
input::placeholder { color: color-mix(in srgb, var(--text-muted) 75%, transparent); }

.form-divider { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
.form-foot { margin: 14px 0 0; text-align: center; font-size: 14px; }
.form-errors {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 11px;
  padding: 11px 13px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 15px;
}

/* Amount entry (hero) */
.amount-field {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 0 2px;
}
.amount-currency { font-size: 34px; font-weight: 700; color: var(--text-muted); }
.amount-input {
  width: 100%;
  max-width: 220px;
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  font-size: 52px !important;
  font-weight: 800;
  text-align: center;
  padding: 0 !important;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.amount-input:focus { outline: none; }
.amount-input::-webkit-outer-spin-button, .amount-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.amount-hint { text-align: center; margin-bottom: 8px; }

.amount-inline { display: flex; align-items: center; gap: 8px; }
.amount-inline .amount-currency-sm { font-size: 18px; font-weight: 700; color: var(--text-muted); }

/* Category chips */
.picker { border: 0; padding: 0; margin: 4px 0 15px; }
.picker legend { font-size: 14px; font-weight: 600; padding: 0; margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 13px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  user-select: none;
}
.chip-input { position: absolute; opacity: 0; pointer-events: none; }
.chip-emoji { font-size: 16px; }
.chip:has(.chip-input:checked) {
  border-color: var(--chip-color, var(--brand));
  background: color-mix(in srgb, var(--chip-color, var(--brand)) 14%, var(--surface));
  color: color-mix(in srgb, var(--chip-color, var(--brand)) 60%, var(--text));
}
.chip:has(.chip-input:focus-visible) { box-shadow: 0 0 0 3px var(--brand-soft); }

/* Color swatches */
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--swatch);
  cursor: pointer;
  position: relative;
  box-shadow: inset 0 0 0 2px var(--surface), 0 0 0 1px var(--border);
}
.swatch-input { position: absolute; opacity: 0; }
.swatch:has(.swatch-input:checked) { box-shadow: inset 0 0 0 3px var(--surface), 0 0 0 2px var(--swatch); }

/* Emoji input */
.emoji-input { text-align: center; font-size: 22px !important; }

/* Segmented control */
.segmented { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: 12px; }
.seg { flex: 1; margin: 0; }
.seg-input { position: absolute; opacity: 0; }
.seg span {
  display: block;
  text-align: center;
  padding: 9px;
  border-radius: 9px;
  font-weight: 600;
  font-size: 15px;
  color: var(--text-muted);
}
.seg:has(.seg-input:checked) span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.code-input { text-transform: uppercase; letter-spacing: 0.18em; font-weight: 700; text-align: center; }

/* ---------- Auth ---------- */
.auth {
  width: min(100% - 32px, 400px);
  margin: 0 auto;
  padding-top: 40px;
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand h1 { font-size: 24px; margin-top: 14px; }
.auth-brand p { color: var(--text-muted); margin: 6px 0 0; }
.brand-mark-lg { width: 56px; height: 56px; border-radius: 16px; font-size: 34px; margin: 0 auto; }
.auth-switch { text-align: center; margin-top: 18px; color: var(--text-muted); font-size: 15px; }

/* ---------- Settings bits ---------- */
.settings-row { display: flex; align-items: center; justify-content: space-between; }
.settings-label { color: var(--text-muted); font-weight: 600; font-size: 14px; }
.settings-value { font-weight: 600; }
.invite-card { text-align: center; }
.invite-help { color: var(--text-muted); font-size: 14px; margin: 0 0 12px; }
.invite-code {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--brand-strong);
  background: var(--brand-soft);
  border-radius: 12px;
  padding: 14px;
  text-indent: 0.22em;
}
.invite-actions { display: flex; gap: 10px; margin-top: 14px; }
.invite-actions .btn { flex: 1; margin-top: 0; padding: 11px; font-size: 15px; }
.invite-actions form { flex: 1; display: flex; }
.invite-actions form .btn { width: 100%; }

.avatar {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 700;
  font-size: 14px;
  flex-shrink: 0;
}
.tag {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: var(--brand-soft);
  color: var(--brand-strong);
  padding: 1px 6px;
  border-radius: 6px;
}
.row-action {
  background: transparent;
  border: 0;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 4px;
}
.row-action.danger { color: var(--danger); }
.switch-row { cursor: pointer; background: transparent; border: 0; border-bottom: 1px solid var(--border); font-family: inherit; }
.member-row { gap: 12px; }
.danger-form { margin-top: 10px; }

/* ---------- Empty & misc ---------- */
.empty { text-align: center; padding: 26px 16px; }
.empty-title { font-weight: 700; margin: 0; }
.empty-sub { color: var(--text-muted); margin: 6px 0 14px; font-size: 14px; }
.nudge { font-size: 12px; font-weight: 600; color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); padding: 3px 9px; border-radius: 999px; }

/* ---------- Flash ---------- */
.flash {
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 14px;
}
.flash-notice { background: var(--brand-soft); color: var(--brand-strong); }
.flash-alert { background: var(--danger-soft); color: var(--danger); }

/* Tailwind-style `native:` variant. The Ruby Native shell marks the document
   with [data-native-app], so anything tagged `native:hidden` is web-only chrome
   (page titles, back/cancel links, the bottom submit button) that the native
   navigation bar already provides. Mirrors the gem's own `.native-hidden`. */
[data-native-app] .native\:hidden { display: none !important; }
