:root {
  --page: #f3f5f7;
  --surface: #ffffff;
  --surface-alt: #f8fafb;
  --ink: #18202b;
  --muted: #667085;
  --line: #d7dde4;
  --brand: #0f766e;
  --brand-hover: #0b5f59;
  --blue: #175cd3;
  --green: #067647;
  --amber: #b54708;
  --red: #b42318;
  --code: #101828;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
h1, h2 { letter-spacing: 0; }
h1 { margin: 0; font-size: 22px; }
h2 { margin: 0; font-size: 16px; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.brand-block { min-width: 180px; }
.product-label { margin-top: 2px; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.studio-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.route-nav {
  display: inline-grid;
  grid-template-columns: repeat(4, minmax(62px, 1fr));
  min-height: 38px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
}
.route-nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 68px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}
.route-nav a:last-child { border-right: 0; }
.route-nav a:hover { color: var(--ink); background: var(--surface); }
.route-nav a.active { color: #fff; background: var(--brand); }

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 18px;
  width: min(1520px, 100%);
  margin: 0 auto;
  padding: 18px;
}
.sidebar, .content { display: grid; align-content: start; gap: 16px; min-width: 0; }
.view-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding: 2px 2px 0;
}
.view-heading h2 { margin-top: 4px; font-size: 20px; }
.view-kicker { color: var(--brand); font-size: 10px; font-weight: 800; }
section {
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 16px;
}
.sidebar section { display: grid; gap: 14px; }
form { display: grid; gap: 12px; }
label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
input, select, textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid #b8c2cc;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
  outline: none;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #175cd31f; }
.two-column { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
fieldset { margin: 0; border: 1px solid var(--line); padding: 10px; }
legend { color: var(--muted); font-size: 12px; }
.check-row { display: flex; align-items: center; gap: 8px; min-height: 32px; color: var(--ink); }
.check-row input { width: 17px; min-height: 17px; accent-color: var(--brand); }

.button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 8px 13px;
  font-weight: 650;
}
.button.primary { background: var(--brand); color: #fff; }
.button.primary:hover { background: var(--brand-hover); }
.button.secondary { border-color: var(--line); background: var(--surface); color: var(--ink); }
.button.secondary:hover { background: var(--surface-alt); }
.button.danger { border-color: #f3b7b1; background: #fff5f4; color: var(--red); }
.button.small { min-height: 30px; padding: 4px 9px; font-size: 12px; }
.button.full { width: 100%; }

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
  padding: 0;
}
.metrics article { min-height: 84px; padding: 15px; border-right: 1px solid var(--line); }
.metrics article:last-child { border-right: 0; }
.metrics span { display: block; color: var(--muted); font-size: 12px; }
.metrics strong { display: block; margin-top: 8px; font-size: 25px; }

.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.section-heading select { width: 150px; min-height: 34px; padding: 5px 8px; }
.section-meta { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.table-scroll { width: 100%; overflow-x: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { padding: 10px 8px; border-bottom: 1px solid #e6e9ed; text-align: left; vertical-align: middle; }
th { color: var(--muted); background: var(--surface-alt); font-size: 11px; font-weight: 650; text-transform: uppercase; }
td { font-size: 13px; }
.task-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--blue); }
.task-actions { display: flex; justify-content: flex-end; gap: 6px; }

.status-pill, .count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 25px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--surface-alt);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.status-pill.success { border-color: #a6e3c8; background: #ecfdf3; color: var(--green); }
.status-pill.info { border-color: #b2ccff; background: #eff4ff; color: var(--blue); }
.status-pill.warning { border-color: #fedf89; background: #fffaeb; color: var(--amber); }
.status-pill.danger { border-color: #fecdca; background: #fef3f2; color: var(--red); }

.approval-list { display: grid; gap: 9px; }
.approval-item {
  display: grid;
  gap: 14px;
  border: 1px solid var(--line);
  background: var(--surface-alt);
  padding: 12px;
}
.approval-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.approval-item strong { display: block; margin-bottom: 4px; }
.approval-item p { margin: 0; color: var(--muted); line-height: 1.55; }
.approval-actions { display: flex; gap: 7px; }
.local-media-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: -2px 0 16px;
  padding: 0 0 14px;
  border-bottom: 1px solid var(--line);
}
.local-media-actions { display: flex; gap: 7px; }
#localFolderStatus[data-tone="success"] { color: var(--green); }
#localFolderStatus[data-tone="warning"] { color: var(--amber); }
#localFolderStatus[data-tone="danger"] { color: var(--red); }
.review-media { display: grid; gap: 12px; min-width: 0; }
.review-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(145px, 1fr));
  gap: 10px;
}
.review-image-option { position: relative; display: grid; gap: 6px; min-width: 0; color: var(--ink); }
.review-image-option > input {
  position: absolute;
  top: 7px;
  left: 7px;
  z-index: 2;
  width: 18px;
  min-height: 18px;
  accent-color: var(--brand);
}
.review-image-frame {
  display: grid;
  place-items: center;
  width: 100%;
  aspect-ratio: 9 / 16;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #eef1f4;
  color: var(--muted);
  padding: 8px;
  text-align: center;
  font-size: 11px;
}
.review-image-frame img { width: 100%; height: 100%; object-fit: cover; }
.review-image-option:has(input:checked) .review-image-frame { border: 3px solid var(--brand); padding: 6px; }
.review-image-option > span { overflow-wrap: anywhere; font-size: 11px; }
.review-image-frame.media-error { color: var(--red); }
.review-video { display: grid; gap: 8px; justify-items: start; }
.review-video video { width: min(360px, 100%); max-height: 640px; background: #000; }
.event-list, .handoff-list { display: grid; gap: 8px; }
.event-item, .handoff-item {
  display: grid;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid #e6e9ed;
  padding: 10px 0;
}
.event-item { grid-template-columns: 100px minmax(0, 1fr) auto; }
.handoff-item { grid-template-columns: minmax(0, 1fr) auto; }
.event-item:last-child, .handoff-item:last-child { border-bottom: 0; }
.event-content strong, .handoff-item strong { display: block; margin-bottom: 3px; }
.event-content p, .handoff-item p { margin: 0 0 4px; color: var(--ink); line-height: 1.45; }
.event-meta { display: block; color: var(--muted); font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.event-marker { align-self: start; }
.handoff-actions { display: flex; align-items: center; gap: 8px; }
.empty-state { padding: 18px 0 4px; color: var(--muted); text-align: center; }

dialog {
  width: min(920px, calc(100vw - 28px));
  max-height: calc(100vh - 40px);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0;
  background: var(--surface);
}
dialog::backdrop { background: #1018288f; }
.dialog-heading { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.icon-button { width: 34px; height: 34px; border: 0; background: transparent; color: var(--muted); font-size: 24px; }
pre {
  max-height: calc(100vh - 120px);
  margin: 0;
  overflow: auto;
  padding: 16px;
  background: var(--code);
  color: #e4e7ec;
  font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 36px));
  transform: translateY(20px);
  opacity: 0;
  pointer-events: none;
  border: 1px solid #344054;
  border-radius: 5px;
  background: #1d2939;
  color: #fff;
  padding: 11px 14px;
  transition: opacity 160ms ease, transform 160ms ease;
}
#toast.visible { transform: translateY(0); opacity: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }

@media (max-width: 980px) {
  .topbar { flex-wrap: wrap; }
  .route-nav { order: 3; width: 100%; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); }
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metrics article:nth-child(3) { border-right: 0; }
  .metrics article:nth-child(-n + 3) { border-bottom: 1px solid var(--line); }
}

@media (max-width: 640px) {
  .topbar { padding: 11px 14px; }
  .brand-block { min-width: 0; }
  .product-label { display: none; }
  .route-nav a { min-width: 0; padding-inline: 6px; }
  .workspace { padding: 10px; gap: 10px; }
  .sidebar { grid-template-columns: 1fr; }
  section { padding: 13px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metrics article { border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
  .metrics article:nth-child(2n) { border-right: 0; }
  .metrics article:last-child { border-bottom: 0; }
  .approval-header { align-items: flex-start; flex-direction: column; }
  .approval-actions { justify-content: flex-start; }
  .local-media-bar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { gap: 6px; }
  .topbar-actions .status-pill { display: none; }
  .topbar-actions .button { padding-inline: 9px; }
  .view-heading { align-items: flex-start; flex-direction: column; gap: 2px; }
  .event-item { grid-template-columns: 1fr auto; }
  .event-marker { grid-column: 1 / -1; }
  .handoff-item { grid-template-columns: 1fr; }
  .handoff-actions { justify-content: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  #toast { transition: none; }
}
