:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --surface-soft: #eef4f8;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e1e8;
  --brand: #d71920;
  --brand-dark: #a90f16;
  --teal: #087f8c;
  --green: #168251;
  --amber: #b7791f;
  --danger: #c0392b;
  --shadow: 0 18px 45px rgba(20, 34, 50, 0.09);
  --radius: 8px;
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

body.auth-pending .app-shell,
body.auth-locked .app-shell {
  display: none;
}

body.auth-ready .login-screen {
  display: none;
}

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

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 20px;
  background: #121820;
}

.login-card {
  display: grid;
  width: min(420px, 100%);
  gap: 16px;
  padding: 26px;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.28);
}

.login-brand {
  margin-bottom: 4px;
  color: var(--ink);
}

.login-brand span {
  color: var(--muted);
}

.login-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 13px;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  color: #fff;
  background: #121820;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  margin-bottom: 28px;
}

.brand-mark {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--brand);
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 4px;
  color: #aab4c0;
  font-size: 12px;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  color: #d9e1e8;
  background: transparent;
  text-align: left;
}

.nav-parent b {
  margin-left: auto;
  color: #93a4b7;
  font-size: 13px;
}

.nav-item span {
  display: grid;
  width: 22px;
  place-items: center;
  color: #93a4b7;
  font-weight: 700;
}

.nav-item:hover,
.nav-item.active {
  color: #fff;
  background: #252f3b;
}

.nav-item.active span {
  color: #ffce6a;
}

.nav-submenu {
  display: none;
  gap: 6px;
  margin: -2px 0 8px 33px;
}

.nav-submenu.open {
  display: grid;
}

.nav-subitem {
  min-height: 36px;
  padding: 0 12px;
  border: 0;
  border-radius: var(--radius);
  color: #b8c5d2;
  background: transparent;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
}

.nav-subitem:hover,
.nav-subitem.active {
  color: #fff;
  background: #1f2935;
}

.workspace {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 0;
  font-size: 17px;
}

.topbar-actions,
.toolbar,
.report-actions,
.subnav {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: #314255;
  background: #fff;
  font-size: 13px;
  font-weight: 750;
}

.permission-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.subnav {
  margin: 4px 0 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.subnav-item {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: #314255;
  background: #fff;
  font-weight: 750;
}

.subnav-item:hover,
.subnav-item.active {
  color: #fff;
  border-color: var(--teal);
  background: var(--teal);
}

.operation-panel {
  display: none;
}

.operation-panel.active {
  display: block;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 128px;
  padding: 18px;
  border-top: 4px solid var(--teal);
}

.metric-card.alert {
  border-top-color: var(--danger);
}

.metric-card span,
.metric-card small,
.panel-heading span {
  color: var(--muted);
}

.metric-card span {
  display: block;
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin: 12px 0 8px;
  font-size: 28px;
  line-height: 1.1;
}

.dashboard-layout,
.report-grid,
.operations-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(320px, 0.8fr);
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  padding: 16px;
}

.panel-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.panel-heading span {
  align-self: end;
  font-size: 13px;
  white-space: nowrap;
}

.chart-panel canvas {
  display: block;
  width: 100%;
  height: 320px;
}

.todo-list,
.reason-list {
  display: grid;
  gap: 10px;
}

