/* =========================================================
   共通スタイル（ダークモード基調）
   色はすべてカスタムプロパティで定義し、night-mode.css で上書きする。
   ========================================================= */

:root {
  --bg: #0b1020;
  --surface: #121a2e;
  --surface-2: #18223a;
  --surface-3: #1f2b47;
  --border: #26324d;
  --text: #e6ebf5;
  --text-dim: #9aa6bf;
  --text-faint: #6b7792;
  --accent: #6ea8ff;
  --accent-strong: #3d84f5;

  --safe: #3ecf8e;
  --warn: #f5c542;
  --danger: #ff5c5c;
  --day-shade: rgba(255, 214, 102, 0.06);

  /* グラフ系列 */
  --c-cloud-total: #d5dde9;
  --c-cloud-low: #7d8fae;
  --c-cloud-mid: #5f9ee0;
  --c-cloud-high: #b59cff;
  --c-wind-10: #4fd1c5;
  --c-wind-80: #f6ad55;
  --c-wind-120: #fc8181;
  --c-gust: #fbd38d;
  --c-grid: rgba(154, 166, 191, 0.14);
  --c-cursor: rgba(230, 235, 245, 0.75);

  --radius: 12px;
  --radius-sm: 8px;
  --gap: 14px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Menlo", "Consolas", monospace;
}

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

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 700;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

/* ---------- ヘッダー ---------- */

.app-header {
  position: sticky;
  top: 0;
  z-index: 1100;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  flex: none;
  border-radius: 7px;
}

.brand-title {
  font-size: 16px;
  letter-spacing: 0.02em;
}

.brand-sub {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0 8px;
  color: var(--text-dim);
  font-size: 12px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.data-status {
  color: var(--text-dim);
  font-size: 12px;
}

.data-status[data-kind="cache"],
.data-status[data-kind="dummy"] {
  color: var(--warn);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn:hover {
  background: var(--surface-3);
  border-color: var(--accent);
}

.btn:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: progress;
}

.btn-night-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #b3261e;
  box-shadow: 0 0 6px #b3261e;
}

/* ---------- レイアウト ---------- */

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: var(--gap);
  padding: var(--gap) max(16px, env(safe-area-inset-right)) var(--gap) max(16px, env(safe-area-inset-left));
  max-width: 1600px;
  margin: 0 auto;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 0;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 10px;
}

.card-head h2 {
  font-size: 14px;
}

.card-head h2 small {
  margin-left: 6px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 400;
}

.card-time {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
}

.side {
  display: grid;
  gap: var(--gap);
  align-content: start;
  min-width: 0;
}

@media (min-width: 1024px) {
  .layout {
    grid-template-columns: minmax(0, 1.85fr) minmax(320px, 1fr);
  }

  .timeline-card {
    grid-column: 1 / -1;
  }
}

/* ---------- 地図 ---------- */

.map-card {
  position: relative;
  overflow: hidden;
  padding: 0;
}

.map {
  width: 100%;
  height: 58vh;
  min-height: 340px;
  background: #0a0f1c;
}

@media (min-width: 1024px) {
  .map {
    height: 100%;
    min-height: 560px;
  }
}

.leaflet-container {
  font-family: var(--font);
}

.leaflet-control-attribution {
  font-size: 10px;
}

.loc-popup {
  font-size: 12px;
  line-height: 1.5;
}

.loc-popup strong {
  font-size: 13px;
}

.popup-btn {
  margin-top: 6px;
  min-height: 30px;
  background: var(--accent-strong);
  border-color: var(--accent);
  color: #fff;
  font-size: 12px;
}

/* 風流線のカーソル値表示（leaflet-velocity） */
.leaflet-control-velocity {
  background: color-mix(in srgb, var(--surface) 90%, transparent) !important;
  color: var(--text) !important;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px !important;
  font-size: 11px;
}

/* ---------- レイヤーパネル ---------- */

.layer-panel {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  width: min(290px, calc(100% - 64px));
  max-height: calc(100% - 20px);
  overflow: auto;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 12px;
}

.layer-panel:empty {
  display: none;
}

.layer-panel-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.layer-panel-toggle::after {
  content: "▾";
  color: var(--text-dim);
  transition: transform 0.15s;
}

.layer-panel[data-collapsed="true"] .layer-panel-toggle::after {
  transform: rotate(-90deg);
}

.layer-panel[data-collapsed="true"] .layer-panel-body {
  display: none;
}

.layer-panel-body {
  display: grid;
  gap: 12px;
  padding: 0 12px 12px;
}

