/* ===== Tokens — Studio đen vàng ===== */
:root {
  --bg: #0a0a0c;
  --sidebar: #0e0e11;
  --surface: #141418;
  --surface-raised: #1b1b21;
  --surface-sunken: #0f0f13;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f5f7;
  --text-muted: #9ca0ab;
  --accent: #eab308;
  --accent-strong: #ca8a04;
  --accent-hover: #facc15;
  --accent-text: #facc15;
  --accent-fg: #0b0b0d;
  --accent-soft: rgba(234, 179, 8, 0.11);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.1);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.12);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.1);
  --radius: 12px;
  --radius-sm: 10px;
  --radius-lg: 16px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-lift: 0 24px 60px -32px rgba(0, 0, 0, 0.9);
  --shadow-accent: 0 14px 36px -18px rgba(234, 179, 8, 0.48);
  --ring: 0 0 0 3px rgba(234, 179, 8, 0.28);
  --btn-primary-bg: linear-gradient(180deg, #facc15 0%, #eab308 100%);
  --grain: radial-gradient(1100px 520px at 82% -22%, rgba(234, 179, 8, 0.07), transparent 60%);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #faf9f6;
  --sidebar: #ffffff;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --surface-sunken: #f3f1ec;
  --border: #e6e3dc;
  --border-strong: #d5d0c6;
  --text: #161513;
  --text-muted: #656159;
  --accent: #ca8a04;
  --accent-strong: #a16207;
  --accent-hover: #eab308;
  --accent-text: #854d0e;
  --accent-fg: #111111;
  --accent-soft: rgba(234, 179, 8, 0.12);
  --success: #047857;
  --success-soft: #e8f6ef;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --shadow: 0 1px 2px rgba(22, 21, 19, 0.05);
  --shadow-lift: 0 24px 50px -32px rgba(22, 21, 19, 0.3);
  --shadow-accent: 0 14px 30px -16px rgba(202, 138, 4, 0.35);
  --ring: 0 0 0 3px rgba(202, 138, 4, 0.24);
  --btn-primary-bg: linear-gradient(180deg, #facc15 0%, #eab308 100%);
  --grain: radial-gradient(1000px 460px at 85% -20%, rgba(234, 179, 8, 0.08), transparent 60%);
  color-scheme: light;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--grain);
  background-repeat: no-repeat;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { line-height: 1.2; letter-spacing: -0.02em; margin: 0; }
p { margin: 0; }
a { color: var(--accent-text); }
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.84em;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1px 6px;
}

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.muted { color: var(--text-muted); font-size: 0.9rem; }
.tabular { font-variant-numeric: tabular-nums; }

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  padding: 20px 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
}

.sidebar-top { display: flex; flex-direction: column; gap: 26px; }
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 0 6px; min-width: 0; }
.user-avatar {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--accent-soft);
  border: 1px solid var(--border-strong);
  color: var(--accent-text);
  font-size: 0.78rem; font-weight: 700;
}
.user-pill {
  font-size: 0.85rem; font-weight: 600; color: var(--text-muted);
  max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.sidebar-logout { justify-content: flex-start; width: 100%; }
.inline-form { margin: 0; }

.brand {
  display: inline-flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--text); flex-shrink: 0;
  padding: 0 6px;
}
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--btn-primary-bg); color: var(--accent-fg);
  font-size: 0.72rem; font-weight: 800; letter-spacing: 0.02em;
  display: grid; place-items: center;
  box-shadow: var(--shadow-accent);
}
.brand-name { font-size: 1rem; font-weight: 700; letter-spacing: -0.015em; }

.main-nav { display: flex; flex-direction: column; gap: 4px; }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 500;
  color: var(--text-muted); text-decoration: none;
  min-height: 40px;
  transition: background 0.14s ease, color 0.14s ease;
}
.nav-icon { width: 16px; text-align: center; font-size: 0.95rem; opacity: 0.9; }
.nav-link:hover { color: var(--text); background: var(--surface); }
.nav-link.active {
  color: var(--text); font-weight: 600;
  background: var(--accent-soft);
  box-shadow: inset 2px 0 0 var(--accent);
}
.nav-link.active .nav-icon { color: var(--accent-text); opacity: 1; }

