:root {
  --bg: #eef6f7;
  --bg-deep: #d7ecef;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-solid: #f7fbfc;
  --ink: #17343a;
  --ink-soft: #4a6b72;
  --line: rgba(31, 111, 122, 0.14);
  --teal: #1f6f7a;
  --teal-bright: #2f8f86;
  --coral: #d96b4c;
  --danger: #b42318;
  --shadow: 0 8px 24px rgba(23, 52, 58, 0.08);
  --radius: 10px;
  --font: "Manrope", "Segoe UI", sans-serif;
  --display: "Syne", "Manrope", sans-serif;
  --max: 1180px;
  --topbar-h: 48px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 8% -20%, rgba(126, 200, 216, 0.35), transparent 55%),
    linear-gradient(180deg, #f4fbfc 0%, var(--bg) 50%, var(--bg-deep) 100%);
  line-height: 1.4;
  font-size: 14px;
}

a {
  color: var(--teal);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

code {
  font-size: 0.9em;
  background: rgba(31, 111, 122, 0.08);
  padding: 0.1em 0.3em;
  border-radius: 4px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.is-hidden {
  display: none !important;
}

.ambient {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
  opacity: 0.45;
}

.ambient__wave,
.ambient__caustic {
  display: none;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 clamp(0.75rem, 2vw, 1.25rem);
  backdrop-filter: blur(12px);
  background: rgba(247, 251, 252, 0.9);
  border-bottom: 1px solid var(--line);
}

.topbar__brand {
  font-family: var(--display);
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
  color: var(--teal);
  text-decoration: none;
  flex: 0 0 auto;
}

.topbar__meta {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.topbar__actions {
  margin-left: auto;
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  justify-content: flex-end;
  flex: 0 0 auto;
}

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-weight: 700;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn--primary {
  background: var(--teal);
  color: #fff;
}

.btn--primary:hover {
  background: #185860;
}

.btn--accent {
  background: var(--coral);
  color: #fff;
}

.btn--accent:hover {
  background: #c4573b;
}

.btn--ghost {
  background: rgba(255, 255, 255, 0.55);
  border-color: var(--line);
  color: var(--ink);
}

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

.btn--danger {
  background: rgba(180, 35, 24, 0.08);
  color: var(--danger);
  border-color: rgba(180, 35, 24, 0.2);
}

.btn--tiny {
  padding: 0.15rem 0.4rem;
  font-size: 0.7rem;
  border-radius: 6px;
}

main {
  position: relative;
  z-index: 1;
}

.toolbar {
  position: sticky;
  top: var(--topbar-h);
  z-index: 30;
  backdrop-filter: blur(12px);
  background: rgba(238, 246, 247, 0.92);
  border-bottom: 1px solid var(--line);
}

.toolbar__inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.45rem clamp(0.75rem, 2vw, 1.25rem);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.search-results {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0  clamp(0.75rem, 2vw, 1.25rem) 0.55rem;
}

.search-results__head {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--teal);
  margin-bottom: 0.35rem;
}

.search-results__empty,
.search-results__more {
  margin: 0;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.search-results__list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 220px;
  overflow: auto;
  padding-right: 0.15rem;
}

.search-results__item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.55rem;
  align-items: baseline;
  width: 100%;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  padding: 0.4rem 0.55rem;
  font: inherit;
  cursor: pointer;
  color: var(--ink);
}

.search-results__item:hover {
  border-color: var(--teal);
  background: rgba(31, 111, 122, 0.08);
}

.search-results__path {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--teal);
  white-space: nowrap;
}

.search-results__title {
  font-size: 0.84rem;
  font-weight: 600;
}

.tree-section.is-collapsed .tree-section__body {
  display: none;
}

