/* 日韓通訳オンライン診療 試作版 共通スタイル */
:root {
  --bg: #ffffff;
  --panel: #f5f7fa;
  --panel-2: #ffffff;
  --border: #d0d7e2;
  --text: #111111;
  --text-dim: #555e6b;
  --accent: #2563eb;
  --accent-2: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --doctor-color: #2563eb;
  --patient-color: #16a34a;
  font-size: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans KR", "Malgun Gothic", sans-serif;
  min-height: 100%;
}

body { padding: 16px; }

h1, h2, h3 { margin: 0 0 8px; }

button {
  font-family: inherit;
  font-size: 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 10px 16px;
  cursor: pointer;
}
button:hover { filter: brightness(1.15); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 700; }
button.success { background: var(--accent-2); border-color: var(--accent-2); color: #fff; font-weight: 700; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
button.ghost { background: transparent; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  font-family: inherit;
  font-size: 1rem;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
}
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: 0.85rem; color: var(--text-dim); margin: 10px 0 4px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 14px;
}

.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.hint { font-size: 0.8rem; color: var(--text-dim); }
.error-text { color: var(--danger); font-size: 0.85rem; }

[hidden] { display: none !important; }

/* ヘッダー */
.app-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.app-header h1 { font-size: 1.2rem; }
.gear-btn { font-size: 1.3rem; padding: 6px 10px; }

/* 設定パネル */
#settingsPanel { position: relative; }
#settingsPanel .card { max-height: 70vh; overflow-y: auto; }

/* PINロック */
.center-screen {
  min-height: 80vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
}
.pin-input {
  letter-spacing: 0.5em; text-align: center; font-size: 1.5rem; max-width: 220px;
}

/* URL発行 */
#issuedUrlBox {
  word-break: break-all;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 10px;
  font-size: 0.85rem;
  margin-top: 8px;
}

/* 待合 */
.knock-box {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--panel-2); border-radius: 10px; padding: 12px;
}

/* 通話画面 */
.call-wrap { position: relative; }
.video-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #000;
  border-radius: 14px;
  overflow: hidden;
}
body[data-role="patient"] .video-stage { aspect-ratio: 3 / 4; }
video.remote-video { width: 100%; height: 100%; object-fit: cover; background: #000; }
video.local-video {
  position: absolute; right: 10px; bottom: 10px;
  width: 28%; max-width: 160px; aspect-ratio: 3/4;
  object-fit: cover; border-radius: 10px; border: 2px solid var(--border);
  background: #111;
}

/* ---- 医師: 通話画面（2カラム＝映像/字幕）100vh内に収める ---- */
body[data-role="doctor"] #mainScreen {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 32px);
  overflow: hidden;
}
body[data-role="doctor"] #mainScreen > * { flex: 0 0 auto; }
body[data-role="doctor"] #callCard.call-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
body[data-role="doctor"] #callCard h3,
body[data-role="doctor"] #doctorWaitingHint { flex: 0 0 auto; margin: 0 0 6px; }
body[data-role="doctor"] .call-body {
  display: flex;
  gap: 12px;
  flex: 1 1 auto;
  min-height: 0;
}
body[data-role="doctor"] .video-col {
  flex: 1 1 60%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
body[data-role="doctor"] .video-col .video-stage {
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(100vh - 220px);
  aspect-ratio: auto;
}
body[data-role="doctor"] .video-col .badge-row,
body[data-role="doctor"] .video-col .controls-row { flex: 0 0 auto; margin: 4px 0; }
body[data-role="doctor"] .subtitle-col {
  flex: 0 0 40%;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
body[data-role="doctor"] .subtitle-col .subtitle-log {
  flex: 6 1 0;
  min-height: 0;
  max-height: none;
  height: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  background: var(--panel-2);
  overflow-y: auto;
}

/* カルテメモ（医師画面のみ・右カラム下段40%） */
body[data-role="doctor"] .subtitle-col .karte-memo {
  flex: 4 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  background: var(--panel-2);
}
.karte-memo-header {
  display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap;
  flex: 0 0 auto;
}
.karte-memo-header h4 { margin: 0; font-size: 0.85rem; color: var(--text-dim); }
.karte-memo-actions { gap: 6px; }
.karte-memo-actions button { padding: 4px 8px; font-size: 0.72rem; }
#karteMemoText {
  flex: 1 1 auto;
  min-height: 0;
  resize: none;
  font-size: 0.85rem;
}
#karteCopyHint { flex: 0 0 auto; margin: 0; color: var(--accent-2); }

/* 患者用URL カードの折りたたみ（通話中は1行に） */
.issue-header { display: flex; justify-content: space-between; align-items: center; cursor: pointer; }
.issue-header h3 { margin: 0; }
#issueCard.collapsed .issue-details { display: none; }
#issueCard .issue-summary { font-size: 0.8rem; color: var(--text-dim); }

/* 字幕枠プレースホルダ */
.subtitle-placeholder { color: var(--text-dim); font-size: 0.85rem; padding: 6px 4px; }
.subtitle-bubble .who { display: inline-flex; gap: 6px; align-items: baseline; }
.subtitle-bubble .who .ts { font-size: 0.65rem; opacity: 0.8; }

/* ---- 患者: 通話画面（映像/字幕/操作を100vh内に収める） ---- */
body[data-role="patient"] #callScreen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 10px;
  overflow: hidden;
  background: var(--bg);
}
body[data-role="patient"] #callScreen .video-stage {
  flex: 0 0 auto;
  max-height: 45vh;
  aspect-ratio: auto;
  width: 100%;
}
body[data-role="patient"] #callScreen .subtitle-log {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  background: var(--panel-2);
  margin: 0;
}
body[data-role="patient"] #callScreen .badge-row,
body[data-role="patient"] #callScreen .controls-row { flex: 0 0 auto; margin: 0; }
body[data-role="patient"] .subtitle-bubble.from-doctor .main-text { font-size: 1.4rem; line-height: 1.3; }
body[data-role="patient"] .subtitle-bubble.from-patient .main-text { font-size: 0.9rem; }

