/* ============================================================
   GeoatlasDV - App layout & components ("Clean Studio")
   ============================================================ */

/* ---------- Shell ---------- */
.appshell { display: flex; gap: 14px; height: 100vh; padding: 14px; }
.board { flex: 1; min-width: 0; display: flex; min-height: 0; }
.view { flex: 1; min-width: 0; }
.view[hidden] { display: none; }
.view.is-active { display: grid; min-height: 0; }
.view--visualize { grid-template-columns: var(--rail-w) minmax(0, 1fr) var(--insp-w); gap: 14px; }
.view--full { grid-template-columns: minmax(0, 1fr); }
.card {
  background: var(--panel);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-card);
  border: 1px solid rgba(27,27,35,.04);
}

/* ---------- Panels ---------- */
.panel { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.panel--left, .panel--inspector { overflow-y: auto; }
.panel--left { padding: 20px 18px 26px; }
.panel--inspector { padding: 20px 18px 22px; }
.panel--stage { padding: 0; }

.panel__head { margin-bottom: 20px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.themebtn .ico-sun { display: none; }
.themebtn .ico-moon { display: block; }
:root[data-theme="dark"] .themebtn .ico-sun { display: block; }
:root[data-theme="dark"] .themebtn .ico-moon { display: none; }
.panel__eyebrow { font-size: 11px; text-transform: uppercase; letter-spacing: .14em; color: var(--ink-muted); font-weight: 600; }
.panel__brand { font-family: var(--display); font-size: 22px; font-weight: 700; letter-spacing: -0.03em; margin-top: 2px; color: var(--accent); }
.panel__brand span { color: var(--accent-ink); }

/* ---------- Steps ---------- */
.step { margin-bottom: 22px; }
.step__head { display: flex; align-items: center; gap: 9px; margin-bottom: 13px; }
.step__num {
  width: 20px; height: 20px; border-radius: 6px; background: var(--ink); color: var(--canvas);
  font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.step__title { font-size: 14px; font-weight: 650; letter-spacing: -0.01em; }

/* Segmented control */
.seg { display: inline-flex; width: 100%; background: var(--panel-2); border-radius: var(--r-pill); padding: 3px; margin-bottom: 14px; }
.seg__btn {
  flex: 1; border: 0; background: transparent; color: var(--ink-2);
  font-size: 12.5px; font-weight: 600; padding: 7px 12px; border-radius: var(--r-pill);
  transition: color var(--dur-1), background var(--dur-1), box-shadow var(--dur-1);
}
.seg__btn.is-active { background: var(--panel); color: var(--ink); box-shadow: var(--sh-1); }

.src { display: none; }
.src.is-active { display: block; animation: fade var(--dur-2) var(--ease); }
.src__hint { font-size: 12px; color: var(--ink-muted); margin-top: 8px; }

/* Dropzone */
.dropzone {
  display: grid; place-items: center; gap: 8px; text-align: center;
  border: 1.5px dashed var(--hair-2); border-radius: var(--r-lg);
  padding: 26px 16px; color: var(--ink-2); transition: border-color var(--dur-1), background var(--dur-1);
}
.dropzone:hover, .dropzone.is-drag { border-color: var(--accent); background: var(--accent-wash); }
.dropzone__icon { font-size: 24px; color: var(--accent); }
.dropzone__label { font-size: 13px; line-height: 1.4; }
.dropzone__label em { color: var(--ink-3); font-style: normal; }

/* Data peek */
.datapeek { margin-top: 14px; border: 1px solid var(--hair); border-radius: var(--r-md); overflow: hidden; }
.datapeek__meta { font-family: var(--sans); font-size: 11px; color: var(--ink-2); padding: 7px 10px; background: var(--panel-2); border-bottom: 1px solid var(--hair); }
.datapeek__scroll { max-height: 156px; overflow: auto; }
.datapeek table { border-collapse: collapse; width: 100%; font-size: 11.5px; font-family: var(--system); }
.datapeek th, .datapeek td { padding: 5px 9px; text-align: left; border-bottom: 1px solid var(--hair); white-space: nowrap; }
.datapeek th { position: sticky; top: 0; background: var(--panel); font-weight: 600; color: var(--ink); }
.datapeek td { color: var(--ink-2); font-family: var(--system); }
.datapeek__edithint { float: right; color: var(--ink-3); font-style: italic; }
.datapeek__tools { display: flex; gap: 8px; margin-top: 8px; }
.datapeek__tools .btn { flex: 1; padding: 7px 10px; font-size: 12.5px; }
.datapeek td[contenteditable] { cursor: text; }
.datapeek td[contenteditable]:hover { background: var(--panel-2); }
.datapeek td[contenteditable]:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-wash); color: var(--ink); }
.datapeek th .colname { cursor: text; border-radius: 3px; padding: 0 2px; display: inline-block; min-width: 8px; }
.datapeek th .colname:hover { background: var(--panel-2); }
.datapeek th .colname:focus { outline: 2px solid var(--accent); outline-offset: 0; background: var(--accent-wash); }

/* ---------- Chart picker ---------- */
.chartgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.chartcard {
  position: relative; border: 1px solid var(--hair); background: var(--panel-3); border-radius: var(--r-md);
  padding: 12px 10px 10px; text-align: left; color: var(--ink-2);
  transition: transform var(--dur-1) var(--ease), border-color var(--dur-1), box-shadow var(--dur-1), background var(--dur-1);
}
.chartcard:hover { transform: translateY(-2px); border-color: var(--hair-2); box-shadow: var(--sh-2); color: var(--ink); background: var(--panel); }
.chartcard.is-active { border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 1px var(--accent); color: var(--ink); }
.chartcard.is-active .chartcard__ico { color: var(--accent); }
.chartcard__ico { display: block; height: 30px; margin-bottom: 8px; color: var(--ink-3); }
.chartcard__ico svg { height: 100%; width: auto; }
.chartcard__name { font-size: 12px; font-weight: 600; letter-spacing: -0.01em; }

/* ---------- Stage ---------- */
.stagebar {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 16px;
  padding: 18px 22px 14px; border-bottom: 1px solid var(--hair);
}
.stagebar__title { min-width: 0; flex: 1; }
.stage__title, .stage__sub { display: block; width: 100%; border: 0; background: transparent; padding: 1px 0; }
.stage__title { font-size: 19px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink); }
.stage__title::placeholder { color: var(--ink-3); }
.stage__sub { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.stage__sub::placeholder { color: var(--ink-3); }
.stage__title:focus, .stage__sub:focus { outline: none; }
.stagebar__actions { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }

.pilltoggle { display: flex; gap: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--hair-2);
  background: var(--panel); color: var(--ink-2); border-radius: var(--r-pill);
  padding: 7px 12px 7px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: border-color var(--dur-1), color var(--dur-1), background var(--dur-1);
}
.pill:hover { border-color: var(--hair-2); color: var(--ink); }
.pill.is-on { background: var(--ink); border-color: var(--ink); color: var(--canvas); }
.pill__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); transition: background var(--dur-1); }
.pill.is-on .pill__dot { background: var(--good); }

