/* 水際の番人 ダッシュボードの見た目
   まずはシンプルに。色や配置は自由に変えてOK！ */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  background: #f0f4f8;
  color: #1a202c;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- ヘッダー ---------- */
header {
  background: #1e3a8a;   /* 濃い青 */
  color: white;
  padding: 12px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
header h1 { font-size: 20px; }

/* ヘッダー右側（音ボタン＋接続ランプ）を横並びにする */
.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

/* WebSocketの接続状態ランプ */
.status.online  { color: #4ade80; }  /* 緑 = 接続中 */
.status.offline { color: #f87171; }  /* 赤 = 切断 */

/* 警報音のON/OFFボタン */
#sound-toggle {
  font-family: inherit;
  font-size: 12px;
  padding: 5px 12px;
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: 999px;   /* 丸い形にする */
  background: transparent;
  color: white;
  cursor: pointer;
  white-space: nowrap;
}
#sound-toggle:hover { background: rgba(255, 255, 255, 0.15); }
/* 有効になったら緑にして、ひと目で分かるようにする */
#sound-toggle.sound-on { border-color: #4ade80; color: #4ade80; }

/* ---------- メインの2カラムレイアウト ---------- */
.container {
  flex: 1;
  display: grid;
  grid-template-columns: 2fr 1fr;   /* 左(地図):右(タイムライン) = 2:1 */
  gap: 12px;
  padding: 12px;
  min-height: 0;   /* これがないと中身が伸びてスクロールが壊れる */
}

.map-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

/* ---------- 地図（S-2 / S-4） ---------- */
#map {
  flex: 1;
  min-height: 300px;
  border-radius: 12px;
  background: white;
  z-index: 0;   /* Leafletがヘッダーやポップアップより前に出ないように */
}

/* タブ（現在地図 ⇔ 危険箇所マップ） */
.map-tabs { display: flex; gap: 6px; }
.tab {
  font-family: inherit;
  font-size: 13px;
  padding: 7px 16px;
  border: 1px solid #cbd5e1;
  border-radius: 8px 8px 0 0;
  background: #e2e8f0;
  color: #475569;
  cursor: pointer;
}
.tab.active {
  background: white;
  color: #1e3a8a;
  font-weight: bold;
  border-bottom-color: white;
}

/* 地図の下の凡例 */
.legend {
  font-size: 12px;
  color: #475569;
  background: white;
  border-radius: 8px;
  padding: 6px 12px;
}
.legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin: 0 4px 0 10px;
  vertical-align: middle;
}
.legend .dot:first-child { margin-left: 0; }

/* ---------- タイムライン ----------
   ここから下は、タイムラインを実装したときに使えるスタイルを用意してある。
   <ul id="timeline"> に <li class="confirmed"> のように種類名のclassを
   付けるだけで色分けが効く。 */
.timeline-area {
  background: white;
  border-radius: 12px;
  padding: 16px;
  overflow-y: auto;   /* 件数が増えたらスクロール */
}
.timeline-area h2 { font-size: 16px; margin-bottom: 10px; }

#timeline { list-style: none; }
#timeline li {
  padding: 8px 10px;
  border-left: 4px solid #cbd5e1;
  margin-bottom: 6px;
  background: #f8fafc;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  line-height: 1.5;
}

/* イベントの種類ごとに左の線の色を変える */
#timeline li.confirmed  { border-left-color: #dc2626; background: #fef2f2; } /* 赤 = 転落確定 */
#timeline li.suspect    { border-left-color: #ea580c; }                       /* 橙 = 第1報 */
#timeline li.wobble     { border-left-color: #eab308; }                       /* 黄 = ふらつき */
#timeline li.minor_fall { border-left-color: #f97316; }                       /* 橙 = 軽微転落 */

#timeline li .time { color: #64748b; font-size: 11px; }
/* ユニット名・センサーの証拠・電池残量を小さく添える行 */
#timeline li .meta { color: #475569; font-size: 11px; margin-top: 2px; }

/* 新着イベントをふわっと目立たせるアニメーション */
@keyframes flash {
  from { background: #fde68a; }
  to   { background: #f8fafc; }
}
#timeline li.new { animation: flash 2s ease-out; }

footer { padding: 0 12px 12px; }

/* ---------- デバイス状態（S-6） ---------- */
.device-status {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.device-card {
  flex: 1;
  min-width: 220px;
  background: white;
  border-radius: 10px;
  padding: 10px 14px;
  border-left: 4px solid #cbd5e1;
}
.device-card.online  { border-left-color: #22c55e; }  /* 緑 = オンライン */
.device-card.offline { border-left-color: #94a3b8; }  /* 灰 = オフライン */
.device-name { font-size: 13px; font-weight: bold; }
.device-meta { font-size: 12px; color: #475569; margin-top: 2px; }
.device-meta.batt-low { color: #dc2626; font-weight: bold; }  /* 電池20%未満は赤 */

/* ============================================================
   スマホ・タブレット対応（画面幅700px以下のときだけ適用）

   @media は「条件を満たすときだけ効くCSS」を書く仕組み。
   ここに書いた指定は幅700px以下でしか適用されないので、
   PCでの見た目は一切変わらない。

   考え方: PCは「画面に収める」レイアウト（左右2カラム・高さ100vh）だが、
   スマホでは「縦に並べてページごとスクロール」に切り替える。
   ============================================================ */
@media (max-width: 700px) {

  /* 画面の高さに押し込むのをやめ、内容の分だけ縦に伸ばす */
  body { height: auto; min-height: 100vh; }

  /* ヘッダー: 文字を小さくし、入りきらなければ折り返す */
  header {
    padding: 10px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  header h1 { font-size: 16px; }
  .header-right { gap: 10px; }
  #sound-toggle { font-size: 11px; padding: 4px 10px; }
  .status { font-size: 12px; }

  /* 本体: grid（左右2カラム）をやめて、上から順に縦積みにする */
  .container {
    display: block;
    padding: 8px;
  }
  .map-area { margin-bottom: 8px; }

  /* プレースホルダーが縦に伸びすぎないよう控えめにする */
  .placeholder { padding: 14px; min-height: 150px; }
  .placeholder p { font-size: 15px; }
  .placeholder .hint { font-size: 12px; line-height: 1.7; }
  .placeholder.small { flex: none; min-height: 90px; }

  /* タイムライン: 高さを画面の55%に固定し、その枠の中だけでスクロールさせる。
     こうしないとイベントが増えるほどページが縦に伸び、下のデバイス状態まで
     延々スクロールする羽目になる。
     スクロールを <ul> 側に付けているので、「イベントタイムライン」の見出しは
     動かずに残り、リストだけが中で動く。 */
  .timeline-area {
    overflow-y: visible;   /* 外枠はページに任せる */
    padding: 12px;
  }
  #timeline {
    max-height: 55vh;            /* vh = 画面の高さに対する% */
    overflow-y: auto;            /* はみ出したらこの中でスクロール */
    overscroll-behavior: contain; /* 端まで来てもページ側が動かないようにする */
    border: 1px solid #e2e8f0;   /* スクロールする領域だと見て分かるように */
    border-radius: 8px;
    padding: 6px;
  }

  /* 指で読める文字サイズに上げる */
  #timeline li { font-size: 14px; padding: 10px 12px; }
  #timeline li .time { font-size: 12px; }
  #timeline li .meta { font-size: 12px; }

  footer { padding: 0 8px 8px; }
}
