:root {
  --bg: #071327;
  --bg-2: #091a34;
  --panel: #102442;
  --panel-2: #152b4c;
  --panel-3: #0f213c;
  --border: rgba(255, 255, 255, 0.08);
  --text: #eef5ff;
  --muted: #9cb2cf;
  --accent: #d6a135;
  --accent-2: #edbb58;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
  --sidebar-width: 400px;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, Arial, Helvetica, sans-serif;
}

body { overflow: auto; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  width: 100vw;
  height: 100vh;
}

.sidebar {
  background: linear-gradient(180deg, #061225 0%, #08152d 100%);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px;
}

.deep-page {
  min-height: 100vh;
  background: linear-gradient(180deg, #061225 0%, #08152d 100%);
  padding: 18px;
  overflow-y: auto;
}

.deep-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

.brand-block { padding: 6px 2px 16px 2px; }

.brand-eyebrow {
  font-size: 12px;
  letter-spacing: 0.08em;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}

.brand-block h1,
.deep-header h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.05;
}

.brand-subtitle {
  margin: 10px 0 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--muted);
}

.panel {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 12px;
}

.panel h3 {
  margin: 0 0 10px 0;
  font-size: 16px;
  font-weight: 700;
}

.panel-help,
.legend-note,
.status-text,
.empty-state {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

label {
  display: block;
  margin-top: 12px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

input, select, button {
  font: inherit;
}

input[type="text"],
input[type="number"],
input[type="range"],
select {
  width: 100%;
}

input[type="text"],
input[type="number"],
select {
  appearance: none;
  border: 1px solid rgba(255,255,255,0.1);
  background: #09172f;
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder { color: #6e84a7; }

input:focus,
select:focus {
  border-color: rgba(214, 161, 53, 0.7);
  box-shadow: 0 0 0 3px rgba(214, 161, 53, 0.12);
}

input[type="range"] {
  accent-color: var(--accent);
  padding: 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  cursor: pointer;
}

.checkbox-row input {
  width: auto;
  transform: scale(1.05);
}

.button-row,
.preset-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

button,
.link-button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: #231806;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.06s ease, opacity 0.15s ease, background 0.15s ease;
}

button:hover,
.link-button:hover {
  background: var(--accent-2);
}

button:active,
.link-button:active {
  transform: translateY(1px);
}

.button-secondary {
  background: #314b73;
  color: #eef5ff;
}

.button-secondary:hover {
  background: #3c5d8d;
}

.disabled-link {
  pointer-events: none;
  opacity: 0.45;
}

.preset-button {
  min-width: 54px;
  padding: 8px 10px;
}

.radius-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}

.radius-input-row input { flex: 1; }

.suffix {
  color: var(--muted);
  font-size: 13px;
  min-width: 24px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  font-size: 13px;
  color: var(--text);
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  display: inline-block;
  flex: 0 0 14px;
}

.legend-dot-years-low { background: #38bdf8; }
.legend-dot-years-mid { background: #84cc16; }
.legend-dot-years-high { background: #ef4444; }

.legend-dot-realtime {
  background: #f2c14a;
  box-shadow: 0 0 0 2px rgba(242,193,74,0.4), 0 0 10px rgba(242,193,74,0.7);
}

.summary-wrap { margin-top: 12px; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metric-card {
  background: linear-gradient(180deg, var(--panel-3) 0%, #0d1b33 100%);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

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

.metric-value {
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
}

.summary-meta {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.subsection-title {
  margin-top: 14px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.breakdown-list {
  display: grid;
  gap: 6px;
}

.breakdown-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
  color: var(--text);
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.candidate-list {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
}

.candidate-item {
  width: 100%;
  text-align: left;
  background: linear-gradient(180deg, #0e203d 0%, #0c1a33 100%);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.candidate-item:hover {
  background: linear-gradient(180deg, #13284a 0%, #10223f 100%);
}

.candidate-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.candidate-code {
  font-weight: 800;
  color: var(--accent-2);
}

.candidate-distance {
  color: var(--muted);
  font-size: 12px;
}

.candidate-name {
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 6px;
}

.candidate-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.candidate-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 700;
}

.realtime-pill {
  background: rgba(242,193,74,0.18);
  color: #ffd774;
  border: 1px solid rgba(242,193,74,0.45);
}

.station-title {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.station-code {
  color: var(--accent-2);
  font-weight: 800;
  font-size: 15px;
}

.station-name {
  font-size: 14px;
  line-height: 1.4;
}

.detail-grid {
  display: grid;
  gap: 6px;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 13px;
}

.detail-row span { color: var(--muted); }

.map-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  background: #dfe6ee;
}

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

.map-hint {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  z-index: 1000;
  background: rgba(8,21,45,0.92);
  color: #f8fbff;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: var(--shadow);
  font-size: 13px;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.map-hint.hidden { opacity: 0; }

.leaflet-container {
  font-family: Inter, Arial, Helvetica, sans-serif;
  background: #dfe6ee;
}

.leaflet-popup-content-wrapper { border-radius: 14px; }
.leaflet-popup-content {
  margin: 12px 14px;
  line-height: 1.4;
  font-size: 13px;
}

.popup-card { min-width: 210px; }
.popup-title {
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 4px;
}
.popup-name {
  font-size: 13px;
  margin-bottom: 6px;
}
.popup-line {
  font-size: 12px;
  color: #334155;
}

.circle-center-marker,
.circle-radius-handle-marker,
.circle-label-marker,
.circle-count-marker {
  background: transparent !important;
  border: 0 !important;
}

.circle-center-dot {
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: #ffffff;
  border: 3px solid #f2c14a;
  box-shadow:
    0 0 0 4px rgba(242,193,74,0.18),
    0 0 14px rgba(242,193,74,0.55);
}

.circle-radius-handle {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #f2c14a;
  border: 2px solid #ffffff;
  box-shadow:
    0 0 0 3px rgba(242,193,74,0.18),
    0 0 10px rgba(242,193,74,0.5);
}

.circle-label-marker div,
.circle-count-marker div {
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  box-shadow: 0 10px 22px rgba(0,0,0,0.28);
  white-space: nowrap;
}

.circle-label-marker div {
  background: rgba(8,21,45,0.92);
  color: #ffffff;
  border: 1px solid rgba(255,255,255,0.14);
}

.circle-count-marker div {
  background: rgba(242,193,74,0.96);
  color: #2b1f07;
  border: 1px solid rgba(255,255,255,0.22);
}

.leaflet-interactive.realtime-station {
  filter: drop-shadow(0 0 4px rgba(242,193,74,0.95)) drop-shadow(0 0 8px rgba(242,193,74,0.4));
}

.leaflet-interactive.circle-inside {
  filter: saturate(1.12) brightness(1.06);
}

.leaflet-interactive.station-selected {
  filter: drop-shadow(0 0 6px rgba(255,255,255,0.95)) drop-shadow(0 0 12px rgba(255,255,255,0.35));
}

.warning-box {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fde7b2;
  font-size: 13px;
  line-height: 1.45;
}

.hidden { display: none !important; }

.plot-img {
  width: 100%;
  max-width: 1100px;
  display: block;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #fff;
}

.table-wrap {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th,
.data-table td {
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-weight: 700;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr)) auto;
  gap: 12px;
  align-items: end;
}

.inline-form-actions {
  display: flex;
  align-items: end;
}

.station-actions {
  margin-top: 12px;
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
    max-height: 44vh;
  }

  .inline-form {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .inline-form {
    grid-template-columns: 1fr;
  }
}
/* Map page: lock scroll */
.app-shell {
  height: 100vh;
  overflow: hidden;
}

/* Deep pages: allow scroll */
.deep-page {
  height: auto;
  min-height: 100vh;
  overflow-y: auto;
}

.qaqc-badge-wrap {
  margin-bottom: 12px;
}

.qaqc-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 800;
  font-size: 13px;
  min-width: 160px;
}

.qaqc-badge.good {
  background: rgba(34, 197, 94, 0.16);
  color: #bbf7d0;
  border: 1px solid rgba(34, 197, 94, 0.45);
}

.qaqc-badge.caution {
  background: rgba(245, 158, 11, 0.16);
  color: #fde7b2;
  border: 1px solid rgba(245, 158, 11, 0.45);
}

.qaqc-badge.poor {
  background: rgba(239, 68, 68, 0.16);
  color: #fecaca;
  border: 1px solid rgba(239, 68, 68, 0.45);
}

.qaqc-badge.neutral {
  background: rgba(148, 163, 184, 0.16);
  color: #dbeafe;
  border: 1px solid rgba(148, 163, 184, 0.45);
}

.qaqc-card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.qaqc-test-card {
  border-radius: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel-3) 0%, #0d1b33 100%);
}

.qaqc-test-card.good {
  border-color: rgba(34, 197, 94, 0.35);
}

.qaqc-test-card.caution {
  border-color: rgba(245, 158, 11, 0.35);
}

.qaqc-test-card.neutral {
  border-color: rgba(148, 163, 184, 0.35);
}

.qaqc-test-name {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}

.qaqc-test-flag {
  font-size: 20px;
  font-weight: 800;
  margin-bottom: 4px;
}

.qaqc-test-detail {
  font-size: 12px;
  color: var(--text);
  line-height: 1.35;
}

.chart-wrap {
  width: 100%;
  overflow-x: auto;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.qaqc-svg {
  width: 100%;
  height: auto;
  display: block;
}

.table-link {
  color: #f0c96b;
  text-decoration: none;
  font-weight: 700;
}

.table-link:hover {
  text-decoration: underline;
}

@media (max-width: 980px) {
  .qaqc-card-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 640px) {
  .qaqc-card-grid {
    grid-template-columns: 1fr;
  }
}
