:root {
  --bg: #0f172a;
  --panel-bg: #ffffff;
  --panel-muted: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --shadow: 0 10px 25px rgba(15, 23, 42, 0.16);
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* Mobile-first shell: Address bar + Map on top, focused vertical scroll feed below */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

.top-address-bar {
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
  z-index: 1200;
  flex-shrink: 0;
}

.top-bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-compact {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 14px;
}

.brand-name {
  display: none;
  font-weight: 800;
  font-size: 16px;
}

.top-search-box {
  flex: 1 1 auto;
  position: relative;
}

.meta-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 12px;
  color: var(--text);
}

.meta-chip {
  background: #f1f5f9;
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
}

.workspace-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.map-stage {
  position: relative;
  flex: 0 0 42dvh;
  min-height: 220px;
  width: 100%;
}

#map {
  height: 100%;
  width: 100%;
}

.workspace-panel {
  flex: 1 1 auto;
  min-height: 0;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.scroll-feed {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 12px 32px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-snap-type: y proximity;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.feed-view {
  scroll-snap-align: start;
  scroll-margin-top: 10px;
  opacity: 0.78;
  transition: opacity 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.feed-view.in-focus {
  opacity: 1;
  border-color: var(--primary);
  box-shadow: 0 6px 18px rgba(2, 132, 199, 0.14);
}

.panel-section {
  background: var(--panel-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-section h2 {
  margin: 0 0 2px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text);
}

input[type="search"],
input[type="number"],
select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid rgba(2, 132, 199, 0.25);
  border-color: var(--primary);
}

.input-row {
  display: flex;
  gap: 6px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.align-end {
  display: flex;
  align-items: flex-end;
}

.btn {
  min-height: 42px;
  border: none;
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, opacity 0.15s ease;
}

.btn-compact {
  flex: 0 0 auto;
  padding: 8px 14px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  flex: 1;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #e2e8f0;
  color: var(--text);
}

.btn-ghost {
  background: #fff;
  border: 1px solid #cbd5e1;
  color: var(--text-muted);
}

.btn-ghost:hover {
  background: #f1f5f9;
}

.btn-link {
  background: transparent;
  color: var(--primary);
  padding: 4px 6px;
  font-size: 12px;
  border: none;
  cursor: pointer;
}

.dropdown-list {
  list-style: none;
  margin: 4px 0 0;
  padding: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow-y: auto;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 1500;
}

.dropdown-list li {
  padding: 10px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
}

.dropdown-list li:hover {
  background: #eff6ff;
}

.meta-label {
  color: var(--text-muted);
}

.mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.mode-btn {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.mode-btn.active {
  border-color: var(--primary);
  background: #e0f2fe;
  color: #0369a1;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.dot-source {
  background: #0284c7;
}

.dot-target {
  background: #7c3aed;
}

.coords-summary {
  font-size: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.action-row {
  display: flex;
  gap: 8px;
}

.hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

/* Detail SVG, rotation bar & material chips */
.rotation-bar {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.rotation-bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
}

.rotation-controls {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.btn-rotate {
  min-height: 38px;
  padding: 6px 4px;
  font-size: 12px;
}

.svg-compass {
  font-size: 10px;
  font-weight: 700;
  fill: #64748b;
}

.svg-skel-label {
  font-size: 10px;
  font-weight: 800;
  fill: #6d28d9;
}

.detail-svg-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-svg-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.detail-total-badge {
  background: #f1f5f9;
  color: var(--text);
  padding: 3px 8px;
  border-radius: 999px;
}

.detail-svg {
  width: 100%;
  height: auto;
  display: block;
  user-select: none;
}

.svg-hit {
  cursor: pointer;
}

.svg-hit:hover rect {
  filter: brightness(0.96);
}

.svg-label-bold {
  font-size: 11px;
  font-weight: 700;
  fill: #0f172a;
}

.svg-label-small {
  font-size: 9.5px;
  font-weight: 600;
  fill: #334155;
}

.svg-unit-title {
  font-size: 11px;
  font-weight: 700;
  fill: #ffffff;
}

.svg-unit-sub {
  font-size: 9.5px;
  fill: #e0f2fe;
}

.detail-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chip-group {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px;
}

.chip-group-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: var(--text);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  flex: 1 1 auto;
}

.chip-btn.active {
  background: #0284c7;
  border-color: #0284c7;
  color: #ffffff;
}

/* Result & History */
.result-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}

.result-card.green {
  border-left: 5px solid var(--green);
}

.result-card.red {
  border-left: 5px solid var(--red);
}

.result-placeholder {
  font-size: 12px;
  color: var(--text-muted);
}

.result-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.result-db {
  font-size: 24px;
  font-weight: 800;
}

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.pill-green {
  background: var(--green-soft);
  color: var(--green);
}

.pill-red {
  background: var(--red-soft);
  color: var(--red);
}

.result-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: 12px;
}

.period-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.period-item {
  background: var(--panel-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  text-align: center;
}

.period-head {
  display: flex;
  align-items: center;
  gap: 5px;
  font-weight: 700;
}

.period-limit {
  color: var(--text-muted);
  font-size: 11px;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-dot-green {
  background: #16a34a;
}

.status-dot-yellow {
  background: #eab308;
}

.status-dot-red {
  background: #dc2626;
}

.section-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-item {
  min-height: 44px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.history-item:hover {
  border-color: var(--primary);
}

.alert {
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.4;
}

.alert-error {
  background: var(--red-soft);
  color: #991b1b;
  border: 1px solid #fecaca;
}

.hidden {
  display: none !important;
}

/* Map Overlays */
.map-overlay {
  position: absolute;
  z-index: 900;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 8px 10px;
  font-size: 12px;
}

.legend-card {
  bottom: 10px;
  left: 10px;
  min-width: 96px;
  padding: 6px 8px;
}

.direction-cone-interactive {
  cursor: grab;
  touch-action: none;
}

.direction-cone-interactive.dragging {
  cursor: grabbing;
}

.hover-readout {
  top: 10px;
  left: 54px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.map-step-prompt {
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  pointer-events: none;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  max-width: calc(100% - 116px);
  text-align: center;
  line-height: 1.25;
}

.map-locate-btn,
.map-reset-btn {
  left: 10px;
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
}

.map-locate-btn {
  top: 84px;
}

.map-reset-btn {
  top: 122px;
  font-size: 17px;
}

.map-locate-btn:hover,
.map-reset-btn:hover {
  background: #f8fafc;
}

.map-reset-btn.hidden {
  display: none;
}

.legend-card {
  bottom: 10px;
  left: 10px;
  min-width: 140px;
}

.legend-title {
  font-weight: 700;
  font-size: 11px;
  margin-bottom: 4px;
}

.legend-bar {
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(22, 163, 74, 0.85) 0%,
    rgba(132, 204, 22, 0.85) 35%,
    rgba(250, 204, 21, 0.9) 55%,
    rgba(249, 115, 22, 0.9) 75%,
    rgba(220, 38, 38, 0.92) 100%
  );
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 10px;
}

.map-pin {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.map-pin.source {
  background: #0284c7;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
}

.map-pin.target {
  background: #7c3aed;
}

.map-pin-crosshair {
  position: relative;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.map-pin-crosshair svg {
  display: block;
}

.target-badge {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  padding: 1px 6px;
  font-size: 10px;
  font-weight: 800;
  color: #0f172a;
  white-space: nowrap;
  pointer-events: none;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.16);
}

.target-list {
  margin: 8px 0 0 0;
  padding: 6px 0 0 0;
  border-top: 1px solid var(--border);
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

.target-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.target-remove-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
}

.report-meta-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.report-meta-fields input {
  width: 100%;
  box-sizing: border-box;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 13px;
  background: #ffffff;
  color: var(--text);
}

.map-pin.rotate-handle {
  width: 24px;
  height: 24px;
  background: #ffffff;
  color: #0284c7;
  border: 2.5px solid #0284c7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  line-height: 1;
  cursor: grab;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.3);
}

.map-pin.rotate-handle:active {
  cursor: grabbing;
}

/* Desktop breakpoint: Address bar on top, Map + Scroll Feed side by side */
@media (min-width: 900px) {
  .brand-name {
    display: inline;
  }

  .top-search-box {
    max-width: 560px;
  }

  .workspace-body {
    display: grid;
    grid-template-columns: 430px 1fr;
    min-height: 0;
  }

  .workspace-panel {
    order: 1;
    border-top: none;
    border-right: 1px solid var(--border);
    min-height: 0;
  }

  .map-stage {
    order: 2;
    flex: none;
    height: 100%;
    min-height: 0;
  }

  .legend-card {
    bottom: 22px;
    left: 14px;
    min-width: 220px;
  }
}

.formula-details {
  margin-top: 10px;
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.formula-details summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: #0284c7;
  user-select: none;
}

.formula-body {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text);
}

.formula-equation {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11.5px;
  overflow-x: auto;
}

.formula-criteria {
  margin: 0;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.formula-criteria li {
  color: var(--text);
}

.formula-sub {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
}
