/* ============================================================
   PANELS.CSS — Data, Files, Chat-preview, AI-config panels
   ============================================================ */

/* ── Shared panel container ──────────────────────────────── */
.data-panel,
.files-panel,
.chat-preview-panel,
.ai-config-panel {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-base);
  font-family: var(--font-sans, 'Inter', sans-serif);
  font-size: 13px;
  color: var(--text-primary, #2a2520);
}

/* ================================================================
   DATA PANEL  (dp-)
   ================================================================ */
.data-panel-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.data-panel-empty,
.dp-detail-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted, #78736a);
  font-size: 12px;
  padding: 32px;
  text-align: center;
}
.data-panel-empty svg { opacity: 0.15; margin-bottom: 8px; }

.dp-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-muted);
  font-size: 12px;
}

.dp-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-subtle, rgba(100,85,70,0.15));
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Layout: tree + detail side by side */
.dp-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* Tree sidebar */
.dp-tree {
  width: 180px;
  min-width: 140px;
  max-width: 240px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-subtle, rgba(100,85,70,0.1));
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg-surface, #faf9f5);
}

.dp-tree-header {
  display: flex;
  align-items: center;
  padding: 8px 10px 6px;
  border-bottom: 1px solid var(--border-hairline, rgba(100,85,70,0.06));
  flex-shrink: 0;
}

.dp-tree-title {
  flex: 1;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary, #6b6560);
}

