:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #d8dde5;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --danger: #b42318;
  --danger-bg: #fff0ed;
  --ok: #067647;
  --run: #175cd3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Microsoft JhengHei", Arial, sans-serif;
  font-size: 15px;
}

a {
  color: inherit;
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  letter-spacing: 0;
}

.topbar nav a {
  color: var(--muted);
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-pill {
  color: var(--muted);
  font-size: 14px;
}

.runner-link,
.runner-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  background: #f2f4f7;
  color: #475467;
  font-size: 14px;
}

.topbar nav .runner-link {
  color: #475467;
}

.logout-form {
  margin: 0;
}

.logout-form button {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  padding: 0;
}

.page {
  width: min(1120px, calc(100% - 32px));
  margin: 28px auto 56px;
}

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

.section-head.compact {
  margin-top: 34px;
}

.runner-switch {
  min-width: 180px;
  display: grid;
  justify-items: end;
  gap: 6px;
}

.runner-switch span {
  color: var(--muted);
  font-size: 13px;
}

.runner-switch strong {
  font-size: 18px;
}

.page-actions {
  margin-top: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.25;
}

h2 {
  font-size: 18px;
  line-height: 1.35;
}

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

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
}

.card,
.form-panel,
.notice,
.job-meta,
.templates-panel,
.outputs,
.log-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.card {
  display: flex;
  min-height: 160px;
  flex-direction: column;
  justify-content: space-between;
  padding: 18px;
}

.tool-card.is-disabled {
  border-style: dashed;
  background: #fbfcfd;
}

.card-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.tool-card-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.tool-visibility-form {
  margin: 0;
}

.tool-switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.tool-switch:hover {
  border-color: var(--accent);
}

.tool-switch-track {
  position: relative;
  display: inline-flex;
  width: 32px;
  height: 18px;
  border-radius: 999px;
  background: #d0d5dd;
  transition: background 0.15s ease;
}

.tool-switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.2);
  transition: transform 0.15s ease;
}

.tool-switch.is-on {
  border-color: #067647;
  color: #067647;
  background: #ecfdf3;
}

.tool-switch.is-on .tool-switch-track {
  background: #12b76a;
}

.tool-switch.is-on .tool-switch-thumb {
  transform: translateX(14px);
}

.tool-switch.is-off {
  border-color: #d92d20;
  color: #b42318;
  background: #fff0ed;
}

.tool-switch.is-off:hover {
  border-color: #b42318;
}

.tool-switch.is-off .tool-switch-track {
  background: #d92d20;
}

.owner-only-note {
  display: inline-block;
  margin-top: 8px;
  color: #b54708;
  font-weight: 700;
}

.button,
button.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  width: fit-content;
}

