/* ============================================================
   EasyEcon — Design Tokens & Base Styles
   Phase 0: Foundation
   ============================================================
   All theming is done via CSS custom properties.
   User accent color is injected inline in <head> at runtime.
   ============================================================ */

/* ---------- Design Tokens ---------- */
:root {
  /* Brand */
  --brand-green: #1f5c3d;
  --brand-green-light: #2e7d54;

  /* Accent — overridable per user via inline <style> */
  --accent: #1f5c3d;
  --accent-hover: #174a30;

  /* Surfaces */
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-alt: #f5f5f4;
  --border: #e7e5e4;
  --border-strong: #d6d3d1;

  /* Text */
  --text: #0c0a09;
  --text-muted: #57534e;
  --text-faint: #a8a29e;

  /* Semantic */
  --positive: #16a34a;
  --negative: #dc2626;
  --warning: #d97706;
  --info: #2563eb;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08);

  /* Radii */
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  /* Typography */
  --font-display: 'Poppins', system-ui, -apple-system, sans-serif;
  --font-body: 'Geist', system-ui, -apple-system, sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, monospace;
}

/* ---------- Dark Mode ---------- */
.theme-dark,
.theme-system {
  /* Only activated by JS class or media query below */
}

@media (prefers-color-scheme: dark) {
  .theme-system {
    --bg: #0c0a09;
    --surface: #1c1917;
    --surface-alt: #292524;
    --border: #44403c;
    --border-strong: #57534e;
    --text: #fafaf9;
    --text-muted: #a8a29e;
    --text-faint: #78716c;
  }
}

.theme-dark {
  --bg: #0c0a09;
  --surface: #1c1917;
  --surface-alt: #292524;
  --border: #44403c;
  --border-strong: #57534e;
  --text: #fafaf9;
  --text-muted: #a8a29e;
  --text-faint: #78716c;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ---------- Base ---------- */
html {
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg);
  letter-spacing: -0.01em;
}

/* ---------- App Shell Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

@media (max-width: 768px) {
  .app {
    grid-template-columns: 1fr;
  }
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 18px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.brand-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--brand-green);
  display: grid;
  place-items: center;
  color: white;
  font-family: var(--font-display);
  font-weight: 300;
  font-size: 17px;
  letter-spacing: -0.05em;
  flex-shrink: 0;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 16px;
  letter-spacing: -0.02em;
}

/* ---------- Navigation ---------- */
.nav-section {
  padding: 12px 8px 6px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

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

.nav-item.active {
  background: var(--surface-alt);
  color: var(--text);
  font-weight: 500;
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
}

.nav-item.active .nav-icon {
  opacity: 1;
}

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

/* ---------- Main Content ---------- */
.main {
  padding: 28px 36px;
  max-width: 1400px;
}

@media (max-width: 768px) {
  .main {
    padding: 20px;
  }
}

/* ---------- Page Header ---------- */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
}

.page-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.025em;
  margin-bottom: 4px;
}

.page-subtitle {
  font-size: 13.5px;
  color: var(--text-muted);
}

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

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover {
  border-color: var(--border-strong);
  background: var(--surface-alt);
}

.btn-primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

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

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  justify-content: center;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

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

.card-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.card-link {
  font-size: 12px;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
}

.card-link:hover {
  color: var(--text);
}

/* ---------- Stat Cards ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

@media (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color 0.15s;
}

.stat-card:hover {
  border-color: var(--border-strong);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-weight: 500;
}

.stat-value {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.1;
  margin-bottom: 6px;
}

.stat-meta {
  font-size: 11.5px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.trend-up { color: var(--positive); }
.trend-down { color: var(--negative); }
.trend-neutral { color: var(--text-muted); }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface-alt);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

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

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

tr:hover td {
  background: var(--surface-alt);
}

/* ---------- Progress Bars ---------- */
.progress {
  height: 6px;
  background: var(--surface-alt);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-bar.warn { background: var(--warning); }
.progress-bar.danger { background: var(--negative); }

/* ---------- Tags ---------- */
.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 500;
  background: var(--surface-alt);
  color: var(--text-muted);
}

.tag-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ---------- Amounts ---------- */
.amount {
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 12.5px;
}

.amount-negative { color: var(--text); }
.amount-positive { color: var(--positive); }
.amount-foreign { color: var(--text-faint); font-size: 11px; font-weight: 400; }

/* ---------- Toggle ---------- */
.toggle {
  width: 36px;
  height: 20px;
  background: var(--border-strong);
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  border: none;
}

.toggle.on {
  background: var(--accent);
}

.toggle::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.toggle.on::after {
  transform: translateX(16px);
}

/* ---------- Icon helpers ---------- */
.icon-sm { width: 14px; height: 14px; }
.icon { width: 16px; height: 16px; }

/* ---------- App Shell (Phase 0 placeholder) ---------- */
.app-shell {
  max-width: 600px;
  margin: 120px auto;
  padding: 40px;
  text-align: center;
  font-family: var(--font-body);
}

.app-shell h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 500;
  letter-spacing: -0.03em;
  margin-bottom: 12px;
  color: var(--brand-green);
}

.app-shell p {
  color: var(--text-muted);
  margin-bottom: 8px;
}

.app-shell a {
  color: var(--accent);
  text-decoration: none;
}

.app-shell a:hover {
  text-decoration: underline;
}

/* ---------- Household Switcher ---------- */
.household-switcher {
  margin-top: auto;
  padding: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.12s;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.household-switcher:hover {
  background: var(--border);
}

/* ---------- Dashboard Grid ---------- */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

@media (max-width: 1100px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- Animation ---------- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fadeIn 0.2s ease;
}
