:root {
  --bg-dark: #0b0e17;
  --bg-panel: #121726;
  --bg-card: #181f33;
  --bg-input: #0f1422;
  --border-col: #28324e;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --accent: #10b981;
  --accent-hover: #059669;
  --warn: #f59e0b;
  --danger: #ef4444;
  --cyan: #06b6d4;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.45;
  overflow-x: hidden;
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: linear-gradient(90deg, #111629 0%, #19213a 100%);
  border-bottom: 1px solid var(--border-col);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  font-size: 26px;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.45);
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand h1 {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand p {
  font-size: 11.5px;
  color: var(--text-muted);
}

.badge-pro {
  background: linear-gradient(135deg, #6366f1, #ec4899);
  color: #fff;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 6px;
  font-weight: 700;
}

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

.pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-input);
  border: 1px solid var(--border-col);
  padding: 5px 11px;
  border-radius: 20px;
  font-size: 11.5px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
}

.dot.ok {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

.dot.err {
  background: var(--danger);
}

/* MOBILE / TABLET QUICK NAVIGATION BAR */
.mobile-nav-bar {
  display: none;
  background: #111629;
  border-bottom: 1px solid var(--border-col);
  padding: 6px 10px;
  gap: 6px;
  position: sticky;
  top: 0;
  z-index: 90;
}

.m-nav-btn {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border-col);
  color: var(--text-muted);
  border-radius: 7px;
  padding: 8px 6px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
}

.m-nav-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* 3-COLUMN STUDIO LAYOUT */
.studio-grid {
  display: grid;
  grid-template-columns: 420px 1fr 410px;
  gap: 12px;
  padding: 12px;
  min-height: calc(100vh - 64px);
}

@media (max-width: 1400px) {
  .studio-grid {
    grid-template-columns: 370px 1fr 370px;
  }
}

/* TABLET & MOBILE RESPONSIVE BREAKPOINTS */
@media (max-width: 1120px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
  }

  .status-pills {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  .pill {
    font-size: 11px;
    padding: 4px 9px;
  }

  .mobile-nav-bar {
    display: flex;
  }

  .studio-grid {
    grid-template-columns: 1fr;
    padding: 8px;
    gap: 10px;
  }

  /* On tablet/mobile, switch between panels cleanly using mobile-nav-bar */
  .studio-grid.mobile-tab-mode .panel {
    display: none;
  }
  .studio-grid.mobile-tab-mode .panel.mobile-active {
    display: flex;
  }
}

@media (max-width: 640px) {
  .brand h1 {
    font-size: 14px;
    flex-wrap: wrap;
  }

  .brand p {
    font-size: 11px;
  }

  .form-grid-2,
  .form-grid-3,
  .chk-grid-2,
  .btn-row-2 {
    grid-template-columns: 1fr;
  }

  .upload-row,
  .voice-select-row {
    flex-wrap: wrap;
  }

  .upload-row .btn,
  .voice-select-row select,
  .voice-select-row .btn {
    width: 100%;
  }

  .card-header {
    flex-wrap: wrap;
  }

  .subtabs {
    grid-template-columns: repeat(3, 1fr);
  }

  .player-stage {
    min-height: 260px !important;
    padding: 4px !important;
  }

  #main-video {
    max-height: 360px !important;
  }

  .srt-table th,
  .srt-table td {
    padding: 4px;
    font-size: 11px;
  }
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-col);
  border-radius: 10px;
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-grow {
  flex: 1;
  min-height: 260px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding-bottom: 6px;
}

.card-header h2 {
  font-size: 13px;
  font-weight: 700;
  color: #e2e8f0;
}

.tag, .badge-sub {
  font-size: 10.5px;
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(6, 182, 212, 0.15);
  color: #67e8f9;
  border: 1px solid rgba(6, 182, 212, 0.3);
}

/* FORMS & INPUTS */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 11.5px;
  color: var(--text-muted);
  font-weight: 500;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

.chk-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

input[type="text"],
input[type="number"],
input[type="password"],
select,
textarea {
  background: var(--bg-input);
  border: 1px solid var(--border-col);
  color: var(--text-main);
  padding: 6px 9px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12.5px;
  outline: none;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
}

input[type="color"] {
  background: var(--bg-input);
  border: 1px solid var(--border-col);
  border-radius: 6px;
  width: 100%;
  height: 30px;
  padding: 2px;
  cursor: pointer;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  cursor: pointer;
}

.chk-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #cbd5e1;
  cursor: pointer;
  user-select: none;
}

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 12px;
  border-radius: 6px;
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  color: #fff;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 11.5px;
}

.btn-xs {
  padding: 3px 8px;
  font-size: 11px;
}

