/* =========================================================================
   알레르기 리포트 플랫폼 — 디자인 시스템
   토큰 기반, 라이트/다크 대응, 접근성 고려
   ========================================================================= */

:root {
  /* 색상 토큰 (라이트) */
  --bg: #f6f7fb;
  --bg-elev: #ffffff;
  --bg-subtle: #f0f2f8;
  --surface-2: #f7f8fc;
  --border: #e4e7f0;
  --border-strong: #d3d8e6;
  --text: #1a1f2e;
  --text-2: #4a5266;
  --text-3: #838ca3;

  --brand: #5b63f0;
  --brand-strong: #4a4fe0;
  --brand-soft: #eef0fe;
  --brand-contrast: #ffffff;

  /* 시맨틱: 판정 */
  --relevant: #e5484d;
  --relevant-soft: #fdecec;
  --relevant-border: #f7c9cb;
  --sensitized: #64748b;
  --sensitized-soft: #eef1f5;
  --sensitized-border: #dbe0e8;
  --indet: #d9860a;
  --indet-soft: #fdf3e3;
  --indet-border: #f3dcae;
  --ok: #17a673;
  --ok-soft: #e6f7f0;

  /* 그림자 */
  --shadow-sm: 0 1px 2px rgba(24,32,60,.06), 0 1px 3px rgba(24,32,60,.05);
  --shadow-md: 0 4px 12px rgba(24,32,60,.08), 0 2px 6px rgba(24,32,60,.05);
  --shadow-lg: 0 16px 40px rgba(24,32,60,.14);
  --shadow-brand: 0 8px 24px rgba(91,99,240,.28);

  /* 형태 */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;
  --r-pill: 999px;

  /* 타이포 */
  --font: 'Pretendard', 'Pretendard Variable', -apple-system, BlinkMacSystemFont,
          'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', system-ui, sans-serif;

  --step: 60px;
  --maxw: 960px;
}

/* 다크 토큰 — 수동 토글(data-theme="dark")과 OS 선호(미디어) 양쪽 모두에 적용.
   수동 토글이 항상 이겨야 하므로 :root[data-theme="dark"] 를 명시하고,
   OS 다크는 사용자가 라이트로 강제(data-theme="light")하지 않은 경우에만 적용한다. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1017; --bg-elev: #171a24; --bg-subtle: #1d212e; --surface-2: #1a1e2a;
  --border: #262b3a; --border-strong: #333a4d;
  --text: #eef0f6; --text-2: #b3bacb; --text-3: #7d859a;
  --brand: #7c83ff; --brand-strong: #6b72f5; --brand-soft: #21243a;
  --relevant: #ff6369; --relevant-soft: #2c1a1d; --relevant-border: #4a2529;
  --sensitized: #8b95a8; --sensitized-soft: #20242f; --sensitized-border: #2e3444;
  --indet: #f0a94a; --indet-soft: #2a2113; --indet-border: #453518;
  --ok: #33c495; --ok-soft: #14271f;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 6px 18px rgba(0,0,0,.45);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.6);
  --shadow-brand: 0 8px 24px rgba(91,99,240,.35);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e1017; --bg-elev: #171a24; --bg-subtle: #1d212e; --surface-2: #1a1e2a;
    --border: #262b3a; --border-strong: #333a4d;
    --text: #eef0f6; --text-2: #b3bacb; --text-3: #7d859a;
    --brand: #7c83ff; --brand-strong: #6b72f5; --brand-soft: #21243a;
    --relevant: #ff6369; --relevant-soft: #2c1a1d; --relevant-border: #4a2529;
    --sensitized: #8b95a8; --sensitized-soft: #20242f; --sensitized-border: #2e3444;
    --indet: #f0a94a; --indet-soft: #2a2113; --indet-border: #453518;
    --ok: #33c495; --ok-soft: #14271f;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
    --shadow-md: 0 6px 18px rgba(0,0,0,.45);
    --shadow-lg: 0 20px 48px rgba(0,0,0,.6);
    --shadow-brand: 0 8px 24px rgba(91,99,240,.35);
  }
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--brand); }
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; }

/* ---------------- App shell ---------------- */
.app-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.app-header .bar {
  max-width: var(--maxw); margin: 0 auto; padding: 14px 20px;
  display: flex; align-items: center; gap: 12px;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: -.02em; }
