/* ========================================
   術前診察アプリ - PreOp Assessment Tool v3.0
   ======================================== */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
/* style.css loads after tailwind.css: keep utility .hidden authoritative over component display rules */
.hidden { display: none !important; }
body { font-feature-settings: "palt"; }

/* ---------- Header buttons ---------- */
.hdr-btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.4rem 0.7rem; border-radius: 0.5rem; font-size: 0.8rem;
  background: rgba(255,255,255,0.1); color: #fff; transition: background .15s;
}
.hdr-btn:hover { background: rgba(255,255,255,0.2); }
.hdr-btn-primary { background: #10b981; font-weight: 700; }
.hdr-btn-primary:hover { background: #059669; }
.hdr-btn:disabled { opacity: .6; }

/* ---------- Status bar ---------- */
.status-pill {
  display: inline-flex; align-items: center; gap: 0.35rem;
  padding: 0.25rem 0.65rem; border-radius: 9999px;
  font-size: 0.7rem; font-weight: 700; white-space: nowrap; transition: all .2s;
}
.section-nav {
  display: flex; gap: 0.35rem; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px;
}
.section-nav::-webkit-scrollbar { display: none; }
.nav-item {
  display: inline-flex; align-items: center; gap: 0.35rem; flex-shrink: 0;
  padding: 0.25rem 0.6rem; border-radius: 9999px; border: 1px solid #e5e7eb;
  background: #fff; color: #6b7280; font-size: 0.68rem; font-weight: 600; transition: all .15s;
}
.nav-item:hover { border-color: #7dd3fc; color: #0369a1; background: #f0f9ff; }
.nav-item i { font-size: 0.65rem; opacity: .7; }
.nav-dot { width: 7px; height: 7px; border-radius: 50%; background: #d1d5db; flex-shrink: 0; }
.nav-done .nav-dot { background: #22c55e; }
.nav-partial .nav-dot { background: #f59e0b; }
.nav-empty .nav-dot { background: #d1d5db; }
.nav-optional .nav-dot { background: #e5e7eb; }
.nav-risk-high { border-color: #fca5a5; color: #b91c1c; background: #fef2f2; }
.nav-risk-high .nav-dot { background: #ef4444; box-shadow: 0 0 0 2px #fecaca; }
.nav-risk-medium { border-color: #fcd34d; color: #92400e; background: #fffbeb; }
.nav-risk-medium .nav-dot { background: #f59e0b; }

/* ---------- Cards ---------- */
.card {
  background: #fff; border-radius: 1rem; overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  transition: box-shadow .2s;
}
.card:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); }
.card-header {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.8rem 1.15rem; font-size: 0.92rem; font-weight: 700; color: #0c4a6e;
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe); border-bottom: 1px solid #e0f2fe;
}
.card-header > i:first-child { color: #0284c7; }
.card-status { margin-left: auto; display: inline-flex; align-items: center; gap: .3rem; font-size: .65rem; font-weight: 600; }
.card-chevron { display: none; font-size: .7rem; color: #94a3b8; transition: transform .2s; margin-left: .5rem; }
.card-body { padding: 1.15rem; }
.subhead { font-size: .8rem; font-weight: 700; color: #374151; margin-bottom: .6rem; display: flex; align-items: center; gap: .4rem; }

/* ---------- Form ---------- */
.label { display: block; font-size: .76rem; font-weight: 600; color: #4b5563; margin-bottom: .3rem; line-height: 1.3; }
.ref-range { font-weight: 400; color: #9ca3af; font-size: .66rem; }
.unit { font-weight: 400; color: #9ca3af; font-size: .66rem; }
.input {
  display: block; width: 100%; padding: .5rem .7rem; border: 1.5px solid #d1d5db; border-radius: .5rem;
  font-size: .875rem; color: #1f2937; background: #fff; outline: none; transition: border-color .2s, box-shadow .2s, background .2s;
}
.input:focus { border-color: #0ea5e9; box-shadow: 0 0 0 3px rgba(14,165,233,.15); }
.input::placeholder { color: #c0c4cc; }
.input:read-only { background: #f9fafb; color: #6b7280; }
.input.risk-high { border-color: #ef4444 !important; background: #fef2f2 !important; color: #991b1b; font-weight: 700; }
.input.risk-medium { border-color: #f59e0b !important; background: #fffbeb !important; color: #92400e; font-weight: 600; }
.input.inf-neg { border-color: #86efac; background: #f0fdf4; }
input[type=number]::-webkit-inner-spin-button { opacity: .4; }

.checkbox-card, .radio-card {
  display: flex; align-items: center; gap: .5rem; padding: .45rem .7rem; background: #f9fafb;
  border: 1.5px solid #e5e7eb; border-radius: .5rem; cursor: pointer; font-size: .78rem; color: #4b5563;
  transition: all .15s; user-select: none;
}
.checkbox-card:hover, .radio-card:hover { border-color: #93c5fd; background: #eff6ff; }
.checkbox-card:has(input:checked), .radio-card:has(input:checked) { border-color: #0ea5e9; background: #e0f2fe; color: #0369a1; font-weight: 600; }
.checkbox-card input, .radio-card input { accent-color: #0ea5e9; }

/* segmented radio */
.seg { display: inline-flex; border: 1.5px solid #d1d5db; border-radius: .5rem; overflow: hidden; background: #fff; }
.seg-item { position: relative; cursor: pointer; }
.seg-item input { position: absolute; opacity: 0; inset: 0; }
.seg-item span { display: block; padding: .4rem .8rem; font-size: .76rem; color: #4b5563; border-right: 1.5px solid #e5e7eb; transition: all .15s; }
.seg-item:last-child span { border-right: none; }
.seg-item:hover span { background: #f0f9ff; }
.seg-item:has(input:checked) span { background: #0284c7; color: #fff; font-weight: 700; }
.seg-item:has(input[value="abnormal"]:checked) span, .seg-item:has(input[value="yes"]:checked) span { background: #dc2626; }
.seg-item:has(input[value="not_done"]:checked) span { background: #6b7280; }

.toggle-chip { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; font-size: .7rem; color: #6b7280; padding: .25rem .6rem; border-radius: 9999px; border: 1px solid #e5e7eb; background: #fff; user-select: none; }
.toggle-chip:has(input:checked) { background: #e0f2fe; border-color: #0ea5e9; color: #0369a1; font-weight: 600; }
.toggle-chip input { accent-color: #0ea5e9; }

/* ---------- Lab items ---------- */
.lab-group { padding-top: .25rem; }
.lab-item { position: relative; border-radius: .6rem; padding: .35rem; margin: -.35rem; transition: background .2s; }
.lab-item.lab-attention { background: #fffbeb; outline: 1.5px dashed #fbbf24; }
.lab-input-row { display: flex; align-items: center; gap: .4rem; }
.lab-input-row .input { flex: 1; min-width: 0; }
.lab-flag { width: 1.2rem; text-align: center; font-size: .8rem; font-weight: 800; flex-shrink: 0; }
.flag-red { color: #dc2626; }
.flag-amber { color: #d97706; }
.flag-green { color: #16a34a; font-size: .7rem; }
.lab-attn-chip { display: inline-block; font-size: .6rem; font-weight: 700; color: #b45309; background: #fef3c7; border: 1px solid #fcd34d; border-radius: 9999px; padding: 0 .4rem; line-height: 1.3; }

/* ---------- Choice cards (NYHA / HJ / Mallampati) ---------- */
.choice-grid { display: grid; gap: .6rem; grid-template-columns: repeat(2, minmax(0,1fr)); }
@media (min-width: 768px) { .choice-grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); } .choice-grid.cols-5 { grid-template-columns: repeat(5, minmax(0,1fr)); } }
.choice-card {
  display: flex; flex-direction: column; gap: .3rem; padding: .6rem .7rem; border: 2px solid #e5e7eb; border-radius: .75rem;
  background: #fafafa; cursor: pointer; transition: all .15s; user-select: none;
}
.choice-card:hover { border-color: #7dd3fc; background: #f0f9ff; transform: translateY(-1px); }
.choice-card.selected { border-color: #0ea5e9; background: #e0f2fe; box-shadow: 0 0 0 3px rgba(14,165,233,.18); }
.choice-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 1.6rem; height: 1.6rem; padding: 0 .4rem; border-radius: 9999px; font-size: .75rem; font-weight: 800; }
.choice-desc { font-size: .66rem; color: #6b7280; line-height: 1.4; }
.mallampati-card { align-items: stretch; text-align: left; }
.mp-svg { width: 100%; height: auto; max-height: 72px; border-radius: .4rem; background: #fff; border: 1px solid #f3f4f6; }

/* ---------- ASA buttons ---------- */
.asa-override-btn { flex: 1; padding: .3rem 0; font-size: .75rem; font-weight: 800; border-radius: .4rem; border: 1px solid #c7d2fe; background: #fff; color: #4338ca; transition: all .15s; }
.asa-override-btn:hover { background: #eef2ff; }
.asa-override-btn.active { background: #4f46e5; color: #fff; border-color: #4f46e5; }
.asa-auto-btn { flex: 1; padding: .3rem 0; font-size: .65rem; font-weight: 600; border-radius: .4rem; border: 1px solid #e5e7eb; background: #fff; color: #6b7280; }
.asa-auto-btn:hover { background: #f3f4f6; }

/* ---------- Gauge ---------- */
.gauge-wrap { width: 118px; flex-shrink: 0; }
.gauge-svg { width: 100%; height: auto; display: block; }
.gauge-svg #gauge-fill { transition: stroke-dashoffset .5s ease, stroke .3s; }
.gauge-svg #gauge-needle { transition: transform .5s ease; }
.gauge-text { font-size: 15px; font-weight: 800; fill: #0f172a; }

/* ---------- Risk indicator ---------- */
.risk-indicator { display: inline-flex; width: .9rem; height: .9rem; border-radius: 50%; flex-shrink: 0; transition: all .3s; background: #e5e7eb; }
.risk-indicator.risk-green { background: #22c55e; box-shadow: 0 0 5px rgba(34,197,94,.5); }
.risk-indicator.risk-yellow { background: #f59e0b; box-shadow: 0 0 5px rgba(245,158,11,.5); }
.risk-indicator.risk-red { background: #ef4444; box-shadow: 0 0 8px rgba(239,68,68,.5); animation: pulse-red 2s infinite; }
.risk-indicator.risk-gray { background: #9ca3af; }
@keyframes pulse-red { 0%,100% { box-shadow: 0 0 5px rgba(239,68,68,.4); } 50% { box-shadow: 0 0 13px rgba(239,68,68,.75); } }

.risk-item { display: flex; align-items: center; gap: .5rem; padding: .45rem .6rem; border-radius: .5rem; font-size: .72rem; cursor: pointer; transition: filter .15s; }
.risk-item:hover { filter: brightness(.97); }
.risk-item-high { background: #fef2f2; color: #991b1b; border-left: 3px solid #ef4444; }
.risk-item-medium { background: #fffbeb; color: #92400e; border-left: 3px solid #f59e0b; }
.risk-item .risk-indicator { width: .6rem; height: .6rem; animation: none; }

.risk-chip { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .5rem; border-radius: 9999px; font-size: .63rem; font-weight: 600; white-space: nowrap; cursor: pointer; }
.risk-chip-high { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.risk-chip-medium { background: #fffbeb; color: #d97706; border: 1px solid #fde68a; }

/* ---------- Consent ---------- */
.consent-check { display: flex; align-items: center; gap: .75rem; padding: .7rem .9rem; background: #f9fafb; border: 2px solid #e5e7eb; border-radius: .75rem; cursor: pointer; transition: all .2s; }
.consent-check:has(input:checked) { background: #f0fdf4; border-color: #22c55e; }
.consent-check:has(input:not(:checked)) { background: #fef2f2; border-color: #fca5a5; }
.consent-check input { width: 1.25rem; height: 1.25rem; accent-color: #22c55e; }

/* ---------- Buttons ---------- */
.btn-secondary { display: inline-flex; align-items: center; padding: .45rem .9rem; background: #f3f4f6; border: 1.5px solid #d1d5db; border-radius: .5rem; font-size: .78rem; color: #4b5563; cursor: pointer; transition: all .15s; }
.btn-secondary:hover { background: #e5e7eb; border-color: #9ca3af; }
.btn-danger { display: inline-flex; align-items: center; padding: .3rem .55rem; background: #fef2f2; border: 1px solid #fca5a5; border-radius: .375rem; font-size: .72rem; color: #dc2626; cursor: pointer; }
.btn-danger:hover { background: #fee2e2; }
.sort-btn { padding: .15rem .5rem; border-radius: 9999px; border: 1px solid #e5e7eb; background: #fff; color: #6b7280; }
.sort-btn.active { background: #0284c7; border-color: #0284c7; color: #fff; font-weight: 700; }
.lst-badge { display: inline-flex; align-items: center; font-size: .62rem; font-weight: 700; padding: .1rem .4rem; border-radius: .3rem; }

/* ---------- Tooth chart ---------- */
.tooth-chart-container { display: flex; flex-direction: column; align-items: center; gap: .5rem; padding: .9rem .5rem; background: #fff; border-radius: .75rem; border: 1px solid #e5e7eb; overflow-x: auto; }
.tooth-row { display: flex; gap: .2rem; align-items: flex-end; }
.tooth-row-label { font-size: .62rem; font-weight: 600; color: #6b7280; width: 2.4rem; text-align: right; padding-right: .4rem; align-self: center; }
.tooth { display: flex; align-items: center; justify-content: center; border: 1.5px solid #cbd5e1; font-size: .58rem; color: #64748b; cursor: pointer; transition: all .15s; user-select: none; background: #fff; }
.tooth-molar { width: 1.75rem; height: 1.75rem; border-radius: .35rem; }
.tooth-premolar { width: 1.55rem; height: 1.7rem; border-radius: .45rem; }
.tooth-canine { width: 1.4rem; height: 1.85rem; border-radius: .7rem .7rem .35rem .35rem; }
.tooth-incisor { width: 1.3rem; height: 1.7rem; border-radius: .3rem .3rem .5rem .5rem; }
.tooth-row:last-child .tooth-canine { border-radius: .35rem .35rem .7rem .7rem; }
.tooth-row:last-child .tooth-incisor { border-radius: .5rem .5rem .3rem .3rem; }
.tooth:hover { border-color: #60a5fa; background: #eff6ff; }
.tooth.selected { background: #ef4444; border-color: #dc2626; color: #fff; font-weight: 700; box-shadow: 0 0 6px rgba(239,68,68,.4); }
.tooth-divider { width: 1px; height: 1.75rem; background: #9ca3af; margin: 0 .3rem; align-self: center; }
.jaw-divider { width: 80%; height: 2px; background: linear-gradient(to right, transparent, #9ca3af, transparent); }

/* ---------- Allergy ---------- */
.allergy-entry { padding: .9rem; background: #f9fafb; border: 1.5px solid #e5e7eb; border-radius: .75rem; }
.allergy-entry.severity-severe { border-color: #fca5a5; background: #fef2f2; }
.allergy-entry.severity-moderate { border-color: #fde68a; background: #fffbeb; }

/* ---------- Medications ---------- */
.med-tag { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; border-radius: 9999px; font-size: .7rem; font-weight: 600; border: 1px solid; }
.med-tag-cat { font-size: .58rem; font-weight: 500; opacity: .8; padding-left: .3rem; border-left: 1px solid currentColor; }
.med-tag-gray { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }
.med-tag-red { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.med-tag-amber { background: #fffbeb; color: #b45309; border-color: #fde68a; }
.med-tag-blue { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.med-tag-purple { background: #faf5ff; color: #7e22ce; border-color: #e9d5ff; }
.med-tag-teal { background: #f0fdfa; color: #0f766e; border-color: #99f6e4; }
.med-tag-pink { background: #fdf2f8; color: #be185d; border-color: #fbcfe8; }
.med-tag-cyan { background: #ecfeff; color: #0e7490; border-color: #a5f3fc; }
.med-group { border-radius: .6rem; padding: .6rem .75rem; margin-bottom: .5rem; border: 1px solid; }
.med-group-title { font-size: .72rem; font-weight: 700; display: flex; align-items: center; gap: .4rem; margin-bottom: .35rem; }
.med-group-item { font-size: .72rem; padding: .25rem 0; border-top: 1px dashed rgba(0,0,0,.08); }
.med-hold { font-size: .68rem; color: #374151; margin-top: .1rem; }
.med-group-red { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.med-group-amber { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.med-group-blue { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.med-group-purple { background: #faf5ff; border-color: #e9d5ff; color: #6b21a8; }
.med-group-teal { background: #f0fdfa; border-color: #99f6e4; color: #115e59; }
.med-group-pink { background: #fdf2f8; border-color: #fbcfe8; color: #9d174d; }
.med-group-cyan { background: #ecfeff; border-color: #a5f3fc; color: #155e75; }
.med-group-gray { background: #f9fafb; border-color: #e5e7eb; color: #374151; }

/* ---------- Overall risk ---------- */
.risk-display-high { background: linear-gradient(135deg, #fef2f2, #fee2e2) !important; }
.risk-display-medium { background: linear-gradient(135deg, #fffbeb, #fef3c7) !important; }
.risk-display-low { background: linear-gradient(135deg, #f0fdf4, #dcfce7) !important; }
.section-risk-high { box-shadow: 0 0 0 2px #ef4444, 0 4px 12px rgba(239,68,68,.12) !important; }
.section-risk-medium { box-shadow: 0 0 0 2px #f59e0b, 0 4px 12px rgba(245,158,11,.12) !important; }
.combo-warning { display: flex; align-items: flex-start; gap: .5rem; padding: .6rem; background: #fff7ed; border: 1px solid #fed7aa; border-radius: .5rem; font-size: .72rem; color: #9a3412; }

/* ---------- Mobile accordion ---------- */
@media (max-width: 767px) {
  .card-header { cursor: pointer; }
  .card-chevron { display: inline-block; }
  .card.collapsed .card-body { display: none; }
  .card.collapsed .card-chevron { transform: rotate(-90deg); }
  .card-body { padding: .9rem; }
  .tooth-molar { width: 1.5rem; height: 1.5rem; } .tooth-premolar { width: 1.35rem; height: 1.5rem; } .tooth-canine { width: 1.25rem; height: 1.6rem; } .tooth-incisor { width: 1.15rem; height: 1.5rem; }
  .tooth { font-size: .52rem; }
  .status-pill { font-size: .62rem; padding: .2rem .5rem; }
  #risk-summary-chips { display: none; }
  header p { display: none; }
  .section-nav { margin-top: .35rem; }
}

/* ---------- Scrollbar / animation ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; border-radius: 3px; }
::-webkit-scrollbar-thumb { background: #94a3b8; border-radius: 3px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.fade-in { animation: fadeIn .3s ease-out; }

/* ========================================
   PRINT: A4 summary only
   ======================================== */
#print-summary { display: none; }
@media print {
  @page { size: A4; margin: 10mm 11mm; }
  body { background: #fff !important; }
  #app-shell { display: none !important; }
  #print-summary { display: block; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.p-page { font-size: 9.5pt; color: #111827; line-height: 1.35; }
.p-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid #0369a1; padding-bottom: 4px; margin-bottom: 6px; }
.p-title { font-size: 15pt; font-weight: 800; color: #0c4a6e; }
.p-sub { font-size: 7.5pt; color: #6b7280; }
.p-head-right { font-size: 7.5pt; color: #6b7280; }
.p-grid-4 { display: grid; grid-template-columns: 1.4fr 1.2fr 1fr 1fr; gap: 5px; margin-bottom: 6px; }
.p-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.p-box { border: 1px solid #cbd5e1; border-radius: 5px; padding: 4px 7px; }
.p-box-asa { background: #eef2ff; border-color: #a5b4fc; }
.p-k { font-size: 7pt; color: #6b7280; font-weight: 700; }
.p-v { font-size: 11pt; font-weight: 800; }
.p-big { font-size: 15pt; color: #3730a3; }
.p-s { font-size: 7.5pt; color: #374151; }
.p-h { font-size: 8pt; font-weight: 800; color: #0c4a6e; background: #f0f9ff; border-left: 3px solid #0ea5e9; padding: 2px 6px; margin: 6px 0 3px; }
.p-body { font-size: 8.5pt; padding: 0 2px; }
.p-pre { white-space: pre-wrap; }
.p-small { font-size: 7.5pt; }
.p-muted { color: #9ca3af; }
.p-chip { display: inline-block; border: 1px solid #cbd5e1; border-radius: 9999px; padding: 0 6px; margin: 1px 2px 1px 0; font-size: 7.5pt; }
.p-labs { display: flex; flex-wrap: wrap; gap: 4px 10px; }
.p-lab-group { flex: 1 1 45%; }
.p-lab-group-title { font-size: 7pt; font-weight: 700; color: #6b7280; border-bottom: 1px solid #e5e7eb; margin-bottom: 1px; }
.p-lab { display: flex; justify-content: space-between; gap: 4px; font-size: 8pt; padding: 0 3px; border-radius: 3px; }
.p-lab-name { color: #374151; }
.p-lab-val { font-weight: 700; margin-left: auto; }
.p-lab-unit { color: #9ca3af; font-size: 7pt; width: 3.2em; }
.p-lab.p-high { background: #fee2e2; color: #991b1b; }
.p-lab.p-med { background: #fef3c7; color: #92400e; }
.p-table { width: 100%; border-collapse: collapse; font-size: 8pt; }
.p-table td { border-bottom: 1px solid #e5e7eb; padding: 1.5px 4px; vertical-align: top; }
.p-table td:first-child { width: 30%; font-weight: 600; }
.p-table td:nth-child(2) { width: 18%; color: #6b7280; }
.p-risk-list.many { columns: 2; column-gap: 8px; }
.p-risk { font-size: 7.6pt; padding: 1px 5px; break-inside: avoid; border-left: 3px solid; margin-bottom: 2px; border-radius: 2px; }
.p-risk-high { background: #fef2f2; border-color: #ef4444; color: #991b1b; }
.p-risk-medium { background: #fffbeb; border-color: #f59e0b; color: #92400e; }
.p-risk-combo { background: #fff7ed; border-color: #f97316; color: #9a3412; }
.p-foot { margin-top: 8px; border-top: 1px solid #e5e7eb; padding-top: 3px; font-size: 7pt; color: #9ca3af; text-align: center; }
.text-red { color: #dc2626; } .text-amber { color: #d97706; } .text-green { color: #16a34a; }
