:root {
  --bg: #0d0f14;
  --panel: #151922;
  --panel-hover: #1c222e;
  --field: #0a0c10;
  --border: #303744;
  --border-light: #3f4756;
  --fg: #e7eaf0;
  --muted: #9da7b6;
  --accent: #5b8cff;
  --accent-hover: #739dff;
  --danger: #ff6b6b;
  --danger-bg: rgba(255, 107, 107, 0.15);
  --success: #55d187;
  --success-bg: rgba(85, 209, 135, 0.15);
  --warning: #ffd166;
  --radius: 8px;
  --radius-sm: 5px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mm: 'Padauk', 'Noto Sans Myanmar', 'Myanmar Text', sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background-color: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

/* Typography & Helpers */
h1, h2, h3, h4 { font-weight: 600; color: #fff; }
h1 { font-size: 1.15rem; }
h2 { font-size: 1.3rem; margin-bottom: 0.25rem; }
h3 { font-size: 0.95rem; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
h4 { font-size: 0.9rem; margin-bottom: 0.4rem; }

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; }
.mm-text { font-family: var(--font-mm); }
.hidden { display: none !important; }
.space-between { display: flex; justify-content: space-between; align-items: center; }
.row-flex { display: flex; gap: 8px; align-items: center; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.mt-4 { margin-top: 16px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: #252b36;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #333b49; border-color: var(--border-light); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-success { background: #235c3b; color: #a4f5c6; border-color: #318253; font-weight: 600; }
.btn-success:hover:not(:disabled) { background: #2c7249; }
.btn-danger { background: #4a252a; color: #ffd9dc; border-color: #6a3038; }
.btn-danger:hover:not(:disabled) { background: #653039; }
.btn-secondary { background: #1c222e; }
.btn-sm { padding: 4px 8px; font-size: 0.8rem; }
.btn-lg { padding: 12px 20px; font-size: 1rem; border-radius: var(--radius); }
.btn-icon { padding: 6px 10px; }

/* Inputs, Selects */
input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  background: var(--field);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}
input[type="text"]:focus, input[type="password"]:focus, select:focus {
  border-color: var(--accent);
}
select { cursor: pointer; }

/* Sliders */
input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: var(--field);
  outline: none;
  border: 1px solid var(--border);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid #fff;
}
.range-labels {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 3px;
}

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Top Nav */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-badge {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 3px 7px;
  border-radius: 4px;
}
.brand-text h1 { margin-bottom: 0; line-height: 1.1; }
.brand-text .sub { font-size: 0.75rem; color: var(--muted); }

.tabs-nav {
  display: flex;
  gap: 4px;
}
.nav-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--muted);
  border: none;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  position: relative;
  transition: all 0.15s ease;
}
.nav-btn:hover { color: var(--fg); background: rgba(255, 255, 255, 0.05); }
.nav-btn.active { color: #fff; background: #252b36; border: 1px solid var(--border); }
.badge {
  background: var(--border);
  color: #fff;
  font-size: 0.7rem;
  padding: 1px 6px;
  border-radius: 10px;
}

/* Layout Panes */
.main-content {
  flex: 1;
  padding: 12px;
}
.tab-pane { display: none; }
.tab-pane.active { display: block; }

.workspace-layout {
  display: grid;
  grid-template-columns: 340px 1fr 340px;
  gap: 12px;
  align-items: start;
}

/* Cards */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
  overflow: hidden;
}
.card-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
}
.card-body { padding: 14px; }

/* Forms */
.form-row { margin-bottom: 12px; }
.form-row:last-child { margin-bottom: 0; }
.label-with-val {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}
.checkbox-row { margin-top: 8px; }
.switch-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.switch-label input { width: 16px; height: 16px; accent-color: var(--accent); }

/* Dropzone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 18px 10px;
  text-align: center;
  background: var(--field);
  cursor: pointer;
  position: relative;
  transition: border-color 0.15s;
}
.drop-zone:hover { border-color: var(--accent); }
.drop-zone input {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  opacity: 0;
  cursor: pointer;
}
.drop-text { margin: 6px 0 2px; }

/* Selected Banner */
.selected-banner {
  display: flex;
  gap: 10px;
  align-items: center;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px;
  margin-top: 8px;
}
.thumb-wrap img {
  width: 72px;
  height: 48px;
  object-fit: cover;
  border-radius: 4px;
  background: #000;
  display: block;
}
.info-wrap {
  overflow: hidden;
  flex: 1;
}
.info-wrap strong {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.88rem;
}

/* Center Pane: Preview */
.preview-card .card-body {
  padding: 12px;
}
.preview-stage-container {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #05070a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-stage-container img#previewImage {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.overlay-layer {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
}
.overlay-elem {
  position: absolute;
  transform: translate(-50%, -50%);
  user-select: none;
  pointer-events: none;
  font-family: var(--font-mm);
}
.title-elem {
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.9), 0 0 2px #000;
  font-weight: 700;
  text-align: center;
  white-space: pre-wrap;
  max-width: 82%;
}
.extra-elem {
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
  font-weight: 600;
  text-align: center;
  max-width: 78%;
}
.logo-elem img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Seek Row */
.seek-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 14px;
}

/* Mobile Positioning Panel */
.mobile-positioning-panel {
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.pos-panel-header {
  margin-bottom: 8px;
}
.pos-panel-header h4 { margin-bottom: 0; }

.segmented-control {
  display: flex;
  gap: 4px;
  background: #151922;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin: 6px 0 12px;
}
.seg-btn {
  flex: 1;
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: 4px;
  padding: 6px 4px;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.seg-btn.active {
  background: var(--accent);
  color: #fff;
}

/* Preset 9-Grid */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin: 6px 0 12px;
}
.grid-btn {
  background: #1c222e;
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 4px;
  font-size: 0.78rem;
  cursor: pointer;
  font-weight: 500;
}
.grid-btn:hover { background: #262e3d; border-color: var(--accent); }

.tap-place-row { margin-bottom: 12px; }

/* Stepper Sliders */
.fine-tuning-sliders {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.slider-stepper label {
  font-size: 0.8rem;
  color: var(--muted);
  display: block;
  margin-bottom: 2px;
}
.stepper-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.step-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #252b36;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: #fff;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
}
.step-btn:hover { background: #333b49; }

/* Workspace Footer & Execution Dock */
.workspace-footer {
  grid-column: 1 / -1;
  width: 100%;
}

.run-card {
  margin-bottom: 0;
  border: 1px solid var(--border-light);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
  background: #121620;
  border-radius: var(--radius);
}

.run-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 20px;
  padding: 16px 20px;
}

/* Action Buttons (Left) */
.run-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.btn-action {
  height: 46px;
  min-width: 165px;
  padding: 0 20px;
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-action:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.btn-action:active:not(:disabled) {
  transform: translateY(0);
}

/* Center: Status & Progress */
.run-status-col {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.run-status-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  background: #235c3b;
  color: #a4f5c6;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 4px;
  letter-spacing: 0.6px;
  white-space: nowrap;
}

.status-badge.running {
  background: #1c3b6e;
  color: #7cb3ff;
  border: 1px solid #2e599e;
  box-shadow: 0 0 10px rgba(91, 140, 255, 0.25);
}

.status-badge.stopped {
  background: #4a2e12;
  color: #ffc285;
  border: 1px solid #73491f;
}

.status-badge.failed {
  background: #4a1f24;
  color: #ff9da6;
  border: 1px solid #782e37;
}

.stage-text {
  font-size: 0.88rem;
  color: var(--fg);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.progress-pct {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent);
  margin-left: auto;
}

.progress-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #5b8cff, #55d187);
  transition: width 0.25s ease;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
}

.btn-xs {
  padding: 2px 8px;
  font-size: 0.75rem;
}

/* Right: Tools & Toggle */
.run-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.btn-drawer-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 42px;
  padding: 0 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border-color: var(--border-light);
  background: #1a202c;
  color: var(--fg);
  border-radius: var(--radius-sm);
}

.btn-drawer-toggle:hover {
  background: #252d3d;
  border-color: var(--accent);
}

.drawer-arrow {
  transition: transform 0.2s ease;
}

.drawer-arrow.open {
  transform: rotate(180deg);
}

/* Pulsing live dot */
.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #657080;
  display: inline-block;
  transition: all 0.2s;
}

.live-dot.active {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse-dot 1.4s infinite;
}

@keyframes pulse-dot {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.25); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Live Process Output Console Drawer */
.logs-drawer {
  border-top: 1px solid var(--border);
  background: #090c12;
}

.logs-drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  background: #0f131c;
  border-bottom: 1px solid var(--border);
}

