:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #d9dde3;
  --accent: #2f6fed;
  --accent-dark: #1f50bd;
  --text: #1c2230;
  --muted: #6b7280;
  --danger: #d9433b;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
button:hover { background: #eef1f6; border-color: #b9c0cc; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.icon-btn { border: none; background: none; font-size: 16px; padding: 2px 6px; }
.mini { padding: 1px 8px; font-size: 16px; line-height: 1.2; }

.hidden { display: none !important; }

/* ===================== Login ===================== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 40, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.login-box {
  background: var(--panel);
  width: min(360px, 92vw);
  padding: 28px 26px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 18px 48px rgba(0,0,0,.3);
}
.login-box h1 { margin: 0; font-size: 24px; text-align: center; }
.login-sub { margin: 0 0 12px; text-align: center; color: var(--muted); font-size: 14px; }
.login-box label { font-size: 12px; color: var(--muted); margin-top: 8px; }
.login-box input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
}
.login-box .btn-primary { margin-top: 16px; padding: 10px; font-size: 15px; }
.login-error {
  margin-top: 10px;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

/* ===================== Layout ===================== */
#app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.brand { font-size: 18px; white-space: nowrap; }
.title-input {
  flex: 0 1 260px;
  max-width: 260px;
  margin-right: auto;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 15px;
}
.topbar-actions { display: flex; gap: 8px; }

.layout { flex: 1; display: flex; overflow: hidden; }

.sidebar {
  width: 250px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.side-section { padding: 14px; border-bottom: 1px solid var(--border); }
.side-head { display: flex; justify-content: space-between; align-items: center; }
.sidebar h2 { font-size: 14px; margin: 0 0 10px; color: var(--muted); }
.side-head h2 { margin: 0; }
.tab-title { font-size: 13px; font-weight: 600; color: var(--muted); }

/* Sidebar-Tabs */
.side-tabs { display: flex; gap: 3px; margin-bottom: 12px; }
.side-tab {
  flex: 1;
  padding: 6px 2px;
  font-size: 11px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  white-space: nowrap;
}
.side-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.side-tab.active:hover { background: var(--accent-dark); }

.side-stats { font-size: 13px; }
.side-stats h4 {
  margin: 10px 0 4px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.side-stats table { width: 100%; border-collapse: collapse; }
.side-stats td {
  padding: 4px 6px;
  border-bottom: 1px solid var(--border);
}
.side-stats td:last-child { text-align: right; font-weight: 600; }
.side-stats .rev-time { font-size: 11px; color: var(--muted); font-weight: 400; }
.side-stats td { vertical-align: top; }

.doc-list, .snippet-list { list-style: none; margin: 0; padding: 0; }
.doc-list li, .snippet-list li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 4px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.doc-list li:hover, .snippet-list li:hover { background: #eef1f6; }
.doc-list li.active { background: #e3ecff; color: var(--accent-dark); font-weight: 600; }
.item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-actions { display: flex; gap: 2px; }
.item-actions button { border: none; background: none; padding: 0 3px; font-size: 13px; }
.item-actions button:hover { background: none; }
.item-actions .del:hover { color: var(--danger); }

/* ===================== Main / Editor ===================== */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.group { display: flex; align-items: center; gap: 6px; }
.group .label { color: var(--muted); font-size: 12px; }
.toggle { background: var(--accent); color: #fff; border-color: var(--accent); }
.toggle:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.export button:hover { border-color: var(--accent); color: var(--accent-dark); }

.editor-area { flex: 1; overflow: hidden; display: flex; }
.editor {
  flex: 1;
  border: none;
  resize: none;
  padding: 24px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 15px;
  line-height: 1.6;
  outline: none;
}
.preview {
  flex: 1;
  overflow-y: auto;
  padding: 24px 40px;
  background: var(--panel);
  line-height: 1.65;
}
.preview h1, .preview h2, .preview h3 { line-height: 1.3; }
.preview pre {
  background: #1c2230;
  color: #e8eaf0;
  padding: 14px;
  border-radius: 6px;
  overflow-x: auto;
}
.preview code {
  background: #eef1f6;
  padding: 2px 5px;
  border-radius: 4px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: .9em;
}
.preview pre code { background: none; padding: 0; color: inherit; }
.preview blockquote {
  border-left: 4px solid var(--accent);
  margin: 12px 0;
  padding: 4px 16px;
  color: var(--muted);
}
.preview table { border-collapse: collapse; }
.preview th, .preview td { border: 1px solid var(--border); padding: 6px 10px; }
.preview img { max-width: 100%; }

/* Prompt-Eingabefläche unterhalb des Textes */
.prompt-area {
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding: 10px 16px;
}
.prompt-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.prompt-head label { font-size: 13px; font-weight: 600; color: var(--muted); }
.prompt-input {
  width: 100%;
  min-height: 56px;
  max-height: 140px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
  outline: none;
}
.prompt-input:focus { border-color: var(--accent); }

.status {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--muted);
  background: var(--panel);
  border-top: 1px solid var(--border);
  min-height: 26px;
}

/* ===================== Modale ===================== */
.modal-box {
  background: var(--panel);
  width: min(820px, 92vw);
  max-height: 88vh;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 48px rgba(0,0,0,.3);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-body { padding: 16px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.modal-body label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.modal-body input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}
.modal-body textarea {
  min-height: 220px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  resize: vertical;
}
#exportContent {
  border: none;
  resize: none;
  padding: 16px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  outline: none;
  min-height: 360px;
  max-height: 60vh;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}

.history-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.history-table th, .history-table td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
}
.history-table th { color: var(--muted); font-weight: 600; }
.history-table td .btn-primary,
.history-table td button { padding: 4px 9px; font-size: 12px; margin-right: 4px; }

.comment-list { list-style: none; margin: 0 0 6px; padding: 0; }
.comment-list li {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: #fbfcfe;
}
.comment-list .comment-text { white-space: pre-wrap; font-size: 14px; }
.comment-list .comment-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}
.comment-list .comment-meta button {
  border: none;
  background: none;
  padding: 0 4px;
  font-size: 12px;
}
.comment-list .comment-meta .del:hover { color: var(--danger); }
.comment-empty { color: var(--muted); font-size: 13px; }

/* ===================== Konfigurations-Dialog ===================== */
.config-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 16px 0;
  border-bottom: 1px solid var(--border);
}
.config-tab {
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  padding: 8px 16px;
  font-size: 13px;
  background: var(--bg);
}
.config-tab.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.config-tab.active:hover { background: var(--accent-dark); }

.config-panel { display: flex; flex-direction: column; gap: 6px; }

.modal-body select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--panel);
  color: var(--text);
}
.cfg-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px !important;
  color: var(--text) !important;
  margin-top: 10px !important;
}
.cfg-check input { width: auto; }
.cfg-hint {
  margin: 4px 0 8px;
  padding: 8px 10px;
  font-size: 13px;
  color: var(--muted);
  background: var(--bg);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}
