:root {
  --bg-primary: #faf9f7;
  --bg-secondary: #f5f0eb;
  --bg-elevated: #ffffff;
  --text-primary: #1a1a1a;
  --text-secondary: #6b6762;
  --text-tertiary: #948e87;
  --accent: #c96442;
  --accent-hover: #ac5032;
  --sage: #718064;
  --border-light: #e8e4df;
  --border-medium: #d5d0ca;
  --shadow: 0 8px 32px rgba(56, 43, 34, 0.07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text-primary);
  background: var(--bg-primary);
  font-family: Charter, Georgia, "Noto Serif SC", serif;
}

button, select, textarea { font: inherit; }

.shell {
  width: min(1180px, calc(100% - 48px));
  height: 100dvh;
  margin: 0 auto;
  padding: 48px 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.masthead {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 32px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font: 600 0.75rem/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.14em;
}

h1 {
  margin: 0;
  font-size: clamp(2.25rem, 6vw, 4rem);
  line-height: 1;
  letter-spacing: -0.035em;
}

h2 { margin: 0; font-size: 1.75rem; line-height: 1.2; letter-spacing: -0.02em; }

.lede {
  max-width: 650px;
  margin: 16px 0 0;
  color: var(--text-secondary);
  font-size: 1.05rem;
  line-height: 1.65;
}

.status {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  padding-bottom: 8px;
  color: var(--text-secondary);
  font: 500 0.875rem/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--text-tertiary);
}

