* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: #111827;
  background: #f6f7f9;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  overscroll-behavior-y: none;
}

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

button {
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 8px;
  padding: 9px 13px;
  cursor: pointer;
}

button:hover {
  background: #f3f4f6;
}

.primary {
  border-color: #111827;
  background: #111827;
  color: #fff;
}

.primary:hover {
  background: #020617;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #f8fafc, #eef2ff 45%, #ecfeff);
}

.login-card {
  width: min(390px, calc(100vw - 32px));
  padding: 30px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 18px 50px rgba(15, 23, 42, .08);
}

.login-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

.login-card p {
  margin: 0 0 26px;
  color: #6b7280;
}

.remember-login {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  margin-top: -2px;
}

.remember-login input {
  width: auto;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: #4b5563;
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  color: #111827;
  padding: 10px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 0 3px rgba(56, 189, 248, .16);
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 242px 1fr;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px 18px;
  background: #fff;
  border-right: 1px solid #e5e7eb;
}

.brand strong {
  display: block;
  font-size: 22px;
  line-height: 1.3;
}

.side-divider {
  height: 1px;
  background: #e5e7eb;
}

.account {
  display: grid;
  gap: 8px;
  padding: 10px;
  background: #f8fafc;
  border-radius: 8px;
}

.account span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 700;
}

.account button {
  padding: 7px 9px;
}

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

.account-actions button {
  flex: 1 1 auto;
  min-width: 70px;
}

nav {
  display: grid;
  gap: 8px;
}

nav button {
  text-align: left;
  border-color: transparent;
  background: transparent;
}

nav button.active {
  background: #111827;
  color: #fff;
}

.main {
  min-width: 0;
  padding: 24px 28px;
}

.section-tabs {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 6px;
  margin: 0 0 16px;
  padding: 5px;
  background: #e0f2fe;
  border: 1px solid #bae6fd;
  border-radius: 10px;
}

.section-tabs button {
  min-width: 118px;
  border-color: transparent;
  background: transparent;
  text-align: center;
}

.section-tabs button.active {
  background: #fff;
  border-color: #7dd3fc;
  color: #075985;
  box-shadow: 0 2px 8px rgba(14, 116, 144, .12);
}

.notice {
  margin-bottom: 14px;
  padding: 11px 13px;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
}

.notice.ok {
  background: #ecfdf5;
  color: #047857;
}

.notice.bad {
  background: #fef2f2;
  color: #b91c1c;
}

.video-workbench {
  display: grid;
  grid-template-columns: 128px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.video-workbench-main {
  min-width: 0;
}

.workspace-grid {
  position: sticky;
  top: 24px;
  display: grid;
  gap: 8px;
  margin: 0;
}

.workspace-tab {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  min-height: 38px;
  padding-inline: 12px;
  background: #fff;
}

.workspace-tab.active {
  border-color: #111827;
  box-shadow: inset 0 0 0 1px #111827;
}

.bulb {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #22c55e;
}

.bulb.processing {
  background: #eab308;
}

.bulb.failed {
  background: #ef4444;
}

.studio {
  display: grid;
  grid-template-columns: minmax(0, 780px) 310px;
  gap: 22px;
  align-items: start;
}

.studio.video {
  grid-template-columns: minmax(0, 700px) 310px;
  gap: 18px;
}

.stage-column {
  min-width: 0;
}

.stage {
  width: min(780px, 100%);
  height: min(47vh, 430px);
  min-height: 280px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #050505;
  border-radius: 10px;
  border: 1px solid #111827;
}

.stage img,
.stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #050505;
  touch-action: manipulation;
  user-select: none;
}

.asset-menu {
  position: fixed;
  z-index: 80;
  display: grid;
  grid-template-columns: repeat(2, max-content);
  gap: 8px;
  padding: 8px;
  background: #fff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  box-shadow: 0 18px 46px rgba(15, 23, 42, .18);
}

.asset-menu button {
  min-width: 94px;
  border-color: #7dd3fc;
  color: #075985;
}

.empty-output,
.failed-output,
.generating {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: #f9fafb;
}

.empty-output {
  color: #9ca3af;
}

.failed-output {
  padding: 26px;
  color: #fecaca;
  text-align: center;
}

.generating strong {
  font-size: 24px;
}

.generating span {
  color: #d1d5db;
}

.prompt-form {
  width: min(780px, 100%);
  margin-top: 16px;
  padding: 16px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .05);
}

.prompt-form textarea {
  min-height: 126px;
  resize: vertical;
  border: 0;
  box-shadow: none;
  padding: 8px;
  font-size: 15px;
}