.cfg-textarea {
  min-height: 96px !important;
  font-family: inherit !important;
  font-size: 13px !important;
}

/* ===================== Dunkles Farbschema ===================== */
body.theme-dark {
  --bg: #1c2230;
  --panel: #252c3c;
  --border: #3a4356;
  --accent: #4d83f5;
  --accent-dark: #3c6fd8;
  --text: #e8eaf0;
  --muted: #9aa3b6;
  --danger: #f0635a;
}
body.theme-dark button:hover { background: #2f3849; }
body.theme-dark .doc-list li:hover,
body.theme-dark .snippet-list li:hover { background: #2f3849; }
body.theme-dark .doc-list li.active { background: #2f3d63; color: #cfe0ff; }
body.theme-dark .preview code { background: #2f3849; }
body.theme-dark .comment-list li { background: #2a3142; }

/* ===================== Historie / Änderungsverlauf ===================== */
.rev-list { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.rev-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  background: var(--panel);
}
.rev-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
}
.rev-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  white-space: nowrap;
}
.rev-badge-edit { background: #eef1f6; color: var(--muted); }
.rev-badge-prompt { background: var(--accent); color: #fff; }

/* KI-Prompt-Einträge optisch hervorheben */
.rev-item.rev-prompt {
  border-color: var(--accent);
  border-left: 3px solid var(--accent);
  background: #f4f7ff;
}
.rev-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.rev-prompt-text {
  font-size: 12px;
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-word;
}
.rev-result { margin-top: 4px; }
.rev-result summary {
  font-size: 11px;
  color: var(--accent-dark);
  cursor: pointer;
}
.rev-result pre {
  margin: 4px 0 0;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 160px;
  overflow-y: auto;
}
body.theme-dark .rev-badge-edit { background: #2f3849; color: var(--muted); }
body.theme-dark .rev-item.rev-prompt { background: #28304a; }

/* Aktions-Buttons je Historien-Eintrag (Diff / Wiederherstellen) */
.rev-actions { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 6px; }
.rev-diff-btn,
.rev-restore-btn {
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 4px;
}
.rev-diff-btn:hover,
.rev-restore-btn:hover { border-color: var(--accent); color: var(--accent-dark); }

/* ===================== KI-Schnellbefehle (Sidebar) ===================== */
.side-commands { margin-top: auto; }
.side-commands-hint {
  margin: 6px 0 8px;
  font-size: 11px;
  color: var(--muted);
}
.command-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.command-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 4px;
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  text-align: center;
}
.command-btn:hover { border-color: var(--accent); color: var(--accent-dark); }
.command-btn .cmd-icon { font-size: 18px; line-height: 1; }
.command-btn .cmd-label { white-space: nowrap; }

/* Rückgängig-Button unter den KI-Befehlen */
.command-undo {
  margin-top: 8px;
  width: 100%;
  font-size: 12px;
  padding: 7px 4px;
  border-radius: 6px;
}
.command-undo:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}
.command-undo:disabled { opacity: .5; cursor: default; }

/* ===================== Analyse-Dialog (z. B. Recht) ===================== */
.analysis-body {
  display: block;
  line-height: 1.6;
  font-size: 14px;
}
.analysis-body h1 { font-size: 20px; margin: 12px 0 6px; }
.analysis-body h2 { font-size: 17px; margin: 14px 0 6px; }
.analysis-body h3 { font-size: 15px; margin: 12px 0 4px; }
.analysis-body p { margin: 8px 0; }
.analysis-body ul,
.analysis-body ol { margin: 8px 0; padding-left: 22px; }
.analysis-body li { margin: 3px 0; }
.analysis-body code {
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: .9em;
}
.analysis-body blockquote {
  border-left: 3px solid var(--accent);
  margin: 10px 0;
  padding: 4px 14px;
  color: var(--muted);
}
.analysis-body table { border-collapse: collapse; }
.analysis-body th,
.analysis-body td { border: 1px solid var(--border); padding: 5px 9px; }

/* ===================== Versionsvergleich (Diff-Dialog) ===================== */
.modal-box-wide { width: min(1180px, 96vw); }
.diff-summary {
  font-size: 12px;
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.diff-key {
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
}
.diff-key-add { background: #e9f7ec; color: #14692b; border-color: #b6e0bf; }
.diff-key-change { background: #fff6e0; color: #8a5a00; border-color: #ecd9a8; }
.diff-key-remove { background: #fdecec; color: #a51c1c; border-color: #efbcbc; }

.diff-table {
  width: 100%;
  border-collapse: collapse;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  table-layout: fixed;
}
.diff-table th {
  text-align: left;
  padding: 6px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-weight: 600;
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
}
.diff-table td {
  padding: 2px 8px;
  border: 1px solid var(--border);
  vertical-align: top;
  white-space: pre-wrap;
  word-break: break-word;
}
.diff-num {
  width: 38px;
  text-align: right;
  color: var(--muted);
  user-select: none;
  background: var(--bg);
}
.diff-mark {
  width: 20px;
  text-align: center;
  font-weight: 700;
  user-select: none;
}

/* 🟥 entfernt · 🟩 hinzugefügt · 🟧 geändert (links alt / rechts neu) */
.diff-remove .diff-left  { background: #fdecec; color: #a51c1c; }
.diff-add    .diff-right { background: #e9f7ec; color: #14692b; }
.diff-change .diff-left  { background: #fdecec; color: #a51c1c; }
.diff-change .diff-right { background: #e9f7ec; color: #14692b; }
.diff-remove .diff-right,
.diff-add    .diff-left  { background: #f6f7f9; }
.diff-remove .diff-mark  { color: #a51c1c; }
.diff-add    .diff-mark  { color: #14692b; }
.diff-change .diff-mark  { color: #8a5a00; }

body.theme-dark .diff-remove .diff-left,
body.theme-dark .diff-change .diff-left  { background: #4a2530; color: #f3b6b6; }
body.theme-dark .diff-add .diff-right,
body.theme-dark .diff-change .diff-right { background: #1f3d2a; color: #bfe7c6; }
body.theme-dark .diff-remove .diff-right,
body.theme-dark .diff-add .diff-left { background: #222a3a; }
body.theme-dark .diff-key-add { background: #1f3d2a; color: #bfe7c6; border-color: #2c5a3c; }
body.theme-dark .diff-key-change { background: #4a3c1e; color: #f0d59a; border-color: #6a5526; }
body.theme-dark .diff-key-remove { background: #4a2530; color: #f3b6b6; border-color: #6a3640; }