.iconbtn {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--hair-2);
  background: var(--panel); color: var(--ink-2); display: grid; place-items: center;
  transition: border-color var(--dur-1), color var(--dur-1);
}
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn:hover { color: var(--ink); border-color: var(--ink-3); }

/* Suggested forms chips */
.suggestbar { display: flex; flex-wrap: wrap; gap: 7px; padding: 12px 22px 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--hair-2);
  background: var(--panel); color: var(--ink-2); border-radius: var(--r-pill);
  padding: 5px 12px; font-size: 12px; font-weight: 550; cursor: pointer;
  transition: border-color var(--dur-1), color var(--dur-1), background var(--dur-1);
}
.chip:hover { border-color: var(--accent); color: var(--accent-ink); background: var(--accent-wash); }
.chip__star { color: var(--accent); font-size: 10px; }

.stage__canvas { position: relative; flex: 1; min-height: 340px; padding: 16px 22px; }
.stage__canvas svg { display: block; width: 100%; height: auto; overflow: visible; }

.stage__foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 22px; border-top: 1px solid var(--hair); font-size: 11px; color: var(--ink-3);
}
.stage__source-input { border: 0; background: transparent; font-size: 11px; color: var(--ink-2); width: 160px; }
.stage__source-input:focus { outline: none; border-bottom: 1px solid var(--accent); }
.stage__brand { font-weight: 600; }

