* { box-sizing: border-box; }

:root {
  --bg: #212121;
  --sidebar: #171717;
  --panel: #2f2f2f;
  --panel-hover: #3a3a3a;
  --user-bubble: #303030;
  --text: #ececec;
  --muted: #9b9b9b;
  --line: #ffffff1a;
  --accent: #19c37d;
  --accent-dark: #0f9c65;
  --danger: #ff6b6b;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

a { color: var(--accent); }

/* ---------------- Login ---------------- */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 50% -10%, #19c37d22, transparent 70%),
    var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: #1c1c1c;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: 0 24px 60px #00000066;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  letter-spacing: .2px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  background: linear-gradient(140deg, var(--accent), #0b6b52);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  flex: none;
}

.auth-card h1 {
  font-size: 23px;
  margin: 22px 0 6px;
  font-weight: 600;
}

.auth-card p.sub {
  color: var(--muted);
  margin: 0 0 22px;
  font-size: 14px;
}

.field { margin-bottom: 14px; }

.field label {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 13px;
  border-radius: 11px;
  border: 1px solid #ffffff20;
  background: #262626;
  outline: none;
  transition: border-color .15s, background .15s;
}

.field input:focus {
  border-color: var(--accent);
  background: #2b2b2b;
}

.btn-primary {
  width: 100%;
  padding: 11px 16px;
  border: 0;
  border-radius: 11px;
  background: var(--accent);
  color: #07231a;
  font-weight: 600;
  margin-top: 6px;
  transition: background .15s, opacity .15s;
}

.btn-primary:hover { background: #21d78d; }
.btn-primary:disabled { opacity: .6; cursor: default; }

.auth-switch {
  margin-top: 18px;
  text-align: center;
  font-size: 13.5px;
  color: var(--muted);
}

.auth-switch button {
  background: none;
  border: 0;
  color: var(--accent);
  padding: 0;
  font-weight: 500;
}

.notice {
  margin-top: 14px;
  font-size: 13.5px;
  padding: 9px 12px;
  border-radius: 10px;
  display: none;
}

.notice.error {
  display: block;
  background: #ff6b6b1f;
  color: #ffb4b4;
  border: 1px solid #ff6b6b40;
}

.notice.ok {
  display: block;
  background: #19c37d1f;
  color: #8ff0c8;
  border: 1px solid #19c37d40;
}

.auth-foot {
  margin-top: 20px;
  font-size: 12px;
  color: #6f6f6f;
  text-align: center;
}

/* ---------------- App-Shell ---------------- */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 264px;
  flex: none;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
  border-right: 1px solid var(--line);
  transition: margin-left .2s ease;
}

.sidebar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 10px;
}

.sidebar .brand { font-size: 15px; }
.sidebar .brand-mark { width: 26px; height: 26px; border-radius: 8px; font-size: 13px; }

.icon-btn {
  background: none;
  border: 0;
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  transition: background .15s, color .15s;
}

