:root {
  --teal: #0d9488;
  --teal-dark: #0f766e;
  --teal-light: #ccfbf1;
  --bg: #ece7e1;
  --ink: #2b2420;
  --muted: #6b5f57;
  --line: #c9b8ae;
  --pink: #f4c8c4;
  --pink-dark: #e7b0ab;
  --paper: #fffdf8;
  --card: #ffffff;
  --danger: #c24141;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100dvh;
  height: 100vh;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px 8px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  white-space: nowrap;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 0.72rem;
}

.brand-clinic {
  font-weight: 500;
  font-size: 0.82rem;
  color: var(--muted);
  padding-left: 10px;
  margin-left: 4px;
  border-left: 1px solid var(--line);
}

.header-patient {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.header-no {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  font-weight: 700;
}

.header-name {
  font-size: 1.15rem;
  font-weight: 700;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}

.storage-pill {
  font-size: 0.75rem;
  color: var(--muted);
  background: #f3eee8;
  border-radius: 999px;
  padding: 4px 10px;
  white-space: nowrap;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.btn:active { transform: scale(.98); }

.btn-primary {
  background: var(--teal);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.btn-lg { padding: 12px 28px; font-size: 1.05rem; }

.search-main {
  flex: 1;
  display: grid;
  place-items: center;
}

.search-hero {
  width: min(480px, 90vw);
  text-align: center;
}

.search-hero h1 { margin: 0 0 8px; }
.search-hero p { margin: 0 0 20px; color: var(--muted); }

.search-box input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  font-size: 1.2rem;
  margin-bottom: 14px;
  font-family: inherit;
}

.hint { font-size: 0.85rem; color: var(--muted); margin-top: 14px; }
.search-error { color: var(--danger); margin-top: 12px; }
.hidden { display: none !important; }
.empty-msg { padding: 40px; text-align: center; color: var(--muted); }

.chart-split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(210px, 20%) minmax(640px, 1fr);
  gap: 10px;
  padding: 10px;
}

.plan-pane,
.progress-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid #b08986;
  overflow: hidden;
}

.plan-pane {
  background: var(--pink);
}

.progress-pane {
  background: var(--paper);
  min-width: 0;
}

.progress-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

.progress-head h1 {
  margin: 0;
  font-size: 0.92rem;
  letter-spacing: 0.04em;
}

.plan-fixed {
  flex: 0 0 auto;
  padding: 4px 8px 4px;
}

.plan-fixed .field { margin-bottom: 6px; }

.plan-fixed textarea {
  min-height: 2.2rem;
  font-size: 0.76rem;
}

.check-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 2px 6px;
}

.check-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.68rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
}

.check-item input {
  flex: 0 0 auto;
  margin: 0;
}

.srp-plan {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.srp-chart {
  display: grid;
  grid-template-rows: auto auto;
  gap: 0;
  border: 1px solid #c9a8a3;
  border-radius: 6px;
  background: rgba(255,255,255,.55);
  overflow: hidden;
}

.srp-arch {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr)) 2px repeat(8, minmax(0, 1fr));
  gap: 2px;
  padding: 3px 4px;
  position: relative;
}

.srp-arch.is-upper {
  border-bottom: 1px solid #c9a8a3;
  padding-bottom: 4px;
}

.srp-arch.is-lower {
  padding-top: 4px;
}

.srp-arch::before {
  content: '';
  position: absolute;
  top: 2px;
  bottom: 2px;
  left: calc(50% - 1px);
  width: 2px;
  background: #c9a8a3;
  pointer-events: none;
}

.srp-tooth {
  appearance: none;
  border: 0;
  background: transparent;
  width: 100%;
  min-width: 0;
  min-height: 1.35rem;
  padding: 2px 0;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  color: #2b2420;
  text-align: center;
  border-radius: 3px;
  cursor: pointer;
}

.srp-cell {
  position: relative;
  display: block;
  min-width: 0;
  min-height: 1.35rem;
}

.srp-cell.is-gone {
  pointer-events: none;
}

.srp-cell.is-set {
  background: var(--srp-bg);
  border-radius: 3px;
  box-shadow: inset 0 -2px 0 rgba(255,255,255,.35);
}

.srp-tooth.is-picking {
  outline: 2px solid #0d9488;
  outline-offset: 0;
  background: rgba(13, 148, 136, 0.12);
}

.srp-tooth.is-set {
  color: var(--srp-ink);
  cursor: default;
}

