:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  color: #202522;
  background: #f6f7f5;
  font-synthesis: none;
  letter-spacing: 0;
  --surface: #ffffff;
  --surface-subtle: #f7f9f7;
  --border: #dce1dc;
  --border-strong: #c9d0ca;
  --text: #202522;
  --text-muted: #68716a;
  --brand: #1f7a53;
  --brand-dark: #176342;
  --sidebar: #202622;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #f6f7f5; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.hidden { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #eef2ee;
}
.login-form {
  width: min(100%, 400px);
  padding: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 18px 44px rgba(32, 38, 34, 0.09);
}
.login-form h1 { margin: 20px 0 30px; font-size: 23px; line-height: 1.25; }
.login-form label, .field-block > label, .field-heading label { display: block; margin-bottom: 8px; font-weight: 650; font-size: 14px; }
.login-form input { width: 100%; margin-bottom: 18px; }
.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 750;
}
.brand-mark.compact { width: 36px; height: 36px; font-size: 13px; }

input, textarea, select {
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: #fff;
  color: #202321;
  outline: none;
}
input, select { height: 42px; padding: 0 12px; }
textarea { width: 100%; resize: vertical; min-height: 150px; padding: 12px; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31, 122, 83, 0.12); }

.primary-button, .quiet-button, .nav-button, .table-action {
  border: 0;
  border-radius: 6px;
  min-height: 38px;
  padding: 0 14px;
}
.primary-button { width: 100%; background: var(--brand); color: #fff; font-weight: 700; transition: background .16s, transform .16s; }
.primary-button:hover { background: var(--brand-dark); }
.primary-button:active { transform: translateY(1px); }
.primary-button:disabled { background: #9ca99f; cursor: wait; }
.quiet-button { background: #ecefeb; color: #333835; }
.quiet-button:hover { background: #e0e4df; }
.form-error { color: #a33a2b; min-height: 20px; margin: 8px 0 0; font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 232px minmax(0, 1fr); }
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 16px;
  background: var(--sidebar);
  color: #f5f6f4;
}
.brand-row { display: flex; align-items: center; gap: 11px; padding: 0 6px 26px; }
.brand-row div:last-child { min-width: 0; }
.brand-row strong, .brand-row span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-row strong { font-size: 15px; }
.brand-row span { margin-top: 2px; color: #aeb6b0; font-size: 12px; }
.nav-list { display: grid; gap: 4px; }
.nav-button { position: relative; width: 100%; min-height: 42px; text-align: left; background: transparent; color: #cbd1cc; transition: background .16s, color .16s; }
.nav-button:hover { background: #313632; color: #fff; }
.nav-button.active { background: #f0f7f2; color: var(--brand-dark); font-weight: 700; }
.nav-button.active::before { content: ""; position: absolute; left: 0; top: 11px; bottom: 11px; width: 3px; border-radius: 2px; background: var(--brand); }
.sidebar-status { display: flex; align-items: center; gap: 10px; margin-top: auto; padding: 16px 8px; border-top: 1px solid #3a403b; }
.sidebar-status strong, .sidebar-status span { display: block; }
.sidebar-status strong { font-size: 13px; }
.sidebar-status span { margin-top: 3px; color: #aeb6b0; font-size: 12px; }
.status-dot { width: 9px; height: 9px; flex: 0 0 9px; border-radius: 50%; background: #c08a28; }
.status-dot.ready { background: #4eb47c; }
.sidebar > .quiet-button { margin-top: 8px; background: #313632; color: #d8ddd9; }

.workspace { min-width: 0; padding: 0 clamp(20px, 3vw, 42px) 40px; }
.topbar { position: sticky; top: 0; z-index: 10; min-height: 78px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: rgba(246, 247, 245, 0.96); backdrop-filter: blur(10px); }
.topbar h2 { margin: 0; font-size: 21px; }
.topbar-meta { display: block; margin-top: 5px; color: #6d756f; font-size: 12px; }
.topbar-meta::before { content: ""; display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: #3fa66d; vertical-align: 1px; }
.view { display: none; padding-top: 24px; }
.view.active { display: block; }

.generate-layout { display: grid; grid-template-columns: minmax(400px, 0.92fr) minmax(420px, 1.08fr); align-items: stretch; overflow: hidden; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.generator { min-width: 0; padding: 26px 28px 24px; }
.field-block { margin-bottom: 22px; }
.field-heading { display: flex; justify-content: space-between; align-items: center; }
.field-heading span { color: #777f79; font-size: 12px; }
.upload-zone {
  min-height: 96px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  padding: 16px;
  border: 1px dashed #aeb6b0;
  border-radius: 7px;
  background: var(--surface-subtle);
  text-align: center;
  cursor: pointer;
}
.upload-zone:hover { border-color: var(--brand); background: #f1f7f3; }
.upload-zone input { display: none; }
.upload-zone strong { color: #185a3d; font-size: 14px; }
.upload-zone span { color: #777f79; font-size: 12px; }
.reference-list { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.reference-item { position: relative; aspect-ratio: 1; overflow: hidden; border: 1px solid #d5d9d5; border-radius: 6px; background: #fff; }
.reference-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.reference-item button { position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; padding: 0; border: 0; border-radius: 50%; background: rgba(25, 28, 26, 0.78); color: #fff; }
.settings-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.settings-grid label span { display: block; margin-bottom: 7px; color: #555d57; font-size: 12px; font-weight: 650; }
.settings-grid select { width: 100%; }
.toggle-row { display: inline-flex; align-items: center; gap: 9px; margin: 22px 0; cursor: pointer; font-size: 14px; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track { width: 38px; height: 22px; padding: 3px; border-radius: 11px; background: #bcc3bd; transition: background .16s; }
.toggle-track span { display: block; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .16s; }
.toggle-row input:checked + .toggle-track { background: var(--brand); }
.toggle-row input:checked + .toggle-track span { transform: translateX(16px); }
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: 16px; border-top: 1px solid #daddda; padding-top: 18px; }
.form-actions .form-error { flex: 1; margin: 0; }
.generate-button { width: auto; min-width: 128px; }

.result-pane { min-width: 0; border-left: 1px solid var(--border); padding: 26px 28px 24px; background: #fbfcfb; }
.result-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.result-header h3 { margin: 0; font-size: 15px; }
.status-badge { display: inline-flex; align-items: center; min-height: 26px; padding: 0 9px; border-radius: 13px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.status-badge.neutral { background: #ecefeb; color: #626963; }
.status-badge.queued, .status-badge.running { background: #fff0cf; color: #785512; }
.status-badge.succeeded, .status-badge.ready { background: #e1f3e7; color: #17603e; }
.status-badge.failed, .status-badge.exhausted, .status-badge.disabled { background: #f8e2de; color: #913426; }
.status-badge.used { background: #e8ece8; color: #555d57; }
.result-stage { min-height: 430px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; align-content: center; border: 1px solid var(--border); border-radius: 7px; background: #edf0ed; overflow: hidden; }
.result-stage.empty { place-items: center; color: #7b837d; font-size: 13px; }
.result-stage img { width: 100%; height: 100%; min-height: 260px; max-height: 680px; object-fit: contain; background: #171a18; }
.job-meta { display: grid; gap: 4px; margin-top: 10px; color: #666e68; font-size: 12px; overflow-wrap: anywhere; }

.table-wrap { position: relative; overflow: auto; border: 1px solid var(--border); border-radius: 7px; background: var(--surface); }
table { width: 100%; min-width: 860px; border-collapse: separate; border-spacing: 0; font-size: 13px; }
th, td { padding: 13px 14px; border-bottom: 1px solid #e4e7e4; text-align: left; vertical-align: middle; }
th { position: sticky; top: 0; z-index: 2; color: #687069; font-size: 12px; font-weight: 700; background: #f3f6f3; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #f8faf8; }
#view-history table { min-width: 920px; table-layout: fixed; }
#view-history th:first-child, #view-history td:first-child { width: 80px; }
#view-history th:nth-child(2), #view-history td:nth-child(2) { width: 23%; }
#view-history th:nth-child(3), #view-history td:nth-child(3) { width: 188px; }
#view-history th:nth-child(4), #view-history td:nth-child(4) { width: 58px; text-align: center; }
#view-history th:nth-child(5), #view-history td:nth-child(5) { width: 118px; }
#view-history th:nth-child(6), #view-history td:nth-child(6) { width: 80px; }
#view-history th:nth-child(7), #view-history td:nth-child(7) { width: 14%; }
#view-history th:last-child, #view-history td:last-child { width: 66px; text-align: right; }
#view-history .params-cell { min-width: 0; }
#view-history .detail-cell { min-width: 0; max-width: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td { background: #fff; }
.prompt-cell { max-width: 440px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.params-cell { min-width: 190px; display: grid; gap: 3px; }
.params-cell strong { color: #303531; font-size: 12px; }
.params-cell span { color: #687069; font-size: 12px; white-space: nowrap; }
.duration-cell { min-width: 82px; white-space: nowrap; }
.error-cell { max-width: 320px; color: #8a3a2f; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-action { min-height: 30px; padding: 0 9px; background: #ecefeb; color: #333835; font-size: 12px; white-space: nowrap; }
.empty-table { padding: 48px; background: #fff; color: #777f79; text-align: center; }
.account-summary { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 10px; margin-bottom: 18px; }
.account-toolbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.account-toolbar .account-summary { flex: 1; }
.account-actions { display: flex; align-items: center; gap: 8px; }
.account-register-button { width: auto; min-width: 112px; }
.danger-button { color: #94392c; background: #f5e8e5; white-space: nowrap; }
.danger-button:hover { color: #7e2e23; background: #efd8d3; }
.action-status { min-height: 20px; margin: -8px 0 12px; color: #17603e; font-size: 13px; }
.action-status.error { color: #913426; }
.summary-item { min-width: 0; padding: 13px 14px; border: 1px solid var(--border); border-top: 3px solid var(--brand); border-radius: 6px; background: var(--surface); }
.summary-item:nth-child(2) { border-top-color: #c18a2f; }
.summary-item:nth-child(3) { border-top-color: #4e7294; }
.summary-item:nth-child(4) { border-top-color: #6d6f8f; }
.summary-item:nth-child(5) { border-top-color: #8a6b52; }
.summary-item strong, .summary-item span { display: block; }
.summary-item strong { font-size: 18px; }
.summary-item span { margin-top: 3px; color: #737b75; font-size: 12px; }
.runtime-alert { margin-bottom: 24px; padding: 12px 14px; border-left: 3px solid #b43f30; background: #fae9e5; color: #7f2e24; font-size: 13px; line-height: 1.5; }
.section-heading { min-height: 52px; display: flex; align-items: flex-start; justify-content: space-between; }
.section-heading h3 { margin: 0; font-size: 15px; }
.section-heading span { display: block; margin-top: 4px; color: #737b75; font-size: 12px; }
.section-heading.log-heading { margin-top: 28px; }
.log-filter { width: 128px; flex: 0 0 128px; }
.id-cell { width: 210px; max-width: 210px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: Consolas, monospace; font-size: 12px; }
.detail-cell { min-width: 260px; max-width: 520px; color: #5f6761; overflow-wrap: anywhere; line-height: 1.45; }
.log-table-wrap { height: min(58vh, 620px); min-height: 360px; overflow: auto; }
.log-table th { white-space: nowrap; }
.log-time { width: 120px; white-space: nowrap; color: #646c66; }
.log-object { display: inline-block; min-width: 104px; color: #454c47; font-family: Consolas, monospace; font-size: 12px; white-space: nowrap; }
.log-message { min-width: 360px; color: #454c47; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.log-level { display: inline-flex; min-width: 68px; justify-content: center; padding: 4px 7px; border-radius: 4px; background: #e8ece8; color: #555d57; font-size: 11px; font-weight: 700; white-space: nowrap; }
.log-level.warning { background: #fff0cf; color: #785512; }
.log-level.error, .log-level.critical { background: #f8e2de; color: #913426; }
.log-level.task_started, .log-level.task_succeeded, .log-level.account_registered { background: #e1f3e7; color: #17603e; }
.log-level.account_used { background: #e8ece8; color: #555d57; }
.configuration-form { width: min(100%, 860px); }
.configuration-form + .configuration-form { margin-top: 48px; }
.configuration-heading { min-height: 68px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; border-bottom: 1px solid #cfd4cf; }
.configuration-heading h3 { margin: 0; font-size: 16px; }
.configuration-heading > div > span { display: block; margin-top: 5px; color: #737b75; font-size: 12px; }
.config-status { display: inline-flex; min-height: 28px; align-items: center; padding: 0 10px; border-radius: 14px; background: #f8e2de; color: #913426; font-size: 12px; font-weight: 700; }
.config-status.configured { background: #e1f3e7; color: #17603e; }
.configuration-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px 14px; padding: 24px 0; }
.configuration-field { min-width: 0; }
.configuration-field.wide { grid-column: 1 / -1; }
.configuration-field > span { display: block; margin-bottom: 7px; color: #555d57; font-size: 12px; font-weight: 650; }
.configuration-field input, .configuration-field select, .configuration-field textarea { width: 100%; }
.key-input-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.copy-key-button { min-width: 92px; white-space: nowrap; }
.configuration-prompt { min-height: 108px; }
.configuration-actions { display: flex; min-height: 64px; align-items: center; justify-content: flex-end; gap: 16px; border-top: 1px solid #cfd4cf; }
.configuration-actions > span { flex: 1; color: #17603e; font-size: 13px; }
.configuration-actions > span.error { color: #913426; }
.configuration-save { width: auto; min-width: 120px; }

@media (max-width: 1080px) {
  .generate-layout { grid-template-columns: 1fr; }
  .result-pane { border-left: 0; border-top: 1px solid var(--border); }
  .account-summary { grid-template-columns: repeat(3, minmax(120px, 1fr)); }
}
@media (max-width: 760px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: sticky; top: 0; z-index: 20; height: auto; display: grid; grid-template-columns: 36px minmax(0, 1fr) 58px; align-items: center; gap: 9px; padding: 9px 10px; }
  .brand-row { padding: 0; }
  .brand-row > div:last-child { display: none; }
  .brand-mark.compact { width: 36px; height: 36px; }
  .nav-list { display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none; }
  .nav-list::-webkit-scrollbar { display: none; }
  .nav-button { min-width: max-content; min-height: 36px; padding: 0 10px; text-align: center; font-size: 13px; }
  .nav-button.active::before { left: 10px; right: 10px; top: auto; bottom: 2px; width: auto; height: 2px; }
  .sidebar-status { display: none; }
  .sidebar > .quiet-button { width: 58px; min-height: 36px; margin: 0; padding: 0 5px; font-size: 11px; white-space: nowrap; }
  .workspace { padding: 0 16px 26px; }
  .topbar { top: 54px; min-height: 66px; }
  .topbar h2 { font-size: 19px; }
  .view { padding-top: 18px; }
  .generator, .result-pane { padding: 20px 18px; }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .reference-list { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .result-stage { min-height: 300px; grid-template-columns: 1fr; }
  .form-actions { align-items: stretch; flex-direction: column; }
  .generate-button { width: 100%; }
  .configuration-grid { grid-template-columns: 1fr; }
  .configuration-field.wide { grid-column: auto; }
  .key-input-row { grid-template-columns: 1fr; }
  .copy-key-button { width: 100%; }
  .configuration-actions { align-items: stretch; flex-direction: column; padding-top: 16px; }
  .configuration-save { width: 100%; }
  .account-toolbar { align-items: stretch; flex-direction: column; }
  .account-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .account-actions { width: 100%; }
  .account-actions > button { flex: 1; width: auto; }
  .action-status { margin-top: 0; }
  .section-heading { gap: 12px; }
  .log-filter { width: 116px; flex-basis: 116px; }
  .login-form { padding: 30px 24px; }
}

@media (max-width: 420px) {
  .sidebar { grid-template-columns: 34px minmax(0, 1fr) 54px; gap: 6px; }
  .nav-button { padding: 0 8px; }
  .sidebar > .quiet-button { width: 54px; }
  .reference-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .account-summary { grid-template-columns: 1fr 1fr; }
}
