/* ============ Gift Card Tracker — styles ============ */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f0f2f7;
  --border: #e3e6ee;
  --text: #151826;
  --muted: #6b7185;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #eef0ff;
  --good: #059669;
  --good-soft: #e7f7f0;
  --danger: #dc2626;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(16,20,40,.04), 0 4px 16px rgba(16,20,40,.06);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f17;
    --surface: #161925;
    --surface-2: #1d2130;
    --border: #272c3d;
    --text: #eceef5;
    --muted: #9298ad;
    --accent: #818cf8;
    --accent-ink: #0d0f17;
    --accent-soft: #23264a;
    --good: #34d399;
    --good-soft: #0f2a22;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
.num, td.num, .stat-value { font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.good { color: var(--good); }
.danger-text { color: var(--danger); }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; gap: 18px;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand-mark {
  display: inline-grid; place-items: center;
  width: 52px; height: 52px; border-radius: 14px;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: #fff;
}
.brand-mark.sm { width: 32px; height: 32px; border-radius: 9px; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 11px; }
.tab {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 8px;
  color: var(--muted); font-weight: 500; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ---------- Buttons & inputs ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface);
  padding: 8px 14px; border-radius: 10px; font-weight: 600; cursor: pointer;
  transition: transform .05s, background .15s, border-color .15s;
  white-space: nowrap; text-decoration: none; color: inherit;
}
.btn:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 88%, #000); border-color: transparent; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: transparent; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-block { width: 100%; padding: 11px; }
.plus { font-size: 18px; line-height: 1; font-weight: 500; }
.icon-btn {
  display: inline-grid; place-items: center; width: 38px; height: 38px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  color: var(--muted); cursor: pointer;
}
.icon-btn:hover { color: var(--text); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea, .input {
  width: 100%; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 70px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field .hint { font-size: 12px; color: var(--muted); }
.input-affix { position: relative; }
.input-affix input { padding-left: 26px; }
.input-affix.suffix input { padding-left: 12px; padding-right: 30px; }
.input-affix .affix { position: absolute; top: 50%; transform: translateY(-50%); left: 11px; color: var(--muted); pointer-events: none; }
.input-affix.suffix .affix { left: auto; right: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
input[type="number"]::-webkit-inner-spin-button, input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="color"] { padding: 3px; height: 42px; cursor: pointer; }

/* ---------- Layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 24px 20px 60px; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; margin: 0; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 6px; }
.panel-head h2 { font-size: 15px; margin: 0; }
.panel-body { padding: 10px 18px 18px; }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { padding: 16px 18px; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.stat-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat.hero { background: linear-gradient(135deg, var(--accent), #9333ea); color: #fff; border: 0; }
.stat.hero .stat-label, .stat.hero .stat-sub { color: rgba(255,255,255,.8); }

.dash-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 18px; }
.dash-grid .full { grid-column: 1 / -1; }

/* Brand bars */
.bar-row { display: grid; grid-template-columns: 130px 1fr auto; align-items: center; gap: 12px; padding: 8px 0; }
.bar-row + .bar-row { border-top: 1px dashed var(--border); }
.bar-name { display: flex; align-items: center; gap: 8px; font-weight: 600; min-width: 0; }
.bar-name span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; min-width: 3px; }
.bar-val { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.bar-val small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 9px 3px 7px; border-radius: 99px; font-size: 13px; font-weight: 600;
  background: var(--surface-2); white-space: nowrap;
}
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--good-soft); color: var(--good); }
.pill.muted-pill { background: var(--surface-2); color: var(--muted); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* ---------- Cards list ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px; border-bottom: 1px solid var(--border); }
.filters .input { width: auto; flex: 1 1 160px; padding: 8px 11px; }
.filters .search { flex: 2 1 220px; }
.balance-cell { min-width: 150px; }
.mini-track { height: 5px; background: var(--surface-2); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.mini-fill { height: 100%; background: var(--good); border-radius: 99px; }
.summary-bar { display: flex; gap: 20px; flex-wrap: wrap; padding: 12px 16px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.summary-bar b { color: var(--text); font-variant-numeric: tabular-nums; }

/* Brand tiles */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.tile { padding: 18px; position: relative; overflow: hidden; }
.tile::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--c, var(--accent)); }
.tile h3 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.tile-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile-stats div small { display: block; color: var(--muted); font-size: 12px; }
.tile-stats div b { font-size: 16px; font-variant-numeric: tabular-nums; }
.tile-actions { display: flex; gap: 6px; margin-top: 14px; }

