/* ============================================================
   AERMOD Smelter Tool — Stage B styling
   PlumeCalc-inspired design tokens
   ============================================================ */

:root {
  --bg1: #f7f7f8;
  --bg2: #ececef;
  --bg3: #e3e3e7;
  --surface: #ffffff;
  --border: #d4d4d8;
  --border2: #a1a1aa;
  --text1: #18181b;
  --text2: #3f3f46;
  --text3: #71717a;
  --primary: #1f3864;
  --primary-hover: #15264a;
  --accent: #2e5496;
  --info: #2563eb;
  --warn: #d97706;
  --danger: #dc2626;
  --success: #059669;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  margin: 0; padding: 0;
  color: var(--text1);
  background: var(--bg1);
  font-size: 14px;
}

/* ============ Header ============ */
header {
  background: var(--primary);
  color: white;
  padding: 0.9rem 1.5rem;
  display: flex; align-items: baseline; gap: 1rem;
}
header h1 { margin: 0; font-size: 1.3rem; font-weight: 600; }
header .subtitle { font-size: 0.85rem; opacity: 0.85; }

.disclaimer {
  background: #fef3c7;
  border-left: 4px solid var(--warn);
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  margin: 0;
}

/* ============ Layout ============ */
main {
  display: grid;
  grid-template-columns: 480px 1fr;
  gap: 0;
  height: calc(100vh - 88px);
}

#controls-section {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

#map-section { position: relative; height: 100%; }
#map { height: 100%; width: 100%; background: var(--bg2); }

/* ============ Tab navigation ============ */

/* ============ Stage B fixes ============ */
.tabs {
  display: flex;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 0;
  flex-shrink: 0;
}
.tabs button.tab-btn {
  flex: 1;
  width: auto !important;
  background: transparent !important;
  border: 0 !important;
  border-bottom: 2px solid transparent !important;
  border-radius: 0 !important;
  padding: 0.65rem 0.5rem !important;
  margin: 0 !important;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text3) !important;
  cursor: pointer;
}
.tabs button.tab-btn:hover {
  background: var(--bg3) !important;
  color: var(--text1) !important;
}
.tabs button.tab-btn.active {
  background: var(--surface) !important;
  color: var(--primary) !important;
  border-bottom-color: var(--primary) !important;
}

/* Control selector: prefer dropdown over buttons */
#control-grid { display: none; }
#control-select {
  display: block;
  width: 100%;
  padding: 0.5rem;
  font-size: 0.85rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  font-family: inherit;
  margin-top: 0.4rem;
}
#control-desc {
  margin-top: 0.5rem;
  padding: 0.5rem 0.7rem;
  background: var(--surface);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 0.78rem;
  color: var(--text2);
  line-height: 1.45;
}
/* ============ Panel content ============ */
.panel {
  display: none;
  padding: 1rem 1.2rem;
  overflow-y: auto;
  flex: 1;
}
.panel.active { display: block; }

.section-label {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--text3);
  text-transform: uppercase;
  margin: 1rem 0 0.5rem;
  padding-bottom: 0.3rem;
  border-bottom: 1px solid var(--border);
}
.section-label:first-child { margin-top: 0; }

/* ============ Wizard steps ============ */
.wiz-step {
  margin-bottom: 1.2rem;
  padding: 0.8rem 0.9rem;
  background: var(--bg2);
  border-radius: 6px;
  border: 1px solid var(--border);
}
.wiz-step-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text2);
  margin-bottom: 0.5rem;
  display: flex; align-items: center; gap: 0.5rem;
}
.wiz-num {
  display: inline-block;
  background: var(--primary);
  color: white;
  width: 22px; height: 22px;
  border-radius: 50%;
  text-align: center;
  font-family: var(--mono);
  font-size: 0.7rem;
  line-height: 22px;
}

/* ============ Throughput slider ============ */
.wiz-range {
  width: 100%;
  margin: 0.5rem 0;
}
.wiz-value-display {
  font-family: var(--mono);
  font-size: 1rem;
  color: var(--primary);
  font-weight: 600;
}

/* ============ Control buttons ============ */
.wiz-opt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.wiz-opt-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.55rem 0.7rem;
  text-align: left;
  font-size: 0.78rem;
  cursor: pointer;
  margin: 0; width: auto;
  transition: all 0.1s;
  color: var(--text1);
  line-height: 1.35;
}
.wiz-opt-btn:hover { border-color: var(--primary); }
.wiz-opt-btn span {
  display: block;
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text3);
  margin-top: 0.15rem;
}
.wiz-opt-btn.wiz-selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.wiz-opt-btn.wiz-selected span { color: rgba(255,255,255,0.85); }

/* ============ Scenario buttons ============ */
.scenario-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.scenario-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.55rem 0.5rem;
  font-size: 0.75rem;
  cursor: pointer;
  margin: 0;
  width: auto;
  text-align: center;
  color: var(--text1);
}
.scenario-btn:hover { border-color: var(--primary); background: var(--bg2); }
.scenario-btn.eu_bat   { border-left: 3px solid var(--info); }
.scenario-btn.lmic_good { border-left: 3px solid var(--success); }
.scenario-btn.lmic_avg  { border-left: 3px solid var(--warn); }
.scenario-btn.lmic_bad  { border-left: 3px solid var(--danger); }