.btn-primary {
  background: var(--primary);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-accent {
  background: var(--accent);
}
.btn-accent:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: #334155;
}
.btn-secondary:hover:not(:disabled) {
  background: #475569;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-col);
  color: #cbd5e1;
}
.btn-outline:hover:not(:disabled) {
  border-color: var(--primary);
  color: #fff;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  color: #cbd5e1;
}

.btn-danger {
  background: var(--danger);
}

.btn-export {
  background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
  font-size: 14px;
  font-weight: 800;
  padding: 11px;
  letter-spacing: 0.4px;
  box-shadow: 0 4px 15px rgba(239, 68, 68, 0.3);
}
.btn-export:hover:not(:disabled) {
  filter: brightness(1.08);
}

.upload-row, .btn-row-inline, .voice-select-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.file-status, .hint-text {
  font-size: 11.5px;
  color: var(--text-muted);
}

.ocr-tools-bar {
  background: rgba(15, 20, 34, 0.65);
  border: 1px dashed var(--border-col);
  padding: 7px 9px;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

/* SRT TABLE */
.srt-table-wrap {
  flex: 1;
  overflow-y: auto;
  max-height: 310px;
  border: 1px solid var(--border-col);
  border-radius: 6px;
  background: var(--bg-input);
}

.srt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.srt-table th {
  position: sticky;
  top: 0;
  background: #1e293b;
  color: #cbd5e1;
  text-align: left;
  padding: 6px 7px;
  font-size: 11px;
  z-index: 2;
}

.srt-table td {
  padding: 5px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  vertical-align: top;
}

.srt-table tr:hover {
  background: rgba(99, 102, 241, 0.08);
}

.srt-table textarea {
  background: transparent;
  border: 1px solid transparent;
  padding: 3px 4px;
  font-size: 12px;
  resize: vertical;
  min-height: 34px;
}

.srt-table textarea:focus {
  background: var(--bg-card);
  border-color: var(--primary);
}

.empty-row {
  text-align: center;
  color: var(--text-muted);
  padding: 24px !important;
}

/* CENTER PLAYER & INTERACTIVE CANVAS */
.preview-card {
  flex: 1;
}

.form-inline {
  display: flex;
  align-items: center;
  gap: 6px;
}
.form-inline select {
  width: auto;
}

.player-stage {
  flex: 1;
  background: #05070c;
  border: 1px solid var(--border-col);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 440px;
  position: relative;
  overflow: hidden;
  padding: 8px;
}

.canvas-container {
  position: relative;
  display: inline-block;
  max-width: 100%;
  max-height: 540px;
}

#main-video {
  display: block;
  max-width: 100%;
  max-height: 520px;
  border-radius: 4px;
  background: #000;
}

#overlay-canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: calc(100% - 42px); /* leave bottom native video controls clickable */
  pointer-events: auto;
  cursor: move;
  touch-action: none;
}

.layer-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  font-size: 11.5px;
  color: var(--text-muted);
  padding-top: 4px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
}

.lg-box {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 3px;
}
.lg-ocr { background: #38bdf8; }
.lg-blur { background: #f97316; }
.lg-sub { background: #22c55e; }
.lg-logo { background: #a855f7; }
.lg-text { background: #eab308; }

.audio-tracks-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg-input);
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border-col);
}

.track-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11.5px;
}

.track-pill audio {
  height: 28px;
  flex: 1;
}

/* CONSOLE & PROGRESS */
.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
}

.pct-badge {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11.5px;
}

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

.progress-bar-inner {
  height: 100%;
  background: linear-gradient(90deg, #6366f1, #10b981);
  transition: width 0.25s ease;
}

.log-console {
  background: #070a12;
  border: 1px solid var(--border-col);
  border-radius: 6px;
  padding: 8px 10px;
  height: 135px;
  overflow-y: auto;
  font-family: 'Consolas', 'Courier New', monospace;
  font-size: 11.5px;
  color: #a7f3d0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* SUBTABS */
.subtabs {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  background: var(--bg-input);
  padding: 4px;
  border-radius: 7px;
}

.subtab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 6px 4px;
  border-radius: 5px;
  cursor: pointer;
}

.subtab.active {
  background: var(--primary);
  color: #fff;
}

.subtab-pane {
  display: none;
  flex-direction: column;
  gap: 8px;
  padding-top: 6px;
}

.subtab-pane.active {
  display: flex;
}

.zones-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 110px;
  overflow-y: auto;
}

.zone-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-input);
  padding: 5px 8px;
  border-radius: 5px;
  border: 1px solid var(--border-col);
  font-size: 11.5px;
}

.vision-box, .export-result-box {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11.5px;
  color: #d1fae5;
  max-height: 110px;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: var(--bg-card);
  border: 1px solid var(--border-col);
  border-radius: 12px;
  width: 92%;
  max-width: 480px;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-col);
}

.modal-header h3 {
  font-size: 14px;
}

.btn-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
}

.modal-body {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-footer {
  padding: 10px 16px;
  border-top: 1px solid var(--border-col);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
