:root {
  color-scheme: light;
  --bg: #f3f4f6;
  --panel: #ffffff;
  --panel-hover: #e9edf2;
  --panel-sub: #f7f8fa;
  --ink: #202b38;
  --ink-bright: #14202d;
  --muted: #536070;
  --subtle: #536070;
  --line: #cbd2da;
  --line-light: #e1e5ea;
  --control-border: #697582;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath d='m5 7.5 5 5 5-5' fill='none' stroke='%23536070' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --accent: #245b87;
  --accent-hover: #19466b;
  --accent-bg: #e8f0f7;
  --accent-border: #829fba;
  --soft: #e8f0f7;
  --primary: #245b87;
  --primary-hover: #19466b;
  --on-primary: #ffffff;
  --warn: #875600;
  --warn-bg: #fff5dd;
  --warn-border: #bd9b50;
  --error: #b42318;
  --error-bg: #fff0ed;
  --error-border: #d99a92;
  --ok: #256a46;
  --ok-bg: #eaf5ee;
  --ok-border: #8cb49c;
  --shadow: 0 4px 18px rgb(32 43 56 / 10%);
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --r: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
}

:root[data-appearance="dark"] {
  color-scheme: dark;
  --bg: #10161e;
  --panel: #19212b;
  --panel-hover: #273342;
  --panel-sub: #151d27;
  --ink: #e7edf4;
  --ink-bright: #ffffff;
  --muted: #b0bdcc;
  --subtle: #b0bdcc;
  --line: #455365;
  --line-light: #354151;
  --control-border: #8492a3;
  --select-arrow: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 20 20'%3E%3Cpath d='m5 7.5 5 5 5-5' fill='none' stroke='%23b0bdcc' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  --accent: #9dcbf4;
  --accent-hover: #c4e2fc;
  --accent-bg: #223b53;
  --accent-border: #6c91b2;
  --soft: #223b53;
  --primary: #9dcbf4;
  --primary-hover: #c4e2fc;
  --on-primary: #14202d;
  --warn: #efc77d;
  --warn-bg: #3b2e17;
  --warn-border: #9c7b43;
  --error: #ffb0a8;
  --error-bg: #422422;
  --error-border: #b27971;
  --ok: #91d4aa;
  --ok-bg: #20392c;
  --ok-border: #6c9e7d;
  --shadow: 0 4px 18px rgb(0 0 0 / 20%);
}

* {
  box-sizing: border-box;
}

::placeholder { color: var(--muted); opacity: 1; }
input[type="radio"], input[type="checkbox"] { accent-color: var(--primary); width: 24px; height: 24px; }
.save-state { font-size: .875rem; color: var(--ok); }
.save-state.unsaved { color: var(--warn); }

body {
  margin: 0;
  font: .9375rem/1.5 var(--font-ui);
  background: var(--bg);
  color: var(--ink);
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
}

.hidden { display: none !important; }
.login-card { max-width: 420px; margin: 70px auto; }
.login-card h1 { margin: 0 0 20px; font-size: 1.25rem; }
.login-card #loginError:empty { display: none; }
.login-view .topbar { display: none; }
.session-status { margin: 70px auto; }
.setup-notice { flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: var(--space-2) var(--space-4); padding: var(--space-2) var(--space-4); border-bottom: 1px solid var(--line); background: var(--panel-sub); color: var(--muted); font-size: .875rem; }
.login-card label { display: block; margin: 14px 0; }
.login-card input { width: 100%; margin-top: 6px; }
.task-panel { padding: 8px 0 0; border-top: 1px solid var(--line-light); margin-top: 12px; background: transparent; font-size: .875rem; color: var(--muted); }
.task-head { display: flex; gap: 12px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.task-panel summary { cursor: pointer; overflow-wrap: anywhere; }
.task-panel ol { max-height: 150px; overflow: auto; color: var(--muted); padding-left: 22px; }
.feedback-entry { padding: 12px 0; border-bottom: 1px solid var(--line); }
.feedback-entry p { white-space: pre-wrap; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  #accountName { display: none; }
  .topbar { gap: 6px; padding: 0 8px; }
  .tools-right { gap: 4px; }
  .task-panel { padding: 8px 0 0; }
}
.spacer { flex: 1; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .875rem; }
.full-width { width: 100%; }

/* --- Topbar --- */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  min-height: 56px;
  height: auto;
  flex-wrap: wrap;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
  z-index: 30;
}

.brand-group {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 10px;
}

.brand {
  font-weight: 700;
  color: var(--accent);
  background: transparent;
  border: 1px solid transparent;
  font-size: 1.25rem;
  letter-spacing: 0;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.brand:hover {
  background: var(--accent-bg);
  color: var(--accent-hover);
  border-color: var(--accent);
}

.project-title-wrap {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
}

.project-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tools-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.account-actions { display: contents; }
.mobile-control { display: none; }

.nav-toggle {
  background: var(--bg);
  border: 1px solid var(--line);
  padding: 4px 10px;
  font-size: .875rem;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all .15s ease;
}

.nav-toggle:hover {
  color: var(--ink);
  border-color: var(--muted);
}

.nav-toggle.active {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--accent);
}

