:root {
  color-scheme: light;
  --canvas: #f4f7f6;
  --surface: #ffffff;
  --surface-subtle: #f5f8f7;
  --border: #e2e9e7;
  --text: #202a29;
  --muted: #5c6e6b;
  --accent: #176d83;
  --accent-dark: #15566d;
  --accent-soft: #e9f4f5;
  --user-bubble: #215da1;
  --user-bubble-text: #ffffff;
  --assistant-bubble: #f5f8f7;
  --error-bubble: #fff1ef;
  --error-text: #a52b23;

  --json-key: #175c8b;
  --json-number: #9c5700;
}

* {
  box-sizing: border-box;
}

.app-shell {
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--surface);
}

.history-sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  flex-direction: column;
  gap: 16px;
  padding: 18px 12px;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--canvas);
}

.new-chat-button {
  display: flex;
  min-height: 42px;
  align-items: center;
  gap: 9px;
  padding: 0 11px;
  border: 1px solid #d5e0de;
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  text-align: left;
  cursor: pointer;
}

.new-chat-button:hover,
.new-chat-button:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.new-chat-plus {
  display: inline-flex;
  width: 21px;
  height: 21px;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd9d6;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1;
}

.history-heading {
  margin: 5px 8px -8px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
}

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

.conversation-item {
  display: flex;
  min-width: 0;
  min-height: 42px;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.conversation-item:hover {
  background: #eaf0ee;
}

.conversation-item.active {
  border-color: #d7e5e2;
  background: var(--surface);
}

.conversation-title {
  overflow: hidden;
  font-size: 0.83rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-date {
  color: var(--muted);
  font-size: 0.72rem;
}

.history-status {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.history-status:empty {
  display: none;
}

.history-status.error {
  color: var(--error-text);
}

.history-toggle,
.history-backdrop {
  display: none;
}

html,
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--canvas);
  color: var(--text);
  font-family: "Aptos", "Segoe UI Variable", "Segoe UI", "Helvetica Neue", sans-serif;
}

.app {
  height: 100vh;
  height: 100dvh;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}

.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 72px;
  padding: 12px max(20px, calc((100% - 1040px) / 2));
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.app-logo {
  width: 36px;
  height: 36px;
  display: block;
  object-fit: contain;
}

.brand-name {
  overflow: hidden;
  font-size: 1rem;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-name span {
  color: var(--muted);
  font-weight: 500;
}

.model-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  max-width: 48%;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.model-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #318b69;
}

.model-caption {
  flex: 0 0 auto;
}

.model-name {
  overflow: hidden;
  color: var(--text);
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.messages {
  flex: 1;
  width: 100%;
  max-width: 860px;
  min-height: 0;
  margin: 0 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 32px 28px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  scroll-padding-block: 24px;
}

.empty-state {
  display: flex;
  flex: 1;
  min-height: 40vh;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 32px 12px;
  text-align: center;
}

.empty-eyebrow {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
}

.empty-state h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 1.2;
  font-weight: 650;
}

.empty-state > p:last-child {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.98rem;
}

.message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  max-width: 82%;
}

.message-user {
  align-self: flex-end;
  align-items: flex-end;
}

.bubble {
  max-width: 100%;
  padding: 11px 15px;
  border-radius: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.96rem;
}

.message-user .bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-bottom-right-radius: 5px;
}

.message-assistant .bubble {
  background: var(--assistant-bubble);
  border: 1px solid #edf1ef;
  border-bottom-left-radius: 5px;
}

.message-assistant .bubble.bubble-error {
  background: var(--error-bubble);
  border-color: #f2d3cf;
  color: var(--error-text);
}

