/* ================================================================
   Stella-JS — スタイルシート
   設計方針: シンプル・読みやすい・モバイル対応
================================================================ */

/* ── リセット・基礎 ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg:          #0f1117;
  --bg-surface:  #1a1d27;
  --bg-card:     #21253a;
  --accent:      #7c6af7;
  --accent-dim:  #4a4180;
  --text:        #e8eaf0;
  --text-muted:  #8892a4;
  --border:      #2e3348;
  --success:     #4caf7d;
  --warning:     #e8a838;
  --error:       #e05252;
  --radius:      8px;
  --font-mono:   'SF Mono', 'Fira Code', 'Consolas', monospace;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  line-height: 1.6;
}

/* ── レイアウト ───────────────────────────────────────────────── */
#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

/* ── 2カラムグリッド ────────────────────────────────────────────── */
#layout {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 0;
  align-items: start;
}

#sidebar {
  position: sticky;
  top: 16px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#content-area {
  padding-left: 24px;
  min-width: 0;
}

/* ── サイドバーナビゲーション ─────────────────────────────────── */
#main-nav {
  padding: 4px 0 16px;
}

.nav-group {
  margin-bottom: 2px;
}

.nav-group-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 10px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-group-hd:hover { background: var(--bg-surface); color: var(--text); }
.nav-group.open > .nav-group-hd { color: var(--text); background: var(--bg-surface); }

.nav-chevron {
  display: inline-block;
  font-style: normal;
  font-size: 11px;
  transition: transform 0.2s;
}
.nav-group:not(.open) > .nav-group-hd .nav-chevron { transform: rotate(-90deg); }

.nav-group-body {
  display: none;
  flex-direction: column;
  padding: 2px 0 4px 6px;
}
.nav-group.open > .nav-group-body { display: flex; }