.inline select {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: .875rem;
  background: var(--bg);
  color: var(--ink);
}

.model-picker select,
.model-picker input {
  width: 150px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--ink);
}

#apiKey { width: 100%; max-width: 340px; }

/* --- Layout Shell --- */
.shell {
  flex: 1 1 auto;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

.pane-full {
  flex: 1;
  padding: var(--space-6);
  overflow-y: auto;
  background: var(--bg);
}

.container-narrow {
  max-width: 760px;
  margin: 0 auto;
}

.container-library { max-width: 1100px; margin: 0 auto; }
.library-heading { margin-bottom: 20px; }
.library-heading h1 { font-size: 1.5rem; margin: 0 0 6px; }
.library-toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: var(--space-4); margin-bottom: var(--space-4); }
.library-toolbar label { display: flex; flex-direction: column; gap: var(--space-2); font-size: .875rem; }
.library-toolbar label:first-child { flex: 1; min-width: 200px; }
.project-library { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); gap: 16px; }
.project-card { padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); min-width: 0; }
.library-card-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.library-card-head h2 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.library-card-head .hint { flex: none; }
.library-source-names { font-size: .875rem; color: var(--muted); overflow-wrap: anywhere; }
.library-output-list { display: flex; flex-direction: column; gap: 10px; margin: 16px 0; }
.library-output-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 1rem; }
.library-card-actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.library-delete { margin-left: auto; }
.library-nav { width: 100%; margin-bottom: 12px; font: inherit; }
.library-content { overflow-y: auto; min-height: 0; padding: var(--space-6); }
.library-section { margin-bottom: 28px; }
.library-section h2 { font-size: 1rem; margin: 0 0 12px; }
.library-entry { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-4); padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: var(--space-3); background: var(--panel); }
.library-entry > div { min-width: 0; overflow-wrap: anywhere; }
.library-entry p { margin: 5px 0; }
.library-entry strong { font-size: 1rem; }
.library-source-entry { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px; margin-bottom: 8px; text-align: left; }
.library-source-entry > div { display: flex; flex-direction: column; gap: 4px; min-width: 0; overflow-wrap: anywhere; }
.template-choices { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); gap: var(--space-3); margin: var(--space-4) 0; }
.template-choice { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-4); border: 1px solid var(--line); border-radius: var(--r); cursor: pointer; min-width: 0; }
.template-choice:has(input:checked) { border-color: var(--muted); background: var(--panel-sub); }
.template-choice input { width: auto; margin-top: 3px; }
.template-choice p { margin: 6px 0 0; }
.template-details { padding: var(--space-4); background: var(--bg); border-radius: var(--r); font-size: 1rem; }
.template-details p { overflow-wrap: anywhere; }
.template-details ul { padding-left: 20px; line-height: 1.7; }
@media (max-width: 760px) {
  #mainProjects { padding: 16px; }
  .library-card-head { flex-wrap: wrap; }
  .library-content { padding: 14px; }
}

.workspace {
  position: relative;
  flex: 1;
  display: flex;
  overflow: hidden;
  width: 100%;
}

/* --- Left Sidebar: Explorer --- */
.sidebar-explorer {
  width: 17.5rem;
  flex: none;
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.explorer-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.explorer-title {
  font-size: .875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}

.explorer-content {
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.tree-group {
  display: flex;
  flex-direction: column;
}

.source-actions { display: flex; flex-direction: column; gap: 0; margin-bottom: 4px; }

.tree-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  margin-bottom: 3px;
}

.tree-group-label {
  font-size: .875rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--muted);
}

.ghost-icon-small {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 1rem;
  line-height: 1;
}

.ghost-icon-small:hover {
  background: var(--panel-hover);
  color: var(--ink);
}

.tree-items {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.tree-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  min-height: 44px;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: .9375rem;
  color: var(--ink);
  transition: all .12s ease;
  user-select: none;
}

.tree-item:hover {
  background: var(--panel-hover);
}

.tree-item.active {
  background: var(--accent-bg);
  color: var(--accent);
  font-weight: 600;
  border-color: var(--accent-border);
}

.tree-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--muted);
}

.tree-item.active .tree-icon {
  color: var(--accent);
}

.icon-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.lucide {
  width: 15px;
  height: 15px;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
  fill: none;
  display: inline-block;
  vertical-align: -2px;
  flex: none;
}

.tree-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tree-badge {
  font-size: .875rem;
  color: var(--muted);
  background: var(--panel-hover);
  border-radius: 10px;
  padding: 1px 6px;
  margin-left: auto;
  flex: none;
}

.tree-item.active .tree-badge {
  color: var(--accent);
  background: var(--accent-bg);
}

/* --- Center Stage --- */
.main-column {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

.view-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  min-height: 52px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex: none;
}

.title-meta {
  display: flex;
  flex-direction: column;
}

.title-meta strong {
  font-size: 1rem;
  color: var(--ink);
}

