@font-face {
  font-family: "DM Sans";
  src: url("fonts/DMSans-Variable.woff2") format("woff2-variations"),
       url("fonts/DMSans-Variable.woff2") format("woff2");
  font-weight: 100 1000;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "DM Sans";
  src: url("fonts/DMSans-Italic-Variable.woff2") format("woff2-variations"),
       url("fonts/DMSans-Italic-Variable.woff2") format("woff2");
  font-weight: 100 1000;
  font-style: italic;
  font-display: swap;
}

:root {
  --bg: #0f1613;
  --panel: #17201c;
  --panel-raised: #1c2620;
  --line: #263029;
  --ink: #edf1ed;
  --muted: #8fa095;

  --tanne: #00593b;
  --tanne-hover: #006e49;
  --klee: #00b24a;
  --grashalm: #8abd24;
  --user-bubble: #163524;

  --danger: #f0838a;
  --danger-bg: #2c1518;

  --badge-antrag-bg: #3a3317;
  --badge-antrag-fg: #f1d97a;
  --badge-opus-bg: #2e2445;
  --badge-opus-fg: #cdb8f5;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --font: "DM Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
}

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

button { font: inherit; cursor: pointer; }

.small { font-size: 0.85rem; }
.muted { color: var(--muted); }

.primary, .secondary {
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.9rem;
  border: 1px solid var(--tanne);
  font-weight: 500;
}
.primary { background: var(--tanne); color: #fff; }
.primary:hover { background: var(--tanne-hover); }
.primary:disabled { opacity: 0.55; cursor: not-allowed; }
.secondary { background: transparent; color: var(--grashalm); border-color: #3a4a33; }
.secondary:hover { border-color: var(--grashalm); }

.link-button {
  background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline;
}

.icon-button {
  background: none; border: 0; font-size: 1.3rem; padding: 0.25rem 0.5rem; color: inherit;
}

/* --- Login --- */
.login-page { display: grid; place-items: center; background: var(--bg); padding: 1rem; }
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  padding: 2rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.login-card form { display: grid; gap: 0.9rem; margin: 1.25rem 0; }
.login-card label { display: grid; gap: 0.3rem; font-weight: 500; font-size: 0.9rem; }
.login-card input {
  font: inherit; padding: 0.6rem 0.7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}
.login-card input:focus { outline: 2px solid var(--grashalm); outline-offset: -1px; }
.alert {
  background: var(--danger-bg); color: var(--danger); padding: 0.6rem 0.8rem; border-radius: var(--radius-sm);
}

/* --- Layout --- */
.layout { display: grid; grid-template-columns: 290px 1fr; height: 100vh; height: 100dvh; }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  min-height: 0;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 1rem; }
.brand { font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.new-chat { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; padding: 0 1rem 0.75rem; }
.new-chat button { white-space: nowrap; padding-left: 0.4rem; padding-right: 0.4rem; font-size: 0.92rem; }

#conversation-list { flex: 1; overflow-y: auto; padding: 0 0.5rem; }
.conv {
  display: flex; align-items: center; gap: 0.35rem;
  border-radius: var(--radius-sm); padding: 0.15rem 0.25rem 0.15rem 0.6rem;
}
.conv:hover, .conv.active { background: var(--user-bubble); }
.conv a {
  flex: 1; min-width: 0; color: inherit; text-decoration: none; padding: 0.4rem 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv .kind { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.conv .delete { visibility: hidden; background: none; border: 0; color: var(--muted); }
.conv:hover .delete, .conv.active .delete { visibility: visible; }
.list-empty { padding: 0.5rem 0.75rem; color: var(--muted); font-size: 0.9rem; }

.account { border-top: 1px solid var(--line); padding: 0.9rem 1rem; display: grid; gap: 0.2rem; }
.account-name { font-weight: 500; }
.budget-warn { color: var(--danger); }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-header {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.8rem 1.25rem; border-bottom: 1px solid var(--line);
}
.chat-header h1 {
  font-size: 1.05rem; margin: 0; flex: 1; min-width: 0; font-weight: 700; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge {
  font-size: 0.75rem; font-weight: 500; padding: 0.15rem 0.55rem; border-radius: var(--radius-pill);
  background: var(--user-bubble); color: var(--klee);
}
.badge.antrag { background: var(--badge-antrag-bg); color: var(--badge-antrag-fg); }
.badge.model { background: var(--panel-raised); color: var(--muted); border: 1px solid var(--line); }
.badge.model.opus { background: var(--badge-opus-bg); color: var(--badge-opus-fg); border-color: transparent; }
#model-picker, #effort-picker {
  font: inherit; font-size: 0.85rem; padding: 0.25rem 0.4rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--panel-raised); color: var(--ink); max-width: 45vw;
}
.conv .model-mark {
  font-size: 0.65rem; font-weight: 500; color: var(--badge-opus-fg); background: var(--badge-opus-bg);
  border-radius: var(--radius-pill); padding: 0 0.4rem;
}

#messages { flex: 1; overflow-y: auto; padding: 1.25rem; display: flex; flex-direction: column; gap: 1rem; }
#messages:empty { display: none; }

.msg { max-width: 820px; width: 100%; margin: 0 auto; }
.msg.user .bubble {
  background: var(--user-bubble); border-radius: var(--radius); padding: 0.7rem 0.95rem;
  white-space: pre-wrap; margin-left: auto; width: fit-content; max-width: 90%;
}
.msg.assistant .bubble { padding: 0.2rem 0.1rem; overflow-wrap: anywhere; }
.msg.assistant .bubble.streaming { white-space: pre-wrap; color: var(--muted); }
.bubble p:first-child { margin-top: 0; }
.bubble h2 { font-size: 1.15rem; }
.bubble h3 { font-size: 1.05rem; }
.bubble table { border-collapse: collapse; margin: 0.5rem 0; display: block; overflow-x: auto; }
.bubble th, .bubble td { border: 1px solid var(--line); padding: 0.3rem 0.5rem; text-align: left; }
.bubble a[href] { text-decoration: none; }
.bubble a[href]:hover { text-decoration: underline; }
.bubble pre { background: var(--panel); padding: 0.75rem; border-radius: var(--radius-sm); overflow-x: auto; }

.status {
  font-size: 0.85rem; color: var(--muted); display: flex; align-items: center; gap: 0.45rem;
  margin-bottom: 0.3rem;
}
.status::before {
  content: ""; width: 0.7rem; height: 0.7rem; border-radius: 50%;
  border: 2px solid var(--grashalm); border-right-color: transparent;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error { color: var(--danger); }

.sources { margin-top: 0.6rem; border-top: 1px solid var(--line); padding-top: 0.5rem; font-size: 0.9rem; }
.sources summary { cursor: pointer; color: var(--muted); font-weight: 500; }
.sources ol { padding-left: 1.4rem; margin: 0.4rem 0; }
.sources li { margin: 0.35rem 0; }
.sources blockquote {
  margin: 0.2rem 0 0; padding-left: 0.6rem; border-left: 3px solid var(--line);
  color: var(--muted); font-size: 0.85rem; white-space: pre-wrap;
}

.msg-actions { margin-top: 0.4rem; display: flex; gap: 0.5rem; }
.msg-actions button {
  font-size: 0.8rem; background: none; border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0.2rem 0.55rem; color: var(--muted);
}

.empty-state { flex: 1; overflow-y: auto; padding: 2rem 1.25rem; }
.empty-state > div { max-width: 640px; margin: 8vh auto 0; }
.empty-state h2 { margin-top: 0; font-weight: 700; letter-spacing: -0.01em; }

.composer {
  display: flex; gap: 0.6rem; padding: 0.75rem 1.25rem 0.25rem;
  max-width: 870px; width: 100%; margin: 0 auto;
}
.composer textarea {
  flex: 1; font: inherit; resize: none; padding: 0.65rem 0.8rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink); max-height: 40vh;
}
.composer textarea:focus { outline: 2px solid var(--grashalm); outline-offset: -1px; }
.disclaimer { text-align: center; margin: 0.2rem 1rem 0.6rem; }

.only-mobile { display: none; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 25% 0 0; min-width: 260px; z-index: 10;
    transform: translateX(-105%); transition: transform 0.2s ease;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.5);
  }
  .sidebar.open { transform: none; }
  .only-mobile { display: inline-block; }
  #model-picker, #effort-picker { max-width: 32vw; }
  .chat-header { gap: 0.5rem; }
  .chat-header h1 { min-width: 5.5rem; }
  #messages, .chat-header { padding-left: 1rem; padding-right: 1rem; }
  .composer { padding: 0.6rem 1rem 0.2rem; }
}
