/* ============================================================
 * 画像診断ページ専用スタイル
 *   既存 style.css の CSS 変数（--color-*, --radius-*, --shadow-*）を継承
 * ============================================================ */

/* ----------- ページ全体 ----------- */
.diagnose-page {
  /* style.css の .content の制約を上書き */
  max-width: 1280px !important;
  padding: 24px 32px 96px !important;
}

@media (max-width: 767px) {
  .diagnose-page {
    padding: 16px 12px 64px !important;
  }
}

.topbar-subtitle {
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 13px;
  margin-left: 4px;
}

/* ----------- サイドバー（診断専用ナビ） ----------- */
.diagnose-sidebar {
  padding: 16px 0;
}
.diagnose-nav-section {
  padding: 8px 0 16px;
  border-bottom: 1px solid var(--color-border-soft);
}
.diagnose-nav-section:last-child {
  border-bottom: none;
}
.diagnose-nav-title {
  margin: 0 0 8px;
  padding: 0 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.diagnose-nav-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.diagnose-nav-section a {
  display: block;
  padding: 6px 16px;
  font-size: 13px;
  color: var(--color-text);
  border-left: 3px solid transparent;
  transition: background 0.1s, border-color 0.1s, color 0.1s;
}
.diagnose-nav-section a:hover {
  background: var(--color-border-soft);
  text-decoration: none;
  color: var(--color-accent);
  border-left-color: var(--color-accent);
}

/* ----------- ヒーロー ----------- */
.diagnose-hero {
  text-align: center;
  padding: 16px 16px 24px;
}
.diagnose-hero h2 {
  font-size: 28px;
  margin: 0 0 8px;
  border: none !important;
  padding: 0 !important;
}
.diagnose-hero p {
  color: var(--color-text-muted);
  margin: 0;
  line-height: 1.6;
}

/* ----------- デモバナー ----------- */
.demo-banner {
  display: flex;
  gap: 12px;
  padding: 14px 18px;
  background: #fff7e6;
  border: 1px solid #f6d97a;
  border-radius: var(--radius-md);
  margin-bottom: 24px;
  align-items: flex-start;
}
[data-theme="dark"] .demo-banner {
  background: #3a2c00;
  border-color: var(--color-warning);
  color: #ffe8a3;
}
.demo-banner-icon {
  font-size: 22px;
  flex: 0 0 auto;
  line-height: 1.4;
}
.demo-banner-body { flex: 1; min-width: 0; }
.demo-banner-body strong {
  display: block;
  margin-bottom: 4px;
  font-size: 15px;
}
.demo-banner-body p {
  margin: 0;
  font-size: 13px;
  line-height: 1.6;
}
.demo-banner-body code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: rgba(0,0,0,0.06);
  padding: 1px 5px;
  border-radius: var(--radius-sm);
}
[data-theme="dark"] .demo-banner-body code {
  background: rgba(255,255,255,0.1);
}
.demo-banner-close {
  flex: 0 0 auto;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0 4px;
  line-height: 1;
}

/* ----------- OpenCV ロードステータス ----------- */
.cv-status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--color-text-muted);
}
.cv-status[data-status="ready"] {
  background: rgba(26, 127, 55, 0.08);
  border-color: var(--color-success);
  color: var(--color-success);
}
.cv-status[data-status="failed"] {
  background: rgba(207, 34, 46, 0.08);
  border-color: var(--color-danger);
  color: var(--color-danger);
}
.cv-status-icon { font-size: 16px; }
.cv-status[data-status="loading"] .cv-status-icon {
  display: inline-block;
  animation: cvspin 1.4s linear infinite;
}
@keyframes cvspin { to { transform: rotate(360deg); } }
.cv-status small { display: block; opacity: 0.7; font-size: 11px; }