/* Activity list */
.activity { list-style: none; margin: 0; padding: 0; }
.activity li { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.activity li:last-child { border-bottom: 0; }
.activity .what { flex: 1; min-width: 0; }
.activity .what small { display: block; color: var(--muted); font-size: 12px; }
.activity .amt { font-weight: 600; font-variant-numeric: tabular-nums; }

.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty h3 { color: var(--text); margin: 0 0 6px; }
.empty .btn { margin-top: 14px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(10,12,22,.5);
  display: grid; place-items: center; padding: 16px; animation: fade .15s ease;
}
.modal {
  background: var(--surface); border-radius: 18px; width: 100%; max-width: 520px;
  max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal.wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 4px; }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 14px 22px 8px; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 22px 20px; flex-wrap: wrap; }
.modal-foot .spacer { flex: 1; }
.close-x { border: 0; background: transparent; font-size: 24px; line-height: 1; color: var(--muted); cursor: pointer; padding: 4px 8px; }

.calc-box {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
  background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px;
}
.calc-box small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.calc-box b { font-size: 20px; font-variant-numeric: tabular-nums; }

/* Card detail */
.gc-visual {
  border-radius: 16px; padding: 18px 20px; color: #fff; position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--c), color-mix(in srgb, var(--c) 55%, #000));
  margin-bottom: 16px;
}
.gc-visual::after { content: ""; position: absolute; width: 220px; height: 220px; right: -70px; top: -90px; border-radius: 50%; background: rgba(255,255,255,.12); }
.gc-visual .gc-top { display: flex; justify-content: space-between; font-weight: 600; opacity: .95; }
.gc-visual .gc-bal { font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin-top: 18px; font-variant-numeric: tabular-nums; }
.gc-visual .gc-sub { opacity: .85; font-size: 13px; }
.gc-visual .mini-track { background: rgba(255,255,255,.25); height: 6px; }
.gc-visual .mini-fill { background: #fff; }
.detail-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.detail-grid div small { display: block; color: var(--muted); font-size: 12px; }
.detail-grid div b { font-variant-numeric: tabular-nums; }
.seg { display: inline-flex; background: var(--surface-2); padding: 3px; border-radius: 10px; margin-bottom: 12px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.txn-form { background: var(--surface-2); border-radius: 12px; padding: 14px 14px 2px; margin-bottom: 16px; }
.txn-form .field input { background: var(--surface); }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 6px 0 6px; font-weight: 600; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-weight: 500; box-shadow: 0 8px 30px rgba(0,0,0,.25); max-width: calc(100% - 32px);
}
.toast.error { background: var(--danger); color: #fff; }

/* ---------- Auth page ---------- */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1000px 500px at 20% -10%, var(--accent-soft), transparent), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 32px 28px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 16px 0 4px; font-size: 22px; letter-spacing: -.02em; }
.auth-card > p { margin: 0 0 20px; }
.alert { background: var(--danger-soft); color: var(--danger); padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .tab { flex: 1; padding: 7px 8px; }
  .hide-sm { display: none; }
  .container { padding: 18px 16px 50px; }
  .stat-value { font-size: 22px; }
  .bar-row { grid-template-columns: 96px 1fr auto; gap: 8px; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .filters .input { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .filters .search { flex-basis: 100%; }
  .seg button { padding: 6px 10px; font-size: 14px; }

  /* Tables become stacked cards on phones */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 13px; text-align: left; }
  table.stack td.no-label::before { content: none; }
  table.stack td.no-label { justify-content: flex-start; }
  .balance-cell { min-width: 0; }
  .balance-cell .mini-track { display: none; }
}
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px 14px; }
  .stat-value { font-size: 19px; }
  .logo-text { font-size: 15px; }
}
