/*
 * KIWi Lichttechnik Assistant – Frontend (Wrapper-UI)
 * Ersteller: Benjamin Kürten, Rashad LouLou
 * Datum: 24.06.2026
 */
:root {
  --bg: #05070d;
  --ink: #f5f7fb;
  --muted: #7e879c;
  --blue: #2f7df0;
  --blue-deep: #1c4fb8;
  --cyan: #38bdf8;
  --border: rgba(255, 255, 255, 0.08);
  --surface: rgba(255, 255, 255, 0.04);
}

* { box-sizing: border-box; }

/* The `hidden` attribute is only a weak UA rule (display:none) and gets
   overridden by author rules like `.chat-screen { display: grid }`. Force it
   so a hidden view is truly gone — otherwise login + chat render stacked and
   the protected UI is visible before authentication. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea { font-family: inherit; }

/* ---------------------------------------------------------------- */
/* Auth screen: dark flat surface, single blue glow + circuit grid   */
/* ---------------------------------------------------------------- */

.auth-screen {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: var(--bg) url("/assets/auth-background.png") center center / cover no-repeat;
}

.auth-stage {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 72px;
  padding: 32px;
  max-width: 1080px;
}

.auth-brand { max-width: 420px; }

.auth-brand-logo {
  height: 34px;
  margin-bottom: 22px;
  animation: logo-glow 5s ease-in-out infinite;
}
@keyframes logo-glow {
  0%, 100% { filter: drop-shadow(0 0 0 rgba(47, 125, 240, 0)); }
  50% { filter: drop-shadow(0 0 14px rgba(47, 125, 240, 0.45)); }
}

.auth-eyebrow {
  margin: 0 0 14px; font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted); font-weight: 700;
  opacity: 0; animation: fade-up 0.6s ease-out 0.1s forwards;
}

.auth-brand h1 {
  font-size: 44px; line-height: 1.15; font-weight: 800; letter-spacing: -0.02em; margin: 0 0 14px;
  opacity: 0; animation: fade-up 0.6s ease-out 0.22s forwards;
}
.auth-brand h1 span { color: var(--blue); }

.auth-lead {
  color: var(--muted); font-size: 16px; line-height: 1.6; margin: 0; max-width: 380px;
  opacity: 0; animation: fade-up 0.6s ease-out 0.34s forwards;
}

/* Interop check: rag-core reachability, populated by app.js. Not part of the
   Open WebUI auth flow above -- purely a "is the backend stack up" signal. */
