/* KAI – schlankes UI. Alle IDs/Klassen aus app.js bleiben erhalten. */
:root {
  /* 5D Brandbook 2022 */
  --brand-red: #9b0230;      /* Pantone 207 C */
  --brand-red-dark: #7d0227;
  --brand-red-faint: #fdf2f5;
  --brand-teal: #69C9BA;
  --brand-blue: #0065A1;
  --brand-orange: #FF6B00;

  --grey-950: #111111;
  --grey-900: #1a1a1a;
  --grey-700: #3d3d3d;
  --grey-500: #6b7480;
  --grey-400: #9aa3ad;
  --grey-300: #d0d4d9;
  --grey-200: #e8eaed;
  --grey-100: #f4f6f8;
  --grey-50:  #fafbfc;
  --white:    #ffffff;

  --sidebar-width: 280px;
  --sidebar-bg: #faf8f8;
  --sidebar-border: #ecdde1;

  --font-ui: 'Open Sans', Arial, sans-serif;
  --font-display: 'Roboto Slab', Georgia, serif;
  --font-mono: Consolas, 'Courier New', monospace;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --shadow: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.07);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.25);
  --shadow-focus: 0 0 0 3px rgba(155, 2, 48, 0.15);

  /* Semantische Tokens (hell) */
  --bg: var(--white);
  --bg-alt: var(--grey-50);
  --tile: var(--grey-200);
  --card-bg: var(--white);
  --text: var(--grey-900);
  --text-2: var(--grey-700);
  --text-muted: var(--grey-500);
  --text-faint: var(--grey-400);
  --border: var(--grey-200);
  --accent: var(--brand-red);
  --accent-hover: var(--brand-red-dark);
  --accent-text: var(--brand-red);
  --accent-soft: var(--brand-red-faint);
  --accent-contrast: #ffffff;
  --bubble-user: var(--brand-red);
  --bubble-assistant: var(--white);
  --ok: #22c55e;
  --ok-text: #16a34a;
}

[data-theme="dark"] {
  --bg: #161920;
  --bg-alt: #1e2230;
  --sidebar-bg: #1a1d26;
  --sidebar-border: #2b2f3e;
  --tile: #2b2f3e;
  --card-bg: #1e2230;
  --text: #e4e6ed;
  --text-2: #c3c8d2;
  --text-muted: #8b95a4;
  --text-faint: #5c6472;
  --border: #2b2f3e;
  --accent-text: #ff8ca3;
  --accent-soft: rgba(155, 2, 48, 0.15);
  --bubble-assistant: #232736;
  --shadow: 0 1px 3px rgba(0,0,0,0.25);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.30);
  --shadow-lg: 0 4px 20px rgba(0,0,0,0.40);
  --shadow-focus: 0 0 0 3px rgba(155, 2, 48, 0.25);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
::placeholder { color: var(--text-faint); }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--grey-300); border-radius: 8px; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #2b2f3e; }
::-webkit-scrollbar-track { background: transparent; }
.icon { width: 16px; height: 16px; flex-shrink: 0; }

.layout { display: flex; height: 100vh; }

/* ------------------------------------------------------------- Sidebar */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  min-height: 0;
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px 18px; border-bottom: 1px solid var(--sidebar-border); flex-shrink: 0; }
.brand-logo { height: 32px; width: auto; flex-shrink: 0; object-fit: contain; padding: 3px; box-sizing: content-box; }
[data-theme="dark"] .brand-logo { background: #fff; border-radius: 6px; }
.brand-text { min-width: 0; }
.brand-title { font-family: var(--font-display); font-weight: 700; font-size: 14px; line-height: 1.2; color: var(--accent-text); }
[data-theme="dark"] .brand-title { color: var(--text); }
.brand-subtitle { font-size: 10px; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-muted); margin-top: 2px; }

.new-chat-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin: 14px 14px 0; padding: 11px 16px; flex-shrink: 0;
  border: 1px solid var(--accent); border-radius: var(--radius-sm);
  background: transparent; color: var(--accent-text);
  font-weight: 600; font-size: 13px; letter-spacing: 0.04em;
  transition: background .15s, color .15s;
}
.new-chat-btn:hover { background: var(--accent); color: var(--accent-contrast); }

