﻿@import url('https://fonts.googleapis.com/css2?family=BIZ+UDPGothic:wght@400;700&display=swap');

:root {
  --bg:       #10151d;
  --surface:  #303947;
  --surface2: #3b4656;
  --border:   #4c5a6c;
  --border2:  #a8bedc;
  --border-strong: #74859b;
  --accent:   #7fb0ff;
  --accent2:  #356fd6;
  --accent3:  #285dbb;
  --green:    #22c55e;
  --amber:    #f59e0b;
  --red:      #ef4444;
  --text:     #ffffff;
  --text2:    #f1f5f9;
  --text3:    #c9d5e2;
  --draw:     #dc143c;   /* 計測線の統一描画色 */
  --draw-sel: #2E59BC;   /* 選択中オブジェクトのハイライト色 */
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { width: 100%; height: 100%; overflow: hidden; }
body {
  font-family: 'BIZ UDPGothic', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

/* ============================================================
   共通部品
   ============================================================ */
.btn {
  padding: 8px 15px;
  border-radius: 5px;
  border: none;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}
.btn-primary { background: var(--accent2); color: #fff; }
.btn-primary:hover { background: var(--accent3); }
.btn-ghost {
  background: rgba(255,255,255,0.03);
  color: var(--text2);
  border: 2px solid var(--border-strong);
}
.btn-ghost:hover { border-color: var(--accent); color: var(--text); background: rgba(127,176,255,0.16); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.85; }

/* モーダル共通 */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-box {
  background: var(--surface);
  border: 2px solid var(--border2);
  border-radius: 12px;
  padding: 28px;
  width: 360px;
  transform: translateY(10px);
  transition: transform 0.2s;
}
.modal-overlay.open .modal-box { transform: translateY(0); }
.modal-box.wide { width: 560px; }
.modal-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 20px;
  color: var(--text);
}
.modal-field { margin-bottom: 12px; }
.modal-field label {
  display: block;
  font-size: 12px;
  color: var(--text3);
  margin-bottom: 5px;
  letter-spacing: 0.05em;
}
.modal-field input,
.modal-field select {
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  padding: 9px 11px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}
.modal-field input:focus,
.modal-field select:focus { border-color: var(--accent); }
.modal-field select option { background: var(--surface); }
.modal-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 20px;
}
.modal-warn {
  font-size: 12px;
  color: var(--amber);
  margin-top: 6px;
  min-height: 16px;
}

/* トースト */
.toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%) translateY(70px);
  background: var(--surface2);
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  padding: 10px 18px;
  font-size: 13px;
  color: var(--text);
  transition: transform 0.25s;
  z-index: 300;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* スピナー（API通信中） */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   画面の表示切り替え
   ============================================================ */
.screen { width: 100%; height: 100%; display: none; flex-direction: column; position: relative; }
.screen.active { display: flex; }

/* ============================================================
   画面1：患者選択画面
   ============================================================ */
