:root {
  color-scheme: light;
  --bg: #f7f7f8;
  --surface: #ffffff;
  --surface-muted: #f3f4f6;
  --surface-subtle: #ececf1;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --muted-strong: #4b5563;
  --accent: #10a37f;
  --accent-strong: #0b8b6c;
  --danger: #dc2626;
  --danger-bg: #fff1f2;
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family:
    ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

[hidden] {
  display: none !important;
}

button,
textarea,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.auth-gate {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at top left, rgba(16, 163, 127, 0.14), transparent 32%),
    radial-gradient(circle at bottom right, rgba(15, 118, 110, 0.12), transparent 28%),
    var(--bg);
}

.auth-card {
  width: min(420px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.auth-kicker {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.auth-card h1 {
  margin: 0;
  font-size: 28px;
}

.auth-copy {
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.7;
}

.auth-form {
  display: grid;
  gap: 12px;
  margin-top: 24px;
}

.auth-label {
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 600;
}

.auth-form input {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
}

.auth-form input:focus {
  border-color: var(--accent);
  outline: 2px solid rgba(16, 163, 127, 0.14);
  outline-offset: 0;
}

.auth-message {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.auth-submit {
  width: 100%;
  justify-content: center;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(247, 247, 248, 0.88);
  backdrop-filter: blur(14px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  color: white;
  font-weight: 700;
  background: linear-gradient(135deg, #10a37f, #0f766e);
}

.brand-kicker {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-badge,
.request-meta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted-strong);
  background: var(--surface);
  font-size: 13px;
}

.status-badge.warning {
  color: #92400e;
  background: #fffbeb;
  border-color: #fcd34d;
}

.icon-button,
.text-button {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: var(--surface);
}

.icon-button:hover,
.text-button:hover {
  background: var(--surface-muted);
}

.workspace {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 69px);
}

.chat-stage {
  width: min(1120px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0 220px;
}

.welcome-panel {
  padding: 36px 28px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, #ffffff 0%, #fafafa 100%);
  box-shadow: var(--shadow);
}

.welcome-panel[hidden] {
  display: none;
}

.welcome-label {
  margin: 0 0 12px;
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.welcome-panel h2 {
  margin: 0;
  font-size: clamp(30px, 5vw, 46px);
  line-height: 1.05;
  letter-spacing: -0.04em;
}

.welcome-copy {
  max-width: 720px;
  margin: 18px 0 0;
  color: var(--muted-strong);
  font-size: 17px;
  line-height: 1.7;
}

.conversation {
  display: grid;
  gap: 20px;
  margin-top: 24px;
}

.turn {
  width: 100%;
}

.turn-shell {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 700;
}

.avatar-user {
  color: white;
  background: #111827;
}

.avatar-assistant {
  color: white;
  background: linear-gradient(135deg, #10a37f, #14b8a6);
}

.message-bubble,
.assistant-block {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.message-bubble {
  padding: 18px 20px;
}

.turn-title {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
}

.turn-content {
  color: var(--text);
  line-height: 1.7;
  white-space: pre-wrap;
}

.assistant-block {
  padding: 22px;
}

.assistant-head {
  margin-bottom: 14px;
}

.assistant-subtitle {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.result-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.result-tab {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted-strong);
  background: var(--surface-muted);
  font-size: 14px;
  font-weight: 600;
}

.result-tab:hover {
  background: var(--surface);
}

.result-tab.active {
  border-color: #b9e7db;
  color: var(--accent-strong);
  background: #eefbf7;
}

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

.result-tab.streaming {
  color: var(--accent-strong);
}

.result-tab.error {
  color: var(--danger);
  background: #fff7f7;
  border-color: #fecdd3;
}

.result-tab-meta {
  font-size: 12px;
  font-weight: 500;
  opacity: 0.85;
}

.result-panel {
  display: block;
}

.result-card {
  min-height: auto;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: #fcfcfd;
}

.result-card.loading {
  background: linear-gradient(180deg, #fcfcfd 0%, #f9fafb 100%);
}

.result-card.error {
  border-color: #fecdd3;
  background: var(--danger-bg);
}

.result-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.result-provider {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}

.result-model {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.result-latency {
  flex-shrink: 0;
  padding: 6px 11px;
  border-radius: 999px;
  color: var(--muted-strong);
  background: var(--surface-subtle);
  font-size: 12px;
}

.result-note {
  margin: 0 0 16px;
  padding: 12px 14px;
  border: 1px solid #fde68a;
  border-radius: 14px;
  color: #92400e;
  background: #fffbeb;
  font-size: 13px;
  line-height: 1.6;
}

.result-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
}

.retry-button {
  height: 36px;
  padding: 0 14px;
  border: 1px solid #fca5a5;
  border-radius: 10px;
  color: #b91c1c;
  background: #fff7f7;
}

.retry-button:hover {
  background: #fee2e2;
}

.retry-button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.composer-shell {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 18;
  display: flex;
  justify-content: center;
  padding: 18px 16px 24px;
  background: linear-gradient(180deg, rgba(247, 247, 248, 0) 0%, rgba(247, 247, 248, 0.92) 34%, #f7f7f8 100%);
}

.composer-card {
  width: min(1120px, calc(100vw - 32px));
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
}

.composer-card textarea,
.settings-drawer textarea,
.settings-drawer input[type="number"] {
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
}

.composer-card textarea {
  resize: none;
  min-height: 28px;
  max-height: 240px;
  padding: 2px 6px 10px;
  line-height: 1.7;
}

.composer-card textarea::placeholder,
.settings-drawer textarea::placeholder {
  color: #9ca3af;
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-top: 1px solid var(--line);
  padding: 12px 4px 0;
}

.composer-meta,
.composer-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.composer-meta {
  color: var(--muted);
  font-size: 13px;
}

.send-button {
  height: 40px;
  padding: 0 16px;
  border-radius: 12px;
  color: white;
  background: var(--accent);
}

.send-button:hover {
  background: var(--accent-strong);
}

.send-button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 29;
  background: rgba(17, 24, 39, 0.36);
}

.settings-drawer {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  display: grid;
  align-content: start;
  gap: 18px;
  width: min(420px, 100vw);
  height: 100vh;
  padding: 24px;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -24px 0 60px rgba(15, 23, 42, 0.12);
  transform: translateX(100%);
  transition: transform 180ms ease;
}

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

.settings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.settings-kicker {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.settings-head h2 {
  margin: 0;
  font-size: 24px;
}

.settings-section {
  display: grid;
  gap: 10px;
}

.section-label,
.input-group span {
  color: var(--muted-strong);
  font-size: 13px;
  font-weight: 600;
}

.provider-stack {
  display: grid;
  gap: 10px;
}

.provider-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fafafa;
}

.provider-row.disabled {
  opacity: 0.56;
}

.provider-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.provider-main input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.provider-name {
  font-size: 14px;
  font-weight: 600;
}

.provider-model {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.provider-state {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
}

.state-online {
  color: var(--accent-strong);
  background: #ecfdf5;
}

.state-offline {
  color: var(--danger);
  background: #fef2f2;
}

.settings-drawer textarea,
.settings-drawer input[type="number"] {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fafafa;
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.input-group {
  display: grid;
  gap: 8px;
}

.loading-lines {
  display: grid;
  gap: 8px;
}

.loading-lines span {
  display: block;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #ececf1 0%, #f7f7f8 50%, #ececf1 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
}

.loading-lines span:nth-child(1) {
  width: 92%;
}

.loading-lines span:nth-child(2) {
  width: 76%;
}

.loading-lines span:nth-child(3) {
  width: 64%;
}

.markdown-body {
  color: var(--text);
  max-width: 88ch;
  font-size: 15px;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.markdown-body > :first-child {
  margin-top: 0;
}

.markdown-body > :last-child {
  margin-bottom: 0;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin: 1.15em 0 0.55em;
  line-height: 1.3;
}

.markdown-body h1 {
  font-size: 1.55rem;
}

.markdown-body h2 {
  font-size: 1.28rem;
}

.markdown-body h3 {
  font-size: 1.08rem;
}

.markdown-body p,
.markdown-body ul,
.markdown-body ol,
.markdown-body blockquote,
.markdown-body pre,
.markdown-body table,
.markdown-body hr {
  margin: 0.9em 0;
}

.markdown-body ul,
.markdown-body ol {
  padding-left: 1.3em;
}

.markdown-body li + li {
  margin-top: 0.3em;
}

.markdown-body code {
  padding: 0.15em 0.4em;
  border-radius: 8px;
  background: #f3f4f6;
  font-family:
    ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.markdown-body pre {
  overflow-x: auto;
  padding: 14px;
  border-radius: 14px;
  background: #111827;
  color: #f9fafb;
}

.markdown-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.markdown-body blockquote {
  padding-left: 1em;
  border-left: 3px solid var(--line-strong);
  color: var(--muted-strong);
}

.markdown-body hr {
  border: 0;
  border-top: 1px solid var(--line);
}

.markdown-body a {
  color: #2563eb;
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  display: block;
  overflow-x: auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.markdown-body th,
.markdown-body td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

.markdown-body th {
  background: #f9fafb;
  font-weight: 600;
}

.markdown-body tr:last-child td {
  border-bottom: 0;
}

.markdown-body th:last-child,
.markdown-body td:last-child {
  border-right: 0;
}

@keyframes shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

@media (max-width: 900px) {
  .topbar {
    padding: 14px 16px;
  }

  .chat-stage,
  .composer-card {
    width: min(100vw - 20px, 980px);
  }

  .composer-footer {
    flex-direction: column;
    align-items: flex-start;
  }

  .composer-actions {
    width: 100%;
    justify-content: space-between;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar-actions .status-badge {
    display: none;
  }

  .chat-stage {
    padding-top: 20px;
    padding-bottom: 210px;
  }

  .welcome-panel {
    padding: 24px 18px;
    border-radius: 20px;
  }

  .turn-shell {
    grid-template-columns: 1fr;
  }

  .avatar {
    width: 36px;
    height: 36px;
    border-radius: 12px;
  }

  .message-bubble,
  .assistant-block,
  .result-card,
  .composer-card {
    border-radius: 18px;
  }

  .results-grid {
    grid-template-columns: 1fr;
  }
}
