:root {
  color-scheme: light;
  --bg: #f4f0eb;
  --panel: #ffffff;
  --panel-strong: #111111;
  --text: #171411;
  --muted: #776f66;
  --line: #ded6cd;
  --accent: #f47721;
  --accent-strong: #d75b07;
  --accent-soft: #fff0e4;
  --shadow: 0 24px 70px rgba(24, 17, 11, 0.12);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f0f10;
  --panel: #181818;
  --panel-strong: #f8f3ee;
  --text: #f4eee8;
  --muted: #aaa19a;
  --line: #302d2a;
  --accent: #ff8a2b;
  --accent-strong: #ff9d4d;
  --accent-soft: #2a1b10;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(244, 119, 33, 0.12), transparent 34rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.no-outline .app-shell {
  grid-template-columns: 260px minmax(0, 1fr);
}

.no-outline .outline-panel {
  display: none;
}

.sidebar,
.outline-panel {
  position: sticky;
  top: 24px;
  height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  box-shadow: var(--shadow);
}

.sidebar {
  border-radius: 8px;
  padding: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: var(--accent);
  color: #111;
  font-weight: 800;
}

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

.brand span,
.kicker,
.save-status,
.outline-nav a {
  color: var(--muted);
}

.section-nav {
  display: grid;
  gap: 8px;
  margin-top: 22px;
}

.section-nav button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 13px 14px;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 700;
}

.section-nav button:hover,
.section-nav button.active {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  background: var(--accent-soft);
}

.main-panel {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 78px;
  margin-bottom: 16px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 4.4rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.kicker {
  margin: 0 0 8px;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.topbar-actions,
.toolbar,
.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.icon-btn,
.toolbar button,
.upload-btn {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  background: var(--panel);
  color: var(--text);
  font-weight: 800;
}

.primary-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: #111;
}

.secondary-btn,
.ghost-btn {
  background: transparent;
}

.ghost-btn {
  width: 100%;
  margin-top: 16px;
}

.icon-btn {
  width: 42px;
  padding: 0;
}

.toolbar {
  position: sticky;
  top: 12px;
  z-index: 5;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.1);
}

.search-bar {
  display: none;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
}

.wetboek-page .search-bar {
  display: flex;
}

.search-bar input {
  flex: 1;
  min-width: 180px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--panel);
  color: var(--text);
}

.toolbar button,
.upload-btn {
  height: 36px;
  min-height: 36px;
}

.toolbar button.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}

.toolbar select {
  height: 36px;
  min-width: 132px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: var(--panel);
  color: var(--text);
  font-weight: 700;
}

#fontSize {
  min-width: 92px;
}

.underline {
  text-decoration: underline;
}

.divider {
  width: 1px;
  height: 28px;
  background: var(--line);
}

.upload-btn {
  display: inline-flex;
  align-items: center;
  position: relative;
}

.upload-btn input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.save-status {
  margin-left: auto;
  font-size: 0.85rem;
  font-weight: 700;
}

