/* ═══════════════════════════════════════════════════════════════════
   DonorGraph — Shared Theme
   Forest + Cream color scheme
   Mobile-first, no build step required
   ═══════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Lora:wght@400;500;600&family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── CSS Variables ─────────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg:       #F8F6F0;
  --bg2:      #EEEBE2;
  --surface:  #FFFFFF;
  --surface2: #F4F1EA;

  /* Text */
  --ink:  #1A2518;
  --ink2: #3D4F3A;
  --ink3: #7A8C76;

  /* Primary — Forest Green */
  --accent:    #2C5F2E;
  --accent2:   #4A8A4C;
  --accent-bg: #EBF4EB;
  --accent-bd: rgba(44,95,46,0.25);

  /* Secondary — Warm Sage */
  --sage:    #4A7C59;
  --sage-bg: #E8F4EE;
  --sage-bd: rgba(74,124,89,0.25);

  /* Amber — warnings, political */
  --amber:    #8B6914;
  --amber-bg: #FBF4E0;
  --amber-bd: rgba(139,105,20,0.25);

  /* Danger */
  --danger:    #C0392B;
  --danger-bg: #FEF0EE;
  --danger-bd: rgba(192,57,43,0.2);

  /* Borders */
  --border:  #D8D4C8;
  --border2: #E8E4DA;

  /* Shadows */
  --sh:    0 1px 3px rgba(26,37,24,0.06), 0 1px 2px rgba(26,37,24,0.04);
  --sh-md: 0 4px 12px rgba(26,37,24,0.08), 0 2px 4px rgba(26,37,24,0.04);
  --sh-lg: 0 8px 32px rgba(26,37,24,0.12), 0 4px 12px rgba(26,37,24,0.06);

  /* Layout */
  --sidebar-w: 220px;
  --topbar-h:  56px;
  --bottom-nav-h: 60px;
}

/* ── Reset ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: 'DM Sans', sans-serif; }
input, select, textarea { font-family: 'DM Sans', sans-serif; }
img { max-width: 100%; }

/* ── Layout shell ───────────────────────────────────────────────── */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  min-height: 100vh;
}

/* ── Topbar ─────────────────────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--topbar-h);
}
.logo { display: flex; align-items: center; gap: 8px; }
.logo-icon {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.logo-name {
  font-family: 'Lora', serif;
  font-size: 17px; font-weight: 600;
  color: var(--ink); letter-spacing: -0.3px;
}
.logo-badge {
  font-size: 9px;
  background: var(--accent-bg); color: var(--accent);
  padding: 2px 7px; border-radius: 10px;
  font-weight: 600; border: 1px solid var(--accent-bd);
}
.topbar-search {
  flex: 1; max-width: 360px; position: relative;
}
.topbar-search svg {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%); color: var(--ink3);
  pointer-events: none;
}
.topbar-search input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; color: var(--ink);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.topbar-search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(44,95,46,0.12);
}
.topbar-search input::placeholder { color: var(--ink3); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.t-icon-btn {
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: transparent;
  display: flex; align-items: center; justify-content: center;
  position: relative; transition: background .15s;
}
.t-icon-btn:hover { background: var(--bg2); }
.notif-dot {
  position: absolute; top: 6px; right: 6px;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); border: 1.5px solid white;
}
.user-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 10px 5px 5px;
  border: 1px solid var(--border); border-radius: 8px;
}
.user-av {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: var(--accent);
}
.user-pill-name { font-size: 12px; color: var(--ink2); font-weight: 500; }
.ham-btn {
  display: none; background: none; border: none;
  padding: 6px; color: var(--ink2);
  align-items: center; justify-content: center;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 10px;
  display: flex; flex-direction: column;
  gap: 2px; overflow-y: auto;
}
.nav-section {
  font-size: 10px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink3); padding: 10px 10px 4px;
  margin-top: 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 8px;
  font-size: 13px; color: var(--ink2);
  transition: all .12s; border: none; background: none;
  width: 100%; text-align: left; text-decoration: none;
}
.nav-item:hover { background: var(--bg2); color: var(--ink); }
.nav-item.active {
  background: var(--accent-bg);
  color: var(--accent); font-weight: 600;
}
.nav-item svg { width: 15px; height: 15px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--accent-bg); color: var(--accent);
  font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 10px;
}
.sidebar-footer {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.usage-card {
  background: var(--bg); border-radius: 8px;
  padding: 10px 12px; margin-top: 6px;
}
.usage-label {
  font-size: 10px; color: var(--ink3);
  text-transform: uppercase; letter-spacing: .05em;
  margin-bottom: 5px;
}
.usage-bar {
  height: 4px; background: var(--border);
  border-radius: 2px; overflow: hidden; margin-bottom: 4px;
}
.usage-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  border-radius: 2px;
}
.usage-text {
  font-size: 10px; color: var(--ink3);
  display: flex; justify-content: space-between;
}

/* ── Main content ────────────────────────────────────────────────── */
.main {
  overflow-y: auto;
  padding: 22px;
  background: var(--bg);
  min-width: 0;
}