.ps-header {
  height: 56px; min-height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ps-logo {
  font-size: 13px;
  letter-spacing: 0.08em;
  color: var(--accent);
  text-transform: uppercase;
  cursor: pointer;
}

/* 検索エリア：検索窓の上端を画面中央より少し上に固定 */
.ps-search-area {
  position: absolute;
  top: calc(45% - 24px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 0;
  width: 720px; /* 一覧4列表示に合わせて拡張 */
}

.ps-search-wrap { position: relative; width: 420px; margin: 0 auto; } /* 検索窓は420px固定・中央揃え */

.ps-search-wrap input {
  width: 100%;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 8px;
  padding: 10px 14px 10px 36px;
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s, border-radius 0.1s;
}
.ps-search-wrap input:focus { border-color: var(--accent); }
/* 検索結果が表示されているとき：入力欄の下角を直角にしてドロップダウンとつなげる */
.ps-search-wrap input.has-results {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  border-bottom-color: var(--border);
}
.ps-search-wrap input::placeholder { color: var(--text3); }
.ps-search-icon {
  position: absolute; left: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 15px; color: var(--text3);
}

/* 検索窓の×クリアボタン */
.ps-clear-btn {
  position: absolute; right: 10px; top: 50%;
  transform: translateY(-50%);
  background: none; border: none;
  color: var(--red);
  font-size: 32px;
  cursor: pointer;
  line-height: 1;
  padding: 2px 4px;
  transition: color 0.12s;
}
.ps-clear-btn:hover { color: var(--text); }

.ps-new-btn {
  padding: 10px 18px;
  background: var(--accent2);
  border: none; border-radius: 8px;
  color: #fff; font-size: 14px;
  cursor: pointer; font-family: inherit;
  font-weight: 700; white-space: nowrap;
  transition: background 0.12s;
}
.ps-new-btn:hover { background: var(--accent3); }

/* ハンバーガーメニュー */
.ps-hamburger {
  position: relative;
}
.ps-hamburger-btn {
  width: 40px; height: 40px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  background: none; border: 1px solid var(--border); border-radius: 8px;
  cursor: pointer; transition: background 0.12s;
}
.ps-hamburger-btn:hover { background: var(--surface2); }
.ps-hamburger-btn span {
  display: block; width: 18px; height: 2px;
  background: var(--text2); border-radius: 2px;
  transition: background 0.12s;
}
.ps-hamburger-btn:hover span { background: var(--text); }

/* ハンバーガーのドロップダウン */
.ps-menu-dropdown {
  display: none;
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.3);
  min-width: 160px; z-index: 200; overflow: hidden;
}
.ps-menu-dropdown.is-open { display: block; }
.ps-menu-item {
  display: block; width: 100%; padding: 12px 16px;
  background: none; border: none;
  text-align: left; font-size: 15px; color: var(--text2);
  cursor: pointer; transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}
.ps-menu-item:hover { background: var(--surface2); color: var(--text); }
.ps-menu-item + .ps-menu-item { border-top: 1px solid var(--border); }

/* 結果エリア：検索窓の直下に表示 */
.ps-list-area {
  margin-top: 4px;
  overflow-y: auto;
}
.ps-list-area::-webkit-scrollbar { width: 4px; }
.ps-list-area::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* プルダウンモード（検索時） */
.ps-grid.is-dropdown {
  width: 420px;
  margin: 0 auto;
  border: 2px solid var(--border-strong);
  border-top: none;
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}
.ps-grid.is-dropdown .ps-card {
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
}
.ps-grid.is-dropdown .ps-card:last-child {
  border-bottom: none;
}
.ps-grid.is-dropdown .ps-card:first-child {
  border-top: 2px solid var(--border-strong);
  border-radius: 0;
}

/* カードモード（一覧表示時） */
.ps-grid.is-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding-top: 8px;
}

.ps-card {
  padding: 12px 16px;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s;
  /* aタグのデフォルトスタイルをリセット */
  display: block;
  color: inherit;
  text-decoration: none;
}
/* カード共通ホバー（一覧モード） */
.ps-card:hover { border-color: var(--accent); background: var(--surface2); }