/* 待機室スピナー（CSSのみ） */
.wait-spinner {
  width: 36px; height: 36px; margin: 14px auto;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: telemed-spin 0.9s linear infinite;
}
@keyframes telemed-spin { to { transform: rotate(360deg); } }

.badge-row { display: flex; gap: 8px; margin: 10px 0; flex-wrap: wrap; }
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 0.8rem;
  background: var(--panel-2); border: 1px solid var(--border);
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim); }
.badge.state-listening .dot { background: var(--accent); }
.badge.state-translating .dot { background: var(--warn); }
.badge.state-speaking .dot { background: var(--accent-2); }
.badge.state-error .dot { background: var(--danger); }
.badge.state-idle .dot { background: var(--text-dim); }

.controls-row { display: flex; gap: 8px; justify-content: center; margin: 10px 0; flex-wrap: wrap; }
.controls-row button { flex: 1 1 auto; min-width: 90px; }

.subtitle-log {
  max-height: 40vh; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px;
  padding: 4px 2px;
}
.subtitle-bubble {
  border-radius: 12px; padding: 8px 12px; max-width: 90%;
}
.subtitle-bubble.from-doctor { align-self: flex-start; background: rgba(59,130,246,0.15); border: 1px solid var(--doctor-color); }
.subtitle-bubble.from-patient { align-self: flex-end; background: rgba(34,197,94,0.15); border: 1px solid var(--patient-color); }
.subtitle-bubble .who { font-size: 0.7rem; color: var(--text-dim); margin-bottom: 2px; }
.subtitle-bubble .main-text { font-size: 1.05rem; font-weight: 600; }
.subtitle-bubble .sub-text { font-size: 0.8rem; color: var(--text-dim); margin-top: 2px; }
.subtitle-bubble.interim { opacity: 0.55; font-style: italic; }
.subtitle-bubble.warn { background: rgba(245,158,11,0.15); border-color: var(--warn); }

.banner {
  border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; font-size: 0.9rem;
}
.banner.info { background: rgba(59,130,246,0.15); border: 1px solid var(--accent); }
.banner.warn { background: rgba(245,158,11,0.15); border: 1px solid var(--warn); }
.banner.error { background: rgba(239,68,68,0.15); border: 1px solid var(--danger); }

/* 患者用トップ */
.patient-hero { text-align: center; padding: 24px 8px; }
.patient-hero button.primary { font-size: 1.2rem; padding: 16px 28px; width: 100%; max-width: 320px; }

@media (max-width: 480px) {
  body { padding: 10px; }
  .card { padding: 12px; }
}

/* アプリ内ブラウザ案内のリンクボタン */
a.link-btn {
  display: inline-block;
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 10px;
  padding: 10px 16px;
  text-decoration: none;
  margin: 10px 0;
}
a.link-btn:hover { filter: brightness(1.15); }

/* リンク・入力欄（白背景用） */
a { color: var(--accent); }
input, select, textarea { background: #fff; color: var(--text); border: 1px solid var(--border); }