.prompt-editor {
  position: relative;
  min-height: 126px;
}

.prompt-highlight,
.prompt-editor textarea {
  min-height: 126px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  line-height: 1.55;
}

.prompt-highlight {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 8px;
  border: 1px solid transparent;
  color: transparent;
  pointer-events: none;
  font-size: 15px;
}

.prompt-highlight mark {
  border-radius: 5px;
  background: rgba(14, 165, 233, .22);
  color: transparent;
}

.prompt-editor textarea {
  position: relative;
  z-index: 1;
  background: transparent;
  caret-color: #111827;
}

.reference-box {
  margin-bottom: 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 10px;
  background: #f8fafc;
  padding: 12px;
}

.reference-box.compact {
  color: #64748b;
  font-size: 14px;
}

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

.reference-head strong {
  font-size: 14px;
  color: #334155;
}

.upload-button {
  display: inline-flex;
  width: auto;
  margin: 0;
  border: 1px solid #111827;
  border-radius: 8px;
  background: #111827;
  color: #fff;
  padding: 8px 12px;
  cursor: pointer;
}

.upload-button.ghost {
  border-color: #cbd5e1;
  background: #fff;
  color: #111827;
}

.upload-button input {
  display: none;
}

.reference-url-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.reference-url-grid label {
  margin: 0;
}

.reference-empty {
  display: grid;
  place-items: center;
  min-height: 88px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  color: #94a3b8;
  font-size: 14px;
}

.reference-thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}

.reference-thumb {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
}

.reference-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reference-thumb span {
  position: absolute;
  left: 5px;
  bottom: 5px;
  border-radius: 999px;
  padding: 3px 7px;
  background: rgba(15, 23, 42, .76);
  color: #fff;
  font-size: 12px;
}

.reference-thumb button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(15, 23, 42, .78);
  color: #fff;
  font-size: 16px;
  line-height: 1;
}

.prompt-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  padding-top: 12px;
  border-top: 1px solid #f1f5f9;
}

.upload-chip {
  display: inline-flex;
  width: auto;
  margin: 0 auto 0 0;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  padding: 8px 12px;
  background: #f8fafc;
  cursor: pointer;
}

.upload-chip input {
  display: none;
}

.upload-hint {
  margin-right: auto;
  color: #64748b;
  font-size: 14px;
}

.params-panel {
  position: sticky;
  top: 24px;
  padding: 18px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
}

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

.check {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 9px;
}

.check input {
  width: auto;
}

.history {
  max-width: 1100px;
}

.history-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  margin-bottom: 14px;
}

.history h1,
.admin-list h1 {
  margin: 0;
  font-size: 24px;
}

.list {
  overflow: hidden;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
}

.date-row {
  padding: 9px 14px;
  background: #f8fafc;
  color: #475569;
  font-weight: 700;
}

.task-row {
  display: grid;
  grid-template-columns: 160px 145px 64px 1fr 58px 76px 82px 58px;
  gap: 12px;
  align-items: center;
  min-height: 42px;
  padding: 7px 14px;
  border-top: 1px solid #f1f5f9;
  font-size: 14px;
}

.task-row span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.task-row b {
  font-size: 13px;
}

.task-row b.completed {
  color: #059669;
}

.task-row b.failed {
  color: #dc2626;
}

.task-row b.processing,
.task-row b.queued {
  color: #ca8a04;
}

.task-row a {
  color: #2563eb;
  text-decoration: none;
}

.download-row {
  grid-template-columns: 160px 76px 180px 1fr 92px;
}

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

button.danger:hover {
  background: #fef2f2;
}

.empty-list {
  padding: 24px;
  color: #64748b;
}

.pager {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 12px;
}

.admin-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 22px;
  align-items: start;
}

.admin-list,
.admin-form {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 18px;
}

.admin-list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.admin-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px 64px 64px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid #f1f5f9;
}

.admin-row:first-of-type {
  margin-top: 12px;
}

.admin-row span,
.admin-row small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.admin-row small {
  color: #64748b;
}

.admin-form h2 {
  margin: 0 0 16px;
  font-size: 19px;
}

.admin-form textarea {
  min-height: 118px;
  font-family: Consolas, monospace;
  font-size: 13px;
}

.model-permission {
  margin: 4px 0 16px;
}

.model-permission > strong {
  display: block;
  margin-bottom: 9px;
  color: #334155;
  font-size: 14px;
}

.model-checks {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 8px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f8fafc;
}

.model-check {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 9px;
  align-items: start;
  margin: 0;
  padding: 8px;
  border-radius: 8px;
  background: #fff;
}

