html {
    height: 100%;
    overflow: hidden;
}

body {
    height: 100%;
    overflow: hidden;
    margin: 0;
    font-family: var(--sans);

    /* ── 1280px 초과 시 패널 컨테이너를 중앙 정렬 ── */
    display: flex;
    justify-content: center;
    align-items: stretch;

    /* ── cream 톤 배경 (landing 디자인 일치) ── */
    background-color: var(--cream);
    background-image:
        /* 미세한 격자 (분위기) */
        repeating-linear-gradient(0deg,
            rgba(0,0,0,0.018) 0px, rgba(0,0,0,0.018) 1px,
            transparent 1px, transparent 48px),
        repeating-linear-gradient(90deg,
            rgba(0,0,0,0.018) 0px, rgba(0,0,0,0.018) 1px,
            transparent 1px, transparent 48px),
        /* 부드러운 조명 효과 (accent + warm) */
        radial-gradient(ellipse 55% 70% at 8%  40%, rgba(26, 107, 74, 0.06) 0%, transparent 60%),
        radial-gradient(ellipse 50% 60% at 92% 60%, rgba(200, 98, 42, 0.04) 0%, transparent 55%);
}

/* 배경 장식 — 라이트 톤 점 패턴 */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background-image:
        radial-gradient(circle 2px at center, rgba(26,107,74,0.06) 0%, transparent 100%);
    background-size: 80px 80px;
}

/* === Panel System === */
.panel-container {
    display: flex;
    height: 100vh;                              /* fallback */
    height: 100dvh;                             /* iOS 15.4+ / Android Chrome 108+ — 시스템 UI 제외 동적 viewport */
    width: 100%;
    overflow: hidden;
    position: relative;
    z-index: 1;
    box-shadow: 0 8px 30px rgba(14,13,11,0.08), 0 2px 8px rgba(14,13,11,0.04);
}
/* dvh 미지원 구버전 브라우저용 JS 보조변수 폴백 (window.innerHeight 기반) */
@supports not (height: 100dvh) {
    .panel-container { height: calc(var(--vh, 1vh) * 100); }
}

.panel {
    transition: flex 0.42s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid #e2e8f0;
    background: white;
    position: relative;
}
.panel.active    { flex: 1 1 auto; min-width: 0; }
.panel.completed { flex: 0 0 clamp(96px, 6vw, 120px); cursor: pointer; }
.panel.pending   { flex: 0 0 clamp(96px, 6vw, 120px); opacity: 0.38; pointer-events: none; }
.panel:last-child { border-right: none; }

/* Hover on completed panels */
.panel.completed:hover { background: var(--accent-light); }

/* View toggle */
.panel-collapsed-view { display: none; }
.panel-expanded-view  { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.panel.completed .panel-collapsed-view,
.panel.pending   .panel-collapsed-view { display: flex; }
.panel.completed .panel-expanded-view,
.panel.pending   .panel-expanded-view  { display: none; }

/* === Collapsed view layout === */
.panel-collapsed-view {
    flex-direction: column;
    align-items: center;
    padding: 20px 8px;
    gap: 12px;
    height: 100%;
    overflow: hidden;
}
.panel-step-badge {
    width: clamp(40px, 3vw, 56px);
    height: clamp(40px, 3vw, 56px);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: clamp(18px, 1.3vw, 24px);
    flex-shrink: 0;
    transition: background 0.3s, color 0.3s;
}
.panel.completed .panel-step-badge { background: var(--accent); color: white; }
.panel.pending   .panel-step-badge { background: #e2e8f0; color: #94a3b8; }

.panel-collapsed-title {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: clamp(15px, 1.1vw, 20px);
    font-weight: 600;
    color: #94a3b8;
    letter-spacing: 0.06em;
    white-space: nowrap;
}
.panel.completed .panel-collapsed-title { color: #475569; }

.panel-vertical-label {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    font-size: clamp(14px, 1vw, 18px);
    color: #64748b;
    font-weight: 500;
    max-height: 200px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    letter-spacing: 0.03em;
}
.panel.completed .panel-vertical-label { color: var(--accent); font-weight: 700; }

/* === Panel Header === */
.panel-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: clamp(16px, 1.2vw, 26px) clamp(18px, 2vw, 40px);
    border-bottom: 2px solid var(--accent-light);
    background: white;
    flex-shrink: 0;
    gap: clamp(9px, 0.8vw, 16px);
    position: relative;
}
/* 관리자 + 초보자 가이드 버튼 묶음 — 좁은 화면에선 통째로 다음 줄로 (등급 뱃지와 겹침 방지) */
.panel-header .panel-actions { display: inline-flex; align-items: center; flex-shrink: 0; }
@media (max-width: 480px) {
    .panel-header .panel-actions { flex-basis: 100%; margin-left: 0; }
}
/* 현재 활성 패널 헤더 좌측에 accent 그린 보더 — 컨셉 컬러 강조 */
.panel.active .panel-header::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--accent);
}
.panel-header h2 {
    font-size: clamp(20px, 1.6vw, 32px);
    font-weight: 700;
    color: var(--ink);
    margin: 0;
    font-family: var(--sans);  /* UI 라벨은 sans 유지 — 가독성 우선 */
    letter-spacing: -0.01em;
}
.step-circle {
    width: clamp(30px, 2.2vw, 44px);
    height: clamp(30px, 2.2vw, 44px);
    border-radius: 50%;
    background: var(--accent);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(15px, 1.1vw, 22px);
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(26,107,74,0.3);
}