/* プルダウンモードのホバー：背景色のみ変更 */
.ps-grid.is-dropdown .ps-card:hover {
  background: rgba(74, 158, 255, 0.50);
}
.ps-card-name { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.ps-card-id { font-size: 12px; color: var(--text3); }
.ps-empty {
  text-align: center; padding: 20px;
  color: var(--text3); font-size: 13px; line-height: 2;
}

/* ============================================================
   画面2：モード選択画面
   ============================================================ */
.ms-header {
  height: 56px; min-height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ms-header-left { display: flex; align-items: center; gap: 14px; }
.ms-back-btn {
  padding: 6px 12px;
  background: transparent;
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text2);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.12s;
}
.ms-back-btn:hover { border-color: var(--accent); color: var(--accent); }
.ms-logo { font-size: 13px; letter-spacing: 0.08em; color: var(--accent); text-transform: uppercase; cursor: pointer; }
/* モード選択画面：患者名バッジ（分析画面と同じ枠付きデザイン・フォントサイズはモード選択基準） */
.ms-patient-name {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 12px;
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: 5px;
  font-size: 17px;
  font-weight: 700;
}
.ms-header-right { display: flex; gap: 8px; }

.ms-body {
  flex: 1; display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: 20px; padding: 40px;
}
.ms-mode-btn-large {
  width: 560px;
  padding: 22px;
  background: var(--accent2);
  border: 2px solid #9ec5ff;
  border-radius: 12px;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  letter-spacing: 0.05em;
  /* aタグのデフォルトスタイルをリセット */
  text-decoration: none;
  display: block;
}
.ms-mode-btn-large:hover:not(:disabled) { border-color: var(--accent3); background: var(--accent3); }
.ms-mode-btn-large:disabled { opacity: 0.35; cursor: not-allowed; }
.ms-mode-row { display: flex; gap: 16px; width: 560px; }
.ms-mode-btn-half {
  flex: 1;
  padding: 18px;
  background: var(--accent2);
  border: 2px solid #9ec5ff;
  border-radius: 12px;
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  text-align: center;
  letter-spacing: 0.05em;
  /* aタグのデフォルトスタイルをリセット */
  text-decoration: none;
  display: block;
}
.ms-mode-btn-half:hover:not(:disabled) { border-color: var(--accent3); background: var(--accent3); }
.ms-mode-btn-half:disabled { opacity: 0.35; cursor: not-allowed; }
.ms-mode-available { border-color: var(--accent2) !important; }
.ms-badge-soon {
  display: inline-block;
  margin-left: 8px;
  font-size: 12px;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--border-strong);
  color: var(--text);
  font-weight: 400;
  vertical-align: middle;
}

/* 患者検索ボタン（モードボタン群の下・中央） */
.ms-back-to-list {
  padding: 16px 28px;
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.15s;
  letter-spacing: 0.04em;
}
.ms-back-to-list:hover { border-color: var(--accent); background: var(--surface2); }

/* セッション一覧（モーダル内） */
.session-list { margin-bottom: 16px; }
.session-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  margin-bottom: 6px;
  font-size: 14px;
}
.session-item-label { color: var(--text); font-weight: 700; }
.session-item-date { color: var(--text3); font-size: 12px; margin-left: 8px; }
.session-delete-btn {
  padding: 3px 8px;
  background: transparent;
  border: 2px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text3);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.1s;
}
.session-delete-btn:hover { border-color: var(--red); color: var(--red); }
.session-empty { color: var(--text3); font-size: 13px; padding: 8px 0; }

/* ============================================================
   画面2.5：画像登録画面
   ============================================================ */
.ir-header {
  height: 56px; min-height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ir-header-left { display: flex; align-items: center; gap: 14px; }
.ir-logo { font-size: 13px; letter-spacing: 0.08em; color: var(--accent); text-transform: uppercase; cursor: pointer; }
.ir-title { font-size: 15px; color: var(--text2); }
.ir-title strong { color: var(--text); }
.ir-body {
  flex: 1; overflow-y: auto; padding: 28px;
  min-height: 0;
}
.ir-body::-webkit-scrollbar { width: 4px; }
.ir-body::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.ir-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}
.ir-part-card {
  background: var(--surface);
  border: 2px solid var(--border-strong);
  border-radius: 10px;
  overflow: hidden;
}
.ir-part-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.ir-part-name { font-size: 14px; font-weight: 700; }
.ir-part-num { font-size: 12px; color: var(--text3); }
.ir-part-body { padding: 12px 14px; }
.ir-upload-zone {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 6px;
  height: 80px;
  border: 2px dashed var(--border-strong);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.12s;
  color: var(--text3);
  font-size: 13px;
}
.ir-upload-zone:hover { border-color: var(--accent); color: var(--text2); }
.ir-upload-zone.uploaded {
  border-style: solid;
  border-color: var(--green);
  color: var(--green);
}
.ir-upload-icon { font-size: 20px; }
input[type=file] { display: none; }
.ir-footer {
  padding: 16px 28px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 10px;
  flex-shrink: 0;
}