.history-label {
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--text-faint); padding: 18px 20px 10px;
}
.my-agents-section .history-label { margin-top: 24px; }
.my-agents-section + .history-label { margin-top: 22px; }
.history-list { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; padding: 0 14px; }
.history-empty { color: var(--text-faint); font-size: 13px; margin: 6px 8px; }
.history-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px; border-radius: 8px; font-size: 13.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.history-item:hover { background: var(--tile); }
.history-item.active { background: var(--tile); color: var(--accent-text); }
.history-item-badge {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 8px;
  background: var(--tile); display: flex; align-items: center; justify-content: center;
  font-size: 14px; color: var(--text-muted);
}
.history-item.active .history-item-badge { background: var(--accent-soft); }
.history-item-badge:empty {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='1.8' stroke-linejoin='round'%3E%3Cpath d='M20 4H4v12h4v4l5-4h7z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: center; background-size: 14px;
}
.history-item > span:nth-child(2) { flex: 1; min-width: 0; }
.history-item .del-btn { opacity: 0; border: none; background: none; color: var(--text-faint); font-size: 12px; padding: 4px; border-radius: 6px; }
.history-item:hover .del-btn { opacity: 1; }
.history-item .del-btn:hover { color: var(--accent-text); background: var(--accent-soft); }

/* Konfiguration-Eintrag (nur 5D User / Demo-Admin) */
#config-mode-btn.mode-switch-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 9px 8px; margin: 8px 0; border: none; border-radius: 8px;
  background: transparent; color: var(--text-2); font-size: 13.5px; font-weight: 600; text-align: left;
}
#config-mode-btn.mode-switch-btn:hover { background: var(--tile); }
#config-mode-btn.mode-switch-btn.active { background: var(--accent-soft); color: var(--accent-text); }

.sidebar-footer { border-top: 1px solid var(--sidebar-border); padding: 14px 14px 18px; margin-top: auto; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-soft); border: 1.5px solid rgba(155,2,48,0.25); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 600; font-size: 13px;
}
.user-meta { flex: 1; min-width: 0; }
.user-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 10px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; color: var(--accent-text); margin-top: 1px; }
.logout-btn {
  width: 32px; height: 32px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--card-bg); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
}
.logout-btn:hover { color: var(--accent-text); border-color: var(--accent); }

/* "Meine Agenten" */
.my-agents-list { display: flex; flex-direction: column; gap: 2px; }
.agent-chip {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 7px 8px; border: none; border-radius: 8px; background: none;
  font-size: 13.5px; font-weight: 600; text-align: left;
}
.agent-chip:hover { background: var(--tile); }
.agent-chip > span:first-child {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 8px; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; font-size: 15px;
}

/* ---------------------------------------------------------------- Main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 62px; flex-shrink: 0; box-shadow: var(--shadow);
  display: flex; justify-content: space-between; align-items: center;
  padding: 0 24px; border-bottom: 1px solid var(--border);
}
.topbar-title { font-family: var(--font-display); font-weight: 700; font-size: 17px; line-height: 1.2; }
.topbar-status { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); display: inline-block; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-actions > button, .demo-role-select {
  height: 34px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--card-bg); color: var(--text-2);
}
.topbar-actions > button { width: 34px; display: flex; align-items: center; justify-content: center; padding: 0; }
.topbar-actions > button:hover { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.demo-role-select { padding: 0 10px; font-size: 12.5px; font-weight: 600; }
.usage-badge { font-size: 12px; color: var(--text-muted); white-space: nowrap; padding: 0 10px; }
.usage-badge:empty { display: none; }
.usage-badge.limit-near { color: #b45309; }
.usage-badge.limit-reached { color: var(--accent-text); font-weight: 600; }
.role-demo #usage-badge, .role-demo #settings-btn, .role-demo #playbook-btn, .role-demo #config-mode-btn { display: none; }

#playbook-btn { position: relative; }
.pending-badge {
  position: absolute; top: -6px; right: -6px;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 18px;
  text-align: center; border: 2px solid var(--bg);
}

/* Hell/Dunkel als Schiebeschalter */
#theme-toggle { width: auto !important; border-radius: 99px !important; background: var(--card-bg) !important; position: relative; gap: 6px; padding: 0 8px !important; margin-left: 4px; }
#theme-toggle .icon { width: 14px; height: 14px; position: relative; z-index: 1; }
#theme-toggle .icon-sun { color: #f59e0b; }
#theme-toggle .icon-moon { color: var(--text-faint); }
[data-theme="dark"] #theme-toggle .icon-sun { color: var(--text-faint); }
[data-theme="dark"] #theme-toggle .icon-moon { color: var(--text); }
#theme-toggle .toggle-knob {
  position: relative; width: 32px; height: 18px; border-radius: 99px; background: var(--grey-300); flex-shrink: 0;
}
#theme-toggle .toggle-knob::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.2); transition: transform 220ms cubic-bezier(.4,0,.2,1);
}
[data-theme="dark"] #theme-toggle .toggle-knob { background: var(--accent); }
[data-theme="dark"] #theme-toggle .toggle-knob::after { transform: translateX(14px); }
[data-theme="dark"] #theme-toggle .icon-moon { color: #818cf8; }

