/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn svg {
  width: 15px;
  height: 15px;
  flex: none;
}

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

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: var(--accent-hover);
}

.btn-outline {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--text-2);
}

.btn-outline:hover {
  background: var(--surface-2);
  color: var(--navy);
}

.btn-ghost {
  background: transparent;
  color: var(--accent);
  padding: 0 8px;
  height: 32px;
  font-size: 12.5px;
}

.btn-ghost:hover {
  background: var(--accent-soft);
}

.btn-danger {
  background: var(--expense);
  color: #fff;
}

.btn-danger:hover {
  background: #a34d4d;
}

.btn-danger-outline {
  background: var(--surface);
  border-color: #e8c7c7;
  color: var(--expense);
}

.btn-danger-outline:hover {
  background: var(--expense-soft);
}

.btn-sm {
  height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  display: grid;
  place-items: center;
  padding: 0;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--navy);
}

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

/* Inputs & Selects */
.select-control, .input-control {
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0 11px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: 0;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.select-control:focus, .input-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Panels & Cards */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.panel-head {
  padding: 18px 20px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--navy);
}

.panel-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.panel-body {
  padding: 6px 20px 20px;
}

/* KPI Stat Cards */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
  transition: border-color 0.15s, transform 0.15s;
}

.stat-card.clickable {
  cursor: pointer;
}

.stat-card.clickable:hover {
  border-color: var(--accent-border);
  transform: translateY(-1px);
}

.stat-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.stat-icon {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: var(--surface-3);
  color: var(--text-2);
}

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

.stat-card.expense .stat-icon { background: var(--expense-soft); color: #ff3b30; }
.stat-card.income .stat-icon { background: var(--income-soft); color: #34c759; }
.stat-card.balance .stat-icon { background: var(--amber-soft); color: #ff9500; }
.stat-card.budget .stat-icon { background: var(--purple-soft); color: #af52de; }

.stat-value {
  font-size: 25px;
  font-weight: 750;
  letter-spacing: -0.03em;
  margin: 12px 0 6px;
  color: var(--navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-foot {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.trend-good { color: var(--income); font-weight: 600; }
.trend-warn { color: var(--expense); font-weight: 600; }

/* Progress Bar */
.progress-track {
  height: 6px;
  border-radius: 99px;
  background: #edf1f5;
  overflow: hidden;
  margin-top: 10px;
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: 99px;
  background: var(--accent);
  transition: width 0.3s ease;
}

.progress-fill.warn { background: #ff9500; }
.progress-fill.over { background: #ff3b30; }

/* Callout Banner */
.callout {
  padding: 12px 15px;
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  color: var(--accent-hover);
  font-size: 12.5px;
  line-height: 1.55;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 16px;
}

.callout.amber {
  background: var(--amber-soft);
  border-color: #ecd9bc;
  color: #8b5e27;
}

.callout.neutral {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text-2);
}

.callout svg {
  width: 17px;
  height: 17px;
  flex: none;
  margin-top: 2px;
}

/* Avatars & Pills */
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  flex: none;
}

.avatar-sm {
  width: 24px;
  height: 24px;
  font-size: 11px;
}

.avatar-lg {
  width: 44px;
  height: 44px;
  font-size: 16px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
}

.pill.household { background: var(--accent-soft); color: var(--accent-hover); }
.pill.personal { background: var(--surface-3); color: var(--text-2); }
.pill.income { background: var(--income-soft); color: var(--income); }
.pill.expense { background: var(--expense-soft); color: var(--expense); }
.pill.transfer { background: var(--transfer-soft); color: var(--transfer); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.admin { background: var(--navy-soft); color: var(--navy); }

/* Tabs & Segmented Controls */
.tabs {
  display: inline-flex;
  background: var(--surface-3);
  padding: 3px;
  border-radius: var(--radius-sm);
  gap: 2px;
}

.tab-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 6px 13px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 600;
  transition: 0.15s;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--navy);
  box-shadow: 0 1px 4px rgba(31, 45, 61, 0.08);
}

/* Tables */
.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
  padding: 11px 14px;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.data-table td {
  padding: 13px 14px;
  border-bottom: 1px solid #f1f4f8;
  font-size: 13px;
  color: var(--text-2);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background 0.12s;
}

.data-table tbody tr.clickable:hover {
  background: #f9fbfc;
  cursor: pointer;
}

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

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

.cat-icon-box {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  flex: none;
}

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

.merchant-name {
  font-weight: 650;
  color: var(--text);
  font-size: 13px;
  line-height: 1.3;
}

.merchant-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 1px;
}

.amount-cell {
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
  font-size: 13.5px;
}

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

/* Mobile Transaction Cards (hidden on desktop) */
.tx-card-list {
  display: none;
}

/* Filter Bar */
.filter-bar {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.filter-summary {
  padding: 10px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12.5px;
  color: var(--text-2);
}

/* Charts */
.chart-box {
  position: relative;
  width: 100%;
}

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: var(--navy);
  color: #fff;
  padding: 8px 11px;
  border-radius: 9px;
  font-size: 11.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: translate(-50%, -100%);
  transition: opacity 0.12s;
  z-index: 10;
  white-space: nowrap;
}

.chart-tooltip.show {
  opacity: 1;
}

.donut-layout {
  display: flex;
  align-items: center;
  gap: 22px;
}

.cat-legend {
  display: grid;
  gap: 9px;
  flex: 1;
  min-width: 0;
}

.cat-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-2);
  padding: 4px 6px;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.12s;
}

.cat-legend-row:hover {
  background: var(--surface-2);
}

.cat-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: none;
}

.cat-legend-val {
  margin-left: auto;
  font-weight: 650;
  color: var(--navy);
  font-size: 12.5px;
}

/* Member & List Rows */
.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid #f0f3f7;
}

.list-row:first-child {
  border-top: 0;
  padding-top: 4px;
}

.list-row.clickable {
  cursor: pointer;
  padding: 11px 8px;
  margin: 0 -8px;
  border-radius: 10px;
}

.list-row.clickable:hover {
  background: var(--surface-2);
}

/* Import Cards & Dropzone */
.dropzone {
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-md);
  padding: 28px 20px;
  text-align: center;
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.source-card {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  text-align: left;
  width: 100%;
}

.source-card:hover {
  border-color: var(--accent-border);
}

.source-card.selected {
  border-color: var(--accent);
  background: #f0f7ff;
}

.source-badge {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 750;
  font-size: 17px;
  flex: none;
}

.source-badge.wechat { background: #e9f9ee; color: #248a3d; }
.source-badge.alipay { background: #e8f2ff; color: #007aff; }

/* Empty State */
.empty-state {
  text-align: center;
  padding: 42px 20px;
  color: var(--muted);
}

.empty-state-icon {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--surface-3);
  color: var(--muted);
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
}

.empty-state h3 {
  margin: 0 0 6px;
  font-size: 15px;
  color: var(--navy);
}

.empty-state p {
  margin: 0 0 16px;
  font-size: 13px;
}

/* Modal & Drawer */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(24, 35, 49, 0.38);
  backdrop-filter: blur(3px);
  z-index: 40;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.backdrop.show {
  display: flex;
}

.backdrop.drawer-mode {
  justify-content: flex-end;
  align-items: stretch;
  padding: 0;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: min(520px, 100%);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 22px 24px;
}

.drawer-box {
  background: var(--surface);
  width: min(460px, 100%);
  height: 100%;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
}

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

.modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--navy);
}

