/* DebtFree — iOS-inspired local web app styles */
:root {
  --bg: #f2f2f7;
  --bg-sunk: #e9e9ef;
  --card: #ffffff;
  --text: #101014;
  --muted: #6b7280;
  --faint: #9ca3af;
  --accent: #4f46e5;
  --accent-soft: rgba(79, 70, 229, 0.12);
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --border: rgba(0, 0, 0, 0.07);
  --shadow: 0 1px 2px rgba(16, 16, 20, 0.05), 0 6px 20px rgba(16, 16, 20, 0.05);
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-sunk: #1c1c1e;
    --card: #1c1c1e;
    --text: #f4f4f6;
    --muted: #98989f;
    --faint: #6a6a70;
    --accent: #7c7cf0;
    --accent-soft: rgba(124, 124, 240, 0.16);
    --border: rgba(255, 255, 255, 0.09);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-sunk);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
a { color: var(--accent); text-decoration: none; }

#phone {
  max-width: 430px;
  width: 100%;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-x: hidden;
}
@media (min-width: 500px) {
  #phone { box-shadow: 0 0 0 1px var(--border), 0 24px 80px rgba(0,0,0,.25); }
}

/* ---------- App bar ---------- */
.appbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: max(14px, env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid transparent;
}
.appbar.scrolled { border-bottom-color: var(--border); }
.appbar .title { font-size: 17px; font-weight: 700; flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .side { min-width: 64px; display: flex; gap: 14px; align-items: center; }
.appbar .side.right { justify-content: flex-end; }
.backlink { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); font-weight: 600; font-size: 15px; }
.iconbtn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 50%;
  color: var(--accent); background: transparent; border: none; cursor: pointer;
}
.iconbtn:active { background: var(--accent-soft); }

/* ---------- Screen ---------- */
#screen { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 8px 16px 96px; scroll-behavior: smooth; -webkit-overflow-scrolling: touch; }
#screen.no-pad { padding-top: 0; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 430px; z-index: 40;
  display: flex;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 6px 8px calc(10px + env(safe-area-inset-bottom));
}
.tabbar.hidden { display: none; }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--faint); font-size: 10px; font-weight: 600; padding: 4px 0; border-radius: 10px;
}
.tab.active { color: var(--accent); }

