:root {
  --bg: #15161E;
  --panel: rgba(26, 27, 37, .85);
  --card: rgba(30, 32, 44, .92);
  --line: #262838;
  --line-2: #2E3350;
  --line-3: #34405E;
  --text: #F4F4F8;
  --muted: #A6A3B8;
  --muted-2: #BAB8CA;
  --blue: #42BBF5;
  --blue-soft: rgba(66, 187, 245, .1);
  --lime: #B4E61E;
  --user-bg: #1D2638;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, sans-serif;
}
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.accent { color: var(--blue); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
button { font-family: inherit; }

.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-image:
    linear-gradient(rgba(66,187,245,.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(66,187,245,.05) 1px, transparent 1px);
  background-size: 40px 40px;
}
.scan {
  position: absolute; left: 0; right: 0; height: 120px; z-index: 0;
  background: linear-gradient(180deg, transparent, rgba(66,187,245,.06), transparent);
  animation: scan 7s linear infinite; pointer-events: none;
}
@keyframes scan { from { top: -120px; } to { top: 100%; } }

/* Kopfzeile */
.topbar {
  position: relative; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: rgba(21,22,30,.88); backdrop-filter: blur(6px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo-crop { position: relative; width: 48px; height: 48px; overflow: hidden; flex: none; }
.logo-crop img { position: absolute; width: 96px; height: 96px; left: -24px; top: -14px; }
.brand-text { display: flex; flex-direction: column; gap: 2px; }
.brand-name { font-size: 24px; font-weight: 700; letter-spacing: -.5px; line-height: 1; }
.brand-tag { font-size: 11px; letter-spacing: 3px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.status-pill {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px;
  border: 1px solid var(--line-2); border-radius: 999px;
  font-family: 'JetBrains Mono', monospace; font-size: 12px; color: #D2ECFA;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 10px var(--lime); animation: blink 1.6s ease-in-out infinite; }
.dot.off { background: #F5A142; box-shadow: 0 0 10px #F5A142; }
@keyframes blink { 50% { opacity: .35; } }
.icon-btn {
  width: 44px; height: 44px; flex: none; display: flex; align-items: center; justify-content: center;
  background: transparent; border: 1px solid var(--line-2); border-radius: 10px; color: var(--muted-2); cursor: pointer;
}
.icon-btn:hover { border-color: var(--blue); color: var(--text); }
.menu-btn { display: none; }

/* Layout */
.layout { position: relative; z-index: 1; flex: 1; min-height: 0; display: flex; }
.sidebar, .statuspanel {
  background: var(--panel); padding: 20px 16px;
  display: flex; flex-direction: column; gap: 16px; overflow-y: auto;
}
.sidebar { width: 270px; flex: none; border-right: 1px solid var(--line); }
.statuspanel { width: 290px; flex: none; border-left: 1px solid var(--line); }
.label { font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: 2px; color: var(--muted); }

.primary-btn {
  height: 46px; border: none; border-radius: 10px; background: var(--blue); color: #0B1A24;
  font-weight: 700; font-size: 15px; letter-spacing: .5px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px; transition: box-shadow .2s;
}
.primary-btn:hover, .send-btn:hover { box-shadow: 0 0 24px rgba(66,187,245,.6); }

.history { display: flex; flex-direction: column; gap: 4px; }
.hist-item {
  display: flex; align-items: center; gap: 6px; padding: 0 4px 0 12px; min-height: 42px;
  border-radius: 8px; border: 1px solid transparent; color: var(--muted-2); font-size: 14px; cursor: pointer;
  background: transparent; text-align: left; width: 100%;
}
.hist-item:hover { background: rgba(66,187,245,.07); }
.hist-item.active { background: var(--blue-soft); border-color: var(--line-2); color: var(--text); }
.hist-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-del { width: 32px; height: 32px; border: none; background: transparent; color: var(--muted); border-radius: 6px; cursor: pointer; opacity: .6; }
.hist-del:hover { color: var(--text); opacity: 1; background: rgba(255,255,255,.05); }
.hist-empty { font-size: 13px; color: var(--muted); padding: 4px 2px; }

.quota {
  margin-top: auto; padding: 14px; border: 1px solid var(--line-2); border-radius: 12px;
  display: flex; flex-direction: column; gap: 10px; background: rgba(66,187,245,.04);
}
.quota-head { display: flex; justify-content: space-between; font-family: 'JetBrains Mono', monospace; font-size: 11px; color: var(--muted); }
.meter { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.meter-fill { height: 6px; background: var(--blue); box-shadow: 0 0 12px var(--blue); transition: width .4s; }
.meter-fill.lime { background: var(--lime); box-shadow: 0 0 10px var(--lime); }

/* Chat */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat { flex: 1; overflow-y: auto; padding: 32px clamp(16px, 4vw, 56px) 16px; }
#messages, .hero { max-width: 900px; margin: 0 auto; }
#messages { display: flex; flex-direction: column; gap: 22px; }

.hero { display: flex; flex-direction: column; align-items: center; gap: 18px; padding: 24px 0 28px; text-align: center; }
.hero h1 { margin: 0; font-size: clamp(28px, 4vw, 40px); font-weight: 600; letter-spacing: -.5px; }
.hero p { margin: 0; font-size: 13px; }
.hero.compact { padding: 4px 0 16px; gap: 10px; }
.hero.compact .orb { width: 72px; height: 72px; }
.hero.compact .core { inset: 25px; }
.hero.compact .ring.r2 { inset: 8px; }
.hero.compact .ring.r3 { inset: 16px; }
.hero.compact h1, .hero.compact p { display: none; }

.orb { position: relative; width: 132px; height: 132px; border-radius: 50%; transition: width .3s, height .3s; }
.ring { position: absolute; inset: 0; border-radius: 50%; border: 1px solid rgba(66,187,245,.35); animation: spin 14s linear infinite; }
.ring.r2 { inset: 14px; border-style: dashed; border-color: rgba(180,230,30,.55); animation-duration: 9s; animation-direction: reverse; }
.ring.r3 { inset: 30px; border: 2px solid transparent; border-top-color: var(--blue); border-right-color: var(--lime); animation-duration: 3.2s; }
.core {
  position: absolute; inset: 46px; border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #E4F9B0, #B4E61E 30%, #42BBF5 70%, #1B5E86 100%);
  box-shadow: 0 0 40px rgba(66,187,245,.7), 0 0 90px rgba(66,187,245,.3);
  animation: pulse 2.6s ease-in-out infinite;
}
.busy .ring.r3 { animation-duration: .9s; }
.busy .core { animation-duration: .9s; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.86); opacity: .8; } }

.msg-user { display: flex; justify-content: flex-end; }
.bubble-user {
  max-width: 78%; padding: 14px 18px; border-radius: 14px 14px 4px 14px;
  background: var(--user-bg); border: 1px solid var(--line-3); font-size: 15px; line-height: 1.55;
  white-space: pre-wrap; word-wrap: break-word;
}
.msg-ai { display: flex; gap: 14px; align-items: flex-start; }
.avatar {
  flex: none; position: relative; width: 38px; height: 38px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--blue); box-shadow: 0 0 16px rgba(66,187,245,.35); background: var(--bg);
}
.avatar img { position: absolute; width: 72px; height: 72px; left: -18px; top: -10px; }
.bubble-ai {
  flex: 1; min-width: 0; padding: 16px 18px; border-radius: 4px 14px 14px 14px;
  background: var(--card); border: 1px solid #2A2D42; display: flex; flex-direction: column; gap: 10px;
}
.bubble-ai.error { border-color: #F5A142; }
.ai-meta { font-family: 'JetBrains Mono', monospace; font-size: 11px; letter-spacing: 2px; color: var(--blue); }
.ai-text { font-size: 15px; line-height: 1.6; color: #E4E3EE; white-space: pre-wrap; word-wrap: break-word; }
.ai-text code { font-family: 'JetBrains Mono', monospace; font-size: 13px; background: rgba(66,187,245,.1); padding: 1px 6px; border-radius: 4px; color: #D2ECFA; }
.ai-text pre {
  white-space: pre; overflow-x: auto; margin: 6px 0; padding: 14px; border-radius: 10px;
  background: #0F1016; border: 1px solid var(--line-2);
  font-family: 'JetBrains Mono', monospace; font-size: 13px; line-height: 1.5; color: #D2ECFA;
}
.ai-text strong { color: #fff; }
.typing span { display: inline-block; width: 6px; height: 6px; margin-right: 4px; border-radius: 50%; background: var(--blue); animation: blink 1s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
.typing { font-family: 'JetBrains Mono', monospace; font-size: 12px; color: var(--muted); }
.cursor::after { content: '▍'; color: var(--blue); animation: blink 1s infinite; margin-left: 2px; }

/* Eingabe */
.composer-wrap { padding: 12px clamp(16px, 4vw, 56px) 20px; }
.composer-inner { max-width: 900px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 36px; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line-2);
  background: rgba(66,187,245,.04); color: #D2ECFA; font-size: 13px; cursor: pointer;
}
.chip:hover { background: rgba(66,187,245,.12); border-color: var(--blue); }
.composer {
  display: flex; align-items: flex-end; gap: 10px; padding: 8px 8px 8px 18px;
  border: 1px solid var(--line-3); border-radius: 16px; background: var(--card); transition: box-shadow .2s, border-color .2s;
}
.composer:focus-within { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue), 0 0 30px rgba(66,187,245,.18); }
.prompt-sign { color: var(--blue); font-size: 16px; line-height: 44px; }
#prompt {
  flex: 1; min-width: 0; min-height: 44px; max-height: 200px; resize: none; padding: 11px 0;
  background: transparent; border: none; outline: none; color: var(--text); font-family: inherit; font-size: 16px; line-height: 1.4;
}
#prompt::placeholder { color: #8C8AA0; }
.send-btn {
  width: 48px; height: 44px; flex: none; border-radius: 12px; border: none; background: var(--blue); color: #0B1A24;
  cursor: pointer; display: flex; align-items: center; justify-content: center; transition: box-shadow .2s;
}
.send-btn.stop { background: var(--lime); }
.footnote { text-align: center; font-size: 11px; color: #9592A8; }

/* Statuspanel */
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.stat, .card { padding: 12px; border: 1px solid #2A2D42; border-radius: 10px; display: flex; flex-direction: column; gap: 8px; }
.card { padding: 14px; gap: 12px; }
.stat-label { font-family: 'JetBrains Mono', monospace; font-size: 10px; color: var(--muted); letter-spacing: 1px; }
.stat-val { font-size: 22px; font-weight: 600; }
.bars { height: 56px; display: flex; align-items: flex-end; gap: 4px; }
.bar { width: 6px; height: 56px; border-radius: 2px; background: var(--blue); transform-origin: bottom; animation: eq 1.2s ease-in-out infinite; }
.bar.lime { background: var(--lime); }
.busy .bar { animation-duration: .45s; }
@keyframes eq { 0%, 100% { transform: scaleY(.25); } 50% { transform: scaleY(1); } }
.sys { margin-top: auto; font-size: 10px; line-height: 1.7; color: #9592A8; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* Kleinere Bildschirme */
@media (max-width: 1200px) {
  .statuspanel { display: none; }
}
@media (max-width: 820px) {
  .menu-btn { display: flex; }
  .sidebar {
    position: absolute; top: 0; bottom: 0; left: 0; z-index: 5; width: 280px;
    transform: translateX(-100%); transition: transform .25s; background: #1A1B25;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 40px rgba(0,0,0,.6); }
  .status-pill { display: none; }
  .bubble-user { max-width: 90%; }
  .avatar { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
