:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --panel: #ffffff;
  --panel-strong: #eef3f5;
  --text: #202326;
  --muted: #657078;
  --line: #d6dce0;
  --accent: #0a6f86;
  --accent-strong: #064f61;
  --amber: #a76418;
  --danger: #a33a2a;
  --user-bubble: #dfeef5;
  --assistant-bubble: #f7f8fa;
  --shadow: 0 1px 2px rgba(27, 32, 36, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 320px) 1fr;
  gap: 18px;
  align-items: end;
  min-height: 86px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfa;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: 0 0 34px;
  height: 34px;
  border: 1px solid #9eb4bf;
  border-radius: 7px;
  color: var(--accent-strong);
  background: #e4eef2;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.15;
}

.brand p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(140px, 200px) minmax(220px, 300px);
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 5px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

input {
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input:focus,
textarea:focus {
  border-color: #6aa3b4;
  box-shadow: 0 0 0 3px rgba(10, 111, 134, 0.14);
}

.workspace {
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: minmax(0, 1fr);
  height: calc(100vh - 124px);
  min-height: 560px;
  padding: 12px;
}

.pane {
  min-width: 0;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.pane {
  display: grid;
  grid-template-rows: auto 1fr;
}

.chat-pane {
  grid-template-rows: auto 1fr auto;
}

.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 46px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-strong);
}

.pane-head h2 {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
}

.actions {
  display: flex;
  align-items: center;
  gap: 7px;
}

.button {
  display: inline-grid;
  place-items: center;
  min-width: 62px;
  height: 32px;
  padding: 0 12px;
  border: 1px solid #b8c2c8;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.button:hover {
  border-color: #849aa5;
  background: #f8fafb;
}

.button-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.button-primary:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.button-secondary {
  color: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

textarea {
  width: 100%;
  height: 100%;
  min-height: 0;
  resize: none;
  padding: 12px;
  border: 0;
  border-radius: 0 0 8px 8px;
  outline: none;
  background: #fff;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  tab-size: 2;
}

.chat-log {
  min-height: 0;
  overflow: auto;
  padding: 14px;
  background: #fff;
}

.chat-empty {
  color: var(--muted);
  font-size: 13px;
}

.chat-message {
  display: grid;
  gap: 5px;
  max-width: min(760px, 86%);
  margin-bottom: 14px;
}

.chat-message-user {
  margin-left: auto;
}

.chat-role {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.chat-message-user .chat-role {
  text-align: right;
}

.chat-bubble {
  max-width: 100%;
  overflow-wrap: anywhere;
  padding: 9px 11px;
  border: 1px solid #cbd7df;
  border-radius: 8px;
  background: var(--assistant-bubble);
  line-height: 1.55;
}

.chat-message-user .chat-bubble {
  border-color: #bfd3dd;
  background: var(--user-bubble);
}

.chat-message.is-error .chat-bubble {
  border-color: #e3b7ae;
  background: #fff1ee;
  color: var(--danger);
}

.chat-result {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  font-size: 13px;
  line-height: 1.3;
}

.result-link {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.result-link:hover,
.result-link:focus-visible {
  color: var(--accent);
}

.result-separator {
  color: var(--muted);
}

.result-dialog {
  width: min(1120px, calc(100vw - 32px));
  height: min(780px, calc(100vh - 40px));
  max-width: none;
  max-height: none;
  padding: 0;
  border: 1px solid #b8c5cb;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(31, 42, 46, 0.32);
}

.result-dialog::backdrop {
  background: rgba(31, 42, 46, 0.46);
}

.result-dialog-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100%;
  min-height: 0;
}

.result-dialog-head {
  display: flex;
  gap: 12px;
  align-items: start;
  justify-content: space-between;
  min-width: 0;
  padding: 14px 16px 12px;
  border-bottom: 1px solid var(--line);
  background: #f8faf8;
}

.result-dialog-labels {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.result-dialog-title {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-dialog-meta {
  min-width: 0;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-dialog-close {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border: 1px solid #c6d0d5;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.result-dialog-close:hover,
.result-dialog-close:focus-visible {
  border-color: #82959e;
  background: #f2f6f7;
}

.result-dialog-body {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 10px;
  min-height: 0;
  overflow: hidden;
  padding: 12px;
}

.result-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.result-action-button {
  height: 28px;
  padding: 0 9px;
  border: 1px solid #b8c2c8;
  border-radius: 6px;
  background: #fff;
  color: var(--accent-strong);
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.result-action-button:hover {
  border-color: #849aa5;
  background: #f8fafb;
}

.result-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.result-tab {
  display: grid;
  align-content: center;
  min-width: 146px;
  min-height: 48px;
  padding: 6px 12px;
  border: 1px solid #c6d0d5;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

.result-tab:hover,
.result-tab:focus-visible {
  color: var(--accent-strong);
  background: #f2f6f7;
}

.result-tab.is-active {
  border-color: var(--accent);
  background: #e9f4f6;
  box-shadow: inset 0 0 0 1px rgba(10, 111, 134, 0.18);
}

.result-tab-title {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.2;
}

.result-tab-description {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.result-tab-panels {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.result-tab-panel {
  height: 100%;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  border: 1px solid #dfe5e8;
  border-radius: 0 7px 7px 7px;
  background: #fff;
}

.json-output {
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0;
  overflow: auto;
  padding: 9px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
  padding: 10px;
  border-top: 1px solid var(--line);
  background: #fbfcfa;
}

.composer textarea {
  height: 96px;
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.55;
}

.composer .button {
  width: 74px;
  height: 38px;
}

.statusbar {
  display: grid;
  grid-template-columns: minmax(180px, 0.4fr) minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  height: 38px;
  padding: 0 14px;
  border-top: 1px solid var(--line);
  background: #fbfcfa;
  color: var(--muted);
  font-size: 12px;
}

.status,
.validation {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.validation {
  text-align: right;
}

.statusbar.is-error .status,
.statusbar.is-error .validation {
  color: var(--danger);
}

.statusbar.is-warning .status,
.statusbar.is-warning .validation {
  color: var(--amber);
}

@media (max-width: 1100px) {
  html,
  body {
    height: auto;
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .settings {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(520px, auto);
    height: auto;
    min-height: 0;
  }

  .chat-pane {
    min-height: 520px;
  }

  .result-dialog {
    height: min(760px, calc(100vh - 24px));
    width: calc(100vw - 20px);
  }

  .result-dialog-body {
    overflow: auto;
  }

  .result-tab-panels {
    min-height: 320px;
  }

  .result-tab-panel {
    max-height: 320px;
  }

  .statusbar {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 44px;
    align-items: start;
    padding: 8px 14px;
  }

  .validation {
    text-align: left;
  }
}

@media (max-width: 620px) {
  .topbar,
  .workspace {
    padding-left: 10px;
    padding-right: 10px;
  }

  .actions {
    gap: 5px;
  }

  .button {
    min-width: 56px;
    padding: 0 9px;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer .button {
    width: 100%;
  }

  .chat-message {
    max-width: 94%;
  }

  .result-dialog-title,
  .result-dialog-meta {
    white-space: normal;
  }
}