#viewChat .title-meta { flex-direction: row; align-items: center; gap: var(--space-2); min-width: 0; }
#activeConvTitleDisplay { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.title-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.doc-icon {
  font-size: 1.125rem;
  flex: none;
}

.doc-title-input {
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  outline: none;
  padding: 4px 6px;
  border-radius: 4px;
  width: min(340px, 100%);
}

.doc-title-input:hover, .doc-title-input:focus {
  background: var(--bg);
  border: 1px solid var(--line);
}

.pill-category {
  font-size: .875rem;
  color: var(--muted);
  background: var(--panel-hover);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1px 8px;
  flex: none;
}
.pill-category:empty { display: none; }

.output-header-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* --- Document Editor View --- */
.document-editor-container {
  flex: 1;
  display: flex;
  overflow: hidden;
  background: var(--panel);
}

#documentEditorText {
  width: 100%;
  height: 100%;
  padding: 24px 36px;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-ui);
  font-size: 1.125rem;
  line-height: 1.7;
  color: var(--ink);
  resize: none;
}

/* --- Image Source View --- */
.image-source-container {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  background: var(--bg);
}

.image-preview-wrap {
  min-width: 0;
  min-height: 0;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  background: var(--bg);
}

#imagePreview {
  display: block;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.image-caption-editor {
  padding: 24px;
  border-left: 1px solid var(--line);
  background: var(--panel-sub);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#imageCaption {
  width: 100%;
  min-height: 160px;
  resize: vertical;
  font: inherit;
}

@media (max-width: 900px) {
  .image-source-container {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }

  .image-preview-wrap {
    min-height: 50vh;
  }

  .image-caption-editor {
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

/* --- Chat View --- */
#viewChat { position: relative; }

.chat-file-drop {
  position: absolute;
  inset: 8px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  border: 2px dashed var(--accent);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  text-align: center;
  pointer-events: none;
}

.file-import-status { margin: 0 0 10px; overflow-wrap: anywhere; }

.chat-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.chat-workspace .chat-stream {
  min-width: 0;
}
.chat-draft-resize { width: 16px; flex: none; cursor: col-resize; touch-action: none; background: var(--panel-sub); border-inline: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.chat-draft-resize::after { content: ''; height: 44px; width: 3px; border-radius: 2px; background: var(--control-border); }
.chat-draft-resize:hover, .chat-draft-resize:focus-visible { background: var(--accent-bg); }

.chat-draft-preview {
  display: flex;
  flex-direction: column;
  width: var(--draft-preview-width, 46%);
  flex-shrink: 0;
  min-width: 260px;
  border-left: 1px solid var(--line);
  background: var(--panel);
}

.chat-draft-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.chat-draft-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-draft-title-row strong { min-width: 0; overflow-wrap: anywhere; flex: 1; }
#btnChatDraftWord { flex: none; white-space: nowrap; }

.chat-revision-brief {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  white-space: pre-wrap;
  max-height: 140px;
  overflow-y: auto;
}

.chat-draft-text {
  padding: 12px;
  overflow-y: auto;
  line-height: 1.55;
  font-size: 1rem;
}

.chat-draft-paragraph {
  display: grid;
  grid-template-columns: 2em 1fr;
  gap: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 900px) {
  .chat-workspace { flex-direction: column; }
  .chat-draft-preview {
    width: 100%;
    min-width: 0;
    height: var(--draft-preview-height, 45%);
    max-height: 70%;
    border-left: none;
    border-top: 1px solid var(--line);
  }
  .chat-draft-resize { width: 100%; height: 20px; cursor: row-resize; border-inline: none; border-block: 1px solid var(--line); }
  .chat-draft-resize::after { width: 44px; height: 3px; }
}

.chat-stream {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}

.turn {
  padding: 10px 14px;
  border-radius: var(--r);
  border: 1px solid var(--line);
  max-width: min(92%, 76ch);
  line-height: 1.55;
}

.turn.user {
  align-self: flex-end;
  background: var(--accent-bg);
  border-color: var(--accent-border);
  color: var(--ink);
}

.turn.assistant {
  align-self: flex-start;
  background: var(--panel);
  border-color: var(--line);
  box-shadow: var(--shadow);
  user-select: text;
}

.turn .who {
  font-size: .875rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.turn.user .who {
  color: var(--accent);
}

.turn.assistant .who {
  color: var(--accent);
}
.pending-chat-status { color: var(--muted); }
.pending-chat-status.failed { color: var(--error); }

.turn-content {
  white-space: pre-wrap;
  font-size: .9375rem;
  word-break: break-word;
}

.turn-content blockquote {
  margin: 10px 0;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
  color: var(--ink);
  font-style: italic;
  border-radius: 0 4px 4px 0;
}

/* Markdown in KI-Antworten: ruhige, kompakte Gliederung im Gespraechsfluss. */
.turn-content > *:first-child { margin-top: 0; }
.turn-content > *:last-child { margin-bottom: 0; }

.turn-content .md-p {
  margin: 0 0 10px;
}

.turn-content .md-h {
  margin: 14px 0 6px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--ink);
}

.turn-content h3.md-h {
  font-size: 1.0625rem;
}

.turn-content .md-list {
  margin: 0 0 10px;
  padding-left: 22px;
}

.turn-content .md-list li {
  margin: 4px 0;
}

.turn-content code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--panel-sub);
  border: 1px solid var(--line);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9375rem;
}

.turn-content pre {
  margin: 10px 0;
  padding: 10px 12px;
  overflow-x: auto;
  border-radius: 6px;
  background: var(--panel-sub);
  border: 1px solid var(--line);
}

.turn-content pre code {
  padding: 0;
  border: none;
  background: none;
}

.turn-content hr {
  margin: 14px 0;
  border: none;
  border-top: 1px solid var(--line);
}

.chat-input-container {
  border-top: 1px solid var(--line);
  padding: var(--space-3);
  background: var(--panel);
  flex: none;
}

.quote-staging {
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 10px;
}

.staging-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.staging-text {
  font-size: .875rem;
  color: var(--accent);
  font-style: italic;
  max-height: 60px;
  overflow: auto;
}

.chat-composer {
  border: 1px solid var(--control-border);
  border-radius: var(--r);
  padding: var(--space-3);
  background: var(--panel);
}
.chat-composer:focus-within { border-color: var(--accent); }
.chat-composer:has(#chatInput:focus-visible) { outline: 3px solid var(--accent); outline-offset: 3px; }
.composer-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); margin-top: var(--space-2); }
.composer-actions { display: flex; align-items: center; gap: var(--space-2); width: 100%; }
#btnVoiceHelp { margin-right: auto; }