.logo .mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(145deg, var(--brand), #8a4dd6);
  display: grid; place-items: center; color: #fff; font-size: 16px;
  box-shadow: var(--shadow-brand);
}
.logo small { display:block; font-weight:600; font-size:11px; color:var(--text-3); letter-spacing:0; }
.header-spacer { flex: 1; }
.theme-toggle, .ghost-btn {
  border: 1px solid var(--border); background: var(--bg-elev); color: var(--text-2);
  width: 38px; height: 38px; border-radius: var(--r-pill); display: grid; place-items: center;
  font-size: 16px; transition: .15s;
}
.theme-toggle:hover, .ghost-btn:hover { border-color: var(--border-strong); color: var(--text); }

main { max-width: var(--maxw); margin: 0 auto; padding: 24px 20px 80px; }

/* ---------------- Stepper ---------------- */
.stepper { display: flex; gap: 6px; margin: 8px 0 26px; overflow-x: auto; padding-bottom: 4px; }
.stepper .step {
  flex: 1 1 0; min-width: 92px; display: flex; flex-direction: column; gap: 7px;
  cursor: default;
}
.stepper .step .dot-row { display: flex; align-items: center; gap: 8px; }
.stepper .step .num {
  width: 26px; height: 26px; border-radius: var(--r-pill); flex: 0 0 auto;
  display: grid; place-items: center; font-size: 12.5px; font-weight: 800;
  background: var(--bg-subtle); color: var(--text-3); border: 1.5px solid var(--border);
  transition: .2s;
}
.stepper .step .line { flex: 1; height: 2px; background: var(--border); border-radius: 2px; }
.stepper .step:last-child .line { display: none; }
.stepper .step .label { font-size: 12px; color: var(--text-3); font-weight: 600; padding-left: 2px; }
.stepper .step.active .num { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow-brand); }
.stepper .step.active .label { color: var(--text); }
.stepper .step.done .num { background: var(--ok); border-color: var(--ok); color: #fff; }
.stepper .step.done .line { background: var(--ok); }
.stepper .step.clickable { cursor: pointer; }
.stepper .step.clickable:hover .num { border-color: var(--brand); color: var(--brand); }

/* ---------------- Panels / cards ---------------- */
.panel {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-xl);
  box-shadow: var(--shadow-md); padding: 30px; animation: rise .35s cubic-bezier(.2,.7,.3,1);
}
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
.panel + .panel { margin-top: 18px; }
.panel-head { margin-bottom: 22px; }
.panel-head .eyebrow { font-size: 12px; font-weight: 800; letter-spacing: .08em; color: var(--brand); text-transform: uppercase; }
.panel-head h1 { font-size: 25px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 8px; }
.panel-head p { color: var(--text-2); font-size: 14.5px; }

.card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 18px; box-shadow: var(--shadow-sm);
}
.card.soft { background: var(--surface-2); box-shadow: none; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: var(--r-md); font-weight: 700; font-size: 14.5px;
  border: 1px solid transparent; transition: .15s; white-space: nowrap;
}
.btn.primary { background: var(--brand); color: var(--brand-contrast); box-shadow: var(--shadow-brand); }
.btn.primary:hover { background: var(--brand-strong); transform: translateY(-1px); }
.btn.primary:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.secondary { background: var(--bg-elev); color: var(--text); border-color: var(--border-strong); }
.btn.secondary:hover { background: var(--bg-subtle); }
.btn.subtle { background: var(--brand-soft); color: var(--brand); }
.btn.subtle:hover { background: color-mix(in srgb, var(--brand-soft) 70%, var(--brand) 12%); }
.btn.danger-ghost { background: transparent; color: var(--relevant); border-color: transparent; padding: 8px; }
.btn.danger-ghost:hover { background: var(--relevant-soft); }
.btn.sm { padding: 8px 14px; font-size: 13px; }
.btn.block { width: 100%; }
.actions { display: flex; gap: 12px; justify-content: space-between; margin-top: 26px; flex-wrap: wrap; }
.actions .spacer { flex: 1; }

