:root {
  --bg: #0f172a;
  --bg-elev: #17213a;
  --card: #182238;
  --border: #26324d;
  --text: #e6ebf5;
  --muted: #8a96ad;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #3b82f6;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
.hidden { display: none !important; }
button { font-family: inherit; }
input, textarea { font-family: inherit; }

/* ---------- Lock screen ---------- */
.lock-screen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: var(--bg); padding: 24px; z-index: 50;
}
.lock-card { width: 100%; max-width: 340px; text-align: center; }
.lock-logo {
  width: 64px; height: 64px; margin: 0 auto 16px; border-radius: 18px; background: var(--green);
  color: var(--bg); font-weight: 800; font-size: 28px; display: flex; align-items: center; justify-content: center;
}
.lock-card h1 { font-size: 20px; margin: 0 0 4px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.pin-input {
  width: 100%; text-align: center; font-size: 28px; letter-spacing: 10px; padding: 14px;
  margin: 20px 0 10px; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text);
}
.error { color: var(--red); font-size: 13px; margin-bottom: 10px; }

/* ---------- App shell ---------- */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px; background: var(--bg-elev); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-size: 18px; font-weight: 700; }
.icon-btn { background: none; border: none; color: var(--text); font-size: 18px; padding: 6px; cursor: pointer; }
.views { flex: 1; overflow-y: auto; padding: 14px 14px calc(90px + var(--safe-bottom)); }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; display: flex; background: var(--bg-elev);
  border-top: 1px solid var(--border); padding-bottom: var(--safe-bottom); z-index: 10;
}
.tab {
  flex: 1; background: none; border: none; color: var(--muted); padding: 10px 4px 8px; font-size: 11px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; cursor: pointer;
}
.tab-icon { font-size: 19px; }
.tab.active { color: var(--green); }

/* ---------- Cards / generic ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card-title { font-weight: 700; margin-bottom: 10px; font-size: 14.5px; }
.highlight-card { border-color: var(--green); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.stat-value { font-size: 19px; font-weight: 800; }
.stat-row { display: flex; justify-content: space-between; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 6px; }
.link-row { display: block; color: var(--blue); font-size: 13px; margin-top: 8px; text-decoration: none; }

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: 10px; padding: 11px 16px; font-size: 14.5px; font-weight: 600;
  cursor: pointer; background: var(--border); color: var(--text);
}
.btn-block { width: 100%; }
.btn-primary { background: var(--green); color: #06210f; }
.btn-small { padding: 8px 12px; font-size: 13px; }
.btn-ghost { background: transparent; border: 1px solid var(--border); }
.btn-charge { background: rgba(239,68,68,.15); color: #fca5a5; border: 1px solid rgba(239,68,68,.35); }
.btn-payment { background: rgba(34,197,94,.15); color: #86efac; border: 1px solid rgba(34,197,94,.35); }
.section-actions { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.toggle-line { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* ---------- Accounts list ---------- */
.account-list { display: flex; flex-direction: column; gap: 10px; }
.account-row {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 13px 14px; display: flex; justify-content: space-between; align-items: center; cursor: pointer;
}
.account-row .left { display: flex; flex-direction: column; gap: 3px; }
.account-name { font-weight: 700; font-size: 14.5px; }
.account-meta { font-size: 12px; color: var(--muted); }
.account-row .right { text-align: right; }
.account-balance { font-weight: 800; font-size: 15px; }
.apr-pill {
  display: inline-block; font-size: 11px; padding: 2px 7px; border-radius: 20px; margin-top: 4px;
  background: rgba(59,130,246,.15); color: #93c5fd;
}

/* ---------- Account detail ---------- */
.back-btn { background: none; border: none; color: var(--blue); font-size: 14px; padding: 6px 0 14px; cursor: pointer; }
.detail-header { display: flex; justify-content: space-between; align-items: flex-start; }
.detail-name { font-size: 19px; font-weight: 800; }
.detail-balance { font-size: 34px; font-weight: 800; margin: 10px 0 2px; }
.quick-row { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin: 16px 0 6px; }
.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
.kv-grid > div { font-size: 14px; }
.notes-wrap { margin-top: 14px; font-size: 13.5px; }

/* ---------- Plan ---------- */
.extra-row { display: flex; align-items: center; gap: 8px; }
.extra-row span { color: var(--muted); }
.extra-row input { flex: 1; background: var(--bg-elev); border: 1px solid var(--border); color: var(--text); border-radius: 8px; padding: 9px; font-size: 15px; }
.plan-target { font-size: 17px; font-weight: 700; }
.order-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.order-row:last-child { border-bottom: none; }
.order-rank { color: var(--muted); width: 22px; display: inline-block; }

/* ---------- Bills ---------- */
.month-switch { display: flex; align-items: center; justify-content: center; gap: 18px; margin-bottom: 14px; font-weight: 700; }
.bills-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.bill-row {
  display: flex; justify-content: space-between; align-items: center; background: var(--card);
  border: 1px solid var(--border); border-radius: 12px; padding: 11px 13px;
}
.bill-row.due-soon { border-color: var(--amber); }
.bill-row.paid { opacity: .55; }
.bill-left { display: flex; flex-direction: column; gap: 2px; }
.bill-name { font-weight: 700; font-size: 14px; }
.bill-sub { font-size: 12px; color: var(--muted); }
.due-badge { font-size: 11px; padding: 2px 7px; border-radius: 20px; background: rgba(245,158,11,.18); color: var(--amber); }
.paid-check { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border); background: none; color: var(--green); font-size: 15px; }
.paid-check.checked { background: var(--green); border-color: var(--green); color: #06210f; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: flex-end; z-index: 60;
}
.modal { background: var(--bg-elev); width: 100%; border-radius: 18px 18px 0 0; padding: 18px; max-height: 85vh; overflow-y: auto; padding-bottom: calc(24px + var(--safe-bottom)); }
.modal-header { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 16px; margin-bottom: 14px; }
.modal-body label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 5px; }
.modal-body input, .modal-body select, .modal-body textarea {
  width: 100%; background: var(--card); border: 1px solid var(--border); color: var(--text);
  border-radius: 9px; padding: 10px; font-size: 15px;
}
.modal-body textarea { font-family: monospace; font-size: 12.5px; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; }

textarea#bulkImportText { width: 100%; margin-bottom: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: calc(96px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  background: #111827; border: 1px solid var(--border); color: var(--text); padding: 10px 16px;
  border-radius: 30px; font-size: 13.5px; z-index: 80; box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

@media (min-width: 640px) {
  .views { max-width: 640px; margin: 0 auto; width: 100%; }
  .topbar-title, .tabbar { max-width: 100%; }
}