.srp-del {
  position: absolute;
  top: -5px;
  right: -4px;
  z-index: 2;
  width: 14px;
  height: 14px;
  padding: 0;
  border: 1px solid #fff;
  border-radius: 50%;
  background: #5c4a42;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.srp-cell:nth-child(8) { grid-column: 8; }
.srp-cell:nth-child(9) { grid-column: 10; }

.srp-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.occ-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.occ-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: nowrap;
}

.occ-group-title {
  flex: 0 0 3.6rem;
  font-size: 0.7rem;
  font-weight: 800;
  color: #8a6a65;
}

.occ-pick {
  position: relative;
  flex: 0 0 1.35rem;
  width: 1.35rem;
  height: 1.35rem;
  border: 1px solid #cfc3b6;
  border-radius: 4px;
  background: #efe6dc;
}

.occ-pick.is-disabled {
  opacity: 0.4;
}

.occ-pick select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 1.55rem;
  font-weight: 700;
}

.occ-pick::after {
  content: '▾';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: #5c4a42;
  font-size: 0.78rem;
  font-weight: 800;
}

.occ-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.occ-chip {
  border: 1px solid #c9a8a3;
  border-radius: 999px;
  padding: 2px 9px 2px 10px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.35;
  background: #fff7f5;
  color: #5c4a42;
  cursor: pointer;
  white-space: nowrap;
}

.occ-chip::after {
  content: ' ×';
  font-weight: 800;
  color: #a67c74;
}

.occ-talk-row {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  flex-wrap: nowrap;
}

.occ-talk-arrow {
  flex: 0 0 auto;
  box-sizing: border-box;
  padding-left: 0.7em;
  margin-right: 2px;
  font-size: 0.78rem;
  font-weight: 800;
  color: #8a6a65;
  line-height: 1;
  text-align: left;
  pointer-events: none;
  user-select: none;
}

.occ-talk-items {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
  flex: 1;
}

.occ-talk {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 0 0 auto;
}

.occ-talk-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #5c4a42;
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
}

.occ-talk-box {
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: 1.5px solid #c9a8a3;
  border-radius: 3px;
  background: rgba(255,255,255,.9);
  font: inherit;
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1;
  color: #111;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.occ-talk-box.is-on {
  border-color: #0f766e;
  background: #ecfdf5;
}

.plan-steps {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid #d7a8a3;
  background: rgba(255,255,255,.18);
}

.plan-steps-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 8px;
  font-size: 0.82rem;
  font-weight: 700;
}

.btn-sm { padding: 4px 8px; font-size: 0.75rem; }

.plan-steps-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: scroll;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
  padding: 0 8px 10px;
}

.plan-steps-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.plan-step {
  display: grid;
  grid-template-columns: 1.4rem 1.4rem 1fr 1.4rem;
  gap: 4px;
  align-items: start;
  background: rgba(255,255,255,.72);
  border: 1px solid #d7a8a3;
  border-radius: 8px;
  padding: 4px;
}

.plan-step.dragging {
  opacity: 0.55;
  box-shadow: 0 4px 12px rgba(0,0,0,.12);
}

.step-handle {
  border: 0;
  background: transparent;
  color: #8a6a65;
  font-size: 0.85rem;
  letter-spacing: -2px;
  cursor: grab;
  touch-action: none;
  padding: 6px 0;
  line-height: 1;
}

.step-mark {
  font-size: 0.95rem;
  font-weight: 700;
  padding-top: 6px;
  text-align: center;
}

.plan-step textarea {
  min-height: 3.2rem;
  font-size: 0.78rem;
  border: 0;
  background: transparent;
  padding: 4px 2px;
}

.step-open {
  min-height: 3.2rem;
  width: 100%;
  border: 0;
  background: transparent;
  padding: 4px 4px;
  font: inherit;
  text-align: left;
  color: #2b2420;
  cursor: pointer;
}

.step-open.is-empty {
  color: #aa8f86;
  font-weight: 600;
}

.step-open-main {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
}

.step-placeholder {
  font-size: 0.82rem;
  font-weight: 600;
  color: #aa8f86;
}

.step-nosite {
  font-size: 0.82rem;
  font-weight: 800;
  color: #5c4a42;
}

.step-tx {
  font-size: 0.92rem;
  font-weight: 800;
  color: #2b2420;
  line-height: 1.2;
}