.dp-tree-add-btn {
  -webkit-appearance: none;
  appearance: none;
  width: 20px; height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-muted);
  transition: all 0.15s;
}
.dp-tree-add-btn:hover {
  background: var(--bg-hover, #edeae3);
  border-color: var(--border-subtle);
  color: var(--accent);
}

.dp-tree-empty {
  padding: 12px 10px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: italic;
}

.dp-tree-table-wrap { display: flex; flex-direction: column; }

.dp-tree-table {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 8px;
  cursor: pointer;
  font-size: 12px;
  border-radius: 3px;
  margin: 1px 4px;
  transition: background 0.1s;
  user-select: none;
}
.dp-tree-table:hover { background: var(--bg-hover, #edeae3); }
.dp-tree-table.active {
  background: var(--accent-subtle);
  color: var(--accent);
}

.dp-chevron {
  font-size: 8px;
  transition: transform 0.15s;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
}
.dp-chevron.open { transform: rotate(90deg); }

.dp-tree-icon { font-size: 12px; }
.dp-tree-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-tree-badge {
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-elevated, #edeae3);
  border-radius: 10px;
  padding: 1px 5px;
  flex-shrink: 0;
}

.dp-tree-cols { padding: 0 0 4px 24px; }
.dp-tree-col {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  font-size: 11px;
  border-radius: 2px;
  cursor: pointer;
  color: var(--text-muted);
}
.dp-tree-col:hover { background: var(--bg-hover); color: var(--text-primary); }
.dp-tree-col.active { color: var(--accent); }
.dp-tree-col.pk .dp-tree-name::after { content: ' 🔑'; font-size: 9px; }
.dp-tree-type { font-size: 9px; color: var(--text-faint, #a8a09a); margin-left: auto; }
.dp-col-loading { padding: 4px 24px; font-size: 10px; color: var(--text-muted); }

/* Detail area */
.dp-detail {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.dp-detail-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  background: var(--bg-surface);
}

.dp-detail-title {
  font-weight: 600;
  font-size: 13px;
}

.dp-detail-sub {
  font-size: 10px;
  color: var(--text-muted);
}

.dp-detail-tabs { display: flex; gap: 2px; margin-left: 8px; }
.dp-dtab {
  -webkit-appearance: none;
  appearance: none;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.12s;
}
.dp-dtab:hover { background: var(--bg-hover); color: var(--text-primary); }
.dp-dtab.active {
  color: var(--accent);
  background: var(--accent-subtle);
  border-color: rgba(107,45,60,0.2);
}

/* Data grid */
.dp-data-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-hairline);
  flex-shrink: 0;
}

.dp-filter-input {
  flex: 1;
  padding: 4px 8px;
  font-size: 11px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  color: var(--text-primary);
  outline: none;
}
.dp-filter-input:focus { border-color: var(--accent); }

.dp-btn {
  -webkit-appearance: none;
  appearance: none;
  padding: 4px 10px;
  font-size: 11px;
  font-family: inherit;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-primary);
  transition: all 0.12s;
  white-space: nowrap;
}
.dp-btn:hover { background: var(--bg-hover); }
.dp-btn-ghost { background: none; border-color: transparent; color: var(--text-muted); }
.dp-btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.dp-btn-danger { color: #c0392b; border-color: rgba(192,57,43,0.3); }
.dp-btn-danger:hover { background: rgba(192,57,43,0.08); }
.dp-link { background: none; border: none; cursor: pointer; color: var(--accent); text-decoration: underline; font-size: inherit; font-family: inherit; padding: 0; }

.dp-grid-wrap { flex: 1; overflow: auto; }
.dp-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.dp-grid thead { position: sticky; top: 0; z-index: 1; background: var(--bg-surface); }
.dp-grid th {
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.dp-grid th:hover { background: var(--bg-hover); }
.dp-grid .dp-act-col { width: 28px; }
.dp-th-type { display: block; font-size: 9px; font-weight: 400; color: var(--text-muted); text-transform: none; letter-spacing: 0; }
.dp-grid td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-hairline);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dp-grid tr:hover td { background: var(--bg-hover); }
.dp-sortable { cursor: pointer; }
.dp-cell-pk { color: var(--text-muted); font-style: italic; }
.dp-cell-input {
  width: 100%;
  padding: 2px 4px;
  font-size: 12px;
  font-family: inherit;
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  border-radius: 2px;
  outline: none;
}
.dp-row-new td { background: var(--accent-subtle); }

.dp-grid-empty, .dp-grid-loading {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  font-style: italic;
}

.dp-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px;
  border-top: 1px solid var(--border-hairline);
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* SQL editor */
.dp-sql-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; padding: 10px; gap: 8px; }
.dp-sql-textarea {
  width: 100%;
  min-height: 80px;
  padding: 8px 10px;
  font-size: 12px;
  font-family: 'JetBrains Mono', 'Fira Mono', monospace;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  outline: none;
  resize: vertical;
}
.dp-sql-textarea:focus { border-color: var(--accent); }
.dp-sql-actions { display: flex; gap: 6px; }
.dp-sql-result { flex: 1; overflow: auto; }
.dp-sql-error { color: #c0392b; font-size: 11px; padding: 6px; background: rgba(192,57,43,0.06); border-radius: 3px; }

/* Schema editor */
.dp-schema-wrap { flex: 1; overflow-y: auto; padding: 10px; }
.dp-schema-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.dp-schema-table th {
  padding: 5px 8px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
}
.dp-schema-table td { padding: 5px 8px; border-bottom: 1px solid var(--border-hairline); }

/* ================================================================
   FILES PANEL  (fp-)
   ================================================================ */
.files-panel-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fp-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 12px;
  padding: 24px;
  text-align: center;
}
.fp-empty-icon { font-size: 32px; opacity: 0.2; }
.fp-empty-hint { font-size: 11px; color: var(--text-faint, #a8a09a); }

.fp-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  font-size: 12px;
  color: var(--text-muted);
}

.fp-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  min-height: 0;
}

/* Sidebar tree */
.fp-sidebar {
  width: max-content;
  min-width: 225px;
  max-width: 360px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-surface);
}

.fp-sidebar-header {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-hairline);
  flex-shrink: 0;
}

.fp-search-wrap { flex: 1; position: relative; }
.fp-search-icon {
  position: absolute;
  left: 6px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  font-size: 11px;
}
.fp-search {
  width: 100%;
  padding: 3px 6px 3px 22px;
  font-size: 11px;
  background: var(--bg-inset);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  color: var(--text-primary);
  outline: none;
}
.fp-search:focus { border-color: var(--accent); }

