:root {
  color-scheme: light dark;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --text: #172033;
  --muted: #65758a;
  --border: #d9e0ea;
  --user-bubble: #e9f1ff;
  --assistant-bubble: #f7f9fc;
  --accent: #9a4f2f;
  --accent-text: #ffffff;
  --shadow: 0 12px 32px rgba(27, 36, 48, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111111;
  --surface: #222222;
  --surface-raised: #2b2b2b;
  --text: #ececec;
  --muted: #a4a4a4;
  --border: #3f3f3f;
  --user-bubble: #254f48;
  --assistant-bubble: #2a2a2a;
  --accent: #93451f;
  --accent-text: #f7f7f7;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.34);
}

:root[data-theme="light"] {
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;
    --bg: #111111;
    --surface: #222222;
    --surface-raised: #2b2b2b;
    --text: #ececec;
    --muted: #a4a4a4;
    --border: #3f3f3f;
    --user-bubble: #254f48;
    --assistant-bubble: #2a2a2a;
    --accent: #93451f;
    --accent-text: #f7f7f7;
    --shadow: 0 14px 36px rgba(0, 0, 0, 0.34);
  }
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
}

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

button {
  border: 0;
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.app-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 16px 16px 118px;
}

.top-actions {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--text);
}

.icon-button.small {
  width: 30px;
  height: 30px;
}

.loading {
  align-items: center;
  gap: 8px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  box-shadow: var(--shadow);
  font-size: 0.9rem;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 3px solid color-mix(in srgb, var(--muted) 40%, transparent);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.chat-area {
  flex: 1;
  overflow: auto;
  padding: 50px 8px 8px;
}

.message {
  display: flex;
  margin: 0 0 14px;
}

.message.user {
  justify-content: flex-start;
}

.message.assistant {
  justify-content: flex-end;
}

.message-bubble {
  position: relative;
  max-width: min(760px, 78vw);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--assistant-bubble);
  box-shadow: var(--shadow);
  padding: 12px 14px;
}

.message.user .message-bubble {
  background: var(--user-bubble);
}

.message-content {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
  line-height: 1.48;
}

.info-button {
  position: absolute;
  right: 8px;
  bottom: 8px;
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--surface-raised);
  color: var(--muted);
  font-weight: 700;
}

.message.assistant .message-content {
  padding-bottom: 24px;
}

.composer-bar {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 15;
}

.prompt-shell {
  position: relative;
  min-height: 88px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 14px 56px 14px 14px;
}

#promptInput {
  display: block;
  width: 100%;
  min-height: 28px;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  line-height: 1.45;
}

#promptInput::placeholder {
  color: var(--muted);
}

.prompt-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.model-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: min(260px, calc(100vw - 128px));
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--text);
}

.model-button-icon {
  flex: 0 0 auto;
}

.model-button-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.send-button {
  position: absolute;
  right: 10px;
  bottom: 14px;
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 1.25rem;
  font-weight: 700;
}

.model-menu {
  position: absolute;
  left: 14px;
  bottom: 56px;
  width: min(420px, calc(100vw - 48px));
  max-height: 420px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
  padding: 10px;
  z-index: 30;
}

.model-menu-section + .model-menu-section {
  margin-top: 10px;
}

.model-menu-heading {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  margin: 4px 4px 6px;
  text-transform: uppercase;
}

.model-menu-item {
  display: block;
  width: 100%;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  padding: 8px;
  text-align: left;
}

.model-menu-item:hover,
.model-menu-item.is-selected {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}

.details-popover {
  position: fixed;
  right: 26px;
  bottom: 126px;
  z-index: 35;
  width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  box-shadow: var(--shadow);
  padding: 14px;
}

.details-popover-header,
.bench-header,
.bench-header-actions {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

h2,
h3,
p {
  margin: 0;
}

p {
  margin-top: 6px;
  color: var(--muted);
  line-height: 1.45;
}

.details-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin: 12px 0 0;
}

.details-grid dt {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

.details-grid dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.46);
  padding: 24px;
}

.bench-panel {
  width: min(1180px, 100%);
  max-height: min(820px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.api-key-panel {
  width: min(560px, 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 20px;
}

.bench-header-actions {
  align-items: center;
}

.bench-status {
  color: var(--muted);
  min-width: 160px;
  text-align: right;
}

.field {
  display: grid;
  gap: 8px;
  margin-top: 18px;
  font-weight: 650;
}

.bench-prompt textarea {
  min-height: 110px;
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--text);
  padding: 12px;
}

.field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-raised);
  color: var(--text);
  padding: 12px;
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.actions button,
#startBenchButton {
  min-height: 40px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  padding: 0 14px;
  font-weight: 700;
}

.bench-table-wrap {
  margin-top: 18px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.bench-table {
  width: 100%;
  min-width: 1040px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.bench-table th,
.bench-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.bench-table th {
  position: sticky;
  top: 0;
  background: var(--surface-raised);
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  z-index: 1;
}

.mono-cell,
.bench-output pre {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

.row-complete {
  background: color-mix(in srgb, #2f8f5b 10%, transparent);
}

.row-error {
  background: color-mix(in srgb, #b44b36 14%, transparent);
}

.chevron-button {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--text);
}

.bench-output-row td {
  padding: 0;
  background: var(--surface-raised);
}

.bench-output {
  padding: 14px 18px 18px;
  border-bottom: 1px solid var(--border);
}

.bench-output h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.bench-output h3 + pre {
  margin-bottom: 16px;
}

.bench-output pre {
  max-height: 320px;
  margin: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.86rem;
  line-height: 1.5;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px 12px 112px;
  }

  .top-actions {
    top: 12px;
    right: 12px;
  }

  .composer-bar {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .message-bubble {
    max-width: 88vw;
  }

  .bench-header,
  .bench-header-actions {
    flex-direction: column;
  }

  .bench-status {
    text-align: left;
  }
}
