/* =====================================================================
   Dokumente: Vorlagenauswahl, Dokument-Editor, Vorschau, Vorlagen-Editor,
   Workflow, Register, Amtsblatt, Protokoll
   ===================================================================== */

/* Schreibschrift für die Unterschrift (selbst gehostet, OFL) */
@font-face {
  font-family: 'DOJ Signature';
  src: url('/fonts/signature.woff2') format('woff2');
  font-display: swap;
}

.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, "Courier New", monospace; font-size: 13px; }
.danger-text { color: var(--danger); }
.toolbar-top { padding: 0 0 16px; }
.toolbar-top input[type="search"] { max-width: 440px; }

/* ---------- Vorlagenauswahl ---------- */
.tpl-group { margin-bottom: 26px; }
.tpl-group h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); margin-bottom: 10px; }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 10px; }
.tpl-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  text-align: left;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, transform .15s;
}
.tpl-card:hover, .tpl-card:focus-visible { border-color: var(--text); box-shadow: var(--shadow-sm); transform: translateY(-1px); }
.tpl-icon {
  flex: none;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: var(--text);
  background: var(--surface-2);
}
.tpl-icon.sm { width: 30px; height: 30px; border-radius: 8px; }
.tpl-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.tpl-text strong { font-weight: 600; }

/* ---------- Tabellen ---------- */
.doc-table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.doc-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.doc-table th { text-align: left; font-weight: 500; color: var(--text-dim); font-size: 12px; padding: 11px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--bg-soft); }
.doc-table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.doc-table tbody tr:last-child td { border-bottom: none; }
.doc-table tr.clickable { cursor: pointer; }
.doc-table tr.clickable:hover td { background: var(--hover); }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions .btn { padding: 4px 10px; }

/* ---------- Dokument-Editor ---------- */
.doc-editor { display: flex; flex-direction: column; height: 100%; }
.ed-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex-wrap: wrap;
}
.ed-title { flex: 1; min-width: 160px; display: flex; flex-direction: column; line-height: 1.3; }
.ed-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.ed-toggle { display: none; padding: 0 16px; border-bottom: 1px solid var(--line); }
.ed-toggle .tabs { margin: 0; border: none; }
.ed-split { flex: 1; display: flex; min-height: 0; }
.ed-form { width: 42%; min-width: 340px; overflow-y: auto; padding: 22px 24px 48px; border-right: 1px solid var(--line); background: var(--surface); }
.ed-preview { flex: 1; min-width: 0; overflow-y: auto; background: var(--paper-stage); }

.field-form .field label .req { color: var(--danger); }
.field-form .field.missing > label { color: var(--danger); }
.field-form .field.missing input, .field-form .field.missing textarea, .field-form .field.missing select, .field-form .field.missing .check-col { border-color: var(--danger); }
.field-inline { margin-bottom: 14px; }
.check-col { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.person-group { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px 0; background: var(--bg-soft); }
.person-group .field { margin-bottom: 10px; }
.person-group .grow2 { flex: 2; }
label.sub { font-size: 11.5px !important; color: var(--text-dim) !important; }
.list-items { display: flex; flex-direction: column; gap: 10px; margin-bottom: 8px; }
.list-card { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-soft); }
.list-card-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 6px 6px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.list-card-tools { display: flex; gap: 2px; }
.list-card-tools .win-btn { width: 28px; height: 28px; }
.list-card-body { padding: 10px 12px 0; }

/* Vorschau (Papier auf grauer Fläche) */
.doc-preview { padding: 20px; position: relative; }
.doc-status { position: absolute; top: 6px; right: 18px; }
.doc-stage { overflow: hidden; display: flex; justify-content: center; }
.doc-frame { border: none; background: transparent; transform-origin: top left; flex: none; box-shadow: 0 4px 24px rgba(0, 0, 0, .14); }

