/*
 * /3d.html — extracted from cms/templates/3d.ejs (charter compliance: no inline <style>).
 * Loaded only on this page; classes are /3d.html-specific (.picker-stage, .list-stage,
 * .viewer-stage, .list-card, .survey-banner, .warning-banner, etc).
 */

/* Lock the page to exactly viewport height so the viewer never causes
   page scroll. agri-map base.css ships `body { min-height: 100vh }`
   which lets the body grow past the viewport — override with explicit
   100dvh (dynamic viewport, accounts for mobile address bar) +
   overflow: hidden. The header (whatever its current height — desktop,
   mobile drawer-open, email-verify banner visible) takes intrinsic
   height; .page-3d takes whatever remains. */
html { height: 100%; }
body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.site-header { flex: 0 0 auto; }
.page-3d { flex: 1 1 auto; position: relative; min-height: 0; min-width: 0; overflow: hidden; }

/* Picker stage — visible until a location is confirmed */
/* Default hidden — JS (setStage) sets el.style.display='flex' to show.
   Was inline style="display:none" before; moved here for CSP style-src-attr. */
.picker-stage {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  background: #f5f6f8;
}
.picker-intro {
  padding: var(--space-3) var(--space-4);
  background: #fff;
  border-bottom: 1px solid var(--color-border-primary);
}
.picker-intro h1 {
  margin: 0 0 var(--space-1) 0;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
}
.picker-intro p {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.picker-host {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
}

/* Viewer stage — full-bleed under the header once a location is picked */
.viewer-stage {
  position: absolute; inset: 0;
  display: none;
  background: #1a1d23;
}
.viewer-stage.is-active { display: block; }
.viewer-host { position: absolute; inset: 0; }

/* Reset button overlay (top-left, inside viewer) */
.viewer-reset {
  position: absolute;
  top: var(--space-3); left: var(--space-3);
  z-index: 10;
  padding: var(--space-2) var(--space-3);
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-sm);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.viewer-reset:hover { background: #fff; }

/* Error / setup-missing fallback */
.stage-error {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  padding: var(--space-4);
  background: #fff;
}
.stage-error.is-active { display: flex; }
.stage-error-card {
  max-width: 520px;
  padding: var(--space-4);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.stage-error-card h2 {
  margin: 0 0 var(--space-2) 0;
  font-size: var(--font-size-lg);
}
.stage-error-card p {
  margin: 0 0 var(--space-3) 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}

/* Login wall (unauthenticated) */
.login-wall {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: var(--space-4);
  background: linear-gradient(135deg, #f5f6f8 0%, #eef0f4 100%);
}
.login-wall-card {
  max-width: 480px;
  padding: var(--space-4);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-md);
  background: #fff;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.login-wall-card h2 { margin: 0 0 var(--space-2) 0; font-size: var(--font-size-lg); }
.login-wall-card p  { margin: 0 0 var(--space-3) 0; font-size: var(--font-size-sm); color: var(--color-text-secondary); }
.login-wall-card button {
  padding: var(--space-2) var(--space-4);
  background: var(--color-interactive);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  font-weight: var(--font-weight-semibold);
  cursor: pointer;
}
.login-wall-card button:hover { filter: brightness(1.05); }

/* Quota banner over the viewer (recent-claim mode) */
.quota-banner {
  position: absolute;
  top: var(--space-3); left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  max-width: 600px;
  padding: var(--space-2) var(--space-3);
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  text-align: center;
}
.quota-banner strong { color: var(--color-text-primary); }
.quota-banner a { color: var(--color-interactive); }

/* History list — replaces the recent-claim banner. Both the heading
   and the cards live in a single centered column so they share the
   same horizontal extent (no full-width banner sitting awkwardly
   above isolated centered cards). */
.list-stage {
  position: absolute; inset: 0;
  display: none;
  background: #f5f6f8;
  overflow-y: auto;
}
.list-stage.is-active { display: block; }
.list-container {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
  box-sizing: border-box;
}
.list-header {
  margin: 0 0 var(--space-4) 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.list-header h1 { margin: 0; font-size: var(--font-size-xl); font-weight: var(--font-weight-semibold); }
.list-header p  { margin: 4px 0 0 0; font-size: var(--font-size-sm); color: var(--color-text-secondary); max-width: 560px; }
.list-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-3);
  align-content: start;
}
.list-card {
  background: #fff;
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.list-card:hover { box-shadow: var(--shadow-md); border-color: var(--color-interactive); }
/* .list-card-place + .list-card-date overridden in the thumbnail
   block below — see "Card thumbnails + cleaner hierarchy". */
.list-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--space-6);
  color: var(--color-text-muted);
}

/* ── Warning banner (above the survey + tiles) ──────────────
   Heads-up box for known limitations (cadastre accuracy, first-
   render IGN download time, missing building geometry). Yellow/
   amber palette. Dismissable per session via sessionStorage —
   resets on tab close so any updated copy is seen next visit. */
.warning-banner {
  background: #fef3c7;
  border: 1px solid #fde68a;
  border-left: 3px solid #f59e0b;
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin: var(--space-9) 0 var(--space-5);
  color: #78350f;
  position: relative;
}
.warning-banner-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); margin-bottom: var(--space-2); }
.warning-banner-title { font-size: var(--font-size-md); font-weight: var(--font-weight-semibold); color: #78350f; }
.warning-banner-dismiss {
  background: none; border: 0; color: #92400e;
  font-size: 18px; line-height: 1; cursor: pointer; padding: 4px;
}
.warning-banner-dismiss:hover { color: #78350f; }
.warning-list {
  margin: 0; padding-left: var(--space-5);
  font-size: var(--font-size-sm); line-height: 1.5; color: #78350f;
}
.warning-list li { margin: 2px 0; }
.warning-list strong { color: #78350f; }
.warning-banner.is-hidden { display: none; }

/* ── Survey banner (above the tiles) ────────────────────────────
   Renders unconditionally on the list stage; client-side JS hides
   it when localStorage flag is set (after submit or dismiss).
   Submission posts to /api/3d/feedback — gracefully treats 404 as
   success until the backend route ships (PLAN-RENDER-FEEDBACK §10
   step 5; agri-map task #12). */
.survey-banner {
  background: #fff;
  border: 1px solid var(--color-border-primary);
  border-left: 3px solid var(--color-interactive);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin: 0 0 var(--space-10);
  position: relative;
}
.survey-banner-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-3); }
.survey-banner h2 { margin: 0 0 4px; font-size: var(--font-size-md); font-weight: var(--font-weight-semibold); }
.survey-banner p { margin: 0 0 var(--space-3); font-size: var(--font-size-sm); color: var(--color-text-secondary); }
.survey-banner-dismiss {
  background: none; border: 0; color: var(--color-text-muted);
  font-size: 18px; line-height: 1; cursor: pointer;
  padding: 4px; flex-shrink: 0;
}
.survey-banner-dismiss:hover { color: var(--color-text-primary); }
.survey-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: var(--space-3); }
.survey-option { display: flex; align-items: center; gap: 8px; font-size: var(--font-size-sm); cursor: pointer; }
.survey-option input[type=checkbox] { margin: 0; }
.survey-other-row {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 4px;
}
.survey-other-row label {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
}
.survey-other-text {
  width: 100%; padding: 6px 8px;
  border: 1px solid var(--color-border-primary);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: var(--font-size-sm);
  line-height: 1.4;
  color: inherit;
  box-sizing: border-box; resize: vertical;
  min-height: 48px;
}
.survey-other-text:focus {
  outline: 2px solid var(--color-interactive);
  outline-offset: -1px;
  border-color: var(--color-interactive);
}
.survey-actions { display: flex; gap: 8px; align-items: center; }
.survey-submit {
  padding: 7px 14px; background: var(--color-interactive); color: #fff;
  border: 0; border-radius: var(--radius-sm);
  font: inherit; font-weight: var(--font-weight-medium);
  cursor: pointer;
}
.survey-submit:hover { filter: brightness(1.05); }
.survey-submit:disabled { background: #d6d9df; color: #6b7079; cursor: not-allowed; filter: none; }
.survey-status { font-size: var(--font-size-sm); color: var(--color-text-muted); }
.survey-status.is-error { color: #b91c1c; }
.survey-banner.is-hidden { display: none; }

/* ── Card thumbnails + cleaner hierarchy ────────────────────── */
.list-card {
  padding: 0;
  overflow: hidden;
}
.list-card-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: linear-gradient(135deg, #e8eaf0, #d6d9df);
  object-fit: cover;
  display: block;
}
.list-card-thumb-fallback {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: linear-gradient(135deg, #e8eaf0, #d6d9df);
  display: flex; align-items: center; justify-content: center;
  color: var(--color-text-muted); font-size: 22px;
}
.list-card-body { padding: var(--space-3); }
.list-card-place {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  line-height: 1.3;
  margin-bottom: 6px;
  /* Truncate long place_label values to 2 lines, ellipsis. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: 2.6em;
}
.list-card-date {
  display: inline-block;
  font-size: 11px;
  color: var(--color-text-secondary);
  background: #f1f3f6;
  padding: 2px 8px;
  border-radius: 999px;
}

/* ── Action tile (in-grid "+ explore" or countdown) ────────── */
.list-action-tile {
  background: #fff;
  border: 2px dashed var(--color-border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  min-height: 220px;
}
.list-action-tile.is-active:hover { border-color: var(--color-interactive); background: #fafbff; }
.list-action-tile.is-disabled { cursor: default; background: #fafbfc; }
.list-action-tile-icon { font-size: 32px; line-height: 1; color: var(--color-interactive); margin-bottom: 8px; }
.list-action-tile.is-disabled .list-action-tile-icon { color: var(--color-text-muted); }
.list-action-tile-title {
  font-size: var(--font-size-md);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  margin-bottom: 6px;
}
.list-action-tile-sub {
  font-size: var(--font-size-sm);
  color: var(--color-text-secondary);
  line-height: 1.4;
}
.list-action-tile-sub strong { color: var(--color-text-primary); }
.list-action-tile-sub a { color: var(--color-interactive); }

/* ── Sticky dioramap credit footer ──────────────────────────── */
.dioramap-credit-footer {
  flex: 0 0 auto;
  background: #1a1d23;
  color: #d6d9df;
  padding: 6px var(--space-4);
  font-size: 11px;
  line-height: 1.4;
  text-align: center;
  border-top: 1px solid #2a2d33;
}
.dioramap-credit-footer a {
  color: #ffffff;
  text-decoration: none;
  border-bottom: 1px dotted rgba(255,255,255,0.4);
}
.dioramap-credit-footer a:hover { border-bottom-color: #ffffff; }
.dioramap-credit-footer .credit-sep { opacity: 0.55; margin: 0 8px; }
@media (max-width: 480px) {
  .dioramap-credit-footer { font-size: 10px; padding: 5px var(--space-3); }
  .dioramap-credit-footer .credit-sep { display: none; }
  .dioramap-credit-footer .credit-line { display: block; }
}

/* ── Toast for survey + countdown updates ────────────────── */
.ag-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  background: rgba(20, 20, 28, 0.95);
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  animation: ag-toast-in 200ms ease-out;
}
@keyframes ag-toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* Hide tarteaucitron's floating cookie-consent icon on /3d.html
   only — it overlaps the viewer canvas controls (compass / SDK
   attribution). Consent banner itself still works; only the
   persistent "lock" icon is suppressed. The mandatory consent
   flow lives on other pages where the icon is unobstructive. */
#tarteaucitronIcon, .tarteaucitronIcon { display: none !important; }

/* "← Retour" pill on the viewer (top-left). Replaces the old reset
   button when the user has history. */
.viewer-back {
  position: absolute;
  top: var(--space-3); left: var(--space-3);
  z-index: 10;
  padding: 6px 12px;
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--color-border-primary);
  border-radius: 999px;
  font-size: var(--font-size-sm);
  color: var(--color-text-primary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  font-family: inherit;
}
.viewer-back:hover { background: #fff; }
