:root {
  --bg: #050505;
  --surface: #0d0d0d;
  --surface-2: #131313;
  --border: #222;
  --text: #f5f5f5;
  --muted: #8a8a8a;
  --accent: #ff7a1a;
  --accent-hover: #ff8d3a;
}

/* Reset & Global */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  width: 100%;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", sans-serif;
  overflow-x: hidden;
  -ms-overflow-style: none;  /* IE and Edge */
  scrollbar-width: none;
}

body::-webkit-scrollbar {
  display: none;
}

i.ph { font-size: 22px; flex-shrink: 0; }

/* --- TOPBAR --- */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 100;
}

.brand {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-family: "JetBrains Mono", monospace;
  font-size: 1.1rem;
  font-weight: 500;
}

.topbar-btn {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: 0.2s;
}

.topbar-btn:hover { background: var(--surface-2); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.nav-btn,
.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  height: 46px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: 0.2s;
}

.nav-btn:hover,
.login-btn:hover {
  background: var(--surface-2);
}

.login-btn i {
  font-size: 24px;
}

.login-btn:hover {
  background: var(--surface-2);
  border-color: var(--muted);
}

.login-btn i {
  font-size: 24px;
}

/* Auf Mobile Text verstecken, um Platz zu sparen */
@media (max-width: 480px) {
  .login-btn span {
    display: none;
  }
  .login-btn {
    padding: 10px;
    width: 46px;
    height: 46px;
    justify-content: center;
  }
}

/* Container für die Positionierung */
.user-menu-container {
  position: relative;
  height: 46px;
}

.user-popup {
  position: absolute;
  top: calc(100% + 12px);
  right: 0;
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  display: none; /* Standardmäßig aus */
  flex-direction: column;
  gap: 16px;
  z-index: 200;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.user-popup.show {
  display: flex;
}

.user-popup-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.save-key-btn {
  width: 100%;
  padding: 8px;
  margin-top: 8px;
  border-radius: 8px;
  border: 1px solid #113311; /* Dunkelgrüner Rand */
  background: #0a1a0a;      /* Sehr dunkler grüner Hintergrund */
  color: #44ff44;           /* Leuchtendes Grün für Text/Icon */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: 0.2s;
  font-family: inherit;
  font-weight: 500;
}

.save-key-btn:hover {
  background: #112211;      /* Leicht helleres Grün beim Hover */
}

.save-key-btn:active {
  transform: translateY(0);
}

.save-key-btn i {
  font-size: 1.2rem;
}

.user-popup-content .input-group {
  margin-bottom: 15px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-group label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.input-group input {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  font-family: "JetBrains Mono", monospace;
  font-size: 13px;
  outline: none;
}

.input-helper {
  margin: 8px 0 16px 0;
  display: flex;
}

.input-helper a {
  color: rgba(255, 255, 255, 0.5); /* Dezentes Grau passend zum Label */
  font-size: 0.8rem;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.03); /* Ganz leichter Hintergrund-Schimmer */
  border: 1px solid rgba(255, 255, 255, 0.05);
  transition: all 0.2s ease;
}

.input-helper a:hover {
  color: #fff; /* Wird weiß beim Drüberfahren */
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.2);
}

.input-helper i {
  font-size: 1rem;
  color: var(--accent, #007aff); /* Das Icon darf farbig bleiben */
}

.logout-btn {
  width: 100%;
  padding: 8px;
  margin-top: 8px;
  border-radius: 8px;
  border: 1px solid #442222;
  background: #221111;
  color: #ff5555;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: 0.2s;
  font-family: Inter, sans-serif;
}

.logout-btn:hover {
  background: #331111;
}

/* --- SIDEBAR --- */
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  transition: 0.3s;
  z-index: 150;
}

.sidebar-overlay.active {
  opacity: 1;
  visibility: visible;
}

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  max-width: 85vw;
  height: 100vh;
  background: #080808;
  border-right: 1px solid var(--border);
  z-index: 200;
  transform: translateX(-100%);
  transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 80px 20px 20px;
  display: flex;
  flex-direction: column;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.sidebar-search {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 14px 18px;
  border-radius: 999px;
  margin-bottom: 24px;
}

.sidebar-search input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  width: 100%;
  font-size: 16px;
}

.sidebar-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: 14px;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font-size: 1rem;
  transition: 0.2s;
}

.sidebar-item:hover { background: var(--surface); }
.sidebar-item i { color: var(--muted); }

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 18px 0;
}

.sidebar-title {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  margin: 12px 18px;
  letter-spacing: 1px;
  font-weight: 600;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  width: 100%;
  padding: 12px 18px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: 0.2s;
}

.chat-item:hover { background: var(--surface-2); color: var(--accent); }

/* --- HERO --- */
.hero {
  position: absolute;
  top: 40%;
  left: 32px;
  transform: translateY(-50%);
  width: calc(100% - 64px);
  max-width: 800px;
}

