:root {
  --form: #2D6A4F;
  --form-light: #D8F3DC;
  --form-mid: #95D5B2;
  --inhalt: #1D3557;
  --inhalt-light: #D4E4F7;
  --inhalt-mid: #A8CAEE;
  --prozess: #7B2D8B;
  --prozess-light: #F0DBF5;
  --prozess-mid: #D4A5DF;
  --verfahren: #C65D07;
  --verfahren-light: #FDE8D0;
  --verfahren-mid: #F5C28A;
  --bg: #FAFAF7;
  --text: #2C2C2C;
  --text-light: #666;
  --border: #E0DDD5;
  --white: #FFFFFF;
  --check-green: #40916C;
  --color-none: #E8E5DC;
  --color-none-light: #FDFCFB;
  --color-summary: #FFF3BF;
  --color-summary-light: #FFFEF9;
  --color-exemplary: #FFE066;
  --color-exemplary-light: #FFFCF0;
  --color-accountable: #F4A236;
  --color-accountable-light: #FEF6EB;
  --color-forbidden: #D62828;
  --color-forbidden-light: #FDEAEA;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 1140px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
}

.container > * {
  margin-bottom: 2rem;
}

header {
  text-align: center;
}

header h1 {
  font-family: 'Source Serif 4', serif;
  font-weight: 700;
  font-size: 2rem;
  color: var(--text);
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

header .subtitle {
  font-size: 1.05rem;
  color: var(--text-light);
  max-width: 680px;
  margin: 0 auto;
  line-height: 1.6;
}

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  justify-content: center;
  padding: 1rem 1.5rem;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.legend-title {
  width: 100%;
  text-align: center;
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-light);
  margin-bottom: 0.25rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text);
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: #6b7280;
  cursor: help;
}

.legend-item:hover .tooltip,
.legend-item:focus .tooltip {
  opacity: 1;
  visibility: visible;
}

.legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.info-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid #777;

  background: white;
  color: #555;
  font-size: 12px;
  font-weight: bold;
  font-family: Arial, sans-serif;

  cursor: help;
}

.tooltip {
  position: absolute;
  bottom: 130%;
  left: 50%;
  transform: translateX(-50%) translateY(-4px);

  width: max-content;
  max-width: 220px;
  padding: 8px 10px;
  border-radius: 6px;

  background: #111827;
  color: white;
  font-size: 13px;
  font-weight: normal;
  line-height: 1.4;

  opacity: 0;
  visibility: hidden;
  pointer-events: none;

  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 10;
}

.tooltip::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);

  border-width: 6px;
  border-style: solid;
  border-color: #111827 transparent transparent transparent;
}

/* Grid */
.raster {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.ebene {
  background: var(--white);
  border-radius: 12px;
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: box-shadow 0.2s;
}

.ebene:hover {
  box-shadow: 0 4px 16px rgba(0,0,0,0.07);
}

.ebene-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.5rem;
  cursor: pointer;
  user-select: none;
}

.ebene-label {
  font-family: 'Source Serif 4', serif;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--white);
  background: var(--ebene-color);
  padding: 0.3rem 1rem;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.ebene-desc {
  font-size: 0.92rem;
  color: var(--text-light);
  flex: 1;
}

.ebene-toggle {
  font-size: 1.2rem;
  color: var(--text-light);
  transition: transform 0.25s;
  flex-shrink: 0;
}

.ebene details:open .ebene-toggle {
  transform: rotate(180deg);
}

.ebene-body {
  overflow: hidden;
}

/* Header rows */
.header-grid {
  padding: 0 1.5rem 1.5rem;
}

.header-row{
  display: grid;
  grid-template-columns: 1fr 4fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.header-row:last-child {
  margin-bottom: 0;
}

.header-row label {
  padding: 0.9rem 1.1rem;
  font-weight: 600;
  background: #EEEEEE;
  border-right: 1px solid var(--border);
}

.header-row input {
  padding: 0.9rem 1.1rem;
  font-size: 0.82rem;
  color: var(--text-light);
  border: none;
}

.header-row input:focus {
  outline: none;
}

/* Category rows */
.category-grid {
  padding: 0 1.5rem 1.5rem;
}

.category-row-and-button {
  position: relative;
}

.category-grid button {
  margin-bottom: 0.75rem;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 2px;
}

.category-grid button.add-category {
  padding: 0 10px;
  height: 1.5rem;
  background: var(--bg);
  font-size: 18px;
  color: var(--text);
  vertical-align: middle;
}

.category-row-and-button button.remove-category {
  position: absolute;
  top: 5px;
  left: 5px;
  margin: 0;
  width: 0.8rem;
  height: 0.8rem;
  background: var(--bg);
  font-size: 8px;
  color: var(--text);
  vertical-align: middle;
}

.category-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 0.75rem;
}