.nav-item {
  display: block;
  width: 100%;
  padding: 6px 8px 6px 12px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-left: 2px solid transparent;
  border-radius: 0 var(--radius) var(--radius) 0;
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.nav-item:hover { background: var(--bg-card); color: var(--text); }
.nav-item.active {
  background: var(--bg-card);
  color: var(--accent);
  border-left-color: var(--accent);
}

/* ── ヘッダー ─────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  flex-wrap: wrap;
}

header h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

header .subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 12px;
  flex: 1;
}

/* ── BSP ステータスバッジ ──────────────────────────────────────── */
.status-badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.status-loading { background: var(--accent-dim); color: var(--text); }
.status-ok      { background: var(--success);    color: #0f1117; }
.status-error   { background: var(--error);      color: #fff; }

/* ── メインメニュー（タブ） ───────────────────────────────────── */
#main-menu {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.tab-btn {
  padding: 8px 14px;
  background: var(--bg-surface);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  transition: background 0.15s, color 0.15s;
}
.tab-btn:hover  { background: var(--bg-card); color: var(--text); }
.tab-btn.active { background: var(--accent);  color: #fff; border-color: var(--accent); }

/* ── タブコンテンツ ────────────────────────────────────────────── */
.tab-content { display: none; }
.tab-content.active { display: block; }

.tab-content > h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
}

/* ── サブメニュー ─────────────────────────────────────────────── */
.sub-menu {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.sub-btn {
  padding: 6px 12px;
  background: var(--bg-card);
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s, color 0.15s;
}
.sub-btn:hover  { color: var(--text); }
.sub-btn.active { background: var(--accent-dim); color: var(--text); border-color: var(--accent); }

/* 第2レベル サブメニュー */
.sub-menu-2 { margin-top: 10px; }

.sub-btn-2 {
  padding: 5px 10px;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.15s, color 0.15s;
}
.sub-btn-2:hover  { color: var(--text); }
.sub-btn-2.active { background: var(--bg-card); color: var(--accent); border-color: var(--accent); }

.sub-content   { display: none; margin-top: 12px; }
.sub-content.active { display: block; }

.sub-content-2 { display: none; margin-top: 10px; }
.sub-content-2.active { display: block; }

.sub-content h3, .sub-content-2 h4 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ── フォーム ─────────────────────────────────────────────────── */
.calc-form {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 480px;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-row label {
  width: 130px;
  flex-shrink: 0;
  color: var(--text-muted);
  font-size: 12px;
}

.form-row input,
.form-row select {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}
.form-row input:focus,
.form-row select:focus {
  outline: none;
  border-color: var(--accent);
}

.calc-btn {
  align-self: flex-start;
  padding: 7px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: opacity 0.15s;
}
.calc-btn:hover    { opacity: 0.85; }
.calc-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── 結果エリア ───────────────────────────────────────────────── */
.result-area {
  margin-top: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  min-height: 60px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  display: none;
  overflow-x: auto;
}
.result-area.visible { display: block; }
.result-area.loading { color: var(--text-muted); }
.result-area.error   { color: var(--error); border-color: var(--error); }

/* ── 結果テーブル ─────────────────────────────────────────────── */
.result-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.result-table th {
  text-align: left;
  padding: 4px 10px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  white-space: nowrap;
}
.result-table td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  white-space: nowrap;
}
.result-table tr:last-child td { border-bottom: none; }
.result-table tr:hover td { background: var(--bg-card); }

/* ── 設定セクション ───────────────────────────────────────────── */
.settings-section {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  max-width: 480px;
}
.settings-section h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 600;
}
.settings-note {
  margin: 8px 0 0;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
}
.form-row-top { align-items: flex-start; }
.checkbox-group {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px 16px;
  align-items: start;
}
.checkbox-group label {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
}
.checkbox-group input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 2px;
  accent-color: var(--accent);
  width: 13px;
  height: 13px;
  cursor: pointer;
}

/* ── プレースホルダー ──────────────────────────────────────────── */
.placeholder {
  color: var(--text-muted);
  font-size: 12px;
  padding: 20px;
  text-align: center;
  background: var(--bg-surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* ── ローディングインジケーター ──────────────────────────────── */
.loading-wrap {
  padding: 16px 0 8px;
}
.loading-bar-track {
  width: 100%;
  height: 3px;
  background: var(--bg-card);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 10px;
}
.loading-bar-fill {
  height: 100%;
  width: 38%;
  background: var(--accent, #8b5cf6);
  border-radius: 2px;
  animation: loading-sweep 1.4s cubic-bezier(0.4, 0, 0.6, 1) infinite;
  will-change: transform;
}
@keyframes loading-sweep {
  0%   { transform: translateX(-260%); }
  100% { transform: translateX(370%);  }
}
/* % 確定プログレスバー（アニメーション停止・幅で進捗を示す） */
.loading-bar-fill.is-progress {
  animation: none;
  transform: none;
  width: var(--progress, 0%);
  transition: width 0.15s ease;
}
.loading-label {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
  text-align: center;
  letter-spacing: 0.03em;
}
.loading-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin: 4px 0 0;
  text-align: center;
  opacity: 0.65;
}

/* ── 設定タブ：更新履歴 ────────────────────────────────────────── */
.changelog-entry {
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.changelog-entry:last-child { border-bottom: none; }
.changelog-ver {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.changelog-date {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}
.changelog-list {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.8;
}

/* ── ウェルカムパネル ────────────────────────────────────────────── */
.welcome-panel {
  padding: 4px 0 32px;
}
.welcome-panel .welcome-lead {
  color: var(--text-muted);
  font-size: 12px;
  margin: 0 0 24px;
}
.feature-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}
.feature-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
  text-align: left;
}
.feature-card:hover {
  border-color: var(--accent);
  background: var(--bg-card);
  transform: translateY(-2px);
}
.feature-card.is-coming {
  opacity: 0.55;
  cursor: default;
}
.feature-card.is-coming:hover {
  transform: none;
  border-color: var(--border);
  background: var(--bg-surface);
}
.feature-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.feature-card-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.6;
}
.welcome-about {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 16px;
  font-size: 12px;
  line-height: 1.8;
  color: var(--text-muted);
}
.welcome-about-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.welcome-about p {
  margin: 0 0 8px;
}
.welcome-about p:last-child { margin-bottom: 0; }
.welcome-about strong { color: var(--text); }
.welcome-about a { color: var(--accent); text-decoration: none; }
.welcome-about a:hover { text-decoration: underline; }

.welcome-footer {
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
/* ロゴクリックでホームに戻る */
header h1 { cursor: pointer; transition: opacity 0.15s; }
header h1:hover { opacity: 0.75; }

/* ── CHANGELOG.md レンダリング ─────────────────────────────────── */
#changelog-content { font-size: 13px; line-height: 1.75; }
#changelog-content .cl-h2 {
  font-size: 14px; font-weight: 700; color: var(--text);
  margin: 20px 0 6px; padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
#changelog-content .cl-h3 {
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  margin: 14px 0 4px;
}
#changelog-content .cl-h4,
#changelog-content .cl-h5 {
  font-size: 12px; font-weight: 600; color: var(--text-muted);
  margin: 10px 0 4px;
}
#changelog-content .cl-p {
  margin: 4px 0; color: var(--text-muted);
}
#changelog-content hr {
  border: none; border-top: 1px solid var(--border); margin: 10px 0;
}
#changelog-content .cl-table {
  margin: 8px 0; font-size: 12px;
}

