/* =====================================================================
   AutoSu Studio — styles
   Vanilla CSS, no framework. Theme via CSS variables.
   ===================================================================== */

* { box-sizing: border-box; }

:root {
  /* Dark theme (default) */
  --bg: #08090b;
  --bg-elev: #111316;
  --bg-elev-2: #181a1e;
  --border: #2a2d32;
  --border-soft: #202328;
  --text: #f4f4f1;
  --text-dim: #a4a7ad;
  --text-faint: #747880;
  --primary: #f4d32b;
  --primary-fg: #141300;
  --primary-hover: #ffe04a;
  --accent: #f4d32b;
  --err: #f85149;
  --danger: #f85149;
  --success: #3fb950;
  --warning: #d29922;
  --info: #58a6ff;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans Thai", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="light"] {
  --bg: #ffffff;
  --bg-elev: #f6f8fa;
  --bg-elev-2: #eef1f4;
  --border: #d0d7de;
  --border-soft: #e6eaef;
  --text: #1f2328;
  --text-dim: #59636e;
  --text-faint: #818b98;
  --primary: #d4a017;
  --primary-fg: #1f2328;
  --primary-hover: #b88a0c;
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
}

[data-theme="accent"] {
  --bg: #0f111a;
  --bg-elev: #1a1d2b;
  --bg-elev-2: #252938;
  --border: #2d3344;
  --text: #e7eaf3;
  --primary: #ff5e8a;
  --primary-fg: #0f111a;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  max-width: 100%;
  overflow-x: hidden;
  color-scheme: dark;
}

a { color: var(--info); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

.hidden { display: none !important; }

/* =====================================================================
   Loading screen
   ===================================================================== */
.app-loading {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--bg);
  z-index: 1000;
  gap: 1rem;
  color: var(--text-dim);
}
.loading-spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =====================================================================
   Auth screen
   ===================================================================== */
.auth-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
  padding: 1rem;
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}
.auth-brand {
  text-align: center;
  margin-bottom: 1.5rem;
}
.auth-icon { font-size: 2.5rem; }
.auth-brand h1 { margin: 0.5rem 0 0.25rem; font-size: 1.5rem; }
.auth-tagline { color: var(--text-dim); margin: 0; font-size: 0.9rem; }
.auth-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem;
}
.auth-tab {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 0.75rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.auth-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.auth-form { display: flex; flex-direction: column; gap: 1rem; }
.auth-field { display: flex; flex-direction: column; gap: 0.35rem; }
.auth-field label { font-size: 0.85rem; color: var(--text-dim); }
.auth-field input {
  padding: 0.65rem 0.75rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.auth-field input:focus { outline: none; border-color: var(--primary); }
.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
}
.auth-footer { text-align: center; color: var(--text-faint); font-size: 0.8rem; margin-top: 1rem; }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.15s;
}
.btn:hover { background: var(--border-soft); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: var(--primary-fg);
  border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--bg-elev-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-icon {
  background: none; border: none; padding: 0.4rem;
  cursor: pointer; font-size: 1.1rem;
}

/* =====================================================================
   App shell (header + main)
   ===================================================================== */
.app-shell {
  min-height: 100vh;
  display: flex; flex-direction: column;
}
.app-header {
  display: flex; align-items: center; gap: 1.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.app-brand { display: flex; align-items: center; gap: 0.5rem; font-weight: 600; }
.brand-icon { font-size: 1.3rem; }
.app-nav { display: flex; gap: 0.5rem; flex: 1; }
.nav-link {
  color: var(--text-dim);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.nav-link:hover { background: var(--bg-elev-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--bg-elev-2); color: var(--primary); }
.app-user { display: flex; align-items: center; gap: 0.5rem; }
.user-email { color: var(--text-dim); font-size: 0.9rem; }

.app-main {
  flex: 1;
  max-width: 960px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem;
}

/* =====================================================================
   Views
   ===================================================================== */
.view-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.5rem;
}
.view-header h2 { margin: 0; font-size: 1.4rem; }
.view-sub { color: var(--text-dim); margin: 0.25rem 0 0; font-size: 0.9rem; }

/* =====================================================================
   Panels
   ===================================================================== */
.panel {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1rem;
  overflow: hidden;
}
.panel-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev-2);
}
.panel-title { font-weight: 500; }
.panel-body { padding: 1rem; }

/* =====================================================================
   Dropzone
   ===================================================================== */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
  background: var(--bg-elev-2);
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--primary);
  background: var(--bg-elev);
}
.dropzone-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.dropzone-text { font-size: 1rem; margin-bottom: 0.25rem; }
.dropzone-hint { color: var(--text-faint); font-size: 0.85rem; }

.upload-progress { margin-top: 1rem; }
.upload-progress-label {
  display: flex; justify-content: space-between;
  font-size: 0.85rem; color: var(--text-dim);
  margin-bottom: 0.4rem;
}

