/* =============================================================================
   LTN 1/20 Assessment Tool — Light Theme
   ============================================================================= */

:root {
  --bg-page: #f5f3ef;
  --bg-panel: #ffffff;
  --bg-input: #f7f6f3;
  --text-primary: #1a1a1a;
  --text-secondary: #5f6368;
  --text-muted: #9aa0a6;
  --accent: #c96442;
  --accent-hover: #b5532f;
  --accent-light: #fdf0eb;
  --border: #e5e2dc;
  --border-light: #f0ede8;
  --green: #1a9850;
  --amber: #d4a017;
  --red: #d73027;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 10px;
  --panel-width: 300px;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-body);
  background: var(--bg-page);
  color: var(--text-primary);
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  position: relative;
}

/* =============================================================================
   Map — full viewport
   ============================================================================= */

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* =============================================================================
   Left Panel — floating sidebar
   ============================================================================= */

#panel-left {
  position: absolute;
  top: 12px;
  left: 12px;
  bottom: 12px;
  width: var(--panel-width);
  z-index: 10;
  background: var(--bg-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s ease, opacity 0.3s ease;
}

#panel-left.panel-collapsed {
  transform: translateX(calc(-100% - 20px));
  opacity: 0;
  pointer-events: none;
}

.btn-expand-left {
  position: absolute;
  top: 16px;
  left: 12px;
  z-index: 10;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--text-secondary);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.btn-expand-left.visible { display: flex; }
.btn-expand-left:hover { background: var(--bg-input); }

/* Panel header */

.panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
  flex-shrink: 0;
}

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.panel-header h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--text-primary);
}

.panel-header .subtitle {
  font-weight: 400;
  font-size: 13px;
  color: var(--text-secondary);
}

.region-tag {
  margin-top: 4px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-weight: 500;
}

.btn-collapse {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  flex-shrink: 0;
}
.btn-collapse:hover { background: var(--bg-input); color: var(--text-secondary); }

/* Panel body — scrollable */

.panel-body {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* Sections / Accordion */

.panel-section {
  border-bottom: 1px solid var(--border-light);
}

.section-toggle {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  cursor: pointer;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
}

.section-toggle:hover { color: var(--text-secondary); }

.chevron {
  font-size: 14px;
  transition: transform 0.2s;
  font-weight: 400;
}

.section-open .chevron { transform: rotate(90deg); }

.section-content {
  padding: 0 16px 14px;
  display: none;
}

.section-open .section-content { display: block; }

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.helper-text {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  margin-bottom: 12px;
}

/* =============================================================================
   OD Inputs
   ============================================================================= */

.od-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.od-marker {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.origin-marker { background: var(--green); color: #fff; }
.dest-marker { background: var(--red); color: #fff; }

.od-row input {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
}

.od-row input::placeholder { color: var(--text-muted); }
.od-row input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }

.btn-clear {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}
.btn-clear:hover { color: var(--text-primary); }

.od-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.btn-primary {
  flex: 1;
  padding: 9px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; }

.btn-secondary {
  padding: 9px 14px;
  background: var(--bg-input);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}
.btn-secondary:hover { border-color: var(--text-muted); }

/* =============================================================================
   Select & Toggle
   ============================================================================= */

#colour-by, .sheet-content select {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-body);
  cursor: pointer;
}
#colour-by:focus { outline: 1px solid var(--accent); }

.toggle-group {
  display: flex;
  gap: 2px;
  background: var(--bg-input);
  border-radius: 6px;
  padding: 2px;
}

.toggle-btn {
  flex: 1;
  padding: 7px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  border-radius: 4px;
  transition: all 0.15s;
}
.toggle-btn.active {
  background: var(--accent);
  color: #fff;
}

/* =============================================================================
   Legend
   ============================================================================= */

#legend {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 20px;
  height: 4px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Layer toggles */

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  margin-bottom: 8px;
}

.layer-toggle input { accent-color: var(--accent); }

/* =============================================================================
   Link Inspector
   ============================================================================= */

.info-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
}

.info-table td {
  padding: 4px 0;
  border-bottom: 1px solid var(--border-light);
}

.info-table td:first-child {
  color: var(--text-muted);
  padding-right: 10px;
  white-space: nowrap;
  width: 40%;
  font-size: 11px;
}

.info-table td:last-child {
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 11px;
}

/* =============================================================================
   Score Card — floating top-right
   ============================================================================= */

#score-card {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 10;
  width: 260px;
  background: var(--bg-panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transition: width 0.3s;
}

.score-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-light);
}

