/* ChatLPC – Styles */

:root {
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sidebar-w: 260px;
  --content-w: 768px;

  --bg: #ffffff;
  --bg-sidebar: #f7f7f8;
  --bg-elevated: #ffffff;
  --bg-hover: #ececf1;
  --bg-active: #e1e1e8;
  --bg-input: #ffffff;
  --bg-user: #f0f0f4;
  --bg-code: #f4f4f6;
  --text: #1f1f24;
  --text-muted: #6e6e80;
  --border: #e3e3e8;
  --accent: #3b5bdb;
  --accent-hover: #2f4bc0;
  --on-accent: #ffffff;
  --danger: #c92a2a;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.16);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #212121;
  --bg-sidebar: #171717;
  --bg-elevated: #2b2b2b;
  --bg-hover: #2c2c2c;
  --bg-active: #383838;
  --bg-input: #2f2f2f;
  --bg-user: #2f2f2f;
  --bg-code: #161616;
  --text: #ececec;
  --text-muted: #9c9c9c;
  --border: #3a3a3a;
  --accent: #5b7cf6;
  --accent-hover: #7391ff;
  --on-accent: #ffffff;
  --danger: #ff7070;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

/* ---------- Basis ---------- */

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
code { font-family: var(--mono); }

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--text-muted);
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

/* ---------- Layout ---------- */

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 10px 18px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.sidebar-close { display: none; }

.new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 8px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  font-weight: 500;
  text-align: left;
}
.new-chat:hover { background: var(--bg-hover); }

.thread-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.thread {
  display: flex;
  align-items: center;
  border-radius: 8px;
}
.thread:hover { background: var(--bg-hover); }
.thread.active { background: var(--bg-active); }
.thread-open {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  text-align: left;
  font-size: 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.thread-delete { opacity: 0; margin-right: 4px; width: 28px; height: 28px; }
.thread:hover .thread-delete,
.thread.active .thread-delete,
.thread-delete:focus-visible { opacity: 1; }
.thread-delete .icon { width: 16px; height: 16px; }
.thread-empty { color: var(--text-muted); font-size: 13px; text-align: center; padding: 16px 12px; margin: 0; }

.sidebar-footer { padding: 8px 12px 12px; border-top: 1px solid var(--border); }
.settings-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: 10px;
  font-size: 14px;
  text-align: left;
}
.settings-btn:hover { background: var(--bg-hover); }

/* ---------- Chat ---------- */

.chat {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
}
.chat-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.menu-btn { display: none; }

.notice {
  max-width: var(--content-w);
  width: calc(100% - 32px);
  margin: 8px auto 0;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}

.messages { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.message-list {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: 24px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.empty-state {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 24px;
  color: var(--text-muted);
  text-align: center;
}
.empty-state .wordmark { font-size: 30px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }
.empty-state p { margin: 0; }

.msg { display: flex; }
.msg-user { justify-content: flex-end; }
.msg-user .msg-body {
  max-width: 80%;
  padding: 10px 16px;
  border-radius: 18px;
  background: var(--bg-user);
}
.msg-assistant .msg-body { width: 100%; min-width: 0; }
.msg-plain { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-label { font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 4px; }
.msg-note { margin-top: 6px; font-size: 13px; font-style: italic; color: var(--text-muted); }
.msg-error {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 14px;
  color: var(--danger);
  border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent);
  background: color-mix(in srgb, var(--danger) 8%, transparent);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* Markdown-Ausgabe */
.msg-markdown { overflow-wrap: anywhere; }
.msg-markdown > :first-child { margin-top: 0; }
.msg-markdown > :last-child { margin-bottom: 0; }
.msg-markdown p { margin: 0 0 12px; }
.msg-markdown h2, .msg-markdown h3, .msg-markdown h4 { margin: 18px 0 8px; line-height: 1.3; }
.msg-markdown h2 { font-size: 1.25em; }
.msg-markdown h3 { font-size: 1.1em; }
.msg-markdown h4 { font-size: 1em; }
.msg-markdown ul, .msg-markdown ol { margin: 0 0 12px; padding-left: 24px; }
.msg-markdown li { margin: 3px 0; }
.msg-markdown blockquote {
  margin: 0 0 12px;
  padding: 4px 14px;
  border-left: 3px solid var(--border);
  color: var(--text-muted);
}
.msg-markdown hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.msg-markdown a { color: var(--accent); }
.msg-markdown code {
  font-size: 0.9em;
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--bg-code);
}
.msg-markdown pre {
  margin: 0 0 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-code);
  overflow-x: auto;
}
.msg-markdown pre code { padding: 0; background: none; font-size: 13px; }

/* Streaming-Cursor */
.streaming > :last-child::after {
  content: "▍";
  margin-left: 2px;
  color: var(--text-muted);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: 0.2s; }
.typing i:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

/* Gedankengang (Qwen3 <think>…</think>) */
.thinking {
  margin: 0 0 12px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--text-muted);
}
.thinking summary { cursor: pointer; font-weight: 500; user-select: none; }
.thinking-body { margin-top: 8px; min-width: 0; }

