:root {
  /* Default to light if no theme attribute is present */
  --bg: #ffffff;
  --bg-elev: #f7f8fa;
  --text: #1f2328;
  --muted: #6a737d;
  --border: #d0d7de;
  --accent: #0969da;
  --btn-bg: #f6f8fa;
  --btn-bg-hover: #eef1f4;
  --header-h: 52px; /* default, JS passt an */
  --versions-w: 0px;
}

/* Light */
body[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f7f8fa;
  --text: #1f2328;
  --muted: #6a737d;
  --border: #d0d7de;
  --accent: #0969da;
  --btn-bg: #f6f8fa;
  --btn-bg-hover: #eef1f4;
}

/* Dark */
body[data-theme="dark"] {
  --bg: #0d1117;
  --bg-elev: #151b23;
  --text: #e6edf3;
  --muted: #9aa6b2;
  --border: #30363d;
  --accent: #4493f8;
  --btn-bg: #161b22;
  --btn-bg-hover: #202833;
}

/* Pitch Black */
body[data-theme="black"] {
  --bg: #000000;
  --bg-elev: #0a0a0a;
  --text: #f5f5f5;
  --muted: #c0c0c0;
  --border: #222222;
  --accent: #4da3ff;
  --btn-bg: #0f0f0f;
  --btn-bg-hover: #151515;
}

/* High Contrast */
body[data-theme="high-contrast"] {
  --bg: #000000;
  --bg-elev: #000000;
  --text: #ffff00;
  --muted: #ffe066;
  --border: #ffffff;
  --accent: #ff8c00;
  --btn-bg: #000000;
  --btn-bg-hover: #1a1a1a;
}

/* Sepia */
body[data-theme="sepia"] {
  --bg: #f6f1e7;
  --bg-elev: #efe8dd;
  --text: #3b3024;
  --muted: #6e6256;
  --border: #e0d6c8;
  --accent: #b36b00;
  --btn-bg: #efe8dd;
  --btn-bg-hover: #e7dfd3;
}

/* Solarized Light */
body[data-theme="solarized-light"] {
  --bg: #fdf6e3;
  --bg-elev: #f5edd7;
  --text: #657b83;
  --muted: #93a1a1;
  --border: #eee8d5;
  --accent: #268bd2;
  --btn-bg: #f5edd7;
  --btn-bg-hover: #efe4c8;
}

/* Solarized Dark */
body[data-theme="solarized-dark"] {
  --bg: #002b36;
  --bg-elev: #073642;
  --text: #93a1a1;
  --muted: #b3c2c3;
  --border: #0b3a46;
  --accent: #268bd2;
  --btn-bg: #073642;
  --btn-bg-hover: #0a4753;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Helvetica, Arial, Noto Sans, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
}
body.onboarding-open { overflow: hidden; }

.app-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky; top: 0; z-index: 50;
}
.app-header .left, .app-header .center, .app-header .right { display: flex; align-items: center; gap: 8px; }
.app-header .left { justify-self: start; }
.app-header .center { justify-self: center; }
.app-header .right { justify-self: end; }
.logo { font-size: 18px; }
.logo-img { height: 24px; width: auto; }
.title { font-weight: 600; }

/* Buttons with icons */
.has-icon { display: inline-flex; align-items: center; gap: 6px; }
.has-icon iconify-icon { font-size: 16px; line-height: 0; }
.icon-only { display: inline-flex; align-items: center; justify-content: center; }
.icon-only iconify-icon { font-size: 18px; }
.btn-label { display: inline-block; }

