:root {
  --bg: #101113;
  --surface: #17191d;
  --surface-2: #202227;
  --surface-3: #27262b;
  --ink: #f2eee6;
  --text: #d7d1c8;
  --muted: #9e9b94;
  --muted-2: #777973;
  --line: #34363b;
  --line-strong: #5a5d63;
  --brass: #b18a4a;
  --brass-dark: #8b6a35;
  --aubergine: #51405a;
  --danger: #c56a62;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  min-height: 100vh;
}

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

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.auth-screen {
  align-items: center;
  background:
    linear-gradient(180deg, rgba(16, 17, 19, 0.9), rgba(16, 17, 19, 0.98)),
    var(--bg);
  display: flex;
  min-height: 100vh;
  padding: 24px;
}

.auth-panel {
  border-left: 3px solid var(--brass);
  margin: 0 auto;
  max-width: 440px;
  padding: 8px 0 8px 24px;
  width: 100%;
}

.mark,
.brand {
  color: var(--ink);
  font-size: 22px;
  font-weight: 760;
  line-height: 1.1;
}

.auth-panel h1,
.chat-topbar h1 {
  color: var(--ink);
  font-size: 20px;
  line-height: 1.25;
  margin: 10px 0 18px;
}

.auth-panel form {
  display: grid;
  gap: 10px;
}

.auth-actions,
.auth-links {
  display: flex;
  gap: 8px;
}

.auth-actions {
  margin-top: 4px;
}

.auth-actions button {
  flex: 1;
}

.auth-links {
  align-items: center;
  flex-wrap: wrap;
  margin-top: 2px;
}

label {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
}

input,
select,
textarea {
  background: #0f1012;
  border: 1px solid var(--line);
  color: var(--text);
  outline: none;
}

input,
select {
  border-radius: 4px;
  height: 38px;
  padding: 0 10px;
  width: 100%;
}

textarea {
  border-radius: 6px;
  line-height: 1.45;
  max-height: 180px;
  min-height: 44px;
  padding: 11px 12px;
  resize: none;
  width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brass);
  box-shadow: 0 0 0 3px rgba(177, 138, 74, 0.16);
}

button {
  background: var(--brass);
  border: 1px solid var(--brass);
  border-radius: 5px;
  color: #101113;
  font-weight: 760;
  height: 40px;
  padding: 0 14px;
}

button:disabled {
  cursor: wait;
  opacity: 0.58;
}

.text-button {
  background: transparent;
  border: 0;
  color: var(--brass);
  font-size: 13px;
  height: auto;
  padding: 4px 0;
}

.text-button:hover {
  color: var(--ink);
}

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

.auth-error.notice {
  color: var(--muted);
}

.app-shell {
  display: grid;
  grid-template-columns: 284px minmax(0, 1fr) 360px;
  height: 100vh;
  overflow: hidden;
}

.drawer,
.trace-pane {
  background: var(--surface);
  border-color: var(--line);
  border-style: solid;
  min-height: 0;
}

.drawer {
  border-width: 0 1px 0 0;
  display: flex;
  flex-direction: column;
}

.drawer-head,
.chat-topbar,
.trace-head {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 12px;
  min-height: 68px;
  padding: 14px 16px;
}

.drawer-head {
  justify-content: space-between;
}

.subtitle,
.run-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  margin-top: 4px;
}

.new-chat {
  margin: 14px 14px 10px;
  width: calc(100% - 28px);
}

.conversation-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  min-height: 0;
  overflow: auto;
  padding: 0 8px 12px;
}

.conversation-item {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--text);
  height: auto;
  min-height: 44px;
  overflow: hidden;
  padding: 8px 10px;
  text-align: left;
}

.conversation-item:hover,
.conversation-item.active {
  background: var(--surface-2);
  border-color: var(--line);
}

