:root {
  --brand-corporate: #2f5fa7;
  --brand-corporate-hover: #28528f;
  --text-main: #0f172a;
  --text-muted: #475569;
  --bg-surface: #ffffff;
  --bg-soft: #f8fafc;
  --bg-page: #eef2f7;
  --border-soft: #e2e8f0;
  --danger: #dc2626;
  --shadow-soft: 0 1px 3px rgba(15, 23, 42, 0.12);
  --shadow-card: 0 8px 16px rgba(15, 23, 42, 0.08);
  --font-main: "Noto Sans JP", "Noto Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: Consolas, Monaco, "Courier New", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  font-family: var(--font-main);
  font-size: 14px;
  color: var(--text-main);
  background: var(--bg-page);
  overflow: hidden;
}

body {
  display: flex;
  flex-direction: column;
}

.app-shell {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.app-header {
  height: 48px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--brand-corporate);
  color: #ffffff;
}

.app-header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
}

.eyebrow {
  display: none;
}

.header-status {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.22);
}

.status-pill--idle {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.status-pill--loading {
  background: rgba(245, 158, 11, 0.24);
  border-color: rgba(245, 158, 11, 0.35);
  color: #ffffff;
}

.status-pill--success {
  background: rgba(34, 197, 94, 0.22);
  border-color: rgba(34, 197, 94, 0.34);
  color: #ffffff;
}

.status-pill--error {
  background: rgba(220, 38, 38, 0.22);
  border-color: rgba(220, 38, 38, 0.34);
  color: #ffffff;
}

.cursor-readout {
  font-family: var(--font-mono);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.92);
  white-space: nowrap;
}

.app-main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  overflow: hidden;
  background: var(--bg-page);
  border-top: 1px solid var(--border-soft);
}

.panel,
.map-panel {
  min-height: 0;
  background: var(--bg-surface);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.panel {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.panel--controls {
  width: 400px;
  min-width: 200px;
  max-width: 600px;
  flex-shrink: 0;
}

.map-panel {
  position: relative;
  flex: 1 1 auto;
  min-width: 360px;
  overflow: hidden;
  background: #dde7f3;
}

.panel--results {
  width: 600px;
  min-width: 400px;
  max-width: 800px;
  flex-shrink: 0;
}

.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 12px 12px;
  border: 0;
  border-bottom: 1px solid var(--border-soft);
  border-radius: 0;
  background: var(--bg-surface);
}

.panel-section:last-child {
  border-bottom: 0;
}

.panel-section--grow {
  min-height: 0;
  flex: 1 1 auto;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: -10px -12px 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-soft);
}

.section-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
}

.section-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.field-input,
.field-textarea {
  width: 100%;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--bg-surface);
  padding: 8px 10px;
  color: var(--text-main);
  font: inherit;
}

.field-input:focus,
.field-textarea:focus {
  outline: none;
  border-color: var(--brand-corporate);
  box-shadow: 0 0 0 3px rgba(47, 95, 167, 0.2);
}

.field-input--mono,
.overlay-value--mono,
.history-code,
.cursor-readout,
.step-list code,
.panel-note code {
  font-family: var(--font-mono);
}

.field-input--mono {
  font-size: 12px;
}

.field-textarea {
  resize: vertical;
}

.hillshade-range {
  padding: 4px 0;
  cursor: pointer;
  accent-color: var(--brand-corporate);
}

.geotiff-status {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--bg-soft);
  font-size: 12px;
}

.geotiff-status-empty {
  color: var(--text-muted);
}

.geotiff-status-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.geotiff-status-name {
  font-family: var(--font-mono);
  font-weight: 600;
}

.geotiff-status-state {
  color: var(--text-muted);
  white-space: nowrap;
}

/* ── Step info grid ── */
.step-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.step-info-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.step-info-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.step-info-value {
  font-size: 13px;
  font-weight: 700;
}

