/*
  CSS = Cascading Style Sheets
  HTMLの見た目（色・レイアウト・フォント）を定義する言語。
  `セレクタ { プロパティ: 値; }` の形式で書く。
*/

/* ===== グローバルリセット ===== */
* {
  /* すべての要素に適用される基本設定 */
  margin: 0;
  padding: 0;
  box-sizing: border-box;  /* width に padding を含める */
}

body {
  font-family: -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: #f1f5f9;          /* 薄いグレーの背景 */
  color: #1e293b;
  line-height: 1.6;
}

/* ===== ヘッダー（青グラデーション） ===== */
.hero {
  background: linear-gradient(135deg, #1e3a8a 0%, #0ea5e9 100%);
  color: white;
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.hero h1 {
  font-size: 28px;
  margin-bottom: 6px;
}

.hero .meta {
  font-size: 13px;
  opacity: 0.85;
}

/* ===== コンテナ（中央配置・最大幅） ===== */
.container {
  max-width: 1200px;
  margin: 24px auto;            /* 左右自動 = 中央寄せ */
  padding: 0 16px;
}

/* ===== メトリクスカード（4枚並び） ===== */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);   /* 4等分 */
  gap: 16px;
  margin-bottom: 24px;
}

@media (max-width: 768px) {
  /* スマホ画面では2列に */
  .metrics { grid-template-columns: repeat(2, 1fr); }
}

.metric-card {
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  text-align: center;
}

.metric-label {
  font-size: 13px;
  color: #64748b;
  margin-bottom: 6px;
}

.metric-value {
  font-size: 32px;
  font-weight: bold;
  color: #1e3a8a;
}

/* ===== カード（テーブル等のラッパー） ===== */
.card {
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
  margin-bottom: 24px;
}

.card h2 {
  font-size: 18px;
  margin-bottom: 12px;
  color: #1e293b;
}

/* ===== テーブル ===== */
table {
  width: 100%;
  border-collapse: collapse;     /* セル境界を統合 */
  font-size: 14px;
}

th, td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #e2e8f0;
}

th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
}

tbody tr:hover {
  background: #f8fafc;            /* マウスホバー時にハイライト */
  cursor: pointer;
}