.model-check input {
  width: auto;
  margin-top: 3px;
}

.model-check span {
  display: grid;
  gap: 2px;
  min-width: 0;
  color: #111827;
}

.model-check small {
  color: #64748b;
}

.settings-summary {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f8fafc;
  color: #475569;
  font-size: 14px;
}

.settings-summary strong {
  color: #111827;
  font-size: 15px;
}

.settings-summary span {
  word-break: break-all;
}

.form-hint {
  margin: -2px 0 16px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.6;
}

.local-save-row {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #f8fafc;
}

.local-save-row span {
  color: #475569;
  font-size: 14px;
}

.local-save-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #111827;
  font-size: 14px;
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    gap: 10px;
  }

  nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .studio,
  .video-workbench,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .params-panel {
    position: static;
  }

  .workspace-grid {
    position: static;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .local-save-row {
    grid-template-columns: 1fr;
  }

  .reference-url-grid {
    grid-template-columns: 1fr;
  }

  .task-row {
    grid-template-columns: 1fr 80px;
  }

  .task-row span:nth-child(2),
  .task-row b {
    display: none;
  }
}

@media (max-width: 720px) {
  body {
    background: #f8fafc;
  }

  button,
  input,
  select,
  textarea {
    font-size: 16px;
  }

  button {
    min-height: 42px;
    padding: 9px 12px;
  }

  .login-shell {
    min-height: 100dvh;
    padding: 18px;
  }

  .login-card {
    width: 100%;
    padding: 24px 18px;
    border-radius: 12px;
  }

  .shell {
    min-height: 100dvh;
    display: block;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 20;
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    background: #e0f2fe;
    border-right: 0;
    border-bottom: 1px solid #bae6fd;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .05);
  }

  .brand strong {
    text-align: center;
    font-size: 24px;
    line-height: 1.25;
  }

  .side-divider {
    display: none;
  }

  .account {
    padding: 8px;
  }

  .account-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  nav {
    position: static;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(76px, 1fr);
    gap: 6px;
    overflow-x: auto;
    padding: 8px;
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    border-radius: 12px;
    -webkit-overflow-scrolling: touch;
  }

  nav button {
    min-width: 76px;
    min-height: 44px;
    padding: 8px 9px;
    text-align: center;
    border-radius: 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .main {
    padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
  }

  .section-tabs {
    width: 100%;
    grid-auto-columns: 1fr;
    margin-bottom: 12px;
  }

  .section-tabs button {
    min-width: 0;
  }

  .notice {
    margin-bottom: 10px;
  }

  .video-workbench {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .workspace-grid {
    position: static;
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(92px, 1fr);
    grid-template-columns: none;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
  }

  .workspace-tab {
    justify-content: center;
    min-height: 40px;
    padding-inline: 10px;
    white-space: nowrap;
  }

  .studio,
  .studio.video {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .stage-column {
    display: flex;
    flex-direction: column;
  }

  .stage {
    order: 2;
    width: 100%;
    height: min(78dvh, 720px);
    min-height: 520px;
    border-radius: 8px;
  }

  .params-panel {
    position: static;
    order: -1;
    padding: 14px;
    border-radius: 8px;
  }

  .params-panel h2 {
    margin-bottom: 12px;
    font-size: 16px;
  }

  .prompt-form {
    order: 1;
    width: 100%;
    margin-top: 0;
    margin-bottom: 12px;
    padding: 12px;
    border-radius: 10px;
  }

  .prompt-editor,
  .prompt-highlight,
  .prompt-editor textarea,
  .prompt-form textarea {
    min-height: 150px;
  }

  .reference-head {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .upload-button {
    justify-content: center;
  }

  .reference-thumbs {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .prompt-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .history-head {
    align-items: start;
  }

  .history h1,
  .admin-list h1 {
    font-size: 20px;
  }

  .list {
    border-radius: 8px;
  }

  .task-row {
    grid-template-columns: 1fr auto;
    gap: 8px;
    padding: 10px 12px;
  }

  .download-row {
    grid-template-columns: 1fr auto;
  }

  .task-row a,
  .task-row button {
    min-height: 36px;
    padding: 7px 9px;
    font-size: 13px;
  }

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

  .admin-list,
  .admin-form {
    padding: 14px;
    border-radius: 8px;
  }

  .admin-row {
    grid-template-columns: 1fr auto;
    gap: 8px;
  }

  .admin-row small {
    grid-column: 1 / -1;
  }

  .model-checks {
    max-height: 300px;
  }

  .local-save-row {
    grid-template-columns: 1fr;
  }
}
