:root {
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --panel-strong: #eef4f8;
  --ink: #172033;
  --muted: #657084;
  --line: #dbe3ec;
  --line-strong: #c7d2df;
  --nav: #111b29;
  --nav-2: #172537;
  --teal: #0f766e;
  --brand-dark: #0f4b61;
  --teal-soft: #dff6f2;
  --blue: #2563eb;
  --blue-soft: #e8efff;
  --green: #15803d;
  --green-soft: #e5f6ec;
  --amber: #b45309;
  --amber-soft: #fff3dd;
  --red: #be123c;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Pretendard", "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  line-height: 1.6;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.3);
  outline-offset: 2px;
}

a {
  color: inherit;
}

::selection {
  background: rgba(37, 99, 235, 0.18);
}

.app-shell {
  display: grid;
  grid-template-columns: 376px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 22px 18px 18px;
  background: var(--nav);
  color: #fff;
  overflow: hidden;
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.08);
}

.brand {
  display: grid;
  gap: 4px;
  padding: 0 4px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.brand span,
.label {
  color: var(--teal);
  font-size: 12px;
  font-weight: 900;
}

.brand span {
  color: #8ee7dc;
}

.brand strong {
  font-size: 28px;
  line-height: 1.12;
  letter-spacing: 0;
}

.search-box {
  display: grid;
  gap: 7px;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
  font-weight: 800;
}

.search-box input {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  padding: 12px 13px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  outline: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.search-box input::placeholder {
  color: rgba(255, 255, 255, 0.48);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  padding: 8px 11px;
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.86);
  cursor: pointer;
}

.filter-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.filter-btn.is-active {
  background: #fff;
  color: var(--nav);
  border-color: #fff;
}

.count-line {
  padding: 0 2px;
  color: rgba(255, 255, 255, 0.64);
  font-size: 13px;
}

.toc {
  min-height: 0;
  overflow-y: auto;
  padding-right: 5px;
}

.toc::-webkit-scrollbar,
.source-text::-webkit-scrollbar,
.current-rule .legal-text::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.toc::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.24);
  border-radius: 999px;
}

.source-text::-webkit-scrollbar-thumb,
.current-rule .legal-text::-webkit-scrollbar-thumb {
  background: #c9d3df;
  border-radius: 999px;
}

.toc a {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  margin-bottom: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.055);
  color: #fff;
  text-decoration: none;
}

.toc a:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.24);
}

.toc a.is-current {
  border-color: rgba(142, 231, 220, 0.72);
  background: rgba(15, 118, 110, 0.28);
}

.toc a.is-hidden {
  display: none;
}

.toc strong {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.38;
}

.toc span {
  border-radius: 999px;
  padding: 2px 7px;
  background: rgba(142, 231, 220, 0.13);
  color: #a9eee5;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.document {
  min-width: 0;
  padding: 28px;
}

.doc-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: end;
  max-width: 1500px;
  margin: 0 auto 16px;
}

.doc-header h1 {
  margin: 5px 0 0;
  font-size: clamp(30px, 3vw, 44px);
  line-height: 1.16;
  letter-spacing: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(96px, 1fr));
  gap: 10px;
}

.metrics div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel);
  box-shadow: var(--shadow-sm);
}

.metrics strong,
.metrics span {
  display: block;
}

.metrics strong {
  font-size: 27px;
  line-height: 1.05;
}

.metrics span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.doc-actions {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1500px;
  margin: 0 auto 18px;
  padding: 11px 0;
  background: rgba(245, 247, 250, 0.94);
  backdrop-filter: blur(10px);
}

.doc-actions a {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  background: var(--panel);
  color: var(--brand-dark);
  text-decoration: none;
  font-size: 14px;
  font-weight: 900;
  box-shadow: var(--shadow-sm);
}

.doc-actions a:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.view-toolbar {
  position: sticky;
  top: 51px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1500px;
  margin: -4px auto 18px;
  padding: 9px 0 12px;
  background: rgba(245, 247, 250, 0.94);
  backdrop-filter: blur(10px);
}

