:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #20242a;
  --muted: #68707a;
  --line: #d9dee6;
  --brand: #1668dc;
  --brand-strong: #0f52b5;
  --danger: #c9353d;
  --success: #248a52;
  --warn: #9a6a00;
  --shadow: 0 12px 32px rgba(25, 35, 50, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(22px, 3.2vw, 30px);
  line-height: 1.1;
}

h2 {
  margin-bottom: 5px;
  font-size: 18px;
}

.status-badge {
  min-width: 84px;
  padding: 8px 12px;
  border-radius: 999px;
  background: #e8f1ff;
  color: var(--brand-strong);
  text-align: center;
  font-weight: 700;
}

.empty-state,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.empty-state {
  padding: 32px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.left-col,
.right-col {
  display: grid;
  gap: 16px;
  align-content: start;
  min-width: 0;
}

.panel {
  padding: 18px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.panel-header p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 14px;
}

.head-inline {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.head-inline h2 {
  margin: 0;
  line-height: 1.2;
}

.head-inline p {
  margin: 0;
  font-size: 13px;
}

.compact {
  margin-bottom: 10px;
}

.upload-button,
.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.upload-button,
.primary-button {
  background: var(--brand);
  color: #fff;
}

.upload-button:hover,
.primary-button:hover {
  background: var(--brand-strong);
}

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

.upload-button input {
  display: none;
}

.asset-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.asset-card {
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.asset-preview {
  position: relative;
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 6px;
  background: #eef1f5;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
}

.asset-preview img,
.asset-preview video {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.asset-preview audio {
  width: 90%;
}

.asset-body {
  min-width: 0;
}

.asset-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.asset-label {
  color: var(--brand-strong);
  font-size: 13px;
}

.asset-state {
  color: var(--muted);
  font-size: 12px;
}

.asset-name {
  overflow: hidden;
  margin: 6px 0 10px;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.asset-usage-label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.asset-usage-label .asset-usage {
  flex: 1;
  min-width: 0;
}

.asset-usage,
.params-grid input,
.params-grid select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

.asset-usage,
.params-grid input,
.params-grid select {
  min-height: 28px;
  padding: 3px 8px;
}

.asset-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}

.asset-actions button {
  flex: 1;
  min-height: 26px;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  font-size: 12px;
}

.delete-button {
  color: var(--danger);
}

textarea {
  min-height: 178px;
  resize: vertical;
  padding: 12px;
  line-height: 1.55;
}

.ref-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.ref-chip-group {
  display: inline-flex;
  align-items: center;
}

.ref-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand-strong);
}

.ref-chip-group:has(.ref-define) .ref-chip {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  border-right: none;
}

.ref-define {
  align-self: stretch;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-top-right-radius: 999px;
  border-bottom-right-radius: 999px;
  background: #f0f6ff;
  color: var(--brand-strong);
  font-size: 11px;
  font-weight: 700;
}

.ref-define:hover {
  background: #dbeafe;
}

.ref-chip:hover:not(:disabled) {
  border-color: var(--brand);
  background: #f0f6ff;
}

.ref-chip:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.ref-chip-key {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 2px;
  border-radius: 4px;
  background: var(--brand);
  color: #fff;
  font-size: 10px;
  line-height: 1;
}

.ref-chip-thumb {
  flex: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  background: #eef1f5;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.ref-chip-thumb img,
.ref-chip-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ref-chip-thumb * {
  pointer-events: none;
}

.syntax-hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.syntax-hint code {
  padding: 1px 5px;
  border-radius: 4px;
  background: #eef1f5;
  color: var(--text);
  font-size: 11.5px;
}

.params-grid {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-top: 12px;
}

.params-grid > label {
  color: var(--muted);
  font-size: 13px;
}

.params-grid > label:not(.check-row) {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.params-grid > label select {
  width: auto;
  min-width: 0;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
}

.check-row input {
  width: 16px;
  height: 16px;
  min-height: 16px;
}

.actions-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 14px;
}

.validation-box,
.result-box,
.upload-log {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.validation-item {
  border-radius: 6px;
  padding: 9px 10px;
  background: #f1f3f7;
}

.validation-item.blocking {
  background: #fff0f1;
  color: var(--danger);
}

.validation-item.warning {
  background: #fff8e6;
  color: var(--warn);
}

.validation-item.ok {
  background: #edf8f1;
  color: var(--success);
}

.review-inline {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.review-inline-title {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.validation-box.compact {
  gap: 4px;
  font-size: 12.5px;
}

.validation-box.compact .validation-item {
  padding: 4px 8px;
  border-radius: 5px;
  line-height: 1.4;
}

.result-box a {
  color: var(--brand-strong);
  font-weight: 700;
}

.result-item {
  display: grid;
  gap: 8px;
}

.result-item video {
  width: 100%;
  max-height: 420px;
  border-radius: 8px;
  background: #11151c;
}

.result-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 14px;
}

.result-label {
  margin-right: auto;
  color: var(--muted);
  font-weight: 700;
}

.gen-log-status:empty {
  display: none;
}

.gen-log-status {
  padding: 2px 10px;
  border-radius: 999px;
  background: #e8f1ff;
  color: var(--brand-strong);
  font-size: 12px;
  font-weight: 700;
}

.gen-log {
  max-height: 220px;
  overflow-y: auto;
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 6px;
  background: #0f141a;
  color: #cdd6e2;
  font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.5;
}

.gen-log-item {
  white-space: pre-wrap;
  word-break: break-word;
}

.asset-preview img {
  cursor: zoom-in;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(8, 11, 16, 0.82);
  cursor: zoom-out;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.upload-log {
  margin-top: 12px;
}

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

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

@media (max-width: 640px) {
  .app-shell {
    width: min(100vw - 20px, 1180px);
    padding-top: 18px;
  }

  .topbar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

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

  .actions-row {
    flex-direction: column;
  }
}
