:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-muted: #f8fafb;
  --ink: #172028;
  --muted: #65717b;
  --line: #dce2e6;
  --line-strong: #c7d0d6;
  --brand: #126e5c;
  --brand-hover: #0d594a;
  --brand-soft: #e2f1ed;
  --accent: #b75432;
  --danger: #b52e38;
  --danger-soft: #fbe9eb;
  --warning: #9a6518;
  --warning-soft: #fff4db;
  --shadow: 0 18px 55px rgba(23, 32, 40, 0.14);
  --radius: 6px;
  font-family: Inter, "Microsoft YaHei", "PingFang SC", sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.app-shell { min-height: 100vh; }
.topbar {
  min-height: 76px; padding: 14px 24px; display: flex; align-items: center; justify-content: space-between;
  gap: 18px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
}
.brand-block { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 42px; height: 42px; display: grid; place-items: center; flex: 0 0 auto; color: white; background: var(--brand); border-radius: var(--radius); font-size: 13px; font-weight: 800; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 19px; line-height: 1.2; font-weight: 750; }
.brand-block p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.button { min-height: 38px; padding: 8px 13px; border: 1px solid transparent; border-radius: var(--radius); font-weight: 650; font-size: 13px; background: transparent; color: var(--ink); white-space: nowrap; }
.button.primary { color: white; background: var(--brand); border-color: var(--brand); }
.button.primary:hover:not(:disabled) { background: var(--brand-hover); }
.button.secondary { background: var(--surface); border-color: var(--line-strong); }
.button.secondary:hover:not(:disabled) { background: var(--surface-muted); border-color: #aab6bd; }
.button.ghost { min-height: 32px; padding: 5px 8px; color: var(--brand); }
.button.ghost:hover { background: var(--brand-soft); }
.button.danger { color: white; background: var(--danger); border-color: var(--danger); }
.button.danger-ghost { min-height: 32px; padding: 5px 8px; color: var(--danger); }
.button.danger-ghost:hover { background: var(--danger-soft); }
.button.small { min-height: 34px; padding: 6px 10px; }
.icon-button { width: 36px; height: 36px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: var(--radius); color: var(--muted); background: var(--surface); font-size: 24px; line-height: 1; }
.icon-button:hover { color: var(--ink); background: var(--surface-muted); }

main { padding: 20px 24px 40px; }
.table-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; gap: 12px; }
.summary { font-size: 13px; color: var(--muted); }
.search-field input { width: 230px; height: 38px; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--surface); padding: 8px 11px; color: var(--ink); outline: none; }
.search-field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.table-shell { position: relative; width: 100%; overflow: auto; border: 1px solid var(--line); background: var(--surface); min-height: 240px; max-height: calc(100vh - 155px); }
table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
th { position: sticky; top: 0; z-index: 5; height: 44px; padding: 9px 10px; color: #4d5962; background: #edf1f3; border-bottom: 1px solid var(--line-strong); border-right: 1px solid var(--line); font-size: 12px; text-align: left; font-weight: 750; }
td { height: 198px; padding: 8px; vertical-align: top; background: var(--surface); border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); }
tbody tr:hover td { background: #fbfcfc; }
th:last-child, td:last-child { border-right: 0; }
.col-date { width: 132px; }
.col-title { width: 165px; }
.col-orientation { width: 110px; }
.col-protagonist { width: 210px; }
.col-synopsis { width: 320px; }
.col-highlight { width: 360px; }
.col-cover { width: 130px; }
.col-actions { width: 178px; }
.cell-input, .cell-select, .cell-textarea { width: 100%; color: var(--ink); background: transparent; border: 1px solid transparent; border-radius: 4px; outline: none; }
.cell-input, .cell-select { height: 36px; padding: 7px 8px; }
.cell-textarea { height: 104px; padding: 7px 8px; resize: none; line-height: 1.55; overflow: auto; }
.cell-input:hover, .cell-select:hover, .cell-textarea:hover { border-color: var(--line); background: var(--surface); }
.cell-input:focus, .cell-select:focus, .cell-textarea:focus { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 2px var(--brand-soft); }
.row-actions { display: grid; grid-template-columns: 1fr; gap: 7px; }
.row-actions .full { grid-column: 1 / -1; }
.row-meta { margin-top: 8px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 11px; }
.highlight-cell { min-height: 180px; display: grid; grid-template-rows: 88px auto 18px; gap: 7px; }
.highlight-textarea { height: 88px; }
.highlight-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.highlight-actions .button { min-width: 0; padding-inline: 6px; font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.highlight-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.cover-box { width: 112px; height: 104px; position: relative; display: grid; place-items: center; overflow: hidden; border: 1px dashed var(--line-strong); border-radius: 4px; background: var(--surface-muted); }
.cover-box img { width: 100%; height: 100%; object-fit: cover; }
.cover-box input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.cover-box span { padding: 8px; color: var(--muted); font-size: 12px; text-align: center; }
.cover-remove { position: absolute; top: 3px; right: 3px; width: 24px; height: 24px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 4px; background: rgba(23, 32, 40, 0.76); color: white; z-index: 2; }
.empty-state { min-height: 300px; display: grid; place-content: center; justify-items: center; gap: 14px; color: var(--muted); }
.empty-state[hidden] { display: none; }

.drawer-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(23, 32, 40, 0.28); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; z-index: 50; width: min(660px, 94vw); display: flex; flex-direction: column; background: var(--surface); box-shadow: var(--shadow); transform: translateX(102%); transition: transform 180ms ease; }
.drawer.open { transform: translateX(0); }
.drawer-header { min-height: 78px; padding: 16px 18px; display: flex; justify-content: space-between; align-items: center; gap: 16px; border-bottom: 1px solid var(--line); }
.eyebrow { display: block; margin-bottom: 4px; color: var(--brand); font-size: 11px; font-weight: 800; }
.drawer-header h2, .dialog-header h2 { font-size: 19px; }
.drawer-tools { min-height: 58px; padding: 10px 18px; display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--surface-muted); border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.drawer-generate-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.drawer-content { flex: 1; overflow-y: auto; padding: 0 18px 30px; }
.drawer-empty { min-height: 260px; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); text-align: center; }
.generation-item { padding: 22px 0; border-bottom: 1px solid var(--line); }
.generation-item:last-child { border-bottom: 0; }
.generation-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.generation-head strong { display: block; font-size: 14px; }
.generation-time { margin-top: 4px; color: var(--muted); font-size: 11px; }
.mode-badge { display: inline-block; margin-left: 5px; padding: 2px 5px; border-radius: 3px; color: var(--brand); background: var(--brand-soft); font-size: 10px; vertical-align: 1px; }
.inline-actions { display: flex; align-items: center; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.content-field { display: block; margin-top: 12px; }
.content-field > span { display: flex; align-items: center; justify-content: space-between; min-height: 24px; margin-bottom: 5px; color: #4d5962; font-size: 12px; font-weight: 750; }
.content-field textarea { width: 100%; min-height: 108px; padding: 10px 11px; resize: vertical; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-muted); color: var(--ink); line-height: 1.65; outline: none; }
.content-field.prompt textarea { min-height: 230px; }
.content-field textarea:focus { border-color: var(--brand); background: white; box-shadow: 0 0 0 3px var(--brand-soft); }
.quality { font-size: 11px; font-weight: 600; color: var(--brand); }
.quality.warning { color: var(--warning); }
.video-section { margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line-strong); }
.video-section-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.video-section-head h3 { font-size: 13px; }
.video-item { padding: 10px 0; border-top: 1px solid var(--line); }
.video-item:first-of-type { border-top: 0; }
.video-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.status { color: var(--muted); font-size: 12px; }
.status.succeeded { color: var(--brand); }
.status.failed { color: var(--danger); }
.video-error { margin-bottom: 8px; color: var(--danger); font-size: 12px; line-height: 1.5; }
.video-item video { width: 100%; max-height: 340px; display: block; background: #111; border-radius: 4px; }
.video-links { margin-top: 8px; display: flex; gap: 6px; }

dialog { width: min(680px, calc(100vw - 28px)); max-height: calc(100vh - 36px); padding: 0; overflow: auto; border: 0; border-radius: var(--radius); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(23, 32, 40, 0.38); }
.dialog-header { position: sticky; top: 0; z-index: 2; padding: 16px 20px; display: flex; justify-content: space-between; align-items: center; background: var(--surface); border-bottom: 1px solid var(--line); }
.settings-section { padding: 18px 20px; border-bottom: 1px solid var(--line); }
.settings-section h3 { margin-bottom: 14px; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid label { color: #4d5962; font-size: 12px; font-weight: 650; }
.form-grid label.span-2 { grid-column: 1 / -1; }
.form-grid.single-column { grid-template-columns: 1fr; }
.form-grid input, .form-grid select { width: 100%; height: 40px; margin-top: 6px; padding: 8px 10px; color: var(--ink); background: white; border: 1px solid var(--line-strong); border-radius: 4px; outline: none; }
.form-grid input:focus, .form-grid select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.key-state { margin-top: 9px; color: var(--muted); font-size: 11px; }
.dialog-actions { padding: 14px 20px; display: flex; justify-content: flex-end; gap: 8px; background: var(--surface-muted); }
.split-actions { justify-content: space-between; }

.login-page { min-height: 100vh; background: #eef2f3; }
.login-shell { min-height: 100vh; padding: 24px; display: grid; place-items: center; }
.login-panel { width: min(420px, 100%); padding: 28px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 16px 42px rgba(23, 32, 40, 0.12); }
.login-brand { display: flex; align-items: center; gap: 12px; padding-bottom: 22px; border-bottom: 1px solid var(--line); }
.login-brand h1 { font-size: 19px; }
.login-brand p { margin-top: 4px; color: var(--muted); font-size: 12px; }
.login-form { display: grid; gap: 16px; margin-top: 22px; }
.login-form label { color: #4d5962; font-size: 12px; font-weight: 650; }
.login-form input { width: 100%; height: 44px; margin-top: 7px; padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: 4px; color: var(--ink); outline: none; }
.login-form input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.login-submit { width: 100%; min-height: 44px; margin-top: 2px; }
.form-error { padding: 10px 11px; border: 1px solid #efc8cc; border-radius: 4px; color: var(--danger); background: var(--danger-soft); font-size: 12px; line-height: 1.5; }
.form-error[hidden] { display: none; }

.users-dialog { width: min(820px, calc(100vw - 28px)); }
.user-create-grid { grid-template-columns: 1.1fr 1.4fr 0.8fr auto; align-items: end; }
.user-create-button { height: 40px; }
.users-section { padding: 18px 20px 24px; }
.users-section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.users-section-head h3 { font-size: 14px; }
.users-section-head span { color: var(--muted); font-size: 12px; }
.users-list { border-top: 1px solid var(--line); }
.user-row { min-height: 72px; padding: 12px 0; display: grid; grid-template-columns: minmax(150px, 1fr) 120px auto; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.user-identity { min-width: 0; }
.user-identity strong { display: block; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.user-meta { margin-top: 4px; color: var(--muted); font-size: 11px; }
.user-role-select { width: 100%; height: 36px; padding: 6px 8px; border: 1px solid var(--line-strong); border-radius: 4px; background: white; color: var(--ink); }
.user-row-actions { display: flex; justify-content: flex-end; gap: 4px; }
.user-status { display: inline-block; margin-left: 6px; padding: 2px 5px; border-radius: 3px; color: var(--brand); background: var(--brand-soft); font-size: 10px; }
.user-status.disabled { color: var(--danger); background: var(--danger-soft); }

.confirm-layer { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 18px; background: rgba(23, 32, 40, 0.42); }
.confirm-layer[hidden] { display: none; }
.confirm-box { width: min(420px, 100%); padding: 22px; background: white; border-radius: var(--radius); box-shadow: var(--shadow); }
.confirm-box h2 { font-size: 18px; }
.confirm-box p { margin: 12px 0 22px; color: var(--muted); line-height: 1.6; }
.confirm-box .dialog-actions { padding: 0; background: transparent; }
.toast-region { position: fixed; right: 18px; bottom: 18px; z-index: 100; width: min(360px, calc(100vw - 36px)); display: grid; gap: 8px; pointer-events: none; }
.toast { padding: 11px 13px; color: white; background: #26323a; border-radius: var(--radius); box-shadow: 0 8px 24px rgba(23, 32, 40, 0.2); font-size: 13px; line-height: 1.45; animation: toast-in 160ms ease; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }
.loading-dot { display: inline-block; width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: currentColor; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: 0.25; } }

@media (max-width: 720px) {
  .topbar { align-items: flex-start; padding: 12px 14px; }
  .brand-mark { display: none; }
  .brand-block p { display: none; }
  h1 { font-size: 16px; }
  .topbar-actions { gap: 5px; }
  .topbar-actions .button { min-height: 34px; padding: 6px 8px; font-size: 12px; }
  main { padding: 14px 12px 30px; }
  .table-toolbar { align-items: stretch; }
  .search-field { flex: 1; }
  .search-field input { width: 100%; }
  .table-shell { max-height: calc(100vh - 135px); }
  .drawer { width: 100vw; }
  .drawer-content { padding-inline: 14px; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid label.span-2 { grid-column: auto; }
  .login-shell { padding: 14px; }
  .login-panel { padding: 22px 18px; }
  .user-create-grid { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: 1fr; gap: 8px; }
  .user-row-actions { justify-content: flex-start; flex-wrap: wrap; }
}

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