/* ============================================================
   画面3：分析モード
   ============================================================ */
.an-header {
  height: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.an-header-left { display: flex; align-items: center; gap: 10px; }
.an-back-btn {
  display: block;
  padding: 8px 0;
  margin: 0 12px;              /* 左右の外側余白 */
  background: transparent;
  border: 2px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text2); font-size: 14px;
  cursor: pointer; font-family: inherit;
  transition: all 0.1s;
  text-align: center;
  text-decoration: none;
}
.an-back-btn:hover { border-color: var(--accent); color: var(--accent); }
.an-logo { font-size: 13px; letter-spacing: 0.08em; color: var(--accent); text-transform: uppercase; cursor: pointer; }
.an-patient-badge {
  display: flex; align-items: center; gap: 7px;
  padding: 4px 10px;
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: 5px;
  font-size: 15px;
}
.an-patient-badge-link {
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.12s;
}
.an-patient-badge-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.an-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* セッション選択ドロップダウン（ヘッダー内） */
.an-session-select {
  background: var(--surface2);
  border: 2px solid var(--border-strong);
  border-radius: 5px;
  padding: 4px 8px;
  color: var(--text2);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.an-session-select:focus { border-color: var(--accent); }
.an-session-select option { background: var(--surface); }

/* 分析画面ボディ（ツールバー + キャンバス + 右サイドバー） */
.an-body {
  flex: 1; display: flex; flex-direction: column;
  min-height: 0; overflow: hidden;
}
.an-main {
  flex: 1; display: flex; min-height: 0; overflow: hidden;
}

/* ツールバー */
.toolbar {
  height: 44px; min-height: 44px; flex-shrink: 0;
  display: flex; align-items: center; gap: 2px;
  padding: 0 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.toolbar::-webkit-scrollbar { display: none; }
.tool-sep { width: 1px; height: 20px; background: var(--border2); margin: 0 4px; flex-shrink: 0; }
.tool-btn {
  display: flex; align-items: center; gap: 4px;
  padding: 6px 10px;
  border-radius: 4px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text2);
  font-size: 13px;
  cursor: pointer; font-family: inherit;
  white-space: nowrap; flex-shrink: 0;
  transition: all 0.1s;
}
.tool-btn:hover { background: var(--surface2); color: var(--text); }
.tool-btn.active {
  background: rgba(127,176,255,0.22);
  color: var(--text);
  border-color: var(--accent);
}
#scaleDisplay {
  font-size: 12px; color: var(--green);
  font-family: inherit; margin-left: 2px; flex-shrink: 0;
}
.zoom-controls {
  display: flex; align-items: center; gap: 4px;
  flex-shrink: 0;
}
.zoom-label {
  min-width: 44px;
  padding: 0 4px;
  color: var(--text2);
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
}
.zoom-help {
  color: var(--text3);
  font-size: 12px;
  white-space: nowrap;
}
.an-zoom-help-panel {
  border-top: 1px solid var(--border);
  padding: 9px 10px;
  color: var(--text3);
  font-size: 12px;
  line-height: 1.5;
  flex-shrink: 0;
}

/* ダウンロードエリア（トグル＋ボタン） */
.dl-area {
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.dl-toggle {
  display: flex; align-items: center; gap: 4px;
  font-size: 12px; color: var(--text3);
  white-space: nowrap; cursor: pointer;
  user-select: none;
}
.dl-toggle input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 28px; height: 15px;
  background: var(--border);
  border-radius: 8px;
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex-shrink: 0;
}
.dl-toggle input[type="checkbox"]::after {
  content: '';
  position: absolute; top: 2px; left: 2px;
  width: 11px; height: 11px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}
.dl-toggle input[type="checkbox"]:checked {
  background: var(--accent2);
}
.dl-toggle input[type="checkbox"]:checked::after {
  transform: translateX(13px);
}