.layer-group-title {
  margin: 0 0 6px;
  color: var(--text-dim);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.base-options {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.chip {
  position: relative;
}

.chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.chip span {
  display: inline-block;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  cursor: pointer;
}

.chip input:checked + span {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 22%, var(--surface-2));
  color: var(--text);
}

.chip input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.layer-row {
  display: grid;
  gap: 4px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.layer-row-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.layer-name {
  font-weight: 700;
}

.layer-meta {
  color: var(--text-faint);
  font-size: 11px;
}

.opacity-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.opacity-row input[type="range"] {
  flex: 1;
}

.opacity-value {
  width: 34px;
  text-align: right;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.layer-row[data-visible="false"] .opacity-row,
.layer-row[data-visible="false"] .layer-extra {
  opacity: 0.45;
}

/* トグルスイッチ */
.switch {
  position: relative;
  display: inline-block;
  flex: none;
  width: 36px;
  height: 20px;
}

.switch input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.switch-track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  transition: background 0.15s;
  pointer-events: none;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s, background 0.15s;
}

.switch input:checked + .switch-track {
  background: var(--accent-strong);
  border-color: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(16px);
  background: #fff;
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.layer-extra {
  display: flex;
  align-items: center;
  gap: 8px;
}

.select {
  flex: 1;
  min-height: 28px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.wind-legend {
  display: flex;
  gap: 2px;
  margin-top: 2px;
}

.wind-legend span {
  flex: 1;
  padding: 1px 0 0;
  border-top: 4px solid var(--legend-color);
  color: var(--text-faint);
  font-size: 10px;
  text-align: center;
}

input[type="range"] {
  accent-color: var(--accent);
  min-height: 20px;
}

/* ---------- 評価カード ---------- */

.eval-card,
.next-card,
.timeline-card {
  padding: 14px 16px;
}

.eval-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-badge {
  display: inline-grid;
  place-items: center;
  min-width: 112px;
  height: 64px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background: var(--surface-2);
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.status-badge[data-status="SAFE"] {
  color: var(--safe);
  border-color: var(--safe);
  background: color-mix(in srgb, var(--safe) 14%, var(--surface));
}

.status-badge[data-status="WARN"] {
  color: var(--warn);
  border-color: var(--warn);
  background: color-mix(in srgb, var(--warn) 14%, var(--surface));
}

.status-badge[data-status="DANGER"] {
  color: var(--danger);
  border-color: var(--danger);
  background: color-mix(in srgb, var(--danger) 14%, var(--surface));
}

.eval-metric {
  display: grid;
  gap: 2px;
}

.metric-label {
  color: var(--text-dim);
  font-size: 12px;
}

.metric-value {
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}

.metric-value small {
  margin-left: 3px;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 400;
}

.metric-note {
  color: var(--text-faint);
  font-size: 12px;
}

.eval-reason {
  margin: 10px 0 8px;
  color: var(--text-dim);
  font-size: 13px;
}

.wind-table {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin: 0;
}

.wind-table > div {
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border-left: 3px solid var(--level-color, var(--border));
}

.wind-table dt {
  color: var(--text-faint);
  font-size: 11px;
}

.wind-table dd {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.wind-table dd small {
  margin-left: 2px;
  color: var(--text-faint);
  font-size: 10px;
  font-weight: 400;
}

.score-ring {
  --score: 0;
  --ring-color: var(--accent);
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 76px;
  height: 76px;
  border-radius: 50%;
  background: conic-gradient(var(--ring-color) calc(var(--score) * 1%), var(--surface-3) 0);
  font-size: 24px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.score-ring::before {
  content: "";
  position: absolute;
  inset: 7px;
  border-radius: 50%;
  background: var(--surface);
}

.score-ring > span {
  position: relative;
}

.cloud-bars {
  display: grid;
  gap: 5px;
}

.cloud-bar {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) 40px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.cloud-bar-label {
  color: var(--text-dim);
}

.cloud-bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}

.cloud-bar-fill {
  height: 100%;
  width: calc(var(--value, 0) * 1%);
  background: var(--bar-color, var(--accent));
  border-radius: 999px;
  transition: width 0.25s;
}

.cloud-bar-value {
  text-align: right;
  font-family: var(--font-mono);
}

.next-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 13px;
}

.next-list li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.next-list .next-label {
  color: var(--text-dim);
}

.next-list .next-value {
  font-weight: 700;
  text-align: right;
}

/* ---------- タイムライン ---------- */

.timeline-head {
  align-items: center;
}

.hour-control {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  flex: 1 1 360px;
  justify-content: flex-end;
}

.hour-label {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
}

.hour-label strong {
  color: var(--text);
  font-size: 13px;
}

#hour-slider {
  flex: 1 1 220px;
  max-width: 520px;
}

.chart-wrap {
  position: relative;
  height: 320px;
}

@media (max-width: 640px) {
  .chart-wrap {
    height: 260px;
  }
}

.hour-strip {
  display: grid;
  grid-template-columns: repeat(48, minmax(0, 1fr));
  gap: 1px;
  margin-top: 8px;
}

.hour-cell {
  display: grid;
  grid-template-rows: 10px 10px;
  gap: 1px;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.hour-cell span {
  display: block;
  border-radius: 2px;
}

.hour-cell .cell-drone[data-status="SAFE"] { background: var(--safe); }
.hour-cell .cell-drone[data-status="WARN"] { background: var(--warn); }
.hour-cell .cell-drone[data-status="DANGER"] { background: var(--danger); }

.hour-cell .cell-star {
  background: color-mix(in srgb, var(--c-cloud-high) calc(var(--score, 0) * 1%), var(--surface-3));
}

.hour-cell[data-day="1"] .cell-star {
  background: var(--surface-3);
  opacity: 0.5;
}

.hour-cell[aria-current="true"] {
  outline: 2px solid var(--text);
  outline-offset: 1px;
  border-radius: 2px;
}

.strip-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin-top: 6px;
  color: var(--text-faint);
  font-size: 11px;
}

.strip-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  margin-right: 4px;
  border-radius: 2px;
  vertical-align: -1px;
  background: var(--legend-color);
}

.source-note {
  margin: 8px 0 0;
  color: var(--text-faint);
  font-size: 11px;
}

/* ---------- フッター ---------- */

.app-footer {
  max-width: 1600px;
  margin: 0 auto;
  padding: 4px 16px 24px;
  color: var(--text-faint);
  font-size: 11px;
}

/* ---------- トースト ---------- */

.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 2000;
  display: grid;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 13px;
  pointer-events: auto;
  animation: toast-in 0.2s ease-out;
}

.toast[data-kind="error"] { border-left-color: var(--danger); }
.toast[data-kind="warn"] { border-left-color: var(--warn); }
.toast[data-kind="success"] { border-left-color: var(--safe); }

.toast[data-leaving="true"] {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.2s, transform 0.2s;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ひまわり赤外画像: 暗部（暖かい地表）を透過し、雲（低温＝白）だけを地図に重ねる */
.leaflet-himawari-pane {
  mix-blend-mode: screen;
  filter: contrast(1.6) brightness(1.15);
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  text-align: right;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}

.layer-check {
  gap: 6px;
  color: var(--text-dim);
  cursor: pointer;
}

.layer-check input {
  accent-color: var(--accent);
}

/* 予報雲量レイヤーの凡例（地図右下） */
.cloud-legend {
  display: grid;
  gap: 3px;
  width: 210px;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  color: var(--text-dim);
  font-size: 10px;
  line-height: 1.3;
}

.cloud-legend-title {
  color: var(--text);
  font-weight: 700;
}

.cloud-legend-scale {
  display: flex;
  gap: 1px;
}

.cloud-legend-scale span {
  flex: 1;
  padding-top: 1px;
  border-top: 7px solid var(--swatch);
  text-align: left;
  font-family: var(--font-mono);
}

.cloud-legend-scale .cloud-legend-end {
  flex: 0 0 auto;
  padding-left: 2px;
  border-top-color: transparent;
}

.cloud-legend-readout {
  min-height: 13px;
  color: var(--text);
  font-family: var(--font-mono);
}

.cloud-legend [hidden] {
  display: none;
}

@media (max-width: 640px) {
  .cloud-legend {
    width: 170px;
  }
}

/* ---------- 地点検索 ---------- */

.search {
  position: relative;
  display: flex;
  flex: 1 1 280px;
  gap: 6px;
  max-width: 460px;
}

.search-input {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

.search-input::placeholder {
  color: var(--text-faint);
}

.search-btn {
  flex: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 1200;
  max-height: min(60vh, 420px);
  overflow: auto;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search-results [role="option"] {
  display: grid;
  gap: 1px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.search-results [role="option"]:hover,
.search-results [role="option"][aria-selected="true"] {
  background: var(--surface-3);
}

.search-result-name {
  font-weight: 700;
}

.search-result-detail {
  color: var(--text-dim);
  font-size: 12px;
}

.search-message {
  padding: 8px 10px;
  color: var(--text-dim);
}

.search-credit {
  padding: 6px 10px 4px;
  color: var(--text-faint);
  font-size: 10px;
}

@media (max-width: 760px) {
  .search {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }
}