.document-page {
  min-height: calc(100vh - 156px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: clamp(28px, 5vw, 72px);
  background: var(--panel);
  box-shadow: var(--shadow);
  outline: none;
}

.document-page[contenteditable="true"] {
  caret-color: var(--accent);
}

.document-page :first-child {
  margin-top: 0;
}

.document-page h2 {
  margin: 2.3rem 0 1rem;
  padding-bottom: 0.55rem;
  border-bottom: 2px solid var(--accent);
  font-size: clamp(1.55rem, 2vw, 2.1rem);
  letter-spacing: 0;
}

.document-page h3 {
  margin: 1.8rem 0 0.65rem;
  font-size: 1.15rem;
  letter-spacing: 0;
}

.document-page .document-highlight {
  border-radius: 8px;
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: 0 0 0 8px color-mix(in srgb, var(--accent) 18%, transparent);
  transition: background 180ms ease, box-shadow 180ms ease;
}

.document-page .search-hit {
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 42%, #ffffff);
  color: #111;
  padding: 0 0.12em;
}

.document-page p,
.document-page li,
.document-page td,
.document-page th {
  font-size: 1rem;
  line-height: 1.78;
}

.document-page p:empty,
.document-page span:empty,
.document-page li:empty,
.document-page o\:p {
  display: none;
}

.document-page li > p {
  display: inline;
  margin: 0;
}

.document-page li > p + p {
  margin-left: 0.35rem;
}

.document-page ol,
.document-page ul {
  margin: 0.75rem 0 0.9rem 1.35rem;
  padding-left: 1.15rem;
}

.document-page li > ol,
.document-page li > ul {
  display: block;
  margin-top: 0.25rem;
  margin-bottom: 0.25rem;
}

.document-page li {
  margin: 0.12rem 0;
  padding-left: 0.2rem;
}

.document-page ol.alpha-list {
  margin-left: 2.75rem;
  margin-top: 0.35rem;
  margin-bottom: 0.35rem;
}

.document-page .manual-list-row {
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  column-gap: 0.55rem;
  align-items: start;
  margin: 0.18rem 0;
  line-height: 1.55;
}

.document-page .manual-list-level-1 {
  margin-left: 3rem;
}

.document-page .manual-list-marker {
  font-weight: 700;
  text-align: right;
  user-select: none;
}

.document-page .manual-list-content {
  display: block;
  min-width: 0;
}

.document-page .manual-list-content:empty::after {
  content: "\00a0";
}

.document-page .manual-list-content:empty {
  display: block;
}

.document-page .law-article-heading {
  margin-top: 2.3rem;
}

.document-page .law-row {
  display: grid;
  grid-template-columns: 2.4rem minmax(0, 1fr);
  column-gap: 0.6rem;
  align-items: start;
  margin: 0.22rem 0;
  line-height: 1.58;
}

.document-page .law-row-level-1 {
  margin-left: 1.35rem;
}

.document-page .law-row-marker {
  font-weight: 800;
  text-align: right;
  user-select: none;
}

.document-page .law-row-content {
  display: block;
  min-width: 0;
}

.document-page .law-row-content:empty::after {
  content: "\00a0";
}

.document-page .law-row-content:empty {
  display: block;
}

.document-page ol + ol,
.document-page ul + ul,
.document-page ol + ul,
.document-page ul + ol {
  margin-top: -0.25rem;
}

.document-page table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.25rem 0;
  border: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, var(--panel-strong) 8%);
}

.document-page th,
.document-page td {
  border: 1px solid var(--line);
  padding: 14px 16px;
  vertical-align: top;
}

.document-page th {
  background: color-mix(in srgb, var(--panel) 84%, var(--panel-strong) 16%);
  text-align: left;
  font-weight: 800;
}

.document-page .law-table thead th {
  font-style: italic;
  text-align: center;
}

.document-page .law-table tbody th {
  width: 28%;
}

.document-page .law-table td {
  text-align: center;
}

.document-page img {
  max-width: 100%;
  border-radius: 8px;
  margin: 1rem 0;
}

.outline-panel {
  border-radius: 8px;
  padding: 22px;
}

.outline-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.outline-nav {
  display: grid;
  gap: 8px;
  margin-top: 22px;
}

.outline-nav a {
  display: block;
  border-left: 3px solid transparent;
  padding: 8px 10px;
  text-decoration: none;
  line-height: 1.35;
}

.outline-nav a:hover {
  border-left-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}

.outline-nav .article-link {
  padding-left: 22px;
  font-size: 0.92rem;
}

.outline-nav .title-link {
  color: var(--text);
  font-weight: 800;
}

.modal {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.58);
}

.modal form {
  padding: 24px;
}

.modal h2 {
  margin: 0 0 8px;
}

.modal input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--bg);
  color: var(--text);
}

.error-text {
  min-height: 20px;
  color: #e74d3c;
  font-weight: 700;
}

body:not(.edit-mode) .editor-only {
  display: none;
}

body:not(.auth-mode) .auth-only {
  display: none;
}

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

  .outline-panel {
    display: none;
  }
}

@media (max-width: 780px) {
  .app-shell {
    display: block;
    padding: 12px;
  }

  .sidebar,
  .outline-panel {
    position: static;
    height: auto;
    margin-bottom: 14px;
  }

  .section-nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .document-page {
    min-height: 60vh;
    padding: 24px;
  }
}
