/* ─────────────────────────────────────────────────────────────
   환경교육 조사 결과 대시보드 — 화면 스타일
   원칙: 보고서 표지의 짙은 청록을 상단 띠로, 본문은 종이빛 바탕에 가는 선으로 구획.
   그림자·그라데이션 없이 선·여백·숫자 크기로 위계를 만든다. 8px 간격 체계.
   ───────────────────────────────────────────────────────────── */
@import url("https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/variable/pretendardvariable-dynamic-subset.min.css");

:root {
  color-scheme: light;
  --paper: #f4f5f1;
  --surface: #ffffff;
  --surface-2: #edf1ee;
  --ink: #15201e;
  --ink-2: #4a5855;
  --ink-3: #7a8683;
  --line: #dfe4e0;
  --line-2: #c9d2cd;
  --brand: #0e9c89;
  --brand-deep: #0b3d38;
  --brand-ink: #0f5f55;
  --brand-soft: #dcefeb;
  --accent: #b86b1d;
  --accent-soft: #f8ead8;
  --danger: #c0392b;
  --radius: 8px;
  --radius-s: 6px;
  --font: "Pretendard Variable", Pretendard, -apple-system, "Segoe UI", "Malgun Gothic", system-ui, sans-serif;
  --maxw: 1360px;
  --gutter: 20px;
  --tap: 36px;
}

