/* ===== Money Hub — styles ===== */
:root {
  --bg: #0b0f17;
  --bg-2: #111726;
  --panel: #151c2c;
  --panel-2: #1b2335;
  --line: #26304a;
  --line-soft: #1e2740;
  --text: #e8edf7;
  --text-dim: #9aa7c2;
  --text-faint: #6b7794;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --green: #2fd07a;
  --green-soft: #163a2b;
  --red: #ff6b6b;
  --red-soft: #3a1b22;
  --amber: #ffc14d;
  --amber-soft: #3a2f16;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --c1:#5b8cff; --c2:#2fd07a; --c3:#7c5cff; --c4:#ffc14d; --c5:#ff7eb6; --c6:#41d6c3; --c7:#ff6b6b; --c8:#9aa7c2;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #16203a 0%, var(--bg) 55%) fixed;
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 1180px; margin: 0 auto; padding: 0 20px 60px; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 4px 16px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 12px; color: #fff;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 6px 18px rgba(91,140,255,.35);
}
.brand-name { font-weight: 700; font-size: 18px; letter-spacing: .2px; }
.brand-sub { color: var(--text-faint); font-size: 12px; }
.topbar-stat { text-align: right; display: flex; flex-direction: column; }
.topbar-stat-label { color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.topbar-stat-value { font-size: 22px; font-weight: 700; }
.topbar-stat-base { color: var(--text-faint); font-size: 11px; }

/* Tabs */
.tabs {
  display: flex; gap: 6px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--line-soft);
  padding: 6px; border-radius: 14px; position: sticky; top: 10px; z-index: 20;
  box-shadow: var(--shadow);
}
.tab {
  appearance: none; border: 0; cursor: pointer; color: var(--text-dim);
  background: transparent; padding: 9px 16px; border-radius: 10px;
  font-size: 14px; font-weight: 600; transition: .15s;
}
.tab:hover { color: var(--text); background: var(--panel-2); }
.tab.active { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

/* Views */
main { margin-top: 18px; }
.view { display: none; }
.view.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Layout helpers */
.grid { display: grid; gap: 16px; }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-2-1 { grid-template-columns: 2fr 1fr; }
.span-2 { grid-column: span 2; }
@media (max-width: 860px) {
  .cols-3, .cols-2, .cols-2-1 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .topbar-stat-value { font-size: 18px; }
}

/* Cards */
.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--bg-2) 100%);
  border: 1px solid var(--line-soft); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 10px; }
.card-title { font-size: 14px; font-weight: 700; color: var(--text); }
.card-sub { color: var(--text-faint); font-size: 12px; }

.section-head {
  display: flex; align-items: center; justify-content: space-between; margin: 4px 2px 14px; gap: 12px;
}
.section-head h2 { margin: 0; font-size: 20px; }
.section-head p { margin: 2px 0 0; color: var(--text-faint); font-size: 13px; }