/* ---------------- Upload ---------------- */
.dropzone {
  border: 2px dashed var(--border-strong); border-radius: var(--r-xl); padding: 44px 24px;
  text-align: center; transition: .2s; background: var(--surface-2); cursor: pointer;
}
.dropzone:hover, .dropzone.drag { border-color: var(--brand); background: var(--brand-soft); }
.dropzone .icon { font-size: 40px; }
.dropzone h3 { font-size: 17px; margin: 12px 0 6px; }
.dropzone p { color: var(--text-3); font-size: 13.5px; }
.upload-alt { display: flex; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.upload-alt .btn { flex: 1; min-width: 200px; }
.preview-img { max-width: 100%; border-radius: var(--r-md); border: 1px solid var(--border); margin-top: 16px; }

/* ---------------- Table (OCR review) ---------------- */
.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--r-md); }
table.grid { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
table.grid th {
  text-align: left; font-size: 12px; font-weight: 700; color: var(--text-3);
  padding: 11px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.grid td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: none; }
table.grid input, table.grid select {
  width: 100%; border: 1px solid transparent; background: transparent; color: var(--text);
  padding: 7px 8px; border-radius: var(--r-sm); font-size: 14px; font-family: inherit;
}
table.grid input:hover, table.grid select:hover { background: var(--bg-subtle); }
table.grid input:focus, table.grid select:focus { background: var(--bg-elev); border-color: var(--brand); outline: none; }
table.grid td.num input { text-align: right; font-variant-numeric: tabular-nums; }
.row-pos { display: inline-flex; }
.pos-toggle {
  border: 1px solid var(--border-strong); background: var(--bg-elev); border-radius: var(--r-pill);
  padding: 5px 12px; font-size: 12.5px; font-weight: 700; color: var(--text-3); transition: .15s;
}
.pos-toggle.on { background: var(--relevant-soft); color: var(--relevant); border-color: var(--relevant-border); }
.pos-toggle.off { background: var(--sensitized-soft); color: var(--sensitized); }
.tbl-toolbar { display: flex; gap: 10px; align-items: center; margin: 16px 0 0; flex-wrap: wrap; }
.tbl-toolbar .spacer { flex: 1; }
/* OCR 검토 탭 (측정값 / 수치 0 항목) */
.rv-tabs { display: flex; gap: 4px; align-items: center; margin: 0 0 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.rv-tab {
  appearance: none; border: 0; background: transparent; cursor: pointer;
  padding: 9px 14px; font-size: 13.5px; font-weight: 700; color: var(--text-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; align-items: center; gap: 7px;
}
.rv-tab:hover { color: var(--text); }
.rv-tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.rv-count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px;
  padding: 0 6px; border-radius: 999px; font-size: 11.5px; font-weight: 700;
  background: var(--surface-2); color: var(--text-2);
}
.rv-tab.active .rv-count { background: var(--brand); color: #fff; }
.pos-summary {
  margin-top: 16px; padding: 13px 16px; border-radius: var(--r-md);
  background: var(--relevant-soft); border: 1px solid var(--relevant-border); color: var(--relevant);
  font-size: 13.5px; font-weight: 600;
}
.field-inline { display: flex; gap: 8px; align-items: center; }
.badge-count { background: var(--brand); color: #fff; border-radius: var(--r-pill); padding: 2px 9px; font-size: 12px; font-weight: 800; }

/* ---------------- Form fields ---------------- */
.field { margin-bottom: 18px; }
.field > label { display: block; font-weight: 700; font-size: 13.5px; margin-bottom: 8px; }
.field .hint { color: var(--text-3); font-size: 12.5px; font-weight: 500; margin-top: 3px; }
.input, select.input {
  width: 100%; padding: 11px 13px; border: 1px solid var(--border-strong); border-radius: var(--r-md);
  background: var(--bg-elev); color: var(--text); font-size: 14.5px; font-family: inherit; transition: .15s;
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 620px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* chips (multi-select) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-opt {
  border: 1px solid var(--border-strong); background: var(--bg-elev); color: var(--text-2);
  padding: 9px 15px; border-radius: var(--r-pill); font-size: 13.5px; font-weight: 600; transition: .15s;
  user-select: none;
}
.chip-opt:hover { border-color: var(--brand); }
.chip-opt.sel { background: var(--brand); color: #fff; border-color: var(--brand); box-shadow: var(--shadow-brand); }

/* radio / single-choice pills */
.choice-list { display: flex; flex-direction: column; gap: 10px; }
.choice {
  display: flex; align-items: flex-start; gap: 13px; padding: 15px 17px;
  border: 1.5px solid var(--border); border-radius: var(--r-md); background: var(--bg-elev);
  transition: .15s; text-align: left; width: 100%;
}
.choice:hover { border-color: var(--brand); background: var(--surface-2); }
.choice.sel { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px var(--brand-soft); }
.choice .radio {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--border-strong);
  flex: 0 0 auto; margin-top: 1px; transition: .15s; position: relative;
}
.choice.sel .radio { border-color: var(--brand); }
.choice.sel .radio::after { content:''; position:absolute; inset:3px; border-radius:50%; background: var(--brand); }
.choice .body .t { font-weight: 700; font-size: 14.5px; }
.choice .body .h { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
/* horizontal yes/no/unsure */
.choice-row { display: flex; gap: 10px; flex-wrap: wrap; }
.choice-row .choice { flex: 1; min-width: 120px; justify-content: center; text-align: center; }
.choice-row .choice .body .t { font-size: 14px; }

/* ---------------- Questionnaire ---------------- */
.q-section { margin-bottom: 26px; }
.q-section .q-shead { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.q-section .q-shead h2 { font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.q-section .q-sub { color: var(--text-2); font-size: 13px; margin-bottom: 16px; }
.q-block { margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px dashed var(--border); }
.q-block:last-child { border-bottom: none; padding-bottom: 0; margin-bottom: 0; }
.q-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; }
.q-help { color: var(--text-3); font-size: 12.5px; margin-bottom: 12px; line-height: 1.5; }
.q-applies { display: inline-flex; flex-wrap: wrap; gap: 5px; margin-bottom: 11px; }
.q-applies .tag {
  font-size: 11px; font-weight: 700; background: var(--bg-subtle); color: var(--text-2);
  padding: 3px 9px; border-radius: var(--r-pill); border: 1px solid var(--border);
}

/* ---------------- Results ---------------- */
.result-hero {
  background: linear-gradient(150deg, var(--brand) 0%, #8a4dd6 100%); color: #fff;
  border-radius: var(--r-xl); padding: 28px 30px; box-shadow: var(--shadow-brand);
}
.result-hero h1 { font-size: 23px; font-weight: 800; }
.result-hero p { opacity: .92; margin-top: 6px; font-size: 14px; }
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 20px; }
.stat {
  background: rgba(255,255,255,.16); border-radius: var(--r-md); padding: 15px 12px; text-align: center;
  backdrop-filter: blur(4px);
}
.stat .n { font-size: 28px; font-weight: 800; line-height: 1; }
.stat .l { font-size: 12px; opacity: .92; margin-top: 6px; }

.result-tabs { display: flex; gap: 6px; margin: 22px 0 18px; border-bottom: 1px solid var(--border); }
.result-tabs button {
  background: none; border: none; padding: 12px 16px; font-weight: 700; font-size: 14px;
  color: var(--text-3); border-bottom: 2.5px solid transparent; transition: .15s; margin-bottom: -1px;
}
.result-tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.result-tabs button:hover { color: var(--text); }

.allergen-card {
  border: 1px solid var(--border); border-radius: var(--r-lg); padding: 0; overflow: hidden;
  margin-bottom: 12px; background: var(--bg-elev); box-shadow: var(--shadow-sm);
}
.allergen-card .ac-head {
  display: flex; align-items: center; gap: 12px; padding: 15px 18px; cursor: pointer;
}
.allergen-card .emoji { font-size: 22px; }
.allergen-card .ac-title { flex: 1; }
.allergen-card .ac-title .nm { font-weight: 800; font-size: 15.5px; }
.allergen-card .ac-title .meta { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.rel-badge { font-size: 11.5px; font-weight: 800; padding: 5px 11px; border-radius: var(--r-pill); white-space: nowrap; }
.rel-badge.clinically_relevant { background: var(--relevant-soft); color: var(--relevant); border: 1px solid var(--relevant-border); }
.rel-badge.sensitized_only { background: var(--sensitized-soft); color: var(--sensitized); border: 1px solid var(--sensitized-border); }
.rel-badge.indeterminate { background: var(--indet-soft); color: var(--indet); border: 1px solid var(--indet-border); }
.rel-badge.not_assessed { background: var(--bg-subtle); color: var(--text-3); }
.allergen-card .ac-body { padding: 0 18px 18px; display: none; }
.allergen-card.open .ac-body { display: block; animation: rise .25s ease; }
.allergen-card .rationale { font-size: 13.5px; color: var(--text); background: var(--surface-2); border-radius: var(--r-md); padding: 13px 15px; line-height: 1.6; }
.allergen-card .kb-grid { margin-top: 12px; display: grid; gap: 10px; }
.allergen-card .kb-item .k { font-size: 11.5px; font-weight: 800; color: var(--text-3); text-transform: uppercase; letter-spacing: .04em; }
.allergen-card .kb-item .v { font-size: 13px; color: var(--text-2); margin-top: 3px; line-height: 1.6; }
.allergen-card .kb-item ul { margin: 4px 0 0 18px; }
.allergen-card .kb-item li { font-size: 13px; color: var(--text-2); margin-bottom: 3px; }
.chevron { color: var(--text-3); transition: transform .2s; }
.allergen-card.open .chevron { transform: rotate(180deg); }
.src-tag { font-size: 10.5px; color: var(--text-3); }

.report-render { line-height: 1.7; font-size: 14.5px; }
.report-render h1 { font-size: 22px; margin: 4px 0 14px; }
.report-render h2 { font-size: 18px; margin: 24px 0 10px; padding-top: 8px; border-top: 1px solid var(--border); }
.report-render h3 { font-size: 15.5px; margin: 16px 0 8px; }
.report-render ul, .report-render ol { margin: 8px 0 8px 22px; }
.report-render li { margin-bottom: 5px; }
.report-render table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 13.5px; }
.report-render th, .report-render td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.report-render th { background: var(--surface-2); }
.report-render code { background: var(--bg-subtle); padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.report-render hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

.cardnews-frame { width: 100%; height: 660px; border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--bg-subtle); }
.report-frame { width: 100%; height: 760px; border: 1px solid var(--border); border-radius: var(--r-lg); background: #fff; }

.download-row { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }

/* ---------------- Misc ---------------- */
.notice { padding: 13px 16px; border-radius: var(--r-md); font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.notice.warn { background: var(--indet-soft); color: var(--indet); border: 1px solid var(--indet-border); }
.notice.info { background: var(--brand-soft); color: var(--brand); }
.notice.flag { background: var(--relevant-soft); color: var(--relevant); border: 1px solid var(--relevant-border); }
.disclaimer { text-align: center; color: var(--text-3); font-size: 12px; margin-top: 24px; line-height: 1.6; }
.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn.secondary .spinner { border-color: var(--border-strong); border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 50px 0; color: var(--text-3); }
.center-load .spinner { width: 30px; height: 30px; border-color: var(--border); border-top-color: var(--brand); }
.hidden { display: none !important; }
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text); color: var(--bg-elev); padding: 12px 20px; border-radius: var(--r-pill);
  font-size: 13.5px; font-weight: 600; box-shadow: var(--shadow-lg); opacity: 0; transition: .3s; z-index: 100;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ============================================================
   모바일 전용 UI — Step 3(스크리닝)·Step 4(감별 문진)
   웹/태블릿(>640px)은 기존 레이아웃 그대로. 스마트폰에서만 다르게:
   원핸드 조작을 위한 큰 터치 타깃 · 세로 스택 · 하단 고정 내비게이션.
   ============================================================ */
@media (max-width: 640px) {
  /* iOS 자동 확대 방지(입력 16px) + 큰 입력 */
  .input, input.input, select.input, textarea { font-size: 16px !important; }
  .field .input { min-height: 50px; }
  .field > label { font-size: 14px; }
  .panel-head h1 { font-size: 22px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  /* 단일 선택지: 한 손 조작 위해 세로 스택 + 큰 탭 영역 */
  .choice-row { flex-direction: column; }
  .choice-row .choice { min-width: 0; width: 100%; justify-content: flex-start; text-align: left; }
  .choice { min-height: 56px; align-items: center; padding: 14px 16px; }
  .choice .radio { width: 24px; height: 24px; }
  .choice .body .t { font-size: 16px; }
  .choice .body .h { font-size: 13px; }

  /* 칩(다중 선택): 큰 탭 영역 */
  .chips { gap: 9px; }
  .chip-opt { min-height: 46px; padding: 12px 16px; font-size: 15px; display: inline-flex; align-items: center; }

  /* 감별 문진: 한 문항씩 또렷한 카드로 */
  body[data-appstep="3"] .q-block {
    background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-md);
    padding: 16px 15px; margin-bottom: 14px; border-bottom: 1px solid var(--border);
  }
  body[data-appstep="3"] .q-block:last-child { margin-bottom: 14px; padding-bottom: 16px; }
  body[data-appstep="3"] .q-title { font-size: 16.5px; line-height: 1.45; }
  body[data-appstep="3"] .q-help { font-size: 13.5px; }
  .q-section .q-shead h2 { font-size: 19px; }
  .q-applies .tag { font-size: 12px; padding: 5px 10px; }

  /* 하단 고정 내비게이션 — 스크리닝(2)·문진(3) 단계 한정 */
  body[data-appstep="2"] .panel, body[data-appstep="3"] .panel { padding-bottom: 92px; }
  body[data-appstep="2"] .actions, body[data-appstep="3"] .actions {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; margin: 0;
    padding: 11px 16px calc(11px + env(safe-area-inset-bottom, 0px));
    background: var(--bg-elev); border-top: 1px solid var(--border);
    box-shadow: 0 -6px 22px rgba(0,0,0,.10); gap: 10px; align-items: stretch;
  }
  body[data-appstep="2"] .actions .btn.primary, body[data-appstep="3"] .actions .btn.primary {
    flex: 1 1 auto; min-height: 52px; font-size: 15.5px;
  }
  body[data-appstep="2"] .actions .btn.secondary, body[data-appstep="3"] .actions .btn.secondary {
    min-height: 52px; flex: 0 0 auto;
  }
  body[data-appstep="2"] .actions .spacer, body[data-appstep="3"] .actions .spacer { display: none; }

  /* 결과 탭도 모바일에서 스크롤 편하게 */
  .report-frame { height: 68vh; }
  .cardnews-frame { height: min(78vh, 680px); }
}

/* 듀얼 UI 전환 링크 (클래식 ↔ 탐험 퀘스트) */
.ui-switch { font-size: 12.5px; font-weight: 700; color: var(--text-2); border: 1px solid var(--border-strong); border-radius: var(--r-pill); padding: 7px 11px; text-decoration: none; margin-right: 8px; white-space: nowrap; }
.ui-switch:hover { background: var(--bg-subtle); color: var(--text); }
.lang-sel { font-size: 12.5px; font-weight: 700; color: var(--text-2); background: var(--bg-elev); border: 1px solid var(--border-strong); border-radius: var(--r-pill); padding: 6px 10px; font-family: inherit; min-height: 34px; margin-right: 8px; }
/* 쓸 수 없는 AI 엔진 — 고를 수 없고, 흐리게·점선으로 구분한다 */
.lang-sel.unavail { color: var(--text-3); border-style: dashed; opacity: 1; }
.lang-sel:disabled { cursor: not-allowed; }
@media (max-width: 640px) { .ui-switch { display: none; } }

/* ---------- 결과 상담 챗봇 ---------- */
.chat-panel { display: flex; flex-direction: column; gap: 10px; }
.chat-sugg-t { font-size: 12px; font-weight: 800; color: var(--text-3); margin-bottom: 6px; }
.chat-log { max-height: 46vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px;
  padding: 12px; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-md); }
.chat-log:empty { display: none; }
.chat-msg { display: flex; flex-direction: column; gap: 3px; max-width: 88%; }
.chat-msg.user { align-self: flex-end; align-items: flex-end; }
.chat-who { font-size: 11px; font-weight: 800; color: var(--text-3); }
.chat-bubble { font-size: 14px; line-height: 1.65; padding: 10px 14px; border-radius: var(--r-md);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text); }
.chat-msg.user .chat-bubble { background: var(--brand-soft); border-color: var(--brand); }
.chat-input { display: flex; gap: 8px; }
.chat-input .input { flex: 1; }
.chat-foot { display: flex; align-items: center; gap: 10px; justify-content: space-between;
  font-size: 11.5px; color: var(--text-3); }
@media (max-width: 640px) { .chat-msg { max-width: 96%; } .chat-log { max-height: 52vh; } }

/* OCR 확인 화면 — 검증 규칙이 표시한 행 */
tr.row-flag td { background: rgba(255, 176, 32, .13); }
tr.row-flag td:first-child { box-shadow: inset 3px 0 0 #e8a33d; }
.rv-gate { display: block; }
.rv-gate b { font-weight: 800; }

/* ---------- 알러젠 자동완성(표 입력 칸의 제안 목록) ----------
   body 에 붙는 position:fixed 목록 — 가로 스크롤되는 .tbl-wrap 에 잘리지 않는다. 위치·너비는 web/shared.js(acPlace)가 정한다. */
.ac-list { position: fixed; z-index: 45; margin: 0; padding: 4px; list-style: none; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg-elev); border: 1.5px solid var(--brand); border-radius: var(--r-md); box-shadow: var(--shadow-lg); }
.ac-list li { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: var(--r-sm); cursor: pointer; }
.ac-list li:hover { background: var(--bg-subtle); }
.ac-list li[aria-selected="true"] { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand-strong); }
.ac-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; font-size: 14px; color: var(--text); }
.ac-main span { color: var(--text-2); font-size: 13.5px; }
.ac-sub { font-size: 12px; color: var(--text-3); }
.ac-hint { margin: 8px 0 0; }
.ac-hint, .mail-panel > .hint { color: var(--text-3); font-size: 12.5px; }
.ctl-note { font-size: 11.5px; color: var(--text-2); margin-top: 3px; }   /* 검토 표의 검사 대조 행 안내 */
.unk-note { font-size: 11.5px; color: var(--text-2); margin-top: 3px; }   /* 등록 목록에 없는 알러젠 이름 — 막지 않는 안내 */

/* ---------- 결과 이메일 받기 ---------- */
.mail-panel { margin-top: 18px; }
.mail-panel h2 { font-size: 17px; margin: 0 0 4px; }
.mail-panel .q-help { margin-bottom: 12px; }
.mail-kinds { border: 0; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.mail-kinds legend, .mail-label { display: block; padding: 0; font-weight: 800; font-size: 13.5px; margin-bottom: 8px; color: var(--text); }
.mail-kind { display: inline-flex; align-items: center; gap: 8px; border: 1.5px solid var(--border-strong); background: var(--bg-elev); color: var(--text);
  border-radius: var(--r-pill); padding: 8px 14px; font-size: 13.5px; font-weight: 700; cursor: pointer; }
.mail-kind:has(input:checked) { border-color: var(--brand-strong); background: var(--brand-soft); }
.mail-kind:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.mail-kind input { width: 18px; height: 18px; accent-color: var(--brand-strong); }
.mail-row { display: flex; gap: 8px; align-items: stretch; }
.mail-row .input { flex: 1 1 auto; min-width: 0; }
.mail-row .input[aria-invalid="true"] { border-color: var(--relevant); }
.mail-row .btn { flex: none; white-space: nowrap; justify-content: center; }
#mailMsg .notice { margin-top: 12px; }
#pdfMsg .notice { margin-top: 10px; }
.mail-files { margin-top: 4px; font-size: 12.5px; overflow-wrap: anywhere; }
.mail-files ul { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0 6px; }
.mail-files code { display: inline-block; max-width: 100%; margin: 2px 0; background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 1px 6px; }
.mail-panel > .hint { margin: 12px 0 0; }
@media (max-width: 640px) {
  .ac-list li { padding: 11px 10px; }
  .ac-main { font-size: 15px; }
  .mail-kind { min-height: 44px; }
  .mail-row { flex-direction: column; }
  .mail-row .btn { min-height: 48px; }
}

/* 결과 화면 — 화면 언어의 결과를 준비하는 중/준비하지 못함 안내 */
#langSync:empty { display: none; }
.lang-sync { margin: 0 0 14px; align-items: center; }
.lang-sync .spinner { flex: none; }
.lang-sync .btn { margin-left: auto; flex: none; }

/* 결과 상담 — 일반 지식 출처 · 화면 언어로 오지 않은 답변 표시 */
.chat-tr { font-size: 11.5px; color: var(--indet); margin-top: 2px; }
.kb-src { margin-top: 6px; font-size: 11.5px; color: var(--text-2); }
.kb-src summary { cursor: pointer; opacity: .8; }
.kb-src summary:hover { opacity: 1; }
.kb-src .src-item { margin: 6px 0 0 2px; line-height: 1.5; }
.kb-src .src-item a { color: var(--brand); text-decoration: underline; }
.kb-src .src-note { margin-top: 6px; opacity: .75; font-style: italic; }
.kb-src .src-list { margin: 4px 0 0; padding-left: 16px; }
.kb-src .src-list li { margin: 4px 0; }
.kb-src .src-pred { font-weight: 700; opacity: .85; }
.kb-src .src-quote { margin: 2px 0 0; padding-left: 8px; border-left: 2px solid var(--border-strong); opacity: .85; }
.kb-src .src-ids { font-size: 10.5px; opacity: .6; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }
.kb-src .src-map { font-size: 10.5px; opacity: .7; }

/* 좁은 화면(390px): 머리글이 화면 밖으로 밀리지 않게 하고, 결과 탭 다섯 개는 옆으로 밀어 볼 수 있게 한다 */
@media (max-width: 640px) {
  .app-header .bar { padding: 10px 12px; gap: 6px; }
  .logo { min-width: 0; gap: 8px; }
  .logo small { display: none; }
  .lang-sel { margin-right: 0; padding: 6px 6px; max-width: 96px; }
  #engineSel.unavail { max-width: 128px; }
  .theme-toggle { flex: none; width: 34px; height: 34px; }
  .result-tabs { overflow-x: auto; scrollbar-width: thin; }
  .result-tabs button { flex: none; white-space: nowrap; }
}