.icon-btn:hover { background: #ffffff14; color: var(--text); }

.new-chat {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  transition: background .15s;
}

.new-chat:hover { background: #ffffff12; }
.new-chat span.plus { font-size: 17px; color: var(--muted); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border-radius: 10px;
  border: 0;
  background: none;
  color: var(--text);
  font-size: 14px;
  text-align: left;
}

.nav-item:hover { background: #ffffff10; }
.nav-item .ic { width: 18px; color: var(--muted); text-align: center; }

.sidebar-section {
  color: #7d7d7d;
  font-size: 12px;
  padding: 16px 12px 6px;
  text-transform: none;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px 8px;
}

.chat-list::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-thumb { background: #ffffff1f; border-radius: 8px; }

.chat-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  border-radius: 10px;
  padding: 0 6px 0 11px;
}

.chat-entry:hover { background: #ffffff10; }
.chat-entry.active { background: #ffffff1a; }

.chat-entry .title {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  color: var(--text);
  text-align: left;
  font-size: 13.5px;
  padding: 8px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-entry .del {
  background: none;
  border: 0;
  color: var(--muted);
  opacity: 0;
  border-radius: 7px;
  width: 26px;
  height: 26px;
  flex: none;
  font-size: 15px;
  line-height: 1;
}

.chat-entry:hover .del { opacity: 1; }
.chat-entry .del:hover { background: #ff6b6b26; color: var(--danger); }

.chat-list .empty {
  color: #6f6f6f;
  font-size: 13px;
  padding: 4px 12px;
}

.sidebar-bottom {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 12px;
}

.user-row:hover { background: #ffffff10; }
.user-row .avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(140deg, #4b6bfb, #8b5cf6);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  flex: none;
}
.user-row .who { flex: 1; min-width: 0; }
.user-row .who b {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-row .who small { color: var(--muted); font-size: 11.5px; }

/* ---------------- Chat-Bereich ---------------- */
.chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.topbar {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid transparent;
}

.model-select {
  background: transparent;
  border: 0;
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  padding: 6px 26px 6px 8px;
  border-radius: 9px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.model-select:hover { background-color: #ffffff12; }
.model-select option { background: #2a2a2a; color: var(--text); }

.key-chip {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  background: #ffffff0d;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 11px;
}

.key-chip .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}

.key-chip.warn .dot { background: #ffb347; }
.key-chip.bad .dot { background: var(--danger); }

.mobile-menu { display: none; }

.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.chat-scroll::-webkit-scrollbar { width: 10px; }
.chat-scroll::-webkit-scrollbar-thumb { background: #ffffff1f; border-radius: 8px; }

.welcome {
  max-width: 760px;
  margin: 0 auto;
  padding: 12vh 20px 20px;
  text-align: center;
}

.welcome.hidden { display: none; }
.welcome h1 {
  font-size: 29px;
  font-weight: 500;
  margin: 0 0 8px;
  letter-spacing: -.2px;
}
.welcome p { color: var(--muted); margin: 0 auto 26px; max-width: 460px; font-size: 14px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.chip {
  background: #ffffff0d;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
  transition: background .15s;
}

.chip:hover { background: #ffffff1a; }

.messages {
  max-width: 780px;
  margin: 0 auto;
  padding: 20px 20px 8px;
}

.msg { margin-bottom: 26px; }

.msg.user {
  display: flex;
  justify-content: flex-end;
}

.msg.user .bubble {
  background: var(--user-bubble);
  border-radius: 20px;
  padding: 10px 16px;
  max-width: 78%;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.msg-files:first-child { margin-top: 0; }

.file-tag {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #ffffff1a;
  border-radius: 9px;
  padding: 4px 9px;
  font-size: 12px;
  white-space: nowrap;
  max-width: 240px;
}

.file-tag span { overflow: hidden; text-overflow: ellipsis; }
.file-tag .ficon { color: #9be9c6; display: grid; place-items: center; flex: none; }

.drop-overlay {
  position: absolute;
  inset: 10px;
  border: 2px dashed var(--accent);
  border-radius: 18px;
  background: #19c37d1a;
  display: none;
  align-items: center;
  justify-content: center;
  color: #b8f5dc;
  font-weight: 600;
  z-index: 30;
  pointer-events: none;
}

.drop-overlay.show { display: flex; }

.msg.ai .who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
}

.msg.ai .who .brand-mark { width: 22px; height: 22px; border-radius: 7px; font-size: 11px; }

.msg.ai .content { word-wrap: break-word; }
.msg.ai .content > *:first-child { margin-top: 0; }
.msg.ai .content > *:last-child { margin-bottom: 0; }

.content p { margin: 0 0 12px; }
.content h1, .content h2, .content h3 { margin: 20px 0 10px; line-height: 1.3; }
.content h1 { font-size: 22px; }
.content h2 { font-size: 19px; }
.content h3 { font-size: 16.5px; }
.content ul, .content ol { margin: 0 0 12px; padding-left: 24px; }
.content li { margin: 4px 0; }
.content code {
  background: #ffffff1a;
  padding: 2px 5px;
  border-radius: 5px;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 13px;
}
.content pre {
  background: #0d0d0d;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 14px;
}

.code-block {
  margin: 0 0 14px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.code-block pre {
  margin: 0;
  border: 0;
  border-radius: 0;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #161616;
  border-bottom: 1px solid var(--line);
  padding: 5px 6px 5px 14px;
  min-height: 32px;
}

.code-lang {
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: .3px;
  color: #9b9b9b;
  text-transform: none;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: #b9b9b9;
  font-size: 11.5px;
  padding: 4px 8px;
  border-radius: 8px;
  transition: background .15s, color .15s;
}

.copy-btn:hover { background: #ffffff1a; color: #fff; }
.copy-btn.copied { color: var(--accent); }
.copy-btn svg { flex: none; }
.content pre code { background: none; padding: 0; font-size: 13px; line-height: 1.6; }
.content blockquote {
  border-left: 3px solid #ffffff33;
  margin: 0 0 12px;
  padding: 2px 0 2px 14px;
  color: #c9c9c9;
}
.content table { border-collapse: collapse; margin: 0 0 14px; width: 100%; font-size: 14px; }
.content th, .content td { border: 1px solid #ffffff26; padding: 7px 10px; text-align: left; }
.content th { background: #ffffff0f; }
.content hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.content a { text-decoration: underline; }

.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.msg.ai .error-text { color: #ffb4b4; }

/* Composer */
.composer-wrap {
  flex: none;
  padding: 8px 20px 14px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.composer {
  max-width: 780px;
  margin: 0 auto;
  background: var(--panel);
  border-radius: 26px;
  padding: 8px 8px 8px 8px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  border: 1px solid #ffffff12;
  transition: border-color .15s;
}

.attach-btn {
  width: 34px;
  height: 34px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #c9c9c9;
  display: grid;
  place-items: center;
  margin-bottom: 1px;
  transition: background .15s, color .15s;
}

.attach-btn:hover { background: #ffffff1a; color: #fff; }

.composer-body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.file-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 0 2px;
}

.file-list[hidden] { display: none; }

.file-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #ffffff14;
  border: 1px solid #ffffff1f;
  border-radius: 10px;
  padding: 5px 7px 5px 9px;
  font-size: 12.5px;
  max-width: 240px;
}

.file-chip .ficon { color: #9be9c6; display: grid; place-items: center; flex: none; }
.file-chip .fname { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip .fsize { color: #8f8f8f; font-size: 11px; flex: none; }

.file-chip .fremove {
  background: none;
  border: 0;
  color: #9b9b9b;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  flex: none;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}

.file-chip .fremove:hover { background: #ffffff26; color: #fff; }

.composer:focus-within { border-color: #ffffff2e; }

.composer textarea {
  flex: 1;
  border: 0;
  background: none;
  resize: none;
  outline: none;
  max-height: 200px;
  min-height: 26px;
  padding: 8px 0;
  line-height: 1.5;
  color: var(--text);
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: #ffffff33 transparent;
}

.composer textarea::-webkit-scrollbar { width: 6px; }
.composer textarea::-webkit-scrollbar-track { background: transparent; }
.composer textarea::-webkit-scrollbar-thumb {
  background: #ffffff2e;
  border-radius: 6px;
}

.composer textarea::placeholder { color: #8f8f8f; }

.send-btn {
  width: 36px;
  height: 36px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  color: #111;
  display: grid;
  place-items: center;
  transition: opacity .15s, transform .1s;
}

.send-btn:disabled { background: #ffffff2e; color: #8f8f8f; cursor: default; }
.send-btn:not(:disabled):hover { transform: scale(1.05); }
.send-btn.stop { background: #ffffff; }

.hint {
  max-width: 780px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.5px;
  color: #7d7d7d;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%) translateY(12px);
  background: #2b2b2b;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 11px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 60;
  box-shadow: 0 12px 30px #00000066;
}

.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 820px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    margin-left: -280px;
    box-shadow: 0 0 40px #000000aa;
    width: 272px;
  }
  .sidebar.open { margin-left: 0; }
  .mobile-menu { display: grid; }
  .welcome { padding-top: 8vh; }
  .welcome h1 { font-size: 23px; }
  .msg.user .bubble { max-width: 88%; }
  .key-chip span.label { display: none; }
}