.logs-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--fg);
  font-size: 0.88rem;
}

.logs-header-right {
  display: flex;
  gap: 8px;
}

.log-console {
  background: #05070a;
  border: none;
  padding: 14px 18px;
  height: 220px;
  overflow-y: auto;
  font-size: 0.82rem;
  line-height: 1.55;
  color: #cfd6e4;
  white-space: pre-wrap;
  word-break: break-all;
}

.log-console::-webkit-scrollbar {
  width: 8px;
}

.log-console::-webkit-scrollbar-track {
  background: #07090f;
}

.log-console::-webkit-scrollbar-thumb {
  background: #252b36;
  border-radius: 4px;
}

.log-console::-webkit-scrollbar-thumb:hover {
  background: #333b49;
}

/* History Views */
.history-container {
  max-width: 1200px;
  margin: 0 auto;
}
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 12px;
}

.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.source-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: transform 0.15s, border-color 0.15s;
}
.source-card:hover { border-color: var(--accent); }
.source-thumb-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  position: relative;
}
.source-thumb-wrap img { width: 100%; height: 100%; object-fit: cover; }
.source-duration-tag {
  position: absolute;
  bottom: 6px; right: 6px;
  background: rgba(0,0,0,0.8);
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 4px;
}
.source-info { padding: 12px; }
.source-info h4 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.source-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

