:root {
  --bg: #eef2f6;
  --surface: #ffffff;
  --ink: #17202a;
  --muted: #687381;
  --line: #d9dee7;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warn: #b45309;
  --danger: #b91c1c;
  --good: #15803d;
  --shadow: 0 16px 45px rgba(23, 32, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, Tahoma, sans-serif;
  color: var(--ink);
  background: var(--bg);
  display: grid;
  grid-template-columns: 240px 1fr;
}

button,
input,
select {
  font: inherit;
}

.sidebar {
  background: #0f172a;
  color: #fff;
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  object-fit: cover;
}

.brand small {
  display: block;
  color: #bac4d1;
  margin-top: 2px;
}

.tabs {
  display: grid;
  gap: 8px;
}

.tab {
  border: 0;
  border-radius: 8px;
  min-height: 48px;
  padding: 12px 14px;
  text-align: left;
  color: #d7dee9;
  background: transparent;
  cursor: pointer;
  font-weight: 800;
}

.tab.active,
.tab:hover {
  background: #223047;
  color: #fff;
}

.app {
  padding: 24px;
  max-width: 1480px;
  width: 100%;
  margin: 0 auto;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: flex-start;
  margin-bottom: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

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

h1 {
  margin-bottom: 6px;
  font-size: 28px;
  line-height: 1.2;
}

h2 {
  margin-bottom: 4px;
  font-size: 22px;
}

p,
small {
  color: var(--muted);
}

.eyebrow {
  display: inline-block;
  margin-bottom: 6px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.actions,
.generator {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
}

.empty-product-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
}

.empty-product-actions[hidden] {
  display: none;
}

.data-tools {
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.data-tools summary {
  width: fit-content;
  margin-bottom: 12px;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.data-tools-body {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 0 16px;
}

.data-tools-body > div {
  margin-right: auto;
}

.data-tools-body p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.job-manager {
  margin-top: 16px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

.job-manager summary {
  cursor: pointer;
  font-weight: 800;
}

.job-manager-toolbar,
.job-row,
.job-row-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.job-manager-toolbar {
  justify-content: space-between;
  margin: 12px 0;
}

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

.job-row {
  align-items: flex-start;
  justify-content: space-between;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.job-row-main {
  min-width: 0;
}

.job-row-main code {
  overflow-wrap: anywhere;
}

.job-row details {
  margin-top: 6px;
}

.job-row pre {
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
}

.job-file-links {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.button-link {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 800;
}

button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 800;
}

.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.16);
}

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

.secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.danger {
  background: #fff;
  border-color: #fecaca;
  color: var(--danger);
}

.panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  box-shadow: var(--shadow);
}

.panel.active {
  display: block;
}

body[data-work-page="basket"] .panel.active:not(#automation) {
  display: none;
}

body[data-work-page="basket"] #automation.panel.active,
body[data-work-page="post"] #automation.panel.active {
  display: block;
  margin-bottom: 0;
}

.hidden {
  display: none !important;
}

.import-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 16px;
  margin: 18px 0;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fbfdfd;
}

.import-panel h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.import-panel p {
  margin: 0;
  color: var(--muted);
}

.import-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.import-actions input[type="file"] {
  min-width: 260px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

#importHelp {
  margin: 0;
  white-space: pre-wrap;
  color: var(--muted);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
  margin-bottom: 18px;
}

.compact-head {
  margin-bottom: 10px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.form-grid.compact {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
}

label {
  display: grid;
  gap: 6px;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--ink);
  background: #fff;
}

.wide {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow-x: auto;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: top;
}

th {
  color: #475569;
  font-size: 12px;
  text-transform: uppercase;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.card.selected-card {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(13, 148, 136, 0.12);
}

.card-actions {
  margin-top: 12px;
}

.score {
  font-size: 32px;
  font-weight: 800;
  color: var(--accent);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 4px 9px;
  border-radius: 999px;
  background: #e6fffb;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 700;
}

.pill.warn {
  background: #fff7ed;
  color: var(--warn);
}

.pill.danger {
  background: #fef2f2;
  color: var(--danger);
}

.content-output {
  display: grid;
  gap: 14px;
}

.automation-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.automation-mode-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.automation-mode-tab {
  flex: 1 1 220px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  font-weight: 700;
}

.automation-mode-tab.active {
  background: var(--accent);
  color: #fff;
}

.automation-mode-panel {
  display: none;
}

.automation-mode-panel.active {
  display: block;
}

.automation-group {
  margin-bottom: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.automation-group h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.automation-group .automation-actions {
  margin-bottom: 0;
}

.workflow-steps {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.workflow-step {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 16px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.workflow-step:hover {
  border-color: rgba(15, 118, 110, 0.28);
}

.workflow-step h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.workflow-step p {
  margin: 0 0 12px;
  color: var(--muted);
}

.step-actions {
  margin-top: 12px;
}

.product-preview {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  margin: 10px 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.product-preview:empty {
  display: none;
}

.product-preview-media {
  width: 120px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.product-preview-media img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.product-preview-empty {
  color: var(--muted);
  font-size: 13px;
}

.product-preview-detail {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.product-preview-detail strong,
.product-preview-detail small {
  overflow-wrap: anywhere;
}

.product-preview-detail span,
.product-preview-detail small {
  color: var(--muted);
}

.danger-text {
  color: #dc2626 !important;
  font-weight: 700;
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 10px 0;
}

.step-number {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.final-step {
  border-color: rgba(14, 165, 233, 0.35);
  background: #f0f9ff;
}

.final-step .primary {
  min-width: 240px;
  min-height: 46px;
}

.utility-actions {
  display: none;
}

.status-block {
  margin-top: 12px;
}

.status-panel {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.automation-picker {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.compact-picker {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
  margin-bottom: 12px;
}

.automation-picker small {
  color: var(--muted);
  line-height: 1.5;
}

.checkbox-label {
  display: flex;
  align-items: center;
  flex-direction: row;
  justify-content: flex-start;
  gap: 8px;
  min-height: 42px;
}

.checkbox-label input[type="checkbox"] {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  min-width: 22px;
  margin: 0;
  padding: 0;
  border-radius: 5px;
  accent-color: #0f827b;
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.pipe-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
  font-weight: 700;
}

.pipe-step.done {
  border-color: #99f6e4;
  background: #f0fdfa;
  color: var(--accent-dark);
}

.pipe-step.locked {
  border-color: #fed7aa;
  background: #fff7ed;
  color: var(--warn);
}

.content-block {
  border-left: 4px solid var(--accent);
  background: #f8fafc;
  border-radius: 8px;
  padding: 15px;
}

.content-block pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  margin: 0;
  line-height: 1.7;
}

.card pre,
.card p {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.queue-panel {
  margin: 16px 0 0;
}

.queue-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.queue-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  max-height: 520px;
  overflow: auto;
}

.queue-table {
  min-width: 1160px;
}

.queue-table input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
}

.queue-table input[type="datetime-local"] {
  min-width: 190px;
}

.queue-caption {
  max-width: 440px;
  line-height: 1.45;
}

.verify-list {
  display: grid;
  gap: 10px;
}

.verify-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
}

.ok {
  color: var(--good);
  font-weight: 800;
}

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

.manual-chatgpt-card {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fbfc;
}

.manual-chatgpt-card h4 {
  margin: 0 0 4px;
}

.manual-chatgpt-card p {
  margin: 0;
  color: var(--muted);
}

.manual-chatgpt-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.manual-chatgpt-step {
  display: grid;
  gap: 8px;
  align-content: start;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.manual-chatgpt-step span {
  color: var(--muted);
  line-height: 1.45;
}

.manual-storyboard-preview {
  margin-top: 12px;
}

.manual-storyboard-preview img {
  width: min(520px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
}

.card-media {
  width: min(680px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: block;
}

@media (max-width: 900px) {
  body {
    grid-template-columns: 1fr;
  }

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

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

  .topbar,
  .section-head {
    display: block;
  }

  .actions {
    margin-top: 14px;
  }

  .form-grid,
  .form-grid.compact {
    grid-template-columns: 1fr;
  }

  .automation-picker {
    grid-template-columns: 1fr;
  }

  .workflow-step {
    grid-template-columns: 1fr;
  }

  .manual-chatgpt-grid {
    grid-template-columns: 1fr;
  }
}
body.download-user [data-automation-panel="basket"],
body.download-user [data-automation-mode="basket"],
body.download-user .role-hidden,
body.download-user .download-user-hidden { display: none !important; }

.account-corner {
  display: grid;
  gap: 8px;
  width: 100%;
  margin: 4px 0 18px;
}

.current-user {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid #34405d;
  border-radius: 10px;
  background: #181d2d;
  color: #fff;
  box-shadow: none;
}

.current-user span {
  color: #aeb8d8;
  font-size: 11px;
}

.current-user strong {
  font-size: 13px;
}

.logout-button {
  display: block;
  padding: 10px 16px;
  border: 1px solid #ff5b72;
  border-radius: 10px;
  background: #181d2d;
  color: #ff8a9b;
  font-weight: 700;
  text-decoration: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  text-align: center;
}

.logout-button:hover,
.logout-button:focus-visible {
  background: #ff3158;
  color: #fff;
}

.oauth-button {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #ff5b72;
  border-radius: 8px;
  background: #ff3158;
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.oauth-button:hover,
.oauth-button:focus-visible { background: #e52249; }

.public-links {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 0 0 18px;
  font-size: 12px;
}

.public-links a { color: #bac4d1; }
.public-links a:hover, .public-links a:focus-visible { color: #fff; }

.caption-panel:not(:empty) {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.caption-section-head h3 {
  margin: 4px 0 12px;
}

.caption-card-grid {
  display: grid;
  gap: 12px;
}

.caption-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
}

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

.caption-card p {
  margin: 10px 0 0;
  color: var(--text);
  line-height: 1.65;
  white-space: pre-wrap;
}

button[aria-busy="true"] {
  cursor: wait;
  opacity: 0.72;
}

button.button-error {
  border-color: #dc2626 !important;
  background: #dc2626 !important;
  color: #fff !important;
  opacity: 1;
}

.button-error-indicator {
  margin-left: 10px;
  border: 1px solid #b91c1c !important;
  background: #dc2626 !important;
  color: #fff !important;
  cursor: not-allowed;
  opacity: 1 !important;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 4px 28px;
  color: var(--muted);
  font-size: 13px;
}

.app-footer nav { display: flex; gap: 16px; }
.app-footer a { color: inherit; }
.app-footer a:hover, .app-footer a:focus-visible { color: var(--accent); }