.empty { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; gap: 4px; color: var(--ink-3); }
.empty__mark { font-size: 44px; color: var(--hair-2); }
.empty__title { font-size: 16px; font-weight: 600; color: var(--ink-2); }
.empty__hint { font-size: 13px; color: var(--ink-muted); }

/* ---------- Inspector controls ---------- */
.inspector__head { margin-bottom: 16px; }
.inspector__title { font-size: 15px; font-weight: 650; margin-top: 2px; }
.controls__empty { font-size: 13px; color: var(--ink-muted); }
.ctrl { margin-bottom: 15px; }
.ctrl__label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-2); font-weight: 600; margin-bottom: 7px;
}
.ctrl__val { font-family: var(--sans); color: var(--accent-ink); letter-spacing: 0; text-transform: none; }
.ctrl__group { margin-bottom: 20px; }
.ctrl__grouphead {
  font-size: 12px; font-weight: 650; color: var(--ink); letter-spacing: -0.01em;
  padding-bottom: 8px; margin-bottom: 13px; border-bottom: 1px solid var(--hair);
}

.toggle { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; }
.toggle__label { font-size: 13px; color: var(--ink); }
.switch { position: relative; width: 38px; height: 22px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch__track { position: absolute; inset: 0; background: var(--hair-2); border-radius: 999px; transition: background var(--dur-1); }
.switch__track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; box-shadow: var(--sh-1); transition: transform var(--dur-1) var(--ease); }
.switch input:checked + .switch__track { background: var(--accent); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }

input[type=range] { -webkit-appearance: none; width: 100%; height: 4px; background: var(--hair-2); border-radius: 999px; }
input[type=range]::-webkit-slider-thumb { -webkit-appearance: none; width: 16px; height: 16px; border-radius: 50%; background: var(--accent); cursor: pointer; border: 3px solid var(--panel); box-shadow: var(--sh-1); }

.palettes { display: grid; gap: 7px; }
.palette { display: flex; align-items: center; gap: 9px; border: 1px solid var(--hair); border-radius: var(--r-md); padding: 7px 9px; background: var(--panel); cursor: pointer; transition: border-color var(--dur-1), box-shadow var(--dur-1); }
.palette:hover { border-color: var(--hair-2); }
.palette.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.palette__chips { display: flex; gap: 3px; }
.palette__chips span { width: 15px; height: 15px; border-radius: 4px; }
.palette__name { font-size: 12px; color: var(--ink-2); font-weight: 550; }