/* ── flow_dir buttons ── */
.flow-dir-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.flow-dir-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.flow-dir-group-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.flow-dir-btn {
  padding: 5px 8px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--text-main);
  font: inherit;
  font-size: 12px;
  font-family: var(--font-mono);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s, border-color 0.12s;
}

.flow-dir-btn:hover {
  background: var(--bg-soft);
  border-color: var(--brand-corporate);
}

.flow-dir-btn--active {
  background: rgba(255, 0, 255, 0.08);
  border-color: #ff00ff;
  box-shadow: inset 0 0 0 1px rgba(255, 0, 255, 0.18);
}

/* ── Health result (inline) ── */
.health-result {
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  transition: opacity 0.3s;
}

.health-result--ok {
  color: #15803d;
}

.health-result--error {
  color: #dc2626;
}

.health-toast {
  margin-top: 6px;
  padding: 5px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(34, 197, 94, 0.12);
  color: #15803d;
  border: 1px solid rgba(34, 197, 94, 0.3);
  opacity: 0;
  transition: opacity 0.3s;
}

.health-toast--visible {
  opacity: 1;
}

.health-toast--error {
  background: rgba(220, 38, 38, 0.1);
  color: #dc2626;
  border-color: rgba(220, 38, 38, 0.3);
}

.action-btn--primary {
  background: var(--brand-corporate);
  color: #ffffff;
  font-weight: 700;
  width: 100%;
}

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

.toggle-list {
  display: grid;
  gap: 8px;
}

.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 13px;
  line-height: 1.45;
}

.toggle-row input {
  margin-top: 2px;
  accent-color: var(--brand-corporate);
}

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

.action-btn,
.ghost-btn {
  padding: 6px 10px;
  border: 1px solid var(--brand-corporate);
  border-radius: 6px;
  background: var(--bg-surface);
  color: var(--brand-corporate);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.action-btn {
  flex: 1 1 auto;
  background: var(--brand-corporate);
  color: #ffffff;
}

.action-btn--secondary,
.ghost-btn {
  background: var(--bg-surface);
  color: var(--brand-corporate);
}

.action-btn:not(:disabled):hover {
  background: var(--brand-corporate-hover);
  border-color: var(--brand-corporate-hover);
}

.action-btn--secondary:not(:disabled):hover,
.ghost-btn:not(:disabled):hover {
  background: var(--bg-soft);
}

.action-btn:disabled,
.ghost-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.step-list {
  margin: 0;
  padding-left: 18px;
  color: var(--text-muted);
  line-height: 1.55;
}

.panel-note {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

.step-list code,
.panel-note code {
  font-size: 11px;
  background: #eef4ff;
  padding: 1px 4px;
  border-radius: 4px;
}

.map-container {
  position: absolute;
  inset: 0;
}

.map-overlay {
  position: absolute;
  z-index: 2;
  pointer-events: none;
}

.map-overlay.top-left {
  top: 12px;
  left: 12px;
}

.map-overlay.bottom-left {
  left: 12px;
  bottom: 12px;
}

.overlay-card {
  min-width: 180px;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.88);
  box-shadow: var(--shadow-soft);
}

.overlay-card--thin {
  min-width: 160px;
}

.overlay-label {
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.overlay-value {
  font-size: 12px;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.summary-card {
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--bg-soft);
}

.summary-card .summary-key {
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.summary-card .summary-value {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.4;
  word-break: break-word;
}

.summary-empty {
  grid-column: 1 / -1;
  padding: 12px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--bg-soft);
  color: var(--text-muted);
}

.history-count {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
}

.history-list {
  min-height: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: auto;
  padding-right: 2px;
}

.log-textarea {
  min-height: 0;
  flex: 1 1 auto;
  resize: none;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  background: var(--bg-soft);
  font-size: 12px;
}

.history-item {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--bg-surface);
  cursor: pointer;
}

.history-item:hover {
  background: var(--bg-soft);
}

.history-item--active {
  border-color: var(--brand-corporate);
  background: #f3f7ff;
  box-shadow: inset 0 0 0 1px rgba(47, 95, 167, 0.14);
}

.history-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.history-code {
  font-size: 12px;
  font-weight: 700;
}

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

.history-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.history-stat {
  padding: 6px 8px;
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  background: var(--bg-soft);
}

.history-stat-key {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.history-stat-value {
  margin-top: 3px;
  font-size: 12px;
  font-weight: 700;
  word-break: break-word;
}

.maplibregl-popup-content {
  border: 1px solid var(--border-soft);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: var(--font-main);
  box-shadow: var(--shadow-card);
}

.popup-title {
  margin-bottom: 4px;
  font-weight: 800;
}

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

/* ── Pane resizer ── */
.pane-resizer {
  flex-shrink: 0;
  width: 6px;
  cursor: col-resize;
  background: var(--border-soft);
  position: relative;
  z-index: 5;
  transition: background 0.15s;
}

.pane-resizer:hover,
.pane-resizer.active {
  background: var(--brand-corporate);
}

.resizer-tooltip {
  display: none;
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(47, 95, 167, 0.18);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
  pointer-events: none;
  z-index: 10;
}

.pane-resizer.active .resizer-tooltip {
  display: block;
}

body.resizing {
  cursor: col-resize !important;
  user-select: none;
}

body.resizing * {
  pointer-events: none !important;
}

body.resizing .pane-resizer {
  pointer-events: auto !important;
}

/* ── iOS-style toggle switch ── */
.ios-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.ios-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.ios-switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 24px;
  background: #ccc;
  cursor: pointer;
  transition: background 0.25s;
}

.ios-switch-slider::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.25s;
}