/* ------------------------------------------------------------- Welcome */
.chat-scroll { flex: 1; overflow-y: auto; padding: 28px 24px 12px; }
.welcome { max-width: 760px; margin: 60px auto 0; text-align: left; }
.welcome h1 { font-family: var(--font-display); font-size: 44px; line-height: 1.1; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 22px; }
.welcome h1 em { color: var(--accent-text); font-style: italic; font-weight: 400; }
.welcome-sub { max-width: 520px; font-size: 15px; line-height: 1.7; font-weight: 300; color: var(--text-muted); margin: 0 0 32px; text-wrap: pretty; }
.suggestion-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; text-align: left; }
.suggestion-card {
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: 18px 16px 16px; min-height: 140px; display: flex; flex-direction: column; gap: 8px;
  text-align: left; transition: border-color .15s;
}
.suggestion-card:hover { border-color: var(--accent); box-shadow: var(--shadow-sm); transform: translateY(-2px); }
.suggestion-kicker { font-size: 9.5px; font-weight: 400; letter-spacing: 0.28em; text-transform: uppercase; color: var(--text-faint); }
.suggestion-title { font-family: var(--font-display); font-weight: 400; font-size: 15px; line-height: 1.3; }
.suggestion-desc { margin-top: auto; font-size: 12px; line-height: 1.55; color: var(--text-muted); }

/* ------------------------------------------------------------ Messages */
.messages { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.msg.assistant { gap: 12px; align-items: flex-start; }
/* Assistenten-Avatar: rotes KAI-Logo auf weißem Kreis (nie die Variante mit roten Augen) */
.msg.assistant::before {
  content: ""; width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%; margin-top: 2px;
  background: #fff url("/static/logo-mark.png") center / 21px no-repeat;
  border: 1px solid var(--border);
}
.msg-bubble { max-width: 78%; padding: 11px 15px; border-radius: var(--radius-md); white-space: pre-wrap; line-height: 1.55; font-size: 13.5px; }
.msg.user .msg-bubble { background: var(--bubble-user); color: #fff; border-radius: var(--radius-md); border-bottom-right-radius: 3px; box-shadow: var(--shadow); }
.msg.assistant .msg-bubble { max-width: none; flex: 1; min-width: 0; background: var(--bubble-assistant); border: 1px solid var(--border); border-radius: var(--radius-md); border-bottom-left-radius: 3px; padding: 12px 16px; white-space: normal; box-shadow: var(--shadow); }
.msg.error .msg-bubble { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.msg-bubble p { margin: 0 0 8px; }
.msg-bubble p:last-child { margin-bottom: 0; }
.msg-bubble ol, .msg-bubble ul { margin: 0 0 8px; padding-left: 22px; }
.msg-bubble ol:last-child, .msg-bubble ul:last-child { margin-bottom: 0; }
.msg-bubble li { margin-bottom: 3px; }
.msg-bubble code { background: rgba(0,0,0,0.06); padding: 2px 5px; border-radius: 4px; font-size: 12.5px; font-family: var(--font-mono); }
[data-theme="dark"] .msg-bubble code { background: rgba(255,255,255,0.08); }
.msg.user .msg-bubble code { background: rgba(255,255,255,0.22); }
.usage-footnote { margin-top: 12px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 11.5px; color: var(--text-faint); }
.thinking { color: var(--text-muted); font-style: italic; }
.thinking::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 8px; border-radius: 50%; background: var(--accent); vertical-align: middle; animation: kai-pulse 1s ease-in-out infinite; }
@keyframes kai-pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
.msg-chart { max-width: 820px; margin: -6px 0 0 44px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 18px 20px 14px; }
.msg-chart > div:first-child { font-family: var(--font-display); font-weight: 600; font-size: 14px; margin-bottom: 14px !important; }
.msg-chart canvas { max-height: 320px; }

/* ------------------------------------------------------------ Composer */
.chat-input-bar {
  flex-shrink: 0; width: 100%;
  border-top: 1px solid var(--border);
  padding: 12px 20px 14px; margin: 0;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.mode-bar { width: 100%; max-width: 880px; display: flex; align-items: center; gap: 10px; }
.mode-bar-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2); }
.mode-bar-label .icon { width: 14px; height: 14px; color: var(--accent-text); }
.mode-bar-hint { font-size: 12px; color: var(--text-faint); margin-left: 4px; }
.mode-switch { display: flex; gap: 2px; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--sidebar-bg); }
.mode-switch .mode-switch-btn {
  border: none; border-radius: 6px; padding: 5px 12px;
  background: transparent; color: var(--text-muted); font-size: 12.5px; font-weight: 500;
}
.mode-switch .mode-switch-btn:hover { color: var(--text); }
.mode-switch .mode-switch-btn.active { background: var(--bg); color: var(--accent-text); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.chat-input-row { width: 100%; max-width: 880px; display: flex; gap: 10px; }
.chat-input-row input {
  flex: 1; height: 44px; padding: 0 14px;
  border-radius: var(--radius-md); border: 1px solid var(--grey-300);
  background: var(--bg-alt); color: var(--text); font-size: 14px; outline: none;
}
.chat-input-row input:focus { border-color: var(--accent); background: var(--card-bg); box-shadow: var(--shadow-focus); }
#send-btn {
  height: 44px; padding: 0 20px; border: none; border-radius: var(--radius-md);
  background: var(--accent); color: var(--accent-contrast); font-family: var(--font-display); font-weight: 600; font-size: 13.5px;
  display: flex; align-items: center; gap: 8px;
}
#send-btn:hover { background: var(--accent-hover); }
#send-btn:disabled { opacity: .6; cursor: default; }