/* ----------- アップロードゾーン ----------- */
.upload-zone {
  border: 2px dashed var(--color-border);
  border-radius: var(--radius-lg);
  padding: 56px 24px;
  background: var(--color-bg-alt);
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s, transform .1s;
}
.upload-zone:hover,
.upload-zone:focus-visible {
  border-color: var(--color-accent);
  background: var(--color-bg-elev);
  outline: none;
}
.upload-zone.is-dragover {
  border-color: var(--color-accent);
  background: rgba(9, 105, 218, 0.08);
  transform: scale(1.01);
  border-style: solid;
}
.upload-zone-inner { max-width: 520px; margin: 0 auto; }
.upload-icon { font-size: 48px; margin-bottom: 12px; }
.upload-primary {
  font-size: 18px;
  margin: 0 0 18px;
  font-weight: 500;
}
.upload-primary small {
  font-size: 14px;
  color: var(--color-text-muted);
  font-weight: 400;
}
.upload-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.upload-hint {
  color: var(--color-text-muted);
  font-size: 12px;
  margin: 0;
  line-height: 1.5;
}

/* ----------- ボタン ----------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  background: var(--color-bg-elev);
  color: var(--color-text);
  font-family: inherit;
  transition: background .15s, border-color .15s, opacity .15s;
  min-height: 44px;
}
.btn:hover { background: var(--color-bg-alt); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}
.btn-primary:hover { background: var(--color-accent-hover); border-color: var(--color-accent-hover); }
.btn-secondary { background: var(--color-bg-elev); }
.btn-tertiary {
  border: 1px solid transparent;
  background: transparent;
  color: var(--color-accent);
}
.btn-tertiary:hover {
  background: var(--color-bg-alt);
  border-color: var(--color-border);
}

/* ----------- 解析中 ----------- */
.analysis-progress {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  padding: 48px 24px;
  background: var(--color-bg-alt);
  border-radius: var(--radius-lg);
  margin-top: 24px;
}
.spinner {
  width: 44px; height: 44px;
  border: 3px solid var(--color-border);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-text { text-align: center; }
.progress-text strong { font-size: 16px; }
.progress-text p {
  color: var(--color-text-muted);
  margin: 4px 0 0;
  font-size: 13px;
}
.progress-bar {
  width: 100%;
  max-width: 480px;
  height: 6px;
  background: var(--color-border-soft);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--color-accent);
  transition: width .3s ease;
}

/* ----------- 結果パネル ----------- */
.results-panel { margin-top: 24px; }
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  flex-wrap: wrap;
  gap: 12px;
}
.results-header h2 {
  margin: 0;
  font-size: 22px;
  border: none !important;
  padding: 0 !important;
}
.results-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.results-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.results-meta-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--color-text-muted);
}
.results-meta-pill span { color: var(--color-text); font-weight: 500; }

/* グリッド: 1024+ で 3カラム / 768-1024 で 2 / それ以下で 1 */
.results-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.7fr 1.1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 1023px) {
  .results-grid { grid-template-columns: 1fr 1fr; }
  .result-ideal { grid-column: span 2; }
}
@media (max-width: 767px) {
  .results-grid { grid-template-columns: 1fr; }
  .result-ideal { grid-column: auto; }
}

.result-image, .result-ideal, .result-list {
  background: var(--color-bg-elev);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 16px;
  min-width: 0;
}
.result-image h3, .result-ideal h3, .result-list h3 {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--color-text-muted);
  font-weight: 700;
  border: none !important;
  padding: 0 !important;
}

/* ----------- Canvas 領域 ----------- */
.canvas-wrapper {
  position: relative;
  width: 100%;
  background: #0a0a0a;
  border-radius: var(--radius-md);
  overflow: hidden;
  touch-action: pinch-zoom;
  display: flex;
  align-items: center;
  justify-content: center;
}
.canvas-wrapper canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 70vh;
  object-fit: contain;
}
#canvas-overlay {
  position: absolute;
  inset: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}