button {
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
}
button:hover { background: var(--btn-bg-hover); }
button.active { outline: 2px solid var(--accent); }
button:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
button.secondary { background: transparent; }
button.secondary:hover { background: var(--btn-bg-hover); }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
button.primary:hover { filter: brightness(1.05); }
button.primary:focus { color: #fff; }
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
button:disabled:hover {
  background: var(--btn-bg);
}

.view-toggle button { padding: 6px 8px; }
.theme-select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--btn-bg); color: var(--text); }
.theme-select:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-switcher { display: inline-flex; align-items: center; gap: 6px; }
.theme-switcher .icon-only iconify-icon { font-size: 18px; }
.theme-switcher { position: relative; }
.theme-menu { position: absolute; top: calc(100% + 6px); right: 0; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; min-width: 200px; box-shadow: 0 8px 24px rgba(0,0,0,0.2); padding: 6px; z-index: 200; }
.theme-menu.hidden { display: none; }
.theme-menu button { width: 100%; display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: 6px; border: 1px solid transparent; background: transparent; text-align: left; }
.theme-menu button:hover { background: var(--btn-bg-hover); border-color: var(--border); }
.theme-menu .current { outline: 2px solid var(--accent); }

.menu-group { position: relative; display: inline-flex; }
.toolbar-menu { position: absolute; top: calc(100% + 6px); left: 0; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px; min-width: 220px; box-shadow: 0 8px 24px rgba(0,0,0,0.2); padding: 6px; z-index: 200; display: flex; flex-direction: column; gap: 4px; }
.toolbar-menu.hidden { display: none; }
.toolbar-menu button { width: 100%; display: inline-flex; align-items: center; gap: 8px; padding: 8px; border-radius: 6px; border: 1px solid transparent; background: transparent; text-align: left; justify-content: flex-start; }
.toolbar-menu button:hover { background: var(--btn-bg-hover); border-color: var(--border); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  justify-content: center; /* center buttons horizontally */
}
.sticky-tools .toolbar {
  position: sticky;
  top: var(--header-h);
  z-index: 49;
}
.toolbar .sep { width: 1px; background: var(--border); margin: 0 4px; }
.toolbar button { font-size: 13px; }
/* ensure icon+label are centered inside the button */
.toolbar .has-icon { justify-content: center; }
/* align icons nicely on the text baseline */
.toolbar iconify-icon { line-height: 1; vertical-align: middle; }

/* Inline AI panel */
.sticky-tools .ai-inline { padding: 8px 12px; border-bottom: 1px solid var(--border); background: var(--bg-elev); position: sticky; top: calc(var(--header-h) + var(--toolbar-only-h, 44px)); z-index: 39; }
.ai-inline { padding: 10px 14px; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--bg-elev); box-shadow: 0 2px 10px rgba(0,0,0,0.04) inset; }
.ai-inline.hidden { display: none; }
.ai-inline .row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 8px; }
.ai-inline .row:last-child { margin-bottom: 0; }
.ai-inline input[type="text"] { flex: 1; min-width: 260px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); }
.ai-inline button { padding: 8px 10px; }
.ai-inline button.secondary { background: var(--btn-bg); }
.ai-inline .chip { border: 1px solid var(--border); background: var(--btn-bg); color: var(--text); border-radius: 999px; padding: 4px 10px; cursor: pointer; font-size: 12px; }
.ai-inline .chip:hover { background: var(--btn-bg-hover); }
.ai-inline label { display: inline-flex; align-items: center; gap: 6px; }
.ai-inline input[type="range"] { accent-color: var(--accent); }
.ai-inline select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }

.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  height: calc(100vh - (var(--header-h, 52px) + var(--toolbar-total-h, 44px) + var(--status-h, 32px)));
}
.layout.layout-edit { grid-template-columns: 1fr 0; }
.layout.layout-reader { grid-template-columns: 0 1fr; }
/* Hide the inactive pane to avoid any overlay capturing events */
.layout.layout-edit .preview-pane { display: none; }
.layout.layout-reader .editor-pane { position: relative; width: 0; overflow: hidden; border: 0; }
.layout.layout-reader #editor { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

.editor-pane, .preview-pane { min-width: 0; }
.editor-pane { border-right: 1px solid var(--border); }

