:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --ink: #172026;
  --muted: #66727c;
  --line: #d9e0e5;
  --accent: #176b5b;
  --accent-strong: #0f5144;
  --accent-soft: #e8f5f1;
  --info: #245b9d;
  --danger: #b42318;
  --danger-soft: #fff1ee;
  --success: #147a43;
  --success-soft: #ecf8f1;
  --warning: #9a5b00;
  --viewer: #11181d;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--ink);
}

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

button,
.target-open {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

button:hover,
.target-open:hover {
  background: var(--accent-strong);
}

button:disabled,
.target-open.disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #ffffff;
}

input,
select {
  height: 38px;
  padding: 0 10px;
}

textarea {
  min-height: 120px;
  padding: 10px;
  line-height: 1.4;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(23, 107, 91, 0.22);
  border-color: var(--accent);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.15;
}

h2 {
  font-size: 12px;
  line-height: 1.2;
  color: var(--muted);
  letter-spacing: 0;
  text-transform: uppercase;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(390px, 470px);
  min-height: 100vh;
}

.viewer {
  position: relative;
  min-width: 0;
  min-height: 100vh;
  padding-top: 64px;
  background: var(--viewer);
}

.viewer-toolbar {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: #ffffff;
}

.brand {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.mark {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 850;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.empty-state {
  position: absolute;
  inset: 64px 0 0 0;
  display: grid;
  place-items: center;
  color: rgba(255, 255, 255, 0.72);
}

.empty-title {
  font-size: 18px;
  font-weight: 750;
}

iframe {
  display: none;
  width: 100%;
  height: calc(100vh - 64px);
  border: 0;
  background: #ffffff;
}

iframe.is-visible {
  display: block;
}

.recording-layer {
  position: absolute;
  inset: 64px 0 0 0;
  z-index: 4;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #ffffff;
}

.recording-layer[hidden] {
  display: none;
}

.recording-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 58px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.recording-title {
  font-size: 15px;
  font-weight: 800;
}

.recording-status {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.recording-header button {
  min-height: 34px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.recording-header button:hover {
  background: #eef2f4;
}

.recording-mount {
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background: #f3f5f6;
}

.recording-mount .rr-player {
  margin: 0 auto;
  box-shadow: none;
}

.workspace {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: 100vh;
  min-width: 0;
  padding: 14px;
  overflow: hidden;
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.workspace-header {
  display: grid;
  gap: 8px;
}

.status-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

#openSettingsButton {
  min-width: 92px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

#openSettingsButton:hover {
  background: #eef2f4;
}

.status {
  min-height: 40px;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 14px;
  overflow-wrap: anywhere;
}

.status[data-type='success'] {
  border-color: rgba(20, 122, 67, 0.3);
  color: var(--success);
  background: var(--success-soft);
}

.status[data-type='error'] {
  border-color: rgba(180, 35, 24, 0.25);
  color: var(--danger);
  background: var(--danger-soft);
}

.operation-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 36px;
  padding: 8px 10px;
  border: 1px solid rgba(36, 91, 157, 0.24);
  border-radius: 8px;
  background: #eef5ff;
  color: var(--info);
  font-size: 13px;
  font-weight: 700;
}

.operation-status[hidden] {
  display: none;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(36, 91, 157, 0.24);
  border-top-color: var(--info);
  border-radius: 999px;
  animation: spin 0.85s linear infinite;
}

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

.settings-grid {
  display: grid;
  gap: 12px;
}

.settings-grid label,
.session-form label,
.tab-panel label {
  display: grid;
  gap: 5px;
  min-width: 0;
  font-size: 12px;
  font-weight: 750;
}

.settings-grid button {
  width: 100%;
}

.observation-controls {
  display: grid;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.mode-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.mode-row label,
.checkbox-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.target-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.target-open {
  min-width: 68px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.target-open:hover {
  background: #eef2f4;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  z-index: 8;
  background: rgba(17, 24, 29, 0.22);
}

.drawer-backdrop[hidden] {
  display: none;
}

.settings-drawer {
  position: absolute;
  inset: 0 0 0 auto;
  z-index: 9;
  display: flex;
  width: min(430px, 100%);
  flex-direction: column;
  gap: 16px;
  padding: 16px;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: var(--surface);
  box-shadow: -18px 0 34px rgba(17, 24, 29, 0.12);
  pointer-events: none;
  transform: translateX(100%);
  transition: transform 150ms ease;
  visibility: hidden;
}

.settings-drawer.open {
  pointer-events: auto;
  transform: translateX(0);
  visibility: visible;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.drawer-header button {
  min-height: 32px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.drawer-header button:hover {
  background: #eef2f4;
}

.mode-row label:has(input:checked),
.checkbox-line:has(input:checked) {
  border-color: rgba(23, 107, 91, 0.42);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.mode-row input,
.checkbox-line input {
  width: auto;
  height: auto;
  margin: 0;
}

.workspace-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.workspace-tabs button {
  min-width: 0;
  min-height: 34px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
}

.workspace-tabs button.selected,
.workspace-tabs button:hover {
  border-color: rgba(23, 107, 91, 0.42);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.tab-panel {
  display: none;
  min-height: 0;
}

.tab-panel.selected {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  overflow: auto;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-header button {
  min-height: 31px;
  padding: 0 10px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
}

.section-header button:hover {
  background: #eef2f4;
}

.session-actions {
  display: flex;
  gap: 6px;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.chat-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 10px;
  min-height: 220px;
  overflow: auto;
  padding-right: 2px;
}

.chat-messages.empty,
.tests-list.empty,
.tabs-list.empty {
  display: grid;
  place-items: center;
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  font-size: 14px;
}

.chat-message {
  max-width: 94%;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.chat-message.user {
  align-self: flex-end;
  border-color: rgba(23, 107, 91, 0.34);
  background: var(--accent-soft);
}

.chat-message.assistant {
  align-self: flex-start;
}

.chat-message small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.chat-message > :first-child {
  margin-top: 0;
}

.chat-message > :last-child {
  margin-bottom: 0;
}

.chat-message p {
  margin: 0 0 8px;
}

.chat-message h3,
.chat-message h4,
.chat-message h5,
.chat-message h6 {
  margin: 10px 0 6px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.25;
  text-transform: none;
}

.chat-message ul,
.chat-message ol {
  margin: 6px 0 8px;
  padding-left: 20px;
}

.chat-message li {
  margin: 3px 0;
}

.chat-message a {
  color: var(--accent-strong);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.chat-message code {
  padding: 1px 4px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #ffffff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 0.9em;
}

.chat-message pre {
  max-width: 100%;
  margin: 8px 0;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.chat-message pre code {
  padding: 0;
  border: 0;
  background: transparent;
  white-space: pre;
}

.markdown-table-wrap {
  max-width: 100%;
  margin: 8px 0;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.chat-message table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.chat-message th,
.chat-message td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.chat-message th {
  background: var(--surface-soft);
  font-weight: 800;
}

.chat-message tr:last-child td {
  border-bottom: 0;
}

.chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.chat-composer {
  display: grid;
  gap: 8px;
}

.chat-composer textarea {
  min-height: 72px;
  max-height: 180px;
}

.image-attachments,
.message-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.image-attachments[hidden] {
  display: none;
}

.image-attachment {
  position: relative;
  width: 88px;
  height: 68px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.image-attachment img,
.message-images img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-attachment button {
  position: absolute;
  inset: auto 4px 4px 4px;
  min-height: 24px;
  padding: 0 6px;
  border-color: rgba(17, 32, 38, 0.24);
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  font-size: 11px;
}

.image-attachment button:hover {
  background: #ffffff;
}

.message-images {
  margin-top: 8px;
}

.message-images img {
  width: 128px;
  height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.timing-line {
  min-height: 32px;
  padding: 7px 9px;
  border: 1px solid rgba(36, 91, 157, 0.2);
  border-radius: 8px;
  background: #f3f8ff;
  color: var(--info);
  font-size: 13px;
}

.timing-line[hidden] {
  display: none;
}

.tests-list,
.tabs-list {
  display: grid;
  gap: 8px;
}

.test-card {
  display: grid;
  gap: 9px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.test-card-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.test-card-header button {
  min-height: 30px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

.test-card-header button:hover {
  background: #eef2f4;
}

.test-card strong,
.test-card small {
  display: block;
}

.test-card small {
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.3;
}

.test-card p,
.test-card li {
  font-size: 13px;
  line-height: 1.35;
}

.test-card ol {
  margin: 0;
  padding-left: 18px;
}

.test-card p {
  margin: 0;
}

.tab-button {
  justify-content: flex-start;
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  overflow-wrap: anywhere;
  white-space: normal;
  text-align: left;
}

.tab-button:hover,
.tab-button.selected {
  border-color: rgba(23, 107, 91, 0.45);
  background: var(--accent-soft);
}

.session-form {
  display: grid;
  gap: 8px;
}

#releaseAgentButton {
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
}

#releaseAgentButton:hover {
  background: #eef2f4;
}

#systemPrompt {
  min-height: 360px;
  font-size: 12px;
}

@media (max-width: 1120px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .viewer {
    min-height: 60vh;
  }

  iframe {
    height: calc(60vh - 64px);
    min-height: 420px;
  }

  .empty-state,
  .recording-layer {
    min-height: 420px;
  }

  .workspace {
    height: auto;
    min-height: 720px;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 620px) {
  .viewer-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .mode-row {
    width: 100%;
    grid-template-columns: 1fr;
  }

  .mode-row label {
    min-width: 0;
  }

  .settings-grid,
  .chat-form,
  .input-row,
  .target-row {
    grid-template-columns: 1fr;
  }

  .workspace-tabs {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-drawer {
    width: 100%;
  }

  .settings-grid button {
    width: 100%;
  }
}
