/* ==========================================================================
   FoodBridge Amsterdam — shared design system
   Sections: reset, tokens, nav, buttons, homepage, dashboard, components
   ========================================================================== */

:root {
  --green-900: #123321;
  --green-700: #1f6b3f;
  --green-600: #2a8a52;
  --green-100: #e7f4ea;
  --blue-600: #2f6feb;
  --purple-600: #8a4fd1;
  --amber-600: #d1874f;
  --earth-600: #7a6a52;
  --ink: #17201b;
  --muted: #62705f;
  --bg: #f7f8f5;
  --card: #ffffff;
  --border: #e1e6dd;
  --danger: #c94b3f;
  --radius: 14px;
  --shadow-sm: 0 1px 2px rgba(18, 51, 33, 0.06);
  --shadow-md: 0 6px 20px rgba(18, 51, 33, 0.08);
  --font-body: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "Poppins", "Inter", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}
h1, h2, h3 { font-family: var(--font-head); line-height: 1.2; margin: 0 0 10px; }
p { margin: 0 0 12px; color: var(--muted); }
a { color: var(--green-700); }
img, svg { max-width: 100%; }

/* ---------- Nav ---------- */
.site-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 32px;
  background: rgba(247, 248, 245, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.site-nav .brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--ink);
  text-decoration: none;
}
.site-nav .brand .logo-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--green-600), var(--blue-600));
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.site-nav .nav-links { display: flex; gap: 22px; align-items: center; }
.site-nav .nav-links a {
  text-decoration: none;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.92rem;
}
.site-nav .nav-links a.active, .site-nav .nav-links a:hover { color: var(--green-700); }
.site-nav .nav-cta {
  background: var(--green-700);
  color: white !important;
  padding: 8px 16px;
  border-radius: 999px;
  font-weight: 600 !important;
}
.site-nav .role-select {
  background: white;
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}
.site-nav .role-select:hover { border-color: var(--green-600); }
.site-nav .btn-nav-outline {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border);
  padding: 7px 15px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.85rem;
  text-decoration: none;
}
.site-nav .btn-nav-outline:hover { background: white; }
.site-nav .session-chip {
  font-size: 0.78rem;
  color: var(--muted);
}
.site-nav .session-chip:empty { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 10px;
  border: none;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--green-700); color: white; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--green-900); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--border); }
.btn-ghost:hover { background: white; }
.btn-secondary { background: #fbeaea; color: var(--danger); border: none; }
.btn-block { width: 100%; justify-content: center; }

/* ================================================================
   HOMEPAGE
   ================================================================ */
.hero {
  padding: 74px 32px 60px;
  text-align: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(42,138,82,0.10), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(47,111,235,0.10), transparent 45%);
}
.hero .eyebrow {
  display: inline-block;
  background: var(--green-100);
  color: var(--green-700);
  padding: 5px 14px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 18px;
}
.hero h1 {
  font-size: clamp(1.9rem, 3.6vw, 3rem);
  max-width: 900px;
  margin: 0 auto 16px;
}
.hero .lede {
  max-width: 660px;
  margin: 0 auto 28px;
  font-size: 1.08rem;
}
.hero .cta-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }

.section {
  max-width: 1080px;
  margin: 0 auto;
  padding: 56px 32px;
}
.section-head { text-align: center; max-width: 640px; margin: 0 auto 36px; }
.section-head .eyebrow {
  color: var(--green-700); font-weight: 700; font-size: 0.8rem;
  text-transform: uppercase; letter-spacing: 0.06em;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}
.stat-tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow-sm);
}
.stat-tile .num { font-size: 2rem; font-weight: 800; color: var(--green-700); font-family: var(--font-head); }
.stat-tile .cap { font-size: 0.85rem; color: var(--muted); margin-top: 6px; }
.stat-tile .src { font-size: 0.7rem; color: #9aa79a; margin-top: 10px; display: block; }
.stat-tile .src a { color: #9aa79a; }

.flow-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  position: relative;
}
.flow-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: var(--shadow-sm);
}
.flow-card .step-no {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--green-700); color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; margin-bottom: 12px;
}
.flow-card h3 { font-size: 1.02rem; }
.flow-card p { font-size: 0.88rem; margin: 0; }
.flow-card .branch-edible { color: var(--green-700); font-weight: 600; }
.flow-card .branch-inedible { color: var(--earth-600); font-weight: 600; }