.canvas-tooltip {
  position: fixed;
  z-index: 1000;
  background: rgba(0,0,0,0.88);
  color: #fff;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12px;
  pointer-events: none;
  white-space: nowrap;
  transform: translate(-50%, -130%);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.canvas-hint {
  font-size: 12px;
  color: var(--color-text-muted);
  margin: 8px 0 0;
  text-align: center;
}

/* ----------- 理想カード（CSS イラスト） ----------- */
.ideal-illustration {
  display: flex;
  justify-content: center;
  padding: 20px 0;
}
.ideal-card {
  position: relative;
  width: 160px;
  height: 224px;
  background: linear-gradient(135deg, #f8d97a 0%, #f4b962 50%, #e89a3c 100%);
  border-radius: 8px;
  border: 2px solid #b8821a;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ideal-card-header {
  height: 18px;
  background: rgba(255,255,255,0.4);
  border-radius: 3px;
}
.ideal-card-art {
  flex: 2;
  background: linear-gradient(180deg, #b3d9ff 0%, #7fa5ce 100%);
  border-radius: 3px;
  border: 1px solid rgba(0,0,0,0.1);
}
.ideal-card-body {
  flex: 1;
  background: rgba(255,255,255,0.5);
  border-radius: 3px;
}
.ideal-card-footer {
  height: 14px;
  background: rgba(0,0,0,0.15);
  border-radius: 2px;
}
.ideal-checkmark {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 32px;
  height: 32px;
  background: var(--color-success);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  border: 3px solid var(--color-bg-elev);
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}
.ideal-caption {
  font-size: 12px;
  color: var(--color-text-muted);
  text-align: center;
  margin: 8px 0 0;
  line-height: 1.5;
}

/* ----------- 検出カード ----------- */
.detection-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 70vh;
  overflow-y: auto;
}
.detection-empty {
  text-align: center;
  padding: 24px 12px;
  color: var(--color-text-muted);
}
.detection-empty p:first-child {
  font-size: 18px;
  color: var(--color-success);
  font-weight: 500;
}

.detection-card {
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-text-muted);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  background: var(--color-bg-alt);
  transition: box-shadow .2s, transform .15s, border-color .15s;
  cursor: pointer;
}
.detection-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-accent);
}
.detection-card.is-active {
  box-shadow: 0 0 0 3px rgba(9,105,218,0.4);
  transform: translateX(2px);
}
.detection-card[data-severity="mild"]    { border-left-color: var(--color-success); }
.detection-card[data-severity="light"]   { border-left-color: var(--color-success); }
.detection-card[data-severity="moderate"]{ border-left-color: var(--color-warning); }
.detection-card[data-severity="severe"]  { border-left-color: var(--color-danger); }
.detection-card[data-severity="critical"]{ border-left-color: #8b0000; }

.detection-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.detection-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--color-accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  flex: 0 0 auto;
}
.detection-title {
  margin: 0;
  font-size: 15px;
  flex: 1;
  font-weight: 700;
  border: none !important;
  padding: 0 !important;
}
.severity-pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--color-bg-elev);
  border: 1px solid var(--color-border);
  font-weight: 500;
}
.severity-pill.severity-mild,
.severity-pill.severity-light    { color: var(--color-success); border-color: var(--color-success); }
.severity-pill.severity-moderate { color: var(--color-warning); border-color: var(--color-warning); }
.severity-pill.severity-severe,
.severity-pill.severity-critical { color: var(--color-danger);  border-color: var(--color-danger); }

.confidence {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
  font-size: 12px;
  color: var(--color-text-muted);
}
.confidence-label { flex: 0 0 auto; }
.confidence-bar {
  flex: 1;
  height: 4px;
  background: var(--color-border-soft);
  border-radius: 2px;
  overflow: hidden;
}
.confidence-fill {
  height: 100%;
  background: var(--color-accent);
  transition: width .3s ease;
}
.confidence-value {
  flex: 0 0 auto;
  font-weight: 500;
  min-width: 36px;
  text-align: right;
}

.detection-explanation {
  margin: 8px 0;
  font-size: 13px;
  line-height: 1.6;
  color: var(--color-text);
}

.detection-metrics {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 6px 0;
}
.detection-metric {
  font-size: 11px;
  padding: 2px 6px;
  background: var(--color-bg-elev);
  border-radius: 3px;
  color: var(--color-text-muted);
  font-family: var(--font-mono);
}

