@font-face {
  font-family: "Bai Jamjuree";
  src: url("/BaiJamjuree-Regular.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Bai Jamjuree";
  src: url("/BaiJamjuree-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Bai Jamjuree";
  src: url("/BaiJamjuree-Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #090c13;
  --surface: #111722;
  --surface-2: #17202e;
  --surface-3: #1d2838;
  --border: rgba(148, 163, 184, 0.2);
  --border-strong: rgba(148, 163, 184, 0.38);
  --text: #f4f7fb;
  --muted: #94a3b8;
  --accent: #6d5dfc;
  --accent-soft: rgba(109, 93, 252, 0.16);
  --green: #19c98b;
  --green-soft: rgba(25, 201, 139, 0.13);
  --cyan: #22d3ee;
  --red: #fb5c68;
  --amber: #f8b84e;
  --radius: 14px;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }
html { min-width: 0; background: var(--bg); }
body {
  min-width: 0;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 82% -10%, rgba(91, 75, 220, 0.13), transparent 34rem),
    linear-gradient(180deg, #090d15 0%, var(--bg) 55%);
  color: var(--text);
  font-family: "Bai Jamjuree", system-ui, sans-serif;
  line-height: 1.5;
}
button, input, select { font: inherit; }
button, a, input, select { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

:focus-visible {
  outline: 3px solid rgba(34, 211, 238, 0.7);
  outline-offset: 2px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
  background: rgba(9, 12, 19, 0.9);
  backdrop-filter: blur(18px);
}
.app-header-inner {
  width: min(1480px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 11px 22px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.app-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  color: var(--text);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}
.app-brand-icon { font-size: 22px; }
.app-brand small {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 10px;
  vertical-align: middle;
}
.app-nav {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-right: auto;
}
.app-nav a {
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}
.app-nav a:hover { color: var(--text); background: rgba(255,255,255,.04); }
.app-nav a.active {
  border-color: rgba(109, 93, 252, 0.55);
  background: var(--accent-soft);
  color: white;
}
.identity-bar {
  max-width: 280px;
  flex: 0 1 auto;
  overflow: hidden;
  padding: 8px 13px;
  border: 1px solid rgba(34, 211, 238, 0.42);
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.08);
  color: #b7f2fb;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.identity-bar[data-mode="user"] {
  border-color: rgba(25, 201, 139, 0.48);
  background: var(--green-soft);
  color: #b8f7df;
}

.page-shell {
  width: min(1480px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 30px 22px 80px;
}
.page-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}
.page-heading h1 { margin: 2px 0 5px; font-size: clamp(24px, 3vw, 34px); line-height: 1.2; }
.page-heading p:not(.eyebrow) { max-width: 760px; margin: 0; color: var(--muted); }
.eyebrow { margin: 0; color: #9d93ff; font-size: 11px; font-weight: 700; letter-spacing: .14em; }

.button, .icon-button {
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  transition: border-color .15s, background .15s, transform .15s, opacity .15s;
}
.button { display: inline-flex; min-height: 40px; align-items: center; justify-content: center; gap: 7px; padding: 9px 15px; }
.button:hover:not(:disabled), .icon-button:hover:not(:disabled) { transform: translateY(-1px); }
.button:disabled, .icon-button:disabled { cursor: not-allowed; opacity: .45; }
.button-primary { background: linear-gradient(135deg, #6d5dfc, #8b5cf6); color: white; box-shadow: 0 8px 24px rgba(109, 93, 252, .2); }
.button-secondary { border-color: var(--border); background: var(--surface-2); color: var(--text); }
.button-warning { border-color: rgba(248, 184, 78, .4); background: rgba(248, 184, 78, .13); color: #ffe0a3; }
.button-danger-ghost { border-color: rgba(251, 92, 104, .3); background: rgba(251, 92, 104, .06); color: #ffabb2; }
.icon-button { width: 40px; height: 40px; border-color: var(--border); background: var(--surface-2); font-size: 21px; }

.notice, .conflict-panel {
  margin-bottom: 18px;
  border: 1px solid rgba(34, 211, 238, .35);
  border-radius: 12px;
  background: rgba(34, 211, 238, .08);
  color: #c6f7ff;
}
.notice { padding: 12px 15px; overflow-wrap: anywhere; }
.notice[data-tone="error"] { border-color: rgba(251,92,104,.45); background: rgba(251,92,104,.1); color: #ffc4c9; }
.notice[data-tone="success"] { border-color: rgba(25,201,139,.45); background: var(--green-soft); color: #c2f9e4; }
.conflict-panel { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 15px 17px; border-color: rgba(248,184,78,.42); background: rgba(248,184,78,.08); color: #ffe5b4; }
.conflict-panel p { margin: 3px 0 0; color: #d8bf92; font-size: 13px; }

.composer-workspace {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(420px, .95fr);
  gap: 18px;
  align-items: start;
}
.workspace-panel, .history-toolbar, .bulk-toolbar, .edit-job {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(17, 23, 34, .92);
  box-shadow: var(--shadow);
}
.workspace-panel { padding: 18px; }
.composer-panel { position: sticky; top: 84px; }
.panel-heading, .timeline-heading, .draft-row, .set-toolbar, .bulk-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.panel-heading { margin-bottom: 16px; }
.panel-heading h2, .timeline-heading h3 { margin: 0; font-size: 18px; }
.panel-heading p, .timeline-heading p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.library-filters, .history-toolbar {
  display: grid;
  grid-template-columns: minmax(120px, .7fr) minmax(140px, .7fr) minmax(200px, 1.4fr);
  gap: 10px;
}
.library-filters { margin-bottom: 12px; }
.history-toolbar { grid-template-columns: minmax(260px, 1fr) minmax(150px, 220px) auto; margin-bottom: 14px; padding: 14px; align-items: end; }
label > span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 600; }
input, select {
  width: 100%;
  min-width: 0;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0c121c;
  color: var(--text);
  padding: 8px 11px;
}
input::placeholder { color: #68768a; }
input:focus, select:focus { border-color: rgba(109,93,252,.75); outline: 2px solid rgba(109,93,252,.18); }

.job-filter-chip {
  width: fit-content;
  max-width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  padding: 5px 8px 5px 11px;
  border: 1px solid rgba(34,211,238,.32);
  border-radius: 999px;
  background: rgba(34,211,238,.08);
  color: #b7f2fb;
  font-size: 11px;
  overflow-wrap: anywhere;
}
.job-filter-chip button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 17px; }
.section-state { margin: 10px 0 12px; color: var(--muted); font-size: 12px; }

.clip-library {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 11px;
}
@media (min-width: 761px) {
  .clip-library {
    max-height: calc(100vh - 300px);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    align-content: start;
    padding-right: 4px;
  }
}
.clip-card {
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #0d141f;
  transition: border-color .16s, transform .16s, background .16s;
}
.clip-card:hover { border-color: var(--border-strong); transform: translateY(-1px); }
.clip-card.selected { border-color: var(--green); background: rgba(25,201,139,.07); box-shadow: inset 0 0 0 1px rgba(25,201,139,.18); }
.clip-select-label {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}
.clip-checkbox, .job-select { width: 18px; height: 18px; flex: 0 0 auto; margin: 0; accent-color: var(--green); }
.clip-card video {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 340px;
  background: #05070a;
  object-fit: contain;
}
.clip-body { padding: 10px; }
.clip-title { display: block; overflow: hidden; color: var(--text); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.clip-meta, .clip-membership { margin-top: 5px; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.clip-membership { color: #9eeed1; min-height: 15px; }
.clip-usage { display: inline-block; margin-top: 8px; padding: 3px 8px; border-radius: 6px; background: var(--green-soft); color: #9eeed1; font-size: 12px; font-weight: 600; }
.clip-usage[data-used="true"] { background: rgba(248,184,78,.12); color: #ffe0a3; }
.clip-visibility-button { width: 100%; margin-top: 10px; font-size: 12px; }
.clip-card[data-hidden="true"] { border-style: dashed; }
.curation-help { margin: 0 0 12px; color: var(--muted); font-size: 11px; }
.clip-body details { margin-top: 7px; color: var(--muted); font-size: 10px; }
.clip-body summary, .source-manifest summary { cursor: pointer; color: #bfc8d7; }
.clip-prompt { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.set-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 14px;
}
.set-tab {
  max-width: 180px;
  min-height: 38px;
  overflow: hidden;
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #0d141f;
  color: var(--muted);
  cursor: pointer;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.set-tab[aria-selected="true"] { border-color: rgba(109,93,252,.72); background: var(--accent-soft); color: white; }
.set-toolbar { align-items: end; margin-bottom: 18px; }
.set-name-field { min-width: 0; flex: 1; }
.timeline-heading { border-top: 1px solid var(--border); padding-top: 15px; }
.timeline-heading > span { color: var(--muted); font-size: 12px; }
.selected-timeline {
  min-height: 145px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0 16px;
  padding: 0;
  list-style: none;
}
.timeline-item {
  min-width: 0;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: #0d141f;
}
.timeline-order { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 8px; background: var(--accent-soft); color: #d7d2ff; font-weight: 700; }
.timeline-copy { min-width: 0; }
.timeline-copy strong { display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.timeline-copy span { display: block; margin-top: 3px; color: var(--muted); font-size: 10px; overflow-wrap: anywhere; }
.timeline-actions { display: flex; gap: 5px; }
.timeline-actions button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
}
.timeline-actions button[data-action="remove-clip"] { color: #ffabb2; }
.timeline-actions button:disabled { opacity: .35; cursor: not-allowed; }
.empty-state { width: 100%; padding: 34px 14px; border: 1px dashed var(--border-strong); border-radius: 12px; color: var(--muted); text-align: center; }
.empty-state strong { display: block; margin-bottom: 4px; color: var(--text); }
.missing-clip { border-color: rgba(251,92,104,.5); background: rgba(251,92,104,.06); }
.draft-row { border-top: 1px solid var(--border); padding-top: 14px; }
#draftStatus { color: var(--muted); font-size: 12px; }
#draftStatus[data-state="saved"] { color: #9eeed1; }
#draftStatus[data-state="error"] { color: #ffabb2; }
.create-summary { margin: 16px 0 9px; color: var(--muted); font-size: 12px; }
.button-create { width: 100%; min-height: 50px; font-size: 15px; }
.create-result { margin-top: 14px; padding: 14px; border: 1px solid rgba(25,201,139,.4); border-radius: 12px; background: var(--green-soft); }
.create-result h3 { margin: 0 0 8px; }
.create-result p { margin: 5px 0; color: #cbf5e5; font-size: 12px; overflow-wrap: anywhere; }
.create-result .button { margin-top: 10px; }

.bulk-toolbar { margin-bottom: 10px; padding: 14px; }
.bulk-toolbar p { margin: 3px 0 0; color: var(--muted); font-size: 11px; }
.bulk-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.download-status { min-height: 22px; margin: 8px 2px 14px; color: var(--muted); font-size: 12px; }
.edit-job-list { display: flex; flex-direction: column; gap: 11px; }
.edit-job { display: grid; grid-template-columns: minmax(190px, .85fr) minmax(280px, 1.5fr) minmax(185px, .75fr) minmax(170px, .72fr); gap: 16px; padding: 16px; box-shadow: none; }
.job-summary { min-width: 0; display: grid; grid-template-columns: 20px minmax(0,1fr); gap: 9px; align-content: start; }
.job-summary h2 { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.job-summary p { margin: 4px 0 0; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.source-manifest { min-width: 0; }
.source-manifest > strong { display: block; margin-bottom: 7px; font-size: 11px; color: var(--muted); }
.manifest-list { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; list-style: none; }
.manifest-item { min-width: 0; padding: 7px 9px; border: 1px solid var(--border); border-radius: 8px; background: #0d141f; font-size: 10px; }
.manifest-line { display: flex; gap: 7px; align-items: baseline; }
.manifest-order { color: #c9c4ff; font-weight: 700; }
.manifest-filename { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manifest-meta { margin-top: 3px; color: var(--muted); overflow-wrap: anywhere; }
.job-runtime { min-width: 0; }
.status-badge { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.status-badge.queued { background: rgba(248,184,78,.12); color: #ffd99a; }
.status-badge.processing { background: rgba(34,211,238,.12); color: #b7f2fb; }
.status-badge.completed { background: var(--green-soft); color: #aaf3d7; }
.status-badge.failed { background: rgba(251,92,104,.12); color: #ffb3ba; }
.job-progress { width: 100%; height: 8px; margin: 10px 0 6px; accent-color: var(--cyan); }
.job-stage, .job-elapsed, .job-video-duration, .job-error { margin: 4px 0 0; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.job-video-duration { color: #b7f2fb; }
.job-error { color: #ffabb2; white-space: pre-wrap; }
.job-output { min-width: 0; display: flex; flex-direction: column; align-items: stretch; gap: 8px; }
.job-output video { width: 100%; max-height: 210px; border-radius: 9px; background: #05070a; object-fit: contain; }
.job-output .button { min-height: 36px; padding: 7px 10px; font-size: 11px; }
.job-output-placeholder { display: grid; min-height: 120px; place-items: center; border: 1px dashed var(--border); border-radius: 9px; color: var(--muted); font-size: 11px; text-align: center; }

.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0,0,0,.74);
  backdrop-filter: blur(8px);
}
.auth-card { position: relative; width: min(460px, 100%); padding: 24px; border: 1px solid var(--border-strong); border-radius: 16px; background: #111722; box-shadow: 0 30px 90px rgba(0,0,0,.55); }
.auth-card h2 { margin: 5px 0; }
.auth-card > p:not(.eyebrow) { color: var(--muted); font-size: 12px; }
.auth-card label { display: block; margin-top: 12px; color: #d8e0ec; font-size: 12px; font-weight: 600; }
.auth-card label + input { margin-top: 5px; }
.auth-close { position: absolute; top: 10px; right: 13px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 25px; }
.auth-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.form-error { min-height: 20px; margin: 9px 0 0; color: #ffabb2 !important; }
.toast-region { position: fixed; right: 16px; bottom: 16px; z-index: 1200; display: flex; width: min(360px, calc(100% - 32px)); flex-direction: column; gap: 8px; pointer-events: none; }
.toast { padding: 11px 13px; border: 1px solid var(--border-strong); border-radius: 10px; background: #17202e; color: var(--text); box-shadow: var(--shadow); font-size: 12px; overflow-wrap: anywhere; }
.toast.error { border-color: rgba(251,92,104,.5); }
.toast.success { border-color: rgba(25,201,139,.5); }

@media (max-width: 1120px) {
  .app-header-inner { flex-wrap: wrap; gap: 8px 14px; }
  .app-nav { order: 3; width: 100%; flex-wrap: wrap; }
  .composer-workspace { grid-template-columns: 1fr; }
  .composer-panel { position: static; }
  .edit-job { grid-template-columns: minmax(180px,.7fr) minmax(260px,1.3fr) minmax(180px,.7fr); }
  .job-output { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(120px, 200px) auto; align-items: center; }
}

@media (max-width: 760px) {
  .app-header { position: static; }
  .app-header-inner, .page-shell { padding-left: 13px; padding-right: 13px; }
  .app-brand { margin-right: auto; }
  .identity-bar { max-width: 52vw; }
  .app-nav { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); }
  .app-nav a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: center; }
  .page-heading { align-items: stretch; flex-direction: column; gap: 14px; }
  .page-heading .button { align-self: flex-start; }
  .library-filters, .history-toolbar { grid-template-columns: 1fr; }
  .clip-library { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .clip-card video { max-height: 300px; }
  .set-toolbar, .draft-row, .conflict-panel, .bulk-toolbar { align-items: stretch; flex-direction: column; }
  .bulk-actions { justify-content: stretch; }
  .bulk-actions .button { flex: 1 1 150px; }
  .edit-job { grid-template-columns: 1fr; gap: 13px; }
  .job-output { grid-column: auto; display: flex; }
  .job-output video { max-height: 320px; }
}

@media (max-width: 460px) {
  .page-shell { padding-top: 22px; }
  .app-brand { font-size: 16px; }
  .identity-bar { width: 100%; max-width: none; order: 2; }
  .app-nav { order: 3; }
  .clip-library { grid-template-columns: 1fr; }
  .clip-card video { max-height: 420px; }
  .timeline-item { grid-template-columns: 30px minmax(0,1fr); }
  .timeline-actions { grid-column: 1 / -1; justify-content: flex-end; }
  .auth-actions { flex-direction: column-reverse; }
  .auth-actions .button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