.fp-mini-btn {
  -webkit-appearance: none;
  appearance: none;
  width: 22px; height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 0.12s;
  flex-shrink: 0;
}
.fp-mini-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.fp-tree { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 4px; }
.fp-tree-empty { padding: 12px; font-size: 11px; color: var(--text-muted); font-style: italic; }

.fp-tree-folder { }
.fp-tree-folder-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  transition: background 0.1s;
}
.fp-tree-folder-head:hover { background: var(--bg-hover); }
.fp-chevron {
  font-size: 8px;
  color: var(--text-muted);
  transition: transform 0.15s;
}
.fp-tree-folder.open > .fp-tree-folder-head .fp-chevron { transform: rotate(90deg); }
.fp-tree-folder-body { padding-left: 14px; display: none; }
.fp-tree-section {
  padding: 12px 10px 4px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}
.fp-tree-section + .fp-tree-section { margin-top: 0; }
.fp-tree-folder.open > .fp-tree-folder-body { display: block; }
.fp-tree-icon { font-size: 12px; }
.fp-tree-name { flex: 1; white-space: nowrap; overflow: visible; font-size: 12px; }
.fp-tree-size { font-size: 10px; color: var(--text-muted); }

.fp-tree-file {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text-primary);
  transition: background 0.1s;
}
.fp-tree-file:hover { background: var(--bg-hover); }
.fp-tree-file.active { background: var(--accent-subtle); color: var(--accent); }
.fp-tree-file.modified .fp-tree-name::after { content: ' ●'; font-size: 8px; color: var(--accent); }

.fp-sidebar-footer {
  border-top: 1px solid var(--border-hairline);
  padding: 6px 8px;
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

/* Editor area */
.fp-editor-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.fp-tabs {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.fp-tabs::-webkit-scrollbar { height: 3px; }
.fp-tabs::-webkit-scrollbar-thumb { background: var(--border-subtle); }

.fp-tab {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  border-right: 1px solid var(--border-hairline);
  white-space: nowrap;
  transition: all 0.12s;
  flex-shrink: 0;
}
.fp-tab:hover { background: var(--bg-hover); color: var(--text-primary); }
.fp-tab.active { color: var(--accent); background: var(--bg-base); font-weight: 500; }
.fp-tab.modified { font-style: italic; }

.fp-tab-close {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  font-size: 11px;
  color: var(--text-muted);
  padding: 0;
}
.fp-tab-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.fp-editor-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--border-hairline);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.fp-editor-path { flex: 1; font-size: 10px; color: var(--text-muted); font-family: monospace; }
.fp-editor-lang { font-size: 10px; color: var(--text-muted); }

.fp-action-btn {
  -webkit-appearance: none;
  appearance: none;
  padding: 3px 8px;
  font-size: 11px;
  font-family: inherit;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-primary);
  transition: all 0.12s;
  white-space: nowrap;
}
.fp-action-btn:hover { background: var(--bg-hover); }
.fp-action-danger { color: #c0392b; border-color: rgba(192,57,43,0.3); }
.fp-action-danger:hover { background: rgba(192,57,43,0.08); }

.fp-editor-actions { display: flex; gap: 4px; }

/* Code / Preview toggle */
.fp-view-toggle {
  display: flex;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  overflow: hidden;
  flex-shrink: 0;
}
.fp-toggle-btn {
  -webkit-appearance: none;
  appearance: none;
  padding: 2px 10px;
  font-size: 11px;
  font-family: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.1s, color 0.1s;
}
.fp-toggle-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.fp-toggle-btn.active { background: var(--accent-subtle, rgba(139,92,246,0.15)); color: var(--accent, #8b5cf6); font-weight: 600; }

.fp-editor-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.fp-line-numbers {
  padding: 8px 0;
  text-align: right;
  user-select: none;
  font-family: 'JetBrains Mono', 'Fira Mono', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-faint, #a8a09a);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-hairline);
  min-width: 40px;
  overflow-y: hidden;
  overflow-x: hidden;
  flex-shrink: 0;
}
.fp-line-num { padding: 0 6px; display: block; }

.fp-code-wrap {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  min-height: 0;
}

.fp-textarea {
  flex: 1;
  padding: 8px 12px;
  font-family: 'JetBrains Mono', 'Fira Mono', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  background: var(--bg-base);
  border: none;
  outline: none;
  color: var(--text-primary);
  resize: none;
  tab-size: 2;
  white-space: pre;
  overflow-wrap: normal;
  overflow: auto;
  min-width: 0;
}

.fp-image-preview {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 20px;
  background: var(--bg-inset);
}
.fp-image-preview img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 4px; }

/* ─── Monaco Editor container ───────────────────────────────────────────
   Monaco behöver fixed height för att kunna räkna sin layout. flex:1 + 
   min-height:0 ger den all tillgänglig plats utan att overflow:a parent.
   automaticLayout:true i Monaco-optionerna sköter resize-events.        */
.fp-monaco-container {
  flex: 1;
  min-height: 0;
  min-width: 0;
  position: relative;
  background: var(--bg-surface);
}
.fp-monaco-container .monaco-editor {
  position: absolute !important;
  inset: 0;
}
.fp-monaco-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 13px;
  background: var(--bg-surface);
}

.fp-statusbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 10px;
  border-top: 1px solid var(--border-hairline);
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.fp-spinner {
  width: 14px; height: 14px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ================================================================
   AI CONFIG PANEL  (aicfg-)
   ================================================================ */
.ai-config-panel {
  overflow-y: auto;
  padding: 0;
}

.aicfg-wrap {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding-bottom: 24px;
}

.aicfg-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-muted);
  font-size: 12px;
}