.tree-section__head {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  width: 100%;
  padding: 0.45rem 0.65rem;
  background: linear-gradient(90deg, rgba(31, 111, 122, 0.1), rgba(126, 200, 216, 0.06));
  border: 0;
  border-bottom: 1px solid transparent;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.tree-section.is-open .tree-section__head {
  border-bottom-color: var(--line);
}

.tree-section__chevron {
  margin-left: auto;
  color: var(--ink-soft);
  font-size: 0.72rem;
  flex: 0 0 auto;
}

.tree-section.is-open {
  box-shadow: 0 0 0 1px rgba(31, 111, 122, 0.18);
}

.node.is-flash,
.tree-section.is-flash {
  animation: flash-hit 1.8s ease;
}

.node.is-flash > .node__row {
  background: rgba(246, 201, 106, 0.45);
  border-radius: 6px;
}

@keyframes flash-hit {
  0%, 100% { box-shadow: none; }
  20%, 55% { box-shadow: 0 0 0 2px rgba(217, 107, 76, 0.45); }
}

.search {
  flex: 1 1 220px;
}

.search input {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  outline: none;
}

.search input:focus {
  border-color: var(--teal-bright);
  box-shadow: 0 0 0 2px rgba(47, 143, 134, 0.16);
}

.toolbar__stats {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 600;
}

.layout {
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.75rem clamp(0.75rem, 2vw, 1.25rem) 2rem;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 0.85rem;
  align-items: start;
}

.toc {
  position: sticky;
  top: calc(var(--topbar-h) + 46px);
  max-height: calc(100vh - var(--topbar-h) - 60px);
  overflow: auto;
  padding: 0.55rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  backdrop-filter: blur(8px);
}

.toc__title {
  margin: 0 0 0.35rem;
  font-family: var(--display);
  font-size: 0.8rem;
}

.toc__nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.toc__link {
  display: block;
  padding: 0.28rem 0.4rem;
  border-radius: 6px;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
}

.toc__link:hover,
.toc__link.is-active {
  background: rgba(31, 111, 122, 0.1);
  color: var(--teal);
}

.content {
  min-width: 0;
}

.edit-bar {
  margin-bottom: 0.65rem;
  padding: 0.65rem 0.75rem;
  border: 1px dashed rgba(217, 107, 76, 0.45);
  border-radius: var(--radius);
  background: rgba(246, 231, 200, 0.4);
}

.edit-bar__row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: space-between;
  align-items: flex-start;
}

.edit-bar__hint {
  margin: 0;
  flex: 1 1 200px;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.edit-bar__buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.edit-bar__status {
  margin: 0.4rem 0 0;
  min-height: 1em;
  font-size: 0.78rem;
  color: var(--teal);
  font-weight: 600;
}

.catalog {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.tree-section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-solid);
  overflow: hidden;
  scroll-margin-top: calc(var(--topbar-h) + 56px);
}

.tree-section__num {
  flex: 0 0 auto;
  min-width: 1.45rem;
  height: 1.45rem;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  font-size: 0.72rem;
}

.tree-section__title {
  margin: 0;
  flex: 1;
  font-family: var(--display);
  font-size: 0.98rem;
  letter-spacing: -0.02em;
}

.tree-section__body {
  padding: 0.15rem 0.3rem 0.35rem;
}

.node {
  margin: 0;
  border-radius: 6px;
  scroll-margin-top: calc(var(--topbar-h) + 120px);
}

.node.is-filtered-out {
  display: none;
}

.node__row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 0.2rem;
  align-items: center;
  padding: 0.15rem 0.25rem;
  border-radius: 6px;
  min-height: 1.7rem;
}

.node__row:hover {
  background: rgba(31, 111, 122, 0.05);
}

.node.is-match > .node__row {
  background: rgba(246, 201, 106, 0.28);
}

.node__toggle {
  width: 1.35rem;
  height: 1.35rem;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 0.7rem;
  line-height: 1;
  padding: 0;
}

.node__toggle:disabled {
  opacity: 0.25;
  cursor: default;
}

.node__label {
  min-width: 0;
  font-weight: 600;
  color: var(--ink);
  font-size: 0.88rem;
}

.node--l1 > .node__row .node__label {
  font-size: 0.9rem;
  color: var(--teal);
}

.node--l2 > .node__row .node__label {
  font-weight: 700;
}

.node--leaf > .node__row .node__label {
  font-weight: 500;
  color: var(--ink-soft);
}

.node__num {
  color: var(--ink-soft);
  font-weight: 700;
  font-size: 0.72rem;
  margin-right: 0.3rem;
}

.node__children {
  margin-left: 0.7rem;
  padding-left: 0.4rem;
  border-left: 1px solid rgba(31, 111, 122, 0.12);
}

.node.is-collapsed > .node__children {
  display: none;
}