#chatInput {
  display: block;
  width: 100%;
  min-height: 48px;
  max-height: 160px;
  resize: vertical;
  border: 0;
  border-radius: 0;
  padding: var(--space-1);
  font-family: inherit;
  font-size: 1rem;
  min-width: 0;
  background: transparent;
  color: var(--ink);
}

#chatInput:focus {
  outline: none;
  box-shadow: none;
}

.send-btn {
  min-height: 44px;
  height: auto;
  padding: 8px 16px;
  font-weight: 600;
}
.send-icon { display: none; }

.voice-btn {
  width: auto;
  padding: 0 12px;
  gap: var(--space-2);
  min-height: 44px;
  height: auto;
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition: all .15s ease;
}

.voice-btn .lucide {
  width: 18px;
  height: 18px;
}

.voice-btn:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--muted);
}

.voice-btn.listening {
  color: var(--error);
  border-color: var(--error);
  background: var(--error-bg);
  box-shadow: 0 0 0 3px var(--error-bg);
}

.voice-btn:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.input-hints {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
  font-size: .875rem;
}

.app-dialog.voice-help { width: min(840px, calc(100vw - 24px)); max-height: 85dvh; overflow: hidden; }
.voice-help-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.voice-help-header h2 { margin: 0; }
.voice-help-header button { flex: none; }
#btnVoiceHelp { display: inline-flex; align-items: center; gap: var(--space-1); }
#btnVoiceHelp .lucide { width: 16px; height: 16px; }
#btnVoiceHelp[aria-expanded="true"] .lucide { transform: rotate(90deg); }
.voice-help-content { max-height: calc(85dvh - 140px); overflow-y: auto; margin-top: 12px; padding-right: 8px; }
.voice-help table { width: 100%; max-width: 760px; table-layout: fixed; border-collapse: collapse; text-align: left; }
.voice-help caption { text-align: left; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.voice-help th, .voice-help td { padding: 6px 8px; border-bottom: 1px solid var(--line-light); vertical-align: top; overflow-wrap: anywhere; }
.voice-help th:first-child, .voice-help td:first-child { width: 34%; }
.voice-help th { font-weight: 500; color: var(--ink); }

/* --- Draft View --- */
.output-body {
  flex: 1 1 auto;
  display: flex;
  overflow: hidden;
}

.draft-container {
  flex: 1;
  padding: 24px 36px;
  overflow-y: auto;
  background: var(--bg);
}

#draftEditor {
  width: 100%;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-ui);
  font-size: 1.125rem;
  line-height: 1.7;
  color: var(--ink);
  resize: none;
}

.button-link {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  color: var(--accent);
}

/* --- Material Stage View --- */
.material-stage-container {
  flex: 1;
  overflow-y: auto;
  padding: 24px 36px;
  background: var(--bg);
}

.material-full-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 840px;
}

/* --- Right Column: Inspector --- */
.inspector-column {
  width: 320px;
  flex: none;
  border-left: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

@media (max-width: 960px) {
  .inspector-column {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: min(320px, 100%);
    z-index: 40;
    box-shadow: var(--shadow);
  }
}

.inspector-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--line-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Kopfzeile: nur noch anzeigen, womit gearbeitet wird. */
.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font-size: 1rem;
  cursor: pointer;
}

.model-chip:hover { background: var(--panel-sub); }
.model-chip .lucide { width: 14px; height: 14px; }

/* Einstellungen */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.settings-row {
  display: grid;
  grid-template-columns: 140px minmax(0, 1fr);
  align-items: start;
  gap: var(--space-3);
}

