[hidden] { display: none !important; }
:root {
  --bg: #f2f4f7;
  --surface: #ffffff;
  --border: #e3e6ea;
  --border-strong: #d4d9df;
  --text: #17212b;
  --muted: #6b7280;
  --primary: #0f766e;
  --primary-soft: #ecfdf8;
  --expense: #dc2626;
  --income: #16a34a;
  --warn: #d97706;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(23, 33, 43, 0.07);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

input, select {
  font: inherit;
  color: inherit;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  border-radius: 6px;
  padding: 8px 10px;
  min-width: 0;
}

input:focus, select:focus, button:focus-visible {
  outline: 2px solid rgba(15, 118, 110, 0.35);
  outline-offset: 1px;
}

/* Topbar */
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
}

.brand-mark svg { width: 18px; height: 18px; }

.brand-name { font-size: 18px; font-weight: 700; white-space: nowrap; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.month-switch {
  display: flex;
  align-items: center;
  gap: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 3px;
}

.month-switch select {
  border: 0;
  background: transparent;
  padding: 6px 6px 6px 10px;
  min-width: 88px;
  text-align: center;
}

.icon-btn {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  border: 1px solid transparent;
  color: var(--muted);
}

.icon-btn:hover { background: var(--bg); color: var(--text); }

.icon-btn svg { width: 17px; height: 17px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  font-weight: 600;
  white-space: nowrap;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #0c655e; }

.btn-ghost { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #e8eaee; }

.menu-wrap { position: relative; }

.menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(23, 33, 43, 0.12);
  padding: 6px;
  z-index: 30;
}

.menu button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  text-align: left;
}

.menu button:hover { background: var(--bg); }

.menu svg { width: 16px; height: 16px; color: var(--muted); }

/* Workspace */
.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

.sidebar {
  width: 190px;
  flex: 0 0 190px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 600;
}

.nav-item svg { width: 18px; height: 18px; }

.nav-item:hover { background: var(--bg); color: var(--text); }

.nav-item.active { background: var(--primary-soft); color: var(--primary); }

.content {
  flex: 1;
  min-width: 0;
  padding: 22px;
  max-width: 1440px;
}

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

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.page-head h1 { font-size: 22px; font-weight: 700; }

.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-width: 0;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0 10px;
  min-width: 220px;
}

.search-box svg { width: 16px; height: 16px; color: var(--muted); flex: 0 0 auto; }

.search-box input { border: 0; background: transparent; width: 100%; }

.filter-row select { min-width: 104px; }

.insight-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--muted);
}

/* Stats */
.stat-band {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.stat {
  padding: 16px 18px;
  border-left: 1px solid var(--border);
}

.stat:first-child { border-left: 0; }

.stat-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 3px; }

.stat-value { font-size: 20px; font-weight: 700; }

.stat-value.expense { color: var(--expense); }
.stat-value.income { color: var(--income); }

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  min-width: 0;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-head h2 { font-size: 15px; font-weight: 700; }

.panel-sub { font-size: 12px; color: var(--muted); white-space: nowrap; }

.ledger-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  gap: 16px;
}

.analysis-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.analysis-grid.two { grid-template-columns: 1fr 1fr; }

.chart-wrap {
  position: relative;
  height: 240px;
}

.chart-wrap.tall { height: 270px; }

/* Transaction list */
.tx-list {
  max-height: 320px;
  overflow-y: auto;
}

.tx-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 4px;
  border-bottom: 1px solid var(--border);
}

.tx-item:last-child { border-bottom: 0; }

.tx-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: var(--bg);
  color: var(--muted);
}

