:root {
  color-scheme: dark;
  --sidebar: #171717;
  --main: #212121;
  --surface: #2f2f2f;
  --surface-hover: #3a3a3a;
  --border: #424242;
  --text: #ececec;
  --muted: #b4b4b4;
  --user-bg: #303030;
  --assistant-bg: #212121;
  --accent: #10a37f;
  --send-bg: #ececec;
  --send-fg: #212121;
  --send-disabled: #676767;
  --font: Söhne, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  --col: min(48rem, 100%);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--main);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--main);
}

.login-card {
  width: 100%;
  max-width: 22rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1.75rem 1.5rem;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
}

.login-card h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
  text-align: center;
}

.login-sub {
  margin: 0.5rem 0 1.25rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.login-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.login-field input {
  background: var(--main);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  font: inherit;
  padding: 0.55rem 0.65rem;
}

.login-error {
  margin: 0;
  font-size: 0.85rem;
  color: #f87171;
}

.login-submit {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.65rem;
}

.sidebar-link.logout {
  margin-top: 0.35rem;
  color: var(--muted);
}

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

.sidebar {
  width: 260px;
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
}

.sidebar-top {
  flex: 1;
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
}

.new-chat:hover {
  background: var(--surface-hover);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.65rem 0.75rem;
  border: none;
  border-radius: 0.65rem;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  cursor: pointer;
  text-align: left;
}

.sidebar-link:hover {
  background: var(--surface-hover);
}

.sidebar-foot {
  padding: 0.5rem 0.25rem;
}

.model-pill {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  padding: 0.35rem 0.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--main);
}

.topbar {
  height: 3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-bottom: 1px solid transparent;
  position: relative;
}

.topbar-title {
  font-size: 0.95rem;
  font-weight: 500;
}

.icon-btn {
  position: absolute;
  left: 0.75rem;
  border: none;
  background: transparent;
  color: var(--text);
  padding: 0.35rem;
  border-radius: 0.35rem;
  cursor: pointer;
}

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

.mobile-only {
  display: none;
}

.scroll {
  flex: 1;
  overflow-y: auto;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: min(50vh, 24rem);
  padding: 2rem 1rem;
  text-align: center;
}

.empty.hidden {
  display: none;
}

.empty h2 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 500;
}

.empty-hint {
  margin: 0.75rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.log {
  display: flex;
  flex-direction: column;
}

.turn {
  width: 100%;
  border-bottom: 1px solid transparent;
}

.turn.user {
  background: var(--user-bg);
}

.turn.assistant {
  background: var(--assistant-bg);
}

.turn-inner {
  max-width: var(--col);
  margin: 0 auto;
  padding: 1.25rem 1rem;
  display: flex;
  gap: 1rem;
  align-items: flex-start;
}

.avatar {
  width: 28px;
  height: 28px;
  border-radius: 2px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 600;
}

.turn.user .avatar {
  background: #5c5c5c;
  color: #fff;
}

.turn.assistant .avatar {
  background: var(--accent);
  color: #fff;
}

.bubble {
  flex: 1;
  min-width: 0;
  line-height: 1.65;
  font-size: 1rem;
  word-break: break-word;
}

.bubble.pending {
  color: var(--muted);
}

.bubble p {
  margin: 0 0 0.75rem;
}

.bubble p:last-child {
  margin-bottom: 0;
}

.bubble pre {
  margin: 0.5rem 0;
  padding: 0.75rem 1rem;
  background: #1a1a1a;
  border-radius: 0.5rem;
  overflow-x: auto;
  font-size: 0.875rem;
}

.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: #1a1a1a;
  padding: 0.1em 0.35em;
  border-radius: 0.25rem;
}

.bubble pre code {
  background: none;
  padding: 0;
}

.footer {
  padding: 0.75rem 1rem 1rem;
  background: linear-gradient(transparent, var(--main) 20%);
}

.composer-wrap {
  max-width: var(--col);
  margin: 0 auto;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.5rem;
  padding: 0.65rem 0.65rem 0.65rem 1rem;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.05), 0 4px 24px rgba(0, 0, 0, 0.25);
}

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

textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem;
  line-height: 1.5;
  resize: none;
  max-height: 200px;
  padding: 0.35rem 0;
  field-sizing: content;
}

textarea:focus {
  outline: none;
}

.send {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--send-bg);
  color: var(--send-fg);
  flex-shrink: 0;
}

.send:disabled {
  background: transparent;
  color: var(--send-disabled);
  cursor: not-allowed;
}

.disclaimer {
  margin: 0.5rem 0 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }

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

  .mobile-only {
    display: block;
  }

  .shell.sidebar-open::after {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 30;
  }
}

.settings-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--main);
  color: var(--text);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.settings-screen.hidden {
  display: none;
}

.settings-screen-head {
  flex-shrink: 0;
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border);
  max-width: 52rem;
  margin: 0 auto;
  width: 100%;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.25rem 0;
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.back-btn:hover {
  color: var(--text);
}

.settings-screen-head h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 600;
}

.settings-intro {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.5;
}

.settings-screen-body {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  max-width: 52rem;
  margin: 0 auto;
  width: 100%;
  padding: 1rem 1.25rem 2rem;
}

.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.field-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  padding: 1rem 1.1rem;
}

.field-card-wide {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.875rem;
}

.field.row {
  flex-direction: row;
  align-items: flex-start;
  gap: 0.5rem;
}

.field-label {
  display: flex;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.95rem;
  margin-bottom: 0.35rem;
}

.field-label.inline {
  margin-bottom: 0;
  font-weight: 500;
}

.field-desc {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--muted);
}

.field input[type="range"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  background: var(--main);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--text);
  font: inherit;
  padding: 0.45rem 0.55rem;
}

.field textarea {
  resize: vertical;
  min-height: 5rem;
}

.settings-screen-foot {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  position: sticky;
  bottom: 0;
  background: linear-gradient(transparent, var(--main) 24%);
}

.btn-primary,
.btn-secondary {
  border: none;
  border-radius: 0.5rem;
  padding: 0.5rem 0.9rem;
  font: inherit;
  cursor: pointer;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