.settings-row > span:first-child, .settings-row > label { color: var(--muted); font-size: 1rem; padding-top: 8px; }
.settings-row select,
.settings-row input { width: 100%; max-width: 340px; }
.settings-row > span, .settings-row > div { min-width: 0; }
.model-picker .hint { max-width: 340px; overflow-wrap: anywhere; }
.settings-grid label input { width: 100%; max-width: 100%; }
.settings-row select, .settings-row input, .login-card input { min-height: 44px; }
.settings-field { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
.settings-grid .settings-field input { width: 100%; max-width: 340px; }
.field-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.settings-grid > label:not(.settings-row) { display: flex; flex-direction: column; gap: var(--space-2); }
.settings-grid > label:not(.settings-row) input { max-width: 340px; min-height: 44px; }

/* Editor fuer Profildateien */
.profile-editor {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
  min-height: 420px;
}

.profile-files {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.profile-group {
  margin: 12px 0 2px;
  font-size: .875rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.profile-files > .profile-group:first-child { margin-top: 0; }

.profile-file {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  text-align: left;
  font: inherit;
  font-size: .875rem;
  cursor: pointer;
}

.profile-file:hover { background: var(--panel-sub); }
.profile-file.active { background: var(--accent-bg); border-color: var(--accent); }

.profile-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.profile-pane-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.profile-pane-head strong { font-size: 1rem; }
.profile-pane-head .hint { margin-right: auto; }

.profile-text {
  flex: 1;
  min-height: 380px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .9375rem;
  line-height: 1.6;
  resize: vertical;
  tab-size: 2;
}

@media (max-width: 900px) {
  .profile-editor { grid-template-columns: 1fr; }
}

.type-doc {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.type-doc:first-child { margin-top: 8px; border-top: none; padding-top: 0; }
.type-doc h3 { margin: 0 0 4px; font-size: 1rem; color: var(--ink); }

.type-rule {
  padding: 7px 0;
  border-bottom: 1px solid var(--line-light, var(--line));
}

.type-rule:last-child { border-bottom: none; }

.type-rule-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 1rem;
}

/* Auswahl des Ausgabetyps: eine Liste statt einer Knopfreihe, damit die
   Kopfzeile auch bei vielen Templates ruhig bleibt. */
.output-menu {
  position: relative;
  display: inline-block;
}

.output-menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 40;
  min-width: 260px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 60vh;
  overflow-y: auto;
}

.output-menu-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  text-align: left;
  font: inherit;
  cursor: pointer;
}

.output-menu-item:hover {
  background: var(--panel-sub);
}

/* Griff zum Aufklappen: sitzt am Rand der Spalte, die er oeffnet. */
.inspector-handle {
  align-self: stretch;
  width: 44px;
  flex: none;
  border: none;
  border-left: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
}

.inspector-handle:hover {
  background: var(--panel-sub);
  color: var(--ink);
}

#btnCloseInspector {
  font-size: 1.125rem;
  line-height: 1;
  padding: 0 4px;
}

.inspector-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--muted);
}

.inspector-content {
  padding: 12px;
  overflow-y: auto;
  flex: 1;
}

.drawer-static {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel-sub);
  padding: 12px;
}

.static-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 1rem;
  color: var(--ink);
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.item-row {
  display: flex;
  gap: 6px;
  align-items: flex-start;
  padding: 6px 0;
  border-bottom: 1px solid var(--line-light);
  font-size: .875rem;
}

.item-row .txt {
  flex: 1;
  word-break: break-word;
}

.item-row .del {
  cursor: pointer;
  color: var(--muted);
  border: none;
  background: none;
  padding: 0 4px;
  font-size: 1rem;
}

.item-row .del:hover {
  color: var(--error);
}

.findings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.finding-item {
  padding: 8px 12px;
  border-radius: 6px;
  border-left: 3px solid var(--muted);
  background: var(--panel-sub);
  font-size: .875rem;
  line-height: 1.5;
}

.finding-item.error {
  border-left-color: var(--error);
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  border-left-width: 3px;
}

.finding-item.warning {
  border-left-color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-left-width: 3px;
}

.finding-item.hinweis {
  border-left-color: var(--accent);
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  border-left-width: 3px;
}

.finding-item .f-label {
  font-weight: 600;
  margin-bottom: 2px;
}

.pill-group {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

.pill {
  font-size: .875rem;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
}

.pill.error {
  background: var(--error-bg);
  color: var(--error);
  border-color: var(--error-border);
}

.pill.warning {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}

.pill.ok {
  background: var(--ok-bg);
  color: var(--ok);
  border-color: var(--ok-border);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.tag-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--accent-bg);
  border: 1px solid var(--accent-border);
  color: var(--accent);
  font-size: .875rem;
  padding: 2px 8px;
  border-radius: 12px;
}

.tag-item .del {
  cursor: pointer;
  color: var(--muted);
  font-weight: bold;
}

.tag-item .del:hover {
  color: var(--error);
}

/* --- Floating Selection Toolbar --- */
.selection-toolbar {
  position: absolute;
  z-index: 1000;
  background: var(--panel-hover);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 4px 6px;
  display: flex;
  gap: 4px;
  box-shadow: var(--shadow);
  transform: translate(-50%, -100%);
  pointer-events: auto;
}

