/* ── CSS Variables ────────────────────────────────────────────────────── */
:root {
  --bg-body: #07070d;
  --bg-card: #0f1018;
  --bg-card-hover: #161822;
  --bg-input: #12131e;
  --bg-surface: #1a1c2a;
  --border: #1e2035;
  --border-focus: #3b82f6;
  --text-primary: #e8e9f0;
  --text-secondary: #8b8da3;
  --text-muted: #5a5c72;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-glow: rgba(59, 130, 246, 0.15);
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 20px rgba(0, 0, 0, 0.5);
  --transition: 0.2s ease;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ── Reset ───────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  font-family: var(--font);
  background: var(--bg-body);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }
.hidden { display: none !important; }

/* ── Login Screen ────────────────────────────────────────────────────── */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-body);
  padding: 1rem;
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 3rem 2.5rem;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.1em;
  margin-bottom: 0.25rem;
}
.login-subtitle {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}
.login-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 1rem;
  margin-bottom: 1rem;
  outline: none;
  transition: border var(--transition);
}
.login-input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-glow); }
.login-btn {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  transition: background var(--transition);
}
.login-btn:hover { background: var(--accent-hover); }
.login-error { color: var(--danger); font-size: 0.85rem; margin-top: 0.75rem; min-height: 1.2em; }

/* ── Top Bar ─────────────────────────────────────────────────────────── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.top-bar-left { display: flex; align-items: baseline; gap: 0.5rem; }
.brand { font-size: 1.25rem; font-weight: 700; color: var(--accent); letter-spacing: 0.05em; }
.brand-sub { font-size: 0.8rem; color: var(--text-muted); }
.top-bar-center { display: flex; align-items: center; gap: 0.5rem; }
.month-nav-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: background var(--transition);
}
.month-nav-btn:hover { background: var(--bg-card-hover); }
.month-select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  min-width: 180px;
}
.top-bar-right { display: flex; gap: 0.5rem; }
.icon-btn {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 2.25rem;
  height: 2.25rem;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition);
}
.icon-btn:hover { background: var(--bg-card-hover); color: var(--text-primary); }

/* ── Tabs ────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 0;
  padding: 0 1.5rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  padding: 0.75rem 1.25rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}
.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Panels ──────────────────────────────────────────────────────────── */
.panels { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }
.panel { display: none; }
.panel.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ── Metric Cards ────────────────────────────────────────────────────── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  transition: all var(--transition);
}
.metric-card:hover { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-glow); }
.metric-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem; }
.metric-value { font-size: 1.5rem; font-weight: 700; color: var(--text-primary); font-family: var(--font-mono); }
.metric-value.positive { color: var(--success); }
.metric-value.negative { color: var(--danger); }
.metric-value.warning { color: var(--warning); }
.metric-sub { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ── Charts ──────────────────────────────────────────────────────────── */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.chart-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  position: relative;
  min-height: 280px;
}
.chart-box.full-width { grid-column: 1 / -1; }
.chart-box canvas { max-height: 300px; }

/* ── Data Table (Transactions) ───────────────────────────────────────── */
.panel-toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 200px;
  padding: 0.6rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border var(--transition);
}
.search-input:focus { border-color: var(--border-focus); }
.filter-select {
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
}
.table-wrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th {
  background: var(--bg-surface);
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  padding: 0.75rem 1rem;
  text-align: left;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td {
  padding: 0.6rem 1rem;
  border-top: 1px solid var(--border);
  white-space: nowrap;
  color: var(--text-primary);
}
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-card-hover); }
.data-table td.num { font-family: var(--font-mono); font-size: 0.85rem; }