.node__actions {
  display: none;
  gap: 0.15rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

body.is-editing .node__actions {
  display: flex;
}

body.is-editing .node__label-input,
body.is-editing .section-title-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  font: inherit;
  font-size: 0.88rem;
  background: #fff;
}

.footer {
  position: relative;
  z-index: 1;
  max-width: var(--max);
  margin: 0 auto;
  padding: 0.85rem clamp(0.75rem, 2vw, 1.25rem) 1.5rem;
  color: var(--ink-soft);
  font-size: 0.78rem;
  border-top: 1px solid var(--line);
}

.footer p {
  margin: 0;
}

.footer__note {
  margin-top: 0.25rem;
}

.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: calc(100vw - 2rem);
}

.history-modal {
  max-width: min(760px, calc(100vw - 2rem));
  width: min(760px, calc(100vw - 2rem));
}

.modal::backdrop {
  background: rgba(23, 52, 58, 0.45);
  backdrop-filter: blur(4px);
}

.modal__panel {
  width: min(400px, 100%);
  margin: auto;
  padding: 1rem;
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal__panel h2 {
  margin: 0 0 0.4rem;
  font-family: var(--display);
  font-size: 1.1rem;
}

.modal__panel p {
  margin: 0 0 0.75rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
  font-weight: 600;
  font-size: 0.85rem;
}

.field input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.5rem 0.65rem;
  font: inherit;
}

.modal__actions {
  display: flex;
  gap: 0.4rem;
}

.modal__error {
  color: var(--danger);
  font-size: 0.82rem;
  margin: -0.3rem 0 0.6rem;
}

.toast {
  position: fixed;
  right: 0.75rem;
  bottom: 0.75rem;
  z-index: 60;
  max-width: min(320px, calc(100vw - 1.5rem));
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: var(--ink);
  color: #fff;
  font-weight: 600;
  font-size: 0.82rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-show {
  opacity: 1;
  transform: translateY(0);
}

.history-modal__panel {
  width: min(720px, 100%);
  max-height: min(80vh, 720px);
  display: flex;
  flex-direction: column;
  margin: auto;
  padding: 1rem;
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow);
}

.history-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.history-modal__head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.1rem;
}

.history-modal__lead {
  margin: 0 0 0.75rem;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.history-list--modal {
  max-height: none;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 120px;
}

.edit-bar__note {
  margin-top: 0.55rem;
  margin-bottom: 0;
}

.edit-bar__note input {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font: inherit;
  background: #fff;
}

.pending-changes {
  margin-top: 0.55rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
}

.pending-changes__empty {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.8rem;
}

.pending-changes__head {
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
}

.history-empty {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.82rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  padding: 0.35rem 0.45rem;
}

.history-item.is-open {
  border-color: rgba(31, 111, 122, 0.35);
}

.history-item__toggle {
  width: 100%;
  display: grid;
  grid-template-columns: minmax(120px, auto) 1fr auto;
  gap: 0.45rem;
  align-items: center;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: var(--ink);
  padding: 0.15rem;
}

.history-item__when {
  font-weight: 700;
  font-size: 0.78rem;
  color: var(--teal);
}

.history-item__summary {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.history-item__chevron {
  font-size: 0.7rem;
  color: var(--ink-soft);
}

.history-item__note {
  margin: 0.25rem 0.15rem 0.35rem;
  font-size: 0.8rem;
  color: var(--ink);
}

.history-item__details {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--line);
}

.change-group {
  margin-bottom: 0.4rem;
}

.change-group h4 {
  margin: 0 0 0.2rem;
  font-size: 0.78rem;
  color: var(--teal);
}

.change-group ul {
  margin: 0;
  padding-left: 1.1rem;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.change-group li {
  margin: 0.1rem 0;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .toc {
    position: static;
    max-height: none;
  }

  .topbar__meta {
    display: none;
  }

  .history-item__toggle {
    grid-template-columns: 1fr auto;
  }

  .history-item__when {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    min-height: var(--topbar-h);
    flex-wrap: wrap;
    padding-block: 0.4rem;
  }

  .node__children {
    margin-left: 0.4rem;
  }
}

@media print {
  .ambient,
  .topbar,
  .toolbar,
  .toc,
  .edit-bar,
  .btn {
    display: none !important;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 0;
  }

  .node.is-collapsed > .node__children {
    display: block !important;
  }

  .tree-section {
    break-inside: avoid;
  }
}