/* === Panel Body === */
.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: clamp(14px, 1.5vw, 28px) clamp(18px, 2vw, 40px);
    min-height: 0;
    font-size: clamp(15px, 1.1vw, 22px);
}
.panel-body::-webkit-scrollbar { width: 3px; }
.panel-body::-webkit-scrollbar-track { background: transparent; }
.panel-body::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* === Panel Footer === */
.panel-footer {
    padding: clamp(12px, 1vw, 20px) clamp(18px, 2vw, 40px);
    border-top: 1px solid #f1f5f9;
    background: white;
    flex-shrink: 0;
}

/* === Buttons (브랜드 컨셉 컬러 — accent 그린) === */
.btn-next {
    width: 100%;
    background: var(--accent);
    color: white;
    border: none;
    padding: clamp(12px, 1vw, 20px) clamp(16px, 1.2vw, 28px);
    border-radius: 10px;
    font-size: clamp(17px, 1.2vw, 24px);
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
    font-family: var(--sans);
}
.btn-next:hover { background: #155a3c; transform: translateY(-1px); box-shadow: 0 6px 18px rgba(26,107,74,0.25); }
.btn-next:active { transform: translateY(0); }

.btn-submit {
    width: 100%;
    background: var(--accent2);
    color: white;
    border: none;
    padding: clamp(12px, 1vw, 20px) clamp(16px, 1.2vw, 28px);
    border-radius: 10px;
    font-size: clamp(17px, 1.2vw, 24px);
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    transition: background 0.2s, box-shadow 0.2s;
    font-family: var(--sans);
}
.btn-submit:hover { background: var(--accent); box-shadow: 0 6px 18px rgba(26,107,74,0.25); }

/* === Form Fields === */
.field-group { margin-bottom: 16px; }
.field-group:last-child { margin-bottom: 0; }

.field-label {
    display: block;
    font-size: clamp(15px, 1.1vw, 22px);
    font-weight: 600;
    color: #475569;
    margin-bottom: clamp(6px, 0.5vw, 10px);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.field-input {
    width: 100%;
    padding: clamp(10px, 0.8vw, 18px) clamp(13px, 1vw, 22px);
    border: 1.5px solid #e2e8f0;
    border-radius: 8px;
    font-size: clamp(17px, 1.2vw, 24px);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: var(--sans);
    box-sizing: border-box;
    color: #1e293b;
    background: white;
}
.field-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(26,107,74,0.12);
}

/* === Custom checkbox/radio (matching base.html pattern) === */
.custom-input:checked + div {
    background-color: #eff6ff;
    border-color: #2563eb;
    color: #1e40af;
}

/* === Section divider === */
.section-divider { height: 1px; background: #f1f5f9; margin: 12px 0; }

/* === Teeth grid === */
.grid-cols-17 {
    display: grid;
    grid-template-columns: repeat(17, minmax(0, 1fr));
}
#panel-4 .tooth-item {
    aspect-ratio: 1;
    font-size: 10px;
    border-radius: 3px;
    border-width: 1.5px;
    border-style: solid;
}

/* === Treatment category cards (Panel 2) === */
.treat-cat-p3 h4 {
    font-size: clamp(16px, 1.2vw, 24px) !important;
}
.treat-cat-p3 .w-8 {
    width: clamp(32px, 2.5vw, 48px) !important;
    height: clamp(32px, 2.5vw, 48px) !important;
}
.treat-cat-p3 .w-8 i {
    font-size: clamp(16px, 1.2vw, 24px) !important;
}
.treat-cat-p3.selected {
    box-shadow: 0 6px 18px rgba(26,107,74,0.25);
    transform: translateY(-2px);
    border-width: 2px !important;
    border-color: var(--accent) !important;
    outline: 2px solid var(--accent-light);
    outline-offset: -4px;
}
.treat-cat-p3.disabled {
    opacity: 0.35;
    pointer-events: none;
    filter: grayscale(0.6);
}

/* === Gender pills (Panel 1) === */
.gender-pill { display: inline-block; }
.gender-pill .gender-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 18px 28px;
    min-width: 132px;
    min-height: 64px;
    border: 1.5px solid #d1d5db;
    border-radius: 14px;
    background: #fff;
    font-size: 18px;
    font-weight: 600;
    color: #374151;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.gender-pill .gender-icon,
.gender-pill .gender-glyph {
    font-size: 28px;
    line-height: 1;
    font-weight: 400;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Symbol", "Apple Color Emoji", system-ui, sans-serif;
}
.gender-pill .gender-glyph { letter-spacing: -0.02em; }
.gender-pill .gender-svg { width: 30px; height: 30px; flex-shrink: 0; }
.gender-pill:hover .gender-chip {
    background: #f9fafb;
    border-color: #9ca3af;
}
/* 기본 아이콘 색: 남=하늘색, 여=분홍색 */
.gender-pill.gender-male .gender-icon { color: #0ea5e9; }
.gender-pill.gender-female .gender-icon { color: #ec4899; }
/* 선택 시: 각 성별 컬러로 칩 전체 강조 */
.gender-pill.gender-male input[type="radio"]:checked + .gender-chip {
    background: #0ea5e9;
    border-color: #0ea5e9;
    color: #fff;
    box-shadow: 0 4px 12px rgba(14,165,233,0.3);
}
.gender-pill.gender-female input[type="radio"]:checked + .gender-chip {
    background: #ec4899;
    border-color: #ec4899;
    color: #fff;
    box-shadow: 0 4px 12px rgba(236,72,153,0.3);
}
.gender-pill input[type="radio"]:checked + .gender-chip .gender-icon {
    color: #fff;
}
/* 약 부작용/흡연/임신 등 — gender-male/female 색 클래스 없는 일반 pill은
   선택 시 컨셉 컬러(accent 그린)로 강조 (chip 흰배경 위 아이콘 흰색이면 안 보이는 버그 방지) */
.gender-pill:not(.gender-male):not(.gender-female) input[type="radio"]:checked + .gender-chip {
    background: var(--accent-light);
    border-color: var(--accent);
    color: var(--accent);
    box-shadow: 0 4px 12px rgba(26,107,74,0.2);
}
.gender-pill:not(.gender-male):not(.gender-female) input[type="radio"]:checked + .gender-chip .gender-icon {
    color: var(--accent);
}

/* === Panel 2 drill-down === */
#p2-subitems-view { display: none; }
#p2-subitems-view.active { display: block; }
#p2-grid-view.hidden-by-drill { display: none; }
.p2-subitem {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border: 1.5px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    font-size: 16px;
    font-weight: 500;
    color: #1f2937;
    transition: border-color 0.12s, background 0.12s;
}
.p2-subitem:hover { background: #f9fafb; border-color: #9ca3af; }
.p2-subitem.disabled {
    opacity: 0.45;
    pointer-events: none;
    background: #f3f4f6;
}
.p2-subitem .kind-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    flex-shrink: 0;
    min-width: 56px;
    letter-spacing: 0.02em;
}
.p2-subitem.kind-consent {
    border-color: #fecaca;
    background: #fef2f2;
}
.p2-subitem.kind-consent:hover { background: #fee2e2; border-color: #fca5a5; }
.p2-subitem.kind-consent .kind-tag {
    background: #ef4444;
    color: #fff;
}
.p2-subitem.kind-info {
    border-color: #bfdbfe;
    background: #eff6ff;
}
.p2-subitem.kind-info:hover { background: #dbeafe; border-color: #93c5fd; }
.p2-subitem.kind-info .kind-tag {
    background: #3b82f6;
    color: #fff;
}
.p2-subitem.disabled .kind-tag { background: #9ca3af; color: #fff; }
.p2-subitem .chevron { margin-left: auto; color: #9ca3af; font-size: 18px; }
.p2-subitem .chevron.text-xs { font-size: 12px; font-weight: 600; }
.p2-section-header {
    display: flex; align-items: center; gap: 8px;
    font-size: 16px; font-weight: 700;
    color: #374151;
    letter-spacing: 0.02em;
    padding: 10px 0 8px;
    border-bottom: 1px solid #e5e7eb;
    margin-top: 10px; margin-bottom: 10px;
}
.p2-section-header.first { margin-top: 0; }
#p2-subitems-title { font-size: 28px; font-weight: 700; color: #111827; line-height: 1.2; }
#p2-back-btn {
    font-size: 26px;
    font-weight: 700;
    padding: 12px 22px;
    border-radius: 12px;
}
#p2-back-btn i { font-size: 28px; }
#p2-subitems-title { font-size: 26px; font-weight: 700; color: var(--ink); }
#p2-subitems-view > .flex.items-center { gap: 16px; margin-bottom: 18px; }

/* 4-col 등 그리드 안에서는 pill 이 셀 전체를 채우도록 */
.grid .gender-pill { display: block; width: 100%; }
.grid .gender-pill .gender-chip { width: 100%; min-width: 0; }
/* 2-button flex 컨테이너에서도 균등 확장 */
.field-group > .flex.gap-2 > .gender-pill { flex: 1 1 0; min-width: 0; }
.field-group > .flex.gap-2 > .gender-pill .gender-chip { width: 100%; min-width: 0; }

/* === Disease cards (Panel 3, 4-col grid) === */
.disease-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 14px 8px;
    border: 1.5px solid #e5e7eb;
    border-radius: 12px;
    background: #fff;
    text-align: center;
    font-size: 14px;
    font-weight: 500;
    color: #374151;
    line-height: 1.3;
    transition: background 0.12s, border-color 0.12s, color 0.12s, box-shadow 0.12s;
}
.disease-card:hover { background: var(--accent-light); border-color: var(--accent2); }
.disease-card .disease-icon { font-size: 24px; line-height: 1; color: #6b7280; }
.disease-card.none-card .disease-icon { color: var(--accent); }
input[name="disease"]:checked + .disease-card {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(26,107,74,0.25);
}
input[name="disease"]:checked + .disease-card .disease-icon { color: #fff; }

/* === Panel 5 selected option badges (확대) === */
#p5-badges .badge-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #d1fae5;
    color: #065f46;
    border: 1px solid #6ee7b7;
    font-size: 14px;
    font-weight: 600;
    padding: 6px 12px;
    border-radius: 999px;
}
#p5-badges .badge-pill .badge-code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
    font-weight: 700;
    background: rgba(16,185,129,0.18);
    color: #065f46;
    padding: 2px 6px;
    border-radius: 6px;
}
#p5-badges .badge-pill .badge-rm {
    font-size: 16px;
    color: #047857;
    margin-left: 2px;
    line-height: 1;
}
#p5-badges .badge-pill .badge-rm:hover { color: #064e3b; }
#p2-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    background: #fff;
    font-size: 12px;
    color: #4b5563;
    cursor: pointer;
}
#p2-back-btn:hover { background: #f3f4f6; }
#p2-subitems-title {
    font-size: 14px;
    font-weight: 600;
    color: #111827;
}

/* === E-tab options (Panel 3) === */
.option-item-p3 {
    transition: all 0.15s;
}
.option-item-p3.selected {
    border-color: var(--accent) !important;
    background-color: var(--accent-light) !important;
    color: var(--accent);
    font-weight: 600;
}
.option-item-p3.option-disabled {
    opacity: 0.35;
    pointer-events: none;
    filter: grayscale(0.4);
}

/* === 자주 사용 스위치 호버 툴팁 (body 직속 fixed — 패널 overflow/스택 컨텍스트 회피) === */
#p5-freq-tip {
    position: fixed;
    background: #1f2937;
    color: #fff;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    z-index: 2147483647;
    transition: opacity 120ms ease;
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
    transform: translateX(-50%);
}
#p5-freq-tip.visible { opacity: 1; }
#p5-freq-tip::after {
    content: '';
    position: absolute;
    bottom: 100%; left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: #1f2937;
}