/* Unterschriftsvorschau */
.sig-preview { margin: 14px 0 4px; padding: 16px 20px; background: #fff; color: #111; border: 1px solid var(--line); border-radius: var(--radius-sm); max-width: 360px; }
.sig-preview-script { font-family: 'DOJ Signature', cursive; font-size: 34px; color: #10235a; line-height: 1.1; transform: rotate(-2deg); transform-origin: left bottom; padding-left: 4px; }
.sig-preview-line { border-top: 1px solid #222; margin: 2px 0 6px; }
.sig-preview .muted { color: #555; }

/* ---------- Vorlagen-Editor ---------- */
.te-detail { display: flex; flex-direction: column; }
.te-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.te-title { flex: 1; min-width: 180px; display: flex; flex-direction: column; }
.btn.pulse { box-shadow: 0 0 0 3px var(--selected); }

.fb-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.fb-card { border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.fb-card.dragging { opacity: .45; }
.fb-card.drop-target { border-color: var(--text); box-shadow: 0 -2px 0 var(--text) inset; }
.fb-row { display: flex; align-items: center; gap: 8px; padding: 8px; }
.fb-handle { cursor: grab; color: var(--text-faint); padding: 0 4px; user-select: none; letter-spacing: -2px; }
.fb-main { flex: 1; display: grid; grid-template-columns: minmax(140px, 1.4fr) minmax(110px, 1fr) minmax(150px, 1fr) auto; gap: 8px; align-items: center; min-width: 0; }
.fb-main input, .fb-main select { padding: 7px 10px; font-size: 13px; }
.fb-tools { display: flex; gap: 2px; }
.fb-tools .win-btn { width: 28px; height: 28px; }
.fb-details { padding: 0 12px 8px 36px; font-size: 13px; }
.fb-details summary { cursor: pointer; color: var(--text-dim); margin-bottom: 8px; }
.fb-sub { border-left: 2px solid var(--line-strong); padding-left: 10px; display: flex; flex-direction: column; gap: 6px; }

.te-text { display: flex; gap: 16px; min-height: 520px; }
.te-text-edit { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.te-text-preview { width: 46%; min-width: 300px; background: var(--paper-stage); border-radius: var(--radius); overflow-y: auto; max-height: 75vh; }
.te-toolbar { padding: 0 0 8px !important; flex-wrap: wrap; }
.te-toolbar select { max-width: 260px; }
.tabs.mini { margin: 0; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; padding: 3px; gap: 2px; }
.tabs.mini .tab { padding: 5px 13px; border-radius: 999px; font-size: 13px; }
.tabs.mini .tab.active { background: var(--accent); color: var(--accent-fg); }
.tabs.mini .tab.active::after { display: none; }
.fmt-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 4px; border: 1px solid var(--line-strong); border-bottom: none; border-radius: var(--radius-sm) var(--radius-sm) 0 0; background: var(--surface-2); }
.fmt-btn { min-width: 30px; height: 28px; padding: 0 7px; border: none; border-radius: 6px; background: transparent; color: var(--text); font: inherit; font-size: 13px; cursor: pointer; }
.fmt-btn:hover { background: var(--hover); }
.fmt-sep { width: 1px; background: var(--line-strong); margin: 4px 4px; }
.te-visual {
  flex: 1;
  min-height: 420px;
  overflow-y: auto;
  padding: 20px 24px;
  border: 1px solid var(--line-strong);
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  background: #fff;
  color: #111;
  font-family: Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  user-select: text;
}
.te-visual:focus { border-color: var(--text); }
.te-visual h2 { font-size: 15px; margin: 14px 0 6px; }
.te-visual h3 { font-size: 14px; font-style: italic; margin: 10px 0 4px; }
.te-visual table { border-collapse: collapse; width: 100%; }
.te-visual td, .te-visual th { border: 1px solid #999; padding: 3px 6px; }
.te-visual .center { text-align: center; }
.te-visual .spaced { text-align: center; letter-spacing: .25em; font-weight: 700; }
.te-code { flex: 1; min-height: 460px; resize: vertical; line-height: 1.5; white-space: pre; tab-size: 2; }
.te-preview-tab { display: flex; gap: 16px; }
.te-testdata { width: 38%; min-width: 280px; max-height: 75vh; overflow-y: auto; padding-right: 6px; }
.te-testdata .toolbar { padding: 0 0 10px; justify-content: space-between; }
.te-fullpreview { flex: 1; min-width: 0; background: var(--paper-stage); border-radius: var(--radius); max-height: 75vh; overflow-y: auto; }
.version-view { min-height: 400px; background: var(--paper-stage); border-radius: var(--radius); }

/* ---------- Workflow, Register, Amtsblatt ---------- */
.status-info { background: var(--info-bg); color: var(--info); }
.ed-preview.viewer-only { flex: 1; }
.workflow-box { background: var(--surface-2); border: 1px solid var(--line); color: var(--text); }
.workflow-box.status-granted, .workflow-box.status-partially_granted { background: var(--ok-bg); border-color: transparent; color: var(--text); }
.workflow-box.status-rejected { background: var(--danger-bg); border-color: transparent; color: var(--text); }
.decision-options { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.decision-option { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer; transition: border-color .15s; }
.decision-option:hover { border-color: var(--line-strong); }
.decision-option input { width: auto; margin-top: 3px; accent-color: var(--accent); }
.decision-option span { display: flex; flex-direction: column; gap: 2px; }
.decision-option:has(input:checked) { border-color: var(--text); background: var(--hover); }
.decision-option.opt-rejected:has(input:checked) { border-color: var(--danger); background: var(--danger-bg); }
.register-filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.register-filters input, .register-filters select { width: auto; flex: 1 1 160px; padding: 8px 12px; font-size: 13.5px; }
.register-filters input[type="date"] { flex: 0 0 150px; }
.gazette-head { display: flex; align-items: center; gap: 16px; margin-bottom: 18px; }
.gazette-head img { width: 54px; height: 54px; }
.gazette-head h2 { margin: 0; font-family: var(--font-serif); font-weight: 600; letter-spacing: .01em; }
.gazette-list { display: flex; flex-direction: column; gap: 8px; }
.gazette-item { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface); cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.gazette-item:hover, .gazette-item:focus-visible { border-color: var(--text); box-shadow: var(--shadow-sm); }
.gazette-item svg { color: var(--text); flex: none; }
.gazette-date { width: 120px; flex: none; color: var(--text-dim); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.gazette-body { flex: 1; display: flex; flex-direction: column; gap: 3px; min-width: 0; }

/* ---------- Protokoll / Discord ---------- */
.audit-table td { vertical-align: top; }
.audit-warn td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.audit-details td { background: var(--bg-soft); }
.audit-details pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 12px; color: var(--text-dim); max-height: 300px; overflow: auto; }
.hook-row { display: grid; grid-template-columns: 220px auto 1fr auto; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); }
.hook-row:last-child { border-bottom: none; }
.hook-row input[type="url"] { font-size: 13px; }
.hook-row .hook-state { font-size: 12px; display: block; margin-top: 3px; }
.text-ok { color: var(--ok); }
.text-error { color: var(--danger); }
@container (max-width: 700px) { .hook-row { grid-template-columns: 1fr auto; } .hook-row input[type="url"] { grid-column: 1 / -1; } }

/* ---------- Schmale Bereiche ---------- */
@container (max-width: 860px) {
  .ed-toggle { display: flex; }
  .ed-form { width: 100%; min-width: 0; border-right: none; }
  .ed-preview { display: none; }
  .ed-split.show-preview .ed-form { display: none; }
  .ed-split.show-preview .ed-preview { display: block; }
  .te-text, .te-preview-tab { flex-direction: column; }
  .te-text-preview, .te-testdata { width: 100%; min-width: 0; max-height: none; }
  .fb-main { grid-template-columns: 1fr 1fr; }
}
