/* Debt Freedom — warm cream theme */
:root {
  --bg: #faf7f1;           /* soft warm off-white, like aged paper */
  --surface: #ffffff;      /* cards pop slightly */
  --surface-2: #f1ece2;    /* secondary surface */
  --border: #e0d8c8;       /* warm light border */
  --text: #2a2520;         /* warm near-black */
  --muted: #7a6f60;        /* warm gray */
  --accent: #16a34a;       /* deeper green for contrast on light bg */
  --accent-2: #0891b2;     /* deeper cyan */
  --warn: #d97706;         /* amber */
  --danger: #dc2626;       /* red */
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 4px 12px rgba(42, 37, 32, 0.08);
  --tab-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.phone {
  width: 100%;
  max-width: 375px;
  min-height: 100dvh;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.view {
  flex: 1;
  padding: calc(20px + var(--safe-top)) 16px
    calc(var(--tab-h) + 24px + var(--safe-bottom));
  overflow-y: auto;
}

/* Tab bar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 375px;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
}

.tab {
  background: transparent;
  border: 0;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font: inherit;
  cursor: pointer;
  padding: 8px 0;
}

.tab[aria-current="page"] {
  color: var(--accent);
}

.tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tab-label {
  font-size: 11px;
  letter-spacing: 0.02em;
}

/* Cards / shared */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.h-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 16px;
}

.muted {
  color: var(--muted);
}

.progress {
  height: 10px;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
  transition: width 240ms ease;
}

/* Buttons */
button.btn,
.btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #ffffff;
  font: 600 15px/1 inherit;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  width: 100%;
  cursor: pointer;
}

.btn.secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

/* PIN screen */
.pin-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px;
  gap: 24px;
}

.pin-dots {
  display: flex;
  gap: 14px;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  transition: background 120ms ease, transform 120ms ease;
}

.pin-dot.filled {
  background: var(--accent);
  transform: scale(1.05);
}

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
  max-width: 280px;
}

.key {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 22px;
  font-weight: 500;
  padding: 18px 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.key:active {
  background: var(--surface-2);
}

.key.ghost {
  background: transparent;
  border-color: transparent;
}

.pin-subtitle {
  margin: -8px 0 0;
  text-align: center;
  min-height: 20px;
}

.pin-error {
  color: var(--danger);
  font-size: 14px;
  margin: 0;
  min-height: 20px;
  text-align: center;
}

.pin-wrap.shake {
  animation: df-shake 360ms ease;
}

@keyframes df-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-8px); }
  40%, 80% { transform: translateX(8px); }
}

/* Home — hero + progress + bills */
.hero-card {
  background: radial-gradient(
      140% 100% at 0% 0%,
      rgba(22, 163, 74, 0.10) 0%,
      transparent 60%
    ),
    linear-gradient(160deg, #fbf9f3 0%, #f4f8f0 100%);
  border-color: #d4e5d8;
  padding: 20px;
}

.hero-card.empty {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.hero-eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.hero-date {
  margin: 0;
  font-size: 30px;
  line-height: 1.1;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.01em;
}

.hero-countdown {
  margin: 10px 0 0;
  color: var(--text);
  font-size: 14px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}

.card-head .muted,
.card-head p {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pct {
  font-weight: 700;
  color: var(--accent);
  font-size: 14px;
}

.progress-row {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text);
  margin-top: 8px;
}

.bill-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bill-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.bill-row.past {
  opacity: 0.5;
}

.bill-name {
  margin: 0;
  font-weight: 500;
  font-size: 14px;
}

.bill-day {
  margin: 2px 0 0;
  font-size: 12px;
}

.bill-amount {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}

.link {
  color: var(--accent-2);
  text-decoration: none;
}
.link:hover { text-decoration: underline; }

/* Coach card on Home */
.coach-card {
  background: radial-gradient(120% 100% at 100% 0%, rgba(8,145,178,0.08) 0%, transparent 60%),
              var(--surface);
  border-color: #d4e5e8;
}
.coach-card .card-head .icon-btn {
  width: 32px; height: 32px; font-size: 18px;
}
.coach-snapshot {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}
.coach-title {
  margin: 0 0 6px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
}
.coach-detail {
  margin: 0 0 8px;
  font-size: 14px;
  line-height: 1.5;
}
.coach-impact {
  margin: 0 0 10px;
  padding: 8px 12px;
  background: rgba(22, 163, 74, 0.10);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}
.coach-more {
  margin: 8px 0 0;
  font-size: 13px;
}
.coach-more summary {
  cursor: pointer;
  color: var(--accent-2);
  font-weight: 500;
  padding: 4px 0;
}
.coach-secondary {
  list-style: none;
  padding: 8px 0 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.coach-secondary li {
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13px;
  line-height: 1.4;
}
.coach-enc {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

/* Page header with action */
.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.title-row .h-title { margin: 0; }

.icon-btn {
  appearance: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn.ghost { border-color: transparent; background: transparent; }

/* Debts summary hero (reused styling cues from Home hero) */
.debts-summary {
  text-align: center;
  background: radial-gradient(120% 100% at 50% 0%, rgba(22,163,74,0.08) 0%, transparent 70%),
              var(--surface);
}
.debts-summary .hero-date { font-size: 26px; margin: 6px 0; }
.debts-summary .hero-eyebrow { text-align: center; }

/* Segmented control */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  gap: 4px;
}
.seg {
  appearance: none;
  background: transparent;
  border: 0;
  color: var(--muted);
  font: 600 14px inherit;
  padding: 10px 0;
  border-radius: 8px;
  cursor: pointer;
}
.seg.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(42, 37, 32, 0.1), 0 0 0 1px var(--border);
}
.seg-hint { margin: 8px 0 0; font-size: 12px; }

/* Inputs */
.row { display: flex; gap: 8px; align-items: stretch; }

.input {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px;
  font: inherit;
  min-width: 0;
}
.input:focus { outline: none; border-color: var(--accent); }

.row .btn { width: auto; flex: 0 0 auto; padding: 12px 16px; }

/* Debt cards */
.debt-card.paid { border-color: rgba(22,163,74,0.5); }
.debt-card.paid .debt-balance { color: var(--accent); }

.debt-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}
.debt-name { margin: 0; font-size: 16px; font-weight: 600; }
.debt-apr { font-size: 12px; color: var(--warn); }

.debt-amounts {
  display: flex;
  gap: 6px;
  align-items: baseline;
  margin-bottom: 10px;
}
.debt-balance { font-size: 22px; font-weight: 700; }

.debt-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 12px;
}
.debt-meta .warn { color: var(--warn); }

.paid-badge {
  margin: 10px 0 0;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
}

.debt-actions {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.debt-actions .btn { padding: 10px; }
.debt-actions .btn[disabled] { opacity: 0.4; pointer-events: none; }

/* Balance update sheet */
.balance-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 12px;
}
.balance-label {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.balance-input {
  flex: 0 0 130px;
  text-align: right;
}

/* Bottom sheet / modal */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.55);
  animation: df-fade 200ms ease;
}
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 375px;
  background: var(--surface);
  border-top-left-radius: 18px;
  border-top-right-radius: 18px;
  padding: 16px 16px calc(20px + var(--safe-bottom));
  animation: df-slide 240ms cubic-bezier(.2,.8,.2,1);
  max-height: 85dvh;
  overflow-y: auto;
}
@keyframes df-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes df-slide {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.sheet-title { margin: 0; font-size: 18px; font-weight: 700; }

/* Form */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}
.form-actions .btn { flex: 1; }
.btn.danger {
  color: var(--danger);
  border-color: rgba(220,38,38,0.4);
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  min-height: 16px;
}

