:root {
  color-scheme: light;
  --bg: #f6f3ef;
  --surface: #ffffff;
  --surface-muted: #f0f5f4;
  --ink: #19211f;
  --muted: #66716e;
  --line: #d9dfdc;
  --accent: #b21f35;
  --accent-dark: #851629;
  --teal: #0f766e;
  --shadow: 0 20px 60px rgba(23, 31, 29, 0.12);
}

* {
  box-sizing: border-box;
}

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

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

.app-shell {
  height: 100vh;
  padding: 24px;
  overflow: hidden;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1440px;
  height: calc(100vh - 48px);
  min-height: 0;
  margin: 0 auto;
}

@supports (height: 100dvh) {
  body,
  .app-shell {
    height: 100dvh;
  }

  .workspace {
    height: calc(100dvh - 48px);
  }
}

.context-panel,
.chat-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.context-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  border-radius: 8px;
  min-height: 0;
  overflow-y: auto;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-image {
  width: 64px;
  aspect-ratio: 1;
  border-radius: 8px;
  object-fit: cover;
  object-position: center;
  border: 1px solid rgba(178, 31, 53, 0.24);
  background: var(--accent);
  box-shadow: 0 10px 24px rgba(178, 31, 53, 0.18);
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.1;
}

.brand-lockup p,
.eyebrow,
.field-group label,
.context-readout span {
  color: var(--muted);
  font-size: 12px;
}

.field-group {
  display: grid;
  gap: 6px;
}

.field-group label {
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: #fbfcfb;
  color: var(--ink);
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented button.active {
  background: var(--ink);
  color: white;
}

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

.context-readout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: auto;
}

.context-readout div {
  display: grid;
  gap: 4px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-muted);
}

.context-readout strong {
  font-size: 13px;
  overflow-wrap: anywhere;
}

.session-switcher {
  display: grid;
  gap: 8px;
  min-height: 0;
}

.session-list-header {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.session-list {
  display: grid;
  gap: 6px;
  max-height: 220px;
  overflow-y: auto;
}

.session-item {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 48px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfb;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.session-item.active {
  border-color: rgba(178, 31, 53, 0.36);
  background: rgba(178, 31, 53, 0.08);
}

.session-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 800;
}

.session-meta,
.session-empty {
  color: var(--muted);
  font-size: 12px;
}

.session-empty {
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
}

.secondary-action {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  cursor: pointer;
}

.chat-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-radius: 8px;
  overflow: hidden;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.chat-header h2 {
  font-size: 22px;
  line-height: 1.2;
}

.context-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.chip {
  max-width: 240px;
  padding: 6px 9px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 20px;
  overflow-y: auto;
  min-height: 0;
}

.message {
  max-width: min(760px, 88%);
  padding: 13px 14px;
  border-radius: 8px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.message.assistant {
  align-self: flex-start;
  background: var(--surface-muted);
  border: 1px solid var(--line);
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: white;
}

.message.markdown-message {
  white-space: normal;
}

.message.markdown-message p,
.message.markdown-message ul,
.message.markdown-message ol,
.message.markdown-message h3,
.message.markdown-message h4 {
  margin: 0;
}

.message.markdown-message > * + * {
  margin-top: 10px;
}

.message.markdown-message h3 {
  font-size: 17px;
  line-height: 1.25;
}

.message.markdown-message h4 {
  font-size: 15px;
  line-height: 1.3;
}

.message.markdown-message ul,
.message.markdown-message ol {
  display: grid;
  gap: 5px;
  padding-left: 22px;
}

.message.markdown-message li {
  padding-left: 2px;
}

.message.markdown-message strong {
  color: var(--ink);
  font-weight: 800;
}

.message.markdown-message code {
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(25, 33, 31, 0.08);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
}

.message.meta {
  align-self: center;
  max-width: 680px;
  background: transparent;
  color: var(--muted);
  border: 1px dashed var(--line);
  font-size: 13px;
}

.tool-trace {
  align-self: flex-start;
  width: min(760px, 88%);
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  color: var(--muted);
}

.tool-trace.live {
  border-color: rgba(15, 118, 110, 0.28);
}

.tool-trace-header {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.tool-list {
  display: grid;
  gap: 6px;
}

.tool-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
  padding: 8px;
  border-radius: 6px;
  background: var(--surface-muted);
}

.tool-status {
  display: grid;
  place-items: center;
  width: 22px;
  min-width: 22px;
  aspect-ratio: 1;
  border-radius: 999px;
  font-size: 9px;
  font-weight: 900;
  text-transform: uppercase;
}

.tool-row.ok .tool-status {
  background: rgba(15, 118, 110, 0.14);
  color: var(--teal);
}

.tool-row.running .tool-status {
  background: rgba(15, 118, 110, 0.18);
  color: var(--teal);
}

.tool-row.queued .tool-status {
  background: rgba(102, 113, 110, 0.14);
  color: var(--muted);
}

.tool-row.failed .tool-status {
  background: rgba(178, 31, 53, 0.14);
  color: var(--accent);
}

.tool-main {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.tool-name {
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.tool-summary {
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.tool-meta {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 112px;
  gap: 12px;
  padding: 16px;
  border-top: 1px solid var(--line);
  background: #fbfcfb;
}

.composer textarea {
  min-height: 58px;
  max-height: 180px;
  resize: vertical;
}

.composer button {
  min-height: 58px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  cursor: pointer;
}

.composer button:hover,
.secondary-action:hover {
  filter: brightness(0.97);
}

.composer button:disabled {
  background: #b8bfbc;
  cursor: wait;
}

@media (max-width: 920px) {
  body {
    height: auto;
    min-height: 100vh;
    overflow: auto;
  }

  .app-shell {
    height: auto;
    min-height: 100vh;
    padding: 12px;
    overflow: visible;
  }

  .workspace {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 0;
  }

  .context-panel {
    order: 2;
  }

  .chat-panel {
    height: 70vh;
    min-height: 480px;
  }
}

@media (max-width: 560px) {
  .two-col,
  .context-readout,
  .composer {
    grid-template-columns: 1fr;
  }

  .chat-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .context-chips {
    justify-content: flex-start;
  }

  .message {
    max-width: 100%;
  }

  .tool-trace {
    width: 100%;
  }

  .tool-row {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .tool-meta {
    grid-column: 2;
    white-space: normal;
  }
}