/* キャンバスエリア */
.canvas-area {
  flex: 1; min-height: 0; min-width: 0;
  background: var(--bg);
  position: relative; overflow: hidden;
}
.canvas-wrapper {
  width: 100%; height: 100%;
  position: relative; overflow: hidden;
  cursor: crosshair;
}
canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%; display: block;
}
.upload-zone {
  position: absolute; inset: 16px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 10px;
  color: var(--text3); font-size: 14px;
  border: 2px dashed var(--border-strong);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.12s;
}
.upload-zone:hover { border-color: var(--accent); color: var(--text2); }
.upload-zone .icon { font-size: 30px; opacity: 0.4; }
.upload-zone .sub { font-size: 12px; opacity: 0.75; }

/* 右サイドバー（部位切り替え） */
.an-sidebar {
  width: 120px; min-width: 120px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
}
.an-sidebar::-webkit-scrollbar { width: 3px; }
.an-sidebar::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }
.sidebar-label {
  padding: 10px 12px 6px;
  font-size: 12px;
  color: var(--text3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.part-btn {
  padding: 11px 12px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: all 0.1s;
  line-height: 1.4;
  position: relative;
  /* aタグのデフォルトスタイルをリセット */
  display: block;
  text-decoration: none;
}
.part-btn:hover { background: var(--surface2); color: var(--text); }
.part-btn.active {
  background: rgba(127,176,255,0.18);
  color: var(--text);
  border-left: 4px solid var(--accent);
}

/* ============================================================
   分析モード：左サイドバー（手入力パネル）
   ============================================================ */

/* 左サイドバー全体 */
.an-left-sidebar {
  width: 140px; min-width: 140px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0;
}

/* 左サイドバーのラベル */
.an-left-sidebar-label {
  padding: 10px 12px 6px;
  font-size: 12px;
  color: var(--text3);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* テキストエリア */
.an-notes-textarea {
  flex: 1;
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 17px;
  font-family: inherit;
  padding: 10px 12px;
  resize: none;
  outline: none;
  line-height: 1.7;
  overflow-y: auto;
}
.an-notes-textarea:focus { background: rgba(74,158,255,0.04); }
.an-notes-textarea::placeholder { color: var(--text3); font-size: 13px; }
.an-notes-textarea::-webkit-scrollbar { width: 3px; }
.an-notes-textarea::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* 保存中インジケーター（左サイドバー下部） */
.an-notes-status {
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text3);
  letter-spacing: 0.05em;
  flex-shrink: 0;
  min-height: 20px;
}
.an-download-panel {
  border-top: 1px solid var(--border);
  padding: 10px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.an-download-panel .dl-toggle {
  font-size: 13px;
  color: var(--text2);
}
.an-download-btn {
  width: 100%;
  justify-content: center;
  padding: 8px 8px;
  border: 2px solid var(--border-strong);
  background: var(--surface2);
  color: var(--text2);
}
.an-download-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* キャンバス左上の手入力テキスト表示パネル */
.an-notes-overlay {
  position: absolute;
  top: 10px; left: 10px;
  background: rgba(0,0,0,0.62);
  border-radius: 4px;
  padding: 5px 9px;
  font-size: 13px;
  font-weight: 700;
  color: #f5f5f5;
  line-height: 1.7;
  pointer-events: none;  /* クリックをキャンバスに透過させる */
  white-space: pre;      /* 改行をそのまま表示 */
  z-index: 2;
  display: none;         /* 未入力時は非表示 */
  letter-spacing: 0.03em;
}

/* ============================================================
   画面4：一覧モード
   ============================================================ */

/* 画面全体：ヘッダーなし、グリッドとボタンエリアで構成 */
.lm-screen {
  width: 100%; height: 100%;
  display: grid;
  /* 4列×2行。右下のボタンエリアは自動サイズ */
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(2, 1fr);
  gap: 6px;
  padding: 6px;
  background: var(--bg);
  box-sizing: border-box;
}

/* 一覧表示だけ、無操作時はカーソルを隠す */
.lm-screen.cursor-idle,
.lm-screen.cursor-idle .lm-cell,
.lm-screen.cursor-idle .lm-cell canvas {
  cursor: none;
}

/* 各画像セル */
.lm-cell {
  background: #050709;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: outline 0.1s;
  /* aタグのデフォルトスタイルをリセット */
  display: block;
  text-decoration: none;
  color: inherit;
}
.lm-cell:hover { outline: 2px solid var(--accent); }

/* セル内のキャンバス */
.lm-cell canvas {
  width: 100%; height: 100%;
  display: block;
  position: absolute; top: 0; left: 0;
}

/* 部位名ラベル（左上に表示） */
.lm-cell-label {
  position: absolute; top: 6px; left: 8px;
  font-size: 13px; color: rgba(255,255,255,0.9);
  font-weight: 700;
  letter-spacing: 0.05em;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
  z-index: 1;
}

/* 画像なし状態のプレースホルダー */
.lm-cell-empty {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  font-size: 14px;
}

/* 右下のボタンエリア */
.lm-btn-area {
  background: var(--bg);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 20px;
}

/* ボタンエリア内のセッション選択 */
.lm-session-select {
  width: 100%;
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  text-align: center;
}
.lm-session-select:focus { border-color: var(--accent); }
.lm-session-select option { background: var(--surface); }

/* ボタンエリア内のボタン共通 */
.lm-action-btn {
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  color: var(--text2);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.12s;
  text-align: center;
  font-weight: 700;
  text-decoration: none;
}
.lm-action-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================
   一覧モード：1枚拡大表示
   ============================================================ */

/* 拡大表示のオーバーレイ（全画面に被せる） */
.lm-expand-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: none;
  flex-direction: column;
  z-index: 100;
}
.lm-expand-overlay.open { display: flex; }

/* 拡大表示のメインエリア（画像） */
.lm-expand-main {
  flex: 1;
  display: flex;
  min-height: 0;
  background: #050709;
  position: relative;
}

/* 拡大表示の画像キャンバス */
.lm-expand-canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: none;
}
.lm-expand-canvas-wrap canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
  cursor: none;
}

