/* ダークテーマ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #1a1a2e;
  --panel:    #16213e;
  --border:   #0f3460;
  --accent:   #00d4ff;
  --accent2:  #e94560;
  --text:     #e0e0e0;
  --text-dim: #888;
  --good:     #00c853;
  --warn:     #ffab00;
  --error:    #e94560;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 13px;
}

/* ── エラーバナー ── */
#error-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--error);
  color: #fff;
  padding: 8px 16px;
  text-align: center;
  z-index: 9999;
  display: none;
}
#error-banner.visible { display: block; }

/* ── メインレイアウト ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
header h1 { font-size: 15px; color: var(--accent); letter-spacing: 0.05em; }

#status-bar {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 12px;
}

/* ── 中段（左パネル + 地図） ── */
#main-row {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── 左カラム（パネル＋固定ボタン） ── */
#side-column {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

/* ── 左パネル（スクロール可） ── */
#side-panel {
  flex: 1;
  background: var(--panel);
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* ── 操作ボタン（常に下部に表示） ── */
#side-actions {
  flex-shrink: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#side-actions button { width: 100%; }

.panel-section {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
}
.panel-section h3 {
  color: var(--accent);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 8px;
}

/* 探索中心 */
#search-center-info {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
#search-center-coords {
  font-family: monospace;
  color: var(--accent);
}

/* 周波数入力 */
.freq-row {
  display: flex;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.freq-row input[type="number"] {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 4px;
  font-size: 14px;
  font-family: monospace;
}
.freq-row input[type="number"]:focus {
  outline: none;
  border-color: var(--accent);
}
.unit { color: var(--text-dim); font-size: 11px; }

/* ボタン */
button {
  background: var(--border);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s;
}
button:hover { background: var(--accent); color: #000; }
button.primary {
  background: var(--accent);
  color: #000;
  font-weight: bold;
  width: 100%;
  padding: 8px;
}
button.primary:hover { background: #00b8d9; }
button.active { background: var(--accent2); border-color: var(--accent2); color: #fff; }

/* 公式TDoA 実行ボタン・状態表示 */
#btn-tdoa {
  margin-top: 6px;
  border-color: var(--accent2);
  color: var(--accent2);
  font-weight: bold;
}
#btn-tdoa:hover:not(:disabled) { background: var(--accent2); color: #fff; }
#btn-tdoa:disabled { opacity: .5; }
.tdoa-status {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.4;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
}

/* セレクト */
select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 5px 8px;
  border-radius: 4px;
  width: 100%;
  font-size: 12px;
}
select:focus { outline: none; border-color: var(--accent); }

label {
  display: block;
  color: var(--text-dim);
  font-size: 11px;
  margin-bottom: 3px;
}

/* モックモードトグル */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.toggle-row input[type="checkbox"] { accent-color: var(--accent); }

/* ノード一覧 */
#node-list { display: flex; flex-direction: column; gap: 4px; }
.node-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
}
.node-item.active { border-color: var(--good); }
.node-item.selected { border-color: var(--accent); }
.node-snr {
  font-family: monospace;
  color: var(--text-dim);
}
.node-snr.good { color: var(--good); }
.node-snr.warn { color: var(--warn); }

/* ── 地図 ── */
#map {
  flex: 1;
  z-index: 0;
}

/* ── 下パネル（タブ） ── */
#bottom-panel {
  flex-shrink: 0;
  background: var(--panel);
  border-top: 1px solid var(--border);
  height: 230px;
}

.tab-bar {
  display: flex;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
}
.tab-btn:hover { background: var(--panel); color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom: 2px solid var(--accent); background: var(--panel); }

.tab-content { display: none; height: calc(100% - 30px); }
.tab-content.active { display: flex; align-items: center; justify-content: center; }

/* 下部パネルの解析用キャンバスのみ暗背景（Leaflet地図/ヒートマップのcanvasには適用しない） */
#bottom-panel canvas {
  display: block;
  background: #0a0a1a;
}

/* ── メトリクスバー ── */
#metrics-bar {
  display: flex;
  gap: 16px;
  padding: 4px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.metric-item span { color: var(--accent); font-family: monospace; }

/* ウォーターフォール周波数カーソル */
#wf-freq-label {
  position: absolute;
  background: rgba(0, 212, 255, 0.85);
  color: #000;
  font-size: 11px;
  font-family: monospace;
  padding: 2px 5px;
  border-radius: 3px;
  pointer-events: none;
  display: none;
  z-index: 10;
}

/* ウォーターフォールタブ: ヘッダ＋キャンバスを縦積み */
#tab-waterfall.active { display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; }
#tab-waterfall canvas { width: 100%; flex: 1; }

#wf-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 3px 10px;
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
#wf-header #wf-station { color: var(--accent); font-weight: bold; }
#wf-zoom-ctl { margin-left: auto; display: flex; align-items: center; gap: 6px; }
#wf-zoom-ctl button {
  width: 24px; height: 22px; padding: 0;
  font-size: 15px; line-height: 1;
  background: #1a2740; color: #cfe8ff; border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer;
}
#wf-zoom-ctl button:hover { background: #24406a; }
#wf-zoom-level { font-family: monospace; min-width: 22px; text-align: center; }
#wf-range-ctl { display: flex; align-items: center; gap: 8px; }
#wf-range-ctl input {
  width: 52px; padding: 1px 3px;
  background: #1a2740; color: #cfe8ff;
  border: 1px solid var(--border); border-radius: 3px;
  font-size: 11px;
}
#wf-range-ctl button {
  padding: 2px 8px; font-size: 11px; line-height: 1.5;
  background: #1a2740; color: #cfe8ff; border: 1px solid var(--border);
  border-radius: 4px; cursor: pointer;
}
#wf-range-ctl button:hover { background: #24406a; }

/* 計算過程タブ */
#tab-calc.active { display: block; overflow-y: auto; }
#calc-content { padding: 8px 12px; font-size: 12px; line-height: 1.55; color: var(--text); }
#calc-content .calc-block { margin-bottom: 7px; padding-bottom: 6px; border-bottom: 1px solid var(--border); }
#calc-content b { color: var(--accent); }