#editor {
  width: 100%; height: 100%;
  border: none; outline: none; resize: none;
  padding: 16px; background: var(--bg); color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, Liberation Mono, monospace;
  font-size: 14px; line-height: 1.6;
  pointer-events: auto;
}

#preview {
  padding: 16px 20px 40px; overflow: auto; height: 100%;
}

.statusbar {
  display: flex; align-items: center; gap: 16px;
  padding: 6px 12px; border-top: 1px solid var(--border);
  background: var(--bg-elev); color: var(--muted);
  font-size: 12px; height: 32px;
}

.updates-group {
  display: grid;
  gap: 16px;
}

.updates-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.updates-header h4 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.updates-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.updates-item {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--bg);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.updates-item:hover {
  border-color: var(--border);
  background: var(--btn-bg-hover);
}

.updates-item-message {
  margin: 0;
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, Liberation Mono, monospace;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
  background: transparent;
  border: none;
  padding: 0;
}

.updates-item-meta {
  font-size: 12px;
  color: var(--muted);
}

.updates-item-link {
  font-size: 13px;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  align-self: flex-start;
}

.updates-item-link:hover,
.updates-item-link:focus {
  text-decoration: underline;
}

.updates-reload {
  align-self: flex-start;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.updates-reload:hover {
  background: var(--btn-bg-hover);
}

.updates-reload iconify-icon {
  font-size: 16px;
}

/* Markdown body tweaks */
.markdown-body h1, .markdown-body h2, .markdown-body h3,
.markdown-body h4, .markdown-body h5, .markdown-body h6 {
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.markdown-body pre, .markdown-body code { background: var(--bg-elev); }
.markdown-body pre { border: 1px solid var(--border); padding: 12px; border-radius: 6px; overflow: auto; }
.markdown-body blockquote { color: var(--muted); border-left: 4px solid var(--border); margin: 0; padding: 0 12px; }
.markdown-body table { border-collapse: collapse; width: 100%; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 6px 8px; }

/* Drag & drop cue */
body.dragging #workspace { outline: 3px dashed var(--accent); outline-offset: -6px; }

/* Reader mode: hide toolbar for clean reading */
/* keep tools visible in reader mode */

/* When chat is open, reserve space so content is not covered */
body.chat-open #workspace,
body.versions-open #workspace {
  margin-right: calc(var(--chat-w, 0px) + var(--versions-w, 0px));
}
body.chat-open .statusbar,
body.versions-open .statusbar {
  padding-right: calc(12px + var(--chat-w, 0px) + var(--versions-w, 0px));
}
body.chat-open .ai-inline,
body.versions-open .ai-inline {
  margin-right: calc(var(--chat-w, 0px) + var(--versions-w, 0px));
}

/* Responsive */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .layout.layout-edit { grid-template-columns: 1fr; }
  .layout.layout-reader { grid-template-columns: 1fr; }
  .editor-pane { border-right: none; border-bottom: 1px solid var(--border); height: 45vh; }
}

/* Print: show only preview to export as PDF */
@media print {
  .app-header, .toolbar, .statusbar, .editor-pane { display: none !important; }
  .layout { grid-template-columns: 1fr !important; height: auto !important; }
  .preview-pane { display: block !important; }
  body { background: #ffffff !important; color: #000 !important; }
  #preview { padding: 0 !important; }
  .markdown-body pre { break-inside: avoid; }
}

/* Onboarding tutorial */
.onboarding {
  position: fixed;
  inset: 0;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13, 17, 23, 0.65);
  backdrop-filter: blur(4px);
  z-index: 120;
}
.onboarding.hidden { display: none; }
.onboarding-dialog {
  background: var(--bg);
  color: var(--text);
  border-radius: 16px;
  padding: 24px;
  width: min(520px, 100%);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  display: grid;
  gap: 20px;
}
.onboarding-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.onboarding-counter {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.onboarding-body { display: grid; gap: 12px; }
.onboarding-body h2 { margin: 0; font-size: 24px; }
.onboarding-description { margin: 0; font-size: 15px; color: var(--muted); }
.onboarding-list {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 8px;
  font-size: 14px;
}
.onboarding-dots { display: flex; justify-content: center; gap: 8px; }
.onboarding-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--border);
  transition: transform 0.2s ease, background 0.2s ease;
}
.onboarding-dot.active {
  background: var(--accent);
  transform: scale(1.25);
}
.onboarding-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.onboarding-actions .spacer { flex: 1; }