/* 拡大表示のフッター（ボタン類） */
.lm-expand-footer {
  height: 52px; min-height: 52px;
  display: flex; align-items: center;
  gap: 10px; padding: 0 20px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  overflow-x: auto;
}

/* ============================================================
   画面5：説明モード
   ============================================================ */

/* ヘッダー（分析モードと同じ高さ） */
.ex-header {
  height: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 14px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ex-header-left  { display: flex; align-items: center; gap: 10px; }
.ex-header-right { display: flex; align-items: center; gap: 8px; }
.ex-logo { font-size: 13px; letter-spacing: 0.08em; color: var(--accent); text-transform: uppercase; cursor: pointer; }

/* モード選択に戻るボタン */
.ex-back-btn {
  padding: 5px 10px;
  background: transparent;
  border: 2px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text2); font-size: 14px;
  cursor: pointer; font-family: inherit;
  transition: all 0.1s;
}
.ex-back-btn:hover { border-color: var(--accent); color: var(--accent); }

/* 現在のサブモード表示バッジ（Normal & Pre / Pre & Post） */
.ex-mode-badge {
  padding: 4px 10px;
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: 5px;
  font-size: 13px; font-weight: 700;
  color: var(--text2);
}

/* 全画面表示ボタン */
.ex-fullscreen-btn {
  padding: 5px 10px;
  background: transparent;
  border: 2px solid var(--border-strong);
  border-radius: 5px;
  color: var(--text2); font-size: 14px;
  cursor: pointer; font-family: inherit;
  transition: all 0.1s;
}
.ex-fullscreen-btn:hover { border-color: var(--accent); color: var(--accent); }

/* メインエリア（左右パネル + 右サイドバー） */
.ex-body {
  flex: 1; display: flex; min-height: 0; overflow: hidden;
}

/* 左右パネルを並べるコンテナ */
.ex-panels {
  flex: 1; display: flex; gap: 4px;
  padding: 4px; min-width: 0;
  background: var(--bg);
}

/* 左パネル・右パネル共通 */
.ex-panel {
  flex: 1; display: flex; flex-direction: column;
  min-width: 0; background: #050709;
  border-radius: 4px; overflow: hidden;
}