/* ---------- Eingabe ---------- */

.composer { padding: 8px 16px 12px; }
.composer-inner { max-width: var(--content-w); margin: 0 auto; }
.composer-box {
  padding: 10px 12px 8px 16px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--bg-input);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}
.composer-box:focus-within { border-color: color-mix(in srgb, var(--accent) 55%, var(--border)); }
.composer-box textarea {
  display: block;
  width: 100%;
  max-height: 200px;
  padding: 4px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  line-height: 1.5;
}
.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}
.model-select {
  appearance: none;
  -webkit-appearance: none;
  max-width: 100%;
  padding: 6px 30px 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238a8a99' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>") no-repeat right 10px center;
  font-size: 13px;
  cursor: pointer;
}
.model-select:hover { background-color: var(--bg-hover); }
.composer-actions { display: flex; align-items: center; }
.send-btn, .stop-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
}
.send-btn { background: var(--accent); color: var(--on-accent); }
.send-btn:hover { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.35; cursor: default; }
.send-btn:disabled:hover { background: var(--accent); }
.stop-btn { background: var(--text); color: var(--bg); }
.stop-btn .icon { width: 16px; height: 16px; }
.composer-hint { margin: 8px 0 0; text-align: center; font-size: 12px; color: var(--text-muted); }

/* ---------- Einstellungen (Dialog) ---------- */

.modal {
  width: calc(100% - 32px);
  max-width: 460px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: auto;
  overscroll-behavior: contain;
}
.modal::backdrop { background: rgba(0, 0, 0, 0.45); }
.modal-form { padding: 20px 22px; }
.modal h2 { margin: 0 0 12px; font-size: 18px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
}
.switch { position: relative; width: 42px; height: 24px; flex: 0 0 auto; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--border);
  transition: background 0.15s;
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.field { display: block; margin-bottom: 14px; }
.field-label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 500; }
.field input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-input);
  outline: none;
}
.field input:focus { border-color: var(--accent); }
.field-hint { display: block; margin-top: 5px; font-size: 12px; line-height: 1.45; color: var(--text-muted); }
.field-hint code { font-size: 11px; padding: 1px 4px; border-radius: 4px; background: var(--bg-code); }
.field-error { display: block; margin-top: 5px; font-size: 12px; color: var(--danger); }
.field input[aria-invalid="true"] { border-color: var(--danger); }

.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.btn {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elevated);
  font-weight: 500;
}
.btn:hover { background: var(--bg-hover); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* ---------- Mobil ---------- */

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.4);
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .sidebar-close { display: inline-flex; }
  .menu-btn { display: inline-flex; }
  .msg-user .msg-body { max-width: 90%; }
  .composer { padding: 6px 10px 10px; }
}
@media (min-width: 769px) {
  .sidebar-backdrop { display: none !important; }
}
@media (hover: none) and (pointer: coarse) {
  .composer-hint { display: none; }
}