.conversation-title {
  color: var(--ink);
  display: block;
  font-size: 13px;
  font-weight: 720;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-date {
  color: var(--muted-2);
  display: block;
  font-size: 11px;
  margin-top: 3px;
}

.drawer-foot {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding: 14px;
}

.ghost,
.icon-button,
.trace-toggle {
  background: transparent;
  border-color: var(--line);
  color: var(--text);
}

.icon-button {
  align-items: center;
  display: inline-flex;
  font-size: 20px;
  height: 36px;
  justify-content: center;
  padding: 0;
  width: 36px;
}

.chat-pane {
  background: #101113;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
}

.chat-topbar {
  background: rgba(16, 17, 19, 0.96);
  justify-content: space-between;
}

.chat-topbar h1 {
  font-size: 17px;
  margin: 0;
}

.trace-toggle {
  min-width: 72px;
}

.trace-toggle.active {
  background: var(--surface-2);
  border-color: var(--brass);
  color: var(--ink);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  overflow: auto;
  padding: 24px clamp(16px, 5vw, 72px);
}

.empty-state {
  border-left: 3px solid var(--brass);
  margin: auto;
  max-width: 680px;
  padding: 2px 0 2px 22px;
  width: 100%;
}

.empty-state h2 {
  color: var(--ink);
  font-size: 22px;
  margin: 0 0 8px;
}

.empty-state p {
  color: var(--muted);
  line-height: 1.5;
  margin: 0;
}

.message {
  display: grid;
  gap: 7px;
  max-width: 820px;
  width: 100%;
}

.message.user {
  align-self: flex-end;
  max-width: 700px;
}

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

.message-meta {
  color: var(--muted-2);
  font-size: 12px;
}

.bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.58;
  padding: 13px 15px;
  white-space: pre-wrap;
}

.message.user .bubble {
  background: var(--surface-2);
  color: var(--ink);
}

.message.assistant .bubble {
  background: var(--surface);
}

.citation-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.citation,
.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 720;
  padding: 4px 7px;
}

.composer {
  align-items: end;
  background: rgba(16, 17, 19, 0.98);
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 14px clamp(16px, 5vw, 72px) 18px;
}

.composer button {
  min-width: 96px;
}

.trace-pane {
  border-width: 0 0 0 1px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto minmax(0, 1fr);
  overflow: hidden;
}

.trace-head {
  justify-content: space-between;
}

.trace-head h2,
.evidence-head {
  color: var(--ink);
  font-size: 14px;
  margin: 0;
}

.evidence-head {
  border-bottom: 1px solid var(--line);
  border-top: 1px solid var(--line);
  padding: 12px 14px;
}

.trace-list,
.evidence-list {
  min-height: 0;
  overflow: auto;
  padding: 10px 14px;
}

.trace-card,
.evidence-card {
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.trace-card:last-child,
.evidence-card:last-child {
  border-bottom: 0;
}

.trace-card p,
.evidence-card p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
  margin: 6px 0 0;
}

.trace-card strong,
.evidence-card h3 {
  color: var(--ink);
}

.evidence-card h3 {
  font-size: 13px;
  margin: 0 0 8px;
}

.trace-card code {
  background: #0f1012;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: #c8c1b6;
  display: block;
  font-size: 11px;
  line-height: 1.4;
  margin-top: 8px;
  max-height: 140px;
  overflow: auto;
  padding: 8px;
  white-space: pre-wrap;
}

.mobile-only {
  display: none;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: 284px minmax(0, 1fr);
  }

  .trace-pane {
    box-shadow: var(--shadow);
    max-width: 380px;
    position: fixed;
    right: 0;
    top: 0;
    transform: translateX(100%);
    transition: transform 160ms ease;
    width: 88vw;
    z-index: 10;
  }

  .trace-pane.open {
    transform: translateX(0);
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .drawer {
    box-shadow: var(--shadow);
    height: 100vh;
    left: 0;
    position: fixed;
    top: 0;
    transform: translateX(-100%);
    transition: transform 160ms ease;
    width: min(86vw, 308px);
    z-index: 11;
  }

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

  .mobile-only {
    display: inline-flex;
  }

  .messages {
    padding: 18px 14px;
  }

  .composer {
    grid-template-columns: minmax(0, 1fr);
    padding: 12px 14px 14px;
  }

  .composer button {
    width: 100%;
  }
}