/* ── 設定タブ：ライセンス情報 ──────────────────────────────────── */
.license-block {
  margin-bottom: 16px;
  padding: 12px 14px;
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.license-block:last-child { margin-bottom: 0; }
.license-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}
.license-body {
  font-size: 12px;
  color: var(--text);
  line-height: 1.7;
}
.license-body a {
  color: var(--accent);
  text-decoration: none;
}
.license-body a:hover { text-decoration: underline; }

/* ── CSV ダウンロードボタン ─────────────────────────────────────── */
.dl-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.dl-btn:hover { opacity: 0.85; }

/* ── ハンバーガーボタン（PC では非表示） ─────────────────────── */
#menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  flex-shrink: 0;
}

/* ── ジオコーディング結果 ──────────────────────────────────────── */
.geocode-result {
  font-size: 12px;
  color: var(--text-muted);
  margin: -8px 0 4px 0;
  padding-left: 160px;
}

/* ── レスポンシブ ─────────────────────────────────────────────── */
@media (max-width: 600px) {
  /* フォーム */
  .form-row { flex-direction: column; align-items: flex-start; }
  .geocode-result { padding-left: 0; }
  .form-row label { width: auto; }
  .form-row input, .form-row select { width: 100%; }

  /* 1カラムレイアウト */
  #layout {
    grid-template-columns: 1fr;
  }

  /* サイドバー: デフォルト非表示・open クラスで表示 */
  #sidebar {
    display: none;
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding-right: 0;
    padding-bottom: 8px;
    margin-bottom: 12px;
  }
  #sidebar.open {
    display: block;
  }

  /* ハンバーガーボタンを表示 */
  #menu-toggle {
    display: inline-block;
  }

  /* テーブルを横スクロール可能に */
  .result-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* コンテンツエリアの左余白を解除 */
  #content-area {
    padding-left: 0;
  }
}

/* ── パンくずリスト（スタンドアロンPWAモード用）─────────────────── */
#breadcrumb {
  display: none;
  width: 100%;
  align-items: center;
  gap: 5px;
  font-size: 0.74rem;
  color: var(--text-muted);
  padding-top: 6px;
  overflow: hidden;
}

body.is-standalone #breadcrumb.bc-visible {
  display: flex;
}

#breadcrumb-home,
#bc-category {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0 2px;
  color: var(--accent);
  line-height: 1;
  flex-shrink: 0;
  font-size: inherit;
}

#breadcrumb-home {
  font-size: 0.85rem;
}

#breadcrumb-home:active,
#bc-category:active {
  opacity: 0.6;
}

.bc-sep {
  opacity: 0.35;
  flex-shrink: 0;
}

#bc-category {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 2;
}

#bc-menu {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 1;
  min-width: 0;
}