@media (max-width: 640px) {
  .onboarding-dialog {
    padding: 20px;
    width: min(92vw, 480px);
  }
  .onboarding-body h2 { font-size: 20px; }
}

/* Chat panel */
.chat-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.15); backdrop-filter: none; z-index: 30; pointer-events: auto; }
.chat-panel { position: fixed; top: var(--header-h); right: 0; width: min(560px, 100%); height: calc(100% - var(--header-h)); background: var(--bg); color: var(--text); border-left: 1px solid var(--border); z-index: 60; display: flex; flex-direction: column; box-shadow: -6px 0 24px rgba(0,0,0,0.2); }
.chat-panel.hidden, .chat-overlay.hidden { display: none; }

.templates-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(2px); z-index: 140; }
.templates-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(960px, 94vw);
  max-height: min(90vh, 760px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 22px 60px rgba(15, 23, 42, 0.35);
  z-index: 150;
  overflow: hidden;
}
.templates-panel.hidden, .templates-overlay.hidden { display: none; }
body.templates-open { overflow: hidden; }
.templates-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 22px;
  padding-right: 72px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  position: sticky;
  top: 0;
  z-index: 10;
}
.templates-header strong { font-size: 16px; }
.template-search { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg); color: var(--muted); min-width: 0; margin-left: auto; }
.template-search input { border: none; outline: none; background: transparent; color: var(--text); min-width: 160px; }
.template-search input::placeholder { color: var(--muted); }
.templates-close {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: inherit;
  padding: 0;
}
.templates-close:hover {
  background: var(--btn-bg-hover);
}
.templates-close iconify-icon {
  font-size: 18px;
}
.templates-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 22px;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}
.template-categories { display: flex; flex-wrap: wrap; gap: 8px; max-height: 110px; overflow-y: auto; padding-right: 4px; flex: 0 0 auto; }
.template-categories button { border-radius: 999px; padding: 6px 12px; border: 1px solid var(--border); background: var(--btn-bg); color: var(--text); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.template-categories button.active { background: var(--accent); color: #fff; border-color: transparent; }
.template-categories button iconify-icon { font-size: 16px; }
.templates-main { display: flex; gap: 16px; flex: 1; min-height: 0; }
.template-list-wrapper { flex: 1; min-width: 0; display: flex; }
.template-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; width: 100%; overflow-y: auto; padding-right: 4px; }
.template-item { border: 1px solid var(--border); border-radius: 10px; padding: 12px; background: var(--bg); display: flex; flex-direction: column; gap: 8px; cursor: pointer; transition: border-color 0.2s ease, box-shadow 0.2s ease; }
.template-item:hover, .template-item:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(68, 147, 248, 0.25); }
.template-item.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(68, 147, 248, 0.35); }
.template-item header { display: flex; align-items: center; gap: 8px; }
.template-item-title { font-weight: 600; flex: 1; }
.template-item-desc { color: var(--muted); font-size: 13px; margin: 0; }
.template-item-actions { display: flex; align-items: center; gap: 6px; }
.template-item button { background: transparent; border: none; color: inherit; padding: 0; display: inline-flex; align-items: center; justify-content: center; cursor: pointer; }
.template-item button.active iconify-icon { color: var(--accent); }
.template-item-category { font-size: 12px; color: var(--muted); }
.template-item-snippet { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.4; }
.template-item-empty { padding: 12px; border: 1px dashed var(--border); border-radius: 10px; color: var(--muted); font-size: 13px; text-align: center; }
.template-item-favorite { width: 32px; height: 32px; border-radius: 50%; border: 1px solid transparent; background: transparent; }
.template-item-favorite:hover { background: var(--btn-bg-hover); }
.template-item-favorite iconify-icon { font-size: 18px; }
.template-item button iconify-icon { font-size: 18px; }
.template-item button:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.template-preview {
  flex: 1.2;
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}
.template-preview header { display: flex; align-items: center; gap: 12px; }
.template-preview h3 { margin: 0; font-size: 18px; }
.template-preview-actions { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; }
.template-preview-actions .icon-only { width: 36px; height: 36px; border-radius: 999px; border: 1px solid var(--border); background: var(--btn-bg); }
.template-preview-actions .icon-only.active { background: var(--accent); border-color: transparent; color: #fff; }
.template-preview-actions .icon-only.active iconify-icon { color: inherit; }
.template-preview-actions button { padding: 8px 12px; }
.template-preview .muted { margin: 0; }
.template-preview pre {
  margin: 0;
  padding: 14px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  max-height: 320px;
  overflow: auto;
  font-family: 'JetBrains Mono', SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 13px;
  line-height: 1.4;
  white-space: pre-wrap;
}
.template-preview-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; text-align: center; color: var(--muted); }
.template-preview-empty iconify-icon { font-size: 32px; }