.form-field {
  margin-bottom: 14px;
}

.form-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.form-field .input-control,
.form-field .select-control,
.form-field textarea {
  width: 100%;
}

.form-field textarea {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  resize: vertical;
  min-height: 68px;
  outline: 0;
  font-size: 13px;
}

.form-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.amount-hero-input {
  display: flex;
  align-items: center;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  background: var(--surface-2);
}

.amount-hero-input:focus-within {
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.amount-hero-input span {
  font-size: 22px;
  font-weight: 700;
  color: var(--muted);
  margin-right: 8px;
}

.amount-hero-input input {
  border: 0;
  outline: 0;
  background: transparent;
  width: 100%;
  font-size: 28px;
  font-weight: 750;
  color: var(--navy);
  font-variant-numeric: tabular-nums;
}

.field-error {
  color: var(--expense);
  font-size: 12px;
  margin-top: 5px;
}

.field-hint {
  color: var(--muted);
  font-size: 11.5px;
  margin-top: 5px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

/* Detail Key-Value Rows */
.kv-list {
  display: grid;
  gap: 10px;
  margin: 14px 0;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #f1f4f8;
  font-size: 13px;
}

.kv-key {
  color: var(--muted);
  flex: none;
}

.kv-val {
  color: var(--text);
  font-weight: 600;
  text-align: right;
  word-break: break-word;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translate(-50%, 16px);
  opacity: 0;
  background: var(--navy);
  color: #fff;
  border-radius: 11px;
  padding: 11px 16px;
  font-size: 13px;
  font-weight: 500;
  z-index: 60;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  box-shadow: var(--shadow-md);
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}