.rag-core-badge {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 14px 0 0; padding: 5px 10px;
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border);
  border-radius: 999px;
}
.rag-core-badge::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted); flex-shrink: 0;
}
.rag-core-badge.is-ok { color: var(--cyan); }
.rag-core-badge.is-ok::before { background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.rag-core-badge.is-down { color: #fca5a5; }
.rag-core-badge.is-down::before { background: #f87171; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-card {
  position: relative;
  width: 380px;
  flex-shrink: 0;
  background: linear-gradient(165deg, #141a26, #0c0f17);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 26px 26px 24px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  opacity: 0;
  animation: rise 0.6s ease-out 0.46s forwards;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

#view-auth.is-leaving .auth-stage {
  animation: stage-out 0.38s ease-in forwards;
}
@keyframes stage-out {
  to { opacity: 0; transform: scale(0.97); }
}

.auth-tabs {
  position: relative;
  display: flex;
  gap: 28px;
  margin-bottom: 22px;
  border-bottom: 1px solid var(--border);
}
.auth-tab {
  background: none; border: 0; cursor: pointer;
  padding: 0 0 14px; font-size: 14px; font-weight: 600; color: var(--muted);
  transition: color 0.25s ease;
}
.auth-tab.is-active { color: var(--ink); }
.auth-tab-indicator {
  position: absolute;
  bottom: -1px; left: 0;
  height: 2px; width: 88px;
  background: var(--blue);
  transition: transform 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
}
.auth-tab-indicator.is-right { transform: translateX(116px); width: 102px; }

.auth-form { padding-top: 4px; }
.field { display: block; margin-bottom: 16px; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 7px; }
.field-control { position: relative; display: flex; align-items: center; }
.field-icon {
  position: absolute; left: 13px; width: 16px; height: 16px;
  color: var(--muted); pointer-events: none;
}
.field-control input {
  width: 100%; padding: 12px 14px 12px 38px;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-size: 14px;
  transition: border-color 0.2s ease, background 0.2s ease;
}
.field-control.has-toggle input { padding-right: 38px; }
.field-control input:focus {
  outline: none; border-color: var(--blue);
  background: rgba(47, 125, 240, 0.08);
}
.field-toggle {
  position: absolute; right: 10px;
  background: none; border: 0; padding: 4px; cursor: pointer;
  color: var(--muted); display: flex;
}
.field-toggle:hover { color: var(--ink); }
.field-toggle svg { width: 18px; height: 18px; }
.field-toggle .icon-eye-off { display: none; }
.field-toggle.is-visible .icon-eye { display: none; }
.field-toggle.is-visible .icon-eye-off { display: block; }

.auth-divider {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 0 16px; color: var(--muted); font-size: 12px; font-weight: 600;
}
.auth-divider::before, .auth-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-weight: 600; cursor: pointer; font-size: 14px;
  transition: transform 0.15s ease, box-shadow 0.2s ease, background 0.2s ease;
}
.button:hover { transform: translateY(-1px); }
.button.ghost:hover { background: rgba(255, 255, 255, 0.08); }
.button.primary {
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
  color: #fff; border: 0; width: 100%; font-weight: 700;
  box-shadow: 0 10px 28px rgba(47, 125, 240, 0.35);
}
.button.primary:hover {
  box-shadow: 0 14px 36px rgba(47, 125, 240, 0.5);
}
.button.primary .icon-arrow { width: 16px; height: 16px; transition: transform 0.2s ease; }
.button.primary:hover .icon-arrow { transform: translateX(3px); }

.button.oauth-google {
  width: 100%; background: #fff; color: #1f2430; border: 1px solid rgba(0, 0, 0, 0.05);
}
.button.oauth-google:hover { background: #f3f4f6; }

.error {
  background: rgba(239, 68, 68, 0.12); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 10px; padding: 10px 14px; font-size: 13px; margin: 0 0 14px;
}
/* Friendly (non-error) variant, e.g. "registration pending approval". */
.error.is-info {
  background: rgba(56, 189, 248, 0.12); color: #bae6fd; border-color: rgba(56, 189, 248, 0.4);
}

/* ---------------------------------------------------------------- */
/* Chat screen: sidebar + main, distinct from any third-party UI     */
/* ---------------------------------------------------------------- */

.chat-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
  background: var(--bg);
}

.sidebar {
  display: flex; flex-direction: column;
  padding: 22px 18px;
  background: #080b16;
  border-right: 1px solid var(--border);
}
.sidebar-brand { padding: 6px 8px 22px; }
.sidebar-brand img { height: 26px; }

.sidebar-section { display: flex; flex-direction: column; gap: 16px; flex: 1; }
.inline-field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.inline-field select, .inline-field input {
  padding: 9px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03); color: var(--ink); font-size: 13px;
}
.inline-field select:focus, .inline-field input:focus {
  outline: none; border-color: var(--cyan);
}

.sidebar-footer { display: flex; flex-direction: column; gap: 10px; padding-top: 16px; border-top: 1px solid var(--border); }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding: 0 4px; }
.user-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }

.chat-main {
  display: flex; flex-direction: column;
  padding: 22px 28px;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}

.messages {
  flex: 1; overflow-y: auto;
  padding: 8px 4px 20px;
  display: flex; flex-direction: column; gap: 16px;
}
.msg {
  max-width: 72%; padding: 13px 17px; border-radius: 16px; line-height: 1.6; font-size: 14.5px;
  white-space: pre-wrap;
  animation: msg-in 0.25s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  color: #04101f;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ink);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.composer {
  display: flex; gap: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 10px;
}
.composer textarea {
  flex: 1; min-height: 48px; max-height: 160px; padding: 11px 12px;
  border-radius: 12px; border: 0; font-size: 14px; resize: vertical;
  background: transparent; color: var(--ink);
}
.composer textarea:focus { outline: none; }
.composer .send { width: auto; padding: 12px 22px; align-self: flex-end; }

