:root {
  color-scheme: light;
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-muted: #eef1ef;
  --line: #d6dcd8;
  --ink: #202822;
  --muted: #68736c;
  --green: #1f6a4a;
  --green-dark: #174e38;
  --amber: #9c5b13;
  --red: #a33a35;
  --blue: #27658a;
  --shadow: 0 8px 24px rgba(28, 38, 31, .1);
  font-family: "Microsoft YaHei UI", "PingFang SC", system-ui, sans-serif;
  letter-spacing: 0;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--ink); }
body { min-width: 320px; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
[hidden] { display: none !important; }

.auth-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #e9eeea; }
.auth-panel { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 32px; box-shadow: var(--shadow); }
.product-mark { color: var(--green); font-weight: 700; margin: 0 0 28px; }
.auth-panel h1 { font-size: 26px; margin: 0 0 24px; }

label { display: grid; gap: 7px; color: #465148; font-size: 13px; font-weight: 600; }
input, textarea, select { width: 100%; border: 1px solid #c9d1cb; border-radius: 4px; background: var(--surface); color: var(--ink); padding: 10px 11px; outline: none; }
textarea { resize: vertical; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(31, 106, 74, .12); }
.auth-panel form { display: grid; gap: 16px; }

.primary, .quiet-button, .icon-button, .text-button { border: 0; border-radius: 4px; min-height: 36px; }
.primary { background: var(--green); color: white; padding: 8px 15px; font-weight: 700; }
.primary:hover { background: var(--green-dark); }
.quiet-button { background: var(--surface); color: var(--ink); border: 1px solid var(--line); padding: 7px 12px; }
.quiet-button:hover, .icon-button:hover { border-color: #aeb9b1; background: var(--surface-muted); }
.icon-button { width: 36px; height: 36px; min-width: 36px; display: inline-grid; place-items: center; background: transparent; border: 1px solid var(--line); color: var(--ink); font-size: 20px; padding: 0; }
.text-button { background: transparent; color: var(--green); padding: 8px 0; margin-top: 14px; }
.full { width: 100%; }
.form-error { min-height: 18px; color: var(--red); margin: 0; font-size: 13px; }
.form-message { color: var(--muted); font-size: 12px; }

.topbar { height: 58px; padding: 0 18px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: #202a23; color: white; border-bottom: 1px solid #303d34; }
.brand-block { display: flex; align-items: baseline; gap: 14px; min-width: 0; }
.brand-block strong { white-space: nowrap; }
.brand-block span { color: #b9c4bc; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-actions { display: flex; align-items: center; gap: 8px; }
.topbar .icon-button, .topbar .quiet-button { color: white; border-color: #536057; background: transparent; }
.connection-state { color: #bec8c1; font-size: 12px; }

.app-shell { display: grid; grid-template-columns: 232px minmax(430px, 1fr) 380px; height: calc(100vh - 58px); overflow: hidden; }
.project-rail, .production-area, .inspector { min-width: 0; min-height: 0; }
.project-rail { background: #e8ece9; border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 12px; }
.section-heading, .asset-column-heading, .dialog-heading, .inspector-heading, .stage-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-heading h2, .asset-column-heading h2 { margin: 0; font-size: 14px; text-transform: uppercase; color: #58635b; }
.project-list { margin-top: 12px; display: grid; gap: 4px; overflow-y: auto; }
.project-item { width: 100%; text-align: left; border: 0; border-left: 3px solid transparent; background: transparent; padding: 10px 9px; color: var(--ink); }
.project-item strong, .project-item span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-item span { color: var(--muted); font-size: 12px; margin-top: 3px; }
.project-item.active { background: white; border-left-color: var(--green); }
.rail-actions { margin-top: auto; padding-top: 12px; }

.production-area { overflow-y: auto; background: var(--surface); }
.empty-state { min-height: 70vh; display: grid; align-content: center; justify-items: start; max-width: 520px; margin: auto; padding: 32px; }
.empty-state h2 { margin: 0; font-size: 26px; }
.empty-state p { color: var(--muted); line-height: 1.7; }
.project-header { padding: 22px 24px 18px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
.project-header h1 { margin: 3px 0 5px; font-size: 24px; }
.project-logline { color: var(--muted); margin: 0; max-width: 720px; line-height: 1.5; }
.eyebrow { color: var(--green); font-size: 12px; font-weight: 700; margin: 0; text-transform: uppercase; }
.project-header-actions, .stage-actions, .dialog-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.view-tabs { height: 47px; display: flex; border-bottom: 1px solid var(--line); padding: 0 24px; gap: 22px; }
.view-tab { border: 0; background: transparent; color: var(--muted); padding: 0 2px; border-bottom: 3px solid transparent; }
.view-tab.active { color: var(--ink); border-bottom-color: var(--green); font-weight: 700; }
.view-panel { padding: 18px 24px 32px; }
.episode-toolbar, .job-toolbar { display: flex; justify-content: space-between; align-items: end; gap: 16px; margin-bottom: 16px; }
.episode-toolbar label { width: min(300px, 60%); }
.shot-table-header, .shot-row { display: grid; grid-template-columns: 52px minmax(140px, 1fr) 72px 92px; gap: 10px; align-items: center; }
.shot-table-header { height: 34px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); }
.shot-row { width: 100%; min-height: 64px; text-align: left; border: 0; border-bottom: 1px solid #e2e6e3; background: white; padding: 8px 0; color: var(--ink); }
.shot-row:hover { background: #f7f9f7; }
.shot-row.active { background: #edf5f0; box-shadow: inset 3px 0 var(--green); padding-left: 8px; }
.shot-title-cell strong, .shot-title-cell span { display: block; }
.shot-title-cell span { color: var(--muted); font-size: 12px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-tag { display: inline-flex; align-items: center; min-height: 25px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px; font-size: 11px; color: var(--muted); background: var(--surface); white-space: nowrap; }
.status-tag.queued { color: var(--amber); border-color: #d9b98d; }
.status-tag.running { color: var(--blue); border-color: #a5c4d6; }
.status-tag.succeeded, .status-tag.approved, .status-tag.confirmed { color: var(--green); border-color: #9bc4af; }
.status-tag.failed, .status-tag.rejected { color: var(--red); border-color: #d8aaa7; }

.asset-column-heading { margin: 12px 0 6px; }
.asset-column-heading:not(:first-child) { margin-top: 28px; }
.asset-table { border-top: 1px solid var(--line); }
.asset-row { display: grid; grid-template-columns: 160px 1fr; gap: 16px; padding: 12px 0; border-bottom: 1px solid #e2e6e3; }
.asset-row strong { font-size: 14px; }
.asset-row span { color: var(--muted); line-height: 1.5; }
.job-list { border-top: 1px solid var(--line); }
.job-row { padding: 12px 0; display: grid; grid-template-columns: 110px minmax(160px, 1fr) 100px 70px; gap: 12px; border-bottom: 1px solid #e2e6e3; align-items: center; }
.job-row code { font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.status-legend { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 12px; }
.status-legend span { display: inline-flex; align-items: center; gap: 5px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.queued { background: var(--amber); }.dot.running { background: var(--blue); }.dot.succeeded { background: var(--green); }.dot.failed { background: var(--red); }

.inspector { border-left: 1px solid var(--line); background: #f7f8f7; overflow-y: auto; }
.empty-inspector { padding: 28px 22px; color: var(--muted); }
.empty-inspector h2 { color: var(--ink); font-size: 18px; }
#shot-form { padding: 18px 20px 80px; display: grid; gap: 14px; }
.inspector-heading h2 { margin: 3px 0 0; font-size: 18px; }
.inspector-tools { display: flex; justify-content: flex-end; gap: 6px; flex-wrap: wrap; }
.inspector-tools .quiet-button { font-size: 12px; padding: 6px 8px; }
.two-fields { display: grid; grid-template-columns: 1fr 1.5fr; gap: 10px; }
.generation-stage { border-top: 1px solid var(--line); padding-top: 16px; display: grid; gap: 12px; }
.stage-heading h3 { margin: 0; font-size: 15px; }
.media-result { min-height: 0; }
.media-result img, .media-result video { width: 100%; max-height: 420px; object-fit: contain; background: #161a17; border-radius: 4px; }
.media-result .result-actions { display: flex; gap: 8px; margin-top: 8px; }
.sticky-save { position: sticky; bottom: -80px; background: rgba(247, 248, 247, .96); border-top: 1px solid var(--line); padding: 12px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; }

dialog { width: min(520px, calc(100% - 32px)); border: 1px solid var(--line); border-radius: 6px; padding: 0; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(21, 28, 23, .45); }
#entity-form { padding: 20px; }
.dialog-heading h2 { margin: 0; font-size: 19px; }
#entity-fields { display: grid; gap: 14px; margin: 18px 0; }
.dialog-actions { justify-content: flex-end; }
.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 20; display: grid; gap: 8px; width: min(360px, calc(100% - 36px)); }
.toast { background: #202a23; color: white; padding: 11px 13px; border-radius: 4px; box-shadow: var(--shadow); font-size: 13px; }
.toast.error { background: #7f2e2b; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 200px minmax(390px, 1fr) 340px; }
}

@media (max-width: 820px) {
  .topbar { height: auto; min-height: 58px; padding: 10px 12px; }
  .brand-block { display: grid; gap: 2px; }
  .connection-state { display: none; }
  .app-shell { height: auto; min-height: calc(100vh - 58px); display: block; overflow: visible; }
  .project-rail { border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; }
  .project-list { display: flex; overflow-x: auto; margin-top: 8px; }
  .project-item { min-width: 156px; border-left: 0; border-bottom: 3px solid transparent; }
  .project-item.active { border-bottom-color: var(--green); }
  .rail-actions { margin-top: 8px; padding: 0; }
  .rail-actions .full { width: auto; }
  .project-header { align-items: flex-start; padding: 18px 16px; }
  .project-header-actions { justify-content: flex-end; }
  .view-tabs { padding: 0 16px; gap: 18px; overflow-x: auto; }
  .view-panel { padding: 16px; }
  .inspector { border-left: 0; border-top: 1px solid var(--line); max-height: none; }
  #shot-form { padding: 18px 16px 72px; }
  .sticky-save { bottom: 0; }
}

@media (max-width: 520px) {
  .brand-block strong { font-size: 14px; }
  .brand-block span { max-width: 170px; }
  .topbar .quiet-button { padding: 6px 9px; }
  .project-header { display: grid; }
  .project-header-actions { justify-content: flex-start; }
  .shot-table-header, .shot-row { grid-template-columns: 40px minmax(120px, 1fr) 58px 76px; gap: 6px; }
  .shot-row { min-height: 70px; }
  .status-tag { white-space: normal; text-align: center; justify-content: center; }
  .asset-row { grid-template-columns: 105px 1fr; gap: 10px; }
  .job-row { grid-template-columns: 82px minmax(110px, 1fr) 76px; }
  .job-row code { display: none; }
  .two-fields { grid-template-columns: 1fr; }
  .stage-actions > * { flex: 1; }
}