.aicfg-spinner {
  width: 16px; height: 16px;
  border: 2px solid var(--border-subtle);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

.aicfg-error {
  padding: 20px;
  color: #c0392b;
  font-size: 12px;
  background: rgba(192,57,43,0.06);
  border-radius: 4px;
  margin: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* ── Header ──────────────────────────────────────── */
.aicfg-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}

.aicfg-header-left {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}

.aicfg-header-actions {
  display: flex;
  gap: 6px;
}

.aicfg-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ── On/off toggle (label wrapping checkbox) ────── */
.aicfg-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.aicfg-toggle input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
  pointer-events: none;
}

.aicfg-toggle-track {
  display: inline-block;
  width: 32px;
  height: 18px;
  background: var(--border-subtle, rgba(100,85,70,0.2));
  border-radius: 9px;
  position: relative;
  transition: background 0.2s;
  flex-shrink: 0;
}

.aicfg-toggle-track::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  top: 2px; left: 2px;
  transition: left 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}

.aicfg-toggle input:checked ~ .aicfg-toggle-track {
  background: var(--accent);
}

.aicfg-toggle input:checked ~ .aicfg-toggle-track::after {
  left: 16px;
}

.aicfg-toggle-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
}

.aicfg-toggle input:checked ~ .aicfg-toggle-label {
  color: var(--accent);
}

/* ── Sections ────────────────────────────────────── */
.aicfg-sections {
  padding: 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.aicfg-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.aicfg-section-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-secondary);
  padding-bottom: 7px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 2px;
}

/* ── Fields ──────────────────────────────────────── */
.aicfg-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.aicfg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.aicfg-field label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}

.aicfg-hint {
  font-size: 10px;
  font-style: italic;
  color: var(--text-muted);
  font-weight: 400;
}

.aicfg-val {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  min-width: 32px;
}

.aicfg-field input[type="text"],
.aicfg-field input[type="number"],
.aicfg-field select,
.aicfg-field textarea {
  width: 100%;
  padding: 6px 10px;
  font-size: 12px;
  font-family: inherit;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s;
}

.aicfg-field input[type="text"]:focus,
.aicfg-field input[type="number"]:focus,
.aicfg-field select:focus,
.aicfg-field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(107,45,60,0.08);
}

.aicfg-field textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.55;
}

.aicfg-field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

.aicfg-range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 9px;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

/* ── Tools grid ──────────────────────────────────── */
.aicfg-tools-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.aicfg-tool-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg-surface);
  transition: all 0.12s;
  user-select: none;
}

