/* ─── Base ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f172a; --surface: #1e293b; --border: #334155;
  --text: #f1f5f9; --muted: #94a3b8; --accent: #38bdf8;
  --green: #4ade80; --yellow: #fbbf24; --red: #f87171;
  --radius: 12px;
}

html { font-size: 15px; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
       background: var(--bg); color: var(--text); min-height: 100dvh; }

.hidden { display: none !important; }
.text-muted { color: var(--muted); font-size: .85rem; }
.text-green { color: var(--green); }
.text-yellow { color: var(--yellow); }
.text-red { color: var(--red); }
.error-text { color: var(--red); font-size: .85rem; margin-top: 6px; min-height: 1.2em; }

/* ─── Auth Screen ─────────────────────────────────────────────────────── */
.auth-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100dvh; padding: 24px;
}
.auth-screen h1 { font-size: 1.6rem; margin-bottom: 4px; }
.auth-screen .subtitle { color: var(--muted); margin-bottom: 16px; font-size: .9rem; }
.auth-screen input {
  display: block; width: 280px; padding: 12px 14px; margin-bottom: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); font-size: 1rem; outline: none;
}
.auth-screen input:focus { border-color: var(--accent); }
.auth-screen .btn-primary { width: 280px; }
.switch-link { margin-top: 14px; font-size: .85rem; color: var(--muted); }
.switch-link a { color: var(--accent); text-decoration: none; }

/* ─── Buttons ─────────────────────────────────────────────────────────── */
.btn-primary {
  display: block; width: 100%; padding: 12px; border: none; border-radius: var(--radius);
  background: var(--accent); color: #0f172a; font-weight: 600; font-size: 1rem;
  cursor: pointer; transition: opacity .15s;
}
.btn-primary:disabled { opacity: .5; cursor: default; }
.btn-danger {
  display: block; padding: 12px; border: 1px solid var(--red); border-radius: var(--radius);
  background: transparent; color: var(--red); font-weight: 600; font-size: 1rem; cursor: pointer;
}

/* ─── Layout ──────────────────────────────────────────────────────────── */
#app {
  display: flex; flex-direction: column; min-height: 100dvh;
  max-width: 480px; margin: 0 auto; padding-bottom: 72px;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.1rem; }
.member-chip {
  background: var(--accent); color: #0f172a; padding: 4px 12px;
  border-radius: 20px; font-size: .8rem; font-weight: 600; cursor: default;
}

/* ─── Views ───────────────────────────────────────────────────────────── */
.view { display: none; padding: 16px; }
.view.active { display: block; }

/* ─── Nav ─────────────────────────────────────────────────────────────── */
nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; justify-content: space-around; align-items: center;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 0 env(safe-area-inset-bottom, 6px); z-index: 50;
  max-width: 480px; margin: 0 auto;
}
nav button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: none; border: none; color: var(--muted); font-size: .65rem;
  cursor: pointer; padding: 4px 6px; transition: color .15s;
}
nav button.active, nav button:hover { color: var(--accent); }
nav button svg { width: 20px; height: 20px; }

/* ─── Cards ───────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius); padding: 16px;
  margin-bottom: 14px; border: 1px solid var(--border);
}
.card h3 { font-size: .95rem; margin-bottom: 12px; color: var(--accent); }

/* ─── Stats Grid ──────────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat-box {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; text-align: center;
}
.stat-box .label { font-size: .7rem; text-transform: uppercase; color: var(--muted); margin-bottom: 4px; }
.stat-box .value { font-size: 1.1rem; font-weight: 700; }

/* ─── Budget Bars ─────────────────────────────────────────────────────── */
.budget-row { margin-bottom: 10px; }
.budget-label { display: flex; justify-content: space-between; font-size: .82rem; margin-bottom: 4px; }
.budget-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.budget-fill { height: 100%; border-radius: 3px; transition: width .4s; }
.budget-fill.ok { background: var(--green); }
.budget-fill.warning { background: var(--yellow); }
.budget-fill.over { background: var(--red); }