/* ---------- Cards & sections ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; margin-bottom: 12px; box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card.tinted { border: none; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 4px 8px; }
.row { display: flex; align-items: center; gap: 12px; }
.row .grow { flex: 1; min-width: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.divider { height: 1px; background: var(--border); margin: 10px 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.right { text-align: right; }
.bold { font-weight: 700; }
.mono { font-variant-numeric: tabular-nums; }
.big-num { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.pos { color: var(--success); }
.neg { color: var(--danger); }
.warn { color: var(--warning); }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Stat card ---------- */
.stat { background: var(--card); border-radius: 14px; padding: 12px; box-shadow: var(--shadow); border: 1px solid var(--border); overflow: hidden; min-width: 0; }
.grid2 > *, .grid3 > * { min-width: 0; }
.stat .value { overflow-wrap: anywhere; }
.stat .icon { width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.stat .label { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.stat .value { font-size: 17px; font-weight: 800; margin-top: 2px; }
.stat .sub { font-size: 11px; color: var(--faint); margin-top: 2px; }

/* ---------- Hero ---------- */
.hero { background: linear-gradient(135deg, var(--accent), #7c3aed); color: #fff; border: none; }
.hero .big-num { font-size: 34px; }
.hero .muted, .hero .faint { color: rgba(255,255,255,.75); }
.progress-track { height: 10px; border-radius: 6px; background: rgba(255,255,255,.25); overflow: hidden; }
.progress-fill { height: 100%; border-radius: 6px; background: #fff; transition: width .5s ease; }

/* ---------- Pills & badges ---------- */
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 13px; border: none; cursor: pointer;
  font-size: 15px; font-weight: 700; font-family: inherit;
  background: var(--bg-sunk); color: var(--text); width: 100%;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { padding: 8px 14px; font-size: 13px; width: auto; }
.btn:active { transform: scale(.98); }
.btnrow { display: flex; gap: 10px; }
.btnrow .btn { flex: 1; }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--bg-sunk); color: var(--text); font-size: 15px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.field .hint { font-size: 11px; color: var(--faint); margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px; border-radius: 12px; border: 1.5px solid transparent;
  background: var(--bg-sunk); color: var(--muted); font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.chip.selected { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.colorchip { width: 34px; height: 34px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.colorchip.selected { border-color: var(--text); }
.radio-card { display: flex; gap: 12px; padding: 14px; border-radius: 14px; border: 1.5px solid var(--border); cursor: pointer; background: var(--card); }
.radio-card.selected { border-color: var(--accent); background: var(--accent-soft); }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ---------- Lists ---------- */
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: none; }
.list-item a.row { color: inherit; flex: 1; min-width: 0; }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; }
.avatar svg { width: 18px; height: 18px; }
.chevron { color: var(--faint); flex-shrink: 0; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 40px 24px; }
.empty .icon { width: 72px; height: 72px; border-radius: 24px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; }
.empty h3 { font-size: 18px; margin-bottom: 6px; }
.empty p { font-size: 13px; color: var(--muted); line-height: 1.5; max-width: 280px; margin: 0 auto 18px; }

/* ---------- Charts ---------- */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: inherit; }

/* ---------- Mood ---------- */
.mood-picker { display: flex; gap: 8px; }
.mood-opt { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 9px 2px; border-radius: 12px; background: var(--bg-sunk); color: var(--muted); font-size: 10px; font-weight: 600; cursor: pointer; border: 1.5px solid transparent; }
.mood-opt .emoji { font-size: 19px; }
.mood-opt.selected { border-color: currentColor; }

/* ---------- Milestones ---------- */
.milestone { display: flex; gap: 12px; align-items: center; opacity: .55; }
.milestone.achieved { opacity: 1; }
.milestone .medal { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--bg-sunk); color: var(--faint); }
.milestone.achieved .medal { background: linear-gradient(135deg, #f59e0b, #f97316); color: #fff; }

/* ---------- Onboarding ---------- */
.onboarding { min-height: 100dvh; display: flex; flex-direction: column; padding: 24px; }
.onboarding .art { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; }
.onboarding .logo { width: 96px; height: 96px; border-radius: 28px; background: linear-gradient(135deg, var(--accent), #7c3aed); display: flex; align-items: center; justify-content: center; color: #fff; box-shadow: var(--shadow); }
.dots { display: flex; gap: 8px; justify-content: center; padding: 18px 0; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.dots span.active { background: var(--accent); width: 22px; border-radius: 5px; }
.feature-line { display: flex; gap: 12px; align-items: flex-start; text-align: left; }
.feature-line .fi { width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

/* ---------- Table ---------- */
.tablewrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.tablewrap table.data { min-width: 430px; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--border); }
table.data td { padding: 9px 6px; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: none; }
table.data td.num, table.data th.num { text-align: right; }

/* ---------- Search ---------- */
.searchbar { width: 100%; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg-sunk); color: var(--text); font-size: 14px; margin-bottom: 12px; font-family: inherit; }

/* ---------- Notice ---------- */
.notice { display: flex; gap: 8px; font-size: 12px; color: var(--muted); background: var(--bg-sunk); border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; line-height: 1.45; }

/* ---------- Toast / modal ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 90; display: flex; align-items: center; justify-content: center; padding: 24px; }
.modal { background: var(--card); border-radius: 18px; padding: 22px; max-width: 320px; width: 100%; text-align: center; box-shadow: var(--shadow); }
.modal h3 { margin-bottom: 8px; }
.modal p { font-size: 13px; color: var(--muted); margin-bottom: 18px; line-height: 1.5; }
.modal .btnrow { flex-direction: column; gap: 8px; }
.toast {
  position: fixed; bottom: 110px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; z-index: 99; animation: toastIn .25s ease;
}
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
