:root {
  --sidebar-bg: #111923;
  --sidebar-hover: rgba(255, 255, 255, 0.08);
  --sidebar-active: rgba(255, 255, 255, 0.14);
  --sidebar-text: #F8FAFC;
  --sidebar-muted: #94A3B8;

  --paper: #F4F5F7;
  --surface: #FFFFFF;
  --surface-alt: #F8FAFC;
  --ink: #111923;
  --ink-soft: #334155;
  --muted: #64748B;
  --rule: #E2E8F0;
  --rule-strong: #CBD5E1;

  --accent: #2563EB;
  --accent-hover: #1D4ED8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --danger: #DC2626;
  --danger-soft: rgba(220, 38, 38, 0.08);
  --positive: #059669;

  --r-lg: 14px;
  --r-md: 10px;
  --r-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error-text { color: var(--danger); font-size: 13px; margin-bottom: 12px; font-weight: 500; }

.num, .hero-total, .metric-val, .total-badge, .expenses-table td, .cat-row-right, .rate-chip, .currency-pill, .donut-center strong {
  font-variant-numeric: tabular-nums;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 38px;
  padding: 0 16px;
  border-radius: var(--r-sm);
  border: 1px solid var(--rule-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.14s ease, border-color 0.14s ease, transform 0.08s ease;
}
.btn:hover { background: var(--surface-alt); }
.btn:active { transform: translateY(1px); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-block { width: 100%; height: 42px; font-size: 15px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #FFFFFF; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-secondary { background: var(--surface); border-color: var(--rule-strong); color: var(--ink); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--ink); }
.btn-danger-outline { background: transparent; border-color: rgba(220, 38, 38, 0.3); color: var(--danger); }
.btn-danger-outline:hover { background: var(--danger-soft); }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: var(--r-sm); background: var(--surface); border: 1px solid var(--rule); }

input, select {
  height: 38px;
  border: 1px solid var(--rule-strong);
  border-radius: var(--r-sm);
  padding: 0 11px;
  font-size: 14px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  width: 100%;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* Split Architectural Login */
.login-wrapper {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
  background: var(--surface);
}
.login-aside {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.login-aside-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.login-aside-copy h2 {
  font-size: clamp(28px, 3vw, 38px);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.03em;
  margin: 0 0 16px;
}
.login-aside-copy p {
  color: var(--sidebar-muted);
  font-size: 15px;
  max-width: 400px;
  margin: 0;
  line-height: 1.7;
}
.login-aside-meta {
  font-size: 13px;
  color: var(--sidebar-muted);
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 18px;
}
.login-main {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  background: var(--surface);
}
.login-card { width: 100%; max-width: 360px; }
.brand-header { margin-bottom: 26px; }
.brand-header h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.03em; }
.subtitle { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--ink-soft); }
.login-hint { margin-top: 18px; font-size: 13px; color: var(--muted); line-height: 1.6; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: #FFFFFF;
  flex-shrink: 0;
}

/* App Shell: Left Sidebar + Main Workspace */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 244px 1fr;
}

.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-top { display: flex; flex-direction: column; gap: 24px; }
.logo-badge {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.02em;
  color: #FFFFFF;
}

.nav-tabs { display: flex; flex-direction: column; gap: 4px; }
.nav-tab {
  border: none;
  background: transparent;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--sidebar-muted);
  cursor: pointer;
  text-align: left;
  transition: background-color 0.14s ease, color 0.14s ease;
}
.nav-tab:hover { background: var(--sidebar-hover); color: #FFFFFF; }
.nav-tab.active { background: var(--sidebar-active); color: #FFFFFF; font-weight: 600; }

.sidebar-section-label {
  font-size: 12px;
  color: var(--sidebar-muted);
  padding: 0 10px 6px;
}
.view-switcher {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.view-pill {
  border: none;
  background: transparent;
  padding: 8px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--sidebar-muted);
  cursor: pointer;
  text-align: left;
}
.view-pill:hover { background: var(--sidebar-hover); color: #FFFFFF; }
.view-pill.active { background: var(--accent); color: #FFFFFF; }

.sidebar-bottom {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.avatar-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  text-align: left;
}
.avatar-btn:hover { background: var(--sidebar-hover); }
.avatar-circle {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.avatar-circle.avatar-lg { width: 42px; height: 42px; font-size: 17px; }
.avatar-name { font-size: 14px; font-weight: 500; color: #FFFFFF; }
.avatar-sub { font-size: 12px; color: var(--sidebar-muted); display: block; }

/* Main Content */
.main-content {
  padding: 28px 34px 64px;
  max-width: 1120px;
  width: 100%;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.page-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.025em;
}

.card {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 20px 22px;
  margin-bottom: 16px;
}
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 8px; }
.card-header h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--ink); }

/* Ledger Hero Summary Band */
.ledger-hero {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--r-lg);
  padding: 22px 24px;
  margin-bottom: 16px;
}
.ledger-hero-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--rule);
}
.period-modes { display: inline-flex; gap: 4px; background: var(--surface-alt); padding: 3px; border-radius: var(--r-sm); border: 1px solid var(--rule); }
.chip {
  border: none;
  background: transparent;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
}
.chip.active { background: var(--ink); color: #FFFFFF; }
.picker-wrap { display: flex; align-items: center; gap: 6px; }
.picker-wrap input, .picker-wrap select { width: auto; height: 32px; font-size: 13px; }

.ledger-hero-body {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  padding-top: 18px;
}
.hero-primary-stat .hero-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.hero-total {
  font-size: clamp(32px, 4vw, 42px);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.1;
  color: var(--ink);
}
.hero-change { margin-top: 6px; font-size: 13px; color: var(--muted); }
.trend-up { color: var(--danger); font-weight: 500; }
.trend-down { color: var(--positive); font-weight: 500; }

.hero-sub-metrics { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.sub-metric { padding-left: 20px; border-left: 1px solid var(--rule); }
.sub-metric-label { font-size: 12px; color: var(--muted); margin-bottom: 3px; }
.metric-val { font-size: 19px; font-weight: 600; color: var(--ink); }

.split-strip { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--rule); }
.split-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  overflow: hidden;
  display: flex;
  gap: 2px;
  margin-bottom: 10px;
}
.split-segment { height: 100%; transition: width 0.3s ease; border-radius: 999px; }
.split-legend { display: flex; flex-wrap: wrap; gap: 18px; }
.split-item { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-soft); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }

