:root { --bg:#0f1419; --panel:#1a2230; --fg:#e6edf3; --muted:#8b97a7;
  --accent:#4fa3ff; --ok:#2ecc71; --warn:#f1c40f; --bad:#e74c3c;
  --card:#0f1620; --border:#29344a; --border2:#344256; --badge:#33405a; --grid:#23304a; }
/* ライトテーマ（サイト全体）。html.light で全変数を上書き */
html.light { --bg:#eef1f5; --panel:#ffffff; --fg:#1c2530; --muted:#5f6b7a;
  --accent:#2563eb; --ok:#1f9d57; --warn:#b07d00; --bad:#d23b2e;
  --card:#f6f8fb; --border:#dde3ea; --border2:#cfd6df; --badge:#e7ecf2; --grid:#dde3ec; }
* { box-sizing: border-box; }
body { margin:0; font-family: system-ui, "Segoe UI", "Hiragino Sans", sans-serif;
  background:var(--bg); color:var(--fg); }
header { display:flex; align-items:center; justify-content:space-between;
  padding:14px 22px; background:var(--panel); border-bottom:1px solid var(--border); }
header h1 { font-size:20px; margin:0; }
.brand { display:flex; align-items:center; gap:12px; cursor:pointer; }
.brand:hover { opacity:.85; }
.brand-logo { width:46px; height:46px; object-fit:contain; flex:none; }
.brand-text { display:flex; flex-direction:column; line-height:1.15; }
.brand-name { font-size:21px; font-weight:700; letter-spacing:.3px; }
.brand-sub { font-size:12px; color:var(--muted); font-weight:400; }
header nav { display:flex; align-items:center; gap:14px; }
.navlink { color:var(--accent); text-decoration:none; font-size:14px; }
.theme-btn { background:none; border:none; color:var(--fg); cursor:pointer;
  font-size:16px; line-height:1; padding:2px 4px; }
.navlink:hover { text-decoration:underline; }
.navlink.logout { color:var(--muted); }
header .user { color:var(--muted); font-size:13px; }
main { max-width:1280px; margin:0 auto; padding:18px; }
/* コンテナ（箱）は使わず、区切り線で各セクションを分ける */
.panel { padding:20px 0; border-top:1px solid var(--border); }
main > .panel:first-child { border-top:none; padding-top:6px; }
.panel h2 { margin:0 0 12px; font-size:16px; color:var(--accent); }
.controls { display:flex; gap:16px; align-items:center; flex-wrap:wrap; margin-bottom:12px; }
.controls select, .controls button { background:var(--card); color:var(--fg);
  border:1px solid var(--border2); border-radius:6px; padding:6px 10px; font-size:14px; }
.controls button { cursor:pointer; background:var(--accent); color:#04121f; border:none; font-weight:600; }
.cards { display:grid; grid-template-columns:repeat(auto-fill,minmax(200px,1fr)); gap:12px; }
/* デバイス欄：左（選択＋カード）／右（状態グラフ）の2カラム */
/* レイアウト: 折りたたみ式サイドバー ＋ 右コンテンツ */
.layout { display:flex; align-items:flex-start; }
.sidebar { flex:0 0 230px; background:var(--panel); border-right:1px solid var(--border);
  position:sticky; top:0; align-self:stretch; max-height:100vh; overflow:auto;
  transition:flex-basis .15s ease, width .15s ease; }
.sidebar.collapsed { flex-basis:0; width:0; border-right:none; overflow:hidden; }
.sidebar-head { padding:12px 14px; border-bottom:1px solid var(--border);
  font-weight:600; color:var(--accent); font-size:14px; white-space:nowrap; }
.sb-filter { padding:8px 12px; border-bottom:1px solid var(--border); font-size:12px;
  color:var(--muted); display:flex; align-items:center; gap:8px; }
.sb-filter select { flex:1; background:var(--card); color:var(--fg);
  border:1px solid var(--border2); border-radius:6px; padding:4px 8px; font-size:13px; }
.sb-list { list-style:none; margin:0; padding:6px; }
.sb-item { padding:9px 10px; border-radius:8px; cursor:pointer; display:flex;
  align-items:center; gap:9px; white-space:nowrap; }
.sb-item:hover { background:var(--card); }
.sb-item.active { background:var(--card); outline:1px solid var(--accent); }
.sb-item .sb-main { display:flex; flex-direction:column; min-width:0; gap:1px; }
.sb-item .nm { font-size:14px; }
.sb-item .sub { font-size:11px; color:var(--muted); }
.sb-item .sub2 { font-size:11px; color:var(--muted); }
.sb-item .sub2 .v { color:var(--fg); }
.sb-item .sub2 .warn { color:var(--warn); }
.sb-item .dot { width:8px; height:8px; border-radius:50%; flex:none; margin-left:-2px; }
.sb-empty { color:var(--muted); font-size:13px; padding:10px; }
.content { flex:1 1 auto; min-width:0; }
.header-left { display:flex; align-items:center; gap:8px; }
.hamburger { background:none; border:none; color:var(--fg); font-size:20px;
  cursor:pointer; line-height:1; }
.panel-head, .detail-head { display:flex; align-items:center; justify-content:space-between;
  gap:12px; flex-wrap:wrap; }
.panel-head h2, .detail-head h2 { margin:0; }
.collapse-btn { background:var(--card); color:var(--fg); border:1px solid var(--border);
  border-radius:6px; padding:5px 12px; cursor:pointer; font-size:13px; }
.map-panel.map-collapsed .map-wrap { display:none; }
/* 初期画面（デバイス未選択）：詳細セクションを隠し、代わりに俯瞰カードを表示。
   地図の高さは通常時(55vh)と揃える（下の俯瞰カードを見やすくするため拡大しない）。 */
body.no-selection #deviceSection { display:none; }
/* 俯瞰カード一覧：初期画面（未選択）でのみ表示。デバイス選択時は隠す。 */
#overviewSection { display:none; }
body.no-selection #overviewSection { display:block; }
.ov-cards { display:grid; grid-template-columns:repeat(auto-fill,minmax(260px,1fr)); gap:12px; margin-top:10px; }
.ov-card { background:var(--card); border:1px solid var(--border); border-radius:8px;
  padding:12px 14px; cursor:pointer; transition:border-color .12s, box-shadow .12s; }
.ov-card:hover { border-color:var(--accent); box-shadow:0 1px 6px rgba(0,0,0,.12); }
.ov-card.has-recent { border-color:var(--warn,#e0a800); }   /* 直近受信が波形/画像＝活動ありを強調 */
.ov-card .ov-top { display:flex; align-items:center; gap:8px; }
.ov-card .ov-top .dot { width:9px; height:9px; border-radius:50%; flex:none; }
.ov-card .ov-name { font-weight:600; flex:1 1 auto; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.ov-card .ov-id { font-size:11px; color:var(--muted); flex:none; }
.ov-card .ov-row { display:flex; justify-content:space-between; font-size:12px; margin-top:7px; color:var(--muted); }
.ov-card .ov-row span:last-child { color:var(--fg); }
.ov-card .ov-vitals { display:flex; gap:12px; flex-wrap:wrap; font-size:13px; margin-top:8px; }
.ov-card .ov-vitals .vt { white-space:nowrap; }
.ov-card .ov-event { margin-top:9px; padding-top:8px; border-top:1px dashed var(--border);
  font-size:12px; color:var(--warn,#e0a800); }
.ov-card .ov-event b { color:var(--fg); }
.ov-empty { color:var(--muted); font-size:13px; padding:6px 2px; }
.detail-head { justify-content:flex-end; }   /* タイトル無し→期間/更新を右寄せ */
.detail-head .controls { margin-bottom:0; }
.detail-layout { display:flex; gap:16px; align-items:stretch; margin-top:10px; }
.detail-left { flex:0 0 240px; }
.detail-left #accelPanel { margin-top:12px; }   /* カードの下に加速度 */
.detail-right { flex:1 1 auto; min-width:0; display:flex; flex-direction:column; }
.chart-box { position:relative; flex:1 1 auto; min-height:260px; }  /* カードの右に全高グラフ */
/* グラフのドリルダウン操作行（ズームアウト／全体／表示範囲）。既存 .controls と
   同じ部品感にしつつ、更新/CSV より従属に見えるよう accent ではなく card 地に。 */
.chart-tools { display:flex; align-items:center; gap:8px; flex-wrap:wrap;
  margin-bottom:6px; font-size:12px; color:var(--muted); }
.chart-tools button { background:var(--card); color:var(--fg);
  border:1px solid var(--border2); border-radius:6px; padding:4px 10px;
  font-size:12px; cursor:pointer; }
.chart-tools button:hover:not(:disabled) { border-color:var(--accent); }
.chart-tools button:disabled { opacity:.45; cursor:default; }
.chart-tools .range-label { margin-left:auto; }
.chart-tools .range-label b { color:var(--fg); font-weight:600; }
/* 2枚目（傾き）のグラフ。1枚目より低くして、上を主・下を従に見せる。 */
.chart-box-sub { flex:0 0 auto; height:190px; min-height:190px; }
/* 2枚目の見出し。グラフ自体に凡例があるので、名前と注釈だけの控えめな行。 */
.chart-caption { margin-top:12px; margin-bottom:2px; font-size:12px; font-weight:600;
  color:var(--muted); display:flex; align-items:center; }
/* 左カラムへ移した RTC誤差／リセット要因は、加速度リストの下に少し離して置く。 */
.detail-left .rtc-drift { margin-top:12px; }
/* 操作方法の注記。グラフ直下、rtc-drift と同じ体裁。 */
.chart-hint { margin-top:6px; font-size:11px; line-height:1.5; color:var(--muted); }
@media (max-width:820px){
  /* 指ではドラッグ選択がページスクロールと競合するため、案内文を差し替える
     （JS 側も gestures.drag=false / panModifier=null に切り替える）。 */
  .chart-tools .range-label { margin-left:0; flex-basis:100%; }
}
.hidden-select { display:none; }
@media (max-width:820px){ .detail-layout { flex-direction:column; } .detail-left { flex:auto; } }
@media (max-width:820px){ .sidebar { position:static; max-height:none; } }
.card { background:var(--card); border:1px solid var(--border); border-radius:8px; padding:12px 14px; }
.card .name { font-weight:600; }
.card .metric { display:flex; justify-content:space-between; font-size:13px; margin-top:6px; }
.card .metric span:first-child { color:var(--muted); }
.cards-hint { color:var(--muted); font-size:13px; padding:6px 2px; }
/* 加速度3軸テーブル（瞬時/補正/絶対） */
#accelPanel { margin-top:12px; }
.accel-title { font-size:13px; color:var(--accent); margin-bottom:6px; }
.accel-table { width:100%; border-collapse:collapse; font-size:12px;
  font-variant-numeric:tabular-nums; }
.accel-table th, .accel-table td { padding:4px 6px; border-bottom:1px solid var(--border);
  text-align:right; }
.accel-table th:first-child, .accel-table td:first-child { text-align:left; color:var(--muted); }
.accel-table th { color:var(--muted); font-weight:600; }
.badge { padding:4px 10px; border-radius:14px; font-size:13px; background:var(--badge); }
.badge.ok { background:var(--ok); color:#04121f; }
.badge.bad { background:var(--bad); }
.badge.warn { background:var(--warn); color:#04121f; }
table { width:100%; border-collapse:collapse; font-size:14px; }
th, td { text-align:left; padding:8px 10px; border-bottom:1px solid var(--border); }
th { color:var(--muted); font-weight:600; }
tr:hover td { background:var(--card); }
td button { background:var(--accent); color:#04121f; border:none; border-radius:5px;
  padding:4px 10px; cursor:pointer; }
.q1 { color:var(--ok); } .q2 { color:var(--warn); } .q3 { color:var(--bad); }
.sev-critical { color:var(--bad); font-weight:700; }
.sev-error { color:var(--bad); } .sev-warning { color:var(--warn); } .sev-info { color:var(--muted); }
/* ヘルプアイコン(?)＋ホバーで解説ツールチップ */
.info-tip { position:relative; display:inline-flex; align-items:center; justify-content:center;
  width:14px; height:14px; margin-left:5px; border-radius:50%;
  background:var(--badge); color:var(--muted); border:1px solid var(--border2);
  font-size:10px; font-weight:700; line-height:1; cursor:help; vertical-align:middle; }
.info-tip:hover { color:var(--fg); border-color:var(--accent); }
.info-tip::after { content:attr(data-tip);
  position:absolute; top:calc(100% + 8px); left:50%; transform:translateX(-50%);
  width:max-content; max-width:280px; white-space:pre-line; text-align:left;
  background:var(--card); color:var(--fg); border:1px solid var(--border2); border-radius:8px;
  padding:8px 11px; font-size:12px; font-weight:400; line-height:1.5;
  box-shadow:0 6px 20px rgba(0,0,0,.35); z-index:60;
  opacity:0; visibility:hidden; transition:opacity .12s ease; pointer-events:none; }
.info-tip::before { content:""; position:absolute; top:calc(100% + 2px); left:50%;
  transform:translateX(-50%); border:6px solid transparent; border-bottom-color:var(--border2);
  opacity:0; visibility:hidden; transition:opacity .12s ease; z-index:61; }
.info-tip:hover::after, .info-tip:hover::before { opacity:1; visibility:visible; }
footer { text-align:center; color:var(--muted); padding:18px; font-size:12px; }
footer a { color:var(--accent); text-decoration:none; }
footer a:hover { text-decoration:underline; }
small { color:var(--muted); font-weight:400; }

/* 地点マップ（コンテンツ内パネル） */
.map-wrap { position:relative; width:100%; }
#map { height:55vh; min-height:340px; width:100%; background:var(--card);
  border:1px solid var(--border); border-radius:8px; }
/* ダークモード: サイトのテーマ(html.dark)に連動。GSIタイルを反転して夜用に
   （マーカー/凡例/コントロールは非反転）*/
html.dark #map { background:#0a0f17; }
html.dark #map .leaflet-tile-pane { filter:invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); }
/* 凡例：マップ右上、ズームコントロールの左に重ねて表示 */
.map-legend { position:absolute; top:10px; right:52px; z-index:1000; margin:0;
  display:flex; gap:14px; font-size:12px; color:var(--fg); pointer-events:none;
  background:var(--panel); border:1px solid var(--border); border-radius:6px;
  padding:6px 10px; box-shadow:0 1px 4px rgba(0,0,0,.2); }
.map-legend i.dot { display:inline-block; width:10px; height:10px; border-radius:50%;
  margin-right:5px; vertical-align:middle; }
.map-legend i.dot.on { background:var(--ok); }
.map-legend i.dot.off { background:var(--muted); }
.map-legend i.dot.warn { background:var(--warn); }
/* Leaflet の divIcon マーカー */
.site-marker { width:18px; height:18px; border-radius:50%; border:2px solid #04121f;
  box-shadow:0 0 0 2px rgba(255,255,255,.25); }
.site-marker.on { background:var(--ok); }
.site-marker.off { background:var(--muted); }
.site-marker.warn { background:var(--warn); }
/* カメラのデバイスマーカーは 📷 バッジで地震計と区別（色はオンライン状態を維持） */
.site-marker.cam { position:relative; }
.site-marker.cam::after { content:"📷"; position:absolute; left:50%; top:-15px;
  transform:translateX(-50%); font-size:12px; line-height:1; pointer-events:none; }
/* 選択中の地点を強調（個別デバイス選択時にマップが追従して点灯） */
.site-marker.selected { box-shadow:0 0 0 3px var(--accent), 0 0 10px 3px var(--accent);
  transform:scale(1.3); z-index:1000; }
/* Leaflet ポップアップをダークテーマに */
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background:var(--panel); color:var(--fg);
  border:1px solid var(--border); }
.leaflet-popup-content { margin:10px 12px; font-size:13px; }
.leaflet-popup-content b { color:var(--accent); }
.leaflet-popup-content .pin-row { display:flex; justify-content:space-between; gap:14px;
  margin-top:3px; }
.leaflet-popup-content .pin-row span:first-child { color:var(--muted); }
.leaflet-popup-content button { background:var(--accent); color:#04121f; border:none;
  border-radius:5px; padding:4px 10px; margin-top:8px; cursor:pointer; font-weight:600; }
.leaflet-container { font:inherit; }
/* 右上のカスタムツールボタン（現在地/リセット）。ズームバーの直下に配置 */
.map-tools { margin-top:8px; }
.map-tools a { font-size:15px; line-height:26px; text-align:center; text-decoration:none; }

/* カメラパネル */
.cam-sub { color:var(--muted); font-size:12px; margin:12px 0 6px; }
.cam-latest img { max-width:100%; max-height:360px; border-radius:8px; border:1px solid var(--border);
  cursor:zoom-in; }
.cam-latest .cap { color:var(--muted); font-size:12px; margin-top:4px; }
.cam-thumbs { display:flex; flex-wrap:wrap; gap:8px; }
.cam-thumbs img { width:120px; height:80px; object-fit:cover; border-radius:6px;
  border:1px solid var(--border); cursor:zoom-in; }
.cam-videos { display:flex; flex-wrap:wrap; gap:10px; }
.cam-videos .vid { width:240px; }
.cam-videos video { width:240px; border-radius:6px; border:1px solid var(--border); background:#000; }
.cam-videos .cap { color:var(--muted); font-size:12px; margin-top:3px; }
.cam-empty { color:var(--muted); font-size:13px; }
/* ライトボックス */
.lightbox { position:fixed; inset:0; background:rgba(0,0,0,.85); z-index:1000;
  display:flex; align-items:center; justify-content:center; }
#lightboxBody img, #lightboxBody video { max-width:92vw; max-height:88vh; border-radius:6px; }
.lightbox-close { position:fixed; top:14px; right:22px; color:#fff; font-size:34px;
  cursor:pointer; line-height:1; }

/* RTC校正ドリフト表示（statusChart 下のサマリ／外れ値警告） */
.rtc-drift { margin-top:6px; font-size:12px; line-height:1.5; min-height:18px; }
.rtc-drift .rtc-ok { color:var(--muted); }
.rtc-drift b { font-weight:600; }
/* リセット要因サマリ（WDT自動復旧の回数・履歴）。rtc-drift と同じ体裁。 */
.rst-info { margin-top:4px; font-size:12px; line-height:1.5; }
.rst-info .rst-ok { color:var(--muted); }
.rst-info b { font-weight:600; }
/* 俯瞰カードのリセット要因タグ：WDT(異常自動復旧)を赤で強調。 */
.ov-card .ov-vitals .vt-warn { color:var(--bad); font-weight:600; }

/* ドロワー背景（オーバーレイ）。スマホでドロワー表示中のみ display:block にする。 */
/* z-index は Leaflet のペイン/コントロール(最大~461)やマップ凡例/選択マーカー(1000)より
   上に置く必要がある。さもないと地図がドロワーの前面に被さってメニューが隠れる。 */
.sidebar-backdrop { display:none; position:fixed; inset:0; z-index:1900;
  background:rgba(0,0,0,.5); }

/* ===== スマホ最適化（iPhone標準 375〜430px ／ 〜560px）=====
   既存の 820px(タブレット)分岐より後に置き、≤560px で上書きする。 */
@media (max-width:560px){
  /* ヘッダーをコンパクトに。項目が多いので折り返し許可。 */
  header { padding:10px 14px; flex-wrap:wrap; gap:8px 10px; }
  .brand-logo { width:36px; height:36px; }
  .brand-name { font-size:18px; }
  .brand-sub { font-size:11px; }
  header nav { gap:10px; flex-wrap:wrap; justify-content:flex-end; }
  header .user { display:none; }                  /* 省スペースのため非表示 */
  .badge { font-size:12px; padding:3px 8px; }
  .hamburger { font-size:24px; padding:2px 6px; } /* タップ領域を確保 */
  main { padding:12px; }

  /* デバイス一覧サイドバーをオフキャンバス・ドロワー化（既定は画面外） */
  .layout { display:block; }
  .sidebar {
    position:fixed; top:0; left:0; z-index:2000; flex:none;
    width:80%; max-width:300px; height:100vh; height:100dvh; max-height:none;
    border-right:1px solid var(--border); box-shadow:2px 0 18px rgba(0,0,0,.45);
    transform:translateX(-100%); transition:transform .22s ease; }
  .sidebar.open { transform:translateX(0); }      /* ハンバーガーで開く */
  .sidebar.collapsed { width:80%; border-right:1px solid var(--border); overflow:auto; }
  body.sb-open { overflow:hidden; }               /* ドロワー表示中は背面スクロール固定 */
  body.sb-open .sidebar-backdrop { display:block; }

  /* カード・俯瞰は1列、詳細は縦積み */
  .cards, .ov-cards { grid-template-columns:1fr; }
  .detail-left { flex:auto; }
  .chart-box { min-height:240px; }

  /* 地図は低めに。凡例は地図上に重ねず下へ回す（指で隠れない）。 */
  #map { height:46vh; min-height:240px; }
  .map-legend { position:static; margin:8px 0 0; justify-content:center;
    flex-wrap:wrap; pointer-events:auto; }

  /* 横長テーブルは潰さず横スクロール（指でスワイプ） */
  .table-wrap { overflow-x:auto; -webkit-overflow-scrolling:touch; }
  #eventsTable, #alertsTable { min-width:480px; }

  /* カメラ画像/動画は全幅 */
  .cam-videos .vid, .cam-videos video { width:100%; max-width:320px; }
  .cam-thumbs img { width:30vw; height:20vw; }
}

/* ── 地震速報ティッカー（ヘッダ直下） ── */
.quake-ticker { display:flex; align-items:center; gap:10px; background:var(--card);
  border-bottom:1px solid var(--border); padding:5px 12px; font-size:13px; overflow:hidden; }
.qt-label { color:var(--muted); white-space:nowrap; flex:none; font-weight:600; }
.qt-src { color:var(--muted); white-space:nowrap; flex:none; font-size:11px; }
.qt-viewport { overflow:hidden; flex:1 1 auto; }
.qt-track { display:inline-block; white-space:nowrap; will-change:transform;
  animation:qt-scroll linear infinite; }
.qt-viewport:hover .qt-track { animation-play-state:paused; }
.qt-item { margin-right:44px; }
.qt-item .qt-mag { color:var(--accent); font-weight:600; }
.qt-item .qt-int { font-weight:600; }
@keyframes qt-scroll { from { transform:translateX(0); } to { transform:translateX(-50%); } }
@media (prefers-reduced-motion: reduce) {
  .qt-track { animation:none; }
  .qt-viewport { overflow-x:auto; }
}

/* モバイルではティッカーを小さめに（他の文字と同程度）。
   基本 .quake-ticker ルールより後ろに置いて確実に上書きする。 */
@media (max-width:560px) {
  .quake-ticker { font-size:11px; gap:6px; padding:4px 10px; }
  .qt-src { font-size:10px; }
  .qt-item { margin-right:28px; }
}