/* Progress bar */
.progress-bar {
  height: 6px;
  background: var(--bg-elev-2);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s;
}

/* =====================================================================
   Template picker
   ===================================================================== */
.template-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.template-card {
  border: 2px solid var(--border);
  background: var(--bg-elev-2);
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.5rem;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  display: flex; flex-direction: column; gap: 0.35rem;
}
.template-card:hover { border-color: var(--text-faint); }
.template-card.selected {
  border-color: var(--primary);
  background: var(--bg-elev);
}
.template-card .template-sample {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.4rem 0.3rem;
  border-radius: 3px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.1;
  min-height: 2.4em;
  display: flex; align-items: center; justify-content: center;
}
.template-card .template-name {
  font-size: 0.85rem; color: var(--text);
  font-weight: 500;
}
.template-card .template-id {
  font-size: 0.7rem; color: var(--text-faint);
  font-family: var(--mono);
}

/* Subtitle style samples (visual approximation) */
.template-card .sample-default  { color: #fff; text-shadow: 1px 1px 0 #000, -1px 1px 0 #000, 1px -1px 0 #000, -1px -1px 0 #000; }
.template-card .sample-outline  { color: #fff; text-shadow: 2px 2px 0 #000; font-weight: 800; }
.template-card .sample-yellow   { color: #FFE84D; text-shadow: 1px 1px 0 #111; }
.template-card .sample-neon     { color: #0ff; text-shadow: 0 0 4px #0ff, 0 0 8px #0aa; }
.template-card .sample-blue     { color: #fff; text-shadow: 0 0 4px #58a6ff, 0 0 10px #1f6feb; }
.template-card .sample-box      { color: #fff; background: #000; padding: 4px 6px; border-radius: 3px; }
.template-card .sample-sticker  { color: #fff; background: linear-gradient(180deg, #ff8fb1, #ff5e8a); padding: 4px 6px; border-radius: 12px; }
.template-card .sample-green    { color: #3fb950; text-shadow: 1px 1px 0 #000; }
.template-card .sample-karaoke  { color: #ff5e8a; text-shadow: 1px 1px 0 #000; font-weight: 800; }
.template-card .sample-gold     { color: #ffd23f; text-shadow: 1px 1px 0 #6b4f00, 2px 2px 0 #6b4f00; font-weight: 800; }
.template-card .sample-comic    { color: #ff0; text-shadow: 2px 2px 0 #000; font-size: 1rem; }
.template-card .sample-red      { color: #f85149; background: rgba(0,0,0,0.6); padding: 4px 6px; }
.template-card .sample-purple   { color: #c084fc; text-shadow: 1px 1px 0 #000; }
.template-card .sample-ice      { color: #a5f3fc; text-shadow: 0 0 4px #06b6d4; }
.template-card .sample-orange   { color: #fb923c; background: rgba(0,0,0,0.5); padding: 4px 6px; }
.template-card .sample-white-shadow { color: #fff; text-shadow: 0 2px 4px rgba(0,0,0,0.6); }
.template-card .sample-black-label { color: #fff; background: #000; padding: 4px 8px; font-weight: 800; }
.template-card .sample-pixel    { color: #0f0; font-family: monospace; background: #000; padding: 4px; }
.template-card .sample-pastel   { color: #fbcfe8; text-shadow: 1px 1px 0 rgba(0,0,0,0.3); }
.template-card .sample-lime     { color: #bef264; text-shadow: 1px 1px 0 #000; font-weight: 800; }
.template-card .sample-random   { background: linear-gradient(45deg, #ff5e8a, #ffd23f); color: #fff; padding: 4px; }

/* =====================================================================
   Advanced settings (collapsible)
   ===================================================================== */
.advanced-toggle {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  margin-top: 0.5rem;
}
.advanced-toggle summary {
  cursor: pointer; color: var(--text-dim);
  font-size: 0.9rem;
}
.advanced-toggle[open] summary { margin-bottom: 0.75rem; }
.advanced-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}
.advanced-grid label {
  display: flex; flex-direction: column; gap: 0.25rem;
  font-size: 0.85rem; color: var(--text-dim);
}
.advanced-grid input, .advanced-grid select {
  padding: 0.4rem 0.5rem;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.form-hint { color: var(--text-faint); font-size: 0.8rem; margin-top: 0.5rem; }

/* =====================================================================
   Developer / API tokens / code snippets
   ===================================================================== */
.code-inline {
  display: inline-block;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--accent);
  margin: 0 0.5rem;
  word-break: break-all;
}
.token-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.token-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.8rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.token-item-meta { flex: 1; }
.token-item-name { font-weight: 600; }
.token-item-prefix {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: 0.15rem;
}
.token-item-time {
  font-size: 0.72rem;
  color: var(--text-faint);
  margin-top: 0.15rem;
}
.token-item-actions { display: flex; gap: 0.4rem; }
.snippet-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.4rem;
}
.snippet-tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-faint);
  padding: 0.35rem 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.snippet-tab:hover { color: var(--text); }
.snippet-tab.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
  font-weight: 600;
}
.snippet-frame {
  position: relative;
  background: #0a0d12;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow: auto;
}

/* =====================================================================
   History (filter + search + bulk actions)
   ===================================================================== */
.history-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1rem;
  align-items: start;
}
@media (max-width: 720px) {
  .history-layout { grid-template-columns: 1fr; }
}
.history-filters {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  position: sticky;
  top: 1rem;
}
.filter-group { margin-bottom: 0.9rem; }
.filter-group:last-child { margin-bottom: 0; }
.filter-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-faint);
  margin-bottom: 0.4rem;
  font-weight: 700;
}
.radio-row, .check-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  padding: 0.18rem 0;
  cursor: pointer;
  color: var(--text);
}
.radio-row input, .check-row input { cursor: pointer; }
.filter-group input[type="search"],
.filter-group input[type="date"],
.filter-group select {
  width: 100%;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
  font-family: inherit;
}
.filter-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.history-results {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-width: 0;
}
.history-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex-wrap: wrap;
  gap: 0.5rem;
}
.hist-count {
  font-size: 0.85rem;
  color: var(--text-faint);
  margin-right: 0.7rem;
}
.bulk-row { font-size: 0.85rem; color: var(--text-faint); }
.bulk-actions { display: flex; gap: 0.4rem; }
.hist-table {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 200px;
}
.hist-row {
  display: grid;
  grid-template-columns: 32px 110px 80px 1fr 100px 100px 110px;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.1s;
}
.hist-row:hover { background: var(--bg); }
.hist-row.selected { background: rgba(255, 215, 0, 0.08); }
.hist-row:last-child { border-bottom: none; }
.hist-row.hist-head {
  background: var(--bg);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-faint);
  font-weight: 700;
  cursor: default;
}
.hist-row.hist-head:hover { background: var(--bg); }
.hist-row.hist-empty {
  cursor: default;
  color: var(--text-faint);
  text-align: center;
  padding: 1.5rem 0.75rem;
  display: block;
}
.hist-row.hist-empty:hover { background: var(--bg-elev); }
.hist-when { color: var(--text-faint); font-size: 0.78rem; }
.hist-file {
  font-family: var(--mono);
  font-size: 0.8rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hist-badge { font-size: 0.72rem; padding: 0.18rem 0.45rem; }
.hist-pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.5rem;
  font-size: 0.82rem;
  color: var(--text-faint);
}
input[type="date"].hidden { display: none; }

/* =====================================================================
   Cues editor (job detail)
   ===================================================================== */
.cues-list {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  max-height: 480px;
  overflow-y: auto;
}
.cue-row {
  display: grid;
  grid-template-columns: 40px 110px 1fr 60px;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.cue-row:hover { background: var(--bg-elev); }
.cue-row.cue-editing { background: rgba(255,215,0,0.06); border-color: var(--accent); }
.cue-idx { color: var(--text-faint); font-family: var(--mono); }
.cue-time { font-family: var(--mono); font-size: 0.78rem; color: var(--text-faint); }
.cue-text {
  font-family: var(--mono);
  white-space: pre-wrap;
  word-break: break-word;
}
.cue-text textarea {
  width: 100%;
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.5rem;
  font-family: var(--mono);
  font-size: 0.88rem;
  resize: vertical;
  min-height: 2.4rem;
}
.cue-actions { display: flex; gap: 0.2rem; }
.cue-actions .btn { padding: 0.2rem 0.5rem; font-size: 0.78rem; }

/* =====================================================================
   Connection indicator (job detail live status)
   ===================================================================== */
.conn-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.02em;
  transition: all 0.2s ease;
}
.conn-live {
  border-color: #3ecf8e;
  color: #3ecf8e;
  animation: live-pulse 2s ease-in-out infinite;
}
.conn-polling {
  border-color: #f0b54c;
  color: #f0b54c;
}
.conn-idle {
  border-color: var(--border);
  color: var(--text-faint);
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}
.view-header-right {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* =====================================================================
   Drag and drop upload
   ===================================================================== */
.upload-dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text-faint);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  margin: 0.5rem 0;
}
.upload-dropzone:hover {
  border-color: var(--accent);
  color: var(--text);
}
.upload-dropzone.is-dragover {
  border-color: var(--primary);
  background: rgba(255, 215, 102, 0.05);
  color: var(--primary);
  transform: scale(1.01);
}
.upload-dropzone .dz-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}
.upload-dropzone .dz-text {
  font-size: 0.95rem;
  font-weight: 600;
}
.upload-dropzone .dz-hint {
  font-size: 0.75rem;
  margin-top: 0.3rem;
  color: var(--text-faint);
}
.upload-dropzone .dz-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}
.upload-queue {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
}
.upload-queue-row {
  display: grid;
  grid-template-columns: 1fr 70px 90px 30px;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.7rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.upload-queue-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--mono);
}
.upload-queue-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.upload-queue-bar > div {
  height: 100%;
  background: var(--primary);
  transition: width 0.2s;
}
.upload-queue-pct {
  text-align: right;
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-faint);
}
.upload-queue-remove {
  background: none;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0;
}
.upload-queue-remove:hover {
  color: #ff6b6b;
}

/* =====================================================================
   Dashboard
   ===================================================================== */
.dash-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.7rem;
  margin-bottom: 0.9rem;
}
.dash-kpi {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  position: relative;
  overflow: hidden;
}
.dash-kpi::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}
.dash-kpi.kpi-ok::before { background: #3ecf8e; }
.dash-kpi.kpi-err::before { background: #ff6b6b; }
.dash-kpi.kpi-info::before { background: #5aa9ff; }
.dash-kpi-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 700;
  margin-bottom: 0.3rem;
}
.dash-kpi-value {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.1;
  font-family: var(--mono);
}
.dash-kpi-sub {
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-top: 0.2rem;
}
.dash-actions {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.dash-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 0.8rem;
}
.dash-grid > .panel:nth-child(3) { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
}
.dash-recent { display: flex; flex-direction: column; gap: 0.4rem; }
.dash-recent-row {
  display: grid;
  grid-template-columns: 90px 1fr 90px;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.1s;
}
.dash-recent-row:hover { background: var(--bg-elev); }
.dash-recent-time { color: var(--text-faint); font-size: 0.78rem; font-family: var(--mono); }
.dash-recent-file { font-family: var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-recent-status { text-align: right; }
.dash-template-card {
  text-align: center;
  padding: 1.2rem 0.5rem;
}
.dash-template-card .big-template {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0.3rem 0;
}
.dash-template-card .preview-box {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  background: #0a0d12;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 1.05rem;
  margin: 0.4rem 0 0.8rem 0;
  color: #ffd866;
}
.dash-windows {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
}
.dash-window {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.dash-window-label {
  font-size: 0.72rem;
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.dash-window-value {
  font-size: 1.4rem;
  font-weight: 600;
  font-family: var(--mono);
}
.dash-admin {
  margin-top: 1rem;
}
.admin-top-users {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-top: 0.4rem;
}
.admin-top-user {
  display: grid;
  grid-template-columns: 1fr 80px 120px;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}
.admin-top-user-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.admin-top-user-bar > div {
  height: 100%;
  background: var(--accent);
}
@media (max-width: 700px) {
  .dash-recent-row { grid-template-columns: 1fr; }
  .dash-windows { gap: 0.8rem; }
}
.snippet-frame pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.5;
  color: #d6e2ee;
  white-space: pre-wrap;
  word-break: break-word;
}
.snippet-copy {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  z-index: 2;
}
.btn-sm {
  font-size: 0.78rem;
  padding: 0.3rem 0.7rem;
}
.token-revealed {
  background: #0a0d12;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.85rem;
  margin-bottom: 0.75rem;
}
.token-revealed-label {
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-bottom: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.token-revealed-value {
  font-family: var(--mono);
  font-size: 0.92rem;
  color: #ffd866;
  word-break: break-all;
  user-select: all;
}

/* =====================================================================
   Jobs list
   ===================================================================== */
.jobs-list { display: flex; flex-direction: column; gap: 0.5rem; }
.job-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 1rem;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: all 0.15s;
}
.job-row:hover { border-color: var(--text-faint); }
.job-row-info { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.job-row-filename { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job-row-meta { color: var(--text-dim); font-size: 0.8rem; }
.job-row-status { display: flex; flex-direction: column; align-items: flex-end; gap: 0.25rem; }

.empty-state {
  text-align: center; padding: 3rem 1rem;
  color: var(--text-dim);
  background: var(--bg-elev);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}
.badge-pending { background: rgba(88, 166, 255, 0.15); color: var(--info); border-color: var(--info); }
.badge-running { background: rgba(210, 153, 34, 0.15); color: var(--warning); border-color: var(--warning); }
.badge-done    { background: rgba(63, 185, 80, 0.15); color: var(--success); border-color: var(--success); }
.badge-error   { background: rgba(248, 81, 73, 0.15); color: var(--danger); border-color: var(--danger); }
.badge-cancelled { background: var(--bg-elev-2); color: var(--text-faint); }

/* =====================================================================
   Job detail
   ===================================================================== */
.job-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.job-meta > div { color: var(--text-dim); }
.job-meta strong { color: var(--text); font-weight: 500; }
.job-progress { margin: 1rem 0; }
.job-progress-msg { color: var(--text-dim); font-size: 0.85rem; margin-top: 0.4rem; }
.job-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }
.job-events {
  max-height: 400px; overflow-y: auto;
  font-family: var(--mono);
  font-size: 0.8rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
}
.job-event { padding: 0.2rem 0; color: var(--text-dim); }
.job-event .ts { color: var(--text-faint); margin-right: 0.5rem; }
.job-event.error { color: var(--danger); }
.job-event.warn { color: var(--warning); }

/* =====================================================================
   Forms (settings)
   ===================================================================== */
.form-row {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}
.form-row label { color: var(--text-dim); min-width: 140px; }
.form-row input, .form-row select {
  padding: 0.4rem 0.5rem;
  background: var(--bg-elev-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  flex: 1;
}

.managed-note {
  margin: 0 0 1rem;
  color: var(--text-dim);
  line-height: 1.55;
}

.managed-defaults {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.65rem;
  margin: 0;
}

.managed-defaults > div {
  padding: 0.75rem;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.managed-defaults dt {
  margin-bottom: 0.2rem;
  color: var(--text-faint);
  font-size: 0.76rem;
}

.managed-defaults dd {
  margin: 0;
  color: var(--text);
  font-weight: 600;
  overflow-wrap: anywhere;
}

/* =====================================================================
   Toasts
   ===================================================================== */
.toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  display: flex; flex-direction: column; gap: 0.5rem;
  z-index: 1000;
  max-width: 360px;
}
.toast {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
  color: var(--text);
  animation: toast-in 0.2s;
}
.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-info { border-left: 3px solid var(--info); }
@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* =====================================================================
   Responsive
   ===================================================================== */
@media (max-width: 640px) {
  .app-header { flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 0.75rem; }
  .app-nav { order: 3; width: 100%; }
  .app-main { padding: 1rem; }
  .job-row { grid-template-columns: 1fr; gap: 0.5rem; }
  .job-row-status { align-items: flex-start; }
  .user-email { display: none; }
  .template-picker { grid-template-columns: repeat(2, 1fr); }
  .managed-defaults { grid-template-columns: 1fr; }
  .form-row { align-items: flex-start; }
  .form-row label { flex: 0 0 120px; min-width: 120px; }
  .form-row > span,
  .form-row input,
  .form-row select { min-width: 0; overflow-wrap: anywhere; }
}

/* =====================================================================
   TEMPLATE PREVIEW — Sprint 2
   ===================================================================== */
.btn-preview-tpl {
  display: block;
  margin: 0.4rem auto 0;
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  background: rgba(0, 0, 0, 0.05);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 4px;
  cursor: pointer;
  color: inherit;
  transition: background 0.15s, transform 0.1s;
}
.btn-preview-tpl:hover { background: rgba(0, 0, 0, 0.12); }
.btn-preview-tpl:active { transform: scale(0.95); }
.template-card.selected .btn-preview-tpl { background: var(--accent, #3a7afe); color: #fff; border-color: transparent; }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  animation: fadeIn 0.18s ease-out;
}
.modal-backdrop.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }

.modal-box {
  background: var(--bg-elev, #1a1a1a);
  color: var(--text, #eaeaea);
  border-radius: 12px;
  max-width: 90vw; width: 720px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  animation: popIn 0.18s ease-out;
}
@keyframes popIn { from { transform: scale(0.95); opacity: 0 } to { transform: scale(1); opacity: 1 } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.modal-header h3 { margin: 0; font-size: 1.1rem; }
.modal-header button { background: none; border: none; font-size: 1.6rem; line-height: 1; color: inherit; cursor: pointer; opacity: 0.6; padding: 0 0.5rem; }
.modal-header button:hover { opacity: 1; }
.modal-body { padding: 1rem 1.25rem; flex: 1; overflow: auto; }
.modal-footer {
  padding: 0.75rem 1.25rem; border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.85rem; opacity: 0.75;
}
.tpl-preview-box { max-width: 640px; }
.tpl-preview-video { width: 100%; max-height: 60vh; border-radius: 8px; background: #000; display: block; }
.tpl-preview-loading { padding: 3rem 1rem; text-align: center; opacity: 0.6; }
.tpl-preview-error { padding: 2rem 1rem; text-align: center; color: #f44; }
.tpl-preview-note { font-size: 0.8rem; opacity: 0.6; text-align: center; margin: 0.5rem 0 0; }
.tpl-preview-meta { font-size: 0.8rem; opacity: 0.7; }

/* =====================================================================
   COMPARE BEFORE/AFTER — Sprint 2
   ===================================================================== */
.cmp-view { display: grid; gap: 0.5rem; }
.cmp-view.cmp-side  { grid-template-columns: 1fr 1fr; }
.cmp-view.cmp-stack { grid-template-columns: 1fr; }
.cmp-view.cmp-diff  { grid-template-columns: 1fr; }
.cmp-pane { position: relative; }
.cmp-label {
  position: absolute; top: 0.5rem; left: 0.5rem;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  z-index: 2;
  pointer-events: none;
}
.cmp-video {
  width: 100%;
  border-radius: var(--radius-sm, 6px);
  background: #000;
  display: block;
  max-height: 480px;
}
.cmp-view.cmp-stack .cmp-video { max-height: 360px; }
.cmp-view.cmp-diff .cmp-video {
  position: relative;
  /* Overlay mode: stack them on top of each other with mix-blend */
}
.cmp-view.cmp-diff .cmp-pane:first-child { display: none; }
.cmp-view.cmp-diff .cmp-pane:last-child::before {
  content: "";
  position: absolute; inset: 0;
  background: rgba(255, 0, 0, 0.4);
  mix-blend-mode: difference;
  pointer-events: none;
}
.compare-layout-picker { display: flex; gap: 0.15rem; background: rgba(0,0,0,0.05); border-radius: 6px; padding: 0.1rem; }
.compare-layout-picker .btn { padding: 0.2rem 0.5rem; min-width: 32px; }
.compare-layout-picker .btn.active { background: var(--accent, #3a7afe); color: #fff; }

@media (max-width: 768px) {
  .cmp-view.cmp-side { grid-template-columns: 1fr; }
}

/* =====================================================================
   PREFLIGHT WARNINGS — Sprint 2
   ===================================================================== */
.preflight-panel {
  background: var(--bg, #1a1a1a);
  border: 1px solid var(--border, #333);
  border-radius: var(--radius-sm, 6px);
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.8rem;
  font-size: 0.85rem;
}
.preflight-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.preflight-eta {
  font-weight: 600;
  color: var(--text, #eaeaea);
  font-size: 0.9rem;
}
.preflight-system {
  font-size: 0.75rem;
  opacity: 0.6;
}
.preflight-warnings { display: flex; flex-direction: column; gap: 0.3rem; }
.preflight-ok {
  color: #4ade80;
  font-size: 0.85rem;
}
.preflight-warn {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 0.4rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  line-height: 1.4;
}
.preflight-info { background: rgba(59, 130, 246, 0.12); color: #93c5fd; }
.preflight-warn.preflight-warn { background: rgba(245, 158, 11, 0.12); color: #fbbf24; }
.preflight-error { background: rgba(239, 68, 68, 0.15); color: #fca5a5; font-weight: 500; }
.pw-icon { flex-shrink: 0; }
.pw-msg { flex: 1; }

/* =====================================================================
   AI TEMPLATE SUGGESTER — Sprint 3
   ===================================================================== */
.ai-suggest-panel {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.06), rgba(168, 85, 247, 0.06));
  border: 1px solid rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-sm, 6px);
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.8rem;
  font-size: 0.85rem;
}
.ai-suggest-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  gap: 0.5rem;
}
.ai-suggest-title {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text, #eaeaea);
}
.ai-suggest-source {
  font-size: 0.7rem;
  opacity: 0.6;
}
.ai-suggest-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}
.ai-suggest-card {
  background: var(--bg, #1a1a1a);
  border: 1px solid var(--border, #333);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  transition: all 0.15s;
}
.ai-suggest-card:hover { border-color: rgba(99, 102, 241, 0.5); transform: translateY(-1px); }
.ai-suggest-card.applied { border-color: #4ade80; background: rgba(74, 222, 128, 0.05); }
.ai-suggest-sample {
  font-size: 1.5rem;
  font-weight: 800;
  text-align: center;
  padding: 0.3rem 0;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.3);
}
.ai-suggest-name {
  font-weight: 600;
  font-size: 0.85rem;
}
.ai-suggest-reason {
  font-size: 0.72rem;
  opacity: 0.7;
  line-height: 1.35;
  flex: 1;
}
.ai-suggest-apply { width: 100%; }
.ai-suggest-loading,
.ai-suggest-error {
  padding: 1rem;
  text-align: center;
  opacity: 0.6;
  font-size: 0.85rem;
}
.ai-suggest-error { color: #fca5a5; }
@media (max-width: 640px) {
  .ai-suggest-grid { grid-template-columns: 1fr; }
}

/* =====================================================================
   WIZARD STEPPER — Sprint 3
   ===================================================================== */
.wizard-stepper {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.8rem 0.5rem;
  margin-bottom: 1rem;
  background: var(--bg, #1a1a1a);
  border: 1px solid var(--border, #333);
  border-radius: var(--radius, 8px);
  flex-wrap: wrap;
}
.wizard-step {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--text, #eaeaea);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  opacity: 0.4;
}
.wizard-step:disabled { cursor: not-allowed; }
.wizard-step.active { opacity: 1; background: rgba(99, 102, 241, 0.15); border-color: rgba(99, 102, 241, 0.4); font-weight: 600; }
.wizard-step.done { opacity: 0.7; }
.wizard-step.done .wizard-num { background: #4ade80; color: #000; }
.wizard-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.8rem;
  font-weight: 700;
}
.wizard-step.active .wizard-num { background: #6366f1; color: #fff; }
.wizard-arrow { opacity: 0.3; font-size: 0.85rem; }

.wizard-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border, #333);
  gap: 0.5rem;
}
.wizard-nav-final { justify-content: space-between; }
.wizard-hint { font-size: 0.8rem; opacity: 0.6; }
.wizard-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #6366f1;
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  margin-right: 0.4rem;
}

.model-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.6rem;
}
.model-card-thai {
    border-color: rgba(99, 102, 241, 0.4);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.08), rgba(168, 85, 247, 0.04));
}
.model-card-thai:hover {
    border-color: rgba(99, 102, 241, 0.7);
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.12), rgba(168, 85, 247, 0.08));
}
.model-card {
  display: block;
  padding: 0.7rem;
  background: var(--bg, #1a1a1a);
  border: 1px solid var(--border, #333);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}
.model-card:hover { border-color: rgba(99, 102, 241, 0.4); }
.model-card input { display: none; }
.model-card:has(input:checked) { border-color: #6366f1; background: rgba(99, 102, 241, 0.08); }
.model-name { font-weight: 600; font-size: 0.95rem; }
.model-meta { font-size: 0.72rem; opacity: 0.6; margin: 0.2rem 0; }
.model-desc { font-size: 0.78rem; opacity: 0.8; }
.spellfix-toggle { display: flex; align-items: center; gap: 0.5rem; font-size: 0.9rem; cursor: pointer; }

.submit-summary {
  background: var(--bg, #1a1a1a);
  border: 1px solid var(--border, #333);
  border-radius: var(--radius, 8px);
  padding: 1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  padding: 0.3rem 0;
  border-bottom: 1px dashed var(--border, #333);
}
.summary-row:last-child { border-bottom: none; }
.summary-row span { opacity: 0.7; }

@media (max-width: 768px) {
  .wizard-stepper { gap: 0.2rem; padding: 0.5rem 0.3rem; }
  .wizard-step { padding: 0.3rem 0.4rem; font-size: 0.7rem; }
  .wizard-label { display: none; }
  .wizard-arrow { display: none; }
  .wizard-stepper { flex-wrap: wrap; }
  .wizard-step { flex: 1; min-width: 40px; justify-content: center; }
}

/* =====================================================================
   2026 product shell — neutral black, warm yellow, responsive by default
   ===================================================================== */
[data-theme="light"] { color-scheme: light; }

.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;
}

:where(a, button, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 72%, white);
  outline-offset: 3px;
}

.app-header {
  min-height: 68px;
  padding: 0 32px;
  gap: 24px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(16px);
}

.app-brand {
  color: var(--text);
  min-width: max-content;
  font-size: 1.04rem;
  letter-spacing: -0.02em;
}

.app-brand:hover { text-decoration: none; }
.brand-name span { color: var(--primary); }

.app-nav {
  justify-content: center;
  align-self: stretch;
  gap: 18px;
}

.nav-link {
  display: inline-flex;
  align-items: center;
  position: relative;
  padding: 0 6px;
  border-radius: 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.nav-link:hover {
  color: var(--text);
  background: transparent;
}

.nav-link.active {
  color: var(--primary);
  background: transparent;
}

.nav-link.active::after {
  content: "";
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 0;
  height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--primary);
}

.menu-toggle { display: none; }

.btn-icon {
  min-width: 38px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
}

.btn-icon:hover {
  color: var(--text);
  border-color: var(--border);
  background: var(--bg-elev-2);
}

.app-main {
  max-width: 1120px;
  padding: 42px 28px 64px;
}

.view,
.panel,
.panel-body,
.advanced-grid > *,
.job-row > * { min-width: 0; }

.view-header { align-items: flex-start; }
.view-header h1,
.view-header h2 {
  color: var(--text);
  letter-spacing: -0.035em;
}
.view-header h1 { margin: 0; font-size: clamp(2rem, 4vw, 2.65rem); line-height: 1.1; }
.view-header h2 { font-size: 1.55rem; }
.view-sub { max-width: 680px; color: var(--text-dim); }

.create-view { max-width: 1000px; margin: 0 auto; }
.create-view > .view-header:first-child { margin-bottom: 20px; }
.create-intro { display: block; margin: 30px 0 18px; }
.create-intro h2 { margin: 0; }

.create-mode-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-elev);
}

.create-mode {
  padding: 10px 18px;
  border-radius: 7px;
  color: var(--text-dim);
  text-align: center;
  font-weight: 650;
  font-size: 0.9rem;
}

.create-mode:hover { color: var(--text); text-decoration: none; }
.create-mode.active {
  color: var(--primary-fg);
  background: var(--primary);
  box-shadow: 0 5px 18px rgba(244, 211, 43, 0.14);
}

.panel {
  border-color: var(--border);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
}
.panel-header {
  padding: 14px 18px;
  background: var(--bg-elev);
}
.panel-body { padding: 18px; }
.panel-title { font-weight: 700; }

.dropzone,
.normalize-dropzone {
  min-height: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-width: 1px;
  border-color: #4a4d52;
  background: #0c0e10;
}

.dropzone:hover,
.dropzone.dragover,
.normalize-dropzone:hover,
.normalize-dropzone.drag {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 4%, var(--bg));
}

.dropzone-text { font-weight: 700; }
.dropzone-hint { max-width: 600px; }

.wizard-stepper {
  justify-content: space-between;
  padding: 8px;
  background: transparent;
  box-shadow: none;
}

.wizard-step { color: var(--text-dim); }
.wizard-step.active {
  color: var(--text);
  background: rgba(244, 211, 43, 0.08);
  border-color: rgba(244, 211, 43, 0.35);
}
.wizard-step.active .wizard-num,
.wizard-badge {
  color: var(--primary-fg);
  background: var(--primary);
}
.wizard-step.done .wizard-num { background: var(--success); }

.btn {
  min-height: 40px;
  font-weight: 650;
}
.btn-primary { box-shadow: 0 6px 18px rgba(244, 211, 43, 0.12); }

.template-card,
.model-card,
.ai-suggest-card { border-width: 1px; }
.template-card { cursor: default; }
.template-select {
  appearance: none;
  width: 100%;
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.template-card.selected,
.model-card:has(input:checked) {
  border-color: var(--primary);
  background: rgba(244, 211, 43, 0.05);
}

.model-card.model-unavailable {
  cursor: not-allowed;
  filter: grayscale(1);
  opacity: .42;
}

.wizard-nav {
  background: var(--bg-elev);
  z-index: 3;
}

img,
video,
canvas { max-width: 100%; }

@media (max-width: 980px) {
  .app-header {
    min-height: 62px;
    padding: 10px 16px;
    gap: 8px 12px;
    flex-wrap: wrap;
  }

  .app-brand { flex: 1; min-height: 40px; }
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    order: 2;
  }

  .app-nav {
    display: none;
    order: 3;
    flex: 0 0 100%;
    align-self: auto;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0 4px;
    border-top: 1px solid var(--border);
  }
  .app-nav.open { display: flex; }
  .nav-link {
    min-height: 44px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
  }
  .nav-link.active { background: rgba(244, 211, 43, 0.08); }
  .nav-link.active::after { display: none; }

  .app-user {
    display: none;
    order: 4;
    flex: 0 0 100%;
    padding-top: 8px;
    border-top: 1px solid var(--border-soft);
  }
  .app-nav.open + .app-user { display: flex; }
  .user-email {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .app-main { padding: 28px 16px 88px; }
  .view-header { gap: 12px; flex-wrap: wrap; }
  .view-header-right { width: 100%; flex-wrap: wrap; }
  .view-header-right .btn { flex: 1; }

  .create-mode-switch { display: grid; width: 100%; }
  .create-intro { margin-top: 24px; }
  .wizard-stepper {
    display: grid;
    grid-template-columns: repeat(7, minmax(34px, 1fr));
  }
  .wizard-step { min-width: 0; }
  .wizard-nav { position: sticky; bottom: 0; padding-bottom: max(10px, env(safe-area-inset-bottom)); }

  .panel-body,
  .panel-header { padding-left: 14px; padding-right: 14px; }
  .dropzone,
  .normalize-dropzone { min-height: 190px; padding: 28px 14px; }
  .template-picker { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .advanced-grid,
  .model-grid { grid-template-columns: 1fr; }
  .hist-table,
  .compare-grid,
  .cmp-view { max-width: 100%; overflow-x: auto; }
}

@media (max-width: 480px) {
  .app-main { padding-left: 12px; padding-right: 12px; }
  .view-header h1 { font-size: 2rem; }
  .create-mode-switch { grid-template-columns: 1fr 1fr; }
  .create-mode { padding: 10px 8px; }
  .wizard-stepper { margin-left: -4px; margin-right: -4px; }
  .wizard-num { width: 28px; height: 28px; }
  .wizard-nav { align-items: stretch; flex-direction: column-reverse; }
  .wizard-nav .btn { width: 100%; }
  .wizard-hint { text-align: center; }
  .template-picker { grid-template-columns: 1fr; }
  .summary-row { gap: 12px; align-items: flex-start; }
  .summary-row strong { text-align: right; overflow-wrap: anywhere; }
  .toast-container { left: 12px; right: 12px; width: auto; }
}

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