:root {
  --bg: #0f1115;
  --bg-2: #161920;
  --bg-3: #1d212a;
  --line: #2a2f3a;
  --text: #e7e9ee;
  --muted: #8b93a3;
  --accent: #c6f135;
  --accent-ink: #0f1115;
  --danger: #ff6b6b;
  --warn: #ffb547;
  --agent: #9b8cff;
  --radius: 10px;
  --mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }
.error { color: var(--danger); min-height: 1.2em; margin: .5rem 0 0; }
.spacer { flex: 1; }
a { color: var(--accent); }

/* Buttons & Inputs */
.btn { font: inherit; border: 1px solid var(--line); background: var(--bg-3); color: var(--text); padding: .45rem .8rem; border-radius: 8px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.btn:hover { border-color: #3a4150; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.05); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--bg-3); }
.btn.icon { padding: .35rem .55rem; }
.btn.small { padding: .25rem .55rem; font-size: 12px; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; justify-content: center; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
input, textarea, select { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; width: 100%; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
input[type=checkbox] { width: auto; }
label { display: block; margin-bottom: .75rem; color: var(--muted); font-size: 12px; }
label > input, label > textarea, label > select { margin-top: .3rem; }

/* Views */
.view { height: 100%; }
#view-login { display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 2rem; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; letter-spacing: -.01em; }
.brand.big { font-size: 22px; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 800; font-size: 14px; }

.topbar { height: 52px; display: flex; align-items: center; gap: .5rem; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--bg-2); }
.project-title { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.project-title strong, .project-title span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

#view-projects { display: flex; flex-direction: column; }
.projects-main { max-width: 1100px; width: 100%; margin: 0 auto; padding: 24px 16px; overflow: auto; }
.projects-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.projects-head h1 { margin: 0; font-size: 24px; }
.projects-head p { margin: .2rem 0 0; }
.hint { background: #1e2412; border: 1px solid #3c4a1a; padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.project-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; cursor: pointer; display: flex; flex-direction: column; gap: .4rem; min-height: 120px; }
.project-card:hover { border-color: var(--accent); }
.project-card h3 { margin: 0; font-size: 16px; }
.project-card .meta { margin-top: auto; display: flex; justify-content: space-between; align-items: center; }
.empty { color: var(--muted); padding: 2rem; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius); }

/* Workspace */
#view-workspace { display: flex; flex-direction: column; }
.ws-grid { flex: 1; min-height: 0; display: grid; grid-template-columns: 230px minmax(0, 1fr) 360px; }
.panel { min-height: 0; display: flex; flex-direction: column; background: var(--bg); }
.files-panel { border-right: 1px solid var(--line); background: var(--bg-2); }
.chat-panel { border-left: 1px solid var(--line); background: var(--bg-2); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: .5rem .75rem; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--line); min-height: 40px; }
.panel-head.sub { border-top: 1px solid var(--line); }
.panel-actions { display: flex; gap: .1rem; }

.file-tree { list-style: none; margin: 0; padding: .35rem 0; overflow: auto; flex: 1; font-family: var(--mono); font-size: 12.5px; }
.file-tree li { padding: .28rem .75rem; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #c9ced8; display: flex; align-items: center; gap: .35rem; }
.file-tree li.dir { color: var(--muted); cursor: default; }
.file-tree li:not(.dir):hover { background: var(--bg-3); }
.file-tree li.active { background: #252b18; color: var(--accent); }
.file-tree li.flash { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: #3a2f6b; } to { background: transparent; } }
.activity { list-style: none; margin: 0; padding: .35rem .75rem; max-height: 32%; overflow: auto; font-size: 12px; }
.activity li { padding: .25rem 0; color: var(--muted); border-bottom: 1px solid #20242d; }
.activity li b { color: var(--text); font-weight: 500; }
.activity li code { font-family: var(--mono); color: #c9ced8; }

.tabs { display: flex; align-items: center; gap: .2rem; padding: 0 .5rem; border-bottom: 1px solid var(--line); background: var(--bg-2); min-height: 40px; }
.tab { font: inherit; background: none; border: 0; color: var(--muted); padding: .55rem .8rem; cursor: pointer; border-bottom: 2px solid transparent; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.editor-bar { display: flex; align-items: center; gap: .4rem; padding: .35rem .75rem; border-bottom: 1px solid var(--line); min-height: 38px; }
.editor-bar label { margin: 0; display: flex; align-items: center; gap: .35rem; color: var(--muted); }
.editor { flex: 1; min-height: 0; position: relative; }
.editor textarea.fallback { position: absolute; inset: 0; border: 0; border-radius: 0; resize: none; font: 13px/1.5 var(--mono); background: var(--bg); padding: 1rem; }
.editor .placeholder { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 2rem; }
.banner { background: #2e2512; color: var(--warn); padding: .5rem .75rem; font-size: 12px; display: flex; gap: .5rem; align-items: center; border-bottom: 1px solid #4a3a16; }
.preview { flex: 1; border: 0; background: #fff; width: 100%; }

/* Board */
.board { flex: 1; display: grid; grid-template-columns: repeat(4, minmax(170px, 1fr)); gap: 10px; padding: 12px; overflow: auto; }
.column { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 200px; }
.column.drag-over { border-color: var(--accent); }
.column-head { display: flex; justify-content: space-between; align-items: center; padding: .6rem .75rem; font-weight: 600; font-size: 13px; }
.column-head .count { color: var(--muted); font-weight: 400; }
.column-cards { flex: 1; padding: 0 .5rem .5rem; display: flex; flex-direction: column; gap: .45rem; overflow: auto; }
.card { background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: .55rem .65rem; cursor: grab; }
.card:hover { border-color: #3a4150; }
.card.dragging { opacity: .4; }
.card .title { font-weight: 500; }
.card .sub { font-size: 11.5px; color: var(--muted); margin-top: .25rem; display: flex; gap: .4rem; flex-wrap: wrap; }
.tag { font-size: 11px; padding: .05rem .4rem; border-radius: 99px; background: #2a2450; color: #c4baff; }
.add-card { margin: 0 .5rem .5rem; }

/* Chat */
.queue { border-bottom: 1px solid var(--line); padding: .6rem .75rem; background: #17152a; font-size: 12.5px; }
.queue .running { display: flex; align-items: center; gap: .5rem; }
.queue .steps { list-style: none; margin: .4rem 0 0; padding: 0; color: #c4baff; font-family: var(--mono); font-size: 11.5px; max-height: 110px; overflow: auto; }
.queue .steps li { padding: .1rem 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue .waiting { margin-top: .4rem; color: var(--muted); }
.spinner { width: 12px; height: 12px; border: 2px solid var(--agent); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.messages { flex: 1; overflow: auto; padding: .75rem; display: flex; flex-direction: column; gap: .65rem; }
.msg { max-width: 100%; }
.msg .head { font-size: 11.5px; color: var(--muted); margin-bottom: .15rem; display: flex; gap: .4rem; align-items: center; }
.msg .head b { color: var(--text); font-weight: 600; }
.msg .body { background: var(--bg-3); border: 1px solid var(--line); border-radius: 0 10px 10px 10px; padding: .5rem .65rem; overflow-wrap: anywhere; }
.msg.mine .body { background: #1f2614; border-color: #34421a; }
.msg.agent .head b { color: var(--agent); }
.msg.agent .body { background: #1a1830; border-color: #2f2a55; }
.msg.system .body { background: transparent; border: 0; color: var(--muted); padding: 0; font-size: 12.5px; }
.msg.system .head { display: none; }
.body pre { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: .5rem; overflow: auto; font: 12px/1.45 var(--mono); margin: .4rem 0; }
.body code { font-family: var(--mono); font-size: 12.5px; background: var(--bg); padding: 0 .25rem; border-radius: 4px; }
.body pre code { background: none; padding: 0; }
.chat-form { border-top: 1px solid var(--line); padding: .6rem; display: flex; flex-direction: column; gap: .45rem; }
.chat-target { display: flex; align-items: center; gap: .5rem; }
.chat-target label { margin: 0; }
.chat-target select { padding: .3rem .5rem; }
.chat-row { display: flex; gap: .45rem; align-items: flex-end; }
.chat-row textarea { resize: none; max-height: 160px; }

.presence { display: flex; gap: -4px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #0f1115; border: 2px solid var(--bg-2); margin-left: -6px; }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); margin: 0 .3rem; }
.conn.on { background: #3ddc84; }

/* Modals & Toasts */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--bg-2); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 1.1rem; overflow: auto; }
.modal-foot { display: flex; gap: .5rem; justify-content: flex-end; padding: .8rem 1.1rem; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-section { margin-bottom: 1.5rem; }
.modal-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 .6rem; }
.agent-row { display: flex; align-items: center; gap: .6rem; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; margin-bottom: .5rem; }
.agent-row .info { flex: 1; min-width: 0; }
.agent-row .info div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .75rem; }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .4rem; z-index: 60; width: max-content; max-width: calc(100vw - 32px); }
.toast { background: var(--bg-3); border: 1px solid var(--line); padding: .55rem .9rem; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.4); }
.toast.err { border-color: var(--danger); color: #ffc9c9; }

.mobile-nav { display: none; }

/* Mobil: ein Bereich auf einmal, Navigation unten */
@media (max-width: 900px) {
  .ws-grid { grid-template-columns: 1fr; }
  .ws-grid > .panel { display: none; border: 0; }
  .ws-grid[data-mobile="files"] > [data-panel="files"],
  .ws-grid[data-mobile="chat"] > [data-panel="chat"],
  .ws-grid[data-mobile="center"] > [data-panel="center"] { display: flex; }
  .tabs .tab { display: none; }
  .mobile-nav { display: flex; border-top: 1px solid var(--line); background: var(--bg-2); padding-bottom: env(safe-area-inset-bottom); }
  .mobile-nav button { flex: 1; background: none; border: 0; color: var(--muted); font: inherit; font-size: 16px; padding: .45rem 0; display: flex; flex-direction: column; align-items: center; gap: .1rem; cursor: pointer; }
  .mobile-nav button span { font-size: 10.5px; }
  .mobile-nav button.active { color: var(--accent); }
  .board { grid-template-columns: repeat(4, 78vw); scroll-snap-type: x mandatory; }
  .column { scroll-snap-align: start; }
  .activity { max-height: 40%; }
  .presence .avatar:nth-child(n+4) { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  #ws-desc { display: none; }
}