/* スコアバッジ */
.score-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-weight: bold;
  font-size: 13px;
  color: white;
}
.score-high  { background: #10b981; }   /* 緑：12+ */
.score-mid   { background: #f59e0b; }   /* 橙：9-11 */
.score-low   { background: #ef4444; }   /* 赤：8以下 */

/* キュレーションマーク */
.curated-mark { color: #f59e0b; font-weight: bold; }

/* ===== ナビゲーションタブ ===== */
.nav-tabs {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 16px;
}
.nav-link {
  display: inline-block;
  padding: 8px 18px;
  color: white;
  text-decoration: none;
  border-radius: 999px;
  background: rgba(255,255,255,0.15);
  font-size: 14px;
  transition: background 0.15s;
}
.nav-link:hover  { background: rgba(255,255,255,0.30); }
.nav-link.active { background: rgba(255,255,255,0.40); font-weight: bold; }

/* ===== フィルタパネル ===== */
.filters .filter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.filter-item label {
  display: block;
  font-size: 13px;
  color: #475569;
  margin-bottom: 4px;
  font-weight: 500;
}
.filter-item input[type="text"],
.filter-item select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
.filter-item input[type="range"] {
  width: 100%;
}
.filter-item small {
  font-size: 11px;
  color: #94a3b8;
  display: block;
  margin-top: 4px;
}
.filter-item label > input[type="checkbox"] {
  margin-right: 6px;
  vertical-align: middle;
}
.btn-reset {
  margin-top: 8px;
  padding: 8px 14px;
  background: #ef4444;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  width: 100%;
}
.btn-reset:hover { background: #dc2626; }

/* ===== 結果ヘッダー（件数 + ページネーション） ===== */
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 10px;
}
.result-count {
  font-weight: bold;
  color: #1e3a8a;
  font-size: 15px;
}

/* ===== テーブル拡張 ===== */
.table-wrapper {
  overflow-x: auto;             /* 横スクロール */
  border-radius: 6px;
}
#stocks-table {
  font-size: 13px;
  white-space: nowrap;
}
#stocks-table th { font-size: 11px; }
#stocks-table th.th-mark { width: 36px; text-align: center; }

#stocks-table th.sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
}
#stocks-table th.sortable:hover { background: #e2e8f0; }
#stocks-table th.sort-asc::after  { content: ' ▲'; color: #1e3a8a; }
#stocks-table th.sort-desc::after { content: ' ▼'; color: #1e3a8a; }

#stocks-table td.code { font-weight: bold; color: #1e3a8a; }
#stocks-table td.held { background: #e0f2fe; }   /* 保有銘柄ハイライト */

/* 判定セル */
.judge-maru     { background: #d4edda; color: #155724; font-weight: bold; text-align: center; }
.judge-sankaku  { background: #fff3cd; color: #856404; font-weight: bold; text-align: center; }
.judge-batsu    { background: #f8d7da; color: #721c24; font-weight: bold; text-align: center; }
/* ※付き（推定値）= 薄色・斜体・破線 */
.judge-est-maru    { background: #eaf5ec; color: #3a8156; font-style: italic; text-align: center; border: 1px dashed #a3d3b1; }
.judge-est-sankaku { background: #fcf6e3; color: #a08038; font-style: italic; text-align: center; border: 1px dashed #e0c97a; }
.judge-est-batsu   { background: #fbe9eb; color: #a04a52; font-style: italic; text-align: center; border: 1px dashed #e0a4ab; }

/* ===== ページネーション ===== */
.pagination {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}
.pagination button {
  min-width: 32px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid #cbd5e1;
  background: white;
  color: #475569;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}
.pagination button:hover:not(:disabled) { background: #e2e8f0; }
.pagination button.active {
  background: #1e3a8a;
  color: white;
  border-color: #1e3a8a;
  font-weight: bold;
}
.pagination button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pagination .page-info {
  color: #64748b;
  font-size: 13px;
  margin: 0 8px;
}

/* ヒント */
.hint {
  text-align: center;
  color: #64748b;
  font-size: 13px;
  margin: 16px 0;
}

/* ===== 詳細ページ：ヘッダー縮小版 ===== */
.hero-compact { padding: 18px 16px; }
.hero-compact h1 { font-size: 22px; margin-bottom: 0; }

/* 銘柄詳細ヘッダーカード（青グラデーション） */
.stock-header-card {
  background: linear-gradient(135deg, #1e3a8a 0%, #0ea5e9 100%);
  color: white;
  border-radius: 14px;
  padding: 24px 28px;
  margin: 24px 0 18px 0;
  box-shadow: 0 4px 14px rgba(0,0,0,0.10);
}
.stock-header-card .loading { opacity: 0.85; }
.stock-header-card .stock-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
}
.stock-header-card .stock-meta {
  font-size: 13px;
  opacity: 0.85;
  letter-spacing: 1px;
}
.stock-header-card .stock-name {
  font-size: 30px;
  font-weight: bold;
  margin: 6px 0 0 0;
}
.stock-header-card .stock-name .code-prefix {
  font-size: 22px;
  opacity: 0.85;
  margin-right: 12px;
}
.stock-header-card .total-score-box {
  background: rgba(255,255,255,0.12);
  padding: 14px 22px;
  border-radius: 10px;
  text-align: right;
}
.stock-header-card .total-score-box .label {
  font-size: 11px;
  opacity: 0.85;
  letter-spacing: 1px;
}
.stock-header-card .total-score-box .value {
  font-size: 42px;
  font-weight: bold;
  line-height: 1;
}
.stock-header-card .total-score-box .value small {
  font-size: 18px;
  opacity: 0.7;
}
.stock-header-card .total-score-box .breakdown {
  font-size: 11px;
  opacity: 0.9;
  margin-top: 4px;
}
.held-badge {
  background: #fbbf24;
  color: #78350f;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 12px;
  margin-left: 8px;
}

/* チャート領域 */
.chart-area      { width: 100%; height: 320px; }
.chart-area-half { width: 100%; height: 260px; }
.chart-mini      { width: 100%; height: 240px; }

.chart-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}
@media (max-width: 768px) {
  .chart-grid-2 { grid-template-columns: 1fr; }
}

.chart-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
@media (max-width: 1024px) {
  .chart-grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .chart-grid-3 { grid-template-columns: 1fr; }
}

.warn {
  color: #b45309;
  background: #fef3c7;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-top: 8px;
}

/* 判定テーブル */
.judge-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 768px) {
  .judge-grid { grid-template-columns: 1fr; }
}
.judge-grid h3 {
  font-size: 14px;
  margin-bottom: 8px;
  color: #475569;
}
.judge-table { width: 100%; border-collapse: collapse; }
.judge-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 13px;
}
.judge-table td:last-child {
  width: 80px;
  text-align: center;
}

/* メモ */
.prompt-box {
  background: #f1f5f9;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}
.prompt-box summary {
  cursor: pointer;
  font-weight: 500;
  color: #475569;
}
.code-block {
  background: #0f172a;
  color: #f1f5f9;
  padding: 12px;
  border-radius: 6px;
  font-size: 12px;
  white-space: pre-wrap;
  font-family: 'Consolas', 'Monaco', monospace;
  margin-top: 10px;
  max-height: 360px;
  overflow-y: auto;
}
.btn-copy, .link-external {
  display: inline-block;
  margin-top: 10px;
  margin-right: 12px;
  padding: 6px 14px;
  font-size: 13px;
  border-radius: 6px;
  cursor: pointer;
  border: none;
}
.btn-copy        { background: #0ea5e9; color: white; }
.btn-copy:hover  { background: #0284c7; }
.link-external   { background: white; color: #0ea5e9; border: 1px solid #0ea5e9; text-decoration: none; }
.link-external:hover { background: #e0f2fe; }

.memo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 768px) {
  .memo-grid { grid-template-columns: 1fr; }
}
.memo-grid label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #475569;
  margin-bottom: 4px;
}
.memo-grid textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  margin-top: 4px;
}
.memo-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.btn-primary, .btn-danger {
  padding: 8px 18px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
}
.btn-primary { background: #1e3a8a; color: white; }
.btn-primary:hover { background: #1e40af; }
.btn-danger  { background: #ef4444; color: white; }
.btn-danger:hover  { background: #dc2626; }
.memo-status { color: #10b981; font-size: 13px; }