.selection-toolbar::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-width: 6px 6px 0;
  border-style: solid;
  border-color: var(--panel-hover) transparent transparent;
}

.st-btn {
  background: none;
  border: none;
  color: var(--ink);
  font-size: .875rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: background .12s ease;
  white-space: nowrap;
}

.st-btn:hover {
  background: var(--panel-hover);
  color: var(--ink);
}

/* --- Patch Bubble --- */
.patch-bubble {
  position: absolute;
  z-index: 1000;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
  width: 340px;
  transform: translate(-50%, -100%);
}

.bubble-quote {
  font-size: .875rem;
  color: var(--muted);
  font-style: italic;
  max-height: 52px;
  overflow: hidden;
  margin-bottom: 8px;
  border-left: 2px solid var(--accent);
  padding-left: 8px;
}

.patch-bubble input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 1rem;
  background: var(--bg);
  color: var(--ink);
}

.patch-bubble input:focus {
  outline: none;
  border-color: var(--accent);
}

/* --- Buttons & Inputs General --- */
input, select, textarea, button {
  font: inherit;
}

input, select, textarea {
  border: 1px solid var(--control-border);
  border-radius: 6px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--ink);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}

select, .inline select, .model-picker select {
  -webkit-appearance: none;
  appearance: none;
  min-height: 44px;
  padding: 8px 44px 8px 12px;
  border-color: var(--control-border);
  background-image: var(--select-arrow);
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px 20px;
  line-height: 1.4;
  cursor: pointer;
}

@media (forced-colors: active) {
  select, .inline select, .model-picker select {
    -webkit-appearance: auto;
    appearance: auto;
    background-image: none;
    padding-right: 12px;
  }
}

button {
  cursor: pointer;
  border-radius: 6px;
  padding: 8px 14px;
  min-height: 44px;
  border: 1px solid var(--control-border);
  background: var(--panel);
  color: var(--ink);
  transition: all .15s ease;
}

button:hover {
  border-color: var(--muted);
  background: var(--panel-hover);
}

button:disabled {
  opacity: .4;
  cursor: not-allowed;
}

.source-action, .new-chat-control {
  border-color: transparent;
  background: transparent;
  font-size: .875rem;
  font-weight: 400;
  min-height: 44px;
  padding: 8px 10px;
}
.source-action { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; }
.source-action .lucide { width: 18px; height: 18px; color: var(--muted); }
.new-chat-control { color: var(--accent); padding-inline: 8px; }
.source-action:hover, .new-chat-control:hover { border-color: transparent; background: var(--panel-hover); }

.app-dialog {
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  padding: var(--space-6);
  overflow-y: auto;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}
.app-dialog::backdrop { background: rgb(16 22 30 / 40%); }
.app-dialog-wide { width: min(560px, calc(100vw - 32px)); }
.app-dialog.template-dialog { width: min(680px, calc(100vw - 32px)); }
.app-dialog-details { width: min(840px, calc(100vw - 32px)); }
.app-dialog h2 { margin: 0 0 var(--space-4); font-size: 1.25rem; }
.app-dialog p { overflow-wrap: anywhere; }
.app-dialog label { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-4) 0; }
.app-dialog .template-choice { flex-direction: row; margin: 0; }
.app-dialog input, .app-dialog select, .app-dialog textarea { width: 100%; min-height: 44px; }
.app-dialog input[type="radio"] { width: 24px; min-height: 24px; }
.app-dialog input[type="file"] { padding: 4px; font-size: .875rem; }
.app-dialog input::file-selector-button {
  font: inherit;
  color: var(--ink);
  background: var(--panel);
  border: 1px solid var(--control-border);
  border-radius: 4px;
  min-height: 36px;
  padding: 4px 10px;
  margin-right: 8px;
  cursor: pointer;
}
.dialog-error { color: var(--error); font-size: .875rem; margin: 8px 0; }
.dialog-error:empty { display: none; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 24px; }
.dialog-footer { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-top: 24px; }
.dialog-footer .dialog-actions { margin-top: 0; }
button.dialog-secondary-action { border-color: transparent; background: transparent; color: var(--muted); font-size: .875rem; padding-inline: 0; }
button.dialog-secondary-action:hover { color: var(--ink); }
button.danger { color: var(--error); border-color: var(--error); background: var(--panel); }
button.danger:hover { background: var(--error-bg); }

button.primary {
  background: var(--primary);
  color: var(--on-primary);
  border-color: var(--primary);
}

button.primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}

button.ghost {
  color: var(--ink);
  border-color: transparent;
  background: transparent;
}

button.ghost:hover {
  background: var(--panel-hover);
  color: var(--ink);
  border-color: transparent;
}

button.quiet-action { border-color: transparent; background: transparent; color: var(--muted); font-size: .875rem; padding: 8px; }
button.quiet-action:hover { color: var(--ink); background: var(--panel-hover); }
button.icon-action { display: inline-flex; align-items: center; justify-content: center; flex: none; width: 44px; height: 44px; padding: 0; border-color: transparent; background: transparent; color: var(--muted); }
button.icon-action .lucide { width: 18px; height: 18px; }
button.icon-action:hover { background: var(--panel-hover); color: var(--ink); }