.status[data-state="ready"] .status-dot { background: var(--sage); }
.status[data-state="busy"] .status-dot { background: var(--accent); }
.status[data-state="error"] .status-dot { background: #a33b2c; }

.workspace {
  display: grid;
  grid-template-columns: minmax(220px, 0.7fr) minmax(0, 2fr);
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.main-area {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) minmax(140px, 0.28fr);
}

.login-panel {
  min-height: 250px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 48px;
  padding: clamp(32px, 7vw, 72px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-light);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.login-panel[hidden], .workspace[hidden] { display: none; }
.login-panel p:not(.eyebrow) { max-width: 600px; margin: 14px 0 0; color: var(--text-secondary); font-size: 1.05rem; line-height: 1.65; }
.login-button { flex: 0 0 auto; padding: 13px 22px; color: var(--bg-primary); background: var(--accent); border: 0; border-radius: 8px; text-decoration: none; font: 600 0.95rem/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.login-button:hover { background: var(--accent-hover); }

.settings {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-light);
  min-height: 0;
  overflow-y: auto;
}

.setting-group { display: grid; gap: 9px; }

label {
  color: var(--text-secondary);
  font: 600 0.78rem/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

select, textarea {
  width: 100%;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid var(--border-medium);
  border-radius: 9px;
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

select { padding: 11px 12px; }
textarea { padding: 12px 14px; line-height: 1.55; resize: vertical; }

select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(201, 100, 66, 0.1);
}

button {
  border-radius: 8px;
  padding: 10px 17px;
  border: 1px solid transparent;
  cursor: pointer;
  font: 600 0.9rem/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  transition: background 180ms ease, border-color 180ms ease, color 180ms ease;
}

button:disabled { cursor: not-allowed; opacity: 0.5; }
.primary { color: var(--bg-primary); background: var(--accent); }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.secondary { color: var(--accent); background: transparent; border-color: var(--accent); }
.secondary:hover:not(:disabled) { background: rgba(201, 100, 66, 0.07); }
.quiet { padding: 5px 0; color: var(--text-tertiary); background: transparent; border: 0; text-align: left; font-size: 0.78rem; }
.quiet:hover { color: var(--text-primary); }

.note {
  display: grid;
  gap: 6px;
  margin-top: auto;
  color: var(--text-tertiary);
  font: 0.76rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.note strong { color: var(--text-secondary); font-weight: 500; }

.conversation {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr auto;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-light);
}

.messages {
  min-height: 0;
  overflow-y: auto;
  padding: 32px clamp(24px, 6vw, 72px);
  scroll-behavior: smooth;
}

.message {
  max-width: 760px;
  margin: 0 0 32px;
  animation: reveal 280ms cubic-bezier(0.25, 0.1, 0.25, 1) both;
}

.message.user { margin-left: auto; max-width: 650px; }

.message-role {
  margin-bottom: 8px;
  color: var(--text-tertiary);
  font: 600 0.72rem/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.message.user .message-role { color: var(--accent); }

.message-content {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 1.08rem;
  line-height: 1.75;
}

.message.user .message-content {
  padding: 14px 17px;
  background: var(--bg-secondary);
  border-radius: 12px;
}

.message.error .message-content { color: #8b2f24; }
.tool-verification { max-width: 820px; }
.tool-trace { display: grid; gap: 12px; }
.tool-step {
  padding: 13px 15px;
  background: var(--bg-primary);
  border: 1px solid var(--border-light);
  border-left: 3px solid var(--text-tertiary);
  border-radius: 8px;
}
.tool-step strong {
  display: block;
  margin-bottom: 7px;
  color: var(--text-secondary);
  font: 600 0.78rem/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.tool-step pre {
  margin: 0;
  overflow-x: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-primary);
  font: 0.78rem/1.55 "Cascadia Code", Consolas, monospace;
}
.tool-step-call { border-left-color: var(--accent); }
.tool-step-result, .tool-step-success { border-left-color: var(--sage); }
.tool-step-return { border-left-color: #6f9bb3; }
.tool-step-error { border-left-color: #a33b2c; background: #fff8f6; }
.thinking-panel {
  margin: 0 0 18px;
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-light);
}
.thinking-panel summary {
  width: fit-content;
  padding: 2px 0 12px;
  cursor: pointer;
  list-style: none;
  font: 500 0.88rem/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.thinking-panel summary::-webkit-details-marker { display: none; }
.thinking-panel summary::after { content: "›"; display: inline-block; margin-left: 9px; transform: rotate(90deg); transition: transform 180ms ease; }
.thinking-panel:not([open]) summary::after { transform: rotate(0deg); }
.thinking-content {
  max-height: 180px;
  margin: 0 0 14px;
  overflow-y: auto;
  white-space: pre-wrap;
  font-size: 0.92rem;
  line-height: 1.65;
}
.cursor::after { content: "▍"; color: var(--accent); animation: blink 850ms steps(1) infinite; }

.log-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  background: #211d1a;
  color: #cfc9c2;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  border-bottom: 1px solid #37312c;
}

.log-title {
  color: #9a938b;
  font: 600 0.72rem/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.log-actions { display: flex; align-items: center; gap: 16px; }
.log-filter { display: flex; align-items: center; gap: 6px; color: #8b847c; font: 0.76rem/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.log-filter input { accent-color: var(--accent); }
.log-clear { padding: 2px 8px; color: #8b847c; background: transparent; border: 0; font-size: 0.76rem; }
.log-clear:hover { color: #e8e2da; }

.log-body {
  min-height: 0;
  margin: 0;
  padding: 14px 20px 18px;
  overflow-y: auto;
  font: 0.76rem/1.55 "Cascadia Code", Consolas, "JetBrains Mono", monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.log-line { display: block; }
.log-req { color: #d97757; font-weight: 600; }
.log-req-body, .log-res-body, .log-sse-body { color: #8f877e; }
.log-sse { color: #7a9e7e; }
.log-res { color: #6f9bb3; font-weight: 600; }
.log-info { color: #a89f95; }
.log-err { color: #e0705f; font-weight: 600; }

.composer {
  padding: 24px clamp(24px, 6vw, 72px) 30px;
  border-top: 1px solid var(--border-light);
}

.composer textarea { min-height: 88px; background: var(--bg-primary); }
.composer-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 12px; }
.actions { display: flex; gap: 9px; }
.hint { color: var(--text-tertiary); font: 0.78rem/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@keyframes reveal { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes blink { 50% { opacity: 0; } }

@media (max-width: 780px) {
  .shell { width: min(100% - 24px, 680px); height: auto; min-height: 100dvh; padding: 24px 0; display: block; }
  .masthead { display: grid; gap: 16px; }
  .workspace { grid-template-columns: 1fr; height: auto; min-height: 720px; }
  .main-area { grid-template-rows: minmax(0, 1fr) minmax(160px, 0.5fr); }
  .login-panel { display: grid; gap: 28px; }
  .login-button { text-align: center; }
  .settings { border-right: 0; border-bottom: 1px solid var(--border-light); }
  .note { display: none; }
  .messages { height: 300px; padding: 24px 20px; }
  .composer { padding: 18px 20px 22px; }
  .hint { display: none; }
  .composer-footer { justify-content: flex-end; }
}

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