:root {
  --brand-sky: #29b6f6;
  --brand-blue: #1565c0;
  --brand-orange: #ff9800;
  --radius: 12px;
}

:root[data-theme="light"] {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #eef2f6;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e2e6eb;
  --shadow: 0 1px 3px rgba(20, 30, 45, 0.08);
  --overlay: rgba(20, 26, 34, 0.45);
}

:root[data-theme="dark"] {
  --bg: #10151c;
  --surface: #1a2029;
  --surface-alt: #222a35;
  --text: #e8eaed;
  --text-muted: #9aa4b2;
  --border: #2a323d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --overlay: rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-width: 1280px;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
}

#app { min-height: 100vh; display: flex; flex-direction: column; }

button {
  font-family: inherit;
  cursor: pointer;
}

a { color: var(--brand-blue); }

/* ── ヘッダー ─────────────────────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 24px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
}

.brand img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}

.nav-tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}

.nav-tab {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}

.nav-tab:hover { background: var(--surface-alt); }

.nav-tab.active {
  color: var(--brand-blue);
  background: var(--surface-alt);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.icon-btn:hover { background: var(--surface-alt); }

.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  position: relative;
}

.user-chip img {
  width: 26px;
  height: 26px;
  border-radius: 50%;
}

.user-menu {
  position: absolute;
  top: 46px;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 140px;
  overflow: hidden;
  z-index: 30;
}

.user-menu button {
  display: block;
  width: 100%;
  border: none;
  background: none;
  color: var(--text);
  text-align: left;
  padding: 10px 14px;
  font-size: 13px;
}
.user-menu button:hover { background: var(--surface-alt); }

/* ── ログイン画面 ─────────────────────────────────────────────────────── */

.login-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, var(--brand-sky) 0%, #ffd479 65%, var(--brand-orange) 100%);
}

.login-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 48px 56px;
  box-shadow: 0 12px 40px rgba(10, 20, 40, 0.25);
  text-align: center;
  width: 380px;
}

.login-card img { width: 84px; height: 84px; border-radius: 20px; margin-bottom: 16px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; letter-spacing: 1px; }
.login-card p { color: var(--text-muted); margin: 0 0 28px; font-size: 13px; }

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  width: 100%;
  justify-content: center;
}
.google-btn:hover { background: var(--surface-alt); }
.google-btn img { width: 18px; height: 18px; }

.login-error {
  margin-top: 16px;
  color: #d32f2f;
  font-size: 12px;
  min-height: 16px;
}

/* ── メインコンテンツ ─────────────────────────────────────────────────── */

.main {
  flex: 1;
  padding: 24px 32px 48px;
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
}

.view { display: none; }
.view.active { display: block; }

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 14px;
}

/* サマリーカード */
.summary-row { display: flex; gap: 12px; margin-bottom: 20px; }
.summary-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
}
.summary-card .value { font-size: 20px; font-weight: 700; }
.summary-card .label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* 検索バー */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.filter-bar .field { display: flex; flex-direction: column; gap: 4px; }
.filter-bar label { font-size: 11px; color: var(--text-muted); }
.filter-bar input {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.filter-bar .clear-btn {
  align-self: flex-end;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 12px;
}

/* フライトカード一覧 */
.flight-list { display: flex; flex-direction: column; gap: 10px; }

.flight-card {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.flight-card:hover { border-color: var(--brand-blue); cursor: pointer; }

.flight-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--surface-alt);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.flight-main { flex: 1; min-width: 0; }
.flight-title { font-weight: 700; font-size: 14px; }
.flight-sub { color: var(--text-muted); font-size: 12.5px; margin-top: 3px; }

.flight-stats { display: flex; gap: 18px; font-size: 12.5px; color: var(--text-muted); }
.flight-stats b { color: var(--text); font-size: 13px; }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 60px 0;
  font-size: 13px;
}

