/* AI Shorts Generator — single stylesheet, no build step, light + dark. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #16181d;
  --text-dim: #6b7280;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2c313b;
    --text: #e8eaed;
    --text-dim: #98a0ae;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #1e2130;
    --ok: #4ade80;
    --ok-soft: #14301f;
    --warn: #fbbf24;
    --danger: #f87171;
    --danger-soft: #341c1c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }

/* ── topbar ───────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo { font-size: 26px; line-height: 1; }
.topbar h1 { font-size: 17px; }
.tagline { margin: 1px 0 0; font-size: 12.5px; color: var(--text-dim); }

.health {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--text-dim);
  padding: 5px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  white-space: nowrap;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.logout {
  text-decoration: none; font-size: 12.5px; padding: 6px 12px;
  border: 1px solid var(--border); border-radius: 999px; color: var(--text-dim);
  display: inline-block;
}
.logout:hover { color: var(--text); border-color: var(--text-dim); }

/* ── source tabs + upload ─────────────────────────────────────────────── */

.source-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: 8px; }
.source-tab {
  flex: 1; background: transparent; border: none; color: var(--text-dim);
  font-size: 13px; font-weight: 600; padding: 7px 10px; border-radius: 6px;
}
.source-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 22px 14px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border); border-radius: 8px;
  background: var(--surface-2);
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 20px; color: var(--accent); }
.dz-text { font-size: 13px; font-weight: 550; }
.dz-hint { font-size: 11.5px; color: var(--text-dim); }

.upload-bar { height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.upload-bar > i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width .2s ease; }
#upload-status { display: block; margin-top: 5px; font-size: 11.5px; color: var(--text-dim); overflow-wrap: anywhere; }

.health .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-dim);
  flex: none;
}
.health.ok .dot { background: var(--ok); }
.health.bad .dot { background: var(--danger); }

/* ── layout ───────────────────────────────────────────────────────────── */

.layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
  gap: 20px;
  padding: 20px 24px 48px;
  max-width: 1500px;
  margin: 0 auto;
  align-items: start;
}

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .topbar { padding: 12px 16px; }
  .layout { padding: 16px; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

.results { min-height: 320px; }

/* ── form ─────────────────────────────────────────────────────────────── */

.form { display: flex; flex-direction: column; gap: 13px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.field small { font-size: 11.5px; color: var(--text-dim); font-weight: 400; }

input, select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder { color: var(--text-dim); opacity: .7; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }

.advanced {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
}
.advanced summary {
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  user-select: none;
}
.advanced[open] summary { margin-bottom: 11px; }
.advanced .grid2 { margin-bottom: 11px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  transition: background .15s, border-color .15s, opacity .15s;
}

.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 14.5px;
  padding: 11px;
  width: 100%;
}
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.primary:disabled { opacity: .55; cursor: progress; }

.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-dim);
  padding: 3px 9px;
  font-size: 14px;
}
.ghost:hover { color: var(--text); border-color: var(--text-dim); }

.error {
  margin: 0;
  padding: 9px 11px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  font-size: 13px;
  word-break: break-word;
  white-space: pre-wrap;
}

/* ── history ──────────────────────────────────────────────────────────── */

.history { margin-top: 22px; border-top: 1px solid var(--border); padding-top: 14px; }
.history-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px; }
.history-head h2 { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }

.history-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 5px; max-height: 320px; overflow-y: auto; }
.history-list li { }
.history-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 8px 9px;
  border-radius: 8px;
  color: var(--text);
}
.history-item:hover { background: var(--surface-2); }
.history-item.active { background: var(--accent-soft); border-color: var(--accent); }
.history-item .hi-main { flex: 1; min-width: 0; }
.history-item .hi-url {
  display: block;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item .hi-meta { font-size: 11.5px; color: var(--text-dim); }
.history-empty { font-size: 13px; color: var(--text-dim); padding: 6px 2px; }

.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.failed { background: var(--danger-soft); color: var(--danger); }
.badge.running { background: var(--accent-soft); color: var(--accent); }

/* ── empty state ──────────────────────────────────────────────────────── */

.empty { text-align: center; padding: 64px 20px; color: var(--text-dim); }
.empty-icon { font-size: 34px; margin: 0 0 10px; }
.empty p { margin: 4px 0; }
.muted { font-size: 13px; opacity: .8; }

/* ── progress ─────────────────────────────────────────────────────────── */

.progress-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.progress-head h2 { font-size: 16px; overflow-wrap: anywhere; }

.stages { list-style: none; margin: 0 0 4px; padding: 0; display: flex; flex-direction: column; gap: 11px; }

.stage { display: flex; gap: 11px; align-items: flex-start; }
.stage-icon {
  width: 21px; height: 21px; border-radius: 50%;
  border: 2px solid var(--border);
  display: grid; place-items: center;
  font-size: 11px; flex: none; margin-top: 1px;
  color: var(--text-dim);
}
.stage.running .stage-icon { border-color: var(--accent); color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.stage.done .stage-icon { border-color: var(--ok); background: var(--ok); color: #fff; }
.stage.failed .stage-icon { border-color: var(--danger); background: var(--danger); color: #fff; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.stage-body { flex: 1; min-width: 0; }
.stage-label { font-size: 14px; font-weight: 550; }
.stage.pending .stage-label { color: var(--text-dim); }
.stage-message { font-size: 12.5px; color: var(--text-dim); overflow-wrap: anywhere; }

.bar { height: 5px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .25s ease; }
.stage.done .bar > i { background: var(--ok); }

/* ── clips ────────────────────────────────────────────────────────────── */

.clips { margin-top: 22px; }
.clips-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 13px; }
.clips-head h2 { font-size: 15px; }

.clip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.clip {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  display: flex;
  flex-direction: column;
}
.clip video { width: 100%; display: block; background: #000; aspect-ratio: 9 / 16; object-fit: contain; }
.clip-body { padding: 11px 12px 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.clip-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.score {
  font-size: 11.5px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent);
}
.clip-time { font-size: 11.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.clip-title { font-size: 13.5px; font-weight: 600; line-height: 1.35; overflow-wrap: anywhere; }
.clip-hook { font-size: 12.5px; color: var(--text-dim); font-style: italic; overflow-wrap: anywhere; }
.clip-actions { margin-top: auto; padding-top: 8px; display: flex; gap: 8px; }
.clip-actions a {
  font-size: 12.5px; font-weight: 600;
  color: var(--accent); text-decoration: none;
  border: 1px solid var(--border); border-radius: 7px;
  padding: 5px 10px;
}
.clip-actions a:hover { border-color: var(--accent); background: var(--accent-soft); }
.clip.failed .clip-body { color: var(--danger); }

.link-button {
  font-size: 12.5px; font-weight: 600;
  color: var(--accent); background: transparent;
  border: 1px solid var(--border); border-radius: 7px;
  padding: 5px 10px;
}
.link-button:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ── style editor drawer ──────────────────────────────────────────────── */

.drawer { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(10, 12, 16, .55); backdrop-filter: blur(2px); }

.drawer-panel {
  position: relative;
  width: min(460px, 100%);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0, 0, 0, .18);
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(20px); opacity: .6; } to { transform: none; opacity: 1; } }

.drawer-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { font-size: 16px; }
.drawer-head p { margin: 3px 0 0; font-size: 12.5px; overflow-wrap: anywhere; }

.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 13px; }

.drawer-foot {
  display: flex; gap: 9px; padding: 14px 18px;
  border-top: 1px solid var(--border); background: var(--surface-2);
}
.drawer-foot .primary { flex: 2; }
.drawer-foot .ghost { flex: 1; padding: 11px; }

.preview-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.preview-frame { margin: 0; position: relative; }
.preview-frame img {
  width: 100%; display: block; border-radius: 7px;
  background: var(--surface-2); aspect-ratio: 9 / 16; object-fit: cover;
  border: 1px solid var(--border);
}
.preview-frame figcaption {
  font-size: 10.5px; color: var(--text-dim); text-align: center; margin-top: 3px;
  font-variant-numeric: tabular-nums;
}
.preview-frame.loading::after {
  content: ''; position: absolute; inset: 0;
  border-radius: 7px; background: var(--surface-2);
  opacity: .55; animation: pulse 1s ease-in-out infinite;
}
.preview-frame.error img { border-color: var(--danger); }

.preview-note { margin: 0; font-size: 11.5px; color: var(--text-dim); line-height: 1.45; }

.field.range > span { display: flex; justify-content: space-between; align-items: baseline; }
.field.range b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

input[type="range"] { padding: 0; height: 22px; background: transparent; border: none; accent-color: var(--accent); }
input[type="range"]:focus { box-shadow: none; }

input[type="color"] {
  padding: 2px; height: 36px; cursor: pointer;
}
input[type="checkbox"] { width: auto; accent-color: var(--accent); }

.inline { display: flex; align-items: center; gap: 8px; }
.inline input[type="color"] { flex: 1; }

.check { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 8px 0; }
.check span { font-weight: 550; }

.save-preset { display: flex; gap: 8px; align-items: center; }
.save-preset input { flex: 1; }
.save-preset .ghost { white-space: nowrap; padding: 9px 12px; font-size: 13px; }

.drawer-panel.wide { width: min(620px, 100%); }

/* ── clip editor (trim + caption text) ────────────────────────────────── */

.ce-video {
  width: 100%; max-height: 320px; display: block;
  background: #000; border-radius: 8px; object-fit: contain;
}

.ce-section { border-top: 1px solid var(--border); padding-top: 14px; }
.ce-section:first-of-type { border-top: none; padding-top: 0; }
.ce-section h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); margin-bottom: 10px; }
.ce-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.ce-head h3 { margin: 0; }

.ce-trim { display: flex; flex-direction: column; gap: 10px; }
.ce-trim-actions { display: flex; align-items: center; gap: 9px; margin-top: 10px; }
.ce-trim-actions .ghost { font-size: 12.5px; padding: 5px 10px; }
.ce-trim-actions .badge { font-variant-numeric: tabular-nums; }

.ce-words {
  display: flex; flex-wrap: wrap; gap: 6px;
  max-height: 260px; overflow-y: auto;
  padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2);
}
.ce-word { display: flex; align-items: center; gap: 3px; }
.ce-word input {
  font-size: 13px; padding: 4px 7px; width: auto; min-width: 4ch;
  background: var(--surface); border-radius: 6px;
}
.ce-word.empty input { border-color: var(--danger); opacity: .6; text-decoration: line-through; }
.ce-word-time {
  font-size: 10px; color: var(--text-dim); cursor: pointer;
  font-variant-numeric: tabular-nums; padding: 2px;
}
.ce-word-time:hover { color: var(--accent); }

#ce-error { margin-top: 4px; }

/* cancel button in the progress header */
.progress-head .cancel {
  background: transparent; border: 1px solid var(--border);
  color: var(--danger); font-size: 12.5px; padding: 4px 10px;
}
.progress-head .cancel:hover { border-color: var(--danger); background: var(--danger-soft); }
.badge.cancelled { background: var(--surface-2); color: var(--warn); }

@media (max-width: 560px) {
  .drawer-panel, .drawer-panel.wide { width: 100%; }
}
