/* =========================================================
   Waste e-Bank Theme — Light Green
   UI/UX pass: responsive, accessible, motion-safe
   ========================================================= */

:root {
  --wb-green-50:  #f0fdf4;
  --wb-green-100: #dcfce7;
  --wb-green-200: #bbf7d0;
  --wb-green-300: #86efac;
  --wb-green-400: #4ade80;
  --wb-green-500: #22c55e;
  --wb-green-600: #16a34a;
  --wb-green-700: #15803d;
  --wb-green-800: #166534;

  --wb-amber: #f59e0b;
  --wb-amber-light: #fbbf24;
  --wb-red: #dc2626;
  --wb-blue: #2563eb;
  --wb-indigo: #6366f1;
  --wb-yellow: #eab308;

  --bg-page: #f5f6f5;
  --bg-card: #ffffff;
  --bg-card-hover: #fafafa;
  --bg-hero-from: #16a34a;
  --bg-hero-to: #15803d;

  --text-primary: #14532d;
  --text-secondary: #166534;
  --text-muted: #4b5563;          /* bumped from #6b7280 → 4.5:1 on white */
  --text-on-hero: #ffffff;

  --border: #e5e7eb;
  --border-strong: #86efac;

  --badge-active-bg: #dcfce7;
  --badge-active-text: #166534;
  --badge-closed-bg: #fee2e2;
  --badge-closed-text: #991b1b;

  --sidebar-w: 240px;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e5e7eb;

  --r-sm: 0.5rem;
  --r-md: 0.75rem;
  --r-lg: 1rem;
  --r-xl: 1.25rem;
  --r-2xl: 1.5rem;

  --shadow-sm: 0 1px 2px rgba(22, 101, 52, 0.04);
  --shadow-md: 0 4px 12px rgba(22, 101, 52, 0.08);
  --shadow-lg: 0 8px 24px rgba(22, 101, 52, 0.10);

  /* safe-area for iOS notches */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding: 0;
  font-family: 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}
button { font-family: inherit; }
img, svg { max-width: 100%; display: block; }
a { color: var(--wb-green-700); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: 'JetBrains Mono', ui-monospace, 'SF Mono', monospace; }

/* ── Accessibility ── */
:focus-visible {
  outline: 2px solid var(--wb-green-600);
  outline-offset: 2px;
  border-radius: 4px;
}
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

/* =========================================================
   Layout
   ========================================================= */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  z-index: 50;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
  padding: 0 8px;
}
.sidebar-brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--wb-green-500), var(--wb-green-700));
  display: flex; align-items: center; justify-content: center;
  color: white; flex-shrink: 0;
}
.sidebar-brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sidebar-brand-text strong { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.sidebar-brand-text small { font-size: 11px; color: var(--text-muted); }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; }

.sidebar-section {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  padding: 12px 12px 6px;
  font-weight: 700;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 40px;
  padding: 8px 12px;
  border-radius: var(--r-md);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  text-align: left;
  width: 100%;
}
.sidebar-link:hover {
  background: var(--wb-green-50);
  color: var(--text-primary);
  text-decoration: none;
}
.sidebar-link.active {
  background: var(--wb-green-100);
  color: var(--text-primary);
  font-weight: 600;
  border-color: var(--wb-green-300);
}
.sidebar-link svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  margin-top: 24px;
  padding: 12px;
  border-top: 1px solid var(--sidebar-border);
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Main ── */
.main { min-width: 0; display: flex; flex-direction: column; }

/* ── Topbar ── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: white;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-left {
  display: flex; align-items: center; gap: 12px;
  min-width: 0; flex: 1;
}
.topbar-left > div { min-width: 0; }
.topbar-title {
  font-size: 16px; font-weight: 700; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-subtitle {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-right {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.menu-toggle {
  display: none;
  width: 40px; height: 40px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  color: var(--text-secondary);
  align-items: center; justify-content: center;
}
.menu-toggle:hover { background: var(--wb-green-50); }

/* ── Content ── */
.content {
  padding: 24px;
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
}

/* =========================================================
   Pages (single-page nav)
   ========================================================= */