/* ---------------------------------------------------------------- */
/* Admin screen: user management (list / approve / role / delete)    */
/* ---------------------------------------------------------------- */

.admin-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  padding: 26px 32px 40px;
  max-width: 1040px;
  width: 100%;
  margin: 0 auto;
}

.admin-head {
  display: flex; align-items: center; gap: 16px;
  margin-bottom: 22px;
}
.admin-head h1 { font-size: 22px; font-weight: 800; margin: 0; letter-spacing: -0.01em; }
.admin-head .spacer { flex: 1; }
.admin-sub { color: var(--muted); font-size: 13px; margin: 0 0 18px; }

.button.sm { padding: 8px 12px; font-size: 12.5px; font-weight: 600; }
.button.danger { color: #fca5a5; border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.1); }
.button.danger:hover { background: rgba(239, 68, 68, 0.18); }

.admin-table {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
}
.admin-row {
  display: grid;
  grid-template-columns: 1.4fr 1.8fr 0.8fr auto;
  align-items: center;
  gap: 14px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
}
.admin-row:last-child { border-bottom: 0; }
.admin-row.head { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); font-weight: 700; background: rgba(255,255,255,0.02); }
.admin-row .name { font-weight: 600; font-size: 14px; }
.admin-row .email { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.admin-row .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.role-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  border: 1px solid var(--border);
}
.role-badge.admin { color: var(--cyan); border-color: rgba(56,189,248,0.4); background: rgba(56,189,248,0.1); }
.role-badge.user { color: #86efac; border-color: rgba(134,239,172,0.35); background: rgba(134,239,172,0.1); }
.role-badge.pending { color: #fcd34d; border-color: rgba(252,211,77,0.4); background: rgba(252,211,77,0.12); }

.admin-empty { padding: 28px; text-align: center; color: var(--muted); font-size: 14px; }

.admin-add { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; align-items: center; }
.admin-add input, .admin-add select {
  padding: 9px 11px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font-size: 13px;
}
.admin-add input:focus, .admin-add select:focus { outline: none; border-color: var(--blue); }
.admin-add input { min-width: 150px; }
.admin-add .button.sm { width: auto; }

.kn-meta { color: var(--muted); font-size: 12px; }
.kn-upload {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 4px 2px 14px;
}
.kn-upload input[type="file"] {
  color: var(--muted); font-size: 13px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 10px;
}
.kn-upload input[type="file"]::file-selector-button {
  background: rgba(255,255,255,0.06); color: var(--ink);
  border: 0; border-radius: 8px; padding: 6px 10px; margin-right: 10px;
  cursor: pointer; font-weight: 600;
}
.kn-file-row {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  padding: 12px 18px; border-bottom: 1px solid var(--border);
}
.kn-file-row:last-child { border-bottom: 0; }
.kn-file-row .fname { font-size: 14px; word-break: break-all; }
.you-tag { font-size: 11px; color: var(--muted); font-weight: 600; margin-left: 6px; }

@media (max-width: 720px) {
  .admin-row { grid-template-columns: 1fr; gap: 6px; }
  .admin-row.head { display: none; }
  .admin-row .actions { justify-content: flex-start; margin-top: 6px; }
}

@media (max-width: 900px) {
  .auth-stage { flex-direction: column; gap: 36px; text-align: center; }
  .auth-brand { display: flex; flex-direction: column; align-items: center; }
  .auth-brand h1 { font-size: 32px; }
  .chat-screen { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); }
  .sidebar-section { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { flex-direction: row; align-items: center; border-top: 0; }
}

/* ---------------------------------------------------------------- */
/* Compare screen: A/B split — two models answer the same prompt     */
/* ---------------------------------------------------------------- */

.compare-screen {
  min-height: 100vh;
  display: flex; flex-direction: column;
  padding: 22px 28px;
  max-width: 1240px; width: 100%; margin: 0 auto;
}
.compare-kn { flex-direction: row; align-items: center; gap: 8px; font-size: 12px; }
.compare-kn select {
  padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03); color: var(--ink); font-size: 13px;
}

.compare-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  flex: 1; min-height: 0; margin-bottom: 14px;
}
.compare-col {
  display: flex; flex-direction: column; min-height: 340px;
  border: 1px solid var(--border); border-radius: 16px;
  background: #080b16; overflow: hidden;
}
.compare-col-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border);
}
.compare-tag {
  width: 26px; height: 26px; border-radius: 8px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 13px;
  color: #04101f; background: linear-gradient(135deg, var(--blue), var(--cyan));
}
.compare-tag.b { color: #fff; background: linear-gradient(135deg, #a855f7, #ec4899); }
.compare-model {
  flex: 1; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03); color: var(--ink); font-size: 13px;
}
.compare-model:focus { outline: none; border-color: var(--cyan); }
.compare-messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 14px;
}
.compare-messages .msg { max-width: 100%; }

