:root {
  color-scheme: dark;
  --bg: oklch(0.09 0 0);
  --surface: oklch(0.145 0.018 260);
  --surface-2: oklch(0.19 0.021 260);
  --ink: oklch(0.94 0.008 260);
  --muted: oklch(0.70 0.018 260);
  --faint: oklch(0.52 0.018 260);
  --line: oklch(0.28 0.025 260);
  --primary: oklch(0.56 0.161 260);
  --primary-strong: oklch(0.64 0.17 260);
  --accent: oklch(0.70 0.135 185);
  --danger: oklch(0.64 0.18 28);
  --radius-lg: 24px;
  --radius-sm: 10px;
  --shadow: 0 24px 80px oklch(0 0 0 / 0.38);
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background: radial-gradient(circle at top left, oklch(0.24 0.05 260 / 0.55), transparent 36rem), var(--bg);
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
}

button, input, textarea { font: inherit; }
button, textarea, input { border-radius: var(--radius-sm); }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid oklch(0.72 0.14 185 / 0.85); outline-offset: 3px; }

.login-page { display: grid; place-items: center; padding: 24px; }
.login-shell { width: min(100%, 420px); }
.login-panel { padding: 32px; background: linear-gradient(180deg, var(--surface), oklch(0.12 0.012 260)); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.login-kicker, .topbar-label { margin: 0 0 6px; color: var(--muted); font-size: 0.875rem; }
.login-panel h1, .topbar h1 { margin: 0; font-size: 1.45rem; letter-spacing: -0.01em; }
.login-form { display: grid; gap: 12px; margin-top: 28px; }
.login-form label, .composer label { color: var(--muted); font-size: 0.9rem; }
.login-form input, .composer textarea { width: 100%; color: var(--ink); background: oklch(0.10 0.012 260); border: 1px solid var(--line); }
.login-form input { min-height: 46px; padding: 0 14px; }
.login-form button, .composer button, .secondary-button, .ghost-button { min-height: 42px; padding: 0 16px; border: 1px solid transparent; cursor: pointer; transition: border-color 180ms ease, background-color 180ms ease, transform 180ms ease; }
.login-form button, .composer button { color: oklch(0.98 0 0); background: var(--primary); }
.login-form button:hover, .composer button:hover:not(:disabled) { background: var(--primary-strong); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { cursor: wait; opacity: 0.66; }
.form-error { margin: 0 0 8px; padding: 10px 12px; color: oklch(0.98 0.015 28); background: oklch(0.22 0.08 28); border: 1px solid oklch(0.42 0.12 28); border-radius: var(--radius-sm); }

.app-shell { display: grid; grid-template-rows: auto 1fr; min-height: 100vh; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 18px clamp(16px, 4vw, 40px); background: oklch(0.11 0.014 260 / 0.92); border-bottom: 1px solid var(--line); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.secondary-button, .ghost-button { color: var(--ink); background: var(--surface-2); border-color: var(--line); }
.ghost-button { background: transparent; }
.secondary-button:hover, .ghost-button:hover { border-color: var(--accent); }
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; width: min(1440px, 100%); min-height: 0; margin: 0 auto; padding: 18px clamp(12px, 3vw, 32px) 24px; }
.conversation-panel, .usage-panel { background: oklch(0.12 0.014 260 / 0.88); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: 0 12px 38px oklch(0 0 0 / 0.18); }
.conversation-panel { display: grid; grid-template-rows: minmax(260px, 1fr) auto; min-height: calc(100vh - 126px); overflow: hidden; }
.messages { display: flex; flex-direction: column; gap: 16px; overflow-y: auto; padding: clamp(16px, 3vw, 28px); }
.empty-state { display: grid; place-items: start; align-content: center; min-height: 100%; color: var(--muted); }
.empty-state span { width: 42px; height: 3px; margin-bottom: 18px; background: var(--accent); border-radius: 999px; }
.empty-state h2 { margin: 0 0 6px; color: var(--ink); font-size: 1.25rem; }
.empty-state p { margin: 0; }
.message { width: min(82ch, 100%); }
.message.user { align-self: flex-end; }
.message.system { align-self: center; }
.message-role { margin-bottom: 6px; color: var(--muted); font-size: 0.82rem; }
.message-content { padding: 14px 16px; color: var(--ink); background: var(--surface-2); border: 1px solid var(--line); border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; }
.message.user .message-content { background: oklch(0.28 0.08 260); border-color: oklch(0.42 0.10 260); }
.message.system .message-content { color: oklch(0.98 0.015 28); background: oklch(0.20 0.07 28); border-color: oklch(0.42 0.12 28); }
.message-content code, .message-content pre { font-family: var(--mono); overflow-x: auto; }
.message-usage { margin-top: 6px; color: var(--faint); font-size: 0.8rem; }
.composer { display: grid; gap: 10px; padding: 16px; background: oklch(0.10 0.012 260); border-top: 1px solid var(--line); }
.composer textarea { min-height: 86px; max-height: 260px; resize: vertical; padding: 12px 14px; }
.composer-actions { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.status-text { min-height: 1.3em; margin: 0; color: var(--muted); font-size: 0.9rem; }
.usage-panel { align-self: start; padding: 20px; position: sticky; top: 18px; }
.usage-panel h2, .usage-block h3 { margin: 0; }
.usage-panel h2 { font-size: 1.05rem; }
.usage-block { margin-top: 20px; }
.usage-block h3 { color: var(--muted); font-size: 0.88rem; font-weight: 600; }
dl { display: grid; gap: 10px; margin: 12px 0 0; }
dl div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid oklch(0.24 0.018 260); }
dt { color: var(--muted); }
dd { margin: 0; font-family: var(--mono); }

@media (max-width: 920px) {
  .workspace { grid-template-columns: 1fr; }
  .usage-panel { order: -1; position: static; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .usage-panel h2 { grid-column: 1 / -1; }
}

@media (max-width: 620px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions, .topbar-actions form, .topbar-actions button, .composer button { width: 100%; }
  .usage-panel { grid-template-columns: 1fr; }
  .conversation-panel { min-height: 68vh; }
  .composer-actions { align-items: stretch; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 1ms !important; }
}
