:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222c;
  --border: #262b36;
  --text: #e6e8ec;
  --muted: #9aa1ac;
  --accent: #4caf50;
  --accent-ink: #05130a;
  --danger: #f44336;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1rem calc(5rem + env(safe-area-inset-bottom));
}

.view { display: none; }
.view.active { display: block; }

.placeholder { color: var(--muted); }

/* ---- Tab bar: bottom on mobile (default), top on laptop ---- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: space-around;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 0.35rem 0.25rem calc(0.35rem + env(safe-area-inset-bottom));
  z-index: 10;
}

.tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 0.72rem;
  padding: 0.5rem 0.25rem;
  border-radius: 8px;
  cursor: pointer;
  min-height: 44px;
}

.tab.active { color: var(--accent); font-weight: 600; }
.tab:active { background: rgba(255, 255, 255, 0.06); }

/* Cards / shared building blocks */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 1rem;
}

button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

h2 { font-size: 1.25rem; margin: 0.25rem 0 1rem; }
h3 { font-size: 1rem; margin: 0 0 0.75rem; }

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.neg { color: #ff6b6b; }
.pos { color: #51cf66; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

.field-label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; }
.row { display: flex; gap: 0.5rem; flex-wrap: wrap; }

select, input, textarea {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
  min-height: 44px;
}
select { min-width: 180px; }

.new-acct { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }

.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.over { border-color: var(--accent); background: rgba(76, 175, 80, 0.06); }
.link { color: var(--accent); cursor: pointer; text-decoration: underline; }

.stat-row { display: flex; flex-wrap: wrap; gap: 1.25rem; margin-bottom: 1rem; }
.stat-row > div { min-width: 90px; }

.mini-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.mini-table th, .mini-table td { text-align: left; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--border); }

.card.warn { border-color: #a97b1f; background: rgba(169, 123, 31, 0.08); }
.result { margin-left: 0.75rem; color: var(--muted); font-size: 0.85rem; }

/* Transactions */
.filters { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.filters input { flex: 1 1 200px; }

.bulkbar {
  display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.6rem 0.9rem; margin-bottom: 1rem;
}

.link-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 0.35rem 0.6rem; font-size: 0.8rem; cursor: pointer;
}
.link-btn:hover { border-color: var(--accent); }

.list-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; gap: 0.5rem; flex-wrap: wrap; }

.tx-list { display: flex; flex-direction: column; }
.tx-card {
  display: flex; gap: 0.6rem; align-items: flex-start;
  padding: 0.7rem 0; border-bottom: 1px solid var(--border);
}
.tx-card:last-child { border-bottom: none; }
.tx-card .sel { margin-top: 0.2rem; }
.tx-main { flex: 1; min-width: 0; }
.tx-top { display: flex; justify-content: space-between; gap: 0.75rem; align-items: baseline; }
.merchant { font-weight: 600; }
.tx-sub { margin-top: 0.1rem; }
.desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 0.1rem; }
.is-excluded { opacity: 0.45; }
.note-badge { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }
.excl-toggle { font-size: 0.8rem; color: var(--muted); display: inline-flex; align-items: center; gap: 0.3rem; }

.tx-controls { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-top: 0.5rem; }
.tx-controls select.cat { min-width: 130px; min-height: 36px; padding: 0.3rem 0.5rem; }

@media (min-width: 720px) {
  .tx-top { max-width: none; }
  .desc { max-width: 480px; }
}

/* Dashboard */
.stats-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; margin-bottom: 1rem; }
.stat { margin-bottom: 0; }
.stat-val { font-size: 1.3rem; font-weight: 700; margin-top: 0.25rem; }
.delta { font-size: 0.8rem; font-weight: 600; margin-left: 0.25rem; }
.chart-wrap { position: relative; height: 260px; }
.bar-list { display: flex; flex-direction: column; gap: 0.5rem; }
.bar-row { display: grid; grid-template-columns: 1fr 80px auto; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: var(--panel-2); border-radius: 4px; height: 8px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; }
.bar-val { font-size: 0.8rem; }
.sub-row { display: flex; justify-content: space-between; padding: 0.35rem 0; border-bottom: 1px solid var(--border); }
.sub-row:last-child { border-bottom: none; }

@media (min-width: 720px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Rules */
.rule-form .row { align-items: center; margin-bottom: 0.6rem; }
.rule-form label { display: inline-flex; align-items: center; gap: 0.4rem; }
.rule-item {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  padding: 0.6rem 0; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.rule-item:last-child { border-bottom: none; }
.rule-item.disabled { opacity: 0.45; }
.rule-desc code { background: var(--panel-2); padding: 0.1rem 0.35rem; border-radius: 4px; }
.rule-actions { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

/* Ask AI */
.answer { margin-top: 0.75rem; white-space: pre-wrap; line-height: 1.5; }
.chips { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }
.chip {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 0.35rem 0.75rem; font-size: 0.8rem; cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
code { background: var(--panel-2); padding: 0.1rem 0.35rem; border-radius: 4px; font-size: 0.85em; }

/* ---- Laptop / wide screens: move tabs to a top bar ---- */
@media (min-width: 720px) {
  .tabbar {
    position: sticky;
    top: 0;
    bottom: auto;
    justify-content: flex-start;
    gap: 0.25rem;
    border-top: none;
    border-bottom: 1px solid var(--border);
    padding: 0.5rem 1rem;
  }
  .tab {
    flex: 0 0 auto;
    font-size: 0.9rem;
    padding: 0.5rem 0.9rem;
  }
  .tab.active { background: var(--accent); color: var(--accent-ink); }
  #app { padding: 1.5rem 1.5rem 3rem; order: 1; }
  body { display: flex; flex-direction: column; }
  .tabbar { order: 0; }
}