/* custom palette editor */
.custompal { margin-top: 10px; padding: 12px; border: 1px solid var(--hair); border-radius: var(--r-md); background: var(--panel-2); }
.custompal__grid { display: flex; flex-wrap: wrap; gap: 8px; }
.custompal__cell { position: relative; }
.custompal__cell input[type=color] { width: 34px; height: 34px; border: 1px solid var(--hair-2); border-radius: 9px; background: none; cursor: pointer; padding: 2px; }
.custompal__del { position: absolute; top: -6px; right: -6px; width: 16px; height: 16px; border-radius: 50%; border: 0; background: var(--ink); color: var(--canvas); font-size: 11px; line-height: 1; cursor: pointer; display: grid; place-items: center; }
.custompal__del:hover { background: var(--accent); }
.custompal__add { margin-top: 10px; width: 100%; border: 1px dashed var(--hair-2); background: transparent; color: var(--ink-2); border-radius: var(--r-md); padding: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.custompal__add:hover { border-color: var(--accent); color: var(--accent-ink); }

/* ---------- Tooltip ---------- */
.ga-tip {
  position: fixed; pointer-events: none; z-index: 50;
  background: var(--ink); color: var(--canvas); padding: 9px 12px; border-radius: 10px;
  font-size: 12px; line-height: 1.45; box-shadow: var(--sh-2);
  opacity: 0; transform: translateY(4px); transition: opacity var(--dur-1), transform var(--dur-1); max-width: 240px;
}
.ga-tip.is-show { opacity: 1; transform: translateY(0); }
.ga-tip b { font-weight: 650; }
.ga-tip .ga-tip__k { color: var(--canvas); opacity: .62; }
.ga-tip__sw { display: inline-block; width: 8px; height: 8px; border-radius: 3px; margin-right: 6px; }

/* ---------- Chart SVG styling ---------- */
.ga-axis line, .ga-axis path { stroke: var(--hair-2); }
.ga-axis text { fill: var(--ink-muted); font-size: 11px; font-family: var(--sans); font-variant-numeric: tabular-nums; }
.ga-grid line { stroke: var(--hair); }
.ga-axis-title { fill: var(--ink-2); font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; }
.ga-legend text { fill: var(--ink); font-size: 12px; }
.ga-val-label { fill: var(--ink); font-size: 11px; font-weight: 650; }

/* ---------- Export sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; }
.sheet[hidden] { display: none; }
.sheet__scrim { position: absolute; inset: 0; background: rgba(27,27,35,.32); backdrop-filter: blur(3px); animation: fade var(--dur-2); }
.sheet__panel { position: relative; width: min(440px, 92vw); background: var(--panel); border-radius: var(--r-xl); box-shadow: var(--sh-3); overflow: hidden; animation: pop var(--dur-2) var(--ease); }
.sheet__head { display: flex; justify-content: space-between; align-items: center; padding: 20px 22px 14px; border-bottom: 1px solid var(--hair); }
.sheet__head h3 { font-size: 17px; font-weight: 650; }
.sheet__close { border: 0; background: transparent; font-size: 15px; color: var(--ink-3); }
.sheet__close:hover { color: var(--ink); }
.sheet__body { padding: 16px 22px 22px; display: grid; gap: 10px; }
.export-opt { display: grid; gap: 2px; text-align: left; border: 1px solid var(--hair); background: var(--panel); border-radius: var(--r-md); padding: 13px 15px; transition: border-color var(--dur-1), transform var(--dur-1); }
.export-opt:hover { border-color: var(--accent); transform: translateY(-1px); }
.export-opt b { font-size: 14px; font-weight: 650; }
.export-opt span { font-size: 12px; color: var(--ink-3); }

/* Export background chooser */
.exp-bg { display: grid; gap: 8px; padding: 2px 2px 10px; border-bottom: 1px solid var(--hair); }
.exp-bg__lbl { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-3); }
.exp-bg__row { display: flex; gap: 8px; }
.bgsw { width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--hair-2); background: #fff; cursor: pointer; padding: 0; position: relative; transition: box-shadow var(--dur-1), border-color var(--dur-1); }
.bgsw:hover { border-color: var(--accent); }
.bgsw.is-active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-wash); }
.bgsw[data-bg="transparent"] {
  background-color: #fff;
  background-image: linear-gradient(45deg, #d3d3da 25%, transparent 25%), linear-gradient(-45deg, #d3d3da 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #d3d3da 75%), linear-gradient(-45deg, transparent 75%, #d3d3da 75%);
  background-size: 10px 10px; background-position: 0 0, 0 5px, 5px -5px, -5px 0;
}
.bgsw--custom { overflow: hidden; display: grid; place-items: center; }
.bgsw--custom::after { content: "+"; font-size: 15px; font-weight: 700; color: #fff; mix-blend-mode: difference; pointer-events: none; }
.bgsw--custom input { position: absolute; inset: -6px; width: 150%; height: 150%; border: 0; padding: 0; margin: 0; cursor: pointer; opacity: 0; }

/* ---------- UI/UX polish: numerals, focus, affordances, states ---------- */
/* Tabular numbers so digits do not jitter (Figma: readability) */
.datapeek td, .ctrl__val, .story-count, .ticker__num, .ga-legend text, .datapeek__meta { font-variant-numeric: tabular-nums; }
/* Numeric table cells align right (convention) */
.datapeek td.num, .datapeek th.num { text-align: right; }
/* Visible keyboard focus on custom controls (WCAG 2.4.7) */
.chartcard:focus-visible, .palette:focus-visible, .chip:focus-visible, .seg__btn:focus-visible,
.navbtn:focus-visible, .ia-item:focus-visible, .slideitem:focus-visible, .maps-card--btn:focus-visible,
.pill:focus-visible, .export-opt:focus-visible, .ia-item:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm);
}
/* Edit affordance: on-canvas text fields signal they are editable */
.stage__title:hover, .stage__sub:hover, .stage__source-input:hover { box-shadow: inset 0 -1px 0 var(--hair-2); }
.stage__title:focus, .stage__sub:focus, .stage__source-input:focus { box-shadow: inset 0 -2px 0 var(--accent); }
/* Disabled state for unavailable actions (Figma: button states) */
.btn[disabled], .btn[aria-disabled="true"], .iconbtn[disabled] { opacity: .45; cursor: not-allowed; pointer-events: none; }
/* Consistent hover elevation recipe */
.chartcard:hover, .export-opt:hover, .maps-card--btn:hover, .iacard:hover { box-shadow: var(--sh-2); }