/* ─── Expense Items ───────────────────────────────────────────────────── */
.expense-item {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 10px 0; border-bottom: 1px solid var(--border); gap: 8px;
}
.expense-left { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.expense-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.expense-cat { font-weight: 600; font-size: .9rem; }
.expense-meta { font-size: .75rem; color: var(--muted); }
.expense-amount { font-weight: 700; white-space: nowrap; }
.expense-actions { display: flex; gap: 6px; }
.btn-xs {
  padding: 2px 10px; border-radius: 5px; font-size: .68rem; font-weight: 600;
  background: var(--accent); color: #0f172a; border: none; cursor: pointer;
}
.btn-danger-xs { background: var(--red); color: #fff; }

/* ─── Modal ──────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex;
  align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.modal-box {
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  width: 100%; max-width: 360px; border: 1px solid var(--border);
}
.modal-box h3 { margin-bottom: 12px; }
.modal-actions { display: flex; gap: 10px; margin-top: 14px; justify-content: flex-end; }

/* ─── Forms ───────────────────────────────────────────────────────────── */
label { display: block; font-size: .82rem; color: var(--muted); margin-bottom: 10px; }
label input, label select {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: .95rem; outline: none;
}
label input:focus, label select:focus { border-color: var(--accent); }
select { appearance: none; }

/* ─── Filter Row ──────────────────────────────────────────────────────── */
.filter-row { display: flex; gap: 8px; margin-bottom: 12px; }
.filter-row input, .filter-row select {
  flex: 1; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .85rem;
}

/* ─── Financial Freedom ───────────────────────────────────────────────── */
.fi-tabs { display: flex; gap: 0; margin-bottom: 16px; border-radius: 8px; overflow: hidden; border: 1px solid var(--border); }
.fi-tab {
  flex: 1; padding: 8px; border: none; background: var(--bg); color: var(--muted);
  font-size: .85rem; font-weight: 600; cursor: pointer; transition: all .15s;
}
.fi-tab.active { background: var(--accent); color: #0f172a; }
.fi-panel { display: none; }
.fi-panel.active { display: block; }
.fi-pct { text-align: center; font-size: 2.4rem; font-weight: 800; margin-bottom: 16px; }
.fi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fi-cell { background: var(--bg); border-radius: 8px; padding: 10px; }
.fi-cell .k { font-size: .72rem; color: var(--muted); text-transform: uppercase; }
.fi-cell .v { font-size: .95rem; font-weight: 600; margin-top: 2px; }

/* ─── Budget Editor (Settings) ────────────────────────────────────────── */
.budget-edit-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.budget-edit-cat { font-size: .9rem; flex: 1; }
.budget-edit-input {
  width: 140px; padding: 8px 10px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .9rem; text-align: right; outline: none;
}
.budget-edit-input:focus { border-color: var(--accent); }

/* ─── Assets ─────────────────────────────────────────────────────────── */
.asset-summary {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 16px;
  padding: 12px; background: var(--bg); border-radius: 10px;
}
.asset-sum-item { display: flex; flex-direction: column; gap: 2px; }
.asset-sum-item .k { font-size: .7rem; color: var(--muted); text-transform: uppercase; }
.asset-sum-item .v { font-size: .85rem; font-weight: 600; }

.asset-cards { display: flex; flex-direction: column; gap: 10px; }
.asset-card {
  background: var(--bg); border-radius: 10px; padding: 12px; border: 1px solid var(--border);
}
.asset-card-head {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px;
}
.asset-name { font-weight: 600; font-size: .95rem; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .65rem;
  font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.badge-fixed { background: rgba(249,115,22,.2); color: #f97316; }
.badge-liquid { background: rgba(56,189,248,.2); color: #38bdf8; }
.asset-card-body { display: flex; flex-direction: column; gap: 4px; }
.asset-row {
  display: flex; justify-content: space-between; align-items: center; font-size: .82rem;
}
.asset-row .k { color: var(--muted); }
.asset-row .v { font-weight: 500; }
.asset-card-actions { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }
.btn-sm {
  padding: 4px 14px; border-radius: 6px; font-size: .75rem; font-weight: 600;
  background: var(--accent); color: #0f172a; border: none; cursor: pointer;
}
.btn-danger-sm { background: var(--red); color: #fff; }
.btn-outline {
  display: inline-block; padding: 8px 16px; background: transparent; border: 1px dashed var(--border);
  border-radius: 8px; color: var(--accent); cursor: pointer; font-size: .85rem; font-weight: 600;
}
.asset-add-form {
  display: flex; flex-direction: column; gap: 8px; margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--border);
}
.asset-add-form input, .asset-add-form select {
  padding: 10px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .9rem; outline: none;
}
.asset-add-form input:focus, .asset-add-form select:focus { border-color: var(--accent); }

/* ─── Toast ───────────────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
  background: var(--green); color: #0f172a; padding: 10px 20px; border-radius: 20px;
  font-size: .85rem; font-weight: 600; opacity: 0; transition: opacity .3s; pointer-events: none;
  z-index: 100; max-width: 90%;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); color: #fff; }

/* ─── Responsive ──────────────────────────────────────────────────────── */
@media (min-width: 480px) {
  nav { left: 50%; transform: translateX(-50%); width: 480px; }
}