/* パネル上部のセッション選択バー */
.ex-panel-header {
  height: 32px; min-height: 32px;
  display: flex; align-items: center; justify-content: center;
  gap: 8px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 10px;
}
.ex-panel-label {
  font-size: 13px; color: var(--text3);
  letter-spacing: 0.06em; white-space: nowrap;
}

/* パネル内のセッション選択ドロップダウン */
.ex-session-select {
  background: var(--surface2);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 3px 7px;
  color: var(--text2);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.ex-session-select:focus { border-color: var(--accent); }
.ex-session-select option { background: var(--surface); }

/* パネル内のキャンバスラッパー */
.ex-canvas-wrap {
  flex: 1; position: relative; overflow: hidden;
  cursor: none;
}
.ex-canvas-wrap canvas {
  position: absolute; top: 0; left: 0;
  width: 100%; height: 100%;
}
.ex-laser-pointer {
  position: absolute;
  left: 0; top: 0;
  width: 22px; height: 22px;
  border: 2px solid rgba(255, 96, 120, 0.95);
  border-radius: 50%;
  background:
    radial-gradient(circle, rgba(255,245,245,1) 0 2px, rgba(220,20,60,0.98) 3px 5px, rgba(220,20,60,0.2) 6px 9px, transparent 10px);
  box-shadow: 0 0 7px rgba(220, 20, 60, 0.95), 0 0 15px rgba(220, 20, 60, 0.55);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.08s;
  z-index: 4;
}
.ex-laser-pointer.show { opacity: 1; }

/* 画像なし状態 */
.ex-no-image {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2); font-size: 14px;
}

/* 右サイドバー（部位切り替え）：分析モードと同じ構造 */
.ex-sidebar {
  width: 120px; min-width: 120px;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0; overflow-y: auto;
}
.ex-sidebar::-webkit-scrollbar { width: 3px; }
.ex-sidebar::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ============================================================
   サンプル画像管理モーダル内スタイル
   ============================================================ */

/* サンプル管理：7部位のグリッド */
.sample-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

/* 各部位のカード */
.sample-card {
  background: var(--bg);
  border: 2px solid var(--border-strong);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
}
.sample-card-name {
  font-size: 14px; font-weight: 700;
  color: var(--text2); flex-shrink: 0;
}
.sample-card-status {
  font-size: 12px; color: var(--text3);
}
.sample-card-status.has-image { color: var(--green); }

/* サンプル画像のアップロードボタン（小さいボタン） */
.sample-upload-btn {
  padding: 4px 9px;
  background: transparent;
  border: 2px solid var(--border-strong);
  border-radius: 4px;
  color: var(--text2); font-size: 13px;
  cursor: pointer; font-family: inherit;
  transition: all 0.1s; white-space: nowrap;
}
.sample-upload-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================
   認証：ログイン画面
   ============================================================ */
#login-screen {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  width: 320px;
  display: flex; flex-direction: column;
  align-items: center; gap: 16px;
}
.login-logo {
  font-size: 13px; letter-spacing: 0.08em;
  color: var(--accent); text-transform: uppercase;
  margin-bottom: 8px;
}
.login-title { font-size: 17px; color: var(--text2); font-weight: 700; }
.login-input {
  width: 100%;
  background: var(--surface);
  border: 2px solid var(--border-strong); border-radius: 8px;
  padding: 12px 16px; color: var(--text);
  font-size: 17px; font-family: inherit;
  outline: none; text-align: center;
  letter-spacing: 0.1em; transition: border-color 0.15s;
}
.login-input:focus { border-color: var(--accent); }
.login-error { font-size: 13px; color: var(--red); min-height: 18px; text-align: center; }
.login-btn {
  width: 100%; padding: 12px;
  background: var(--accent2); border: none; border-radius: 8px;
  color: #fff; font-size: 15px; font-weight: 700;
  font-family: inherit; cursor: pointer; transition: background 0.12s;
}
.login-btn:hover { background: var(--accent3); }