/* Stat tiles */
.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-label { color: var(--text-faint); font-size: 12px; text-transform: uppercase; letter-spacing: .07em; }
.stat-value { font-size: 30px; font-weight: 750; letter-spacing: -.5px; }
.stat-foot { font-size: 12px; color: var(--text-dim); }
.stat.good .stat-value { color: var(--green); }
.stat.bad .stat-value { color: var(--red); }
.accent-bar { height: 3px; border-radius: 3px; margin-bottom: 14px; background: linear-gradient(90deg,var(--accent),var(--accent-2)); }
.accent-bar.green { background: linear-gradient(90deg,var(--green),#8ef0bf); }
.accent-bar.red { background: linear-gradient(90deg,var(--red),#ffb3b3); }

/* Buttons */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 600;
  border-radius: 10px; padding: 9px 15px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); transition: .15s; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: #fff; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: 0; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); border-color: var(--red-soft); }
.btn.danger:hover { background: var(--red-soft); border-color: var(--red); color: #fff; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* Badges / pills */
.badge {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: 999px; background: var(--panel-2); color: var(--text-dim);
  border: 1px solid var(--line-soft);
}
.badge.cad { color: #ff9b9b; }
.badge.usd { color: #8ef0bf; }
.badge.green { background: var(--green-soft); color: #7ef0b4; border-color: transparent; }
.badge.red { background: var(--red-soft); color: #ffb0b0; border-color: transparent; }
.badge.amber { background: var(--amber-soft); color: var(--amber); border-color: transparent; }
.dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; }

/* Tables */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); padding: 8px 10px; border-bottom: 1px solid var(--line-soft);
}
.table td { padding: 11px 10px; border-bottom: 1px solid var(--line-soft); font-size: 14px; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: rgba(255,255,255,.02); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.t-pos { color: var(--green); }
.t-neg { color: var(--red); }
.t-muted { color: var(--text-faint); }
.cell-main { font-weight: 600; }
.cell-sub { color: var(--text-faint); font-size: 12px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  appearance: none; border: 1px solid var(--line-soft); background: var(--panel-2);
  color: var(--text-dim); width: 30px; height: 30px; border-radius: 8px; cursor: pointer; transition: .15s;
}
.icon-btn:hover { color: #fff; border-color: var(--accent); }
.icon-btn.danger:hover { color: #fff; border-color: var(--red); background: var(--red-soft); }

/* Progress / bars */
.bar { height: 9px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg,var(--accent),var(--accent-2)); }
.bar.green > span { background: linear-gradient(90deg,var(--green),#8ef0bf); }
.bar.amber > span { background: linear-gradient(90deg,var(--amber),#ffe2a1); }
.bar.red > span { background: linear-gradient(90deg,var(--red),#ffb3b3); }

.breakdown-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 12px; align-items: center; margin-bottom: 12px; }
.breakdown-row:last-child { margin-bottom: 0; }
.breakdown-label { font-size: 13px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }
.breakdown-val { font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }

/* Donut */
.donut-wrap { display: flex; align-items: center; gap: 18px; }
.donut { width: 150px; height: 150px; flex: none; }
.donut-center { font-weight: 750; font-size: 16px; }
.legend { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-item .legend-val { margin-left: auto; color: var(--text-dim); font-variant-numeric: tabular-nums; }

/* Account / card tiles */
.acct-tile {
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: 12px; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.acct-tile .acct-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.acct-name { font-weight: 700; }
.acct-inst { color: var(--text-faint); font-size: 12px; }
.acct-bal { font-size: 20px; font-weight: 750; }
.acct-bal.debt { color: var(--red); }

.cc-card {
  border-radius: 16px; padding: 18px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(135deg, #243049, #161d2e);
  border: 1px solid var(--line); min-height: 150px; display: flex; flex-direction: column; gap: 14px;
}
.cc-card.g1 { background: linear-gradient(135deg,#3a2b6b,#1c1f3a); }
.cc-card.g2 { background: linear-gradient(135deg,#0f5b52,#10283a); }
.cc-card.g3 { background: linear-gradient(135deg,#5b3a2b,#2a1b2e); }
.cc-card.g4 { background: linear-gradient(135deg,#2b3a5b,#161d2e); }
.cc-top { display: flex; justify-content: space-between; align-items: flex-start; }
.cc-name { font-weight: 700; font-size: 15px; }
.cc-inst { font-size: 12px; opacity: .7; }
.cc-owed { font-size: 24px; font-weight: 750; }
.cc-owed-label { font-size: 11px; opacity: .7; text-transform: uppercase; letter-spacing: .06em; }
.cc-meta { display: flex; justify-content: space-between; font-size: 12px; opacity: .9; }
.cc-util { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; opacity: .85; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; font-weight: 600; }
.field .hint { color: var(--text-faint); font-size: 11px; margin-top: 5px; font-weight: 400; }
input, select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 10px 12px; font: inherit; outline: none; transition: .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.15); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 560px){ .field-row, .field-row-3 { grid-template-columns: 1fr; } }
.seg { display: flex; gap: 6px; background: var(--bg-2); padding: 4px; border-radius: 10px; border: 1px solid var(--line); }
.seg button { flex: 1; appearance: none; border: 0; background: transparent; color: var(--text-dim); padding: 8px; border-radius: 7px; cursor: pointer; font: inherit; font-weight: 600; }
.seg button.on { background: var(--panel-2); color: #fff; }
.seg button.on.in { color: var(--green); }
.seg button.on.out { color: var(--red); }

/* Modal */
#modal-root { position: fixed; inset: 0; display: none; align-items: flex-start; justify-content: center; z-index: 100; }
#modal-root.open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(5,8,14,.65); backdrop-filter: blur(3px); }
.modal {
  position: relative; margin: 6vh 16px; width: 520px; max-width: 100%; max-height: 86vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow);
  animation: pop .18s ease;
}
.modal.wide { width: 720px; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line-soft); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line-soft); position: sticky; bottom: 0; background: var(--panel); }
.x-btn { appearance: none; background: transparent; border: 0; color: var(--text-faint); font-size: 22px; cursor: pointer; line-height: 1; }
.x-btn:hover { color: #fff; }

/* Toast */
#toast-root { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text); padding: 11px 16px;
  border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; animation: pop .18s ease;
}
.toast.good { border-color: var(--green); }
.toast.bad { border-color: var(--red); }

/* Empty states */
.empty { text-align: center; padding: 40px 20px; color: var(--text-faint); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.empty h3 { color: var(--text-dim); margin: 0 0 6px; }

/* Banner */
.banner {
  display: flex; gap: 12px; align-items: center; justify-content: space-between;
  background: linear-gradient(135deg, rgba(124,92,255,.18), rgba(91,140,255,.12));
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; font-size: 13px;
}
.banner .banner-text { color: var(--text-dim); }
.banner strong { color: var(--text); }

/* Filters */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input, .filters select { width: auto; min-width: 140px; }
.filters .grow { flex: 1; min-width: 180px; }

.spacer { flex: 1; }
.muted { color: var(--text-faint); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mini-list { display: flex; flex-direction: column; gap: 10px; }
.mini-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.mini-row:last-child { border-bottom: 0; }
.kbd { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; background: var(--bg-2); border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px; font-size: 12px; }

.footer { display: flex; justify-content: space-between; color: var(--text-faint); font-size: 12px; margin-top: 30px; padding: 14px 4px 0; border-top: 1px solid var(--line-soft); }

/* Chart */
.chart-svg { width: 100%; height: auto; display: block; }
.chart-empty { height: 200px; display: grid; place-items: center; color: var(--text-faint); }

/* ===== Phone / small-screen tuning ===== */
@media (max-width: 680px) {
  #app {
    padding: 0 12px calc(40px + env(safe-area-inset-bottom));
    padding-left: calc(12px + env(safe-area-inset-left));
    padding-right: calc(12px + env(safe-area-inset-right));
  }
  .topbar { padding: 14px 2px 12px; }
  .brand-mark { width: 38px; height: 38px; }
  .brand-name { font-size: 16px; }
  .topbar-stat-value { font-size: 17px; }

  /* Tabs become a swipeable strip instead of wrapping */
  .tabs {
    flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; top: 6px;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 9px 13px; flex: 0 0 auto; }

  /* Section headers stack their action buttons below the title */
  .section-head { flex-direction: column; align-items: stretch; }
  .section-head .btn-row { justify-content: flex-start; }
  .section-head h2 { font-size: 18px; }

  /* Let wide tables scroll sideways inside their card */
  .card { overflow-x: auto; }
  .table th, .table td { padding: 9px 8px; font-size: 13px; }
  .table { min-width: 460px; }

  .stat-value { font-size: 26px; }
  .seg { max-width: 100% !important; }
  .seg button { padding: 9px 6px; font-size: 13px; }

  /* Bigger touch targets */
  .btn { padding: 11px 15px; }
  .icon-btn { width: 34px; height: 34px; }

  .footer { flex-direction: column; gap: 4px; }
  .modal, .modal.wide { margin: 0; border-radius: 16px 16px 0 0; max-height: 92vh; width: 100%; }
  #modal-root.open { align-items: flex-end; }
}