/* === Toast === */
.toast {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    background: linear-gradient(135deg, #ef4444, #b91c1c);
    color: white;
    padding: 18px 36px;
    border-radius: 14px;
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.2px;
    box-shadow: 0 12px 36px rgba(239,68,68,0.45), 0 0 0 1px rgba(255,255,255,0.08) inset;
    z-index: 9999;
    opacity: 0;
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
    white-space: nowrap;
    max-width: 92vw;
    text-align: center;
}
.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    animation: toastShake 0.55s cubic-bezier(.36,.07,.19,.97) both;
}
@keyframes toastShake {
    10%, 90% { transform: translateX(calc(-50% - 2px)); }
    20%, 80% { transform: translateX(calc(-50% + 4px)); }
    30%, 50%, 70% { transform: translateX(calc(-50% - 8px)); }
    40%, 60% { transform: translateX(calc(-50% + 8px)); }
    100% { transform: translateX(-50%); }
}

/* ── FHD+ (1920px 이상) 폰트 확대 ── */
@media (min-width: 1920px) {
    .panel-header h2 { font-size: 50px; }
    /* 큰 화면에서 panel-body 콘텐츠를 가운데 정렬 — 좌측 쏠림 방지 + 양옆 휑함 완화 */
    .panel.active .panel-body { max-width: 1400px; width: 100%; align-self: center; box-sizing: border-box; font-size: 32px; }
    .panel.active .panel-footer { max-width: 1400px; width: 100%; align-self: center; box-sizing: border-box; }
    .panel-body { font-size: 32px; }
    .panel-collapsed-title { font-size: 30px; }
    .panel-vertical-label { font-size: 26px; }
    .panel-step-badge { font-size: 36px; width: 72px; height: 72px; }
    .step-circle { font-size: 34px; width: 68px; height: 68px; }
    .field-label { font-size: 30px; }
    .field-input { font-size: 32px; padding: 22px 28px; }
    .btn-next, .btn-submit { font-size: 36px; padding: 28px 36px; }
    .treat-cat-p3 h4 { font-size: 32px !important; }
    .treat-cat-p3 .w-8 { width: 64px !important; height: 64px !important; }
    .treat-cat-p3 .w-8 i { font-size: 32px !important; }
    .treat-cat-p3 { padding: 22px !important; }
    .option-item-p3 { font-size: 26px !important; padding: 16px !important; }
    #panel-4 .tooth-item { font-size: 22px; }
    .toast { font-size: 30px; padding: 26px 54px; }

    /* 라디오/체크박스 옵션 박스 (전신질환·흡연·임신·부작용 등) */
    #disease-checkbox-grid label > div,
    label.cursor-pointer > div {
        font-size: 26px !important;
        padding: 18px 16px !important;
        border-width: 2px !important;
        border-radius: 12px !important;
    }
    /* 선택된 치아 박스 (요약 영역) */
    #p4-selectedTeethList { gap: 8px !important; }
    #p4-selectedTeethList span {
        font-size: 24px !important;
        padding: 8px 18px !important;
    }
    #panel-4 h3 { font-size: 26px !important; margin-bottom: 12px !important; }
}

/* ── Mobile Responsive ── */
@media (max-width: 768px) {
    .panel-container {
        flex-direction: column;
    }
    .panel {
        border-right: none;
        border-bottom: 1px solid #e2e8f0;
    }
    .panel.completed,
    .panel.pending {
        flex: 0 0 0px;
        min-height: 0;
        overflow: hidden;
        opacity: 0;
        pointer-events: none;
        padding: 0;
        border: none;
    }
    .panel.active {
        flex: 1 1 auto;
        min-height: 0;
    }
    .panel-collapsed-view {
        display: none !important;
    }
    .panel-header h2 {
        font-size: 17px;
    }
    .panel-body {
        padding: 12px 14px;
    }
    .panel-footer {
        padding: 10px 14px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));   /* 안드로이드 제스처바 / iOS 홈 인디케이터 회피 */
    }
    .grid-cols-17 {
        grid-template-columns: repeat(17, minmax(0, 1fr));
        gap: 1px !important;
    }
    #panel-4 .tooth-item {
        font-size: 8px;
        border-radius: 2px;
    }
}
