:root {
  --bg-primary: #ffffff;
  --bg-secondary: #f8f9fa;
  --bg-tertiary: #f1f3f5;
  --bg-hover: #e9ecef;
  --border: #dee2e6;
  --text-primary: #212529;
  --text-secondary: #6c757d;
  --text-muted: #adb5bd;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #eff6ff;
  --accent-border: #bfdbfe;
  --success: #16a34a;
  --checkbox-checked: #2563eb;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
}

[data-theme="dark"] {
  --bg-primary: #1c1c1e;
  --bg-secondary: #000000;
  --bg-tertiary: #2c2c2e;
  --bg-hover: #3a3a3c;
  --border: #38383a;
  --text-primary: #ffffff;
  --text-secondary: #ebebf599;
  --text-muted: #ebebf54d;
  --accent: #0a84ff;
  --accent-hover: #409cff;
  --accent-light: #0a84ff1a;
  --accent-border: #0a84ff33;
  --success: #30d158;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

input[type="text"], input[type="search"] { outline: none; }
input[type="text"]:focus, input[type="search"]:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.law-item { border: none; background: transparent; cursor: pointer; width: 100%; text-align: left; }
.law-item:hover { background: var(--bg-hover); }
.active-law { background: var(--accent-light) !important; }

.toc-item { cursor: pointer; }
.toc-item:hover { background: var(--bg-hover); }

.btn-active {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(37,99,235,0.3);
  cursor: pointer;
}
.btn-active:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-disabled { background: var(--bg-tertiary); color: var(--text-muted); cursor: not-allowed; }

.mobile-tab { color: var(--text-muted); background: transparent; border: none; cursor: pointer; }
.tab-active { color: var(--accent) !important; }

.law-text { font-family: Georgia, 'Times New Roman', serif; font-size: 15px; line-height: 1.7; }
.law-text p { margin-bottom: 0.8em; color: var(--text-primary); }
.law-text .paragraph-header { margin-bottom: 1em; padding-bottom: 0.5em; border-bottom: 1px solid var(--border); }
.law-text .paragraph-enbez { font-size: 1.4em; font-weight: 700; color: var(--text-primary); }
.law-text .paragraph-title { font-style: italic; color: var(--text-secondary); margin-top: 0.2em; }

/* Gesetzestext Aufzählungen (DL/DT/DD aus GII-XML) */
.law-text dl { margin: 0.5em 0; }
.law-text dt {
  display: inline;
  float: left;
  clear: left;
  min-width: 2.5em;
  font-weight: normal;
}
.law-text dd {
  margin-left: 2.5em;
  margin-bottom: 0.4em;
  padding-left: 0.3em;
}
.law-text dd::after { content: ""; display: block; clear: both; }
.law-text dd dl { margin-left: 0; }
.law-text dd dl dt { min-width: 2em; }
.law-text dd dl dd { margin-left: 2em; }

/* Nummerierte Listen */
.law-text ol { list-style: none; padding: 0; margin: 0.5em 0; }
.law-text ol li { display: flex; gap: 0.5em; margin-bottom: 0.4em; align-items: flex-start; }
.law-text ol li::before { min-width: 1.8em; flex-shrink: 0; }

/* Absatz-Nummern */
.law-text .absatz { display: flex; gap: 0.5em; margin-bottom: 0.6em; align-items: flex-start; }
.law-text .absatz-nr { min-width: 2em; flex-shrink: 0; color: var(--text-secondary); }

/* Inhaltsübersicht */
.io-container { font-size: 14px; line-height: 1.5; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.io-row {
  display: grid;
  grid-template-columns: 4.5em 1fr;
  gap: 0.5em;
  padding: 0.25em 0;
  border-bottom: 1px solid var(--border);
  align-items: baseline;
}
.io-nr { font-weight: 500; color: var(--text-primary); white-space: nowrap; }
.io-title { color: var(--text-primary); }
.io-section { margin-top: 1.2em; margin-bottom: 0.4em; padding-bottom: 0.3em; }
.io-section-type { display: block; font-size: 12px; color: var(--text-muted); font-weight: 400; }
.io-section-name { display: block; font-size: 14px; font-weight: 700; color: var(--text-primary); }
.io-section-standalone { margin-top: 1em; margin-bottom: 0.3em; font-size: 13px; font-weight: 600; color: var(--text-secondary); }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn 0.15s ease-out; }

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: block; }

.section-header {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.5rem 0.75rem 0.25rem;
  margin-top: 0.5rem;
}

/* TOC Abschnitts-Labels */
.toc-section-type {
  display: block;
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.3;
}
.toc-section-name {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-secondary);
  line-height: 1.3;
}

.toc-para-row { cursor: pointer; }
.toc-para-row:hover { background: var(--bg-hover); }
.toc-para-row.active { background: var(--accent-light); }
.toc-section-block > .flex:first-child { background: var(--bg-secondary); }

.toc-para-row input[type="checkbox"] {
  flex-shrink: 0;
  align-self: center;
  margin-top: 0;
}

.para-grid {
  display: grid;
  grid-template-columns: 5.5em 1fr;
  gap: 0.5em;
  align-items: center;
}
.para-grid span:first-child { font-size: 13px; font-weight: 600; align-self: center; }
.para-grid span:last-child { font-size: 13px; align-self: center; line-height: 1.4; }