.view-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff;
  color: #2a3548;
  font-weight: 900;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.view-btn:hover {
  border-color: var(--teal);
  color: var(--teal);
}

.view-btn.is-active {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.rule-stack,
.source-section {
  max-width: 1500px;
  margin: 0 auto;
}

.rule-pair {
  margin-bottom: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.rule-pair:target {
  border-color: rgba(37, 99, 235, 0.45);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.11), var(--shadow-md);
}

.rule-pair.is-hidden {
  display: none;
}

.rule-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: start;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.review-panel {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.review-panel div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
}

.review-panel span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.review-panel strong {
  display: block;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
}

.review-panel .legal-basis,
.review-panel .source-basis {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.legal-basis a,
.source-basis span {
  border: 1px solid #b7d8f8;
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--blue-soft);
  color: #1d4ed8;
  text-decoration: none;
  font-size: 12px;
  font-weight: 900;
}

.source-basis span {
  border-color: var(--line);
  background: var(--panel-soft);
  color: #40516a;
}

.rule-head h2 {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  font-size: clamp(23px, 2vw, 31px);
  line-height: 1.25;
  letter-spacing: 0;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  width: max-content;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: var(--panel-soft);
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}

.badge.new {
  border-color: #b9ead2;
  background: var(--green-soft);
  color: var(--green);
}

.badge.rewrite {
  border-color: #f4d4a2;
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.keep {
  background: #eef3f8;
  color: #40516a;
}

.copy-link {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 9px;
  background: #fff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  cursor: pointer;
}

.copy-link:hover {
  border-color: var(--blue);
  background: var(--blue-soft);
}

.rule-columns {
  display: grid;
  grid-template-columns: minmax(0, 0.96fr) minmax(0, 1.04fr);
}

body[data-view="new"] .rule-column.current,
body[data-view="current"] .rule-column.proposed,
body[data-view="summary"] .rule-columns {
  display: none;
}

body[data-view="new"] .rule-columns,
body[data-view="current"] .rule-columns {
  grid-template-columns: minmax(0, 1fr);
}

body[data-view="new"] .rule-column.proposed,
body[data-view="current"] .rule-column.current {
  border-right: 0;
  border-bottom: 0;
}

body[data-view="new"] .compare-summary,
body[data-view="current"] .compare-summary {
  display: none;
}

.rule-column {
  min-width: 0;
  padding: 18px;
}

.rule-column.current {
  border-right: 1px solid var(--line);
  background: var(--panel-soft);
}

.rule-column.proposed {
  background: #fff;
}

.column-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--brand-dark);
  font-size: 15px;
  font-weight: 900;
}

.column-title::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--teal);
}

.current-rule {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.current-rule h4 {
  margin: 0;
  padding: 11px 13px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-strong);
  color: var(--brand-dark);
  font-size: 14px;
  font-weight: 900;
}

.empty-current {
  margin: 0;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  padding: 14px;
  color: var(--muted);
  background: #fff;
}

.legal-text {
  overflow-wrap: anywhere;
  font-size: 14px;
  line-height: 1.76;
}

.current-rule .legal-text {
  max-height: 540px;
  overflow: auto;
  padding: 14px 16px;
}

.new-rule-text {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  background: #fff;
  box-shadow: var(--shadow-sm);
}

.legal-text h4,
.legal-text h5,
.legal-text h6,
.legal-text p,
.rich-text h4,
.rich-text h5,
.rich-text h6,
.rich-text p {
  margin: 0;
}

.legal-text h4,
.rich-text h4 {
  margin: 10px 0 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  font-size: 21px;
  line-height: 1.35;
}

.legal-text h5,
.rich-text h5 {
  margin: 20px 0 8px;
  padding: 7px 10px;
  border-left: 3px solid var(--teal);
  border-radius: 6px;
  background: var(--teal-soft);
  color: var(--brand-dark);
  font-size: 16px;
}

