* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1626;
  --bg2: #14213d;
  --panel: #1b2a4a;
  --panel2: #223258;
  --text: #e8ecf4;
  --muted: #93a1bd;
  --accent: #fca311;
  --green: #37b26c;
  --red: #d64550;
  --radius: 10px;
}
html, body { height: 100%; }
body {
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.logo { font-weight: 800; font-size: 20px; letter-spacing: 1px; color: var(--text); }
.logo-os { color: var(--accent); }
.logo.big { font-size: 42px; }
.hidden { display: none !important; }

/* Layout */
#app { display: flex; height: 100dvh; }
#sidebar {
  width: 260px; min-width: 260px;
  background: var(--bg2);
  display: flex; flex-direction: column;
  border-right: 1px solid #2a3a60;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; }
#btn-new {
  background: var(--accent); border: 0; color: #14213d; font-size: 18px; font-weight: 700;
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer;
}
#chat-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.chat-item {
  padding: 2px 4px 2px 10px; border-radius: 8px; color: var(--muted);
  font-size: 14px; display: flex; align-items: center; gap: 4px;
}
.chat-item:hover { background: var(--panel); color: var(--text); }
.chat-item.active { background: var(--panel2); color: var(--text); }
.chat-label {
  flex: 1; min-width: 0; cursor: pointer; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; display: flex; align-items: center; gap: 6px; padding: 7px 0;
}
.chat-item .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; animation: pulse 1.2s infinite; }
.chat-del {
  flex: none; background: none; border: 0; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 4px 6px; border-radius: 6px; opacity: 0; transition: opacity 0.15s;
}
.chat-item:hover .chat-del { opacity: 1; }
.chat-del:hover { background: var(--red); color: #fff; }
@media (hover: none) { .chat-del { opacity: 0.6; } } /* Touch: kein Hover → immer sichtbar */
@keyframes pulse { 50% { opacity: 0.3; } }
.side-foot { padding: 10px; border-top: 1px solid #2a3a60; display: flex; flex-direction: column; gap: 6px; }
.foot-btn {
  background: var(--panel); color: var(--text); border: 0; border-radius: 8px;
  padding: 9px; cursor: pointer; font-size: 14px; text-align: left;
}
.foot-btn:hover { background: var(--panel2); }
.badge {
  background: var(--red); color: #fff; border-radius: 10px; font-size: 12px;
  padding: 1px 7px; margin-left: 6px;
}

/* Main */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  display: flex; align-items: center; gap: 10px; padding: 12px 16px;
  background: var(--bg2); border-bottom: 1px solid #2a3a60;
}
#btn-menu { display: none; background: none; border: 0; color: var(--text); font-size: 20px; cursor: pointer; }
#chat-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#run-indicator { color: var(--accent); font-size: 13px; }
#btn-stop { margin-left: auto; background: var(--red); color: #fff; border: 0; border-radius: 8px; padding: 6px 12px; cursor: pointer; }

#messages { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 820px; padding: 12px 16px; border-radius: var(--radius); word-wrap: break-word; }
.msg.user { background: var(--panel2); align-self: flex-end; white-space: pre-wrap; }
.msg.assistant { background: var(--panel); align-self: flex-start; }
.msg.assistant pre {
  background: #0c1220; padding: 10px; border-radius: 8px; overflow-x: auto;
  font-size: 13px; margin: 8px 0;
}
.msg.assistant code { background: #0c1220; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg.assistant pre code { padding: 0; background: none; }
.msg.assistant h1, .msg.assistant h2, .msg.assistant h3 { margin: 10px 0 4px; font-size: 1.05em; }
.msg.assistant ul, .msg.assistant ol { margin: 4px 0 4px 22px; }
.msg.assistant p { margin: 6px 0; }
.msg.assistant table {
  border-collapse: collapse; margin: 10px 0; display: block; overflow-x: auto; max-width: 100%;
}
.msg.assistant th { background: #16203a; text-align: left; }
.msg.assistant td, .msg.assistant th { border: 1px solid #2a3a60; padding: 6px 10px; font-size: 13px; }
.msg.assistant tr:nth-child(even) td { background: #17223e; }
.msg.assistant blockquote {
  border-left: 3px solid var(--accent); margin: 8px 0; padding: 2px 12px; color: var(--muted);
}
.msg.assistant hr { border: 0; border-top: 1px solid #2a3a60; margin: 10px 0; }
.msg .cost { display: block; margin-top: 8px; font-size: 11px; color: var(--muted); }
.tool-chip {
  align-self: flex-start; font-size: 12px; color: var(--muted);
  background: #16203a; border: 1px solid #2a3a60; border-radius: 14px; padding: 3px 12px;
  max-width: 720px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.error-note { color: var(--red); font-size: 13px; align-self: flex-start; }

/* Approval card im Chat */
.approval-card {
  align-self: stretch; max-width: 820px; background: #2b2313; border: 1px solid var(--accent);
  border-radius: var(--radius); padding: 12px 16px;
}
.approval-card .apr-reason { color: var(--accent); font-size: 13px; font-weight: 600; }
.approval-card pre { background: #0c1220; padding: 8px; border-radius: 6px; margin: 8px 0; font-size: 13px; overflow-x: auto; white-space: pre-wrap; }
.approval-card .apr-actions { display: flex; gap: 8px; }
.apr-allow { background: var(--green); }
.apr-deny { background: var(--red); }
.apr-allow, .apr-deny { border: 0; color: #fff; border-radius: 8px; padding: 7px 16px; cursor: pointer; font-weight: 600; }
.apr-done { color: var(--muted); font-size: 13px; }

/* Save-Note-Button an Assistent-Bubble */
.msg.assistant .save-note {
  display: inline-block; margin-top: 8px; background: none; border: 1px solid #2a3a60;
  color: var(--muted); border-radius: 6px; padding: 3px 10px; font-size: 12px; cursor: pointer;
}
.msg.assistant .save-note:hover { color: var(--text); border-color: var(--accent); }

/* Composer */
#composer { display: flex; gap: 10px; padding: 14px 16px calc(14px + env(safe-area-inset-bottom)); background: var(--bg2); border-top: 1px solid #2a3a60; align-items: flex-end; }
#btn-mic, #btn-attach {
  background: var(--panel); border: 1px solid #2a3a60; border-radius: var(--radius); width: 46px; height: 44px;
  font-size: 18px; cursor: pointer; flex: none;
}
#btn-mic.recording { background: var(--red); border-color: var(--red); animation: pulse 1s infinite; }
#attach-bar {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 16px 0; background: var(--bg2);
}
.attach-chip {
  display: flex; align-items: center; gap: 6px; background: var(--panel2); border: 1px solid #2a3a60;
  border-radius: 14px; padding: 4px 10px; font-size: 12px; color: var(--text);
}
.attach-chip .x { cursor: pointer; color: var(--muted); }
.attach-chip .x:hover { color: var(--red); }
#composer.dragover { outline: 2px dashed var(--accent); outline-offset: -4px; }
#input {
  flex: 1; resize: none; background: var(--panel); border: 1px solid #2a3a60; border-radius: var(--radius);
  color: var(--text); padding: 10px 14px; font: inherit;
}
#input:focus { outline: 1px solid var(--accent); }
#btn-send {
  background: var(--accent); border: 0; border-radius: var(--radius); width: 52px;
  font-size: 18px; color: #14213d; cursor: pointer; font-weight: 700;
}
#btn-send:disabled { opacity: 0.4; }

/* Profil-Select */
#profile-select, #job-profile, #job-notify {
  background: var(--panel); color: var(--text); border: 1px solid #2a3a60;
  border-radius: 8px; padding: 6px 8px; font-size: 13px;
}
#profile-select { margin-left: auto; margin-right: 8px; }

/* Jobs/Kosten/Regeln/Features/Skills-Drawer */
#jobs-drawer, #costs-drawer, #rules-drawer, #features-drawer, #skills-drawer {
  position: fixed; top: 0; right: 0; height: 100dvh; width: min(460px, 100vw);
  background: var(--bg2); border-left: 1px solid #2a3a60; z-index: 50;
  display: flex; flex-direction: column;
}
#skills-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.skill-card { background: var(--panel); border: 1px solid #2a3a60; border-radius: var(--radius); padding: 12px; }
.skill-card .skill-name { font-weight: 600; }
.skill-card .skill-desc { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
.skill-card .skill-actions { display: flex; gap: 6px; }
.skill-card .skill-actions button {
  background: var(--panel2); border: 0; color: var(--text); border-radius: 6px; padding: 5px 10px; cursor: pointer; font-size: 12px;
}
.skill-card .skill-actions .del { background: var(--red); color: #fff; }
.skill-view { white-space: pre-wrap; font-size: 12px; background: #0c1220; border-radius: 6px; padding: 8px; margin-top: 8px; max-height: 300px; overflow-y: auto; }
#skill-form { border-top: 1px solid #2a3a60; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
#skill-form input, #skill-form textarea {
  background: var(--panel); border: 1px solid #2a3a60; border-radius: 8px; color: var(--text); padding: 8px 10px; font: inherit; font-size: 13px;
}
#skill-form button { background: var(--accent); border: 0; border-radius: 8px; padding: 9px; font-weight: 700; color: #14213d; cursor: pointer; }
#skill-error { color: var(--red); font-size: 12px; min-height: 14px; }
#features-hint { padding: 10px 14px; font-size: 12px; color: var(--muted); border-bottom: 1px solid #2a3a60; }
#features-list { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.feat-card { background: var(--panel); border: 1px solid #2a3a60; border-radius: var(--radius); padding: 12px; }
.feat-card .feat-top { display: flex; align-items: center; gap: 8px; }
.feat-card .feat-title { font-weight: 600; flex: 1; }
.feat-card .feat-desc { color: var(--muted); font-size: 13px; margin: 6px 0; white-space: pre-wrap; }
.feat-status {
  font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; flex: none;
}
.st-proposed { background: #3a3358; color: #c9b8ff; }
.st-approved { background: #1f3a2a; color: #7bd3a0; }
.st-building { background: #3a3013; color: var(--accent); }
.st-pr_open  { background: #123a4a; color: #6cc5e0; }
.st-done     { background: #1f3a2a; color: #7bd3a0; }
.st-failed   { background: #3a1a1e; color: #e08a92; }
.st-rejected { background: #2a2a2a; color: var(--muted); }
.feat-src { font-size: 11px; color: var(--muted); }
.feat-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.feat-actions button, .feat-actions a {
  background: var(--panel2); border: 0; color: var(--text); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; font-size: 12px; text-decoration: none;
}
.feat-actions .approve { background: var(--green); color: #fff; }
.feat-actions .reject { background: var(--red); color: #fff; }
.feat-actions .pr { background: #2a6f97; color: #fff; }
#feature-form { border-top: 1px solid #2a3a60; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
#feature-form input, #feature-form textarea {
  background: var(--panel); border: 1px solid #2a3a60; border-radius: 8px; color: var(--text); padding: 8px 10px; font: inherit; font-size: 13px;
}
#feature-form button { background: var(--accent); border: 0; border-radius: 8px; padding: 9px; font-weight: 700; color: #14213d; cursor: pointer; }
#feat-error { color: var(--red); font-size: 12px; min-height: 14px; }
#costs-body, #rules-body { overflow-y: auto; padding: 14px; }
.kind-tab { display: flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); cursor: pointer; }
.cost-cards { display: flex; gap: 8px; margin-bottom: 14px; }
.cost-card { flex: 1; background: var(--panel); border: 1px solid #2a3a60; border-radius: var(--radius); padding: 10px; text-align: center; }
.cost-card .v { font-size: 20px; font-weight: 700; color: var(--accent); }
.cost-card .l { font-size: 11px; color: var(--muted); }
#costs-body table, #rules-body table { width: 100%; border-collapse: collapse; }
#costs-body td, #costs-body th { border-bottom: 1px solid #2a3a60; padding: 6px 8px; font-size: 13px; text-align: left; }
.rule-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid #2a3a60; }
.rule-row code { font-size: 12px; word-break: break-all; }
.rule-row button { background: var(--red); border: 0; color: #fff; border-radius: 6px; padding: 4px 10px; cursor: pointer; flex: none; }
.apr-always { background: #2a6f97; }
.apr-always { border: 0; color: #fff; border-radius: 8px; padding: 7px 12px; cursor: pointer; font-weight: 600; }
#jobs-list { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.job-card {
  background: var(--panel); border: 1px solid #2a3a60; border-radius: var(--radius); padding: 12px;
}
.job-card .job-title { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.job-card .job-title .off { color: var(--muted); font-weight: 400; font-size: 12px; }
.job-card .job-meta { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.job-card .job-actions { display: flex; gap: 6px; }
.job-card .job-actions button {
  background: var(--panel2); border: 0; color: var(--text); border-radius: 6px;
  padding: 5px 10px; cursor: pointer; font-size: 13px;
}
.job-card .job-actions button.danger { background: var(--red); }
#job-form {
  border-top: 1px solid #2a3a60; padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
#job-form input, #job-form textarea {
  background: var(--panel); border: 1px solid #2a3a60; border-radius: 8px;
  color: var(--text); padding: 8px 10px; font: inherit; font-size: 13px;
}
#job-form .job-row { display: flex; gap: 8px; }
#job-form button[type=submit] {
  background: var(--accent); border: 0; border-radius: 8px; padding: 9px;
  font-weight: 700; color: #14213d; cursor: pointer;
}
#job-error { color: var(--red); font-size: 12px; min-height: 14px; }

/* Drawer */
#approvals-drawer {
  position: fixed; top: 0; right: 0; height: 100dvh; width: min(420px, 100vw);
  background: var(--bg2); border-left: 1px solid #2a3a60; z-index: 50;
  display: flex; flex-direction: column;
}
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-bottom: 1px solid #2a3a60; }
#btn-close-drawer { background: none; border: 0; color: var(--text); font-size: 18px; cursor: pointer; }
#approvals-list { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }

/* Login */
.login-page { display: flex; align-items: center; justify-content: center; height: 100dvh; }
.login-card {
  background: var(--bg2); padding: 40px; border-radius: 16px; text-align: center;
  display: flex; flex-direction: column; gap: 14px; width: min(360px, 90vw);
  border: 1px solid #2a3a60;
}
.login-card p { color: var(--muted); font-size: 14px; }
.login-card input {
  background: var(--panel); border: 1px solid #2a3a60; border-radius: var(--radius);
  color: var(--text); padding: 12px; font: inherit; text-align: center;
}
.login-card button {
  background: var(--accent); border: 0; border-radius: var(--radius); padding: 12px;
  font-weight: 700; color: #14213d; cursor: pointer; font-size: 15px;
}
#login-error { color: var(--red); font-size: 13px; min-height: 18px; }

/* Mobil */
@media (max-width: 760px) {
  #sidebar { position: fixed; left: -270px; top: 0; height: 100dvh; z-index: 40; transition: left 0.2s; }
  #sidebar.open { left: 0; box-shadow: 4px 0 24px rgba(0,0,0,0.5); }
  #btn-menu { display: block; }
}