.button.primary,
.button:hover {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

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

.button.danger {
  border-color: #d92d20;
  background: #d92d20;
  color: #fff;
}

.button.danger:hover {
  border-color: #b42318;
  background: #b42318;
}

.button:disabled,
button.button:disabled {
  border-color: var(--border);
  background: #eaecf0;
  color: #98a2b3;
  cursor: not-allowed;
}

.button.ghost {
  color: var(--muted);
}

.notice {
  padding: 14px 16px;
  margin-bottom: 16px;
}

.notice.danger {
  background: var(--danger-bg);
  border-color: #f4b8ae;
  color: var(--danger);
}

.notice.success {
  background: #ecfdf3;
  border-color: #abefc6;
  color: var(--ok);
}

.empty {
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
}

.jobs-list {
  display: grid;
  gap: 8px;
}

.job-row {
  display: grid;
  grid-template-columns: 180px 1fr 140px auto;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.job-row span {
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 92px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-style: normal;
  font-weight: 700;
  font-size: 13px;
  background: #eef4ff;
  color: var(--run);
}

.status.succeeded {
  background: #ecfdf3;
  color: var(--ok);
}

.status.failed {
  background: var(--danger-bg);
  color: var(--danger);
}

.status.cancelled {
  background: #f2f4f7;
  color: #475467;
}

.status.cancel_requested {
  background: #fff7e6;
  color: #b54708;
}

.status.codex_checking,
.status.rerunning {
  background: #eef4ff;
  color: var(--run);
}

.status.queued {
  background: #f2f4f7;
  color: #475467;
}

.job-head-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.inline-form {
  margin: 0;
}

.level-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 50px;
  height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-style: normal;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}

.level-低 {
  background: #ecfdf3;
  color: #067647;
}

.level-中 {
  background: #fff7e6;
  color: #b54708;
}

.level-高 {
  background: #fff0ed;
  color: #b42318;
}

.auth-card {
  width: min(440px, 100%);
  margin: 72px auto 0;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-card h1 {
  margin-bottom: 6px;
}

.login-form {
  display: grid;
  gap: 16px;
  margin-top: 20px;
}

.form-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
  max-width: 720px;
}

.field {
  display: grid;
  gap: 8px;
}

.field.is-hidden {
  display: none;
}

.upload-summary {
  display: grid;
  gap: 10px;
  padding: 14px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.upload-summary h2 {
  font-size: 16px;
}

.upload-summary-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
}

.upload-summary-item.is-hidden,
.upload-summary-empty.is-hidden {
  display: none;
}

.upload-summary-item strong {
  font-size: 14px;
}

.upload-summary-item b {
  margin-left: 4px;
  color: var(--danger);
}

.upload-summary-item span,
.upload-summary-empty {
  color: var(--muted);
}

.field span {
  font-weight: 700;
}

.field b {
  margin-left: 4px;
  color: var(--danger);
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
  color: var(--text);
}

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

input.check {
  width: 22px;
  min-height: 22px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row.compact {
  min-height: 42px;
}

small {
  color: var(--muted);
  line-height: 1.5;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.job-meta {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 1px;
  overflow: hidden;
}

.job-meta div {
  display: grid;
  gap: 6px;
  padding: 16px;
  background: #fff;
}

.job-meta span {
  color: var(--muted);
  font-size: 13px;
}

.templates-panel,
.outputs,
.log-panel {
  margin-top: 18px;
  padding: 18px;
}

.templates-panel {
  max-width: 720px;
  margin-bottom: 16px;
}

.outputs h2,
.templates-panel h2,
.log-panel h2 {
  margin-bottom: 12px;
}

.templates-panel p {
  margin-bottom: 12px;
}

.download {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.download + .download {
  margin-top: 8px;
}

.download span {
  color: var(--muted);
  font-size: 13px;
}

pre {
  overflow: auto;
  min-height: 180px;
  max-height: 520px;
  padding: 14px;
  margin: 0;
  background: #111827;
  color: #e5e7eb;
  border-radius: 6px;
  line-height: 1.5;
  white-space: pre-wrap;
}

.log-panel #log {
  height: 68vh;
  min-height: 420px;
  max-height: none;
  overscroll-behavior: contain;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(280px, 340px) 1fr;
  gap: 18px;
  align-items: start;
}

.admin-create {
  max-width: none;
}

.admin-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  overflow: auto;
}

.admin-panel h2,
.admin-create h2 {
  margin-bottom: 14px;
}

.runner-panel {
  max-width: 760px;
}

.runner-options {
  display: grid;
  gap: 10px;
}

.runner-option {
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.runner-option strong,
.runner-option small {
  display: block;
}

.runner-option em {
  min-width: 82px;
  text-align: center;
  padding: 6px 10px;
  border-radius: 999px;
  background: #ecfdf3;
  color: var(--ok);
  font-style: normal;
  font-weight: 700;
  font-size: 13px;
}

.users-table {
  min-width: 820px;
  display: grid;
  gap: 8px;
}

.users-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(140px, 1fr) 96px 96px minmax(140px, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.users-row.users-head {
  border: 0;
  padding: 0 10px 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.users-row strong {
  display: block;
}

.login-checks {
  display: grid;
  gap: 10px;
}

.reauth-panel {
  margin-bottom: 18px;
}

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

.reauth-panel p {
  margin: 0 0 12px;
  color: var(--muted);
}

.reauth-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}

.reauth-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.reauth-action strong,
.reauth-action small {
  display: block;
}

.reauth-action small {
  color: var(--muted);
}

.login-check-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 120px minmax(280px, 2fr) minmax(150px, 1fr);
  gap: 14px;
  align-items: center;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.login-check-details {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}

.login-check-details > div {
  display: grid;
  grid-template-columns: minmax(120px, 180px) 120px minmax(260px, 1fr);
  gap: 10px;
  align-items: center;
  color: var(--muted);
}

.login-check-details .login-status {
  min-height: 26px;
  font-size: 12px;
}

.login-attention {
  display: grid;
  gap: 8px;
}

.login-attention .button {
  justify-self: start;
}

.login-check-row strong,
.login-check-row span,
.login-check-row small {
  display: block;
}

.login-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  font-style: normal;
  font-weight: 700;
  font-size: 13px;
  background: #f2f4f7;
  color: #475467;
}

.login-status-ok {
  background: #ecfdf3;
  color: var(--ok);
}

.login-status-expired {
  background: var(--danger-bg);
  color: var(--danger);
}

.login-status-unknown {
  background: #fff7e6;
  color: #b54708;
}

.login-status-missing,
.login-status-pending {
  background: #f2f4f7;
  color: #475467;
}

.row-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.remote-login-panel {
  display: grid;
  gap: 14px;
  min-width: 0;
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.remote-login-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  flex-wrap: wrap;
  min-width: 0;
}

.remote-login-toolbar > div:first-child {
  min-width: 0;
  max-width: 100%;
}

.remote-login-toolbar strong,
.remote-login-toolbar small {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.remote-login-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.remote-login-screen-wrap {
  width: 100%;
  min-width: 0;
  max-height: 78vh;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0f172a;
}

.remote-login-screen {
  display: block;
  width: 100%;
  max-width: 1280px;
  height: auto;
  aspect-ratio: 1280 / 820;
  background: #0f172a;
  margin: 0 auto;
  cursor: crosshair;
}

.remote-login-inputs {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.remote-login-message {
  min-height: 22px;
}

.image-search-result-panel {
  display: grid;
  gap: 18px;
}

.image-search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.image-search-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.image-search-card img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  background: #f8fafc;
  border-radius: 6px;
}

.image-search-card strong,
.image-search-card span,
.image-search-card small {
  display: block;
  overflow-wrap: anywhere;
}

.image-search-feedback {
  display: grid;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.image-search-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 700px) {
  .topbar {
    padding: 12px 16px;
  }

  .page {
    width: min(100% - 20px, 1120px);
    margin-top: 18px;
  }

  .section-head,
  .job-row {
    grid-template-columns: 1fr;
  }

  .section-head {
    display: grid;
  }

  .runner-switch {
    justify-items: start;
  }

  .job-meta {
    grid-template-columns: 1fr 1fr;
  }

  .log-panel #log {
    height: 62vh;
    min-height: 320px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar nav {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .admin-layout {
    grid-template-columns: 1fr;
  }

  .admin-panel {
    overflow-x: auto;
  }

  .login-check-row {
    grid-template-columns: 1fr;
  }

  .remote-login-toolbar {
    display: grid;
  }

  .remote-login-inputs {
    grid-template-columns: 1fr;
  }
}