@media (max-width: 1024px) {
  .templates-panel {
    width: min(760px, 96vw);
  }
  .templates-main { flex-direction: column; }
  .template-list-wrapper { max-height: 40%; }
  .template-list { max-height: 100%; }
  .template-preview { flex: 1; }
}

@media (max-width: 640px) {
  .templates-panel {
    top: 0;
    left: 0;
    transform: none;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
  }
  .templates-header { flex-wrap: wrap; padding: 16px 18px; }
  .templates-body { padding: 16px 18px; gap: 16px; }
  .template-search { flex: 1 1 100%; }
  .template-search input { width: 100%; }
  .template-categories { max-height: none; overflow: visible; }
  .template-preview pre { max-height: 220px; }
}
.versions-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.1); z-index: 40; }
.versions-panel { position: fixed; top: var(--header-h); right: 0; width: min(420px, 100%); height: calc(100% - var(--header-h)); background: var(--bg); color: var(--text); border-left: 1px solid var(--border); box-shadow: -6px 0 24px rgba(0,0,0,0.18); z-index: 60; display: flex; flex-direction: column; }
.versions-panel.hidden, .versions-overlay.hidden { display: none; }
.versions-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.versions-header strong { font-size: 15px; }
.versions-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; border-bottom: 1px solid var(--border); align-items: flex-end; }
.versions-actions .versions-note { flex: 1; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.versions-actions input { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.versions-actions button { white-space: nowrap; }
.versions-body { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.versions-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.versions-list li { margin: 0; }
.versions-entry { width: 100%; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); padding: 10px 12px; display: grid; gap: 4px; align-items: flex-start; text-align: left; cursor: pointer; transition: background 0.15s ease, border-color 0.15s ease; }
.versions-entry:hover, .versions-entry:focus { background: var(--btn-bg-hover); border-color: var(--accent); outline: none; }
.versions-entry.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.versions-entry .version-meta { display: flex; gap: 8px; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); }
.versions-entry .version-note { font-size: 13px; color: var(--text); word-break: break-word; }
.versions-entry .version-tag { padding: 2px 6px; border-radius: 999px; background: var(--btn-bg); border: 1px solid var(--border); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.versions-empty { font-size: 13px; color: var(--muted); }
.versions-diff { border-top: 1px solid var(--border); padding: 12px; background: var(--bg-elev); display: grid; gap: 10px; }
.versions-diff-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.versions-diff-content { margin: 0; border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: var(--bg); color: var(--text); max-height: 240px; overflow: auto; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; white-space: pre-wrap; }
.versions-diff-actions { display: flex; justify-content: flex-end; }
.diff-eq { background: transparent; }
.diff-ins { background: rgba(46, 160, 67, 0.2); }
.diff-del { background: rgba(255, 59, 48, 0.2); text-decoration: line-through; }
.diff-line { display: inline; }

.settings-panel { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(920px, 95%); height: min(90vh, 720px); max-height: 90vh; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 12px; z-index: 61; display: grid; grid-template-rows: auto 1fr auto; box-shadow: 0 16px 40px rgba(0,0,0,0.35); overflow: hidden; }
.settings-panel.hidden { display: none; }

/* Separate overlay for settings to allow click-to-close */
.settings-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.45); backdrop-filter: blur(2px); z-index: 59; }
.settings-overlay.hidden { display: none; }