.step-site-chart {
  display: grid;
  grid-template-rows: auto auto;
  gap: 0;
  width: 100%;
  max-width: 16rem;
  border: 1px solid #d7a8a3;
  border-radius: 4px;
  background: rgba(255,255,255,.65);
  overflow: hidden;
}

.step-site-arch {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr)) 2px repeat(8, minmax(0, 1fr));
  gap: 1px;
  padding: 2px 3px;
  position: relative;
}

.step-site-arch.is-upper {
  border-bottom: 1px solid #d7a8a3;
}

.step-site-arch::before {
  content: '';
  position: absolute;
  top: 1px;
  bottom: 1px;
  left: calc(50% - 1px);
  width: 2px;
  background: #d7a8a3;
  pointer-events: none;
}

.step-site-tooth {
  min-width: 0;
  min-height: 0.95rem;
  display: grid;
  place-items: center;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1;
  color: #c4b0a8;
  border-radius: 2px;
}

.step-site-tooth.is-on {
  color: #854d0e;
  background: rgba(250, 204, 21, 0.7);
  font-weight: 800;
}

.step-site-tooth:nth-child(8) { grid-column: 8; }
.step-site-tooth:nth-child(9) { grid-column: 10; }

.step-remove {
  border: 0;
  background: transparent;
  color: #aa8f86;
  font-size: 1rem;
  cursor: pointer;
}

.plan-step-empty {
  color: var(--muted);
  text-align: center;
  padding: 16px 8px;
  font-size: 0.8rem;
}

.formula-field { margin-bottom: 4px; }

.formula-axis {
  text-align: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: #8a6a65;
  margin-bottom: 2px;
}

.formula-arch.is-upper { margin-bottom: 2px; }
.formula-arch.is-lower { margin-top: 2px; }

.formula-arch-stack {
  position: relative;
  min-width: 0;
  overflow: visible;
}

.formula-beam-layer,
.formula-teeth,
.formula-nums {
  display: grid;
  grid-template-columns: repeat(8, 1fr) 3px repeat(8, 1fr);
  gap: 1px;
}

.formula-teeth-wrap {
  position: relative;
  min-width: 0;
}

.formula-beam-layer {
  min-height: 0;
  align-items: end;
  overflow: visible;
  grid-auto-rows: max-content;
}

.formula-arch.is-lower .formula-beam-layer {
  align-items: start;
}

.formula-teeth {
  overflow: visible;
}

.formula-prostho-inner {
  position: relative;
  z-index: 2;
  min-width: 0;
  min-height: 0;
}

.formula-prostho-inner:has(.formula-denture-block.is-inner) {
  min-height: 28px;
}

.formula-denture-block {
  position: relative;
  min-width: 0;
  z-index: 1;
}

.formula-denture-block.is-outer {
  z-index: 3;
  pointer-events: none;
}

.formula-denture-block.is-outer .br-del {
  pointer-events: auto;
}

.formula-arch.is-upper .formula-denture-block {
  display: flex;
  flex-direction: column;
}

.formula-arch.is-lower .formula-denture-block {
  display: flex;
  flex-direction: column-reverse;
}

.formula-denture-block.is-inner {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 2;
  pointer-events: none;
}

.formula-denture-block.is-inner .br-del {
  pointer-events: auto;
}

.formula-arch.is-upper .formula-denture-block.is-inner {
  justify-content: flex-end;
}

.formula-arch.is-lower .formula-denture-block.is-inner {
  flex-direction: column-reverse;
  justify-content: flex-start;
}

.formula-beam-layer.is-denture-caps {
  align-items: center;
  pointer-events: none;
}

.formula-beam-layer.is-denture-caps .br-del {
  pointer-events: auto;
}

.den-layer {
  display: grid;
  grid-template-columns: repeat(8, 1fr) 3px repeat(8, 1fr);
  gap: 1px;
  pointer-events: none;
  height: 14px;
}

.formula-denture-block.is-inner .den-layer {
  height: 12px;
}

/* 2段目: 縦線を歯マス外側まで伸ばす（Br段をまたいでマス縁に着地） */
.formula-arch.is-upper .formula-denture-block.is-outer .den-layer {
  height: 43px;
  margin-bottom: -29px;
}

.formula-arch.is-lower .formula-denture-block.is-outer .den-layer {
  height: 43px;
  margin-top: -29px;
}