/* ── Sidebar overlay (mobile) ────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(26,37,24,0.5);
  z-index: 149;
}
.sidebar-overlay.show { display: block; }

/* ── Bottom navigation (mobile only) ────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 0 4px;
}
.bottom-nav-items {
  display: flex; align-items: stretch;
  height: 100%;
}
.bnav-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; border: none; background: none;
  color: var(--ink3); font-size: 10px;
  text-decoration: none; padding: 4px 2px;
  transition: color .15s;
}
.bnav-item svg { width: 20px; height: 20px; }
.bnav-item.active { color: var(--accent); font-weight: 600; }
.bnav-item:hover { color: var(--accent); }

/* ── Page headers ────────────────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  margin-bottom: 18px;
}
.page-title {
  font-family: 'Lora', serif;
  font-size: 22px; font-weight: 600;
  color: var(--ink); letter-spacing: -0.3px;
}
.page-sub { font-size: 13px; color: var(--ink3); margin-top: 3px; }

/* ── Cards ───────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--sh);
}
.card-header {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border2);
  display: flex; align-items: center;
  justify-content: space-between;
  flex-wrap: wrap; gap: 8px;
}
.card-title { font-size: 13px; font-weight: 600; color: var(--ink); }
.card-body { padding: 18px; }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center;
  gap: 6px; padding: 9px 16px;
  border-radius: 8px; font-size: 13px;
  font-weight: 600; border: none;
  white-space: nowrap; transition: all .15s;
  font-family: 'DM Sans', sans-serif;
}
.btn svg { width: 13px; height: 13px; }
.btn-primary {
  background: var(--accent); color: white;
}
.btn-primary:hover { background: #1E4420; }
.btn-ghost {
  background: var(--surface); color: var(--ink2);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg2); }
.btn-danger {
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid var(--danger-bd);
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ── Form elements ───────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field-label {
  display: block;
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink2); margin-bottom: 5px;
}
.field-input, .field-select, .field-textarea {
  width: 100%; padding: 10px 12px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 13px;
  color: var(--ink); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field-input:focus, .field-select:focus, .field-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(44,95,46,0.12);
}
.field-input::placeholder, .field-textarea::placeholder { color: var(--ink3); }
.field-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%237A8C76' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.field-textarea { resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { font-size: 11px; color: var(--ink3); margin-top: 4px; }

/* ── Pills / badges ──────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center;
  padding: 2px 7px; border-radius: 10px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
}
.pill-green  { background: var(--accent-bg); color: var(--accent);  border: 1px solid var(--accent-bd); }
.pill-sage   { background: var(--sage-bg);   color: var(--sage);    border: 1px solid var(--sage-bd); }
.pill-amber  { background: var(--amber-bg);  color: var(--amber);   border: 1px solid var(--amber-bd); }
.pill-slate  { background: var(--bg2);       color: var(--ink3);    border: 1px solid var(--border); }
.pill-danger { background: var(--danger-bg); color: var(--danger);  border: 1px solid var(--danger-bd); }

/* ── Score badge ─────────────────────────────────────────────────── */
.score-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.score-hi { background: var(--accent-bg); color: var(--accent); border: 1.5px solid var(--accent-bd); }
.score-md { background: var(--amber-bg);  color: var(--amber);  border: 1.5px solid var(--amber-bd); }
.score-lo { background: var(--bg2);       color: var(--ink3);   border: 1.5px solid var(--border); }