.gesetz-tabelle {
  border-collapse: collapse;
  width: 100%;
  margin: 0.8em 0;
  font-size: 13px;
  table-layout: fixed;
}
.gesetz-tabelle td, .gesetz-tabelle th {
  border: 1px solid var(--border);
  padding: 0.4em 0.6em;
  text-align: left;
  vertical-align: top;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  hyphens: auto;
  -webkit-hyphens: auto;
}
.gesetz-tabelle td.cell-short, .gesetz-tabelle th.cell-short {
  white-space: nowrap;
}
.gesetz-tabelle th {
  background: var(--bg-tertiary);
  font-weight: 600;
}
.gesetz-tabelle td:first-child,
.gesetz-tabelle th:first-child {
  hyphens: manual;
  -webkit-hyphens: manual;
}

.gesetz-bild {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0.5em 0;
  border: none;
  border-radius: 0;
}

.generate-btn { border: none; width: 100%; border-radius: 0.75rem; font-weight: 600; font-size: 0.875rem; padding: 0.75rem 1rem; transition: all 0.2s; }

.mustervordruck-hinweis {
  padding: 0.75em 1em;
  border-radius: 8px;
  border: 1px dashed var(--border);
  background: var(--bg-secondary);
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
  margin: 0.5em 0;
}

/* Gesetzestext: LA-Elemente in DD als Blöcke */
.law-text dd > span { display: block; }

/* Vorschau Abschnittsüberschriften */
.preview-section-header {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  padding-bottom: 0.4em;
  border-bottom: 1px solid var(--border);
}
.preview-section-header.depth-0 {
  margin-top: 2em;
  border-bottom: 2px solid var(--border);
}
.preview-section-type {
  display: block;
  font-size: 14px;
  color: var(--text-muted);
  font-weight: 500;
}
.preview-section-name {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}
.preview-section-header.depth-0 .preview-section-type { font-size: 15px; }
.preview-section-header.depth-0 .preview-section-name { font-size: 22px; }

/* Kommentarindikator */
mark .comment-indicator {
  display: inline-block;
  font-size: 0.65em;
  margin-left: 1px;
  vertical-align: super;
  cursor: help;
  color: inherit;
  opacity: 0.75;
  font-style: normal;
}
mark .comment-indicator:hover { opacity: 1; }

/* Inline-Kommentar nach Markierung */
.inline-comment {
  font-size: 0.85em;
  font-style: italic;
  color: var(--text-muted);
  cursor: default;
  user-select: none;
}
.inline-comment:hover { color: var(--accent); }

mark[data-note] {
  border-bottom: 2px dotted currentColor;
  cursor: help;
}

.comment-tooltip {
  position: fixed;
  z-index: 9999;
  max-width: 300px;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  background: var(--bg-primary);
  border: 1px solid var(--border);
  color: var(--text-primary);
}
.comment-tooltip.visible { opacity: 1; }
.comment-tooltip::before {
  content: '✎ Kommentar';
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 4px;
}

/* Vorschau Paragraph */
.preview-paragraph {
  margin-bottom: 1.5em;
  padding-bottom: 1.5em;
  border-bottom: 1px solid var(--border);
}
.preview-paragraph:last-child { border-bottom: none; }
.preview-para-header {
  display: flex;
  align-items: baseline;
  gap: 0.5em;
  margin-bottom: 0.2em;
}
.preview-enbez {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  flex-shrink: 0;
}
.preview-title {
  font-size: 14px;
  font-style: italic;
  color: var(--text-secondary);
  margin-top: 0;
  line-height: 1.2;
}
.preview-enbez + .preview-title { margin-top: -0.1em; }

/* Highlight-Toolbar Modi */
#text-panel.highlight-mode,
#text-panel.highlight-mode * {
  cursor: text !important;
}

.highlight-tool-btn.active {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  transform: scale(1.2);
}

#highlight-delete-btn.delete-active {
  background: #FF453A !important;
  color: white !important;
}

mark[data-highlight-id].deletable {
  cursor: pointer !important;
  filter: brightness(0.85);
}

mark[data-highlight-id].deletable:hover {
  filter: brightness(0.7);
  text-decoration: line-through;
}

.highlight-mode-active {
  cursor: text !important;
}

mark[data-color="none"] {
  background: transparent !important;
  border-bottom: 2px dotted var(--accent);
  padding: 1px 0;
  cursor: help;
}
mark[data-color="none"]:hover {
  background: var(--accent-light) !important;
}

#collections-list > div:hover {
  border-color: var(--accent-border) !important;
}

/* Flash-Animation beim Anspringen einer Markierung */
@keyframes highlightFlash {
  0%   { outline: 3px solid var(--accent); outline-offset: 2px; }
  50%  { outline: 3px solid var(--accent); outline-offset: 4px; }
  100% { outline: none; outline-offset: 0; }
}

mark.highlight-flash {
  animation: highlightFlash 1.5s ease-out forwards;
}

/* Resizable Column Dividers */
.col-resizer {
  width: 5px;
  flex-shrink: 0;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  z-index: 10;
  transition: background 0.15s;
}

.col-resizer:hover,
.col-resizer.dragging {
  background: var(--accent);
}

.col-resizer-handle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 3px;
  height: 32px;
  border-radius: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.15s;
}

.col-resizer:hover .col-resizer-handle,
.col-resizer.dragging .col-resizer-handle {
  opacity: 1;
}

body.col-resizing { user-select: none; cursor: col-resize !important; }
body.col-resizing * { cursor: col-resize !important; pointer-events: none; }
body.col-resizing .col-resizer { pointer-events: all !important; }

/* App-Seite: feste Höhe, kein Scroll (4-Spalten-Layout) */
body.app-page {
  height: 100vh;
  overflow: hidden;
}

/* Content-Seiten (/impressum, /datenschutz): normal scrollbar */
body.content-page {
  height: auto;
  min-height: 100vh;
  overflow-y: auto;
}

body.content-page > * {
  overflow: visible !important;
  height: auto !important;
  max-height: none !important;
}