/* フィード用ユーザー行 */
.feed-user { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.feed-user img { width: 30px; height: 30px; border-radius: 50%; }
.feed-user .name { font-weight: 600; font-size: 13px; }
.feed-user .date { font-size: 11.5px; color: var(--text-muted); }
.feed-engage { display: flex; gap: 14px; font-size: 12.5px; color: var(--text-muted); margin-top: 8px; }

/* ── マップビュー ─────────────────────────────────────────────────────── */

.map-layout { display: flex; gap: 16px; height: calc(100vh - 220px); min-height: 480px; }
.map-canvas { flex: 1; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.map-sidebar {
  width: 300px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.sidebar-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.sidebar-block-title {
  font-size: 12.5px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.count-badge {
  background: var(--surface-alt);
  color: var(--text-muted);
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 11px;
  font-weight: 700;
}
.area-item {
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.area-item:hover { background: var(--surface-alt); }
.area-item.active { border-color: var(--brand-blue); background: var(--surface-alt); }
.area-item .name { font-weight: 700; font-size: 13px; }
.area-item .pref { font-size: 11.5px; color: var(--text-muted); }

/* アクティブなパイロット（入山中/フライト中） */
.active-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.active-legend span { display: flex; align-items: center; gap: 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-active { background: var(--brand-orange); }
.dot-flying { background: var(--brand-sky); }
.dot-preparing { background: #ffca28; }
.dot-sos { background: #e53935; }

.active-pilots-list { display: flex; flex-direction: column; gap: 6px; }
.pilot-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
}
.pilot-row:hover { background: var(--surface-alt); }
.pilot-row .avatar-wrap { position: relative; flex-shrink: 0; }
.pilot-row img { width: 32px; height: 32px; border-radius: 50%; display: block; }
.pilot-row .status-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 2px solid var(--surface);
}
.pilot-row .name { font-weight: 600; font-size: 12.5px; }
.pilot-row .meta { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

.empty-state.small { padding: 18px 0; font-size: 12px; }

.pilot-marker { border-radius: 50%; }
.pilot-marker img {
  width: 30px; height: 30px; border-radius: 50%;
  display: block;
  object-fit: cover;
}

.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface);
  color: var(--text);
}

/* ── 詳細モーダル ─────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-overlay.active { display: flex; }

.modal-box {
  background: var(--surface);
  border-radius: 16px;
  width: 780px;
  max-width: 92vw;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px 28px 28px;
}

.modal-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.modal-header h2 { margin: 0; font-size: 18px; }
.modal-header .close-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
}

.modal-sub { color: var(--text-muted); font-size: 12.5px; margin-bottom: 16px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.stat-grid .cell {
  background: var(--surface-alt);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
}
.stat-grid .cell .v { font-size: 16px; font-weight: 700; }
.stat-grid .cell .k { font-size: 11px; color: var(--text-muted); margin-top: 3px; }

.detail-map { height: 320px; border-radius: 12px; overflow: hidden; border: 1px solid var(--border); margin-bottom: 18px; }

.comments-title { font-size: 13px; font-weight: 700; margin-bottom: 8px; }
.comment-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.comment-row img { width: 26px; height: 26px; border-radius: 50%; }
.comment-row .name { font-weight: 600; font-size: 12.5px; }
.comment-row .text { font-size: 13px; margin-top: 2px; }
.comment-row .time { font-size: 11px; color: var(--text-muted); }
.no-comments { color: var(--text-muted); font-size: 12.5px; padding: 8px 0; }

/* ── 設定（プロフィール） ─────────────────────────────────────────────── */

.settings-layout {
  display: flex;
  gap: 28px;
  max-width: 760px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}

.settings-avatar-block {
  flex-shrink: 0;
  width: 140px;
  text-align: center;
}

.avatar-upload img {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  margin-bottom: 10px;
}

.avatar-upload-btn {
  display: inline-block;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
.avatar-upload-btn:hover { border-color: var(--brand-blue); }

.save-status {
  margin-top: 12px;
  font-size: 11.5px;
  color: var(--text-muted);
  min-height: 14px;
}
.save-status.saving { color: var(--text-muted); }
.save-status.saved { color: #2e7d32; }
.save-status.error { color: #d32f2f; }

.settings-form { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.settings-form .form-row { display: flex; gap: 14px; }
.settings-form .form-row .form-field { flex: 1; }

.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.form-field input,
.form-field textarea,
.form-field select {
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  resize: vertical;
}
.form-field input:focus,
.form-field textarea:focus,
.form-field select:focus {
  outline: none;
  border-color: var(--brand-blue);
}

/* ── ローディング ─────────────────────────────────────────────────────── */
.loading-row { text-align: center; padding: 40px 0; color: var(--text-muted); font-size: 13px; }

.segmented { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button {
  border: none; background: var(--surface); color: var(--text-muted);
  padding: 6px 12px; font-size: 12.5px; border-right: 1px solid var(--border);
}
.segmented button:last-child { border-right: none; }
.segmented button.active { background: var(--brand-blue); color: #fff; }
