:root {
  color-scheme: light;
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-raised: #ffffff;
  --surface-subtle: #eeebe3;
  --ink: #14252d;
  --ink-soft: #53656b;
  --navy: #183547;
  --teal: #176f6b;
  --teal-soft: #dcece8;
  --amber-soft: #f6ead0;
  --line: #d9d6cd;
  --line-strong: #b9c1c0;
  --focus: #15807a;
  --danger: #9e3f39;
  --shadow: 0 16px 45px rgba(20, 37, 45, .08);
  --radius-lg: 18px;
  --radius-md: 11px;
  --font: "Pretendard", "Noto Sans KR", "Malgun Gothic", "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10191e;
  --surface: #17242a;
  --surface-raised: #1d2c33;
  --surface-subtle: #23343a;
  --ink: #edf4f1;
  --ink-soft: #aebfbe;
  --navy: #e6f0ef;
  --teal: #73c7bd;
  --teal-soft: #21443f;
  --amber-soft: #493d25;
  --line: #34464b;
  --line-strong: #53666a;
  --focus: #8bd6cd;
  --danger: #f0a39c;
  --shadow: 0 18px 52px rgba(0, 0, 0, .24);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); line-height: 1.6; }
button, input, select { font: inherit; }
button, select { cursor: pointer; }
a { color: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
[hidden] { display: none !important; }

.skip-link { position: fixed; top: 8px; left: 8px; z-index: 100; transform: translateY(-150%); padding: 9px 14px; border-radius: 8px; background: var(--navy); color: var(--surface); font-weight: 800; }
.skip-link:focus { transform: none; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.site-header { position: sticky; top: 0; z-index: 30; border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); }
.header-inner { width: min(1440px, calc(100% - 40px)); min-height: 68px; margin: 0 auto; display: flex; align-items: center; gap: 24px; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-size: .95rem; font-weight: 850; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: var(--navy); color: var(--surface); font-family: Georgia, serif; font-size: 1.12rem; }
.breadcrumbs { min-width: 0; display: flex; align-items: center; gap: 8px; color: var(--ink-soft); font-size: .82rem; overflow: hidden; }
.breadcrumbs a { text-underline-offset: 3px; }
.breadcrumbs strong { color: var(--ink); white-space: nowrap; }
.icon-button { margin-left: auto; display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-raised); color: var(--ink); font-size: .78rem; font-weight: 750; }
.theme-icon { font-size: 1rem; }

.page-shell { width: min(1440px, calc(100% - 40px)); margin: 0 auto; padding: 48px 0 64px; }
.intro { padding: 0 4px 30px; }
.eyebrow { margin: 0 0 7px; color: var(--teal); font-size: .69rem; font-weight: 900; letter-spacing: .16em; }
.intro-heading { display: flex; justify-content: space-between; gap: 40px; align-items: flex-end; }
h1, h2, h3, p { overflow-wrap: anywhere; }
h1 { margin: 0; color: var(--navy); font-size: clamp(2rem, 4vw, 3.7rem); line-height: 1.08; letter-spacing: -.055em; }
.lede { max-width: 650px; margin: 13px 0 0; color: var(--ink-soft); font-size: 1.04rem; }
.dataset-meta { margin: 0; display: grid; grid-template-columns: repeat(3, minmax(82px, auto)); border-top: 1px solid var(--line-strong); }
.dataset-meta div { padding: 12px 22px 0 0; }
.dataset-meta dt { color: var(--ink-soft); font-size: .7rem; font-weight: 800; }
.dataset-meta dd { margin: 1px 0 0; font-size: 1rem; font-weight: 850; }