.website-overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(3px); z-index: 80; }
.website-overlay.hidden { display: none; }
.website-modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(960px, 90vw); height: min(85vh, 780px); background: var(--bg); color: var(--text); border-radius: 18px; box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35); z-index: 81; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--border); }
.website-modal.hidden { display: none; }
.website-modal .chat-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.website-modal-body { flex: 1; padding: 1rem 1.25rem 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
.website-modal-footer { padding: 0.85rem 1.25rem 1.25rem; display: flex; align-items: center; flex-wrap: wrap; gap: 0.75rem; border-top: 1px solid var(--border); background: var(--bg); }
.website-modal-footer .spacer { flex: 1; min-width: 1px; }
.website-modal-footer-group { display: flex; flex-wrap: wrap; gap: 0.75rem; }
.website-status { min-height: 1.5em; margin: 0; font-size: 0.95rem; color: var(--muted); }
.website-status.error { color: #ff6b6b; }
.website-preview-wrapper { flex: 1; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: var(--bg-elev); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04); }
#websitePreviewFrame { width: 100%; height: 100%; border: none; background: #ffffff; }
.settings-body { display: grid; grid-template-columns: 260px 1fr; min-height: 0; }
.settings-nav { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-right: 1px solid var(--border); background: var(--bg-elev); }
.settings-nav .nav-item { text-align: left; border: 1px solid var(--border); background: var(--btn-bg); color: var(--text); padding: 10px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; width: 100%; }
.settings-nav .nav-item.has-icon { display: flex; align-items: center; gap: 8px; justify-content: flex-start; }
.settings-nav .nav-item iconify-icon { font-size: 18px; line-height: 0; }
.settings-nav .nav-item.active { border-color: var(--accent); background: var(--btn-bg-hover); }
.settings-nav .settings-badge {
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid var(--border);
  color: var(--muted);
  background: var(--btn-bg);
}
.settings-nav .settings-badge-experimental {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--btn-bg-hover);
}
.settings-content { padding: 16px; overflow: auto; scrollbar-gutter: stable; min-height: 360px; }
.settings-tab.hidden { display: none; }
.settings-footer { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--bg-elev); }
.settings-footer .spacer { flex: 1; }
.chat-header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--bg-elev); }
.chat-header .spacer { flex: 1; }
.chat-model-badge { font-size: 12px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 2px 8px; background: var(--bg); }
.chat-settings { display: grid; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
/* Auto-snapshot interval input adapts to content width without stretching */
#prefAutoSnapshotInterval {
  width: 120px;
  max-width: 100%;
  margin-top: 6px;
}
/* Larger, more comfortable spacing inside the settings modal only */
.settings-panel .chat-settings { gap: 14px; padding: 14px 16px; }
.settings-panel .chat-settings label { gap: 6px; font-size: 13px; }
.settings-panel .chat-settings input,
.settings-panel .chat-settings select { padding: 10px 12px; font-size: 14px; }
.settings-panel .chat-settings textarea { padding: 10px 12px; font-size: 14px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); resize: vertical; }
.settings-panel #userContextFields.is-disabled .settings-group { opacity: 0.6; transition: opacity 0.2s ease; }
.settings-panel #userContextFields.is-disabled textarea { cursor: not-allowed; }
.settings-panel input[type="range"] { accent-color: var(--accent); }
.settings-panel .settings-group { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 12px; background: var(--bg); }
.settings-panel .settings-group h4 { margin: 0 0 8px 0; font-size: 14px; color: var(--muted); }
.feedback-form { display: grid; gap: 10px; margin-top: 8px; }
.feedback-form .form-row { display: grid; gap: 4px; }
.feedback-form label { font-size: 12px; color: var(--muted); }
.feedback-form input,
.feedback-form textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font-size: 14px; }
.feedback-form textarea { resize: vertical; min-height: 120px; }
.settings-panel .btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--btn-bg); color: var(--text); border-radius: 6px; padding: 6px 10px; text-decoration: none; }
.settings-panel .btn:hover { background: var(--btn-bg-hover); }
.info-panel { display: grid; justify-items: center; gap: 10px; padding: 10px 0; }
.info-avatar { width: 72px; height: 72px; border-radius: 50%; border: 1px solid var(--border); object-fit: cover; background: var(--bg-elev); }
.info-name { font-weight: 600; }
.settings-panel .chat-settings .row { gap: 12px; }
.chat-settings label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); }
.chat-settings input { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.chat-settings select { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); }
.chat-settings .row { display: flex; align-items: center; gap: 8px; }
.chat-settings .chk { display: inline-flex; align-items: center; gap: 6px; color: var(--text); font-size: 13px; }
.ollama-status { min-height: 18px; font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); font-size: 12px; }
.shortcuts { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.shortcuts li { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; padding: 2px 0; }
.shortcuts .keys { white-space: nowrap; }
.shortcuts .desc { color: var(--muted); }
kbd { display: inline-block; padding: 2px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: 12px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; box-shadow: 0 1px 0 rgba(0,0,0,0.06); }
.chat-messages { flex: 1; overflow: auto; padding: 12px; display: grid; gap: 10px; }
.msg { position: relative; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elev); padding-right: 90px; }
.msg.user { border-color: var(--accent); }
.msg.assistant { }
.msg .role { display: block; font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.msg .msg-actions { position: absolute; top: 6px; right: 6px; display: inline-flex; flex-direction: row-reverse; gap: 6px; }
.msg .msg-actions button { border: 1px solid var(--border); background: var(--btn-bg); color: var(--text); border-radius: 6px; font-size: 12px; padding: 2px 6px; opacity: 0.75; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.msg .msg-actions button:disabled { opacity: 0.4; cursor: not-allowed; }
.msg .msg-actions button iconify-icon { font-size: 14px; line-height: 1; }
.msg .msg-actions button:hover { opacity: 1; background: var(--btn-bg-hover); }
.msg .msg-actions button.speak-btn.speaking { border-color: var(--accent); color: var(--accent); }
.think-block { border: 1px dashed var(--border); border-radius: 6px; background: transparent; }
.think-block > summary { cursor: pointer; list-style: none; color: var(--muted); padding: 6px 8px; }
.think-block > summary::marker, .think-block > summary::-webkit-details-marker { display: none; }
.think-block > .think-body { padding: 0 8px 8px; }
.think-block pre { margin: 8px 0; }
.chat-input { border-top: 1px solid var(--border); padding: 10px 12px; display: grid; gap: 8px; }
.chat-suggestions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.chat-suggestions li {
  margin: 0;
}
.chat-suggestions button {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 13px;
  line-height: 1.45;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
}
.chat-suggestions button strong {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
}
.chat-suggestions button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.chat-input textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); resize: vertical; max-height: 40vh; }
.chat-input .row { display: flex; gap: 8px; }
.chat-input .secondary { background: var(--btn-bg); }
/* removed diff styles */