.legal-text h6,
.rich-text h6 {
  margin: 16px 0 7px;
  color: var(--ink);
  font-size: 15px;
  font-weight: 900;
}

.legal-text p,
.rich-text p {
  margin-bottom: 7px;
  color: #273245;
}

.legal-text .legal-list,
.rich-text .legal-list {
  padding-left: 12px;
  color: #354156;
}

.legal-text hr,
.rich-text hr {
  height: 1px;
  margin: 18px 0;
  border: 0;
  background: var(--line);
}

.legal-text blockquote,
.rich-text blockquote {
  margin: 12px 0;
  padding: 10px 12px;
  border-left: 3px solid var(--blue);
  border-radius: 6px;
  background: var(--blue-soft);
  color: #24324a;
}

.legal-text code,
.rich-text code {
  border-radius: 5px;
  padding: 1px 5px;
  background: #eef2f7;
  color: #24324a;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 0.92em;
}

.doc-table-wrap {
  width: 100%;
  margin: 12px 0 16px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.doc-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 13px;
  line-height: 1.5;
}

.doc-table th,
.doc-table td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 9px 10px;
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.doc-table th:last-child,
.doc-table td:last-child {
  border-right: 0;
}

.doc-table tr:last-child td {
  border-bottom: 0;
}

.doc-table th {
  background: var(--panel-strong);
  color: var(--brand-dark);
  font-weight: 900;
}

.compare-summary {
  padding: 0 18px 18px;
  background: #fff;
}

.compare-summary .column-title {
  margin-top: 0;
}

.compare-table {
  min-width: 760px;
}

mark {
  border-radius: 4px;
  padding: 0 2px;
  background: #fef08a;
  color: #1f2937;
}

.doc-table tbody tr:nth-child(even) td {
  background: #fbfcfe;
}

.source-section {
  margin-top: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.source-head {
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.source-head h2 {
  margin: 5px 0 0;
  font-size: 24px;
  line-height: 1.25;
}

.source-text {
  max-height: 760px;
  overflow: auto;
  margin: 0;
  padding: 18px 20px;
  background: #fff;
  color: #273245;
  overflow-wrap: anywhere;
  font-family: "Pretendard", "Noto Sans KR", "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.72;
}

.loading,
.error {
  max-width: 1500px;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  background: #fff;
  color: var(--muted);
  box-shadow: var(--shadow-sm);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    height: auto;
  }

  .toc {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    overflow: visible;
  }

  .toc a {
    margin-bottom: 0;
  }

  .doc-header,
  .rule-head,
  .rule-columns,
  .review-panel {
    grid-template-columns: minmax(0, 1fr);
  }

  .badges {
    justify-content: flex-start;
  }

  .rule-column.current {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .review-panel .legal-basis,
  .review-panel .source-basis {
    grid-column: auto;
  }
}

@media (max-width: 640px) {
  .document {
    padding: 14px;
  }

  .sidebar {
    padding: 16px;
  }

  .toc,
  .metrics {
    grid-template-columns: minmax(0, 1fr);
  }

  .doc-actions {
    position: static;
  }

  .view-toolbar {
    position: static;
  }

  .rule-head,
  .rule-column,
  .source-head {
    padding: 15px;
  }

  .new-rule-text,
  .current-rule .legal-text,
  .source-text {
    padding: 14px;
  }

  .source-text {
    max-height: none;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-shell {
    display: block;
  }

  .sidebar,
  .doc-actions,
  .view-toolbar {
    display: none;
  }

  .document {
    padding: 0;
  }

  .doc-header,
  .rule-stack,
  .source-section {
    max-width: none;
  }

  .metrics {
    display: none;
  }

  .rule-pair,
  .source-section {
    break-inside: avoid;
    box-shadow: none;
  }

  .current-rule .legal-text,
  .source-text {
    max-height: none;
    overflow: visible;
  }

  .rule-columns {
    grid-template-columns: 1fr 1fr;
  }

  .doc-table {
    min-width: 0;
  }
}