.tx-icon.expense { background: #fef2f2; color: var(--expense); }
.tx-icon.income { background: #f0fdf4; color: var(--income); }

.tx-icon svg { width: 16px; height: 16px; }

.tx-main { min-width: 0; }

.tx-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tx-meta { font-size: 12px; color: var(--muted); }

.tx-amount { font-weight: 700; white-space: nowrap; }

.tx-amount.expense { color: var(--expense); }
.tx-amount.income { color: var(--income); }

/* Table */
.table-wrap { overflow-x: auto; min-width: 0; max-width: 100%; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  text-align: left;
  padding: 9px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: 0; }

tbody tr:hover td { background: #fafbfc; }

.tag {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.tag.expense { background: #fef2f2; color: var(--expense); }
.tag.income { background: #f0fdf4; color: var(--income); }

.cat-dot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.cat-dot i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 8px;
}

.row-actions { display: flex; gap: 4px; }

.row-actions .icon-btn { width: 30px; height: 30px; flex-basis: 30px; }

.row-actions .icon-btn.danger:hover { color: var(--expense); background: #fef2f2; }

.empty-row { text-align: center; color: var(--muted); padding: 28px 0; }

/* Analysis */
.mini-table { max-height: 340px; overflow-y: auto; overflow-x: auto; min-width: 0; max-width: 100%; }

.insight-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

.insight-item {
  display: flex;
  gap: 10px;
  padding: 11px 12px;
  background: var(--bg);
  border-radius: 6px;
}

.insight-item svg { width: 17px; height: 17px; color: var(--primary); flex: 0 0 auto; margin-top: 2px; }

.insight-item p { font-size: 13px; }

/* Plan */
.plan-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--radius);
  padding: 22px 24px;
  margin-bottom: 16px;
}

.plan-hero h2 { font-size: 18px; margin-bottom: 6px; }

.plan-hero p { color: #7c2d12; max-width: 760px; }

.plan-score {
  flex: 0 0 auto;
  text-align: center;
  width: 108px;
  height: 108px;
  border: 6px solid #fbbf24;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-num { font-size: 26px; font-weight: 800; color: #b45309; }

.score-label { font-size: 12px; color: #b45309; }

.plan-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.action-list {
  list-style: none;
  counter-reset: step;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.action-list li {
  counter-increment: step;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  font-size: 13px;
}

.action-list li::before {
  content: counter(step);
  width: 24px;
  height: 24px;
  flex: 0 0 24px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  font-size: 12px;
}

.reminder-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 10px;
}

.reminder {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 12px;
  background: #f8fafc;
  border-radius: 6px;
  font-size: 13px;
}

.reminder svg { width: 16px; height: 16px; color: var(--warn); flex: 0 0 auto; margin-top: 2px; }

.budget-ok { color: var(--income); font-weight: 600; }
.budget-warn { color: var(--warn); font-weight: 600; }
.budget-high { color: var(--expense); font-weight: 600; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23, 33, 43, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal {
  width: min(500px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: 0 18px 50px rgba(23, 33, 43, 0.22);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-head h2 { font-size: 18px; }

#entryForm { display: flex; flex-direction: column; gap: 12px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field label { font-size: 12px; color: var(--muted); }

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  overflow: hidden;
  padding: 3px;
  gap: 3px;
}

.seg-btn {
  padding: 8px 10px;
  border-radius: 5px;
  color: var(--muted);
  font-weight: 600;
}

.seg-btn.active { background: var(--primary); color: #fff; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 6px;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #17212b;
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(23, 33, 43, 0.25);
  z-index: 200;
}

/* Responsive */
@media (max-width: 1024px) {
  .analysis-grid, .analysis-grid.two { grid-template-columns: 1fr; }
  .plan-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar-actions { gap: 6px; }
  .btn span { display: none; }
  .btn { padding: 0 11px; }
  .workspace { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: none;
    flex-direction: row;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 8px 10px;
  }
  .nav-item { flex: 1; justify-content: center; }
  .nav-item span { display: none; }
  .content { padding: 14px 12px; }
  .stat-band { grid-template-columns: 1fr 1fr; }
  .stat:nth-child(3) { border-left: 0; border-top: 1px solid var(--border); }
  .stat:nth-child(4) { border-top: 1px solid var(--border); }
  .ledger-grid { grid-template-columns: 1fr; }
  .page-head { align-items: stretch; }
  .filter-row { width: 100%; }
  .search-box { flex: 1; min-width: 0; }
  .plan-hero { flex-direction: column; text-align: center; }
  .form-row { grid-template-columns: 1fr; }
  .chart-wrap, .chart-wrap.tall { height: 230px; }
  .menu { right: auto; left: 0; }
}