.den-cell {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.formula-arch.is-lower .den-cell {
  flex-direction: column-reverse;
}

.den-h {
  height: 2px;
  background: #c24141;
  flex-shrink: 0;
  margin-left: -1px;
  margin-right: -1px;
}

.den-cell.is-start .den-h {
  margin-left: 50%;
}

.den-cell.is-end .den-h {
  margin-right: 50%;
}

.den-cell.is-start.is-end .den-h {
  margin-left: 50%;
  margin-right: 50%;
}

.den-v {
  width: 2px;
  align-self: center;
  flex: 1 1 auto;
  min-height: 0;
  background: #c24141;
  margin-top: -2px;
}

.formula-arch.is-lower .den-v {
  margin-top: 0;
  margin-bottom: -2px;
}

.den-cell.is-draft .den-h {
  background: repeating-linear-gradient(to right, #c24141 0 4px, transparent 4px 7px);
}

.den-cell.is-draft .den-v {
  background: repeating-linear-gradient(to bottom, #c24141 0 4px, transparent 4px 7px);
}

.br-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}

.formula-arch.is-lower .br-group {
  flex-direction: column-reverse;
}

.br-caption {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.62rem;
  font-weight: 800;
  color: #2563eb;
  line-height: 1;
  margin: 1px 0;
  pointer-events: auto;
  white-space: nowrap;
}

.br-beam {
  width: 100%;
  height: 9px;
  border: 2px solid #2563eb;
  background: transparent;
  padding: 0;
  pointer-events: none;
}

.formula-arch.is-upper .br-beam {
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
}

.formula-arch.is-lower .br-beam {
  border-top: 0;
  border-radius: 0 0 6px 6px;
}

.br-group.is-draft .br-beam {
  border-style: dashed;
}

.br-del {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 1px solid #fff;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}

.br-group.is-denture .br-caption { color: #c24141; }
.br-group.is-denture .br-del { background: #c24141; }

.formula-row {
  display: grid;
  grid-template-columns: 1rem 1fr;
  gap: 2px;
  align-items: start;
}

.formula-arch.is-upper .formula-row {
  align-items: end;
}

.formula-jaw {
  font-size: 0.66rem;
  font-weight: 700;
}

.formula-tooth {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
  position: relative;
  z-index: 1;
}

.formula-face {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-weight: 800;
  line-height: 1.05;
  color: #000;
}

.formula-tooth.is-horizontal .formula-face {
  writing-mode: horizontal-tb;
  font-size: 0.78rem;
  letter-spacing: 0;
}

.formula-tooth.is-vertical .formula-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  writing-mode: horizontal-tb;
  font-size: 0.72rem;
  letter-spacing: 0;
}

.formula-tooth.is-vertical .formula-face .fv {
  display: block;
  line-height: 1.05;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
}

.formula-tooth.is-missing .formula-face {
  color: #111;
}

.formula-tooth.formula-mid { margin-left: 0; }

.formula-tooth:nth-child(9) {
  grid-column: 10;
}

.formula-num {
  display: block;
  text-align: center;
  font-size: 0.55rem;
  color: #8a6a65;
  line-height: 1.1;
  padding: 1px 0 0;
}

.formula-arch.is-lower .formula-num {
  padding: 0 0 1px;
}

.formula-num.formula-mid,
.formula-num:nth-child(9) {
  grid-column: 10;
}

.formula-tooth select,
.formula-tooth input {
  width: 100%;
  min-width: 0;
  border: 1px solid #c9a8a3;
  border-radius: 4px;
  padding: 6px 0;
  min-height: 2.4rem;
  font-size: 1.56rem;
  line-height: 1.15;
  font-weight: 700;
  text-align: center;
  color: transparent;
  background: rgba(255,255,255,.8);
  appearance: none;
  position: relative;
  z-index: 2;
  caret-color: transparent;
}

.formula-tooth select option {
  font-size: 1.56rem;
  font-weight: 700;
  color: #111;
  background: #fff;
}

.formula-tooth.is-missing select {
  background: #d4d4d4;
  color: transparent;
  border-color: #b0b0b0;
}

.formula-tooth.is-pontic select {
  background: repeating-linear-gradient(-45deg, #93c5fd 0 3px, #dbeafe 3px 7px);
  border-color: #2563eb;
}

.formula-tooth.is-denture select {
  background: repeating-linear-gradient(-45deg, #f4b4ae 0 3px, #fde8e6 3px 7px);
  border-color: #c24141;
}

.formula-tooth.is-missing.is-pontic select {
  background:
    repeating-linear-gradient(-45deg, #60a5fa 0 3px, transparent 3px 7px),
    #d4d4d4;
  border-color: #2563eb;
  box-shadow: inset 0 0 0 2px #2563eb;
}

.formula-tooth.is-missing.is-denture select {
  background:
    repeating-linear-gradient(-45deg, #f4b4ae 0 3px, transparent 3px 7px),
    #d4d4d4;
  border-color: #c24141;
  box-shadow: inset 0 0 0 2px #c24141;
}

.formula-tooth.is-abutment select {
  box-shadow: inset 0 0 0 2px #2563eb;
}

.formula-tooth.is-picking {
  outline: 2px solid #0d9488;
  outline-offset: 0;
  border-radius: 4px;
}

.formula-tooth.is-br-used {
  opacity: 0.45;
  pointer-events: none;
}

.formula.is-editing .formula-tooth select {
  pointer-events: none;
  caret-color: transparent;
}

.formula.is-editing .formula-tooth {
  cursor: pointer;
}

.formula-tools {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}

.formula-tools .btn {
  flex: 0 0 auto;
  width: auto;
}

.formula-hint {
  margin: 4px 0 0;
  font-size: 0.68rem;
  font-weight: 600;
  color: #8a6a65;
}

.formula-hint.is-alert {
  color: #c24141;
}

.plan-scroll {
  display: none;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.field textarea,
.field input,
.plan-date input,
.foot-field input,
.staff-note,
.site-note,
.progress-table input[type="date"],
.progress-table textarea {
  width: 100%;
  border: 1px solid #d7a8a3;
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
  font-weight: 500;
  background: rgba(255,255,255,.72);
  resize: none;
}

.progress-table textarea,
.progress-table input[type="date"],
.staff-note {
  border-color: #ddd2c6;
  background: #fff;
}

.site-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.site-cell { display: flex; flex-direction: column; gap: 4px; }

.quad {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  aspect-ratio: 1;
  border: 1.5px solid #5c403c;
  background: rgba(255,255,255,.55);
}

.quad::before,
.quad::after {
  content: "";
  position: absolute;
  background: #5c403c;
  pointer-events: none;
}

.quad::before {
  left: 50%;
  top: 8%;
  bottom: 8%;
  width: 1.5px;
  transform: translateX(-50%);
}

.quad::after {
  top: 50%;
  left: 8%;
  right: 8%;
  height: 1.5px;
  transform: translateY(-50%);
}

.quad .q {
  border: 0;
  background: transparent;
  text-align: center;
  font-size: 0.78rem;
  padding: 0 4px;
  z-index: 1;
}

.site-note { font-size: 0.7rem; padding: 3px 5px; }

.arch-sketch {
  margin-top: 8px;
  padding: 6px 4px;
  border-top: 1px dashed #d7a8a3;
}

.arch-row {
  display: flex;
  justify-content: center;
  gap: 2px;
}

.arch-row.lower { margin-top: 4px; transform: scaleY(-1); }

.tooth {
  width: 16px;
  height: 18px;
  border: 1px solid #8a6a65;
  border-radius: 7px 7px 3px 3px;
  font-size: 0.58rem;
  display: grid;
  place-items: center;
  color: #8a6a65;
}

.progress-frame {
  flex: 1;
  min-height: 0;
  min-width: 0;
  margin: 0 10px;
  border: 1px solid #4a3f39;
  background: #fff;
  overflow-y: scroll;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  touch-action: pan-y;
}

.progress-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.progress-table th,
.progress-table td {
  border: 1px solid #cfc3b6;
  vertical-align: top;
  padding: 4px;
}

.progress-table thead th {
  background: #f3ebe3;
  font-size: 0.88rem;
  line-height: 1.2;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 1px 0 #4a3f39;
}

.progress-table thead th {
  border-bottom: 1px solid #4a3f39;
}

.col-date { width: 9.2rem; }
.col-tx { width: calc(22% + 4.4rem); }
.col-flag { width: 8rem; text-align: center; }
.col-staff { width: 9rem; }
.col-next { width: 15%; }
.col-remarks { width: auto; }

.progress-table tbody td {
  height: 12rem;
  min-height: 12rem;
}

.col-date {
  position: relative;
  padding: 4px 6px 6px !important;
}

.date-display {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 3.2rem;
  padding: 1px 2px 0;
}

.date-year {
  display: block;
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0.04em;
}

.date-md {
  display: block;
  font-size: 1.55rem;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}

.date-display.is-empty .date-md {
  font-size: 0.95rem;
  font-weight: 700;
  color: #9a7b74;
}

.date-display.is-same-day .date-year,
.date-display.is-same-day .date-md,
.date-same-day {
  color: #0f766e;
}

.date-same-day {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
}

.row-delete,
.date-edit,
.row-first {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  margin-top: 3px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 5px 4px;
  cursor: pointer;
  position: relative;
  z-index: 1;
  font-family: inherit;
  box-sizing: border-box;
}

.row-delete {
  border: 1px solid #d7bfb6;
  background: #fff8f6;
  color: #8a4f46;
}

.date-edit {
  padding: 0;
  border: 0;
  background: transparent;
  display: block;
  touch-action: manipulation;
}

.date-edit input[type="date"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  opacity: 0;
  pointer-events: none;
}

.date-edit-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 100%;
  margin: 0;
  border: 1px solid #cfc3b6;
  border-radius: 6px;
  background: #f7f1ea;
  color: #5c4a42;
  font-size: 0.78rem;
  font-weight: 700;
  font-family: inherit;
  padding: 5px 4px;
  cursor: pointer;
  touch-action: manipulation;
}

.row-first {
  border: 1px solid #e8b4b0;
  background: #fff5f4;
  color: #b42318;
}

.row-first.is-on {
  background: #c24141;
  border-color: #c24141;
  color: #fff;
}

.date-edit-cal {
  width: 1.15rem;
  height: 1.15rem;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  pointer-events: none;
}

.col-staff {
  padding: 0 !important;
  vertical-align: stretch;
}

.staff-stack {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 11.2rem;
}

.staff-slot {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.staff-slot + .staff-slot {
  border-top: 1px solid #cfc3b6;
}

.staff-role {
  position: absolute;
  top: 3px;
  left: 6px;
  z-index: 1;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--muted);
  line-height: 1;
  pointer-events: none;
}

.staff-combo {
  display: grid;
  grid-template-columns: 1fr 2.9rem;
  flex: 1;
  min-height: 0;
  height: 100%;
}

.staff-combo input {
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  padding: 1.1rem 2px 4px;
  font-size: 1.55rem;
  font-weight: 800;
  font-family: inherit;
  text-align: center;
}

.staff-pick {
  position: relative;
  background: #efe6dc;
  border-left: 1px solid #cfc3b6;
}

.staff-pick select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 1.6rem;
}

.staff-pick::after {
  content: "▾";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  color: #5c4a42;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1;
}

.staff-note { margin-top: 8px; font-size: 0.75rem; }

.progress-table textarea {
  min-height: 11.2rem;
  height: 100%;
  font-size: 1rem;
  line-height: 1.4;
}

.col-flag input[type="checkbox"] {
  width: 1.35rem;
  height: 1.35rem;
}

.med-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 100%;
  padding-top: 4px;
}

.med-check {
  display: grid;
  place-items: center;
  cursor: pointer;
}

.med-summary {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.25;
  color: #0f766e;
}

.med-summary-line {
  display: block;
  white-space: nowrap;
}

.med-picker {
  position: fixed;
  z-index: 80;
  width: 15.5rem;
  padding: 8px;
  border: 1px solid #cfc3b6;
  border-radius: 10px;
  background: #fffdf9;
  box-shadow: 0 10px 28px rgba(60, 40, 30, 0.18);
  text-align: left;
}

.med-picker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 14rem;
  overflow-y: auto;
}

.med-option {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 5px 4px;
  border-radius: 6px;
}

.med-option-main {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  cursor: pointer;
}

.med-option.is-on {
  background: #e7f6f3;
}

.med-option input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
}

.med-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: #4a3f39;
}

.med-qty {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.med-qty button {
  width: 1.35rem;
  height: 1.35rem;
  border: 1px solid #cfc3b6;
  border-radius: 4px;
  background: #fff;
  font-size: 0.85rem;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

.med-qty button:disabled {
  opacity: 0.35;
  cursor: default;
}

.med-qty input[type="number"] {
  width: 2.2rem;
  height: 1.35rem;
  border: 1px solid #cfc3b6;
  border-radius: 4px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0;
  -moz-appearance: textfield;
}

.med-qty input[type="number"]::-webkit-outer-spin-button,
.med-qty input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.med-unit {
  min-width: 1.1rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: #8a6a65;
}

.med-picker-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #eadfd6;
}

.empty-row td {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
}

.progress-table tbody tr.year-rule td,
.progress-table tbody tr.first-rule td {
  height: 6px;
  min-height: 6px;
  padding: 0;
  border: 0;
}

.progress-table tbody tr.year-rule td {
  background: #0d9488;
}

.progress-table tbody tr.first-rule td {
  background: #c24141;
}

.progress-foot {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4.8rem;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  font-size: 0.9rem;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.spt-group,
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.foot-field {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.foot-field input { width: 4.8rem; }

.formula-tooth.is-tx-pick {
  appearance: none;
  border: 1px solid #c9a8a3;
  border-radius: 4px;
  padding: 6px 0;
  min-height: 2.4rem;
  width: 100%;
  background: rgba(255,255,255,.8);
  position: relative;
  cursor: pointer;
}

.formula-tooth.is-tx-pick.is-missing {
  background: #d4d4d4;
  border-color: #b0b0b0;
}

.formula-tooth.is-tx-pick.is-pontic {
  background: repeating-linear-gradient(-45deg, #93c5fd 0 3px, #dbeafe 3px 7px);
  border-color: #2563eb;
}

.formula-tooth.is-tx-pick.is-denture {
  background: repeating-linear-gradient(-45deg, #f4b4ae 0 3px, #fde8e6 3px 7px);
  border-color: #c24141;
}

.formula-tooth.is-tx-pick.is-missing.is-pontic {
  background:
    repeating-linear-gradient(-45deg, #60a5fa 0 3px, transparent 3px 7px),
    #d4d4d4;
}

.formula-tooth.is-tx-pick.is-missing.is-denture {
  background:
    repeating-linear-gradient(-45deg, #f4b4ae 0 3px, transparent 3px 7px),
    #d4d4d4;
}

.formula.is-tx-pick .formula-tooth.is-picking {
  outline: 2px solid #0d9488;
  outline-offset: 0;
}

#tx-picker-root:empty { display: none; }

.tx-picker {
  position: fixed;
  inset: 2.5vh 2.5vw;
  z-index: 120;
  display: flex;
  flex-direction: column;
  background: #fffaf6;
  border: 1px solid #c9a8a3;
  border-radius: 12px;
  box-shadow: 0 18px 48px rgba(40, 24, 16, 0.28);
  overflow: hidden;
}

.tx-picker-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #e2cfc8;
  background: #fff;
}

.tx-picker-head strong {
  font-size: 1.05rem;
}

.tx-picker-body.is-teeth {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 11.5rem;
  gap: 12px;
  padding: 12px;
  overflow: auto;
}

.tx-formula-wrap {
  min-width: 0;
  overflow: auto;
  padding: 6px;
  border: 1px solid #e2cfc8;
  border-radius: 8px;
  background: rgba(255,255,255,.7);
}

.tx-formula-wrap .formula {
  transform: scale(1.08);
  transform-origin: top left;
  width: 92%;
}

.tx-site-side {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.tx-nosite {
  width: 100%;
  font-weight: 800;
}

.tx-blocks,
.tx-jaws {
  display: grid;
  gap: 6px;
}

.tx-blocks {
  grid-template-columns: 1fr;
}

.tx-jaws {
  grid-template-columns: 1fr 1fr;
}

.tx-block {
  border: 1px solid #c9a8a3;
  border-radius: 8px;
  padding: 10px 8px;
  font: inherit;
  font-size: 0.92rem;
  font-weight: 800;
  background: #fff;
  color: #2b2420;
  cursor: pointer;
}

.tx-picker-body.is-tx {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.tx-picker-body.is-tx.is-all {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 12px 14px 18px;
}

.tx-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tx-section-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 800;
  color: #8a6a65;
  padding-bottom: 2px;
  border-bottom: 1px solid #e2cfc8;
}

.tx-items {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 8px;
  align-content: start;
}

.tx-item {
  border: 1px solid #c9a8a3;
  border-radius: 12px;
  padding: 14px 10px;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 800;
  background: #fff;
  cursor: pointer;
  min-height: 3.6rem;
}

@media (max-width: 900px) {
  .chart-split {
    grid-template-columns: 1fr;
  }
}