/* Bills — linked accounts */
.bank-list {
  list-style: none;
  padding: 0;
  margin: 0 0 4px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.bank-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.bank-name { font-weight: 500; }
.bank-row .btn {
  width: auto;
  padding: 8px 12px;
  font-size: 13px;
}

.bills-status {
  margin: 12px 0 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 16px;
}
.bills-status.error { color: var(--danger); }

/* Transaction review list */
.tx-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.tx-date-group {
  list-style: none;
}
.tx-date-label {
  margin: 0 0 6px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}
.tx-day-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tx-row {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.tx-line {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.tx-info {
  flex: 1;
  min-width: 0;
}
.tx-desc {
  margin: 0;
  font-weight: 500;
  font-size: 14px;
  overflow-wrap: anywhere;
  line-height: 1.3;
}
.tx-meta {
  margin: 2px 0 0;
  font-size: 12px;
}
.tx-match {
  display: inline-block;
  margin-top: 4px;
  padding: 2px 8px;
  background: rgba(8, 145, 178, 0.10);
  color: var(--accent-2);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.tx-actions {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 6px;
}
.tx-btn {
  padding: 8px 6px;
  font-size: 12px;
  width: auto;
}

/* (legacy) Recurring candidates */
.candidate-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.candidate {
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.cand-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
.cand-name {
  margin: 0;
  font-weight: 600;
  font-size: 14px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cand-conf {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
}
.cand-meta { margin: 4px 0 0; font-size: 12px; }
.cand-reason {
  margin: 6px 0 0;
  font-size: 12px;
  opacity: 0.7;
  line-height: 1.4;
}
.candidate .row .btn { padding: 8px 12px; font-size: 13px; }

/* Calendar */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal-hd {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 6px 0;
  font-weight: 600;
}
.cal-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text);
  border-radius: 50%;
}
.cal-cell.empty { visibility: hidden; }
.cal-cell.has-bill {
  background: rgba(22, 163, 74, 0.15);
  color: var(--accent);
  font-weight: 700;
}
.cal-cell.has-bill.past { opacity: 0.45; }
.cal-cell.today {
  outline: 1px solid var(--accent-2);
  outline-offset: -1px;
}

/* clickable bill rows in Bills list */
.bill-row.clickable {
  cursor: pointer;
}
.bill-row.clickable:active {
  background: var(--surface);
}

/* Spending Guard */
.guard-cta {
  text-align: center;
  background: radial-gradient(120% 100% at 50% 0%, rgba(8,145,178,0.08) 0%, transparent 70%),
              var(--surface);
}
.guard-cta .muted { margin: 0 0 12px; }
.guard-cta .btn { width: 100%; }

.pct.over { color: var(--danger); }
.progress.over > span {
  background: linear-gradient(90deg, var(--warn), var(--danger));
}

/* Rules list */
.rule-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rule-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.rule-row.off .rule-text {
  opacity: 0.45;
  text-decoration: line-through;
}
.rule-text {
  flex: 1;
  font-size: 14px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.rule-toggle {
  display: inline-flex;
  align-items: center;
}
.rule-toggle input {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  cursor: pointer;
}
.rule-row .icon-btn {
  width: 32px;
  height: 32px;
  font-size: 18px;
  flex: 0 0 auto;
}

/* Reality-check response */
.reality-response { margin-top: 4px; }
.verdict {
  margin: 0 0 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.verdict.buy { color: var(--accent); border: 1px solid rgba(22,163,74,0.35); }
.verdict.skip { color: var(--warn); border: 1px solid rgba(217,119,6,0.35); }

.reality-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
}

/* Alert settings grid */
.alert-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.alert-grid label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}