/* ------------------------------------------------------- Konfiguration */
.config-view { flex: 1; overflow-y: auto; padding: 36px 40px; background: var(--sidebar-bg); }
[data-theme="dark"] .config-view { background: var(--bg); }
.config-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 22px; }
.config-header h2 { margin: 0 0 6px; font-family: var(--font-display); font-size: 30px; line-height: 1.15; }
.config-header .settings-hint { margin: 0; max-width: 640px; font-size: 14.5px; line-height: 1.5; text-wrap: pretty; }
.config-header .settings-hint code { background: var(--tile); padding: 1px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: .9em; }
.config-header .new-chat-btn { width: auto; height: 42px; padding: 0 18px; background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); flex-shrink: 0; }
.config-header .new-chat-btn:hover { background: var(--accent-hover); }
.config-view .playbook-tabs { margin: 0 0 22px; }
.config-tab-panel .config-header { margin-bottom: 18px; align-items: center; }
.agent-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; }
.agent-card {
  border: 1px solid var(--border); border-radius: 14px; background: var(--card-bg);
  padding: 20px; display: flex; flex-direction: column; gap: 16px;
}
.agent-card-head { display: flex; align-items: flex-start; gap: 12px; }
.agent-card-icon {
  width: 42px; height: 42px; flex-shrink: 0; border-radius: 10px; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; font-size: 20px; line-height: 1;
}
.agent-card-head > div { flex: 1; min-width: 0; }
.agent-card-name { font-family: var(--font-display); font-weight: 600; font-size: 16px; line-height: 1.25; }
.agent-card-desc { font-size: 13px; line-height: 1.45; color: var(--text-muted); margin-top: 3px; }
.agent-card-predefined-badge {
  font-size: 11px; font-weight: 600; color: var(--accent-text); border: 1px solid var(--accent);
  border-radius: 999px; padding: 2px 9px; white-space: nowrap;
}
.agent-flow { display: flex; align-items: center; gap: 8px; font-size: 12.5px; background: var(--sidebar-bg); border-radius: 10px; padding: 10px; }
[data-theme="dark"] .agent-flow { background: var(--bg); }
.agent-flow-node { border: 1px solid var(--border); background: var(--card-bg); border-radius: 7px; padding: 6px 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-flow-arrow { color: var(--text-faint); flex-shrink: 0; }
.agent-card-meta { font-size: 12.5px; color: var(--text-muted); line-height: 1.6; }
.agent-card-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.agent-release-toggle { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-2); margin-right: auto; cursor: pointer; }
.agent-release-toggle input { appearance: none; width: 34px; height: 20px; margin: 0; border-radius: 10px; background: var(--border); position: relative; cursor: pointer; transition: background .15s; }
.agent-release-toggle input::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.agent-release-toggle input:checked { background: var(--accent); }
.agent-release-toggle input:checked::after { left: 16px; }

