:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --primary: #0f766e;
  --primary-hover: #115e59;
  --primary-soft: #f0fdfa;
  --primary-border: #99f6e4;

  --paid: #047857;
  --paid-bg: #ecfdf5;
  --unpaid: #b45309;
  --unpaid-bg: #fffbeb;
  --overdue: #be123c;
  --overdue-bg: #fff1f2;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 8px 24px -4px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 20px 44px -12px rgba(15, 23, 42, 0.18);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Plus Jakarta Sans", "Noto Sans TC", -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

.tabular-nums {
  font-variant-numeric: tabular-nums;
}

.text-right {
  text-align: right;
}

.text-amber {
  color: var(--unpaid);
}

.text-danger {
  color: var(--overdue);
}

.mt-2 {
  margin-top: 8px;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

.btn:active {
  transform: translateY(1px);
}

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

.btn-sm {
  padding: 6px 11px;
  font-size: 13px;
}

.btn-full {
  width: 100%;
}

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

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

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

.btn-secondary:hover {
  background: var(--surface-muted);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: #e2e8f066;
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--overdue);
}

.btn-danger-ghost:hover {
  background: var(--overdue-bg);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
}

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

.link-btn {
  border: none;
  background: none;
  color: var(--primary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.link-btn:hover {
  text-decoration: underline;
}

.input {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

.input-sm {
  padding: 7px 10px;
  font-size: 13px;
}

.input-amount {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

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

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.label-row .field-label {
  margin-bottom: 0;
}

/* Auth Gate */
.auth-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #e6f4f1 0%, var(--bg) 55%);
}

.auth-card {
  width: 100%;
  max-width: 410px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 14px;
}

.auth-title {
  margin: 0 0 6px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
}

.auth-subtitle {
  margin: 0 0 22px;
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.alert-box {
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

.alert-box p {
  margin: 6px 0 0;
}

.alert-box code {
  display: inline-block;
  margin-top: 6px;
  padding: 3px 6px;
  border-radius: 4px;
  background: rgba(15, 23, 42, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}

.alert-warning {
  background: var(--unpaid-bg);
  border: 1px solid #fde68a;
  color: #78350f;
}

.form-error {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--overdue-bg);
  color: var(--overdue);
  font-size: 13px;
  font-weight: 500;
}

.form-success {
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--paid-bg);
  color: var(--paid);
  font-size: 13px;
  font-weight: 500;
}

/* Topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

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

.brand-icon {
  flex-shrink: 0;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-title {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-sub {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.storage-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  border: 1px solid var(--primary-border);
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  color: var(--text);
}

.nav-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-nav {
  display: none;
  padding: 0 16px 10px;
  gap: 6px;
}

/* Main Content */
.main-content {
  max-width: 1180px;
  margin: 0 auto;
  padding: 22px 20px 56px;
}

.view-section {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

/* Reminders Strip */
.reminders-panel {
  background: linear-gradient(135deg, #fffbeb 0%, #fff7ed 100%);
  border: 1px solid #fed7aa;
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.reminders-panel.has-overdue {
  background: linear-gradient(135deg, #fff1f2 0%, #fff7ed 100%);
  border-color: #fecdd3;
}

.reminders-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.reminders-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.reminders-summary {
  color: var(--text-secondary);
  font-size: 13px;
}

.pulse-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.22);
}

.reminders-panel.has-overdue .pulse-dot {
  background: var(--overdue);
  box-shadow: 0 0 0 3px rgba(190, 18, 60, 0.22);
}

.reminders-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.reminder-item {
  flex: 1 1 280px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

.reminder-info {
  min-width: 0;
}

.reminder-card-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 600;
}

.reminder-meta {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.reminder-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.reminder-amount {
  font-weight: 700;
  font-size: 14.5px;
}

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.kpi-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.kpi-value {
  margin-top: 6px;
  font-size: 23px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.kpi-meta {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

/* Panel & Toolbar */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.toolbar {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.status-pills {
  display: inline-flex;
  gap: 4px;
  background: var(--surface-muted);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.pill {
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.pill.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

.filter-inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.filter-inputs .input-sm {
  width: auto;
  min-width: 135px;
}

.month-filter-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Ledger Table */
.table-wrap {
  overflow-x: auto;
}

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

.ledger-table th {
  padding: 11px 16px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.ledger-table th.text-right {
  text-align: right;
}

.ledger-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.ledger-table tbody tr:last-child td {
  border-bottom: none;
}

.ledger-table tbody tr:hover {
  background: #f8fafc;
}

.card-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.color-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.card-cell-title {
  font-weight: 600;
  font-size: 14px;
}

.card-cell-sub {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-paid {
  background: var(--paid-bg);
  color: var(--paid);
}

.badge-unpaid {
  background: var(--unpaid-bg);
  color: var(--unpaid);
}

.badge-overdue {
  background: var(--overdue-bg);
  color: var(--overdue);
}

.badge-neutral {
  background: #f1f5f9;
  color: var(--text-secondary);
}

.date-stack {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.date-primary {
  font-size: 13.5px;
  font-weight: 600;
}

.date-secondary {
  font-size: 12px;
  color: var(--text-muted);
}

.amount-main {
  font-size: 15.5px;
  font-weight: 700;
}

.amount-sub {
  font-size: 11.5px;
  color: var(--text-muted);
}

.note-cell {
  max-width: 240px;
}

.method-tag {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  background: #f1f5f9;
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  margin-bottom: 2px;
}

.note-text {
  font-size: 13px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.ledger-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

/* Mobile Ledger List */
.mobile-ledger-list {
  display: none;
  flex-direction: column;
  divide-y: 1px solid var(--border);
}

.mobile-ledger-card {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.mobile-ledger-card:last-child {
  border-bottom: none;
}

.mobile-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.mobile-card-mid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.mobile-card-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 4px;
}

/* Empty State */
.empty-state {
  padding: 48px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 38px;
  margin-bottom: 8px;
}

.empty-state h3 {
  margin: 0 0 6px;
  font-size: 17px;
}

.empty-state p {
  margin: 0 auto 18px;
  max-width: 440px;
  font-size: 14px;
  color: var(--text-muted);
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

/* Analytics View */
.analytics-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.section-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.section-sub {
  margin: 2px 0 0;
  font-size: 13.5px;
  color: var(--text-muted);
}

.year-switcher {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 6px;
}

.year-label {
  font-size: 15px;
  font-weight: 700;
  min-width: 52px;
  text-align: center;
}

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

.chart-panel {
  padding: 18px;
}

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

.panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.panel-sub {
  margin: 3px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.legend {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 12.5px;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.legend-dot.paid {
  background: var(--primary);
}

.legend-dot.unpaid {
  background: #f59e0b;
}

.chart-container {
  width: 100%;
  overflow-x: auto;
}

.chart-svg {
  width: 100%;
  min-width: 460px;
  height: auto;
  display: block;
}

.chart-bar-group {
  cursor: pointer;
}

.chart-bar-group:hover .bar-hover-bg {
  fill: rgba(15, 118, 110, 0.08);
}

.chart-bar-group.selected .bar-hover-bg {
  fill: rgba(15, 118, 110, 0.12);
  stroke: var(--primary);
  stroke-width: 1;
}

.breakdown-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.donut-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 0;
}

.breakdown-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.breakdown-item {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.breakdown-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 13.5px;
}

.breakdown-name {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  min-width: 0;
}

.breakdown-name span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breakdown-bar-track {
  width: 100%;
  height: 7px;
  border-radius: 999px;
  background: #f1f5f9;
  overflow: hidden;
}

.breakdown-bar-fill {
  height: 100%;
  border-radius: 999px;
}

.breakdown-sub {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
}

/* Cards Management */
.cards-header-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  color: var(--text-secondary);
  cursor: pointer;
}

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

.credit-card-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.credit-card-item.archived {
  opacity: 0.72;
}

.credit-card-accent {
  height: 7px;
  width: 100%;
}

.credit-card-body {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.credit-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.credit-card-bank {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.credit-card-name {
  font-size: 17px;
  font-weight: 700;
  margin-top: 2px;
}

.credit-card-last4 {
  font-size: 12.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.credit-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.credit-card-notes {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.credit-card-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}

.credit-card-stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
}

.credit-card-stat-val {
  font-size: 14px;
  font-weight: 700;
  margin-top: 2px;
}

.credit-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.48);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-width: 520px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.modal-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.status-toggle-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  background: var(--surface-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.status-toggle {
  border: none;
  background: transparent;
  padding: 9px 12px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
}

.status-toggle.active[data-payment-status="paid"] {
  background: var(--surface);
  color: var(--paid);
  box-shadow: var(--shadow-sm);
}

.status-toggle.active[data-payment-status="unpaid"] {
  background: var(--surface);
  color: var(--unpaid);
  box-shadow: var(--shadow-sm);
}

.form-row {
  display: flex;
  gap: 12px;
}

.two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.three-cols {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.align-center {
  align-items: center;
}

.flex-1 {
  flex: 1;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--border-strong);
  background: var(--surface-muted);
  color: var(--text-secondary);
  padding: 4px 10px;
  border-radius: 999px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s ease;
}

.chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

.color-picker-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.swatches {
  display: flex;
  gap: 6px;
}

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.swatch.active {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.color-native {
  width: 30px;
  height: 28px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 1px;
  background: var(--surface);
  cursor: pointer;
}

.checkbox-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  margin-top: 18px;
}

.backup-section h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.backup-section p {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.import-box {
  margin-top: 14px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

.import-mode-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 10px;
}

.radio-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
}

/* Toast */
.toast-container {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  background: #0f172a;
  color: #ffffff;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.18s ease;
}

.toast.error {
  background: var(--overdue);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Responsive Breakpoints */
@media (max-width: 980px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .analytics-grid {
    grid-template-columns: 1fr;
  }
  .cards-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .nav-tabs {
    display: none;
  }
  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
  }
  .mobile-nav .nav-tab {
    text-align: center;
    background: var(--surface-muted);
    border: 1px solid var(--border);
  }
  .mobile-nav .nav-tab.active {
    background: var(--primary-soft);
    border-color: var(--primary-border);
    color: var(--primary);
  }
  .table-wrap {
    display: none !important;
  }
  .mobile-ledger-list:not(.hidden) {
    display: flex;
  }
}

@media (max-width: 600px) {
  .topbar-inner {
    padding: 10px 14px;
  }
  .brand-sub,
  .hide-sm {
    display: none;
  }
  .main-content {
    padding: 14px 14px 48px;
  }
  .kpi-grid {
    gap: 10px;
  }
  .kpi-card {
    padding: 13px 14px;
  }
  .kpi-value {
    font-size: 19px;
  }
  .cards-grid,
  .two-cols,
  .three-cols {
    grid-template-columns: 1fr;
  }
  .checkbox-card {
    margin-top: 0;
  }
  .filter-inputs {
    width: 100%;
  }
  .filter-inputs .input-sm {
    flex: 1 1 130px;
  }
}
