/* PerioChart — AppBuilder風ティールUI / iPad横向き */

:root {
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --teal-light: #ccfbf1;
  --teal-bg: #f0fdfa;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --warn-bg: #fef9c3;
  --warn-border: #fde047;
  --danger: #ef4444;
  --orange: #f97316;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

#app { min-height: 100vh; }

/* ── 共通 ── */
.screen { min-height: 100vh; display: flex; flex-direction: column; }

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand, .brand-sm {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--teal-dark);
}

.brand-icon { font-size: 1.4rem; }

.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn:active { transform: scale(.97); }

.btn-primary {
  background: var(--teal);
  color: #fff;
}

.btn-primary:hover { background: var(--teal-dark); }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn-lg { padding: 14px 32px; font-size: 1.05rem; }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 1rem;
}

.badge {
  background: var(--teal-light);
  color: var(--teal-dark);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin: 12px 20px;
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card h2 { margin: 0; font-size: 1rem; }

.hidden { display: none !important; }

/* ── 患者検索 ── */
.search-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 20px;
}

.search-hero {
  text-align: center;
  max-width: 480px;
  width: 100%;
}

.hero-icon {
  width: 72px;
  height: 72px;
  margin: 0 auto 16px;
  background: var(--teal-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
}

.search-hero h1 { margin: 0 0 8px; font-size: 1.8rem; }
.search-hero p { color: var(--muted); margin: 0 0 24px; }

.search-box {
  display: flex;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 14px;
  margin-bottom: 16px;
}

.search-box input {
  flex: 1;
  border: none;
  outline: none;
  padding: 14px 8px;
  font-size: 1rem;
}

.hint { color: var(--muted); font-size: 0.85rem; margin-top: 16px; }

/* ── モーダル ── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 28px;
  width: 100%;
  max-width: 420px;
  position: relative;
}

.modal-wide { max-width: 560px; }

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
}

.modal-card label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
  font-weight: 600;
}

.modal-card input {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.exam-type-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 16px 0;
}

.exam-type-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
  cursor: pointer;
  background: var(--card);
}

.exam-type-card.selected {
  border-color: var(--teal);
  background: var(--teal-bg);
}

.exam-type-card h3 { margin: 0 0 6px; font-size: 1rem; }
.exam-type-card p { margin: 0; font-size: 0.85rem; color: var(--muted); }

/* ── 患者ページ ── */
.patient-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.patient-avatar {
  width: 44px;
  height: 44px;
  background: var(--teal-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.patient-name { font-weight: 700; font-size: 1.1rem; }
.patient-id { color: var(--muted); font-size: 0.85rem; }

.patient-screen {
  max-height: 100dvh;
  overflow: hidden;
}

.preview-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-card h2 {
  flex-shrink: 0;
}

.preview-scroll {
  flex: 1;
  min-height: 0;
  max-height: 360px;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

.mini-chart.readonly { pointer-events: none; }

.empty-msg { color: var(--muted); text-align: center; padding: 24px; }

.draft-notice {
  color: var(--orange);
  font-size: 0.9rem;
  margin: 8px 0 0;
}

.exam-preview-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.exam-preview-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 0.85rem;
}

.mini-chart {
  transform: scale(0.55);
  transform-origin: top left;
  overflow: hidden;
  width: calc(100% / 0.55);
  max-width: none;
}

.mini-chart-basic {
  height: 500px;
  margin-bottom: -225px;
}

.mini-chart-detailed {
  transform: scale(0.4);
  width: calc(100% / 0.4);
  height: 680px;
  margin-bottom: calc(-680px * 0.6);
}

.mini-chart .chart-grid {
  width: calc(83px * 16 + 15px);
  max-width: none;
}

.mini-chart-detailed .chart-grid {
  width: calc(55px * 3 * 16 + 15px);
}

.mini-chart.mini-arch-normal28 .chart-grid {
  width: calc(83px * 14 + 15px);
}

.mini-chart-detailed.mini-arch-normal28 .chart-grid {
  width: calc(55px * 3 * 14 + 15px);
}

/* ── 検査ページ ── */
.exam-screen {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.exam-workspace {
  flex: 1;
  min-height: 0;
  display: flex;
  margin: 0 4px 4px;
}

.exam-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.exam-chart-row {
  flex: 0 1 auto;
  display: flex;
  align-items: stretch;
  gap: 4px;
  min-height: 0;
  max-height: 42%;
}

.exam-chart-row .chart-area {
  flex: 1;
  min-width: 0;
  margin: 0;
}

.exam-side-rail {
  flex-shrink: 0;
  width: 76px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.exam-side-rail .btn {
  padding: 10px 6px;
  font-size: 0.78rem;
  line-height: 1.2;
  white-space: normal;
  text-align: center;
}

.exam-input-dock {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 8px 12px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.exam-input-dock .float-keypad {
  position: static;
  transform: none;
  left: auto;
  bottom: auto;
  box-shadow: none;
  padding: 0;
  max-width: none;
  background: transparent;
}

.exam-input-dock-missing {
  flex-wrap: wrap;
  row-gap: 10px;
}

.btn-undo-dock {
  flex-shrink: 0;
  min-width: 64px;
}

.exam-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.exam-top-left { display: flex; align-items: center; gap: 12px; }

.exam-type-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.toggle-btn {
  border: 1px solid var(--border);
  background: var(--card);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.toggle-btn.active {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.phase-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: var(--teal-bg);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}

.phase-steps { display: flex; gap: 4px; flex-wrap: wrap; }

.phase-step {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8rem;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--border);
}

.phase-step.active {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

.phase-step.done { color: var(--teal-dark); border-color: var(--teal); }

.phase-meta { display: flex; gap: 10px; align-items: center; font-size: 0.8rem; color: var(--muted); }

.phase-bar-nav {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-left: auto;
}

.phase-missing-stats {
  display: flex;
  gap: 12px;
  align-items: center;
  font-size: 0.85rem;
}

.btn-voice-dock {
  flex-shrink: 0;
  min-width: 64px;
}

.exam-side-rail:empty {
  min-width: 76px;
}

.step-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 6px 12px;
  gap: 12px;
  flex-wrap: wrap;
}

.step-header h1 { margin: 0 0 2px; font-size: 1rem; }
.step-desc { margin: 0; color: var(--muted); font-size: 0.8rem; }

.step-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.missing-stats {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-top: 8px;
  font-size: 0.9rem;
}

.alert {
  margin: 0 16px 8px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.85rem;
}

.alert-info {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
}

/* ── 歯式チャート ── */
.perio-container {
  transform-origin: top center;
  width: max-content;
  max-width: 100%;
  margin-inline: auto;
}

.chart-area {
  flex: 1;
  overflow: hidden;
  padding: 2px 4px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 0;
}

.exam-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  margin: 0 4px;
  gap: 4px;
}

.exam-body .chart-area {
  margin: 0;
}

.exam-past-section {
  flex: 1;
  min-height: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px 12px 10px;
  display: flex;
  flex-direction: column;
}

.exam-past-title {
  margin: 0 0 6px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}

.exam-past-scroll {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

/* ステップ4（確認・確定）のみ */
.exam-screen.phase-review .exam-chart-row {
  flex: 1 1 auto;
  max-height: 62%;
}

.exam-screen.phase-review .exam-past-section {
  flex: 0 0 auto;
  max-height: 360px;
}

.exam-screen.phase-review .exam-past-scroll {
  flex: 0 0 auto;
  min-height: 320px;
  max-height: 320px;
}

.exam-screen.phase-review .chart-area .tooth-col:not(.detailed-col) .zp-box {
  width: 42px;
  height: 42px;
}

.exam-screen.phase-review .chart-area .tooth-col:not(.detailed-col) .zp-digit {
  font-size: 22px;
}

.exam-screen.phase-review .chart-area .tooth-col:not(.detailed-col) .zp-arch-upper .zp-digit { bottom: 7px; }
.exam-screen.phase-review .chart-area .tooth-col:not(.detailed-col) .zp-arch-upper.zp-UL .zp-digit { right: 8px; }
.exam-screen.phase-review .chart-area .tooth-col:not(.detailed-col) .zp-arch-upper.zp-UR .zp-digit { left: 8px; }
.exam-screen.phase-review .chart-area .tooth-col:not(.detailed-col) .zp-arch-lower .zp-digit { top: 7px; }
.exam-screen.phase-review .chart-area .tooth-col:not(.detailed-col) .zp-arch-lower.zp-LL .zp-digit { right: 8px; }
.exam-screen.phase-review .chart-area .tooth-col:not(.detailed-col) .zp-arch-lower.zp-LR .zp-digit { left: 8px; }

.chart-grid {
  width: calc(100vw - 24px);
  max-width: 100%;
}

.arch-row {
  display: flex;
  justify-content: center;
  gap: 1px;
}

.midline {
  text-align: center;
  padding: 2px 0;
  border-top: 1px dashed var(--border);
  border-bottom: 1px dashed var(--border);
  margin: 2px 0;
}

.midline span {
  font-size: 0.55rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  font-weight: 600;
}

/* ── Zsigmondy 歯式（L字ボックス — 補助情報） ── */
.zp-box {
  position: relative;
  width: 32px;
  height: 32px;
  margin: 1px 0;
  flex-shrink: 0;
  opacity: 0.85;
  box-sizing: border-box;
  align-self: center;
}

/* 水平線：上顎=bottom / 下顎=top（Zsigmondy ┘└┌┐ に合わせる） */
.zp-arch-upper { border-bottom: 2.5px solid #b45309; }
.zp-arch-lower { border-top: 2.5px solid #b45309; }

/* 垂直線：左象限=left / 右象限=right */
.zp-box.zp-UL,
.zp-box.zp-LL { border-left: 2.5px solid #b45309; }

.zp-box.zp-UR,
.zp-box.zp-LR { border-right: 2.5px solid #b45309; }

.zp-digit {
  position: absolute;
  font-size: 17px;
  font-weight: 600;
  color: #b45309;
  line-height: 1;
}

/* 上顎：数字は下寄せ（カギ内側） */
.zp-arch-upper .zp-digit { bottom: 5px; }
.zp-arch-upper.zp-UL .zp-digit { right: 6px; }
.zp-arch-upper.zp-UR .zp-digit { left: 6px; }

/* 下顎：数字は上寄せ（カギ内側） */
.zp-arch-lower .zp-digit { top: 5px; }
.zp-arch-lower.zp-LL .zp-digit { right: 6px; }
.zp-arch-lower.zp-LR .zp-digit { left: 6px; }

/* 基本検査 — 1.5倍幅に合わせた Zigmondy */
.tooth-col:not(.detailed-col) .zp-box {
  width: 48px;
  height: 48px;
}

.tooth-col:not(.detailed-col) .zp-arch-upper { border-bottom-width: 3.5px; }
.tooth-col:not(.detailed-col) .zp-arch-lower { border-top-width: 3.5px; }
.tooth-col:not(.detailed-col) .zp-box.zp-UL,
.tooth-col:not(.detailed-col) .zp-box.zp-LL { border-left-width: 3.5px; }
.tooth-col:not(.detailed-col) .zp-box.zp-UR,
.tooth-col:not(.detailed-col) .zp-box.zp-LR { border-right-width: 3.5px; }

.tooth-col:not(.detailed-col) .zp-digit {
  font-size: 25px;
}

.tooth-col:not(.detailed-col) .zp-arch-upper .zp-digit { bottom: 8px; }
.tooth-col:not(.detailed-col) .zp-arch-upper.zp-UL .zp-digit { right: 9px; }
.tooth-col:not(.detailed-col) .zp-arch-upper.zp-UR .zp-digit { left: 9px; }
.tooth-col:not(.detailed-col) .zp-arch-lower .zp-digit { top: 8px; }
.tooth-col:not(.detailed-col) .zp-arch-lower.zp-LL .zp-digit { right: 9px; }
.tooth-col:not(.detailed-col) .zp-arch-lower.zp-LR .zp-digit { left: 9px; }

.tooth-col {
  width: calc((100vw - 32px) / 16);
  max-width: 72px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.tooth-col:not(.detailed-col) {
  max-width: 108px;
}

.tooth-col.detailed-col {
  max-width: none;
}

.tooth-col.missing { cursor: pointer; align-self: stretch; }

.tooth-body {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.missing-fill {
  background: #334155;
  width: 100%;
  flex: 1;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
}

.excluded-fill {
  background: #fff;
  width: 100%;
  flex: 1;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  border: 1px solid var(--border);
}

.excluded-mark {
  color: #0f172a;
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1;
}

.missing-icon { color: #94a3b8; font-size: 1.4rem; }

.tooth-col.excluded { cursor: pointer; align-self: stretch; }

.site-row-spacer {
  min-height: 4px;
}

/* 検査開始後の欠損歯 — グレー塗りのみ（Zigmondy・マーク非表示） */
.tooth-col.missing-blocked {
  cursor: default;
  align-self: stretch;
  pointer-events: none;
}

.missing-block {
  width: 100%;
  flex: 1;
  min-height: 72px;
  background: #334155;
  border-radius: 4px;
}

.missing-block.excluded-block {
  display: flex;
  align-items: center;
  justify-content: center;
}

.excluded-block-mark {
  color: #fff;
  font-size: 2.8rem;
  font-weight: 800;
  line-height: 1;
}

.missing-mob-spacer {
  width: 100%;
  height: 40px;
  margin: 1px 0;
  flex-shrink: 0;
}

.tooth-col:not(.detailed-col) .missing-mob-spacer {
  height: 60px;
}

.site-row {
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  width: 100%;
  justify-content: center;
}

.site-row.detailed-row {
  flex-direction: row;
  gap: 3px;
  justify-content: center;
}

.site-row.detailed-row .site-cell {
  flex: 1;
  min-width: 0;
  width: calc((100vw - 32px) / 48);
  max-width: 55px;
}

.site-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-align: center;
  padding: 1px 0;
  border-radius: 2px;
  cursor: default;
}

.site-cell[data-cell] { cursor: pointer; }

.site-cell.focused {
  outline: 2px solid #5eead4;
  outline-offset: -1px;
  background: #f0fdfa;
}

.site-cell.last-committed .pd-value {
  box-shadow: inset 0 0 0 2px #0d9488;
}

.pd-value {
  font-size: clamp(30px, 3.8vw, 38px);
  font-weight: 800;
  line-height: 1.05;
  min-height: 1.15em;
  width: 100%;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.02em;
}

.bop-btn {
  display: block;
  width: 90%;
  max-width: 48px;
  margin-top: 2px;
  padding: 2px 0;
  font-size: 0.55rem;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: 0.03em;
  border-radius: 10px;
  border: 1px solid #fca5a5;
  background: #fff;
  color: #b91c1c;
  cursor: pointer;
  flex-shrink: 0;
}

.site-cell.bop-above .bop-btn {
  margin-top: 0;
  margin-bottom: 2px;
}

.bop-btn.bop-on {
  background: #fecdd3;
  color: #9f1239;
  border-color: #f87171;
}

.bop-btn.bop-readonly {
  cursor: default;
  pointer-events: none;
}

/* 基本検査 — 1.5倍幅に合わせた BOP */
.tooth-col:not(.detailed-col) .bop-btn {
  max-width: 72px;
  padding: 3px 0;
  font-size: 0.82rem;
  border-radius: 12px;
}

/* 基本検査 — 検査表内の縦余白圧縮（Zigmondy ↔ BOP 間） */
.chart-area .tooth-col:not(.detailed-col) .zp-box {
  margin: 0;
}

.chart-area .tooth-col:not(.detailed-col) .site-cell {
  padding: 0;
}

.chart-area .tooth-col:not(.detailed-col) .bop-btn {
  margin: 0;
  padding: 1px 0;
}

.chart-area .tooth-col:not(.detailed-col) .site-cell.bop-above .bop-btn {
  margin-bottom: 0;
}

.chart-area .tooth-col:not(.detailed-col) .site-cell.bop-below .bop-btn {
  margin-top: 0;
}

.chart-area .tooth-col:not(.detailed-col) .tooth-body > .buccal-row,
.chart-area .tooth-col:not(.detailed-col) .tooth-body > .lingual-row {
  margin-top: -2px;
  margin-bottom: -2px;
}

.chart-area .tooth-col:not(.detailed-col) .pd-value {
  min-height: 0;
  line-height: 1;
}

/* パステルカラー（プロービング・動揺度共通） */
.pd-value.pd-green, .mob-slot.pd-green { color: #047857; background: #ecfdf5; }
.pd-value.pd-orange, .mob-slot.pd-orange { color: #c2410c; background: #fff7ed; }
.pd-value.pd-red, .mob-slot.pd-red { color: #b91c1c; background: #fef2f2; }
.mob-slot.val-gray { color: #64748b; background: #f1f5f9; }

.pd-btn.pd-green { background: #d1fae5; color: #047857; border: 1px solid #a7f3d0; }
.pd-btn.pd-orange { background: #ffedd5; color: #c2410c; border: 1px solid #fed7aa; }
.pd-btn.pd-red { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

.mob-btn.val-gray { background: #f1f5f9; color: #64748b; border: 2px solid #e2e8f0; }
.mob-btn.pd-green { background: #d1fae5; color: #047857; border: 2px solid #a7f3d0; }
.mob-btn.pd-orange { background: #ffedd5; color: #c2410c; border: 2px solid #fed7aa; }
.mob-btn.pd-red { background: #fee2e2; color: #b91c1c; border: 2px solid #fecaca; }

.mob-slot {
  width: 100%;
  height: 40px;
  font-size: clamp(22px, 2.6vw, 28px);
  font-weight: 700;
  line-height: 40px;
  text-align: center;
  border-radius: 4px;
  margin: 1px 0;
  letter-spacing: -0.01em;
}

/* 基本検査のみ — 動揺度（1.5倍幅に合わせて拡大） */
.tooth-col:not(.detailed-col) .mob-slot {
  height: auto;
  min-height: 27px;
  padding: 3px 2px;
  font-size: clamp(14px, 1.8vw, 17px);
  line-height: 1.2;
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
}

.mob-slot.focused {
  outline: 2px solid #5eead4;
  outline-offset: -1px;
}

.hidden-input { visibility: hidden; height: 0; overflow: hidden; min-height: 0 !important; padding: 0 !important; }

.present[data-toggle-missing] { cursor: pointer; }

/* ── ツールバー & キーパッド ── */
.btn-voice { background: var(--teal-light); color: var(--teal-dark); border: 1px solid var(--teal); }
.btn-voice-on { background: var(--teal); color: #fff; }

.active-mode { background: var(--teal-bg); border-color: var(--teal); color: var(--teal-dark); }

.float-keypad {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0,0,0,.15);
  padding: 12px 20px;
  z-index: 50;
  max-width: 95vw;
  text-align: center;
}

.keypad-single-row {
  flex-wrap: nowrap;
  gap: 6px;
}

.float-keypad .keypad-row,
.float-keypad .keypad-single-row {
  gap: 22px;
}

.float-keypad .keypad-sep {
  padding: 0 16px;
}

.keypad-row {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.pd-btn, .mob-btn {
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 10px;
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
}

.keypad-sep {
  color: var(--border);
  font-size: 1.4rem;
  font-weight: 300;
  line-height: 48px;
  padding: 0 2px;
  user-select: none;
}

.btn-bop-float {
  min-width: 56px;
  height: 48px;
  padding: 0 14px;
  border-radius: 20px;
  border: 1px solid #fca5a5;
  background: #fff;
  color: #b91c1c;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.04em;
  flex-shrink: 0;
}

.btn-bop-float.bop-active {
  background: #fecdd3;
  color: #9f1239;
  border-color: #f87171;
}

/* ── iPad横向き固定 ── */
@media (orientation: landscape) and (min-width: 900px) {
  html, body { overflow: hidden; }

  .exam-screen {
    display: flex;
    flex-direction: column;
  }

  .phase-bar { padding: 4px 12px; }

  .exam-workspace {
    flex: 1;
    min-height: 0;
    padding-top: 8px;
  }

  .exam-main {
    min-height: 0;
    overflow: hidden;
  }

  .exam-chart-row {
    flex: 0 0 auto;
    min-height: min-content;
    align-items: flex-start;
    max-height: none;
    overflow: visible;
    position: relative;
    justify-content: center;
    padding-top: 0;
  }

  .exam-chart-row .chart-area {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    overflow: visible;
    padding: 8px 4px 64px;
    margin-top: 0;
    margin-bottom: 0;
  }

  .exam-chart-row .chart-area:has(.perio-detailed) {
    padding: 8px 4px 192px;
    margin-top: 0;
    margin-bottom: 0;
  }

  .exam-chart-row .chart-area .perio-container {
    max-width: none;
    margin-inline: auto;
  }

  .exam-chart-row .exam-side-rail:empty {
    position: absolute;
    right: 0;
    top: 0;
    pointer-events: none;
  }

  .chart-area {
    overflow: visible;
  }

  .exam-main > .exam-input-dock {
    flex: 0 0 auto;
    flex-shrink: 0;
    margin-top: 0;
  }

  .exam-screen.exam-basic.phase-mobility .exam-main > .exam-input-dock {
    margin-top: 64px;
  }

  .exam-screen.exam-basic.phase-mobility .exam-chart-row .chart-area {
    padding-bottom: 128px;
    margin-bottom: -64px;
  }

  .exam-main > .exam-past-section {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }

  .exam-main > .exam-past-scroll {
    flex: 1;
    min-height: 0;
  }

  .exam-workspace {
    margin-bottom: 0;
  }

  .exam-screen.phase-review .exam-main > .exam-chart-row {
    flex: 1 1 auto;
  }

  .exam-screen.phase-review .exam-main > .exam-past-section {
    flex: 0 1 auto;
    max-height: 360px;
  }

  .chart-area .perio-container.perio-basic {
    transform: scale(0.75);
    transform-origin: top center;
    margin-bottom: calc(-500px * 0.25);
  }

  .chart-area .perio-container.perio-basic:has(.mob-slot, .missing-mob-spacer) {
    margin-bottom: calc(-1 * (500px + 60px + 60px) * 0.25);
  }

  .chart-area .perio-container.perio-detailed {
    transform: scale(0.425);
    transform-origin: top center;
    margin-bottom: calc(-700px * 0.575);
  }

  .chart-area .perio-container.perio-detailed:has(.mob-slot, .missing-mob-spacer) {
    margin-bottom: calc(-1 * (700px + 42px + 42px) * 0.575);
  }

  /* 28歯モード・精密検査 — 横幅を32歯精密と同じに（scale × 16/14、比率維持） */
  .chart-area .perio-container.perio-detailed.perio-arch-normal28 {
    transform: scale(calc(0.425 * 16 / 14));
    transform-origin: top center;
    margin-bottom: calc(-700px * (1 - 0.425 * 16 / 14));
  }

  .chart-area .perio-container.perio-detailed.perio-arch-normal28:has(.mob-slot, .missing-mob-spacer) {
    margin-bottom: calc(-1 * (700px + 42px + 42px) * (1 - 0.425 * 16 / 14));
  }

  .exam-screen.arch-normal28.exam-detailed.phase-probing .exam-main > .exam-input-dock {
    margin-top: calc(700px * 0.425 * (16 / 14 - 1));
  }

  .exam-screen.arch-normal28.exam-detailed.phase-review .exam-chart-row .chart-area:has(.perio-detailed) {
    padding-bottom: calc(192px + 700px * 0.425 * (16 / 14 - 1));
    margin-bottom: calc(-700px * 0.425 * (16 / 14 - 1));
  }

  .site-row.detailed-row .site-cell {
    width: 55px;
    max-width: 55px;
  }

  .tooth-col.detailed-col {
    width: 165px;
  }

  .tooth-col:not(.detailed-col) {
    width: 83px;
    max-width: 83px;
  }

  .pd-value {
    font-size: 38px;
    min-height: 42px;
  }

  .chart-area .tooth-col:not(.detailed-col) .pd-value {
    min-height: 32px;
  }

  .mob-slot {
    font-size: 28px;
  }

  .tooth-col:not(.detailed-col) .mob-slot {
    font-size: 17px;
    line-height: 1.2;
    min-height: 27px;
    height: auto;
  }

  .chart-area .chart-grid {
    width: auto;
  }

  .chart-area .chart-grid:has(.detailed-col) {
    width: calc(55px * 3 * 16 + 15px);
    transform: none;
  }

  .chart-area .chart-grid:not(:has(.detailed-col)) {
    width: calc(83px * 16 + 15px);
    transform: none;
  }

  .mini-chart .chart-grid {
    width: calc(83px * 16 + 15px);
    transform: none;
  }

  .mini-chart-detailed {
    transform: scale(0.425);
    width: calc(100% / 0.425);
    margin-bottom: calc(-680px * 0.575);
  }

  .mini-chart-detailed .chart-grid {
    width: calc(55px * 3 * 16 + 15px);
  }

  .exam-chart-row .chart-area .perio-arch-normal28 .chart-grid:has(.detailed-col) {
    width: calc(55px * 3 * 14 + 15px);
  }

  .exam-chart-row .chart-area .perio-arch-normal28 .chart-grid:not(:has(.detailed-col)) {
    width: calc(83px * 14 + 15px);
  }

  .mini-chart.mini-arch-normal28 .chart-grid {
    width: calc(83px * 14 + 15px);
  }

  .mini-chart-detailed.mini-arch-normal28 .chart-grid {
    width: calc(55px * 3 * 14 + 15px);
  }
}

@media (max-width: 768px) {
  .exam-type-grid { grid-template-columns: 1fr; }
  .keypad-single-row { flex-wrap: wrap; }
}