.connector-slug-badge {
  font-family: var(--font-mono); font-size: 11.5px; color: var(--accent-text);
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 5px; padding: 2px 7px; cursor: pointer;
}
.connector-slug-badge:hover { border-color: var(--accent); }
.connector-slug-badge[draggable="true"] { cursor: grab; }
.connector-slug-badge[draggable="true"]:active { cursor: grabbing; }

/* ------------------------------------------------------------ Overlays */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(28, 25, 23, 0.45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
}
.settings-modal {
  background: var(--card-bg); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 580px; max-width: 92vw; max-height: 88vh; overflow-y: auto; overflow-x: hidden;
  padding: 22px 26px 24px;
}
.playbook-modal { width: 720px; }
.wide-modal { width: 720px; }
.settings-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.settings-header h2 { margin: 0; font-family: var(--font-display); font-size: 21px; line-height: 1.2; }
.icon-btn { width: 32px; height: 32px; border: none; border-radius: 8px; background: var(--bg-alt); color: var(--text-muted); font-size: 20px; line-height: 1; display: flex; align-items: center; justify-content: center; }
.icon-btn:hover { color: var(--text); }

fieldset { border: none; border-top: 1px solid var(--border); border-radius: 0; margin: 0 0 22px; padding: 16px 0 0; }
fieldset:first-of-type { border-top: none; padding-top: 0; }
legend { padding: 0 8px 0 0; color: var(--text-faint); font-size: 10.5px; font-weight: 600; letter-spacing: 0.14em; text-transform: uppercase; }
legend .settings-hint { display: inline; font-size: 11px; letter-spacing: 0; text-transform: none; font-weight: 400; margin: 0; }
#settings-form label, #agent-form label, #connector-form label {
  display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 12px;
}
#settings-form input, #settings-form select,
#agent-form input, #agent-form select, #agent-form textarea,
#connector-form input, #connector-form select,
.agent-field-search {
  width: 100%; height: 40px; padding: 0 12px; font-weight: 400; font-size: 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--bg-alt); color: var(--text); outline: none;
}
#agent-form textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
#settings-form input:focus, #agent-form input:focus, #agent-form textarea:focus, #connector-form input:focus, .agent-field-search:focus { border-color: var(--accent); background: var(--card-bg); }
.provider-fields { display: flex; flex-direction: column; }
.secondary-btn {
  height: 32px; padding: 0 12px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  background: var(--card-bg); color: var(--text); border: 1px solid var(--border); margin-bottom: 6px;
}
.secondary-btn:hover { border-color: var(--text-faint); }
.settings-hint { color: var(--text-muted); font-size: 12.5px; line-height: 1.5; margin: 0 0 10px; }
.usage-stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 12px; font-size: 12px; color: var(--text-muted);
}
.usage-stats div { background: var(--bg-alt); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; text-align: left; }
.usage-stats div span { display: block; font-family: var(--font-display); font-weight: 600; font-size: 20px; line-height: 1.2; color: var(--text); margin: 4px 0 2px; }
.settings-actions { display: flex; justify-content: flex-end; align-items: center; gap: 14px; padding-top: 6px; }
.settings-saved { color: var(--ok-text); font-size: 13px; }
.settings-actions button[type="submit"] {
  height: 40px; padding: 0 20px; border: none; border-radius: 9px;
  background: var(--accent); color: var(--accent-contrast); font-weight: 700; font-size: 14px;
}
.settings-actions button[type="submit"]:hover { background: var(--accent-hover); }

