:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --line: #d7dee8;
  --text: #172033;
  --muted: #657186;
  --primary: #1867c9;
  --primary-dark: #0f4f9b;
  --success: #0f8f65;
  --warning: #b66a00;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(23, 32, 51, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button,
.file-button {
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  min-height: 40px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
}

button:hover,
.file-button:hover {
  background: var(--primary-dark);
}

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

.secondary,
.ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.secondary:hover,
.ghost:hover {
  background: #e1e9f2;
}

.small-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}

.topbar {
  height: 72px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.provider,
.inline-state {
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  width: calc(100% - 48px);
  max-width: none;
  margin: 0 auto;
  padding: 24px;
  display: grid;
  grid-template-columns: 460px minmax(0, 1fr);
  gap: 20px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.compose-panel {
  padding: 20px;
}

.task-panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.task-panel .panel-head {
  padding: 20px 20px 0;
}

.panel h2 {
  margin: 0;
  font-size: 18px;
}

.field,
.field-row,
.actions {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.field-row {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.actions {
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.field > span,
.field-title label {
  color: var(--muted);
  font-size: 13px;
}

.field-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.text-help-button {
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--primary);
  display: inline;
  line-height: 1.4;
  font-size: 13px;
}

.text-help-button:hover {
  background: transparent;
  color: var(--primary-dark);
  text-decoration: underline;
}

input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 10px 12px;
  outline: none;
}

textarea {
  resize: vertical;
  min-height: 160px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24, 103, 201, 0.12);
}

.file-button input {
  display: none;
}

.image-grid {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(124px, 1fr));
  gap: 10px;
  min-height: 44px;
}

.image-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.image-item label {
  display: grid;
  cursor: pointer;
}

.image-item img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-2);
}

.image-meta {
  display: grid;
  gap: 4px;
  padding: 8px;
  min-width: 0;
}

.image-meta span {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.param-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 14px;
}

.toggle-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.param-help {
  min-height: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--primary);
  display: inline;
  line-height: 1.4;
}

.param-help:hover {
  background: transparent;
  color: var(--primary-dark);
  text-decoration: underline;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 840px;
}

th,
td {
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-weight: 600;
  background: #fbfcfe;
}

.task-id,
.prompt-cell {
  max-width: 220px;
  overflow-wrap: anywhere;
}

.prompt-cell {
  color: #2a3448;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.badge.succeeded {
  background: #e3f8ef;
  color: var(--success);
}

.badge.failed {
  background: #fde8e7;
  color: var(--danger);
}

.badge.running,
.badge.queued,
.badge.submitting {
  background: #fff4df;
  color: var(--warning);
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.empty {
  color: var(--muted);
  text-align: center;
  padding: 36px 12px;
}

.form-error {
  color: var(--danger);
  font-size: 14px;
}

.login-body {
  display: grid;
  place-items: center;
  background: #eef3f8;
}

.login-shell {
  width: min(420px, calc(100vw - 32px));
}

.login-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  gap: 14px;
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.login-panel label {
  color: var(--muted);
  font-size: 14px;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
}

.modal.open {
  display: block;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 18, 30, 0.48);
}

.modal-panel {
  position: relative;
  width: min(1180px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  margin: 24px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(12, 18, 30, 0.25);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

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

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  overflow: hidden;
  padding: 16px 18px 20px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  min-height: 0;
}

.modal-detail,
.task-image-panel {
  min-height: 0;
  overflow: auto;
}

.modal-body pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #182235;
  background: #f6f8fb;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

.task-image-panel {
  border-left: 1px solid var(--line);
  padding-left: 16px;
}

.task-image-panel h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.task-image-list {
  display: grid;
  gap: 10px;
}

.task-image-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.image-thumb-button {
  width: 100%;
  min-height: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  display: grid;
  text-align: left;
}

.image-thumb-button:hover {
  background: var(--surface-2);
}

.image-thumb-button img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: var(--surface-2);
}

.task-image-name {
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview-panel {
  position: relative;
  width: min(1080px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  margin: 24px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(12, 18, 30, 0.25);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.param-modal-panel {
  position: relative;
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  margin: 24px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(12, 18, 30, 0.25);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.prompt-help-panel {
  position: relative;
  width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  margin: 24px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(12, 18, 30, 0.25);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.message-modal-panel {
  position: relative;
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  margin: 24px auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 22px 60px rgba(12, 18, 30, 0.25);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.message-body {
  overflow: auto;
  padding: 18px;
  color: #2a3448;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.prompt-help-body {
  overflow: auto;
  padding: 18px;
  color: #2a3448;
  line-height: 1.7;
}

.prompt-help-body p {
  margin: 0 0 12px;
}

.prompt-help-body pre {
  margin: 12px 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: #f6f8fb;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 14px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.6;
}

.param-help-body {
  overflow: auto;
  padding: 18px;
  color: #2a3448;
  line-height: 1.7;
}

.param-help-body p {
  margin: 0 0 12px;
}

.param-help-body p:last-child {
  margin-bottom: 0;
}

.large-image-wrap {
  min-height: 0;
  overflow: auto;
  padding: 16px;
  display: grid;
  place-items: center;
  background: #f6f8fb;
}

#largeImage {
  max-width: 100%;
  max-height: calc(100vh - 150px);
  object-fit: contain;
}

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

  .modal-body {
    grid-template-columns: 1fr;
  }

  .task-image-panel {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 16px;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    min-height: 68px;
    padding: 12px 16px;
  }

  .workspace {
    width: calc(100% - 28px);
    padding: 14px;
  }

  .param-grid,
  .field-row,
  .actions {
    grid-template-columns: 1fr;
  }
}