/* ── Revenue Form & List ─────────────────────────────────────────────── */
.revenue-form-wrap, .revenue-list-wrap, .cash-balance-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1rem;
}
.section-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; color: var(--text-primary); }
.revenue-form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr auto;
  gap: 0.75rem;
  align-items: end;
}
.revenue-form input, .revenue-form select {
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}
.revenue-form input:focus, .revenue-form select:focus { border-color: var(--border-focus); }
.btn {
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg-card-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

.revenue-entry {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.5rem;
  transition: background var(--transition);
}
.revenue-entry:hover { background: var(--bg-card-hover); }
.revenue-entry-info { flex: 1; }
.revenue-entry-source { font-weight: 600; color: var(--text-primary); }
.revenue-entry-meta { font-size: 0.8rem; color: var(--text-muted); }
.revenue-entry-amount { font-family: var(--font-mono); font-weight: 700; font-size: 1.1rem; color: var(--success); margin: 0 1rem; }
.revenue-entry-actions { display: flex; gap: 0.5rem; }

.cash-form {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}
.cash-form input {
  flex: 1;
  max-width: 300px;
  padding: 0.6rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}
.cash-form input:focus { border-color: var(--border-focus); }
.cash-display { font-size: 0.9rem; color: var(--text-secondary); margin-top: 0.75rem; }

/* ── Toast Notifications ─────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  max-width: 350px;
}
.toast.success { background: var(--success-bg); color: var(--success); border: 1px solid var(--success); }
.toast.error { background: var(--danger-bg); color: var(--danger); border: 1px solid var(--danger); }
.toast.warning { background: var(--warning-bg); color: var(--warning); border: 1px solid var(--warning); }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Empty States ────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

/* ── Skeleton Loading ────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--bg-surface) 25%, var(--bg-card-hover) 50%, var(--bg-surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}
.skeleton-card { height: 100px; }
.skeleton-chart { height: 280px; }
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* ── Export Panel ────────────────────────────────────────────────────── */
.export-options {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 600px;
}
.export-desc { color: var(--text-secondary); margin-bottom: 1.5rem; font-size: 0.9rem; }
.export-buttons { display: flex; gap: 0.75rem; margin-bottom: 1.5rem; }
.export-preview {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  max-height: 300px;
  overflow: auto;
  white-space: pre;
  display: none;
}
.export-preview.visible { display: block; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .charts-row { grid-template-columns: 1fr; }
  .chart-box.full-width { grid-column: auto; }
  .metrics-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}
@media (max-width: 768px) {
  .top-bar { flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem 1rem; }
  .top-bar-center { order: 3; width: 100%; justify-content: center; }
  .panels { padding: 1rem; }
  .revenue-form { grid-template-columns: 1fr 1fr; }
  .tabs { padding: 0 0.75rem; }
  .tab { padding: 0.6rem 0.75rem; font-size: 0.8rem; }
  .data-table th, .data-table td { padding: 0.5rem 0.6rem; }
  .metric-value { font-size: 1.2rem; }
}
@media (max-width: 480px) {
  .revenue-form { grid-template-columns: 1fr; }
  .cash-form { flex-direction: column; }
  .cash-form input { max-width: 100%; }
  .metrics-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { padding: 1rem; }
}

/* ── Print ───────────────────────────────────────────────────────────── */
@media print {
  body { background: #fff; color: #000; }
  .top-bar, .tabs, .toast-container, .login-screen, .btn, .search-input, .filter-select,
  .revenue-form-wrap, .cash-balance-wrap, .export-options { display: none !important; }
  .panel { display: block !important; page-break-inside: avoid; }
  .metric-card { border: 1px solid #ccc; background: #f9f9f9; }
  .metric-value { color: #000; }
  .data-table th { background: #eee; }
  .chart-box { border: 1px solid #ccc; background: #fff; }
}

/* ── Status Indicator ────────────────────────────────────────────────── */
.status-alive { color: var(--success); font-weight: 700; }
.status-dead { color: var(--danger); font-weight: 700; }
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-recurring { background: var(--accent-glow); color: var(--accent); }
.badge-onetime { background: var(--bg-surface); color: var(--text-muted); }
.badge-reimbursable { background: var(--warning-bg); color: var(--warning); }
.badge-invoice { background: var(--success-bg); color: var(--success); }

/* ── Scrollbar ───────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Spinner ─────────────────────────────────────────────────────────── */
.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
