:root {
  --bg:        #080D1A;
  --bg2:       #0F1630;
  --bg3:       #12193A;
  --red:       #8B1A1A;
  --red-l:     #B22222;
  --red-b:     #DC2626;
  --blue:      #1E3A8A;
  --blue-l:    #2563EB;
  --border:    #1E2A50;
  --text:      #EDE9E0;
  --muted:     #8A93B2;
  --radius:    12px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Login ─────────────────────────────────────────── */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-container {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
}

.logo {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-bottom: 2rem;
  font-size: 1.25rem;
  font-weight: 600;
}
.logo-icon {
  width: 36px; height: 36px;
  background: var(--red);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .9rem;
}

.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  margin-bottom: .4rem;
  font-size: .85rem;
  color: var(--muted);
}
.form-group input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .7rem 1rem;
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .15s;
}
.form-group input:focus { border-color: var(--red-l); }

button[type="submit"], .btn-primary {
  width: 100%;
  padding: .8rem;
  background: var(--red);
  border: none; border-radius: 8px;
  color: var(--text);
  font-size: 1rem; font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
button[type="submit"]:hover, .btn-primary:hover { background: var(--red-l); }
button[type="submit"]:disabled { opacity: .5; cursor: not-allowed; }

.error-msg {
  background: rgba(139,26,26,.2);
  border: 1px solid var(--red);
  border-radius: 8px;
  padding: .6rem .9rem;
  font-size: .9rem;
  color: #f87171;
  margin-bottom: 1rem;
}

/* ── Chat ───────────────────────────────────────────── */

.chat-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.chat-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: .9rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.chat-header .logo { margin: 0; font-size: 1.1rem; }

/* ── Split layout ───────────────────────────────────── */

.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.chat-pane {
  width: 35%;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow: hidden;
}

/* ── Session banner ─────────────────────────────────── */

.session-banner {
  background: rgba(30, 58, 138, 0.25);
  border-bottom: 1px solid var(--blue);
  padding: .75rem 1rem;
  flex-shrink: 0;
}
.session-banner p {
  font-size: .85rem;
  color: var(--text);
  margin-bottom: .6rem;
}
.session-banner-actions { display: flex; gap: .5rem; }
.btn-continue {
  flex: 1;
  padding: .4rem .8rem;
  background: var(--blue);
  border: none; border-radius: 8px;
  color: var(--text); font-size: .82rem; font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-continue:hover { background: var(--blue-l); }
.btn-new-start {
  flex: 1;
  padding: .4rem .8rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted); font-size: .82rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-new-start:hover { color: var(--text); border-color: var(--muted); }

/* ── Preview pane ───────────────────────────────────── */

.preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #fff;
}

.preview-pane-header {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: .55rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  gap: .75rem;
}

.preview-label {
  font-size: .82rem;
  font-weight: 500;
  color: var(--muted);
  flex: 1;
}
.preview-label.live     { color: #86efac; }
.preview-label.branch   { color: var(--blue-l); }
.preview-label.building { color: #fbbf24; }

.preview-pane-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-shrink: 0;
}

.btn-approve-inline {
  padding: .35rem .85rem;
  background: #166534;
  border: none; border-radius: 8px;
  color: #dcfce7; font-size: .82rem; font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-approve-inline:hover { background: #15803d; }

.btn-refresh-preview {
  width: 30px; height: 30px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted); font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color .15s, border-color .15s;
}
.btn-refresh-preview:hover { color: var(--text); border-color: var(--muted); }

.preview-frame-wrapper {
  flex: 1;
  position: relative;
  overflow: hidden;
}

.preview-frame-wrapper iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
  display: block;
}

.preview-building {
  position: absolute;
  inset: 0;
  background: rgba(8, 13, 26, 0.88);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .75rem;
  color: var(--text);
}
.preview-building[hidden] { display: none !important; }
.preview-building p { font-size: .95rem; }
.building-hint { color: var(--muted); font-size: .82rem !important; }

.building-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--blue-l);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.btn-check-now {
  margin-top: .25rem;
  padding: .45rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted); font-size: .85rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-check-now:hover { color: var(--text); border-color: var(--muted); }

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  padding: .4rem .9rem;
  font-size: .85rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-logout:hover { color: var(--text); border-color: var(--muted); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

/* Message bubbles */
.msg {
  display: flex;
  max-width: 80%;
}
.msg.user  { align-self: flex-end; flex-direction: row-reverse; }
.msg.agent { align-self: flex-start; }

.msg-bubble {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .95rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.user  .msg-bubble { background: var(--red); color: var(--text); border-bottom-right-radius: 4px; }
.msg.agent .msg-bubble { background: var(--bg3); border: 1px solid var(--border); border-bottom-left-radius: 4px; }

/* Preview card */
.preview-card {
  align-self: flex-start;
  max-width: 90%;
  background: var(--bg3);
  border: 1px solid var(--blue);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}
.preview-card h4 {
  font-size: .85rem;
  color: var(--muted);
  margin-bottom: .5rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.preview-card a {
  color: var(--blue-l);
  font-size: .9rem;
  text-decoration: none;
  word-break: break-all;
}
.preview-card a:hover { text-decoration: underline; }
.preview-card .preview-actions {
  display: flex;
  gap: .75rem;
  margin-top: .9rem;
}
.btn-approve {
  flex: 1;
  padding: .6rem;
  background: #166534;
  border: none; border-radius: 8px;
  color: #dcfce7;
  font-size: .9rem; font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-approve:hover { background: #15803d; }
.btn-request-change {
  flex: 1;
  padding: .6rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: .9rem;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.btn-request-change:hover { color: var(--text); border-color: var(--muted); }

/* Token-Verbrauch unter der Antwort (Variante B: gegen Output-Limit) */
.msg-meta {
  align-self: flex-start;
  font-size: .7rem;
  color: var(--muted);
  margin-top: -.6rem;
  padding-left: .25rem;
  opacity: .8;
}

/* Typing indicator */
.typing-wrap {
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  gap: .45rem;
}
.typing-caption {
  font-size: .8rem;
  color: var(--muted);
  font-style: italic;
  padding-left: .25rem;
  animation: caption-fade .4s ease;
}
@keyframes caption-fade { from { opacity: 0; } to { opacity: 1; } }

.typing {
  align-self: flex-start;
  display: flex; align-items: center; gap: .3rem;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .7rem 1rem;
}
.typing span {
  width: 7px; height: 7px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce .9s ease-in-out infinite;
}
.typing span:nth-child(2) { animation-delay: .15s; }
.typing span:nth-child(3) { animation-delay: .3s;  }
@keyframes bounce { 0%,80%,100%{ transform:translateY(0) } 40%{ transform:translateY(-6px) } }

/* Input area */
.chat-input-area {
  border-top: 1px solid var(--border);
  background: var(--bg2);
  padding: 1rem;
  flex-shrink: 0;
}
.chat-input-row {
  display: flex;
  gap: .75rem;
  align-items: flex-end;
}
.chat-input-row textarea {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: .75rem 1rem;
  color: var(--text);
  font-size: .95rem;
  font-family: inherit;
  resize: none;
  min-height: 46px;
  max-height: 160px;
  outline: none;
  transition: border-color .15s;
}
.chat-input-row textarea:focus { border-color: var(--red-l); }
.btn-send {
  width: 46px; height: 46px;
  background: var(--red);
  border: none; border-radius: 10px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.btn-send:hover  { background: var(--red-l); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; }
.btn-send svg { width: 18px; height: 18px; stroke: white; fill: none; }

/* Status hint */
.status-hint {
  text-align: center;
  font-size: .8rem;
  color: var(--muted);
  margin-top: .5rem;
}

/* Merged banner */
.merged-banner {
  align-self: center;
  background: rgba(22,101,52,.25);
  border: 1px solid #166534;
  border-radius: var(--radius);
  padding: .75rem 1.25rem;
  font-size: .9rem;
  color: #86efac;
  text-align: center;
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