button.ghost-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 2px 4px;
  font-size: 1rem;
}

button.ghost-icon:hover {
  color: var(--ink);
}

button.small {
  padding: 8px 12px;
  font-size: .875rem;
}
button.primary.small { font-size: 1rem; }

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.row-compact {
  display: flex;
  gap: 4px;
  align-items: center;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: var(--space-6);
  margin-bottom: var(--space-4);
}

.new-project-card h2 { margin: 0 0 12px; font-size: 1rem; }
.new-project-row { flex-wrap: wrap; }
.new-project-row input { flex: 1; min-width: 0; }
.chat-empty { margin: 16px 0; }

table.list {
  width: 100%;
  border-collapse: collapse;
}

table.list td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  font-size: 1rem;
  vertical-align: middle;
}

td.right {
  text-align: right;
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  overflow-wrap: anywhere;
  pointer-events: none;
  background: var(--panel-sub);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 1rem;
  z-index: 100;
  box-shadow: var(--shadow);
}

.toast.err {
  background: var(--error-bg);
  border-color: var(--error-border);
  color: var(--error);
}

#modalBody {
  margin: 0;
  padding: var(--space-4);
  max-height: 55vh;
  overflow: auto;
  font-size: .875rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color: var(--ink);
  background: var(--bg);
}

/* --- Beitragsnavigation --- */
.btn-new-conv {
  width: 100%;
  background: var(--panel-sub);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all .15s ease;
}
.btn-new-conv:hover {
  background: var(--line);
  border-color: var(--muted);
  color: var(--ink-bright);
}
.btn-new-conv .plus-sign {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
}
.projects-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px;
  margin-top: 4px;
}
.project-tree-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--panel-sub);
  margin-bottom: 8px;
}
.tree-project-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.other-projects-group {
  margin-top: 16px;
  border-top: 1px solid var(--line-light);
  padding-top: 12px;
}

/* --- Chat Attached Draft Badge (Antigravity Pill) --- */
.attached-draft-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.pill-draft-attach {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-bg);
  border: 1px solid var(--accent);
  color: var(--accent);
  padding: 4px 10px;
  border-radius: 14px;
  font-size: .875rem;
  font-weight: 600;
  box-shadow: var(--shadow);
}
.pill-draft-attach .pill-icon {
  font-size: .875rem;
}
.pill-draft-attach .pill-close {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 0 2px;
  font-size: 1rem;
  line-height: 1;
}
.pill-draft-attach .pill-close:hover {
  color: var(--ink-bright);
}

/* --- Output Mode Switcher --- */
.view-mode-toggle {
  display: flex;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px;
  gap: 2px;
}
.view-mode-toggle .toggle-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  transition: all .15s ease;
}
.view-mode-toggle .toggle-btn:hover {
  color: var(--ink);
}
.view-mode-toggle .toggle-btn.active {
  background: var(--panel);
  color: var(--ink-bright);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* --- Review Container with Line Numbers & Hover-+ --- */
.review-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  background: var(--panel);
  font-family: var(--font-ui);
  font-size: 1.125rem;
  line-height: 1.6;
}
.review-line-wrap {
  display: flex;
  flex-direction: column;
}
.review-line {
  display: flex;
  align-items: flex-start;
  min-height: 44px;
  margin-bottom: 12px;
  border-radius: 4px;
  position: relative;
}
.review-line:hover {
  background: var(--panel-sub);
}
.review-line.has-comment {
  background: var(--accent-bg);
}
.review-gutter {
  width: 86px;
  flex: none;
  padding-right: 12px;
  text-align: right;
  color: var(--subtle);
  user-select: none;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}
.review-line-number {
  font-size: .875rem;
  line-height: 44px;
}
.review-add-btn {
  position: absolute;
  left: 2px;
  top: 0;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: var(--panel);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1;
  border: 1px solid var(--control-border);
  transition: transform .1s ease;
}
.review-add-btn:hover {
  background: var(--accent-bg);
}
.review-line:hover .review-add-btn,
.review-gutter:hover .review-add-btn {
  display: flex;
}
.review-line-content {
  flex: 1;
  white-space: pre-wrap;
  word-break: break-word;
  padding: 0 8px;
  line-height: 1.7;
  max-width: 76ch;
  color: var(--ink);
}

/* --- Inline Comment Cards (Screenshot 1) --- */
.inline-comment-card {
  margin: 4px 12px 12px 86px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.inline-comment-text {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 1rem;
  color: var(--ink);
  line-height: 1.5;
  white-space: pre-wrap;
}
.inline-comment-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 14px;
  border-top: 1px solid var(--line-light);
  padding-top: 6px;
}
.comment-act-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  padding: 2px 4px;
  transition: all .12s ease;
}
.comment-act-btn:hover {
  color: var(--ink);
}
.comment-act-btn.del:hover {
  color: var(--error);
}