.category-row:last-child {
  margin-bottom: 0;
}

.category-info {
  padding: 0.9rem 1.1rem;
  background: var(--ebene-light);
  border-right: 1px solid var(--border);
}

.category-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.category-desc {
  font-size: 0.82rem;
  color: var(--text-light);
  line-height: 1.45;
}

.category-doku {
  display: flex;
  align-items: stretch;
}

.doku-option {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 0.3rem;
  border-right: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.doku-option:nth-last-child(2) {
  border-right-color: var(--color-forbidden);
}

.doku-option:last-child {
  border-right: none;
}

.doku-option:hover {
  background: #f5f5f0;
}

.doku-option.selected {
  background: var(--ebene-light);
}

.doku-option.selected[data-opt="none"] {
  background: var(--color-none-light);
}

.doku-option.selected[data-opt="summary"] {
  background: var(--color-summary-light);
}

.doku-option.selected[data-opt="exemplary"] {
  background: var(--color-exemplary-light);
}

.doku-option.selected[data-opt="accountable"] {
  background: var(--color-accountable-light);
}

.doku-option.selected[data-opt="forbidden"] {
  background: var(--color-forbidden-light);
}

.doku-circle {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.3rem;
  transition: all 0.15s;
}

.doku-option.selected .doku-circle {
  border-color: var(--ebene-color);
  background: var(--ebene-color);
}

.doku-option.selected[data-opt="none"] .doku-circle {
  border-color: var(--color-none);
  background: var(--color-none);
}

.doku-option.selected[data-opt="summary"] .doku-circle {
  border-color: var(--color-summary);
  background: var(--color-summary);
}

.doku-option.selected[data-opt="exemplary"] .doku-circle {
  border-color: var(--color-exemplary);
  background: var(--color-exemplary);
}

.doku-option.selected[data-opt="accountable"] .doku-circle {
  border-color: var(--color-accountable);
  background: var(--color-accountable);
}

.doku-option.selected[data-opt="forbidden"] .doku-circle {
  border-color: var(--color-forbidden);
  background: var(--color-forbidden);
}

.doku-circle svg {
  width: 12px;
  height: 12px;
  opacity: 0;
  transition: opacity 0.15s;
}

.doku-option.selected .doku-circle svg {
  opacity: 1;
}

.doku-label {
  font-size: 0.7rem;
  text-align: center;
  color: var(--text-light);
  line-height: 1.3;
  font-weight: 500;
}

.doku-option.selected .doku-label {
  color: var(--text);
  font-weight: 600;
}

/* Premise banner */
.ebene-premise {
  padding: 0.75rem 1.1rem;
  margin: 0 1.5rem 1rem;
  background: #FFFDF0;
  border: 1px solid #E8DFA5;
  border-radius: 8px;
  font-size: 0.82rem;
  color: #7A6D2B;
  line-height: 1.5;
}

/* Action buttons */
.actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.btn {
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.5rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-reset {
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--text-light);
}

.btn-reset:hover {
  background: #f0efe8;
}

.btn-jspdf, .btn-loadpdf {
  background: var(--inhalt);
  color: var(--white);
}

.btn-export:hover {
  background: #15294a;
}

/* Footnote */
.footnote {
  margin-bottom: 1em;
}

footer a {
  color: var(--prozess);
  text-decoration-line: none;
}

/* Responsive */
@media (max-width: 768px) {
  .container {
    padding: 1.5rem 1rem 3rem;
  }

  header h1 {
    font-size: 1.5rem;
  }

  .header-row{
    grid-template-columns: 1fr;
  }

  .category-row {
    grid-template-columns: 1fr;
  }

  .category-info {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .doku-label {
    font-size: 0.62rem;
  }

  .doku-circle {
    width: 18px; height: 18px;
  }

  .legend {
    gap: 0.3rem 1rem;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .category-row {
    overflow: scroll;
  }

  .ebene-header {
    display: grid;
    grid-template-columns: 19fr 1fr;
  }

  .ebene-label {
    grid-column: 1 / -1;
  }

  .ebene-toggle {
    width: 10px;
  }
}

/* Print styles */
@media print {
  .ebene-body {
    max-height: none !important;
  }

  .ebene-toggle {
    display: none;
  }

  .actions {
    display: none;
  }

  .ebene {
    break-inside: avoid;
  }

  body {
    font-size: 12pt;
  }
}

.hidden {
  display: none !important;
}