/* Jobs Table/List */
.jobs-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.job-item-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}
.job-item-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 250px;
}
.job-item-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Settings Form */
.settings-container {
  max-width: 800px;
  margin: 0 auto;
}
.settings-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.test-result-box {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 0.85rem;
}
.test-result-box.success { background: var(--success-bg); color: #a4f5c6; border: 1px solid #318253; }
.test-result-box.error { background: var(--danger-bg); color: #ffb8be; border: 1px solid #82313a; }

.sys-diagnostic-box {
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-top: 10px;
}
.diag-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.diag-row:last-child { border-bottom: none; }

/* Modals */
.modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-backdrop {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.8);
  backdrop-filter: blur(4px);
}
.modal-dialog {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 720px;
  z-index: 1001;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
.modal-dialog.modal-large { max-width: 960px; }
.modal-header {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
}
.modal-close {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
}
.modal-body {
  padding: 16px;
  overflow-y: auto;
}
.plan-segments-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.plan-segment-item {
  background: var(--field);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
}

/* Responsive Media Queries */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
  .workspace-layout {
    grid-template-columns: 1fr 1fr;
  }
  .center-pane {
    grid-column: 1 / -1;
    order: -1;
  }
  .workspace-footer {
    grid-column: 1 / -1;
  }
  .run-bar {
    grid-template-columns: auto 1fr auto;
    gap: 14px;
    padding: 14px;
  }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
  .top-nav {
    flex-direction: column;
    gap: 8px;
    padding: 8px;
  }
  .tabs-nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
  }
  .nav-btn {
    padding: 6px 10px;
    font-size: 0.8rem;
  }
  .workspace-layout {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .workspace-footer {
    grid-column: 1;
  }
  .run-bar {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 12px;
  }
  .run-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .btn-action {
    width: 100%;
    min-width: 0;
    padding: 0 8px;
    font-size: 0.82rem;
    height: 42px;
  }
  .run-status-col {
    width: 100%;
  }
  .run-tools {
    width: 100%;
    justify-content: flex-end;
  }
  .btn-drawer-toggle {
    width: 100%;
    justify-content: center;
  }
  .preset-grid {
    grid-template-columns: repeat(3, 1fr);
  }
  .step-btn {
    width: 38px;
    height: 38px;
  }
}