/* ---------- Display type (Space Grotesk) ---------- */
.step__title, .inspector__title, .stage__title, .empty__title, .sheet__head h3 {
  font-family: var(--display); letter-spacing: -0.02em;
}
.stage__title { font-weight: 700; }

/* Flash highlight (e.g. when the Data icon jumps to the data panel) */
.is-flash { animation: flash 1s var(--ease); }
@keyframes flash {
  0% { background: var(--accent-wash); box-shadow: 0 0 0 6px var(--accent-wash); border-radius: var(--r-md); }
  100% { background: transparent; box-shadow: 0 0 0 6px transparent; border-radius: var(--r-md); }
}

/* ---------- Animations ---------- */
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ----------
   NOTE: .board is a flex container; the grid columns live on the active
   .view, so breakpoints must target the views, not .board. */
@media (max-width: 1160px) {
  /* Two columns: rail + stage. Inspector drops full-width below. */
  .view--visualize.is-active { grid-template-columns: var(--rail-w) minmax(0, 1fr); grid-auto-rows: min-content; }
  .view--visualize .panel--inspector { grid-column: 1 / -1; max-height: 440px; }
  /* Let the stage header wrap so the headline is never squished */
  .stagebar { flex-wrap: wrap; row-gap: 10px; }
  .stagebar__title { flex-basis: 100%; }
}
@media (max-width: 820px) {
  /* Stack everything; page scrolls. */
  html, body { height: auto; }
  body { overflow-x: hidden; }
  .appshell { flex-direction: column; height: auto; min-height: 100vh; gap: 12px; padding: 10px; max-width: 100%; }
  .appshell, .board, .view, .panel, .stagebar { min-width: 0; max-width: 100%; }
  .board { display: block; }
  .view.is-active { display: grid; grid-template-columns: 1fr; gap: 12px; }
  .panel { overflow: visible; }
  .panel--left, .panel--inspector, .panel--stage { overflow: visible; }
  .panel--inspector { max-height: none; }
  .stage__canvas { min-height: 300px; }
  .stagebar { flex-wrap: wrap; }
  .panel--left, .panel--inspector { padding: 16px 14px 20px; }
  .datapeek, .datapeek__scroll { max-width: 100%; }
}
/* Tiny phones: single-column form grid so cards never overflow */
@media (max-width: 400px) {
  .chartgrid { grid-template-columns: 1fr; }
  .stagebar__actions { width: 100%; }
}
