:root {
  color-scheme: light;
  --bg: #f6f3ec;
  --surface: #fffdf8;
  --surface-2: #ebe5da;
  --ink: #172126;
  --muted: #69757c;
  --line: #d8d0c2;
  --green: #23745a;
  --green-dark: #185842;
  --amber: #c78c2e;
  --rust: #b66145;
  --focus: #1f6feb;
  --shadow: 0 18px 46px rgba(24, 33, 38, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

body.lightbox-open {
  overflow: hidden;
}

button,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.rail {
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-height: 100vh;
  padding: 24px;
  border-right: 1px solid var(--line);
  background: #fdfaf3;
}

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

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--ink);
  color: #fffdf8;
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 18px;
  line-height: 1.2;
}

.brand span,
#modeMeta,
.queue-panel span,
.result-toolbar span {
  color: var(--muted);
  font-size: 13px;
}

.nav-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.nav-tab {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 650;
}

.nav-tab.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(23, 33, 38, 0.1);
}

.queue-panel {
  display: flex;
  flex: 1;
  min-height: 0;
  flex-direction: column;
  gap: 14px;
}

.panel-heading,
.result-toolbar,
.topbar,
.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 15px;
}

.job-list {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

.job-item {
  display: grid;
  gap: 6px;
  width: 100%;
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
}

.job-item.pending {
  border-color: #c8c0b3;
  background: #f0ece4;
  color: var(--muted);
}

.job-item.active {
  border-color: var(--green);
  box-shadow: 0 0 0 2px rgba(35, 116, 90, 0.12);
}

.job-item.pending.active {
  border-color: #aaa195;
  box-shadow: none;
}

.job-item strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.job-item span {
  font-size: 12px;
}

.job-status.queued,
.job-status.running,
.result-toolbar span[data-status="queued"],
.result-toolbar span[data-status="running"] {
  color: #8a8174;
}

.workspace {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  min-width: 0;
  min-height: 100vh;
  padding: 28px;
  gap: 22px;
}

.topbar {
  min-height: 58px;
}

.status-pill {
  min-width: 86px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.status-pill.ready {
  border-color: rgba(35, 116, 90, 0.3);
  color: var(--green-dark);
}

.status-pill.error {
  border-color: rgba(182, 97, 69, 0.4);
  color: var(--rust);
}

.composer,
.result-area {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.composer {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.composer label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fffefb;
  color: var(--ink);
  line-height: 1.55;
}

textarea:focus,
button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.primary-button,
.secondary-button {
  min-width: 96px;
  min-height: 40px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 750;
}

.primary-button {
  border: 1px solid var(--green-dark);
  background: var(--green);
  color: white;
}

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

.primary-button:disabled,
.primary-button:disabled:hover {
  cursor: not-allowed;
  border-color: #bcb4a8;
  background: #bcb4a8;
  color: #fffdf8;
  opacity: 1;
}

.secondary-button {
  border: 1px solid var(--line);
  background: #fffefb;
  color: var(--ink);
}

.result-area {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
}

.result-toolbar {
  min-height: 54px;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
}

.result-view {
  overflow: auto;
  padding: 18px;
}

.empty-state {
  display: grid;
  min-height: 360px;
  place-items: center;
  align-content: center;
  gap: 16px;
  color: var(--muted);
  text-align: center;
}

.empty-visual {
  width: min(280px, 68vw);
  aspect-ratio: 4 / 3;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 0 14%, rgba(23, 33, 38, 0.08) 14% 15%, transparent 15% 100%),
    linear-gradient(0deg, transparent 0 18%, rgba(23, 33, 38, 0.08) 18% 19%, transparent 19% 100%),
    radial-gradient(circle at 28% 35%, rgba(35, 116, 90, 0.86) 0 18%, transparent 19%),
    linear-gradient(135deg, #f2d49a, #cf7652 52%, #2a6954);
  border: 1px solid var(--line);
}

.text-result {
  max-width: 860px;
  white-space: pre-wrap;
  line-height: 1.7;
}

.text-result h3,
.media-result h3,
.storyboard h3 {
  margin: 0 0 14px;
  font-size: 18px;
}

.result-warning {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(182, 97, 69, 0.34);
  border-radius: 8px;
  background: rgba(182, 97, 69, 0.08);
  color: var(--rust);
  font-size: 13px;
  line-height: 1.5;
}

.media-result {
  display: grid;
  grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.image-preview-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
}

.image-preview-button img {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    transform 0.16s ease;
}

.image-preview-button:hover img {
  border-color: rgba(35, 116, 90, 0.54);
  box-shadow: 0 8px 22px rgba(24, 33, 38, 0.16);
  transform: translateY(-1px);
}

.image-preview-button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 4px;
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 28px;
}

.image-lightbox.open {
  display: grid;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 22, 26, 0.86);
}

.lightbox-frame {
  position: relative;
  z-index: 1;
  display: grid;
  gap: 12px;
  width: min(1180px, 100%);
  max-height: calc(100vh - 56px);
  margin: 0;
}

.lightbox-frame img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 132px);
  margin: 0 auto;
  border-radius: 8px;
  background: #11191d;
  object-fit: contain;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

.lightbox-close {
  justify-self: end;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid rgba(255, 253, 248, 0.32);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.12);
  color: #fffdf8;
  font-weight: 750;
}

.lightbox-close:hover {
  background: rgba(255, 253, 248, 0.2);
}

.lightbox-frame figcaption {
  overflow: hidden;
  color: rgba(255, 253, 248, 0.82);
  font-size: 13px;
  line-height: 1.45;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.prompt-block {
  min-height: 220px;
  margin: 0;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #222b2f;
  color: #f8f7f2;
  line-height: 1.6;
  white-space: pre-wrap;
}

.storyboard {
  display: grid;
  gap: 12px;
  max-width: 980px;
}

.shot {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffefb;
}

.shot-time {
  color: var(--rust);
  font-weight: 800;
}

.shot strong {
  display: block;
  margin-bottom: 4px;
}

.shot p {
  color: var(--muted);
  line-height: 1.5;
}

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

  .rail {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .workspace {
    padding: 20px;
  }

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

  .media-result {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .rail,
  .workspace {
    padding: 16px;
  }

  h1 {
    font-size: 24px;
  }

  .composer-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .primary-button,
  .secondary-button {
    width: 100%;
  }

  .shot {
    grid-template-columns: 1fr;
  }
}