.page { display: none; }
.page.active { display: block; animation: fade-in 0.18s ease-out; }
@keyframes fade-in { from { opacity: 0; transform: translateY(2px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  .page.active, .sidebar-link, .btn, .stat-card, .tutor-card, .article-row, .sidebar { animation: none !important; transition: none !important; }
}

/* =========================================================
   Components
   ========================================================= */

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

.card-hero {
  background: linear-gradient(135deg, var(--bg-hero-from) 0%, var(--bg-hero-to) 100%);
  color: var(--text-on-hero);
  border: none;
  border-radius: var(--r-xl);
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  position: relative;
}
.card-hero-icon {
  width: 56px; height: 56px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--r-lg);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  backdrop-filter: blur(8px);
}
.card-hero h2 { margin: 0 0 4px; font-size: 20px; font-weight: 700; }
.card-hero p { margin: 0; font-size: 13px; opacity: 0.92; }
.card-hero-art {
  margin-left: auto;
  font-size: 64px;
  opacity: 0.22;
  pointer-events: none;
  user-select: none;
  flex-shrink: 0;
  line-height: 1;
}

/* Stat card */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  min-width: 0;
}
.stat-card:hover {
  border-color: var(--wb-green-400);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.stat-card-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
.stat-card-icon {
  width: 32px; height: 32px;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.stat-card-name {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.stat-card-count {
  font-size: 22px; font-weight: 800;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1;
  margin: 4px 0 2px;
}
.stat-card-conf {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10px; color: var(--text-muted);
  gap: 4px;
}
.stat-card-conf strong { font-family: 'JetBrains Mono', monospace; font-size: 11px; }
.conf-bar { height: 4px; background: var(--wb-green-100); border-radius: 999px; overflow: hidden; }
.conf-bar-fill { height: 100%; border-radius: 999px; transition: width 0.3s ease; }

/* Color variants */
.cv-cardboard .stat-card-icon { background: #fef3c7; color: #b45309; }
.cv-cardboard .stat-card-name,
.cv-cardboard .stat-card-count,
.cv-cardboard .stat-card-conf strong { color: #b45309; }
.cv-cardboard .conf-bar-fill { background: #f59e0b; }

.cv-metal .stat-card-icon { background: #e0e7ff; color: #4338ca; }
.cv-metal .stat-card-name,
.cv-metal .stat-card-count,
.cv-metal .stat-card-conf strong { color: #4338ca; }
.cv-metal .conf-bar-fill { background: #6366f1; }

.cv-paper .stat-card-icon { background: #d1fae5; color: #047857; }
.cv-paper .stat-card-name,
.cv-paper .stat-card-count,
.cv-paper .stat-card-conf strong { color: #047857; }
.cv-paper .conf-bar-fill { background: #10b981; }

.cv-plastic .stat-card-icon { background: #fee2e2; color: #b91c1c; }
.cv-plastic .stat-card-name,
.cv-plastic .stat-card-count,
.cv-plastic .stat-card-conf strong { color: #b91c1c; }
.cv-plastic .conf-bar-fill { background: #dc2626; }

.cv-cap .stat-card-icon { background: #f3f4f6; color: #4b5563; }
.cv-cap .stat-card-name,
.cv-cap .stat-card-count,
.cv-cap .stat-card-conf strong { color: #4b5563; }
.cv-cap .conf-bar-fill { background: #6b7280; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 8px 14px;
  border-radius: var(--r-md);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
  border: 1px solid transparent;
  background: white;
  color: var(--text-secondary);
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--wb-green-600); color: white; }
.btn-primary:hover { background: var(--wb-green-700); }
.btn-outline { background: white; border-color: var(--wb-green-300); color: var(--wb-green-700); }
.btn-outline:hover { background: var(--wb-green-50); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--wb-green-50); }
.btn-icon { width: 40px; height: 40px; padding: 0; min-height: 0; }
.btn-block { width: 100%; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.badge-active { background: var(--badge-active-bg); color: var(--badge-active-text); border: 1px solid var(--wb-green-300); }
.badge-closed { background: var(--badge-closed-bg); color: var(--badge-closed-text); }
.badge-live { background: var(--wb-green-100); color: var(--wb-green-800); border: 1px solid var(--wb-green-300); }
.badge-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--wb-green-500);
  animation: pulse 1.4s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* Utility */
.hidden { display: none !important; }

/* ── Camera ── */
.cam-frame {
  position: relative;
  background: #0b1220;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  overflow: hidden;
  aspect-ratio: 16/9;
  width: 100%;
}
.cam-frame img {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
}
.cam-overlay { position: absolute; pointer-events: none; }
.cam-overlay.tr { top: 8px; right: 12px; }
.cam-overlay.bl { bottom: 8px; left: 12px; }
.cam-overlay.tl { top: 8px; left: 12px; }
.cam-overlay .mono {
  font-size: 10px;
  color: rgba(34, 197, 94, 0.75);
  letter-spacing: 0.04em;
  background: rgba(11, 18, 32, 0.55);
  padding: 2px 6px;
  border-radius: 4px;
}

/* ── Grids ── */
.grid-stats {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}
.grid-info {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.grid-tutor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

/* ── Tutor card ── */
.tutor-card {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 14px 16px;
  background: var(--wb-green-50);
  border: 1px solid var(--wb-green-200);
  border-radius: var(--r-lg);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
}
.tutor-card:hover {
  background: var(--wb-green-100);
  border-color: var(--wb-green-400);
  text-decoration: none;
}
.tutor-card-icon {
  width: 38px; height: 38px;
  background: white;
  border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  color: var(--wb-green-700);
}
.tutor-card-name {
  flex: 1;
  font-weight: 600;
  color: var(--text-primary);
  font-size: 13px;
  min-width: 0;
}
.tutor-card-arrow {
  color: var(--wb-green-700);
  font-size: 18px;
  line-height: 1;
  flex-shrink: 0;
}

/* ── Quote / ayat ── */
.quote-card {
  background: linear-gradient(180deg, var(--wb-green-50), white);
  border: 1px solid var(--wb-green-200);
  border-radius: var(--r-xl);
  padding: 28px 24px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.quote-arabic {
  font-size: 22px;
  font-family: 'Amiri', 'Traditional Arabic', 'Scheherazade New', serif;
  color: var(--text-primary);
  line-height: 2;
  margin-bottom: 14px;
  direction: rtl;
  word-spacing: 4px;
}
.quote-translation {
  color: var(--text-secondary);
  font-size: 13px;
  font-style: italic;
  max-width: 560px;
  margin: 0 auto 8px;
}
.quote-ref {
  color: var(--wb-green-700);
  font-size: 11px;
  font-weight: 600;
}
.quote-leaves {
  position: absolute;
  right: 14px; bottom: 4px;
  font-size: 48px;
  opacity: 0.15;
  pointer-events: none;
}

/* ── Command list ── */
.command-list { display: flex; flex-direction: column; gap: 8px; }
.command-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 12px 14px;
  background: white;
  border: 1px solid var(--wb-green-200);
  border-radius: var(--r-lg);
}
.command-num {
  width: 24px; height: 24px;
  background: var(--wb-green-600);
  color: white;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.command-text {
  flex: 1;
  font-size: 13px;
  color: var(--text-primary);
  min-width: 0;
}
.command-check { color: var(--wb-green-600); font-size: 16px; flex-shrink: 0; }

/* ── Section heading ── */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.section-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.link-action {
  font-size: 12px;
  color: var(--wb-green-700);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ── Article list ── */
.article-row {
  display: flex;
  align-items: center;
  gap: 16px;
  min-height: 80px;
  padding: 12px;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  margin-bottom: 10px;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
  color: inherit;
  text-decoration: none;
}
.article-row:hover {
  border-color: var(--wb-green-400);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}
.article-thumb {
  width: 72px; height: 72px;
  border-radius: var(--r-md);
  flex-shrink: 0;
  background: var(--wb-green-100);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
}
.article-content { flex: 1; min-width: 0; }
.article-title {
  font-size: 14px; font-weight: 700;
  color: var(--text-primary);
  margin: 0 0 4px;
  line-height: 1.35;
}
.article-excerpt {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.article-arrow {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--wb-green-100);
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--wb-green-700);
  flex-shrink: 0;
  font-size: 18px;
}

/* ── Object detail panel ── */
.detail-row {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px;
  min-width: 0;
}
.detail-icon {
  width: 56px; height: 56px;
  border-radius: var(--r-md);
  background: var(--wb-green-100);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}
.detail-name { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.detail-id { font-size: 11px; color: var(--text-muted); font-family: 'JetBrains Mono', monospace; }
.detail-tag {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600;
  color: var(--wb-green-700);
  margin-top: 4px;
}
.detail-tag::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--wb-green-600);
  flex-shrink: 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.detail-tile {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: white;
  min-width: 0;
}
.detail-tile-label { font-size: 11px; color: var(--text-muted); margin-bottom: 2px; }
.detail-tile-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  font-family: 'JetBrains Mono', monospace;
  word-break: break-word;
}
.detail-tile.span-2 { grid-column: 1 / -1; }
.detail-tile-value.bin {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 13px;
}
.detail-desc {
  padding: 12px;
  background: var(--wb-green-50);
  border: 1px solid var(--wb-green-200);
  border-radius: var(--r-md);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.55;
}

/* Distribution donut */
.dist-wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.dist-list { flex: 1; min-width: 140px; display: flex; flex-direction: column; gap: 10px; }
.donut { width: 110px; height: 110px; flex-shrink: 0; }
.donut-center { font-size: 14px; font-weight: 700; fill: var(--text-primary); font-family: 'JetBrains Mono', monospace; }

.dist-item {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px;
  gap: 8px;
  min-width: 0;
}
.dist-label {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-secondary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dist-dot { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.dist-pct { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 12px; flex-shrink: 0; }

/* ── Total berat big card ── */
.total-weight-card {
  background: linear-gradient(135deg, var(--wb-green-50), white);
  border: 1px solid var(--wb-green-200);
  border-radius: var(--r-xl);
  padding: 18px 22px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.total-weight-icon {
  width: 56px; height: 56px;
  background: white;
  border: 1px solid var(--wb-green-200);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px;
  color: var(--wb-green-700);
  flex-shrink: 0;
}
.total-weight-label { font-size: 12px; color: var(--text-muted); }
.total-weight-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--wb-green-700);
  font-family: 'JetBrains Mono', monospace;
  line-height: 1;
  margin-top: 4px;
}
.total-weight-leaves {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 60px;
  opacity: 0.15;
  pointer-events: none;
}

/* Log entries */
.log-entry {
  padding: 8px 10px;
  border-radius: var(--r-sm);
  font-size: 11px;
  background: var(--wb-green-50);
  border: 1px solid var(--wb-green-100);
  font-family: 'JetBrains Mono', monospace;
  color: var(--text-secondary);
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.log-empty {
  text-align: center;
  padding: 20px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ── Chart card ── */
.chart-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 18px;
}
.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.chart-toolbar > div { min-width: 0; }
.chart-title { font-size: 16px; font-weight: 700; color: var(--text-primary); margin: 0 0 2px; }
.chart-subtitle { font-size: 12px; color: var(--text-muted); margin: 0; }
.chart-svg { width: 100%; height: 280px; display: block; }
.chart-container { position: relative; }
.chart-tooltip {
  position: absolute;
  background: var(--wb-green-700);
  color: white;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  font-size: 12px;
  font-weight: 700;
  font-family: 'JetBrains Mono', monospace;
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50%, calc(-100% - 8px));
  box-shadow: var(--shadow-md);
  z-index: 5;
}
.chart-tooltip::after {
  content: '';
  position: absolute;
  bottom: -5px; left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--wb-green-700);
  border-bottom: 0;
}
.chart-cta { display: flex; justify-content: center; margin-top: 12px; }

/* ── Article page ── */
.article-page {
  max-width: 760px;
  margin: 0 auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: 32px;
  overflow: hidden;
}
.article-page-hero {
  margin: -32px -32px 24px;
  height: 220px;
  background: linear-gradient(135deg, var(--wb-green-400), var(--wb-green-700));
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 80px;
  color: white;
  opacity: 0.95;
}
.article-page h1 {
  font-size: 26px;
  font-weight: 800;
  margin: 0 0 8px;
  color: var(--text-primary);
  line-height: 1.25;
}
.article-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.article-body {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text-secondary);
}
.article-body h2 {
  font-size: 18px;
  color: var(--text-primary);
  margin: 24px 0 8px;
}
.article-body p { margin: 0 0 14px; }
.article-body ul { padding-left: 22px; margin: 0 0 14px; }
.article-body li { margin-bottom: 6px; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--wb-green-700);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
  cursor: pointer;
  min-height: 32px;
}

/* ── Modals ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 83, 45, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
  animation: fade-in 0.15s ease-out;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: white;
  border-radius: var(--r-xl);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
  gap: 12px;
}
.modal-close {
  width: 36px; height: 36px;
  background: none;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  border-radius: var(--r-sm);
  flex-shrink: 0;
}
.modal-close:hover { background: var(--wb-green-50); color: var(--text-primary); }

/* Toast notification */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--wb-green-700);
  color: white;
  padding: 12px 18px;
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.error {
  background: #dc2626;
}
.toast-icon {
  width: 20px; height: 20px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

/* spinner for loading buttons */
.spinner {
  display: inline-block;
  width: 12px; height: 12px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
button:disabled { opacity: 0.65; cursor: not-allowed; }

/* inputs */
input[type="number"].btn,
select.btn {
  font-family: 'JetBrains Mono', monospace;
}

/* numeric input used in BS32 modal — width adjusts to container */
.modal-input {
  width: clamp(80px, 30%, 130px);
  min-height: 36px;
  padding: 6px 10px;
  border: 1px solid var(--wb-green-300);
  background: white;
  color: var(--text-primary);
  border-radius: var(--r-md);
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  text-align: right;
}
.modal-input:focus {
  outline: 2px solid var(--wb-green-600);
  outline-offset: 1px;
  border-color: var(--wb-green-600);
}
select.btn { appearance: none; -webkit-appearance: none; padding-right: 32px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2315803d' stroke-width='2.5'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select.btn option { background: white; color: var(--text-primary); }

/* utility */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.w-full { width: 100%; }

/* Dashboard 2-column grid with proper responsive collapse */
.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

/* Sidebar scrim */
.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(20, 83, 45, 0.4);
  z-index: 45;
  animation: fade-in 0.18s ease-out;
}
.sidebar-scrim.show { display: block; }

/* =========================================================
   Breakpoints
   ========================================================= */

/* ── ≤ 1180px: stat grid 3-cols, dashboard still 2-col but tighter ── */
@media (max-width: 1180px) {
  .grid-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ── ≤ 1024px: dashboard collapses to single column, sidebar still visible ── */
@media (max-width: 1024px) {
  .dashboard-grid { grid-template-columns: minmax(0, 1fr); }
  .grid-stats { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* ── ≤ 860px: sidebar becomes drawer, topbar collapses ── */
@media (max-width: 860px) {
  :root { --sidebar-w: 0px; }

  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  .menu-toggle { display: inline-flex; }

  .topbar { padding: 10px 16px; }
  .topbar-title { font-size: 15px; }
  .topbar-subtitle { display: none; }

  .content { padding: 16px; }

  .grid-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-info { grid-template-columns: 1fr; }
  .grid-tutor { grid-template-columns: 1fr; }

  /* Donut + list side-by-side stays, but smaller donut */
  .donut { width: 96px; height: 96px; }

  /* Histori select shrinks */
  #histori-range { padding: 6px 28px 6px 10px; }

  /* Modal adjustments */
  .modal { padding: 20px; }
  .modal-head > div { min-width: 0; }
}

/* ── ≤ 640px: stats 2-cols, topbar more compact, hero font shrinks ── */
@media (max-width: 640px) {
  .grid-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  .topbar-title { font-size: 14px; }

  .card-hero { padding: 16px; gap: 14px; }
  .card-hero-icon { width: 44px; height: 44px; }
  .card-hero h2 { font-size: 16px; }
  .card-hero p { font-size: 12px; }
  .card-hero-art { font-size: 40px; }

  .quote-card { padding: 22px 16px; }
  .quote-arabic { font-size: 18px; line-height: 1.9; }
  .quote-translation { font-size: 12px; }

  /* Topbar: collapse buttons to icon-only */
  .topbar-right .btn-text { display: none; }
  .btn-icon-only { padding: 0; width: 40px; height: 40px; min-height: 0; }
  #clock { display: none; }

  /* Article card compact */
  .article-row { gap: 12px; padding: 10px; }
  .article-thumb { width: 56px; height: 56px; font-size: 22px; }
  .article-arrow { width: 32px; height: 32px; font-size: 16px; }

  /* Article page */
  .article-page { padding: 20px; }
  .article-page-hero { margin: -20px -20px 20px; height: 160px; font-size: 56px; border-radius: var(--r-xl) var(--r-xl) 0 0; }
  .article-page h1 { font-size: 22px; }
  .article-body { font-size: 14px; }

  .total-weight-value { font-size: 22px; }
  .total-weight-icon { width: 48px; height: 48px; font-size: 22px; }

  /* Histori chart height */
  .chart-svg { height: 220px; }
}

/* ── ≤ 380px: very narrow phones ── */
@media (max-width: 380px) {
  .content { padding: 12px; }
  .card { padding: 12px; }
  .stat-card { padding: 10px; }
  .stat-card-count { font-size: 18px; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-tile.span-2 { grid-column: 1; }
  .dist-wrap { flex-direction: column; align-items: flex-start; }
  .donut { align-self: center; }
}

/* Page-head for static article page */
.article-page-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 18px;
}
.article-page-head .article-page-icon {
  font-size: 26px;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--wb-green-50);
  border: 1px solid var(--border);
  border-radius: 12px;
  flex-shrink: 0;
}
.article-page-head h2 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  color: var(--wb-green-700);
}