.aicfg-tool-item:hover {
  background: var(--bg-hover);
  border-color: rgba(107,45,60,0.2);
}

.aicfg-tool-item.checked {
  background: var(--accent-subtle, rgba(107,45,60,0.06));
  border-color: rgba(107,45,60,0.3);
}

/* Hide native checkbox, style via .checked class */
.aicfg-tool-check {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  min-width: 14px;
  border: 1.5px solid var(--border-subtle);
  border-radius: 3px;
  background: var(--bg-base);
  cursor: pointer;
  margin-top: 1px;
  transition: all 0.12s;
  position: relative;
  flex-shrink: 0;
}

.aicfg-tool-check:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.aicfg-tool-check:checked::after {
  content: '';
  position: absolute;
  left: 3px; top: 1px;
  width: 5px; height: 8px;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(40deg);
}

.aicfg-tool-info { flex: 1; min-width: 0; }
.aicfg-tool-name { font-size: 11px; font-weight: 500; color: var(--text-primary); }
.aicfg-tool-desc { font-size: 10px; color: var(--text-muted); margin-top: 1px; }

/* ── Permissions (aicfg-checks / aicfg-check-item) ── */
.aicfg-checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.aicfg-check-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  cursor: pointer;
  background: var(--bg-surface);
  transition: all 0.12s;
  user-select: none;
}

.aicfg-check-item:hover {
  background: var(--bg-hover);
  border-color: rgba(107,45,60,0.2);
}

/* checked state driven by JS toggling class — same pattern as tool-item */
.aicfg-check-item:has(input:checked) {
  background: var(--accent-subtle, rgba(107,45,60,0.06));
  border-color: rgba(107,45,60,0.3);
}

.aicfg-check-item input[type="checkbox"] {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  min-width: 14px;
  border: 1.5px solid var(--border-subtle);
  border-radius: 3px;
  background: var(--bg-base);
  cursor: pointer;
  margin-top: 1px;
  transition: all 0.12s;
  position: relative;
  flex-shrink: 0;
}

.aicfg-check-item input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.aicfg-check-item input[type="checkbox"]:checked::after {
  content: '';
  position: absolute;
  left: 3px; top: 1px;
  width: 5px; height: 8px;
  border: 2px solid white;
  border-top: none;
  border-left: none;
  transform: rotate(40deg);
}

.aicfg-check-label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-primary);
}

