/* Agent Studio — Design nach design.png (warmes Braun/Creme, Light + Dark). */
:root {
  --sidebar-bg: #2b1d13;
  --sidebar-bg-2: #241811;
  --sidebar-text: #d9c7b6;
  --sidebar-text-dim: #9c8571;
  --sidebar-active: #3a2717;
  --sidebar-active-text: #f4ede4;

  --bg: #f7f1ea;
  --surface: #ffffff;
  --surface-2: #faf5ef;
  --card: #fbf6f0;
  --border: #ece0d3;
  --border-strong: #e0d0be;
  --text: #2c2218;
  --text-dim: #7c6a58;
  --muted: #9a8a78;

  --accent: #7b4a24;
  --accent-hover: #653c1d;
  --accent-soft: #f0e4d6;
  --accent-text: #ffffff;

  --ok: #3f7d4e;
  --warn: #b5852a;
  --err: #b4462f;
  --idle: #9a8a78;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 4px 16px rgba(60, 40, 20, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
:root[data-theme="dark"] {
  --sidebar-bg: #1c130d;
  --sidebar-bg-2: #170f0a;
  --sidebar-text: #cbb6a2;
  --sidebar-active: #33231697;
  --sidebar-active-text: #f6efe6;

  --bg: #17110c;
  --surface: #211710;
  --surface-2: #1c130d;
  --card: #241a12;
  --border: #362619;
  --border-strong: #43301f;
  --text: #efe4d7;
  --text-dim: #b7a48f;
  --muted: #8f7c68;

  --accent: #c8895a;
  --accent-hover: #d8a06f;
  --accent-soft: #33231699;
  --accent-text: #1c130d;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 18px rgba(0,0,0,.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

/* ---------- Auth popup ---------- */
.auth-page { overflow: hidden; }
.auth-ghost { position: fixed; inset: 0; display: grid; grid-template-columns: 248px 1fr; grid-template-rows: 78px 1fr; background: var(--bg); }
.auth-ghost::before { content: "◈  Agent Studio"; grid-row: 1 / 3; padding: 29px 25px; color: #f4ede4; font-size: 16px; font-weight: 700; background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-2)); }
.auth-ghost::after { content: "Agents"; padding: 25px 28px; border-bottom: 1px solid var(--border); color: var(--text); font-size: 22px; font-weight: 700; }
.auth-ghost div { grid-column: 2; width: min(320px, 30%); height: 136px; margin: 38px 0 0 28px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.auth-ghost div:nth-child(2) { margin-left: calc(30% + 48px); }
.auth-ghost div:nth-child(3) { margin-top: 198px; }
.auth-ghost div:nth-child(4) { margin-top: 198px; margin-left: calc(30% + 48px); }
.auth-overlay { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; padding: 22px; background: rgba(31, 21, 13, .56); backdrop-filter: blur(7px); }
.auth-card { width: 420px; max-width: 100%; padding: 30px; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); box-shadow: 0 24px 70px rgba(28, 17, 9, .34); animation: auth-enter .22s ease-out; }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 24px; color: var(--text); font-weight: 700; font-size: 15px; }
.auth-brand .brand-logo { width: 30px; height: 30px; }
.auth-card h1 { margin: 0 0 7px; font-size: 24px; letter-spacing: -.3px; }
.auth-card > p { margin: 0 0 24px; color: var(--text-dim); }
.auth-form { display: flex; flex-direction: column; gap: 8px; }
.auth-form label { margin-top: 7px; color: var(--text); font-size: 13px; font-weight: 600; }
.auth-form input { width: 100%; min-height: 42px; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: 8px; outline: none; background: var(--bg); color: var(--text); font: inherit; }
.auth-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-form .btn { width: 100%; margin-top: 16px; min-height: 43px; display: flex; align-items: center; justify-content: center; gap: 8px; }
.auth-form .btn span { font-size: 18px; line-height: 1; }
.auth-message { margin: 0 0 16px; padding: 10px 12px; border-radius: 8px; color: var(--err); background: color-mix(in srgb, var(--err) 10%, transparent); font-size: 13px; }
.auth-message.success { color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.auth-back { margin: 12px auto 0; font-size: 13px; }
@keyframes auth-enter { from { opacity: 0; transform: translateY(8px) scale(.985); } to { opacity: 1; transform: none; } }

/* ---------- Layout ---------- */
#app { display: flex; min-height: 100vh; }

.sidebar {
  width: 248px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-bg), var(--sidebar-bg-2));
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  padding: 18px 14px;
  transition: width .18s ease;
}
.sidebar.collapsed { width: 68px; }
.sidebar.collapsed .brand-text, .sidebar.collapsed .nav-item span,
.sidebar.collapsed .user-meta { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; }

.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 18px; }
.brand-logo {
  width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  background: radial-gradient(circle at 30% 30%, #a9673a, #6f3f1e);
  display: grid; place-items: center; color: #fff; font-weight: 700;
}
.brand-text b { display: block; color: var(--sidebar-active-text); font-size: 15px; }
.brand-text small { color: var(--sidebar-text-dim); font-size: 12px; }

.nav { display: flex; flex-direction: column; gap: 3px; margin-top: 6px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 9px;
  color: var(--sidebar-text); font-size: 14px;
  border: none; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: #ffffff0d; color: var(--sidebar-active-text); }
.nav-item.active { background: var(--sidebar-active); color: var(--sidebar-active-text); font-weight: 600; }
.nav-item .ic { width: 18px; text-align: center; opacity: .85; }
.nav-item.placeholder { opacity: .5; }

.user-menu { position: relative; margin-top: 10px; }
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 10px; background: #ffffff0a;
  width: 100%; border: 0; color: inherit; text-align: left;
}
.user-card:hover { background: #ffffff14; }
.user-menu-popover { position: absolute; bottom: calc(100% + 8px); left: 0; width: 190px; padding: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); z-index: 70; }
.user-menu-popover a, .user-menu-popover button { display: block; width: 100%; padding: 9px 10px; border: 0; border-radius: 7px; background: none; color: var(--text); text-align: left; font-size: 13px; }
.user-menu-popover a:hover, .user-menu-popover button:hover { background: var(--accent-soft); color: var(--accent); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: #8a5a34; display: grid; place-items: center; color: #fff; font-size: 12px; }
.user-meta b { display: block; color: var(--sidebar-active-text); font-size: 13px; }
.user-meta small { color: var(--sidebar-text-dim); font-size: 11px; }
.build-version { width: 100%; margin-top: 9px; color: var(--sidebar-text-dim); font-size: 10px; line-height: 1.35; text-align: center; }
.sidebar.collapsed .build-version { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 18px 28px; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.topbar .burger { background: none; border: none; font-size: 18px; color: var(--text-dim); padding: 4px 8px; border-radius: 8px; }
.topbar .burger:hover { background: var(--accent-soft); }
.page-title { font-size: 22px; font-weight: 700; margin: 0; }
.topbar-sub { color: var(--accent); font-size: 13px; }
.topbar-spacer { flex: 1; }

.theme-toggle { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.theme-toggle button { border: none; background: none; padding: 5px 9px; border-radius: 999px; font-size: 13px; color: var(--text-dim); }
.theme-toggle button.on { background: var(--accent-soft); color: var(--accent); }

.btn {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 9px; font-size: 13px; font-weight: 600;
  display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { background: none; border-color: transparent; }
.btn.sm { padding: 6px 10px; font-size: 12px; }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Content ---------- */
.content { padding: 24px 28px 60px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; gap: 14px; align-items: flex-start; box-shadow: var(--shadow);
}
.stat .icon { width: 42px; height: 42px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 18px; flex-shrink: 0; }
.stat .label { color: var(--text-dim); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 700; margin: 2px 0; }
.stat .sub { color: var(--muted); font-size: 12px; }

.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.search { flex: 1; min-width: 200px; position: relative; }
.search input {
  width: 100%; padding: 10px 12px 10px 34px; border-radius: 9px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: 13px;
}
.search::before { content: "🔍"; position: absolute; left: 11px; top: 9px; opacity: .5; font-size: 13px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }

table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 12px; text-transform: none; color: var(--text-dim); font-weight: 600; padding: 14px 16px; border-bottom: 1px solid var(--border); }
tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.cell-name { font-weight: 600; display: flex; align-items: center; gap: 10px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.iconbtn { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 8px; width: 30px; height: 30px; display: grid; place-items: center; color: var(--text-dim); }
.iconbtn:hover { background: var(--accent-soft); color: var(--accent); }
.iconbtn.danger:hover { color: var(--err); border-color: var(--err); }

.dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.dot.idle { background: var(--idle); }
.dot.running { background: var(--warn); animation: pulse 1.2s infinite; }
.dot.error { background: var(--err); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; font-weight: 600; display: inline-block; }
.badge.enabled { background: #e4f0e5; color: var(--ok); }
.badge.disabled { background: #efe6da; color: var(--muted); }
.badge.status-success { background: #e4f0e5; color: var(--ok); }
.badge.status-never, .badge.status-failed { background: #f2e2dd; color: var(--err); }
.badge.status-running { background: #f6ecd6; color: var(--warn); }
:root[data-theme="dark"] .badge.enabled, :root[data-theme="dark"] .badge.status-success { background: #24422a; }
:root[data-theme="dark"] .badge.disabled { background: #2e2418; }
:root[data-theme="dark"] .badge.status-failed, :root[data-theme="dark"] .badge.status-never { background: #3d2018; }
:root[data-theme="dark"] .badge.status-running { background: #3a2f14; }

.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.placeholder-page { padding: 60px 20px; text-align: center; color: var(--muted); }
.placeholder-page .big { font-size: 40px; margin-bottom: 10px; }

/* ---------- Forms / drawer / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(30, 20, 12, .45); display: flex; justify-content: flex-end; z-index: 50; }
.drawer { width: 560px; max-width: 92vw; background: var(--bg); height: 100%; overflow-y: auto; box-shadow: -8px 0 30px rgba(0,0,0,.2); }
.modal-center { align-items: center; justify-content: center; }
.modal { width: 520px; max-width: 92vw; background: var(--bg); border-radius: var(--radius); overflow: hidden; max-height: 90vh; display: flex; flex-direction: column; }
.drawer-head, .modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px; border-bottom: 1px solid var(--border); }
.drawer-head h3, .modal-head h3 { margin: 0; font-size: 17px; }
.drawer-body, .modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.x { background: none; border: none; font-size: 20px; color: var(--text-dim); }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 6px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 11px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font-size: 13px; font-family: inherit;
}
.field textarea { min-height: 90px; resize: vertical; }
.field .hint { color: var(--muted); font-size: 11px; margin-top: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); margin: 22px 0 10px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 600; }
.chip button { border: none; background: none; color: inherit; font-size: 14px; line-height: 1; }
.assign-row { display: flex; gap: 8px; margin-top: 10px; }
.assign-row select { flex: 1; }

.switch { display: inline-flex; align-items: center; gap: 8px; }
.switch input { width: auto; }

/* ---------- Retrieval Debug ---------- */
.debug-grid { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin-bottom: 20px; }
.debug-grid .k { color: var(--text-dim); font-size: 12px; font-weight: 600; }
.debug-grid .v { font-size: 13px; word-break: break-word; }
.query-compare { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.query-box { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px; }
.query-box .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.hit { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 12px; overflow: hidden; }
.hit.used { border-color: var(--accent); }
.hit-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--card); flex-wrap: wrap; }
.hit-rank { font-weight: 700; color: var(--accent); }
.score-bar { height: 6px; border-radius: 3px; background: var(--border); flex: 1; min-width: 60px; max-width: 160px; overflow: hidden; }
.score-bar > i { display: block; height: 100%; background: var(--accent); }
.hit-meta { color: var(--text-dim); font-size: 12px; }
.hit-path { font-size: 12px; color: var(--accent); font-weight: 600; }
.hit-body { padding: 12px 14px; font-size: 12.5px; white-space: pre-wrap; color: var(--text); background: var(--surface); max-height: 220px; overflow: auto; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.used-flag { font-size: 11px; font-weight: 700; color: var(--ok); }
.answer-box { background: var(--card); border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 16px 18px; white-space: pre-wrap; line-height: 1.5; }

/* ---------- RAG Settings: zweispaltig + Erklärungs-Panel ---------- */
.rag-layout { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(320px, 1fr); gap: 24px; align-items: start; }
@media (max-width: 1040px) { .rag-layout { grid-template-columns: 1fr; } }
.rag-col-right { position: sticky; top: 12px; }
.rx-panel { padding: 4px 2px; }
.rx-item { display: flex; gap: 12px; padding: 13px 15px; border-bottom: 1px solid var(--border); }
.rx-item:last-child { border-bottom: none; }
.rx-ic { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; flex-shrink: 0; background: var(--accent-soft); }
.rx-ic.purple { background: rgba(147, 112, 219, .16); }
.rx-ic.blue   { background: rgba(70, 130, 210, .15); }
.rx-ic.green  { background: rgba(63, 125, 78, .17); }
.rx-ic.orange { background: rgba(200, 120, 40, .16); }
.rx-ic.yellow { background: rgba(190, 150, 40, .18); }
.rx-ic.pink   { background: rgba(210, 90, 140, .15); }
.rx-ic.red    { background: rgba(185, 70, 50, .15); }
.rx-key { font-weight: 700; font-size: 13px; margin-bottom: 3px; }
.rx-desc { color: var(--text-dim); font-size: 12.5px; line-height: 1.45; }
.sim-scale { margin-top: 10px; max-width: 300px; }
.sim-bar { position: relative; height: 6px; border-radius: 3px; background: linear-gradient(90deg, #b7e0c0, #3f7d4e); }
.sim-marker { position: absolute; left: 50%; top: 50%; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--ok); transform: translate(-50%, -50%); }
.sim-labels { display: flex; justify-content: space-between; margin-top: 6px; }
.sim-labels span { display: flex; flex-direction: column; }
.sim-labels .mid { align-items: center; }
.sim-labels .end { align-items: flex-end; }
.sim-labels b { font-size: 11px; color: var(--text-dim); font-weight: 700; }
.sim-labels small { font-size: 10px; color: var(--muted); }
.rx-reco { margin: 10px 12px 12px; padding: 12px 14px; background: var(--accent-soft); border-radius: 10px; }
.rx-reco-h { font-weight: 700; font-size: 12.5px; margin-bottom: 5px; }
.rx-reco-b { font-size: 11.5px; color: var(--text-dim); line-height: 1.6; }

/* ---------- Datei-Browser ---------- */
.fs-path { font-size: 12px; color: var(--accent); font-weight: 600; margin-bottom: 10px; word-break: break-all; }
.fs-list { max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.fs-row { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 9px 12px; border: none; border-bottom: 1px solid var(--border); background: none; color: var(--text); font-size: 13px; }
.fs-row:last-child { border-bottom: none; }
.fs-row:hover { background: var(--surface-2); }
.fs-ic { width: 20px; text-align: center; flex-shrink: 0; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px; font-size: 13px; z-index: 100; box-shadow: var(--shadow); }
.toast.err { background: var(--err); color: #fff; }
.spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 720px) {
  .sidebar { position: fixed; z-index: 40; height: 100%; }
  .content { padding: 16px; }
  .query-compare, .grid2 { grid-template-columns: 1fr; }
}