/* ── Stats grid ──────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px; margin-bottom: 18px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
  box-shadow: var(--sh);
}
.stat-top {
  display: flex; align-items: flex-start;
  justify-content: space-between; margin-bottom: 8px;
}
.stat-label {
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink3);
}
.stat-icon {
  width: 28px; height: 28px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
}
.stat-value {
  font-family: 'Lora', serif;
  font-size: 22px; font-weight: 600;
  color: var(--ink); line-height: 1;
}
.stat-delta { font-size: 11px; color: var(--sage); margin-top: 4px; }
.stat-neutral { color: var(--ink3) !important; }

/* ── Table ───────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  padding: 9px 14px;
  text-align: left;
  font-size: 10px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink3); border-bottom: 1px solid var(--border);
  background: var(--bg); white-space: nowrap;
}
.data-table td {
  padding: 11px 14px; font-size: 13px;
  border-bottom: 1px solid var(--border2);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #F4F1EA; }
.data-table tr.selected td { background: var(--accent-bg); }

/* ── Wealth bar ──────────────────────────────────────────────────── */
.wbar {
  height: 3px; background: var(--border);
  border-radius: 2px; margin-top: 4px; overflow: hidden;
}
.wbar-fill {
  height: 100%; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
}

/* ── Toggle switch ───────────────────────────────────────────────── */
.toggle {
  width: 38px; height: 22px;
  background: var(--border); border-radius: 11px;
  position: relative; cursor: pointer;
  transition: background .2s; flex-shrink: 0;
}
.toggle.on { background: var(--accent); }
.toggle-thumb {
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%;
  background: white; transition: left .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.toggle.on .toggle-thumb { left: 19px; }
.toggle-row {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border2);
}
.toggle-row:last-child { border-bottom: none; padding-bottom: 0; }
.toggle-info .toggle-title { font-size: 13px; font-weight: 500; color: var(--ink); }
.toggle-info .toggle-sub { font-size: 12px; color: var(--ink3); margin-top: 2px; }

/* ── Skeleton loaders ────────────────────────────────────────────── */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
.skeleton {
  background: linear-gradient(90deg, var(--bg2) 25%, var(--bg) 50%, var(--bg2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}
.skel-line { height: 14px; margin-bottom: 8px; }
.skel-title { height: 20px; width: 60%; margin-bottom: 12px; }
.skel-stat { height: 70px; border-radius: 10px; }

/* ── Empty state ─────────────────────────────────────────────────── */
.empty-state {
  padding: 48px 20px; text-align: center;
}
.empty-icon {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--bg2);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
}
.empty-title { font-size: 15px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.empty-sub { font-size: 13px; color: var(--ink3); }

/* ── Toast ───────────────────────────────────────────────────────── */
#dg-toast {
  position: fixed; bottom: 80px; right: 20px;
  background: var(--ink); color: white;
  padding: 12px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 500;
  z-index: 999; max-width: 320px;
  transform: translateY(80px); opacity: 0;
  transition: all .3s ease;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--sh-lg);
}
#dg-toast.show { transform: translateY(0); opacity: 1; }
#dg-toast.success { border-left: 3px solid var(--accent2); }
#dg-toast.error   { border-left: 3px solid var(--danger); }
#dg-toast.info    { border-left: 3px solid var(--amber); }

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

@media (max-width: 768px) {
  /* Single column layout */
  .shell { grid-template-columns: 1fr; }

  /* Sidebar becomes drawer */
  .sidebar {
    position: fixed;
    left: -250px; top: 0; bottom: 0;
    width: 240px; z-index: 150;
    transition: left .25s ease;
    padding-top: calc(var(--topbar-h) + 10px);
  }
  .sidebar.open {
    left: 0;
    box-shadow: 4px 0 24px rgba(26,37,24,0.18);
  }

  /* Show hamburger */
  .ham-btn { display: flex; }

  /* Hide search bar */
  .topbar-search { display: none; }

  /* Hide desktop user pill label */
  .user-pill-name { display: none; }

  /* Main padding */
  .main {
    padding: 14px;
    padding-bottom: calc(var(--bottom-nav-h) + 14px);
  }

  /* Show bottom nav */
  .bottom-nav { display: block; }

  /* Page title */
  .page-title { font-size: 19px; }

  /* Stats 2x2 */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Hide less important table columns */
  .hide-mobile { display: none !important; }

  /* Field rows become single column */
  .field-row { grid-template-columns: 1fr; }

  /* Topbar */
  .topbar { padding: 0 12px; gap: 8px; }

  /* Logo min width */
  .logo-minw { min-width: auto !important; }
}

@media (max-width: 480px) {
  .main { padding: 10px; padding-bottom: calc(var(--bottom-nav-h) + 10px); }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 19px; }
  #dg-toast { bottom: 70px; right: 10px; left: 10px; }
}