.score-card-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.score-card-body {
  padding: 12px 14px 16px;
  max-height: calc(100vh - 100px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#score-card.score-collapsed .score-card-body { display: none; }
#score-card.score-collapsed .score-card-header { border-bottom: none; }

/* Score overall */

.score-overall {
  text-align: center;
  padding: 8px 0 14px;
}

.score-overall .score-value {
  display: block;
  font-size: 42px;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
  color: var(--text-muted);
}

.score-overall .score-label {
  font-size: 11px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 4px;
  display: block;
}

/* Dimension bars */

.score-dimensions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.dim {
  display: grid;
  grid-template-columns: 105px 1fr 38px;
  gap: 6px;
  align-items: center;
  min-width: 0;
  overflow: hidden;
}

.dim-label {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 3px;
}

.dim-value {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-muted);
  text-align: right;
}

.dim-bar {
  height: 6px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
}

.dim-fill {
  height: 100%;
  width: 0%;
  border-radius: 3px;
  transition: width 0.4s ease, background 0.3s;
  background: var(--text-muted);
}

/* =============================================================================
   Popup override for light theme
   ============================================================================= */

.maplibregl-popup-content {
  background: var(--bg-panel) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  padding: 12px !important;
  font-family: var(--font-body) !important;
  font-size: 12px !important;
  box-shadow: var(--shadow-md) !important;
}

.maplibregl-popup-tip {
  border-top-color: var(--bg-panel) !important;
}

.maplibregl-popup-close-button {
  color: var(--text-muted) !important;
  font-size: 16px !important;
}

/* =============================================================================
   Mobile Bottom Bar
   ============================================================================= */

#mobile-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.06);
  grid-template-columns: repeat(3, 1fr);
  padding: 6px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.mobile-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
}

.mobile-tab.active { color: var(--accent); }
.mobile-tab svg { stroke: currentColor; }

/* Mobile Bottom Sheet */

#mobile-sheet {
  display: none;
  position: fixed;
  bottom: calc(52px + max(8px, env(safe-area-inset-bottom)));
  left: 0;
  right: 0;
  z-index: 19;
  background: var(--bg-panel);
  border-radius: 14px 14px 0 0;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
  max-height: 50vh;
  overflow-y: auto;
  overflow-x: hidden;
}

#mobile-sheet.mobile-sheet-hidden {
  display: none;
}

.sheet-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 6px;
  cursor: pointer;
}
.sheet-handle span {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
}

.sheet-content {
  padding: 0 16px 16px;
}

/* =============================================================================
   Responsive
   ============================================================================= */

/* Tablet */
@media (max-width: 960px) {
  :root { --panel-width: 280px; }
}

/* Mobile */
@media (max-width: 640px) {
  #panel-left { display: none; }
  #score-card { display: none; }
  .btn-expand-left { display: none !important; }

  #mobile-bar {
    display: grid;
  }

  #mobile-sheet {
    display: none;
  }

  #mobile-sheet:not(.mobile-sheet-hidden) {
    display: block;
  }
}

/* MapLibre controls positioning — avoid overlap */
.maplibregl-ctrl-top-left {
  top: 12px;
  left: calc(var(--panel-width) + 24px);
}

@media (max-width: 640px) {
  .maplibregl-ctrl-top-left {
    left: 12px;
    top: 12px;
  }
}

/* =============================================================================
   Dimension Info Tooltips
   ============================================================================= */

.dim {
  position: relative;
}

.info-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  vertical-align: middle;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
}

.info-btn:hover,
.info-btn.info-btn-active {
  opacity: 1;
  color: var(--accent);
}

.dim-info {
  display: none;
  grid-column: 1 / -1;
  background: var(--bg-input);
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.55;
  color: var(--text-secondary);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.dim-info.dim-info-open {
  display: block;
}

.dim-info p {
  margin-bottom: 4px;
}

.dim-info p:last-child {
  margin-bottom: 0;
}

.dim-info strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* =============================================================================
   Help Button
   ============================================================================= */

#btn-help {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 15;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  color: var(--text-secondary);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

#btn-help:hover {
  background: var(--bg-input);
  color: var(--accent);
}

@media (max-width: 640px) {
  #btn-help {
    bottom: calc(60px + max(8px, env(safe-area-inset-bottom)));
    right: 12px;
  }
}

/* =============================================================================
   Onboarding Guide
   ============================================================================= */

#onboarding-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition: opacity 0.3s;
}

#onboarding-overlay.onboarding-hidden {
  display: none;
}

.onboarding-card {
  background: var(--bg-panel);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  max-width: 440px;
  width: 100%;
  overflow: hidden;
}

.onboarding-steps {
  padding: 32px 28px 20px;
  min-height: 220px;
  display: flex;
  align-items: flex-start;
}

.onboarding-step {
  display: none;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.onboarding-step.active {
  display: flex;
}

.onboarding-icon {
  font-size: 28px;
  margin-bottom: 4px;
}

.onboarding-step h3 {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.onboarding-step p {
  font-size: 13px;
  line-height: 1.6;
  color: var(--text-secondary);
}

.onboarding-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px 20px;
  border-top: 1px solid var(--border-light);
}

.onboarding-dots {
  display: flex;
  gap: 8px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
  cursor: pointer;
  transition: background 0.2s;
}

.dot.active {
  background: var(--accent);
}

.onboarding-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn-skip {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
}

.btn-skip:hover {
  color: var(--text-secondary);
}

.btn-next {
  padding: 8px 20px;
  font-size: 13px;
}

/* Mobile onboarding */
@media (max-width: 640px) {
  .onboarding-card {
    max-width: 100%;
  }

  .onboarding-steps {
    padding: 24px 20px 16px;
    min-height: 200px;
  }

  .onboarding-footer {
    padding: 12px 20px 16px;
  }
}