/* Charts */
.charts-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 16px; }
.chart-box { min-height: 230px; }
.svg-chart { width: 100%; height: 225px; display: block; }
.svg-chart rect { transition: opacity 0.14s ease; cursor: pointer; }
.svg-chart rect:hover { opacity: 0.82; }

.category-breakdown { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
.donut-wrap { width: 166px; height: 166px; flex-shrink: 0; margin: 0 auto; position: relative; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-center strong { font-size: 15px; }
.donut-center span { font-size: 12px; color: var(--muted); }
.cat-legend { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 3px; }
.cat-row { display: flex; align-items: center; justify-content: space-between; padding: 7px 9px; border-radius: var(--r-sm); cursor: pointer; }
.cat-row:hover { background: var(--surface-alt); }
.cat-row-left { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; }
.cat-row-right { text-align: right; font-size: 14px; }

/* Currency Grid */
.currency-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
.currency-pill { background: var(--surface-alt); border: 1px solid var(--rule); border-radius: var(--r-md); padding: 11px 13px; }

/* Expenses Filter & Table */
.filter-bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 18px; }
.filter-inputs { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.filter-inputs select, .filter-inputs input { width: auto; min-width: 125px; flex: 1; height: 34px; font-size: 13px; }
.filter-actions { display: flex; gap: 8px; }
.total-badge { font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 4px 11px; border-radius: 999px; font-size: 13px; }

.expenses-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.expenses-table th, .expenses-table td { padding: 12px 10px; border-bottom: 1px solid var(--rule); text-align: left; }
.expenses-table th { font-size: 13px; color: var(--muted); font-weight: 500; }
.expenses-table tr:hover td { background: var(--paper); }
.user-tag { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; color: #FFFFFF; }
.sub-fx { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(350px, 1fr)); gap: 16px; }
.badge { background: var(--accent-soft); color: var(--accent); font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 500; }
.shortcut-import-actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0 6px; }
.api-key-box { margin: 12px 0; }
.api-key-box label { display: block; font-size: 13px; font-weight: 500; color: var(--muted); margin-bottom: 6px; }
.api-key-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.api-key-row code { flex: 1; background: var(--surface-alt); border: 1px solid var(--rule); padding: 7px 10px; border-radius: var(--r-sm); font-size: 13px; word-break: break-all; }
.code-block { background: var(--sidebar-bg); color: #F8FAFC; padding: 13px; border-radius: var(--r-md); font-size: 13px; overflow-x: auto; }
.inline-form { display: flex; gap: 8px; margin-bottom: 12px; align-items: center; }
.inline-form input[type="color"] { width: 42px; height: 38px; padding: 2px; cursor: pointer; }
.cat-manage-list { display: flex; flex-direction: column; gap: 6px; max-height: 280px; overflow-y: auto; }
.cat-manage-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 11px; background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-sm); }
.rates-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(125px, 1fr)); gap: 8px; margin-top: 12px; }
.rate-chip { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 8px 10px; font-size: 13px; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17, 25, 35, 0.5); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-card { width: 100%; max-width: 470px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-lg); padding: 22px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h3 { margin: 0; font-size: 17px; font-weight: 600; }
.form-row { display: flex; gap: 10px; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Toast */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #FFFFFF; padding: 10px 18px; border-radius: 999px; font-size: 13px; font-weight: 500; z-index: 100; }

/* Responsive: collapse sidebar into compact top bar on mobile/tablet */
@media (max-width: 900px) {
  .login-wrapper { grid-template-columns: 1fr; }
  .login-aside { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
    gap: 10px;
    flex-wrap: wrap;
    z-index: 30;
  }
  .sidebar-top { flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap; }
  .nav-tabs { flex-direction: row; }
  .sidebar-section-label { display: none; }
  .view-switcher { flex-direction: row; }
  .sidebar-bottom { border-top: none; padding-top: 0; flex-direction: row; align-items: center; }
  .avatar-sub { display: none; }
  .charts-grid { grid-template-columns: 1fr; }
  .main-content { padding: 18px 14px 48px; }
}
@media (max-width: 639px) {
  .sub-metric { padding-left: 14px; }
  .expenses-table th:nth-child(4), .expenses-table td:nth-child(4) { display: none; }
  .settings-grid { grid-template-columns: 1fr; }
}