.search-panel { display: grid; grid-template-columns: minmax(300px, 1fr) minmax(150px, 220px) auto; gap: 18px; align-items: end; margin-bottom: 18px; padding: 18px 20px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); }
.search-panel label, .search-panel legend, .section-picker label, .row-search-field label, .page-size-field { color: var(--ink-soft); font-size: .73rem; font-weight: 850; }
.search-field > label, .filter-field > label, .section-picker > label, .row-search-field > label { display: block; margin-bottom: 6px; }
.search-input-wrap { display: flex; align-items: center; min-height: 43px; padding: 0 11px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface-raised); }
.search-input-wrap:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 18%, transparent); }
.search-input-wrap > span { color: var(--ink-soft); font-size: 1.25rem; }
.search-input-wrap input { min-width: 0; width: 100%; border: 0; outline: 0; padding: 9px; background: transparent; color: var(--ink); }
.clear-search { width: 28px; height: 28px; border: 0; border-radius: 50%; background: var(--surface-subtle); color: var(--ink); font-size: 1.15rem; line-height: 1; }
.search-field p { margin: 4px 0 0; color: var(--ink-soft); font-size: .7rem; }
.filter-field select, .section-picker select, .page-size-field select { width: 100%; min-height: 43px; padding: 8px 34px 8px 11px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface-raised); color: var(--ink); }
.status-filters { min-width: 280px; margin: 0; padding: 0 0 7px; border: 0; display: flex; flex-wrap: wrap; gap: 9px 14px; }
.status-filters legend { margin-bottom: 7px; }
.status-filters label { display: inline-flex; gap: 6px; align-items: center; color: var(--ink); white-space: nowrap; }
.status-filters input { accent-color: var(--teal); width: 16px; height: 16px; }