.hero-text h1 {
  font-family: "JetBrains Mono", monospace;
  font-size: clamp(2.2rem, 8vw, 4rem);
  margin-bottom: 12px;
  font-weight: 600;
}

.hero-text p {
  font-size: 1.2rem;
  color: var(--muted);
  margin-bottom: 32px;
}

/* --- CHAT INPUT (EXPANDABLE) --- */
.chat-input-wrapper {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100%;
  display: flex;
  justify-content: center;
  padding: 20px 32px 32px;
  background: linear-gradient(transparent, var(--bg) 40%);
  z-index: 90;
}

.chat-input-container {
  width: 100%;
  max-width: 850px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 26px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  transition: border-color 0.3s;
}

.chat-input-container:focus-within { border-color: #444; }

.message-input {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 16px;
  font-family: inherit;
  resize: none;
  padding: 8px 12px;
  line-height: 24px;
  max-height: 88px; /* 3 Zeilen Limit */
  overflow-y: hidden;
}

.chat-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.control-group { display: flex; gap: 8px; }

.circle-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--surface-2);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: 0.2s;
}

.circle-btn:hover { background: #1a1a1a; }
.send-btn { background: var(--accent); color: #fff; }
.send-btn:hover { background: var(--accent-hover); }

/* --- MODEL SELECTION POPUP --- */
.model-select-container {
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}

.selected-model-badge {
  font-size: 12px;
  font-family: "JetBrains Mono", monospace;
  color: var(--muted);
  background: var(--surface-2);
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--border);
  white-space: nowrap;
  /*max-width: 150px;
  overflow: hidden;*/
  text-overflow: ellipsis;
  display: none; /* Erst anzeigen, wenn ein Modell geladen ist */
}

.selected-model-badge.visible {
  display: block;
}

.model-popup {
  position: absolute;
  bottom: calc(100% + 16px); /* Erscheint über der Eingabezeile */
  left: 0;
  width: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 12px;
  display: none; /* Standardmäßig aus */
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.model-popup.show {
  display: flex; /* Wird durch JS getoggled */
}

.model-popup-header {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 4px 8px 8px;
  font-weight: 600;
}

/* Einzelne Modell-Einträge */
.model-option {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  cursor: pointer;
  transition: 0.2s;
  text-align: left;
}

.model-option:hover {
  background: var(--surface-2);
}

.model-option.active {
  background: rgba(255, 122, 26, 0.1);
  border-color: var(--accent);
}

.model-option i {
  font-size: 20px;
  color: var(--muted);
}

.model-option.active i {
  color: var(--accent);
}

.model-info {
  display: flex;
  flex-direction: column;
}

.model-name {
  font-size: 14px;
  font-weight: 500;
}

.model-desc {
  font-size: 11px;
  color: var(--muted);
}

.model-search {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 12px;
}

.model-search i {
    font-size: 16px;
    color: var(--muted);
}

.model-search input {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-size: 13px;
    width: 100%;
    font-family: Inter, sans-serif;
}

.model-list {
    max-height: 320px; /* Höhe für etwa 5-6 Einträge */
    overflow-y: auto;  /* Scrollbar erscheint bei Bedarf */
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 4px; /* Platz für die Scrollbar */
}

/* Scrollbar-Styling für den "JetBrains"-Look */
.model-list::-webkit-scrollbar {
    width: 6px;
}

.model-list::-webkit-scrollbar-track {
    background: transparent;
}

.model-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 10px;
}

.model-list::-webkit-scrollbar-thumb:hover {
    background: var(--muted);
}

/* Nachrichten */
.chat-messages {
    flex: 1;
    padding: 100px 24px 150px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.message {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 85%;
}

.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }

.message-content {
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
}

.user .message-content {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-right-radius: 4px;
}

.assistant .message-content {
    background: transparent;
    color: var(--text);
    padding-left: 0;
}

/* Animation für das Pulsieren */
@keyframes pulse-shimmer {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
  100% {
    opacity: 1;
  }
}

/* Die Klasse, die während des Ladens aktiv ist */
.message.assistant.is-loading .message-content {
  color: var(--muted);
  position: relative;
  overflow: hidden;
  display: inline-block;
  animation: pulse-shimmer 2s ease-in-out infinite;
}

/* Optional: Ein schimmernder Verlaufseffekt */
.message.assistant.is-loading .message-content::after {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 122, 26, 0.1),
    transparent
  );
  animation: shimmer-swipe 2s infinite;
}

@keyframes shimmer-swipe {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* --- RESPONSIVE --- */
@media (max-width: 768px) {
  .hero { left: 24px; width: calc(100% - 48px); }
  .chat-input-wrapper { padding: 12px 16px 24px; }
  .sidebar { width: 280px; }
}