.app-main { min-width: 0; display: flex; flex-direction: column; }

.content-bar {
  position: sticky; top: 0; z-index: 30;
  min-height: 56px; padding: 0 32px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.content-bar-title {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text-muted);
}
.topbar-actions { display: flex; align-items: center; gap: 6px; }
.mobile-logout { display: none; }

.main-wrap { flex: 1; padding-bottom: 48px; }
.canvas-wrap {
  width: 100%; max-width: 1000px;
  margin: 0 auto; padding: 40px 32px 80px;
}

/* ===== Public / auth shell ===== */
.public-bar {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.public-bar-inner {
  min-height: 62px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.container { width: 100%; max-width: 1000px; margin: 0 auto; padding: 0 24px; }
.narrow-wrap { max-width: 440px; padding-top: 10vh; padding-bottom: 64px; }
.share-wrap { padding-top: 36px; padding-bottom: 72px; }

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

.page-head { margin-bottom: 4px; }
.page-head h1 { font-size: 2rem; font-weight: 700; margin-bottom: 6px; }
.page-head .muted { max-width: 60ch; }

/* ===== Controls ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit; font-size: 0.92rem; font-weight: 600;
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease, transform 0.14s ease;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary {
  background: var(--btn-primary-bg);
  color: var(--accent-fg);
  font-weight: 700;
  box-shadow: var(--shadow-accent);
}
.btn-primary:hover:not(:disabled) { filter: brightness(1.06); }
.btn-primary:active:not(:disabled) { transform: translateY(1px); }
.btn-secondary {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { border-color: var(--accent); color: var(--accent-text); }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--surface-raised); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.btn-danger:hover:not(:disabled) { border-color: var(--danger); }
.btn-sm { min-height: 32px; padding: 4px 10px; font-size: 0.83rem; }
.btn-lg { min-height: 50px; padding: 12px 24px; font-size: 1rem; }
.btn-block { width: 100%; }

.btn-spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(0, 0, 0, 0.25);
  border-top-color: var(--accent-fg);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

input[type="text"], input[type="url"], input[type="password"],
input[type="number"], input[type="search"], select {
  width: 100%; min-height: 42px; padding: 9px 12px;
  background: var(--surface-sunken); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font: inherit; font-size: 0.94rem;
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
input::placeholder { color: var(--text-muted); opacity: 0.8; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, summary:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--ring);
}
select { cursor: pointer; }
.checkbox-label {
  display: inline-flex; align-items: center; gap: 9px;
  cursor: pointer; font-size: 0.92rem; min-height: 40px;
}
.checkbox-label input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }
.form-stack { display: flex; flex-direction: column; gap: 16px; margin-top: 24px; }

/* ===== Create workspace ===== */
.create-workspace { display: flex; flex-direction: column; gap: 32px; }
.create-workspace .page-head { margin-bottom: 0; }
.create-workspace .page-head h1 { font-size: 2rem; }

.composer-section { display: flex; flex-direction: column; gap: 12px; }
.url-composer {
  display: flex; align-items: center; gap: 10px;
  min-height: 64px; padding: 8px 8px 8px 16px;
  background: var(--surface-raised);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
.url-composer:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-lift), var(--ring);
}
.composer-icon {
  width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 0.7rem;
}
.url-composer input {
  flex: 1; min-width: 0;
  background: transparent; border: 0; box-shadow: none;
  min-height: 48px; padding: 0; font-size: 1rem;
}
.url-composer input:focus-visible { box-shadow: none; border: 0; }
.url-composer .btn { flex-shrink: 0; min-height: 48px; padding-inline: 20px; }

.field-error { font-size: 0.86rem; color: var(--danger); font-weight: 500; }

/* Source strip after probe */
.source-strip {
  display: flex; align-items: center; gap: 14px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.source-strip-thumb {
  width: 104px; height: 58px; object-fit: cover;
  border-radius: 8px; background: #000; flex-shrink: 0;
}
.source-strip-info { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.source-strip-title {
  font-size: 0.94rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.source-strip-meta {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  font-size: 0.82rem; color: var(--text-muted);
}
.meta-pill {
  display: inline-flex; align-items: center;
  padding: 1px 8px; border-radius: 999px;
  background: var(--surface-sunken); border: 1px solid var(--border);
  font-size: 0.76rem; font-weight: 600; color: var(--text);
}

/* Config columns */
.config-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: 40px;
  align-items: start;
}
.config-block { min-width: 0; margin: 0; padding: 0; border: 0; }
.fieldset-reset { border: 0; }
.fieldset-reset legend { padding: 0; }
.section-label {
  display: block; padding: 0;
  font-size: 0.7rem; font-weight: 700; letter-spacing: 0.13em;
  text-transform: uppercase; color: var(--text-muted);
  margin-bottom: 12px;
}

.segmented-grid { display: grid; gap: 10px; }
.segmented-grid.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.segmented-grid.three-cols { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.segment-option {
  position: relative; display: flex; flex-direction: column; gap: 4px;
  padding: 14px; min-height: 84px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.14s ease, background 0.14s ease;
}
.segment-option:hover { border-color: var(--accent); }
.segment-option input[type="radio"] {
  position: absolute; opacity: 0; width: 1px; height: 1px;
}
.segment-option:has(input:focus-visible) { box-shadow: var(--ring); border-color: var(--accent); }
.segment-option.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.segment-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.segment-title { font-size: 0.92rem; font-weight: 600; line-height: 1.3; }
.segment-desc { font-size: 0.78rem; color: var(--text-muted); line-height: 1.45; }
.segment-check {
  width: 18px; height: 18px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center;
  font-size: 0.66rem; font-weight: 700;
  border: 1px solid var(--border-strong); color: transparent;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.segment-option.active .segment-check {
  background: var(--accent); border-color: var(--accent); color: var(--accent-fg);
}

/* Format tiles */
.format-tile { min-height: 132px; align-items: flex-start; }
.ratio-icon {
  display: block; border: 1.5px solid var(--text-muted); border-radius: 3px;
  margin-bottom: 10px; opacity: 0.75;
}
.ratio-16-9 { width: 30px; height: 17px; }
.ratio-9-16 { width: 17px; height: 30px; }
.ratio-fx {
  display: grid; place-items: center;
  font-size: 11px; color: var(--accent-text);
  border-color: var(--accent-text); opacity: 1;
}
.segment-option.active .ratio-icon { border-color: var(--accent-text); opacity: 1; }
.format-tile .segment-desc { margin-top: 1px; }

/* Inline controls */
.inline-controls { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.control-group { display: flex; flex-direction: column; gap: 8px; }
.control-label-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
}
.control-label-row label { font-size: 0.82rem; font-weight: 600; color: var(--text-muted); }
.pill-group { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.pill-btn {
  min-height: 34px; padding: 5px 13px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 999px; color: var(--text-muted);
  font: inherit; font-size: 0.83rem; font-weight: 600;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  transition: color 0.14s ease, border-color 0.14s ease, background 0.14s ease;
}
.pill-btn:hover { border-color: var(--accent); color: var(--text); }
.pill-btn.active {
  background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text);
}
.number-suffix {
  display: inline-flex; align-items: center; gap: 6px; margin-left: 2px;
  font-size: 0.83rem; color: var(--text-muted);
}
.number-suffix input { width: 76px; min-height: 34px; padding: 4px 8px; font-variant-numeric: tabular-nums; }
.select-compact { max-width: 190px; }
.helper-badge {
  font-size: 0.74rem; font-weight: 600; color: var(--accent-text);
  background: var(--accent-soft); border: 1px solid transparent;
  border-radius: 999px; padding: 2px 9px;
  font-variant-numeric: tabular-nums;
}
.helper-note { font-size: 0.8rem; color: var(--text-muted); }
#aiSplitOptions .helper-note { margin-top: 2px; }

/* Advanced */
.advanced-box { border-top: 1px solid var(--border); padding: 16px 0 0; }
.advanced-box summary {
  cursor: pointer; font-size: 0.86rem; font-weight: 600;
  color: var(--text-muted); list-style: none;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 0; border-radius: var(--radius-sm);
  width: fit-content;
}
.advanced-box summary::-webkit-details-marker { display: none; }
.advanced-box summary::before {
  content: "▸"; font-size: 0.8em;
  transition: transform 0.14s ease;
}
.advanced-box[open] summary::before { transform: rotate(90deg); }
.advanced-box summary:hover { color: var(--text); }
.advanced-body { display: flex; flex-direction: column; gap: 16px; padding: 14px 0 6px; }
.advanced-group { display: flex; flex-direction: column; gap: 12px; }
.advanced-group.two-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.form-footer {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 16px; padding-top: 22px; border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.form-footer .field-error { margin: 0; flex: 1; min-width: 200px; }
.btn-submit { min-width: 210px; }

/* ===== Alerts & status ===== */
.alert {
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-sunken);
  font-size: 0.9rem; display: flex; flex-direction: column; gap: 4px;
}
.alert-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.alert p { color: inherit; opacity: 0.92; }
.alert .btn { align-self: flex-start; margin-top: 4px; }

.status-pill {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: 999px;
  font-size: 0.76rem; font-weight: 600;
  background: var(--surface-sunken); border: 1px solid var(--border);
  color: var(--text-muted); white-space: nowrap;
}
.status-success { background: var(--success-soft); border-color: transparent; color: var(--success); }
.status-warn { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.status-danger { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.status-neutral { background: var(--surface-sunken); color: var(--text-muted); }
.status-accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); }

.progress-track {
  height: 6px; border-radius: 999px;
  background: var(--surface-sunken);
  overflow: hidden;
}
.progress-fill {
  height: 100%; border-radius: inherit;
  background: linear-gradient(90deg, #ca8a04, #facc15);
  transition: width 0.3s ease;
}
:root[data-theme="light"] .progress-fill {
  background: linear-gradient(90deg, #a16207, #eab308);
}

/* ===== Job detail ===== */
.job-detail-card { padding: 28px; }
.detail-top-nav {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 22px; flex-wrap: wrap;
}
.text-link { font-size: 0.88rem; font-weight: 500; text-decoration: none; }
.text-link:hover { text-decoration: underline; }

.detail-header { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 22px; }
.detail-thumb {
  width: 116px; height: 65px; object-fit: cover;
  border-radius: var(--radius-sm); background: #000; flex-shrink: 0;
}
.detail-title-col { min-width: 0; flex: 1; }
.detail-title-col h1 {
  font-size: 1.3rem; margin: 8px 0 6px;
  overflow-wrap: anywhere;
}
.detail-badges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.meta-text { font-size: 0.8rem; color: var(--text-muted); }

.stage-box {
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.stage-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 12px; flex-wrap: wrap;
}
.stage-head strong { font-size: 0.96rem; font-weight: 600; }
.stage-box .progress-track { margin-bottom: 14px; }

.step-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  font-size: 0.8rem; color: var(--text-muted);
}
.step-list li { display: inline-flex; align-items: center; gap: 7px; }
.step-list li::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--border-strong); flex-shrink: 0;
}
.step-list li.is-done { color: var(--text); }
.step-list li.is-done::before { background: var(--success); }
.step-list li.is-current { color: var(--accent-text); font-weight: 600; }
.step-list li.is-current::before {
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.step-list li.is-error { color: var(--danger); }
.step-list li.is-error::before { background: var(--danger); }

.share-ready-box {
  margin-top: 18px; padding: 18px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 10px;
}
.share-ready-info strong { font-size: 0.92rem; color: var(--accent-text); }
.share-ready-info p { font-size: 0.82rem; color: var(--text); }
.share-url-bar { display: flex; gap: 8px; flex-wrap: wrap; }
.share-url-bar input { flex: 1; min-width: 180px; font-size: 0.86rem; }

.detail-actions { margin-top: 20px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.job-detail-card .alert { margin-top: 18px; }

/* ===== History ===== */
.history-top {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; margin-bottom: 24px; flex-wrap: wrap;
}
.history-top h1 { font-size: 2rem; font-weight: 700; margin-bottom: 4px; }
.history-panel { padding: 0; overflow: hidden; }
.history-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; padding: 16px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.search-box { flex: 1; min-width: 220px; max-width: 400px; }
.search-box input { background: var(--surface-sunken); }
.filter-tabs {
  display: flex; gap: 2px; flex-wrap: wrap;
  background: var(--surface-sunken); padding: 3px;
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.filter-tab {
  padding: 5px 11px; border: 0; border-radius: 7px;
  background: transparent; color: var(--text-muted);
  font: inherit; font-size: 0.81rem; font-weight: 500;
  cursor: pointer; min-height: 30px;
  transition: background 0.14s ease, color 0.14s ease;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active {
  background: var(--surface-raised); color: var(--text);
  font-weight: 600; box-shadow: var(--shadow);
}

.history-list { display: flex; flex-direction: column; }
.history-item {
  display: flex; align-items: center; gap: 14px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.14s ease;
}
.history-item:hover { background: var(--surface-sunken); }
.history-item:last-child { border-bottom: 0; }
.history-thumb {
  width: 104px; height: 58px; object-fit: cover;
  border-radius: 8px; background: var(--surface-sunken);
  flex-shrink: 0;
}
.history-thumb-empty {
  width: 104px; height: 58px; border-radius: 8px;
  background: var(--surface-sunken); border: 1px solid var(--border);
  flex-shrink: 0;
}
.history-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.history-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.history-title {
  margin: 0; font-size: 0.96rem; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.history-title a { color: var(--text); text-decoration: none; }
.history-title a:hover { color: var(--accent-text); }
.history-meta { font-size: 0.8rem; color: var(--text-muted); }
.history-share-row { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.history-share-row input {
  min-height: 30px; padding: 3px 8px;
  font-size: 0.78rem; background: var(--surface-sunken);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.history-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.history-footer {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 16px;
  border-top: 1px solid var(--border); flex-wrap: wrap;
}
.history-panel > .alert { margin: 14px 16px; }
.history-panel > .alert .btn { align-self: center; }

.empty-state {
  padding: 52px 20px; text-align: center;
  color: var(--text-muted); font-size: 0.92rem;
}
.empty-state strong { display: block; color: var(--text); margin-bottom: 4px; font-size: 0.98rem; }

/* ===== Share ===== */
.share-header-card { padding: 26px; margin-bottom: 22px; }
.share-header-main h1 { font-size: 1.45rem; overflow-wrap: anywhere; }
.share-meta-line {
  display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
  margin-top: 8px; font-size: 0.88rem; color: var(--text-muted);
}
.countdown-box strong { font-variant-numeric: tabular-nums; color: var(--text); }
.share-header-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.share-url-input {
  flex: 1; min-width: 180px; font-size: 0.86rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-sunken);
}
.share-header-card .helper-note { color: var(--success); font-weight: 500; margin-top: 8px; }

.clips-grid {
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.clip-card { overflow: hidden; display: flex; flex-direction: column; }
.clip-player-box {
  background: #000; aspect-ratio: 16 / 9;
  display: flex; align-items: center; justify-content: center;
}
.clip-player-box.is-vertical { aspect-ratio: 9 / 16; max-height: 460px; }
.clip-player-box video { width: 100%; height: 100%; object-fit: contain; }
.clip-body { padding: 16px; display: flex; flex-direction: column; gap: 10px; flex: 1; }
.clip-top-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; font-size: 0.8rem;
}
.part-tag { font-weight: 700; color: var(--accent-text); font-variant-numeric: tabular-nums; }
.clip-title { font-size: 1rem; font-weight: 600; overflow-wrap: anywhere; }
.clip-body .btn { margin-top: auto; }

.state-card { padding: 48px 32px; text-align: center; max-width: 560px; margin: 40px auto; }
.state-card h1 { font-size: 1.35rem; margin: 12px 0 8px; }
.state-card .progress-track { margin: 18px auto 8px; max-width: 320px; }
.state-meta { margin-top: 16px; font-size: 0.85rem; color: var(--text-muted); }

/* ===== Auth ===== */
.auth-card { padding: 32px; }

/* ===== Responsive ===== */
@media (max-width: 900px) {
  .config-columns { grid-template-columns: 1fr; gap: 28px; }
}

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

  .sidebar {
    position: static; height: auto;
    padding: 12px 16px;
    border-right: 0; border-bottom: 1px solid var(--border);
    gap: 12px;
  }
  .sidebar-top { gap: 10px; }
  .sidebar-foot { display: none; }
  .brand { padding: 0; }
  .main-nav { flex-direction: row; gap: 6px; }
  .nav-link { flex: 1; justify-content: center; min-height: 42px; }
  .nav-link.active { box-shadow: inset 0 -2px 0 var(--accent); background: var(--accent-soft); }

  .content-bar { padding: 0 16px; position: static; }
  .mobile-logout { display: inline-flex; }
  .canvas-wrap { padding: 26px 16px 56px; }
  .page-head h1, .create-workspace .page-head h1, .history-top h1 { font-size: 1.55rem; }

  .url-composer { flex-wrap: wrap; padding: 10px; min-height: 0; }
  .url-composer .composer-icon { display: none; }
  .url-composer input {
    flex-basis: 100%; min-height: 44px; padding: 0 6px;
  }
  .url-composer .btn { width: 100%; }

  .segment-option { min-height: 0; }
  .format-tile { min-height: 0; }

  .advanced-group.two-cols { grid-template-columns: 1fr; }

  .form-footer {
    position: sticky; bottom: 0; z-index: 20;
    margin: 8px -16px -26px;
    padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
    background: var(--bg);
    border-top: 1px solid var(--border);
    justify-content: stretch;
  }
  .form-footer .field-error { flex-basis: 100%; }
  .btn-submit { width: 100%; }

  .detail-header { flex-direction: column; gap: 12px; }
  .detail-thumb { width: 100%; height: 168px; }
  .job-detail-card { padding: 20px; }

  .history-toolbar { flex-direction: column; align-items: stretch; }
  .search-box { max-width: none; }
  .history-item { align-items: flex-start; flex-wrap: wrap; }
  .history-thumb, .history-thumb-empty { width: 72px; height: 41px; }
  .history-title { white-space: normal; }
  .history-actions { width: 100%; flex-direction: row; justify-content: flex-end; margin-top: 4px; }
  .history-share-row { flex-wrap: wrap; }

  .share-url-bar .btn { flex: 1; }
  .clips-grid { grid-template-columns: 1fr; }
  .clip-player-box.is-vertical { max-height: 560px; }
  .share-header-card { padding: 20px; }
  .container { padding: 0 16px; }
}

.user-form-card { padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.users-list-panel { margin-top: 24px; }
.user-item { align-items: center; }
.alert-success {
  background: var(--success-soft);
  border-color: rgba(52, 211, 153, 0.35);
  color: var(--success);
  margin-bottom: 18px;
}

@media (max-width: 380px) {
  .canvas-wrap { padding-inline: 12px; }
  .container { padding: 0 12px; }
  .content-bar { padding: 0 12px; }
  .segmented-grid.three-cols { gap: 8px; }
  .segment-option { padding: 12px 10px; }
  .segment-title { font-size: 0.86rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