.todo-item,
.reason-item {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  min-height: 50px;
  padding: 12px;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.todo-item strong,
.reason-item strong {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
}

.todo-item span,
.reason-item span {
  color: var(--muted);
  font-size: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  color: #0f1720;
  background: #e7edf3;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.green {
  color: #0d5135;
  background: #dff4e9;
}

.badge.amber {
  color: #66420f;
  background: #faefd9;
}

.badge.red {
  color: #7c1f17;
  background: #fde3df;
}

.badge.blue {
  color: #0b4c68;
  background: #dff1f6;
}

.toolbar {
  margin-bottom: 14px;
}

.toolbar.compact {
  justify-content: flex-end;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 280px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
}

select,
input,
textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

select,
input {
  padding: 0 11px;
}

textarea {
  min-height: 78px;
  padding: 10px 11px;
  resize: vertical;
}

.primary-button,
.secondary-button,
.danger-button,
.icon-button,
.table-action {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  font-weight: 750;
}

.primary-button {
  padding: 0 16px;
  color: #fff;
  background: var(--brand);
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button {
  padding: 0 14px;
  color: #17324d;
  background: #dfeaf2;
}

.danger-button {
  padding: 0 14px;
  color: #fff;
  background: var(--danger);
}

.icon-button {
  display: inline-grid;
  width: 40px;
  padding: 0;
  place-items: center;
  color: #17202a;
  background: #dfeaf2;
  font-size: 20px;
}

.table-panel {
  padding: 0;
  overflow: hidden;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 850px;
  border-collapse: collapse;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: #4b5a6a;
  background: #f8fafc;
  font-size: 12px;
  font-weight: 800;
}

td {
  font-size: 14px;
}

tr:last-child td {
  border-bottom: 0;
}

.muted {
  color: var(--muted);
}

.money-plus {
  color: var(--green);
  font-weight: 800;
}

.money-minus {
  color: var(--danger);
  font-weight: 800;
}

.table-action {
  min-height: 32px;
  padding: 0 10px;
  color: #17324d;
  background: #e8eff5;
  font-size: 12px;
}

.table-actions {
  display: flex;
  gap: 7px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(18, 24, 32, 0.52);
}

.modal {
  width: min(760px, 100%);
  max-height: min(760px, 92vh);
  overflow: auto;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 25px 80px rgba(0, 0, 0, 0.28);
}

.modal-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 18px;
}

.form-field {
  display: grid;
  gap: 7px;
}

.form-field.full {
  grid-column: 1 / -1;
}

.form-field label {
  color: #3b4652;
  font-size: 13px;
  font-weight: 750;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  grid-column: 1 / -1;
  padding-top: 6px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  max-width: min(360px, calc(100vw - 44px));
  padding: 13px 15px;
  border-radius: var(--radius);
  color: #fff;
  background: #17202a;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.hidden {
  display: none !important;
}

.report-actions {
  justify-content: flex-end;
}

.image-tool {
  display: grid;
  gap: 12px;
}

.image-tool input[type="file"] {
  width: 100%;
  padding: 8px 10px;
}

.image-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.image-options label {
  display: grid;
  gap: 6px;
  color: #3b4652;
  font-size: 13px;
  font-weight: 750;
}

.image-preview-list {
  display: grid;
  gap: 8px;
}

.image-job {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.image-job span {
  color: var(--muted);
  font-size: 12px;
}

.operations-metrics {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.video-maker-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 22px;
}

.video-controls,
.video-preview-card {
  min-width: 0;
}

.video-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.video-field {
  display: grid;
  gap: 7px;
}

.video-field.full {
  grid-column: 1 / -1;
}

.video-field > span {
  color: #3b4652;
  font-size: 13px;
  font-weight: 750;
}

.video-field input,
.video-field select {
  width: 100%;
}

.video-field input[type="color"] {
  min-height: 40px;
  padding: 4px;
}

.video-storyboard {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  min-height: 110px;
  margin-top: 14px;
}

.video-empty {
  display: grid;
  grid-column: 1 / -1;
  min-height: 110px;
  place-items: center;
  padding: 18px;
  border: 1px dashed #bdc9d4;
  border-radius: var(--radius);
  color: var(--muted);
  background: #f8fafc;
  text-align: center;
  font-size: 13px;
}

.video-scene {
  position: relative;
  min-width: 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.video-scene img {
  display: block;
  width: 100%;
  height: 92px;
  border-radius: 5px;
  object-fit: cover;
}

.video-scene > span {
  position: absolute;
  top: 11px;
  left: 11px;
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: rgba(17, 24, 39, 0.76);
  font-size: 11px;
  font-weight: 800;
}

.video-scene small {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.video-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.video-download {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.video-progress-wrap {
  display: grid;
  gap: 6px;
  margin-top: 14px;
}

.video-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e3eaf0;
}

.video-progress span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 0.12s linear;
}

.video-progress-wrap small,
.video-note {
  color: var(--muted);
  font-size: 12px;
}

.video-note {
  margin: 12px 0 0;
  line-height: 1.6;
}

.video-preview-card {
  display: grid;
  align-content: start;
  justify-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: #121820;
}

.video-preview-stage {
  position: relative;
  width: min(100%, 320px);
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border-radius: 10px;
  background: #111827;
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.35);
}

.video-preview-stage[data-ratio="1:1"] {
  aspect-ratio: 1 / 1;
}

.video-preview-stage[data-ratio="16:9"] {
  width: 100%;
  aspect-ratio: 16 / 9;
}

.video-preview-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.video-preview-placeholder {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  color: #fff;
  background: linear-gradient(145deg, rgba(215, 25, 32, 0.82), rgba(18, 24, 32, 0.96));
  text-align: center;
}

.video-preview-placeholder span {
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
}

.generated-video {
  display: block;
  width: min(100%, 420px);
  max-height: 600px;
  border-radius: 10px;
  background: #000;
}

.video-history-panel {
  margin-top: 16px;
}

.video-history-table {
  min-width: 760px;
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.ai-panel {
  margin-top: 16px;
}

.ai-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.ai-result {
  min-height: 92px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafc;
  white-space: pre-wrap;
  line-height: 1.65;
}

.ai-chat {
  display: grid;
  gap: 9px;
  max-height: 320px;
  margin-top: 12px;
  overflow: auto;
}

.ai-chat-message {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.ai-chat-message strong {
  display: block;
  margin-bottom: 5px;
  color: var(--teal);
  font-size: 13px;
}

.ai-chat-message p {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.6;
}

.ai-chat-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  margin-top: 12px;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

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

  .metric-grid,
  .dashboard-layout,
  .report-grid,
  .operations-grid,
  .operations-metrics,
  .video-maker-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .nav-list,
  .metric-grid,
  .dashboard-layout,
  .report-grid,
    .operations-grid,
    .operations-metrics,
    .image-options,
    .video-maker-grid,
    .video-form-grid,
    .form-grid {
    grid-template-columns: 1fr;
  }

  .video-storyboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-heading span {
    align-self: start;
    white-space: normal;
  }

  h1 {
    font-size: 25px;
  }
}