/* ============ Live emissions readout ============ */
#emissions-readout {
  margin-top: 1rem;
  padding: 0.7rem 0.9rem;
  background: var(--bg2);
  border-radius: 6px;
  border: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.78rem;
}
#emissions-readout .row {
  display: flex; justify-content: space-between;
  padding: 0.15rem 0;
}
#emissions-readout .row.total {
  font-weight: 600; color: var(--primary);
  border-top: 1px solid var(--border);
  margin-top: 0.3rem; padding-top: 0.4rem;
}
#emissions-readout .label { color: var(--text3); }

/* ============ Form fields ============ */
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.field {
  display: flex; flex-direction: column;
  font-size: 0.78rem;
  color: var(--text2);
}
.field input, .field select {
  margin-top: 0.2rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
  background: var(--surface);
  width: 100%;
}
.field-hint {
  font-size: 0.7rem;
  color: var(--text3);
  margin-top: 0.2rem;
}

/* ============ Particle table ============ */
.psd-table { width: 100%; border-collapse: collapse; margin: 0.4rem 0; }
.psd-table th {
  font-family: var(--mono);
  font-size: 0.65rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text3);
  text-align: left;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--border);
}
.psd-table td {
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--border);
}

/* ============ Run button ============ */
.run-bar {
  padding: 0.8rem 1.2rem;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.run-btn {
  width: 100%;
  background: var(--primary);
  color: white;
  border: 0;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
}
.run-btn:hover { background: var(--primary-hover); }
.run-btn:disabled { background: var(--text3); cursor: wait; }

/* ============ Result panel ============ */
#result-box {
  margin-top: 0.8rem;
  padding: 0.7rem 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
#result-box h3 {
  margin: 0 0 0.4rem;
  font-size: 0.8rem;
  color: var(--primary);
  font-family: var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
#result {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg2);
  padding: 0.5rem 0.7rem;
  border-radius: 4px;
  white-space: pre-wrap;
  margin: 0;
}
#breakdown-toggle {
  font-size: 0.75rem;
  color: var(--accent);
  background: transparent;
  border: 0; padding: 0.3rem 0;
  cursor: pointer;
  width: auto;
  margin: 0.4rem 0 0;
}
#breakdown-detail {
  display: none;
  margin-top: 0.4rem;
  padding: 0.5rem 0.7rem;
  background: var(--bg2);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 0.72rem;
  white-space: pre-wrap;
}
#breakdown-detail.open { display: block; }

/* ============ Mobile fallback ============ */
@media (max-width: 800px) {
  main { grid-template-columns: 1fr; height: auto; }
  #controls-section { border-right: 0; border-bottom: 1px solid var(--border); }
  #map-section { height: 400px; }
  .scenario-row, .wiz-opt-grid { grid-template-columns: 1fr 1fr; }
}

/* ============ NUCLEAR OVERRIDES (force layout) ============ */
nav.tabs {
  display: flex !important;
  flex-direction: row !important;
  width: 100% !important;
}
nav.tabs > button.tab-btn {
  flex: 1 1 0 !important;
  display: block !important;
  width: auto !important;
  max-width: none !important;
  background: transparent !important;
  color: #71717a !important;
  border: 0 !important;
  border-bottom: 2px solid transparent !important;
  border-radius: 0 !important;
  padding: 0.7rem 0.3rem !important;
  margin: 0 !important;
  font-size: 0.7rem !important;
  font-weight: normal !important;
  text-transform: uppercase !important;
  cursor: pointer !important;
}
nav.tabs > button.tab-btn:hover {
  background: #e3e3e7 !important;
  color: #18181b !important;
}
nav.tabs > button.tab-btn.active {
  background: #ffffff !important;
  color: #1f3864 !important;
  border-bottom-color: #1f3864 !important;
}

/* Hide button grid; use dropdown */
#control-grid { display: none !important; }

/* Make sure normal buttons (run-btn etc) keep their full-width style
   without leaking into tabs */
button.scenario-btn { width: 100% !important; }

/* Hide inactive panels — single source of truth */
.panel { display: none !important; }
.panel.active { display: block !important; }

/* ============ Layout: make controls section scrollable ============ */
#controls-section {
  overflow-y: auto !important;
}

/* ============ Map view toggles ============ */
#map-section { position: relative; }

#map-toggles {
  position: absolute;
  top: 12px;
  left: 60px;
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--mono);
}

.toggle-group {
  display: flex;
  gap: 0;
  border-radius: 4px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.toggle-btn {
  flex: 1;
  background: transparent;
  border: 0;
  padding: 6px 12px;
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.toggle-btn:hover {
  background: var(--bg2);
  color: var(--text1);
}

.toggle-btn.active {
  background: var(--accent);
  color: white;
  font-weight: 600;
}

.toggle-btn + .toggle-btn {
  border-left: 1px solid var(--border);
}
