:root {
  --color-primary: #2563eb;
  --color-secondary: #3b82f6;
  --color-accent: #f97316;
  --color-background: #f8fafc;
  --color-foreground: #1e293b;
  --color-muted: #526079;
  --color-border: #dbe3ef;
  --color-success: #078a55;
  --color-danger: #dc2626;
  --color-warning: #b45309;
  --surface: #ffffff;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-md: 0 5px 16px rgba(15, 23, 42, .08);
  --radius-sm: 8px;
  --radius-md: 12px;
  --space-xs: 2px;
  --space-sm: 4px;
  --space-md: 8px;
  --space-lg: 12px;
  --space-xl: 16px;
  --space-2xl: 24px;
  --space-3xl: 32px;
  font-family: Inter, "Microsoft YaHei UI", "PingFang SC", system-ui, -apple-system, sans-serif;
  color: var(--color-foreground);
  background: var(--color-background);
  font-synthesis: none;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--color-background); }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--color-background); color: var(--color-foreground); font-size: 16px; line-height: 1.5; }
button, input, textarea { font: inherit; }
button, a, input[type="file"] { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button, a, [role="button"] { cursor: pointer; }
a { color: var(--color-primary); text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 3px; font-size: clamp(1.65rem, 2.5vw, 2rem); line-height: 1.25; letter-spacing: -.025em; }
h2 { margin-bottom: 0; font-size: 1rem; line-height: 1.4; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 3px solid rgba(37, 99, 235, .32); outline-offset: 2px; }

.topbar {
  position: sticky; top: 0; z-index: 30; min-height: 64px; padding: 0 24px; display: flex; align-items: stretch; gap: 28px;
  background: rgba(255, 255, 255, .92); border-bottom: 1px solid var(--color-border); box-shadow: var(--shadow-sm); backdrop-filter: blur(14px);
}
.brand { display: inline-flex; align-items: center; min-height: 64px; color: var(--color-primary); font-size: 1.25rem; font-weight: 800; letter-spacing: -.02em; white-space: nowrap; }
.main-nav { display: flex; align-items: stretch; gap: 4px; flex: 1; }
.main-nav a, .nav-logout { min-height: 64px; padding: 0 15px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; color: #334155; background: transparent; border: 0; border-bottom: 3px solid transparent; font-size: .95rem; font-weight: 600; transition: color 180ms ease, background 180ms ease, border-color 180ms ease; }
.main-nav a:hover, .nav-logout:hover { color: var(--color-primary); background: rgba(37, 99, 235, .05); }
.main-nav a[aria-current="page"] { color: var(--color-primary); border-bottom-color: var(--color-primary); }
.logout-form { margin-left: auto; }
.nav-toggle { display: none; }
.icon-button { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; color: var(--color-foreground); border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--surface); transition: color 180ms ease, border-color 180ms ease, background 180ms ease; }
.icon-button:hover { color: var(--color-primary); border-color: var(--color-primary); background: #eff6ff; }
.nav-toggle { display: none; }

.page-shell { width: 100%; max-width: 1680px; margin: 0 auto; padding: 22px 24px 42px; }
.page-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.page-heading p { margin-bottom: 0; color: var(--color-muted); }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(290px, 370px); gap: 18px; align-items: start; }
.workspace { min-width: 0; }

.button { min-height: 44px; padding: 10px 18px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: var(--radius-sm); font-size: .95rem; font-weight: 700; line-height: 1.2; white-space: nowrap; transition: transform 180ms ease, box-shadow 180ms ease, color 180ms ease, background 180ms ease, border-color 180ms ease, opacity 180ms ease; }
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.button svg { width: 19px; height: 19px; }
.button-primary { color: #fff; background: var(--color-accent); border-color: var(--color-accent); box-shadow: 0 3px 9px rgba(249, 115, 22, .22); }
.button-primary:hover { background: #ea580c; border-color: #ea580c; }
.button-outline { color: var(--color-primary); background: var(--surface); border-color: var(--color-primary); }
.button-outline:hover { background: #eff6ff; }
.button-quiet { color: #334155; background: #f1f5f9; border-color: #e2e8f0; }
.button-quiet:hover { background: #e2e8f0; }
.button-danger { color: var(--color-danger); background: #fff; border-color: #fca5a5; }
.button-danger:hover { background: #fef2f2; }
.button-small { min-height: 44px; padding: 8px 12px; font-size: .86rem; }

.command-surface { margin-bottom: 16px; padding: 16px; border: 1px solid rgba(219, 227, 239, .9); border-radius: var(--radius-md); background: rgba(255, 255, 255, .78); box-shadow: var(--shadow-md); backdrop-filter: blur(12px); }
.worker-brief { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding-bottom: 13px; }
.worker-state { margin: 4px 0 0; display: flex; align-items: center; gap: 8px; font-weight: 700; }
.worker-state span { width: 10px; height: 10px; border-radius: 50%; background: #94a3b8; box-shadow: 0 0 0 4px rgba(148, 163, 184, .15); }
.worker-state.is-online { color: var(--color-success); }
.worker-state.is-online span { background: #10b981; box-shadow: 0 0 0 4px rgba(16, 185, 129, .14); }
.worker-state.is-offline { color: #64748b; }
.worker-detail { margin: 0; color: var(--color-muted); text-align: right; font-size: .88rem; }
.command-buttons { display: grid; grid-template-columns: minmax(150px, 1.3fr) repeat(4, minmax(116px, 1fr)); gap: 10px; }

.summary-grid { margin-bottom: 16px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--color-border); border-radius: var(--radius-md); overflow: hidden; background: var(--surface); box-shadow: var(--shadow-sm); }
.summary-grid article { min-height: 102px; padding: 15px 17px; position: relative; display: flex; flex-direction: column; justify-content: center; border-right: 1px solid var(--color-border); }
.summary-grid article:last-child { border-right: 0; }
.summary-grid span { color: var(--color-muted); font-size: .88rem; font-weight: 600; }
.summary-grid strong { margin-top: 2px; font-size: 1.8rem; line-height: 1.15; }
.summary-grid svg { position: absolute; top: 17px; right: 15px; width: 28px; height: 28px; color: var(--color-primary); opacity: .85; }
.summary-grid .summary-success svg { color: var(--color-success); }
.summary-grid .summary-failed svg { color: var(--color-danger); }

.progress-panel, .data-panel, .log-rail { border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); }
.progress-panel { margin-bottom: 16px; padding: 16px; }
.preview-panel { margin-bottom: 16px; }
.section-heading { min-height: 44px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading > span { color: var(--color-primary); font-weight: 750; }
.section-heading a { min-height: 44px; padding: 8px 0; display: inline-flex; align-items: center; font-weight: 650; }
.progress-track { height: 10px; margin: 9px 0 10px; overflow: hidden; border-radius: 999px; background: #e8eef7; }
.progress-track span { height: 100%; display: block; border-radius: inherit; background: var(--color-primary); transition: width 260ms ease; }
.progress-meta { display: flex; justify-content: space-between; gap: 16px; color: var(--color-muted); font-size: .86rem; }
.data-panel > .section-heading { padding: 7px 16px; border-bottom: 1px solid var(--color-border); }
.page-panel { margin-bottom: 18px; }

.task-table-wrap { width: 100%; overflow-x: auto; }
.task-table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.task-table th { padding: 11px 13px; color: #475569; background: #f8fafc; border-bottom: 1px solid var(--color-border); font-size: .82rem; text-align: left; letter-spacing: .01em; }
.task-table th:nth-child(1) { width: 24%; }
.task-table th:nth-child(2) { width: 42%; }
.task-table th:nth-child(3) { width: 14%; }
.task-table th:nth-child(4) { width: 20%; }
.task-table td { padding: 12px 13px; vertical-align: top; border-bottom: 1px solid var(--color-border); overflow-wrap: anywhere; }
.task-table tr:last-child td { border-bottom: 0; }
.task-table tbody tr { transition: background 180ms ease; }
.task-table tbody tr:hover { background: #f8fbff; }
.task-table td > strong { display: block; margin-bottom: 5px; font-size: .92rem; }
.cell-meta { display: block; color: var(--color-muted); font-size: .8rem; line-height: 1.55; }
.copy-description { margin: 0 0 4px; color: #334155; display: -webkit-box; overflow: hidden; -webkit-line-clamp: 3; -webkit-box-orient: vertical; font-size: .84rem; line-height: 1.55; }
.edited-note { color: var(--color-primary); font-size: .75rem; font-weight: 700; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.status { width: fit-content; min-height: 28px; padding: 4px 9px; display: inline-flex; align-items: center; border-radius: 7px; color: #334155; background: #eef2f7; font-size: .8rem; font-weight: 750; white-space: nowrap; }
.status-pending, .status-ready, .status-queued { color: #1d4ed8; background: #dbeafe; }
.status-running, .status-publishing, .status-rewriting { color: #075985; background: #e0f2fe; }
.status-published, .status-completed, .status-success, .status-online { color: #047857; background: #d1fae5; }
.status-failed, .status-offline, .status-logged_out { color: #b91c1c; background: #fee2e2; }
.status-paused { color: #92400e; background: #fef3c7; }
.validation-error { display: block; margin-top: 6px; color: var(--color-danger); font-size: .76rem; line-height: 1.4; }
.empty-row td, .empty-state { padding: 34px 16px; color: var(--color-muted); text-align: center; }

.log-rail { position: sticky; top: 82px; max-height: calc(100vh - 105px); overflow: hidden; }
.log-rail > .section-heading { padding: 7px 16px; border-bottom: 1px solid var(--color-border); }
.log-list { max-height: calc(100vh - 168px); margin: 0; padding: 8px 14px 14px; overflow-y: auto; list-style: none; }
.log-list li { padding: 11px 0 11px 16px; display: grid; grid-template-columns: 64px 1fr; gap: 10px; position: relative; border-bottom: 1px solid #edf2f7; }
.log-list li::before { content: ""; width: 8px; height: 8px; position: absolute; top: 17px; left: 0; border-radius: 50%; background: var(--color-primary); }
.log-list li.log-error::before { background: var(--color-danger); }
.log-list li.log-warning::before { background: #f59e0b; }
.log-list time { color: var(--color-muted); font-variant-numeric: tabular-nums; font-size: .78rem; }
.log-list strong { color: var(--color-primary); font-size: .76rem; text-transform: uppercase; }
.log-list .log-error strong { color: var(--color-danger); }
.log-list .log-warning strong { color: var(--color-warning); }
.log-list p { margin: 3px 0; font-size: .84rem; line-height: 1.48; overflow-wrap: anywhere; }
.log-list div > span { color: var(--color-muted); font-size: .72rem; }
.log-screenshot { width: min(240px, 100%); margin-top: 8px; display: block; }
.log-screenshot img { width: 100%; max-height: 180px; display: block; object-fit: contain; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: #f8fafc; }
.screenshot-reference { display: block; margin-top: 5px; overflow-wrap: anywhere; }
.log-list .empty-log { display: block; padding: 28px 4px; color: var(--color-muted); text-align: center; }
.log-list .empty-log::before { display: none; }
.full-log-list { max-height: none; padding: 8px 18px; }
.full-log-list li { grid-template-columns: 190px 1fr; }

.entity-list article { min-height: 66px; padding: 10px 16px; display: grid; grid-template-columns: minmax(220px, 1fr) 120px minmax(180px, .8fr); align-items: center; gap: 16px; border-bottom: 1px solid var(--color-border); }
.entity-list article:last-child { border-bottom: 0; }
.entity-list article > div { display: flex; flex-direction: column; }
.entity-list article span { color: var(--color-muted); font-size: .84rem; }
.entity-list article .status { color: inherit; font-size: .8rem; }

.image-preview-grid { padding: 14px 16px 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.image-preview-grid.compact { padding: 8px 0 0; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); }
.image-preview-grid figure { min-width: 0; margin: 0; overflow: hidden; border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: #f8fafc; }
.image-preview-grid img { width: 100%; aspect-ratio: 1; display: block; object-fit: cover; }
.image-preview-grid figcaption { padding: 6px 8px; overflow: hidden; color: var(--color-muted); font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
.image-preview-grid > .empty-state { grid-column: 1 / -1; margin: 0; }

.account-card-grid { padding: 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.account-card { padding: 15px; border: 1px solid var(--color-border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.account-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.account-card-heading > div { min-width: 0; display: grid; }
.account-card-heading > div span { overflow: hidden; color: var(--color-muted); font-size: .8rem; text-overflow: ellipsis; white-space: nowrap; }
.account-card dl { margin: 14px 0 10px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.account-card dl div { padding: 8px; border-radius: var(--radius-sm); background: #f8fafc; }
.account-card dt { color: var(--color-muted); font-size: .75rem; }
.account-card dd { margin: 1px 0 0; font-size: 1.05rem; font-weight: 750; }
.account-error { min-height: 24px; margin: 0 0 10px; color: var(--color-muted); font-size: .8rem; overflow-wrap: anywhere; }
.account-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; }

.input { width: 100%; min-height: 44px; padding: 10px 13px; color: var(--color-foreground); background: var(--surface); border: 1px solid #cbd5e1; border-radius: var(--radius-sm); font-size: 1rem; transition: border-color 180ms ease, box-shadow 180ms ease; }
.input:hover { border-color: #94a3b8; }
.input:focus { border-color: var(--color-primary); outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, .14); }
textarea.input { resize: vertical; line-height: 1.55; }
.stack-form, .settings-form { display: grid; gap: 12px; }
.stack-form label, .settings-form label, .modal label, .modal legend { font-size: .88rem; font-weight: 700; }
.form-help { margin: 0; color: var(--color-muted); font-size: .82rem; }
.form-divider { display: block; margin: 7px 0; color: var(--color-muted); font-size: .8rem; text-align: center; }
.settings-form { gap: 0; }
.settings-grid { padding: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.settings-grid label { display: grid; gap: 7px; }
.settings-form > .form-help { padding: 0 18px 18px; }

.modal { width: min(590px, calc(100vw - 28px)); max-height: calc(100vh - 28px); margin: auto; padding: 0; color: var(--color-foreground); border: 0; border-radius: 16px; box-shadow: 0 24px 60px rgba(15, 23, 42, .28); }
.modal::backdrop { background: rgba(15, 23, 42, .52); backdrop-filter: blur(4px); }
.modal form { padding: 22px; display: grid; gap: 10px; }
.modal fieldset { margin: 3px 0; padding: 12px; border: 1px solid var(--color-border); border-radius: var(--radius-sm); }
.modal fieldset .input { margin-top: 5px; }
.modal-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-heading h2 { font-size: 1.2rem; }
.modal-heading p { margin: 3px 0 0; color: var(--color-muted); font-size: .84rem; }
.modal-actions { margin-top: 8px; display: flex; justify-content: flex-end; gap: 9px; }

.toast-region { position: fixed; z-index: 80; right: 18px; bottom: 18px; display: grid; gap: 8px; pointer-events: none; }
.toast { max-width: min(390px, calc(100vw - 36px)); padding: 12px 15px; color: #fff; background: #334155; border-radius: var(--radius-sm); box-shadow: var(--shadow-md); animation: toast-in 180ms ease-out; }
.toast.toast-error { background: #b91c1c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.login-page { min-height: 100vh; padding: 24px; display: grid; place-items: center; background: #eef5ff; }
.login-panel { width: min(430px, 100%); padding: 34px; border: 1px solid rgba(255, 255, 255, .8); border-radius: 16px; background: rgba(255, 255, 255, .9); box-shadow: 0 20px 52px rgba(30, 64, 175, .13); backdrop-filter: blur(14px); }
.login-panel h1 { text-align: center; }
.login-panel > p { margin-bottom: 24px; color: var(--color-muted); text-align: center; }
.login-mark { width: 52px; height: 52px; margin: 0 auto 14px; display: grid; place-items: center; color: #fff; background: var(--color-primary); border-radius: 13px; }
.login-mark svg { width: 28px; height: 28px; }
.alert { margin-bottom: 16px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: .9rem; }
.alert-error { color: #991b1b; background: #fee2e2; border: 1px solid #fecaca; }
.alert-success { color: #166534; background: #dcfce7; border: 1px solid #bbf7d0; }

@media (max-width: 1120px) {
  .dashboard-grid { grid-template-columns: 1fr; }
  .log-rail { position: static; max-height: none; }
  .log-list { max-height: 430px; }
  .main-nav a, .nav-logout { padding-inline: 10px; }
  .main-nav svg { display: none; }
}

@media (max-width: 760px) {
  .topbar { min-height: 64px; padding: 0 16px; align-items: center; justify-content: space-between; }
  .brand { min-height: 62px; font-size: 1.18rem; }
  .nav-toggle { display: inline-flex; }
  .main-nav { display: none; position: absolute; top: 64px; right: 12px; left: 12px; padding: 8px; flex-direction: column; align-items: stretch; gap: 2px; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: rgba(255, 255, 255, .98); box-shadow: var(--shadow-md); }
  .main-nav.is-open { display: flex; }
  .main-nav a, .nav-logout { width: 100%; min-height: 48px; padding: 0 13px; justify-content: flex-start; border: 0; border-radius: 7px; }
  .main-nav svg { display: block; }
  .main-nav a[aria-current="page"] { background: #eff6ff; }
  .logout-form { margin: 0; }
  .page-shell { padding: 18px 14px 34px; }
  .page-heading { align-items: flex-start; }
  .page-heading > .button { flex: 0 0 auto; }
  .command-surface { padding: 14px; }
  .worker-brief { align-items: flex-start; }
  .worker-detail { max-width: 48%; }
  .command-buttons { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .command-buttons .button-primary { grid-column: 1 / -1; }
  .command-buttons .button:last-child { grid-column: 1 / -1; }
  .summary-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary-grid article { min-height: 92px; border-bottom: 1px solid var(--color-border); }
  .summary-grid article:nth-child(2) { border-right: 0; }
  .summary-grid article:nth-child(n+3) { border-bottom: 0; }
  .progress-meta { flex-direction: column; gap: 2px; }
  .task-table-wrap { overflow: visible; }
  .task-table, .task-table tbody { display: block; }
  .task-table thead { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
  .task-table tr { padding: 0 14px; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(112px, .7fr); column-gap: 14px; border-bottom: 1px solid var(--color-border); }
  .task-table tr:last-child { border-bottom: 0; }
  .task-table td { padding: 13px 0; display: block; border: 0; }
  .task-table td::before { content: attr(data-label); margin-bottom: 5px; display: block; color: var(--color-muted); font-size: .72rem; font-weight: 700; }
  .task-table td:nth-child(2) { grid-column: 1 / -1; border-top: 1px dashed #e2e8f0; }
  .task-table td:nth-child(3) { grid-column: 1; }
  .task-table td:nth-child(4) { grid-column: 2; grid-row: 3; }
  .row-actions { justify-content: flex-end; }
  .row-actions .button { width: 100%; }
  .empty-row { display: block !important; }
  .empty-row td { display: block; }
  .full-log-list li { grid-template-columns: 1fr; gap: 2px; }
  .entity-list article { grid-template-columns: 1fr auto; gap: 7px 12px; }
  .entity-list article > span:last-child { grid-column: 1 / -1; }
  .settings-grid { grid-template-columns: 1fr; }
  .account-card-grid { grid-template-columns: 1fr; }
}

@media (max-width: 460px) {
  h1 { font-size: 1.55rem; }
  .page-heading { flex-wrap: wrap; }
  .page-heading [data-open-upload] { width: 100%; order: 2; }
  .worker-brief { flex-direction: column; gap: 5px; }
  .worker-detail { max-width: none; text-align: left; }
  .command-buttons { grid-template-columns: 1fr 1fr; }
  .button { padding-inline: 12px; }
  .summary-grid article { padding-inline: 14px; }
  .summary-grid strong { font-size: 1.55rem; }
  .summary-grid svg { width: 24px; height: 24px; }
  .modal form { padding: 18px; }
  .modal-actions .button { flex: 1; }
  .login-page { padding: 14px; }
  .login-panel { padding: 28px 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