.tech-badges { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.tech-badge {
  background: white;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
  display: flex; align-items: center; gap: 8px;
  box-shadow: var(--shadow-sm);
}
.tech-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-600); }
.tech-badge.stub .dot { background: #cfc6a8; }

.reg-callout {
  background: #fff8ea;
  border: 1px solid #f0dfa8;
  border-radius: var(--radius);
  padding: 20px 22px;
  font-size: 0.92rem;
  color: #5c4a12;
}
.reg-callout strong { color: #3d3009; }

.home-cta {
  text-align: center;
  background: linear-gradient(135deg, var(--green-900), var(--green-700));
  color: white;
  border-radius: 20px;
  padding: 48px 32px;
  margin: 0 32px 64px;
}
.home-cta h2 { color: white; }
.home-cta p { color: #d9ecdc; max-width: 560px; margin: 0 auto 24px; }
.home-cta .btn-primary { background: white; color: var(--green-800, var(--green-900)); }
.home-cta .btn-primary:hover { background: #eee; }

.site-footer {
  padding: 28px 32px 40px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

/* ================================================================
   DASHBOARD
   ================================================================ */
.dash-header {
  padding: 18px 32px 6px;
}
.dash-header h1 { font-size: 1.4rem; margin-bottom: 2px; }
.dash-header .sub { font-size: 0.88rem; color: var(--muted); }
.demo-tag {
  display: inline-block;
  background: #fff3d6;
  color: #8a6a1d;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.72rem;
  margin-left: 6px;
  vertical-align: middle;
}

.stats-bar { padding: 14px 32px; }
.stats-bar-meta { font-size: 0.74rem; color: #9aa79a; margin-bottom: 8px; }
.stats-bar-cards { display: flex; gap: 14px; flex-wrap: wrap; }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 20px;
  min-width: 150px;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.stat-card .stat-icon { position: absolute; top: 10px; right: 12px; font-size: 0.9rem; opacity: 0.6; display: block; }
.stat-card span:not(.stat-icon) { display: block; font-size: 1.5rem; font-weight: 800; color: var(--green-700); font-family: var(--font-head); }
.stat-card label { font-size: 0.76rem; color: var(--muted); }
.stat-trend { display: block; font-size: 0.72rem; margin-top: 3px; font-weight: 600; }
.stat-trend.up { color: var(--green-700); }
.stat-trend.down { color: var(--danger); }
.stat-trend:empty { display: none; }

.trust-banner {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin: 10px 32px 0;
  padding: 10px 16px;
  background: #fff8ea;
  border: 1px solid #f0dfa8;
  border-radius: 10px;
  font-size: 0.78rem;
  color: #5c4a12;
}
.trust-banner-text strong { color: #3d3009; margin-right: 4px; }
.trust-banner-text strong:not(:first-child) { margin-left: 10px; }
.trust-banner #dismissBannerBtn {
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: #8a6a1d;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 2px;
  line-height: 1;
}
.trust-banner #dismissBannerBtn:hover { color: #3d3009; }
.trust-banner.hidden { display: none; }

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  grid-template-rows: auto auto;
  gap: 16px;
  padding: 0 32px 32px;
}
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}
.panel h2 { margin-top: 0; font-size: 1.02rem; display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.panel h2 small { font-weight: 400; color: var(--muted); font-size: 0.75rem; }

.intake-panel { grid-row: span 2; }
.map-panel { grid-column: 2; }
.forecast-panel { grid-column: 2; }
.dashboard-panel { grid-column: 1 / -1; }

#surplusForm label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 10px;
  font-weight: 500;
}
#surplusForm label.checkbox { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; }
#surplusForm input[type="text"],
#surplusForm input[type="number"],
#surplusForm input[type="password"],
#surplusForm select {
  width: 100%;
  padding: 7px 9px;
  margin-top: 3px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.88rem;
  font-family: var(--font-body);
}
#surplusForm input.invalid { border-color: var(--danger); }
#surplusForm input.invalid:focus { outline-color: var(--danger); }
#surplusForm button[disabled] { opacity: 0.55; cursor: not-allowed; }
.required-mark { color: var(--danger); font-weight: 700; }
.field-error { display: block; color: var(--danger); font-size: 0.74rem; margin-top: 3px; font-weight: 400; }
.field-error[hidden] { display: none; }

.info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  font-size: 0.68rem;
  font-style: normal;
  cursor: help;
  margin-left: 4px;
}
.info-icon:hover, .info-icon:focus { background: var(--green-600); color: white; outline: none; }

.input-with-toggle { display: flex; gap: 6px; align-items: stretch; }
.input-with-toggle input { flex: 1; }
.input-toggle-btn {
  flex-shrink: 0;
  margin-top: 3px;
  border: 1px solid var(--border);
  background: white;
  border-radius: 7px;
  padding: 0 10px;
  cursor: pointer;
  font-size: 0.9rem;
}
.input-toggle-btn:hover { background: #f0f2ee; }
.pms-connect-row {
  display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap;
}
.pms-connect-row button {
  flex: 1;
  min-width: 130px;
  padding: 7px 8px;
  border-radius: 7px;
  border: 1px dashed var(--blue-600);
  background: #eef3fe;
  color: var(--blue-600);
  font-size: 0.76rem;
  cursor: pointer;
}

.demo-controls { display: flex; gap: 8px; margin-top: 14px; }
.demo-controls button {
  flex: 1;
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #f0f2ee;
  cursor: pointer;
  font-size: 0.8rem;
}

details.settings-panel {
  margin-top: 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 0.82rem;
  background: #fbfcfa;
}
details.settings-panel summary { cursor: pointer; font-weight: 600; color: var(--muted); }
details.settings-panel label { margin-top: 10px; }
.ai-status { font-size: 0.74rem; margin-top: 6px; }
.ai-status.on { color: var(--green-700); }
.ai-status.off { color: var(--muted); }

#map { height: 440px; border-radius: 10px; }
.legend {
  font-size: 0.82rem;
  color: var(--ink);
  margin-top: 10px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
.legend .item { display: inline-flex; align-items: center; gap: 5px; }
.facility-label {
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--ink);
  box-shadow: none !important;
}
.facility-label::before { display: none; }
.dot-sample { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.line-sample { display: inline-block; width: 18px; height: 0; border-top: 3px solid var(--green-600); vertical-align: middle; }
.line-sample.inedible { border-top-color: var(--earth-600); }
.line-sample.dashed { border-top-style: dashed; border-top-color: #999; }

.forecast-panel .note { font-size: 0.78rem; color: var(--muted); margin-top: 8px; }
.weather-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #eef3fe; color: var(--blue-600);
  border-radius: 999px; padding: 4px 12px; font-size: 0.78rem; margin-bottom: 10px;
}

.table-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.table-filters input,
.table-filters select {
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.82rem;
  font-family: var(--font-body);
  background: white;
}
.table-filters input { flex: 1; min-width: 160px; }
.table-filters .btn-secondary { padding: 6px 12px; font-size: 0.8rem; border-radius: 7px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f0f2ee; position: sticky; top: 0; font-weight: 600; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--green-700); }
th[data-sort] .sort-arrow { margin-left: 4px; color: var(--green-700); }

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
  font-size: 0.82rem;
  color: var(--muted);
}
.table-pagination button {
  padding: 5px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: white;
  cursor: pointer;
  font-size: 0.8rem;
}
.table-pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

.table-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  z-index: 200;
}
.loading-overlay.hidden { display: none; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--green-600);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
tr.row-edible td:first-child { border-left: 3px solid var(--green-600); }
tr.row-inedible td:first-child { border-left: 3px solid var(--earth-600); }
tr.record-row { cursor: pointer; }
tr.record-row:hover { background: var(--green-100); }
tr.detail-row td { background: #fbfcfa; font-size: 0.8rem; color: var(--muted); }
tr.detail-row.hidden { display: none; }
.expand-hint { color: #9aa79a; font-size: 0.72rem; }

.row-chevron {
  display: inline-block;
  margin-right: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  transition: transform 0.15s ease;
}
.row-chevron.expanded { transform: rotate(90deg); }

tr.row-highlight { animation: row-flash 2.2s ease; }
@keyframes row-flash {
  0% { background: var(--green-100); }
  70% { background: var(--green-100); }
  100% { background: transparent; }
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  letter-spacing: 0.01em;
}
.badge-edible { background: var(--green-600); }
.badge-inedible { background: var(--earth-600); }
.badge-supermarket { background: var(--blue-600); }
.badge-restaurant { background: var(--purple-600); }
.badge-hotel { background: var(--amber-600); }
.badge-ai { background: #17201b; }

/* ---------- Toasts ---------- */
#toastContainer {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 10px;
  z-index: 100;
}
.toast {
  background: var(--green-900);
  color: white;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.85rem;
  box-shadow: var(--shadow-md);
  max-width: 320px;
  animation: toast-in 0.2s ease;
}
.toast.warn { background: #7a4a12; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.facility-icon { font-size: 20px; text-align: center; }

.app-footer, .site-footer { padding-bottom: 30px; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .intake-panel { grid-row: auto; }
  .map-panel, .forecast-panel, .dashboard-panel { grid-column: 1; }
  .stat-grid, .flow-grid { grid-template-columns: 1fr; }
  .site-nav .nav-links { gap: 12px; }
}

/* Stack the processed-records table into label:value cards below 768px —
   a 7-column table has no room to be legible on a phone. Label stacked
   above value (not side-by-side flex) because cell content mixes badges,
   <br>, and bare text nodes that flex-with-space-between distributes
   unpredictably. */
@media (max-width: 768px) {
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tr.record-row {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 10px;
    padding: 10px 12px;
  }
  tr.row-edible, tr.row-inedible { border-left-width: 1px; }
  tr.row-edible td:first-child, tr.row-inedible td:first-child { border-left: none; }
  tr.record-row td {
    border-bottom: 1px dashed var(--border);
    padding: 7px 0;
  }
  tr.record-row td:last-child { border-bottom: none; }
  tr.record-row td::before {
    content: attr(data-label);
    display: block;
    font-weight: 600;
    font-size: 0.7rem;
    color: var(--muted);
    margin-bottom: 3px;
  }
  tr.detail-row td { display: block; }
}