.app-layout { display: grid; grid-template-columns: minmax(250px, 320px) minmax(0, 1fr); min-height: 620px; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow); overflow: clip; }
.library-sidebar { border-right: 1px solid var(--line); background: color-mix(in srgb, var(--surface-subtle) 54%, var(--surface)); }
.sidebar-heading { display: flex; justify-content: space-between; align-items: center; padding: 24px 22px 17px; border-bottom: 1px solid var(--line); }
.sidebar-heading h2 { margin: 0; color: var(--navy); font-size: 1.15rem; letter-spacing: -.02em; }
.result-count { display: grid; place-items: center; min-width: 28px; height: 28px; padding: 0 7px; border-radius: 999px; background: var(--navy); color: var(--surface); font-size: .75rem; font-weight: 900; }
.search-results-note { padding: 10px 18px; border-bottom: 1px solid var(--line); background: var(--teal-soft); color: var(--ink-soft); font-size: .75rem; }
.document-list { max-height: calc(100vh - 260px); min-height: 520px; overflow-y: auto; padding: 10px; }
.category-heading { margin: 17px 10px 7px; color: var(--ink-soft); font-size: .67rem; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.document-card { width: 100%; margin: 0 0 5px; padding: 13px 12px; border: 1px solid transparent; border-radius: 10px; background: transparent; color: var(--ink); text-align: left; transition: background .16s ease, border-color .16s ease, transform .16s ease; }
.document-card:hover { background: var(--surface-raised); border-color: var(--line); transform: translateX(2px); }
.document-card.is-active { background: var(--surface-raised); border-color: var(--teal); box-shadow: inset 3px 0 var(--teal); }
.document-card-title { display: flex; justify-content: space-between; gap: 10px; font-size: .85rem; font-weight: 850; }
.bookmark-star { color: var(--teal); }
.document-card-meta { display: flex; align-items: center; gap: 7px; margin-top: 5px; color: var(--ink-soft); font-size: .68rem; }
.document-card-snippet { margin: 8px 0 0; color: var(--ink-soft); font-size: .72rem; line-height: 1.45; }
mark { padding: 0 1px; background: var(--amber-soft); color: var(--ink); }

.document-view { min-width: 0; background: var(--surface-raised); scroll-margin-top: 76px; }
.state-panel { min-height: 620px; display: grid; align-content: center; justify-items: center; padding: 40px; text-align: center; }
.state-panel h2 { margin: 14px 0 4px; color: var(--navy); font-size: 1.3rem; }
.state-panel p { margin: 0 0 20px; color: var(--ink-soft); }
.spinner { width: 38px; height: 38px; border: 3px solid var(--line); border-top-color: var(--teal); border-radius: 50%; animation: spin .8s linear infinite; }
.state-symbol { display: grid; place-items: center; width: 42px; height: 42px; border: 1px solid var(--line-strong); border-radius: 50%; color: var(--teal); font-size: 1.25rem; font-weight: 900; }
@keyframes spin { to { transform: rotate(360deg); } }

.document-header { display: flex; justify-content: space-between; gap: 30px; padding: 34px 36px 28px; border-bottom: 1px solid var(--line); }
.document-title-group { min-width: 0; }
.badges, .tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.badge, .tag { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: .65rem; font-weight: 850; }
.badge { background: var(--teal-soft); color: var(--teal); }
.badge.status-reference { background: var(--amber-soft); color: var(--ink); }
.badge.status-archived { background: var(--surface-subtle); color: var(--ink-soft); }
.document-header h2 { margin: 10px 0 6px; color: var(--navy); font-size: clamp(1.5rem, 3vw, 2.2rem); line-height: 1.2; letter-spacing: -.035em; }
.document-header p { max-width: 770px; margin: 0; color: var(--ink-soft); }
.tag-list { margin-top: 14px; }
.tag { border: 1px solid var(--line); color: var(--ink-soft); }
.document-actions { flex: 0 0 auto; display: flex; flex-wrap: wrap; align-content: flex-start; justify-content: flex-end; gap: 8px; }
.primary-button, .secondary-button, .pagination button { min-height: 39px; padding: 8px 13px; border-radius: 9px; font-size: .76rem; font-weight: 850; }
.primary-button { border: 1px solid var(--navy); background: var(--navy); color: var(--surface); }
.secondary-button, .pagination button { border: 1px solid var(--line-strong); background: var(--surface-raised); color: var(--ink); }
.secondary-button[aria-pressed="true"] { border-color: var(--teal); background: var(--teal-soft); color: var(--teal); }

.section-toolbar { display: flex; align-items: end; gap: 20px; padding: 20px 36px; border-bottom: 1px solid var(--line); background: var(--surface); }
.section-picker { width: min(520px, 100%); }
.section-position { margin-left: auto; padding-bottom: 9px; color: var(--ink-soft); font-size: .75rem; }
.section-content { padding: 30px 36px 40px; }
.section-heading { display: flex; justify-content: space-between; gap: 16px; align-items: end; }
.section-heading h3 { margin: 0; color: var(--navy); font-size: 1.35rem; line-height: 1.25; letter-spacing: -.025em; }
.row-total { flex: 0 0 auto; color: var(--ink-soft); font-size: .75rem; }
.section-note { margin: 16px 0 0; padding: 12px 14px; border-left: 3px solid var(--teal); background: var(--teal-soft); color: var(--ink-soft); font-size: .82rem; }
.table-controls { display: flex; justify-content: space-between; align-items: end; gap: 18px; margin: 24px 0 12px; }
.row-search-field { width: min(390px, 100%); }
.row-search-field input { width: 100%; min-height: 39px; padding: 8px 11px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--surface-raised); color: var(--ink); }
.page-size-field { display: flex; gap: 8px; align-items: center; white-space: nowrap; }
.page-size-field select { width: 76px; min-height: 38px; }
.table-wrap { max-width: 100%; max-height: min(64vh, 720px); overflow: auto; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: separate; border-spacing: 0; color: var(--ink); font-size: .78rem; }
th, td { min-width: 128px; padding: 10px 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; white-space: pre-wrap; overflow-wrap: anywhere; }
th:last-child, td:last-child { border-right: 0; }
tbody tr:last-child td { border-bottom: 0; }
thead th { position: sticky; top: 0; z-index: 2; background: var(--navy); color: var(--surface); font-size: .72rem; font-weight: 850; }
.row-number { min-width: 66px; width: 66px; color: var(--ink-soft); text-align: right; font-variant-numeric: tabular-nums; }
thead .row-number { color: var(--surface); }
tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-subtle) 34%, var(--surface-raised)); }
tbody tr:hover td { background: var(--teal-soft); }
.table-empty { margin-top: 15px; padding: 28px; border: 1px dashed var(--line-strong); border-radius: 10px; color: var(--ink-soft); text-align: center; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 16px; }
.pagination button:disabled { opacity: .42; cursor: not-allowed; }
#pageStatus { min-width: 120px; color: var(--ink-soft); font-size: .75rem; text-align: center; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 50; max-width: min(360px, calc(100% - 32px)); padding: 12px 16px; border-radius: 10px; background: var(--navy); color: var(--surface); box-shadow: var(--shadow); font-size: .8rem; font-weight: 750; }
.noscript { margin: 20px; padding: 20px; background: var(--surface); color: var(--danger); }