.ios-switch input:checked + .ios-switch-slider {
  background: var(--brand-corporate);
}

.ios-switch input:checked + .ios-switch-slider::before {
  transform: translateX(20px);
}

/* ── Station search box ── */
.station-search-box {
  padding: 0;
}

.station-search-box .field-input {
  font-size: 13px;
  padding: 6px 10px;
}

/* ── Station tree ── */
.station-tree {
  max-height: 130px;
  overflow-y: auto;
  overflow-x: hidden;
  font-size: 12px;
}

.station-tree-group {
  border-bottom: 1px solid var(--border-soft);
}

.station-tree-group:last-child {
  border-bottom: 0;
}

.station-tree-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 4px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
  color: var(--text-main);
  user-select: none;
  background: none;
  border: none;
  width: 100%;
  text-align: left;
  font-family: inherit;
}

.station-tree-head:hover {
  background: var(--bg-soft);
}

.station-tree-arrow {
  display: inline-block;
  width: 12px;
  text-align: center;
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.15s;
  flex-shrink: 0;
}

.station-tree-group.open > .station-tree-head .station-tree-arrow {
  transform: rotate(90deg);
}

.station-tree-count {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 11px;
  margin-left: auto;
}

.station-tree-items {
  display: none;
  padding: 0 0 4px 16px;
}

.station-tree-group.open > .station-tree-items {
  display: block;
}

.station-tree-item {
  padding: 3px 6px;
  cursor: pointer;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-main);
}

.station-tree-item:hover {
  background: var(--bg-soft);
}

.station-tree-item.active {
  background: rgba(47, 95, 167, 0.12);
  font-weight: 700;
  color: var(--brand-corporate);
}

.station-tree-empty {
  padding: 8px 4px;
  color: var(--text-muted);
  font-size: 12px;
}

/* ── Station info (right pane) ── */
.station-info-grid {
  grid-template-columns: repeat(3, 1fr);
  gap: 4px 12px;
}

.station-info-grid .step-info-label {
  white-space: nowrap;
}

.station-info-placeholder {
  color: var(--text-muted);
}

#app-footer {
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0 12px;
  background: var(--brand-corporate);
  color: #ffffff;
  font-size: 12px;
}

#app-footer small {
  opacity: 0.96;
}