.repair-methods h4 {
  font-size: 13px;
  margin: 12px 0 6px;
  color: var(--color-text-muted);
  font-weight: 700;
  border: none !important;
  padding: 0 !important;
}
.repair-method-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.method {
  padding: 8px 10px;
  background: var(--color-bg-elev);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-sm);
  font-size: 13px;
}
.method strong { display: block; margin-bottom: 4px; }
.method p {
  margin: 4px 0;
  font-size: 12px;
  color: var(--color-text-muted);
  line-height: 1.5;
}
.method-primary { border-left: 3px solid var(--color-accent); }
.method-fallback { padding: 6px 10px; }
.method-fallback summary {
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 12px;
  list-style: revert;
}
.method-link {
  display: inline-block;
  margin-top: 6px;
  font-weight: 500;
  font-size: 13px;
}
.method-link:hover { text-decoration: underline; }

.method-warnings {
  margin: 6px 0 0;
  padding: 6px 8px;
  background: rgba(154, 103, 0, 0.08);
  border-left: 2px solid var(--color-warning);
  border-radius: 2px;
  font-size: 11px;
  color: var(--color-warning);
}
.method-warnings ul { margin: 2px 0 0; padding-left: 18px; }

/* ----------- 結果フッター ----------- */
.results-footer {
  margin-top: 24px;
  padding: 18px 20px;
  background: var(--color-bg-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-soft);
}
.results-footer h3 {
  margin: 0 0 8px;
  font-size: 16px;
  border: none !important;
  padding: 0 !important;
}
.results-footer p {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.6;
}
.primary-chapter-links {
  list-style: none;
  padding: 0;
  margin: 8px 0 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.primary-chapter-links a {
  display: inline-block;
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-bg-elev);
  font-size: 13px;
  text-decoration: none;
}
.primary-chapter-links a:hover {
  background: var(--color-bg-alt);
  border-color: var(--color-accent);
  text-decoration: none;
}

/* ----------- エラー ----------- */
.error-state {
  text-align: center;
  padding: 40px 24px;
  background: var(--color-bg-alt);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-danger);
  margin-top: 24px;
}
.error-icon {
  font-size: 48px;
  margin-bottom: 12px;
}
.error-state h2 {
  margin: 0 0 8px;
  border: none !important;
  padding: 0 !important;
}
.error-state p {
  font-size: 15px;
  margin: 0 0 12px;
  color: var(--color-text);
}
.error-hints {
  display: inline-block;
  text-align: left;
  margin: 12px auto 16px;
  color: var(--color-text-muted);
  font-size: 13px;
  line-height: 1.7;
  background: var(--color-bg-elev);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-md);
  padding: 12px 24px;
  max-width: 480px;
  list-style-position: inside;
}
.error-hints li { margin: 2px 0; }

/* ----------- ヘルプセクション ----------- */
.help-section {
  margin-top: 32px;
  padding: 20px 24px;
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-lg);
}
.help-section h2 {
  margin: 0 0 12px;
  font-size: 18px;
  border: none !important;
  padding: 0 !important;
}
.help-list {
  margin: 0;
  padding-left: 24px;
  font-size: 14px;
  line-height: 1.8;
}
.help-list li { margin: 4px 0; }

/* ----------- topbar ----------- */
.topbar-link {
  color: var(--color-accent);
  font-weight: 500;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  font-size: 14px;
}
.topbar-link:hover {
  background: var(--color-bg-alt);
  text-decoration: none;
}

/* ----------- レスポンシブ: モバイルでサイドバー非表示 ----------- */
@media (max-width: 1023px) {
  .diagnose-sidebar {
    display: none;
  }
  .diagnose-sidebar.is-open {
    display: block;
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    z-index: 90;
    width: var(--sidebar-w);
    max-width: 80vw;
    height: calc(100vh - var(--topbar-h));
    box-shadow: var(--shadow-lg);
    background: var(--color-bg-alt);
  }
  .sidebar-toggle { display: inline-block; }
}
@media (min-width: 1024px) {
  .sidebar-toggle { display: none; }
}

/* スクロールバー（detection-list） */
.detection-list::-webkit-scrollbar {
  width: 6px;
}
.detection-list::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 3px;
}
.detection-list::-webkit-scrollbar-track {
  background: transparent;
}

/* アクセシビリティ: フォーカスリング */
.btn:focus-visible,
.demo-banner-close:focus-visible,
.detection-card:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}