* { box-sizing: border-box; }
html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--font); line-height: 1.55; -webkit-font-smoothing: antialiased; }
a { color: var(--brand-ink); }
button { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; letter-spacing: -0.012em; }
p { margin: 0 0 .6em; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ── 상단 띠 ─────────────────────────────────────────── */
.masthead { background: var(--brand-deep); color: #fff; border-top: 4px solid var(--brand); }
.masthead .wrap { max-width: var(--maxw); margin: 0 auto; padding: 16px var(--gutter) 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 24px; align-items: end; }
.masthead .title { font-size: 1.4rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.masthead .title small { display: block; font-size: .78rem; font-weight: 500; opacity: .78; margin-top: 4px; letter-spacing: 0; }
.masthead .meta { font-size: .76rem; opacity: .88; text-align: right; line-height: 1.5; }
.masthead .meta .badge { display: inline-block; margin-top: 6px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); border: 1px solid #ead7bd; line-height: 1.5; white-space: nowrap; }
.badge.synthetic::before { content: "●"; margin-right: 5px; font-size: .6em; vertical-align: middle; }
.badge.neutral { background: var(--surface-2); color: var(--ink-2); border-color: var(--line); }
.badge.good { background: #dff3e4; color: #1d6b3a; border-color: #bfe3c8; }

.tabs { grid-column: 1 / -1; display: flex; gap: 2px; overflow-x: auto; margin-top: 10px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { display: block; padding: 10px 14px; color: #d3e3df; text-decoration: none; font-weight: 600; font-size: .92rem; border-radius: 8px 8px 0 0; white-space: nowrap; border: 1px solid transparent; border-bottom: 0; min-height: var(--tap); }
.tabs a:hover { color: #fff; background: rgba(255,255,255,.08); }
.tabs a.active { background: var(--paper); color: var(--brand-deep); border-color: var(--paper); }

/* ── 보조 막대(하위 탭 + 필터) ─────────────────────── */
.subbar { position: sticky; top: 0; z-index: 20; background: var(--paper); border-bottom: 1px solid var(--line); }
.subbar .wrap { max-width: var(--maxw); margin: 0 auto; padding: 8px var(--gutter); display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.subtabs { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.subtabs button { border: 1px solid var(--line-2); background: var(--surface); padding: 6px 12px; border-radius: 999px; cursor: pointer; font-size: .86rem; font-weight: 600; color: var(--ink-2); min-height: 32px; }
.subtabs button:hover { border-color: var(--brand); color: var(--brand-ink); }
.subtabs button.active { background: var(--brand-deep); color: #fff; border-color: var(--brand-deep); }
.filters { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-left: auto; }
.filters .label { font-size: .78rem; color: var(--ink-3); margin-right: 2px; }
.fsel { position: relative; }
.fsel > button { border: 1px solid var(--line-2); background: var(--surface); padding: 6px 10px; border-radius: var(--radius-s); cursor: pointer; font-size: .84rem; color: var(--ink); display: inline-flex; gap: 6px; align-items: center; min-height: 32px; }
.fsel > button:hover { border-color: var(--brand); }
.fsel > button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.fsel .menu { position: absolute; top: calc(100% + 4px); left: 0; min-width: 210px; max-height: 320px; overflow: auto; background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--radius); padding: 6px; z-index: 30; display: none; }
.fsel.open .menu { display: block; }
.fsel .menu label { display: flex; gap: 8px; align-items: center; padding: 6px 8px; font-size: .86rem; border-radius: 4px; cursor: pointer; min-height: 32px; }
.fsel .menu label:hover { background: var(--surface-2); }
.fsel .menu .actions { display: flex; gap: 6px; justify-content: space-between; padding: 6px 6px 2px; border-top: 1px solid var(--line); margin-top: 4px; }
.fsel .menu .actions button { border: 0; background: none; color: var(--brand-ink); cursor: pointer; font-size: .8rem; padding: 4px; }
.btn { border: 1px solid var(--line-2); background: var(--surface); padding: 6px 12px; border-radius: var(--radius-s); cursor: pointer; font-size: .86rem; font-weight: 600; color: var(--ink); display: inline-flex; align-items: center; gap: 6px; min-height: 34px; text-decoration: none; }
.btn:hover { border-color: var(--brand); color: var(--brand-ink); }
.btn.primary { background: var(--brand-deep); color: #fff; border-color: var(--brand-deep); }
.btn.primary:hover { background: #0f4f48; color: #fff; }
.btn.small { padding: 4px 10px; font-size: .8rem; min-height: 30px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn.filter-toggle { display: none; }

/* ── 본문 ────────────────────────────────────────────── */
main { max-width: var(--maxw); margin: 0 auto; padding: 18px var(--gutter) 64px; }
.page-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 16px; margin: 4px 0 14px; }
.page-head h2 { font-size: 1.22rem; }
.page-head .desc { color: var(--ink-2); font-size: .9rem; }
.page-head .right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.notice { border-left: 3px solid var(--accent); background: var(--accent-soft); color: #5a3a12; padding: 8px 12px; border-radius: 0 var(--radius-s) var(--radius-s) 0; font-size: .86rem; margin: 0 0 14px; line-height: 1.5; }
.notice.info { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-deep); }

.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; align-items: start; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; } .span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }
@media (max-width: 1100px) { .span-4, .span-3, .span-5, .span-7 { grid-column: span 6; } .span-8 { grid-column: span 12; } }
@media (max-width: 720px) { .grid > * { grid-column: span 12 !important; } }

/* ── 패널(바꿀 수 있는 칸) ─────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 320px; }
.panel.compact { min-height: 0; }
.panel header { display: flex; align-items: flex-start; gap: 8px; padding: 12px 14px 6px; }
.panel header .ttl { flex: 1; min-width: 0; }
.panel header h3 { font-size: 1rem; line-height: 1.3; }
.panel header .sub { font-size: .77rem; color: var(--ink-3); margin-top: 3px; line-height: 1.45; }
.panel header .acts { display: flex; gap: 0; flex-shrink: 0; border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface); }
.icon-btn { border: 0; background: transparent; width: 32px; height: 32px; border-radius: var(--radius-s); cursor: pointer; color: var(--ink-2); display: inline-grid; place-items: center; font-size: .9rem; }
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.icon-btn.on { background: var(--brand-soft); color: var(--brand-ink); }
.icon-btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.panel .unpub { margin: 0 14px 6px; padding: 6px 10px; border-radius: var(--radius-s); background: var(--accent-soft); color: #5a3a12; font-size: .76rem; line-height: 1.4; border-left: 3px solid var(--accent); }
.panel .body { flex: 1; min-height: 240px; position: relative; padding: 0 8px; }
.panel .chart { width: 100%; height: 100%; min-height: 240px; }
.panel .table-wrap { padding: 0 14px 10px; overflow: auto; max-height: 360px; }
.panel footer { padding: 6px 14px 10px; font-size: .74rem; color: var(--ink-3); display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; border-top: 1px dashed var(--line); }
.panel footer .src { flex: 1; min-width: 0; }
.panel .empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); font-size: .9rem; text-align: center; padding: 20px; }
.panel.table-first .body { min-height: 0; }
.table-first .chart { display: none; }
.table-first.show-chart .chart { display: block; }

table.data { border-collapse: collapse; width: 100%; font-size: .82rem; }
table.data th, table.data td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.data th { background: var(--surface-2); color: var(--ink-2); font-weight: 600; position: sticky; top: 0; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data td.sup { color: var(--ink-3); }
table.data tr.total td { font-weight: 700; background: #fafbf9; }
.flag { font-size: .7rem; color: var(--accent); margin-left: 4px; }

/* ── KPI 장부 ───────────────────────────────────────── */
.ledger { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-top: 2px solid var(--brand-deep); border-bottom: 1px solid var(--line-2); background: var(--surface); }
.ledger .kpi { padding: 16px 18px 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); min-height: 112px; }
.ledger .kpi:nth-child(4n) { border-right: 0; }
.kpi .lbl { font-size: .8rem; color: var(--ink-2); }
.kpi .val { font-size: 2rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; margin: 6px 0 4px; color: var(--brand-deep); }
.kpi .val small { font-size: .9rem; font-weight: 600; color: var(--ink-3); margin-left: 2px; }
.kpi .cmp { font-size: .78rem; color: var(--ink-3); }
.kpi .cmp b { color: var(--ink-2); font-weight: 600; }
@media (max-width: 1000px) { .ledger { grid-template-columns: repeat(2, minmax(0, 1fr)); } .ledger .kpi:nth-child(2n) { border-right: 0; } }
@media (max-width: 480px) { .ledger { grid-template-columns: 1fr; } .ledger .kpi { border-right: 0; min-height: 0; padding: 12px 14px; } .kpi .val { font-size: 1.7rem; } }

.cards { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; margin-top: 16px; }
@media (max-width: 800px) { .cards { grid-template-columns: 1fr; } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.card h3 { font-size: 1rem; margin-bottom: 6px; }
.card .kv { display: grid; grid-template-columns: 90px 1fr; gap: 3px 10px; font-size: .84rem; color: var(--ink-2); margin: 8px 0; }
.card .kv b { color: var(--ink); font-weight: 600; }
.card .links { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

/* ── 칩·섹션 머리 ───────────────────────────────────── */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 14px; }
.chip { border: 1px solid var(--line-2); background: var(--surface); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: .85rem; color: var(--ink-2); min-height: 32px; }
.chip.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-ink); font-weight: 700; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin: 22px 0 10px; }
.section-head h3 { font-size: 1rem; color: var(--brand-deep); }
.section-head .rule { flex: 1; height: 1px; background: var(--line-2); }
.section-head .n { font-size: .78rem; color: var(--ink-3); }

/* ── 모달(지표 변경) ────────────────────────────────── */
dialog.modal { border: 1px solid var(--line-2); border-radius: 12px; padding: 0; width: min(680px, 94vw); color: var(--ink); max-height: 92vh; }
dialog.modal::backdrop { background: rgba(11, 61, 56, .4); }
.modal .mhead { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal .mhead h3 { font-size: 1rem; }
.modal .mbody { padding: 14px 18px; display: grid; gap: 12px; overflow: auto; max-height: calc(92vh - 130px); }
.modal .mfoot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.field { display: grid; gap: 4px; }
.field > span { font-size: .8rem; color: var(--ink-2); font-weight: 600; }
.field select, .field input[type=text], .field textarea { font: inherit; font-size: .92rem; padding: 8px 10px; border: 1px solid var(--line-2); border-radius: var(--radius-s); background: var(--surface); color: var(--ink); width: 100%; min-height: 38px; }
.field .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.radio-row { display: flex; flex-wrap: wrap; gap: 6px; }
.radio-row label { border: 1px solid var(--line-2); border-radius: var(--radius-s); padding: 6px 10px; font-size: .85rem; cursor: pointer; min-height: 34px; display: inline-flex; align-items: center; }
.radio-row input { margin-right: 6px; }
.radio-row label:has(input:checked) { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }

/* ── 분석 빌더 ─────────────────────────────────────── */
.builder { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
.builder .form { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; position: sticky; top: 62px; }
.builder .result { display: grid; gap: 14px; }
@media (max-width: 960px) { .builder { grid-template-columns: 1fr; } .builder .form { position: static; } }

/* ── 보고서 ───────────────────────────────────────── */
.report-layout { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.report-side { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; position: sticky; top: 62px; }
@media (max-width: 960px) { .report-layout { grid-template-columns: 1fr; } .report-side { position: static; } }
.report-items { display: grid; gap: 6px; }
.report-item { display: flex; gap: 6px; align-items: center; border: 1px solid var(--line); border-radius: var(--radius-s); padding: 6px 8px; font-size: .84rem; background: var(--paper); }
.report-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.report-item .icon-btn { width: 28px; height: 28px; }
.sheet { background: #fff; border: 1px solid var(--line-2); width: 100%; max-width: 820px; margin: 0 auto; padding: 36px 40px; }
.sheet .cover { border-bottom: 2px solid var(--brand-deep); padding-bottom: 14px; margin-bottom: 18px; }
.sheet .cover h1 { font-size: 1.5rem; }
.sheet .cover .by { color: var(--ink-2); font-size: .9rem; margin-top: 4px; }
.sheet .fig { break-inside: avoid; page-break-inside: avoid; margin: 0 0 22px; }
.sheet .fig h3 { font-size: 1rem; margin-bottom: 2px; }
.sheet .fig .cap { font-size: .78rem; color: var(--ink-3); margin-bottom: 6px; }
.sheet .fig .chart { height: 300px; width: 100%; }
.sheet .fig .tbl { overflow-x: auto; }
.sheet table.data th, .sheet table.data td { white-space: normal; font-size: .76rem; padding: 3px 6px; }
.sheet .fig .memo { font-size: .88rem; color: var(--ink-2); border-left: 3px solid var(--brand-soft); padding: 4px 10px; margin-top: 8px; white-space: pre-wrap; }
.sheet .foot { border-top: 1px solid var(--line); margin-top: 20px; padding-top: 8px; font-size: .74rem; color: var(--ink-3); }
@media (max-width: 600px) { .sheet { padding: 20px 16px; } }

/* ── 데이터 안내 ──────────────────────────────────── */
.prose { max-width: 820px; font-size: .95rem; }
.prose h3 { font-size: 1.05rem; margin: 22px 0 8px; color: var(--brand-deep); }
.prose ul, .prose ol { padding-left: 20px; }
.prose li { margin: 3px 0; }
.prose code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: .86em; }
.prose table.data th, .prose table.data td { text-align: left; white-space: normal; }
.prose .table-wrap { overflow-x: auto; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--brand-deep); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: .86rem; z-index: 50; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; }
.loading { color: var(--ink-3); font-size: .9rem; padding: 30px; text-align: center; }
.error { color: var(--danger); background: #fdecea; border: 1px solid #f5c6c2; padding: 10px 12px; border-radius: var(--radius-s); font-size: .88rem; }

/* ── 휴대폰 ───────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --gutter: 14px; }
  html { font-size: 14.5px; }
  .masthead .wrap { grid-template-columns: 1fr; gap: 4px; padding-top: 12px; }
  .masthead .title { font-size: 1.15rem; }
  .masthead .title small { font-size: .74rem; }
  .masthead .meta { text-align: left; font-size: .72rem; }
  .masthead .meta br { display: none; }
  .masthead .meta .badge { margin: 4px 0 0; }
  .tabs a { padding: 9px 11px; font-size: .86rem; }
  .subbar .wrap { gap: 6px 8px; }
  .subtabs { width: 100%; overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; padding-bottom: 2px; }
  .subtabs::-webkit-scrollbar { display: none; }
  .subtabs button { white-space: nowrap; }
  .btn.filter-toggle { display: inline-flex; }
  .filters { display: none; width: 100%; margin-left: 0; padding-top: 4px; }
  .filters.open { display: flex; }
  .filters .label { display: none; }
  .fsel .menu { position: fixed; left: 10px; right: 10px; top: auto; bottom: 10px; max-height: 60vh; min-width: 0; z-index: 60; }
  .page-head h2 { font-size: 1.08rem; }
  .page-head .right { width: 100%; margin-left: 0; }
  .panel { min-height: 0; }
  .panel header { flex-wrap: wrap; padding: 10px 12px 4px; }
  .panel header .acts { order: 3; width: 100%; justify-content: flex-end; border: 0; border-top: 1px dashed var(--line); border-radius: 0; margin-top: 6px; padding-top: 2px; }
  .icon-btn { width: 38px; height: 36px; }
  .panel .body { padding: 0 2px; }
  .panel .chart { min-height: 220px; }
  .panel footer { font-size: .7rem; }
  .cards { margin-top: 12px; }
  .card { padding: 14px; }
  .card .kv { grid-template-columns: 70px 1fr; }
  dialog.modal { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; border-radius: 0; border: 0; margin: 0; }
  .modal .mbody { max-height: calc(100dvh - 128px); }
  .field .row { grid-template-columns: 1fr; }
  .section-head { margin: 18px 0 8px; }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; scroll-behavior: auto !important; } }