.aicfg-check-desc {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ── Snippet ─────────────────────────────────────── */
.aicfg-snippet-wrap {
  background: var(--bg-inset);
  border-radius: 4px;
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.aicfg-snippet {
  font-family: 'JetBrains Mono', 'Fira Mono', 'Consolas', monospace;
  font-size: 11px;
  padding: 10px 12px;
  color: var(--text-primary);
  white-space: pre-wrap;
  word-break: break-all;
}

.aicfg-snippet-desc {
  font-size: 10px;
  color: var(--text-muted);
  padding: 4px 12px 8px;
}

.aicfg-copy-btn {
  -webkit-appearance: none;
  appearance: none;
  padding: 3px 8px;
  font-size: 11px;
  font-family: inherit;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-primary);
  transition: all 0.12s;
}
.aicfg-copy-btn:hover { background: var(--bg-hover); }

/* ── Buttons ─────────────────────────────────────── */
.aicfg-btn-save {
  padding: 6px 16px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  border: none;
  border-radius: 4px;
  cursor: pointer;
  color: white;
  transition: filter 0.15s;
}
.aicfg-btn-save:hover { filter: brightness(1.1); }
.aicfg-btn-save:disabled { opacity: 0.6; cursor: not-allowed; }

.aicfg-btn-ghost {
  -webkit-appearance: none;
  appearance: none;
  padding: 6px 12px;
  font-size: 12px;
  font-family: inherit;
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.12s;
}
.aicfg-btn-ghost:hover { background: var(--bg-hover); border-color: var(--border-subtle); }

/* ── Toast ───────────────────────────────────────── */
.aicfg-toast {
  position: sticky;
  top: 48px;
  z-index: 20;
  margin: 0 14px;
  padding: 8px 14px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
  text-align: center;
  background: var(--text-primary);
  color: var(--bg-base);
  animation: toastIn 0.2s ease;
}
.aicfg-toast.success { background: #2d6a4f; color: white; }
.aicfg-toast.error { background: #c0392b; color: white; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-6px); } }

/* ================================================================
   CHAT PREVIEW PANEL
   ================================================================ */
.chat-preview-panel {
  overflow-y: auto;
}


/* ── Design-drawer — Builder-UI:ns design-panel (stylar preview via primitiver) ────── */
.preview-container { position: relative; }
.design-drawer {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: 300px; max-width: 88%;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-default);
  box-shadow: -8px 0 24px rgba(0,0,0,.08);
  transform: translateX(100%);
  transition: transform .22s cubic-bezier(.4,0,.2,1);
  z-index: 40; overflow-y: auto;
}
.design-drawer.open { transform: translateX(0); }
.design-drawer-inner { padding: 11px 13px 13px; }
#design-toggle.active { background: var(--accent-subtle); color: var(--accent); border-color: var(--accent); }

.dp-head { display:flex; align-items:center; justify-content:space-between; margin-bottom:8px; }
.dp-title { font-size:13px; font-weight:600; color:var(--text-primary); }
.dp-close { background:none; border:none; cursor:pointer; color:var(--text-muted); font-size:13px; padding:3px 5px; border-radius:6px; line-height:1; }
.dp-close:hover { background:var(--bg-hover); color:var(--text-primary); }
.dp-target { display:inline-flex; gap:2px; padding:2px; background:var(--bg-inset); border-radius:8px; }
.dp-target-btn { font-size:11px; font-weight:600; padding:3px 10px; border:none; border-radius:6px; background:transparent; color:var(--text-muted); cursor:pointer; line-height:1.4; }
.dp-target-btn:hover { color:var(--text-primary); }
.dp-target-btn.active { background:var(--bg-surface); color:var(--text-primary); box-shadow:0 1px 2px rgba(0,0,0,.08); }
/* Redigera direkt-i-appen (WYSIWYG) — flyttad hit från tab-raden. En full-bredds åtgärds-knapp
   under rubriken. Aktivt (redigeringsläge på) = accent-fylld så det syns att läget är aktivt. */
.dp-edit-btn {
  display:flex; align-items:center; justify-content:center; gap:6px;
  width:100%; margin-bottom:10px; padding:7px 10px;
  font-size:12px; font-weight:600; font-family:inherit;
  color:var(--text-primary); background:var(--bg-elevated);
  border:1px solid var(--border-subtle); border-radius:7px;
  cursor:pointer; transition:all 0.15s;
}
.dp-edit-btn:hover:not(:disabled) { background:var(--bg-hover); border-color:var(--accent, #6b2d3c); }
.dp-edit-btn:disabled { opacity:0.4; cursor:not-allowed; }
.dp-edit-btn.active {
  background:var(--accent, #6b2d3c); color:#fffdf8; border-color:transparent;
}
.dp-edit-btn.active:hover { background:var(--accent-light, #8a4254); }

.dp-group-title { font-size:10px; font-weight:600; letter-spacing:.05em; text-transform:uppercase; color:var(--text-faint); margin:9px 0 4px; }

.dp-presets { display:flex; flex-wrap:wrap; gap:4px; }
.dp-preset { background:var(--bg-elevated); border:1px solid var(--border-subtle); border-radius:5px; padding:3px 8px; font-size:11.5px; color:var(--text-secondary); cursor:pointer; transition:all .12s; }
.dp-preset:hover { border-color:var(--accent); color:var(--accent); background:var(--accent-wash); }
.dp-preset.active { border-color:var(--accent); color:var(--accent); background:var(--accent-subtle); font-weight:600; }

/* Bas — neutralt grundläge, avskilt överst (inte "ett tema bland andra") */
.dp-base-row { margin-bottom:8px; padding-bottom:8px; border-bottom:1px solid var(--border-subtle); }
.dp-base { width:100%; text-align:center; padding:7px 8px; font-size:12px; font-weight:500; }
.dp-base.active { font-weight:600; }
.dp-strength-hint { font-size:9.5px; color:var(--text-faint); text-align:center; margin-top:1px; letter-spacing:.02em; }

.dp-color, .dp-font { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-bottom:4px; font-size:12px; color:var(--text-secondary); }
.dp-color input[type=color] { width:40px; height:24px; border:1px solid var(--border-default); border-radius:5px; background:none; cursor:pointer; padding:1px; }
.dp-cat-label { font-size:10px; text-transform:uppercase; letter-spacing:.06em; color:var(--text-tertiary,var(--text-secondary)); margin:8px 0 3px; opacity:.75; }
.dp-accent-auto { width:24px; height:24px; margin-left:6px; border:1px solid var(--border-default); border-radius:5px; background:none; color:var(--text-secondary); cursor:pointer; font-size:12px; line-height:1; padding:0; flex:none; }
.dp-accent-auto:hover { color:var(--text); border-color:var(--primary); }
.dp-color input[type=color][data-auto] { opacity:.45; }
.dp-font select { flex:0 1 62%; background:var(--bg-elevated); border:1px solid var(--border-subtle); border-radius:5px; padding:3px 7px; font-size:11.5px; color:var(--text-primary); cursor:pointer; }

.dp-slider { margin-bottom:3px; }
.dp-slider-row { display:flex; align-items:baseline; justify-content:space-between; margin-bottom:0; }
.dp-label { font-size:12px; color:var(--text-secondary); }
.dp-val { font-size:10.5px; color:var(--text-faint); font-variant-numeric:tabular-nums; }
.dp-slider input[type=range] { width:100%; height:16px; margin:0; accent-color:var(--accent); cursor:pointer; }

.dp-actions { display:flex; gap:8px; margin-top:12px; }
.dp-actions .btn { flex:1; }
.dp-status { font-size:11px; color:var(--success); min-height:14px; margin-top:6px; text-align:center; }

/* Progressiv exponering — hopfällbara lager (Anpassa / Avancerat) */
.dp-layer { border-top:1px solid var(--border-subtle); margin-top:8px; }
.dp-layer > summary { cursor:pointer; padding:9px 2px; font-size:11px; font-weight:600; letter-spacing:.04em; text-transform:uppercase; color:var(--text-secondary); list-style:none; display:flex; align-items:center; gap:7px; user-select:none; }
.dp-layer > summary::-webkit-details-marker { display:none; }
.dp-layer > summary::before { content:'\25B8'; font-size:10px; color:var(--text-muted); transition:transform .15s; }
.dp-layer[open] > summary::before { transform:rotate(90deg); }
.dp-layer > summary:hover { color:var(--text-primary); }
.dp-layer-body { padding:2px 0 6px; }

/* Ljust / Mörkt-toggle (standard-lagret) */
.dp-lightdark { display:flex; gap:6px; margin:10px 0; }
.dp-ld-btn { flex:1; padding:8px; border:1px solid var(--border-default); background:var(--bg-elevated); color:var(--text-secondary); border-radius:6px; font-size:12px; font-weight:500; font-family:inherit; cursor:pointer; transition:background .12s, border-color .12s, color .12s; }
.dp-ld-btn:hover { border-color:var(--border-strong); color:var(--text-primary); }
.dp-ld-btn.active { background:var(--accent-subtle); border-color:var(--accent); color:var(--accent); font-weight:600; }


/* Modell-listan under sökning: ett <select size=N> renderas som en alltid öppen listruta
   i stället för en dropdown, så träffarna står kvar och filtreras live medan man skriver. */
#settings-model.is-searching {
  overflow-y: auto;
  padding: 4px;
  border-radius: 6px;
}
#settings-model.is-searching option {
  padding: 6px 8px;
  border-radius: 4px;
}
#settings-model.is-searching option:checked {
  background: var(--primary, #2563eb);
  color: #fff;
}