/* --- Inline Comment Form --- */
.inline-comment-form {
  margin: 4px 12px 12px 86px;
  background: var(--panel);
  border: 1px solid var(--accent-border);
  border-radius: 6px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
}
.inline-comment-form textarea {
  width: 100%;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px 10px;
  font-size: 1rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  resize: vertical;
  min-height: 46px;
}
.inline-comment-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-bg);
}
.inline-comment-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 760px) {
  .topbar { position: relative; height: auto; min-height: 56px; flex-wrap: nowrap; padding: 4px 8px; gap: 4px; }
  .brand-group { flex: 1; gap: 4px; overflow: hidden; }
  .brand { padding: 4px; font-size: 1.125rem; }
  .project-title-wrap { flex: 1; }
  .project-title { max-width: none; flex: 1; }
  .topbar .spacer { display: none; }
  .tools-right { flex: none; width: auto; gap: 0; flex-wrap: nowrap; }
  .mobile-control { display: inline-flex; align-items: center; gap: 8px; }
  #modelChipLabel { display: none; }
  .model-chip { border: 0; background: transparent; padding: 10px; }
  .account-actions { display: none; }
  .account-actions.menu-open { position: absolute; top: 100%; right: 8px; z-index: 50; display: flex; flex-direction: column; align-items: stretch; gap: 4px; padding: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); }
  .pane-full { padding: 16px; }
  .login-card { margin: 24px auto; }
  .workspace { flex-direction: column; }
  .sidebar-explorer { width: 100%; max-height: none; overflow: visible; border-right: 0; border-bottom: 1px solid var(--line); }
  .explorer-header { padding: 4px 8px; gap: 8px; border-bottom: 0; }
  .explorer-header .btn-new-conv { width: auto; font-weight: 500; margin-left: auto; }
  .explorer-content { display: none; padding: 8px; }
  .sidebar-explorer.nav-open .explorer-content { display: flex; overflow-y: auto; max-height: 45dvh; border-top: 1px solid var(--line); }
  .main-column { min-height: 0; }
  .panel-header { flex-wrap: wrap; padding: 10px 12px; gap: 8px; }
  #viewChat .panel-header { min-height: 52px; padding: 4px 8px; gap: 0; }
  #viewChat .header-actions { margin-left: auto; gap: 0; }
  #viewChat .title-meta { flex: 1; }
  #btnQuickPromptA { display: none; }
  .chat-stream { padding: 12px; }
  .chat-input-container { padding: 8px 8px max(8px, env(safe-area-inset-bottom)); }
  .chat-composer { padding: 8px; }
  .composer-toolbar { gap: 4px; margin-top: 4px; }
  .composer-actions { gap: 4px; }
  #btnVoiceInput { width: 44px; padding: 0; border-color: transparent; }
  #voiceButtonLabel { display: none; }
  #btnSendChat { width: 44px; padding: 0; display: inline-flex; justify-content: center; align-items: center; }
  #btnSendChat span { display: none; }
  #btnSendChat .send-icon { display: block; }
  .chat-input-container:not(:has(#voiceHelp[open])) .chat-composer:not(:focus-within):has(#chatInput:placeholder-shown) { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; padding: 4px; }
  .chat-input-container:not(:has(#voiceHelp[open])) .chat-composer:not(:focus-within):has(#chatInput:placeholder-shown) #chatInput { height: 40px; min-height: 40px; resize: none; padding: 8px; }
  .chat-input-container:not(:has(#voiceHelp[open])) .chat-composer:not(:focus-within):has(#chatInput:placeholder-shown) .composer-toolbar { display: block; margin-top: 0; }
  #btnVoiceHelp { font-size: .875rem; }
  #btnVoiceHelp span { display: none; }
  #btnVoiceHelp { min-width: 44px; }
  #chatInput { min-height: 48px; }
  .file-import-status { max-height: 72px; overflow-y: auto; margin-bottom: 6px; }
  .attached-draft-badge { flex-wrap: wrap; }
  .settings-row { grid-template-columns: 1fr; gap: 6px; }
  .settings-row > span:first-child { padding-top: 0; }
  .output-header-meta { width: 100%; }
  .doc-title-input { min-width: 0; }
  .title-meta-row { flex-wrap: wrap; }
  .settings-row select, .settings-row input { max-width: 100%; }
  #documentEditorText { padding: 16px; }
  .review-container { padding: 12px; }
  .review-gutter { width: 72px; padding-right: 6px; }
  .inline-comment-form, .inline-comment-card { margin-left: 0; margin-right: 0; }
}

@media (max-height: 650px) and (max-width: 760px) {
  .workspace { overflow-y: auto; }
  .sidebar-explorer { max-height: none; }
  .main-column { flex: 1 0 360px; overflow: visible; }
  .chat-workspace { min-height: 120px; }
  .view-panel { overflow: visible; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

#chatInput:focus-visible, #documentEditorText:focus-visible, #draftEditor:focus-visible,
.doc-title-input:focus-visible, :is(button, input, select, textarea, a, summary):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

#chatInput:focus-visible { outline: none; }