/* Tabs (Playbook + Konfiguration) */
.playbook-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.playbook-tab {
  border: none; background: none; padding: 10px 12px; font-size: 13.5px; font-weight: 500;
  color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.playbook-tab:hover { color: var(--text); }
.playbook-tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.pending-list { display: flex; flex-direction: column; gap: 14px; max-height: 55vh; overflow-y: auto; }
.pending-empty { color: var(--text-muted); font-size: 13px; padding: 12px 0; }
.pending-item { border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; background: var(--card-bg); }
.pending-item-meta { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.pending-item-meta::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }
.pending-item-note { font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; margin-bottom: 12px; }
.pending-item-actions { display: flex; gap: 8px; }
.pending-item-actions button { height: 34px; padding: 0 14px; border: none; border-radius: 8px; font-size: 13px; font-weight: 600; }
.approve-btn { background: var(--accent); color: #fff; }
.approve-btn:hover { background: var(--accent-hover); }
.reject-btn { background: var(--card-bg); color: var(--text-2); border: 1px solid var(--border) !important; }
.reject-btn:hover { border-color: var(--text-faint) !important; }
.playbook-files-layout { display: flex; gap: 12px; max-height: 55vh; }
.playbook-file-list { width: 190px; flex-shrink: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.playbook-file-list button { text-align: left; border: 1px solid transparent; background: none; padding: 7px 10px; border-radius: 8px; font-size: 12.5px; color: var(--text); }
.playbook-file-list button:hover { background: var(--tile); }
.playbook-file-list button.active { background: var(--tile); font-weight: 600; color: var(--accent-text); }
.playbook-file-content { flex: 1; overflow-y: auto; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-family: var(--font-mono); font-size: 12px; line-height: 1.5; white-space: pre-wrap; margin: 0; }
.pending-item .playbook-file-content { margin-bottom: 12px; }

/* Agenten-Editor / Connector-Editor */
.agent-template-picker { margin-bottom: 6px; }
.agent-template-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.agent-template-card {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; background: var(--card-bg);
}
.agent-template-card:hover { border-color: var(--accent); }
.agent-template-card > span:first-child { width: 36px; height: 36px; flex-shrink: 0; border-radius: 9px; background: var(--accent-soft); display: flex; align-items: center; justify-content: center; font-size: 18px; }
.agent-template-card strong { display: block; font-size: 14px; }
.agent-template-card div span { font-size: 12.5px; color: var(--text-muted); }
.agent-connector-checklist { display: flex; flex-direction: column; gap: 6px; }
.agent-connector-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-alt); font-size: 13.5px;
}
.agent-connector-item input { margin: 0; accent-color: var(--accent); }
.agent-connector-item .agent-connector-name { flex: 1; font-weight: 600; }
.agent-connector-item .agent-connector-desc { color: var(--text-muted); font-size: 12px; font-weight: 400; }
.agent-field-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.agent-field-picker select { flex: 1; min-width: 0; height: auto !important; padding: 4px !important; }
.agent-field-picker select option { padding: 5px 8px; border-radius: 4px; }
.agent-field-picker button { flex-shrink: 0; white-space: nowrap; margin-bottom: 0; height: auto; }
.agent-permissions-hint { margin-top: 0; margin-bottom: 8px; }
.agent-permissions-wrap { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.agent-permissions-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.agent-permissions-table th {
  text-align: left; font-size: 10.5px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-faint);
  padding: 9px 12px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card-bg);
}
.agent-permissions-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.agent-permissions-table tr:last-child td { border-bottom: none; }
.agent-permissions-connector { color: var(--text-muted); white-space: nowrap; }
.agent-permissions-field { font-family: var(--font-mono); font-size: 12px; }
.agent-permissions-remove { border: none; background: none; color: var(--text-faint); font-size: 16px; }
.agent-permissions-remove:hover { color: var(--accent-text); }
#agent-permissions-empty, #connector-permissions-empty { padding: 14px; text-align: center; margin: 0; }
.perm-badge { display: inline-flex; align-items: center; gap: 4px; border: none; border-radius: 999px; padding: 4px 10px; font-size: 11.5px; font-weight: 600; }
.perm-badge.perm-read { background: var(--accent-soft); color: var(--accent-text); }
.perm-badge.perm-write { background: #fef3c7; color: #b45309; }
.perm-badge.perm-hidden { background: var(--tile); color: var(--text-muted); }
[data-theme="dark"] .perm-badge.perm-write { background: #3b2a10; color: #fcd34d; }

/* --------------------------------------------------------------- Login */
.login-body { display: grid; grid-template-columns: 1fr 1fr; min-height: 100vh; background: var(--bg); }
.login-hero {
  position: relative; overflow: hidden; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; padding: 60px 56px;
}
/* Dekoratives Kreispfeil-Zeichen des 5D Instituts, als SVG nachgezeichnet (siehe
   logo-circular-arrow.svg) - das Original-PNG ist nur 261x238px und wuerde hier unscharf. */
.login-hero-mark {
  position: absolute; right: -96px; bottom: -104px; width: 440px; height: 401px;
  background: url("/static/logo-circular-arrow.svg") no-repeat center / contain;
  opacity: 0.18; pointer-events: none; user-select: none;
}
.login-hero-inner { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 28px; max-width: 420px; }
/* Rotes KAI-Logo auf weißer Kachel – nie invertiert, nie die Variante mit roten Augen */
.login-hero-logo { height: 50px; width: auto; object-fit: contain; }
.login-hero-logo-tile {
  align-self: flex-start; width: 96px; height: 96px; border-radius: 26px; background: #fff;
  display: grid; place-items: center;
  box-shadow: 0 0 0 9px rgba(255, 255, 255, 0.12), 0 12px 32px rgba(0, 0, 0, 0.18);
}
.login-hero-rule { width: 60px; height: 1px; background: rgba(255, 255, 255, 0.35); }
.login-hero h1 { margin: 0; font-family: var(--font-display); font-size: clamp(30px, 3vw, 42px); line-height: 1.12; font-weight: 700; letter-spacing: -0.01em; }
.login-hero h1 em { font-style: italic; font-weight: 400; color: rgba(255, 255, 255, 0.75); }
.login-hero p { margin: 0; font-size: 14px; font-weight: 300; line-height: 1.7; color: rgba(255, 255, 255, 0.72); text-wrap: pretty; }
.login-panel { display: flex; align-items: center; justify-content: center; padding: 60px 56px; background: var(--white); }
.login-card { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 24px; }
.login-card-head { display: flex; align-items: center; gap: 14px; margin-bottom: 6px; }
.login-logo { height: 36px; width: auto; object-fit: contain; }
.login-card h1 { margin: 0; font-family: var(--font-display); font-size: 20px; font-weight: 700; line-height: 1.2; }
.login-subtitle { color: var(--text-muted); font-size: 12px; margin: 2px 0 0; }
.login-field { display: flex; flex-direction: column; gap: 8px; }
.login-label { font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2); }
.login-error { color: var(--accent-text); background: var(--accent-soft); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; margin: 0; }
.login-card input[type="password"] {
  padding: 12px 14px; border-radius: var(--radius-sm); border: 1px solid var(--grey-300);
  background: var(--grey-50); font-size: 14px; outline: none;
}
.login-card input[type="password"]:focus { border-color: var(--accent); background: var(--white); box-shadow: 0 0 0 3px rgba(155,2,48,0.18); }
.login-card button[type="submit"] {
  padding: 14px 20px; border: none; border-radius: var(--radius-sm); margin-top: 6px;
  background: var(--accent); color: #fff; font-family: var(--font-display); font-weight: 600; font-size: 14px; letter-spacing: 0.04em;
}
.login-card button[type="submit"]:hover { background: var(--accent-hover); }
.login-role-switch { display: flex; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 10px; background: var(--sidebar-bg); }
.login-role-btn { flex: 1; border: none; border-radius: 7px; padding: 10px; background: transparent; color: var(--text-muted); font-size: 14px; font-weight: 500; }
.login-role-btn.active { background: var(--card-bg); color: var(--accent-text); font-weight: 600; box-shadow: 0 1px 2px rgba(28, 25, 23, 0.08); }
.login-rule { height: 1px; background: var(--border); margin-top: 6px; }
.login-footnote { margin: 0; text-align: center; font-size: 12px; line-height: 1.6; color: var(--text-muted); padding-top: 8px; border-top: 1px solid var(--grey-100); text-wrap: pretty; }
@media (max-width: 900px) {
  .login-body { grid-template-columns: 1fr; }
  .login-hero { min-height: 280px; padding: 48px 32px; }
  .login-hero-inner { gap: 16px; }
  .login-hero-logo { height: 40px; }
  .login-hero-logo-tile { width: 72px; height: 72px; border-radius: 20px; box-shadow: 0 0 0 7px rgba(255,255,255,0.12); }
  .login-hero-logo { height: 38px; }
  .login-hero p, .login-hero-rule { display: none; }
  .login-hero-mark { width: 330px; height: 300px; right: -90px; bottom: -90px; }
}