/* Sources block (used in chat + compare) */
.msg-text { white-space: pre-wrap; }
.msg-sources { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; font-size: 12.5px; }
.msg-sources > summary { cursor: pointer; color: var(--cyan); font-weight: 700; list-style: none; }
.msg-sources > summary::-webkit-details-marker { display: none; }
.msg-sources > summary::before { content: "◆ "; }
.source-item {
  margin-top: 8px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 10px; background: rgba(255, 255, 255, 0.02);
}
.source-meta { font-weight: 700; font-size: 12px; color: var(--ink); }
.source-excerpt { color: var(--muted); margin-top: 4px; line-height: 1.5; }
.source-link { display: inline-block; margin-top: 6px; color: var(--cyan); font-size: 12px; text-decoration: none; }
.source-link:hover { text-decoration: underline; }

/* Per-answer feedback (stars + thumbs up/down) */
.msg-feedback { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.star-rating { display: inline-flex; gap: 2px; }
.star {
  background: none; border: 0; padding: 0 1px; cursor: pointer;
  font-size: 17px; line-height: 1; color: rgba(255, 255, 255, 0.24);
  transition: color 0.12s ease;
}
.star:hover, .star.is-on { color: #fcd34d; }
.fb-thumbs { display: inline-flex; gap: 8px; }
.fb-btn {
  border: 1px solid var(--border); background: rgba(255, 255, 255, 0.03);
  border-radius: 8px; padding: 4px 10px; cursor: pointer; font-size: 14px;
  line-height: 1; color: var(--ink); transition: background 0.15s ease, border-color 0.15s ease;
}
.fb-btn:hover { background: rgba(255, 255, 255, 0.08); }
.fb-btn.is-active { border-color: var(--cyan); background: rgba(56, 189, 248, 0.15); }
.fb-note { font-size: 12px; color: #86efac; font-weight: 600; }

/* A/B verdict bar */
.compare-verdict {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px; border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: 14px; background: rgba(56, 189, 248, 0.07); margin-bottom: 14px;
}
.verdict-q { font-weight: 700; font-size: 14px; }
.verdict-result { font-weight: 700; font-size: 14px; color: var(--muted); }
.verdict-result.is-set { color: var(--cyan); }
.button.sm.is-active { border-color: var(--cyan); background: rgba(56, 189, 248, 0.18); color: var(--ink); }
.verdict-comment {
  flex-basis: 100%; margin-top: 8px; min-height: 54px;
  border-radius: 10px; border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03); color: var(--ink);
  padding: 8px 10px; font-size: 13px; resize: vertical;
}
.verdict-comment:focus { outline: none; border-color: var(--cyan); }

.compare-screen .composer { max-width: 100%; }

@media (max-width: 860px) {
  .compare-grid { grid-template-columns: 1fr; }
}