.message-author {
  padding: 0 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.bubble-json {
  width: 100%;
}

.plan-card {
  white-space: normal;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.plan-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.plan-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.8rem;
  color: var(--muted);
}

.plan-mode {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 5px;
}

.plan-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.plan-step {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.step-index {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin-top: 2px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
}

.step-body {
  flex: 1;
  min-width: 0;
}

.step-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 0.75rem;
}

.step-agent {
  font-weight: 700;
  color: var(--json-key);
  background: var(--accent-soft);
  padding: 2px 7px;
  border-radius: 5px;
}

.step-capability {
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 5px;
}

.step-id {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.step-task {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.4;
}

.plan-explanation {
  margin: 0;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
  font-size: 0.9rem;
  color: var(--muted);
}

.structured-response {
  display: flex;
  flex-direction: column;
  gap: 12px;
  white-space: normal;
}

.data-fields {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0;
}

.data-field {
  display: grid;
  grid-template-columns: minmax(90px, 0.55fr) minmax(0, 1.45fr);
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.data-field:first-child {
  padding-top: 2px;
}

.data-field:last-child {
  padding-bottom: 2px;
  border-bottom: 0;
}

.data-field dt {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.data-field dd {
  min-width: 0;
  margin: 0;
  overflow-wrap: anywhere;
}

.data-string,
.data-empty,
.response-text {
  margin: 0;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.data-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.data-list > li {
  min-width: 0;
}

.data-list > li + li {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.data-primitive {
  display: inline-block;
  overflow-wrap: anywhere;
}

.data-boolean {
  color: var(--accent);
  font-weight: 650;
}

.data-number {
  color: var(--json-number);
  font-variant-numeric: tabular-nums;
}

.data-null,
.data-empty {
  color: var(--muted);
}

.composer-area {
  flex: 0 0 auto;
  width: 100%;
  padding: 12px 20px calc(14px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.composer-inner {
  max-width: 820px;
  margin: 0 auto;
}

.chat-form {
  display: flex;
  flex-direction: column;
  padding: 10px 12px 8px;
  border: 1px solid #d5e0de;
  border-radius: 15px;
  background: var(--surface);
  transition: border-color 120ms ease;
}

.chat-form:focus-within {
  border-color: var(--accent);
}

.chat-form textarea {
  width: 100%;
  min-height: 44px;
  max-height: 128px;
  resize: none;
  padding: 9px 5px;
  border: 0;
  outline: 0;
  overflow-y: hidden;
  background: transparent;
  color: var(--text);
  font: inherit;
  line-height: 1.5;
}

.chat-form textarea::placeholder {
  color: #778582;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.upload-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.upload-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms ease, color 120ms ease;
}

.upload-button:hover {
  background: var(--surface-subtle);
  color: var(--text);
}

.upload-input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  clip-path: inset(50%);
}

.upload-input:focus-visible + .upload-plus {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.upload-plus {
  display: inline-flex;
  width: 18px;
  height: 18px;
  align-items: center;
  justify-content: center;
  border: 1px solid #cbd9d6;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 400;
  line-height: 1;
}

.send-button {
  flex: 0 0 auto;
  min-width: 76px;
  min-height: 40px;
  padding: 0 17px;
  border: 0;
  border-radius: 9px;
  background: var(--accent-dark);
  color: #fff;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 650;
  cursor: pointer;
  transition: background-color 120ms ease, opacity 120ms ease;
}

.send-button:hover:not(:disabled) {
  background: #10465c;
}

.send-button:disabled {
  opacity: 0.58;
  cursor: not-allowed;
}

.upload-status {
  margin: 0;
  padding: 0 4px 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.upload-status:empty {
  display: none;
}

.upload-status.error {
  color: var(--error-text);
}

.upload-status {
  padding: 8px 4px 0;
  overflow-wrap: anywhere;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

@media (max-width: 600px) {
  .app-shell {
    display: block;
  }

  .history-sidebar {
    position: fixed;
    z-index: 22;
    inset: 0 auto 0 0;
    width: min(84vw, 300px);
    transform: translateX(-105%);
    transition: transform 160ms ease;
    box-shadow: 12px 0 32px rgb(20 40 36 / 12%);
  }

  .app-shell.history-open .history-sidebar {
    transform: translateX(0);
  }

  .history-backdrop:not([hidden]) {
    position: fixed;
    z-index: 21;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    border: 0;
    background: rgb(20 35 32 / 30%);
  }

  .history-toggle {
    display: inline-flex;
    min-height: 38px;
    flex: 0 0 auto;
    align-items: center;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
  }

  .app-header {
    min-height: 64px;
    gap: 12px;
    padding: 10px 16px;
  }

  .app-logo {
    width: 32px;
    height: 32px;
  }

  .brand {
    flex: 1 1 auto;
    gap: 8px;
  }

  .brand-name {
    font-size: 0.92rem;
  }

  .model-indicator {
    max-width: 32%;
    flex: 0 1 auto;
    gap: 6px;
    padding: 6px 8px;
    font-size: 0.74rem;
  }

  .model-caption {
    display: none;
  }

  .messages {
    padding: 24px 16px 20px;
    gap: 18px;
  }

  .empty-state {
    min-height: 32vh;
  }

  .empty-state h1 {
    font-size: 1.7rem;
  }

  .message {
    max-width: 94%;
  }

  .composer-area {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  .chat-form {
    padding: 8px 8px 7px;
    border-radius: 13px;
  }

  .upload-bar {
    gap: 0;
  }

  .upload-button {
    min-height: 40px;
    gap: 5px;
    padding: 5px 7px;
    font-size: 0.77rem;
  }

  .send-button {
    min-width: 68px;
    min-height: 40px;
    padding: 0 12px;
  }
}

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