@media (max-width: 900px) {
  .intro-heading { align-items: flex-start; flex-direction: column; gap: 24px; }
  .search-panel { grid-template-columns: minmax(0, 1fr) minmax(160px, 220px); }
  .status-filters { grid-column: 1 / -1; }
  .app-layout { grid-template-columns: 240px minmax(0, 1fr); }
  .document-header { flex-direction: column; }
  .document-actions { justify-content: flex-start; }
  .document-header, .section-toolbar, .section-content { padding-left: 24px; padding-right: 24px; }
}

@media (max-width: 680px) {
  .header-inner, .page-shell { width: min(100% - 24px, 1440px); }
  .header-inner { min-height: 62px; gap: 12px; }
  .brand > span:last-child { display: none; }
  .breadcrumbs { gap: 5px; font-size: .7rem; }
  .breadcrumbs span:nth-of-type(-n+4), .breadcrumbs a { display: none; }
  .theme-label { display: none; }
  .icon-button { padding: 7px 10px; }
  .page-shell { padding-top: 30px; }
  .intro { padding-bottom: 22px; }
  .dataset-meta { width: 100%; grid-template-columns: repeat(3, 1fr); }
  .dataset-meta div { padding-right: 8px; }
  .search-panel { grid-template-columns: 1fr; padding: 15px; }
  .status-filters { grid-column: auto; min-width: 0; }
  .app-layout { display: block; overflow: visible; }
  .library-sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .document-list { min-height: 0; max-height: 285px; }
  .state-panel { min-height: 420px; }
  .document-header, .section-toolbar, .section-content { padding-left: 18px; padding-right: 18px; }
  .document-header { padding-top: 26px; }
  .document-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .document-actions .primary-button { grid-column: 1 / -1; }
  .section-toolbar { align-items: stretch; flex-direction: column; gap: 7px; }
  .section-position { margin-left: 0; padding: 0; }
  .table-controls { align-items: stretch; flex-direction: column; }
  .page-size-field { justify-content: space-between; }
  .toast { right: 16px; bottom: 16px; }
}

@media (max-width: 380px) {
  .header-inner, .page-shell { width: min(100% - 16px, 1440px); }
  .breadcrumbs strong { max-width: 108px; overflow: hidden; text-overflow: ellipsis; }
  .status-filters { gap: 8px; }
  .document-header, .section-toolbar, .section-content { padding-left: 14px; padding-right: 14px; }
  .pagination { gap: 7px; }
  .pagination button { padding-left: 9px; padding-right: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media print {
  :root, [data-theme="dark"] { --surface-raised: #fff; --ink: #111; --ink-soft: #444; --navy: #152f3e; --line: #bbb; }
  body { background: #fff; }
  .site-header, .intro, .search-panel, .library-sidebar, .document-actions, .section-toolbar, .table-controls, .pagination, .toast { display: none !important; }
  .page-shell { width: 100%; padding: 0; }
  .app-layout { display: block; border: 0; box-shadow: none; }
  .document-header, .section-content { padding: 16px 0; }
  .table-wrap { max-height: none; overflow: visible; border-radius: 0; }
  table { font-size: 9pt; }
  thead th { position: static; background: #e9eeee; color: #111; }
  tr { break-inside: avoid; }
}
