:root {
  color-scheme: light;
  --bg: #eef2f3;
  --panel: #ffffff;
  --ink: #15202b;
  --muted: #64717d;
  --line: #d8e0e5;
  --primary: #0f766e;
  --primary-strong: #115e59;
  --success: #256f3a;
  --danger: #b42318;
  --warn: #a15c07;
  --soft: #f6f8f9;
  --focus: #3b82f6;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select, textarea {
  font: inherit;
}

button {
  border: 0;
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(480px, 100%);
}

.login-panel, .panel, .status-strip {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(21, 32, 43, 0.08);
}

.login-panel {
  padding: 32px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
  letter-spacing: 0;
}

h1, h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 32px;
}

h2 {
  font-size: 16px;
}

.muted {
  color: var(--muted);
  line-height: 1.5;
}

.login-form, .upload-form {
  display: grid;
  gap: 16px;
  margin-top: 24px;
}

label {
  display: grid;
  gap: 7px;
  color: #2e3a44;
  font-weight: 650;
  font-size: 14px;
}

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

input, select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.35;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.primary-btn, .success-btn, .secondary-btn, .danger-btn, .ghost-btn, .icon-btn, .tiny-btn {
  border-radius: 6px;
  min-height: 40px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 750;
}

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

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

.success-btn {
  background: var(--success);
  color: #fff;
}

.secondary-btn {
  background: #eff6ff;
  color: #1d4ed8;
  border: 1px solid #bfdbfe;
}

.secondary-btn:hover {
  background: #dbeafe;
}

.danger-btn {
  background: #fff1f0;
  color: var(--danger);
  border: 1px solid #f0b7b1;
}

.ghost-btn, .icon-btn, .tiny-btn {
  background: #edf2f4;
  color: #21313b;
}

.ghost-btn[data-busy="true"] {
  background: #2563eb;
  color: #fff;
  opacity: 1;
}

.ghost-btn[data-pending="true"] {
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fdba74;
}

.ghost-btn[data-busy="true"] {
  background: #2563eb;
  color: #fff;
  border: 0;
  opacity: 1;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.ghost-btn[data-busy="true"]:disabled {
  opacity: 1;
}

.error-text {
  color: var(--danger);
  margin: 0;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}

.app-header h1 {
  font-size: 22px;
}

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

.user-badge {
  background: #e5f3ef;
  color: var(--primary-strong);
  border-radius: 999px;
  padding: 8px 11px;
  font-size: 13px;
  font-weight: 750;
}

.studio-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
  min-height: calc(100vh - 76px);
}

.left-rail {
  display: grid;
  align-content: start;
  gap: 14px;
}

.panel {
  padding: 16px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.drop-zone {
  min-height: 132px;
  display: grid;
  place-items: center;
  gap: 6px;
  text-align: center;
  border: 1px dashed #7a929a;
  border-radius: 8px;
  background: #f4f7f7;
  padding: 18px;
  cursor: pointer;
}

.drop-zone.drag-active {
  border-color: var(--primary);
  background: #e5f3ef;
}

.drop-zone input {
  display: none;
}

.drop-zone span {
  color: var(--muted);
  font-weight: 500;
}

.upload-progress {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #f6fbfa;
  border: 1px solid #cce3df;
  border-radius: 8px;
}

.upload-progress[hidden] {
  display: none;
}

.upload-queue {
  display: grid;
  gap: 6px;
  padding: 12px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
}

.upload-queue[hidden] {
  display: none;
}

.upload-queue strong {
  color: #1d4ed8;
  font-size: 13px;
}

.upload-queue ol {
  display: grid;
  gap: 4px;
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  font-size: 13px;
}

.upload-progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.upload-progress-row strong,
.upload-progress-row span {
  font-size: 13px;
}

#uploadProgressDetail {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

fieldset {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 0;
}

legend {
  padding: 0 6px;
  font-weight: 750;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
  min-height: 28px;
  font-weight: 600;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.jobs-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.job-card {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) 32px;
  gap: 6px;
  align-items: center;
  text-align: left;
  width: 100%;
  padding: 10px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 7px;
  cursor: pointer;
}

.job-card.active {
  border-color: var(--primary);
  box-shadow: inset 3px 0 0 var(--primary);
}

.job-card.dragging {
  opacity: 0.45;
}

.job-card.drag-over {
  border-color: var(--primary);
  background: #e5f3ef;
}

.drag-handle {
  color: #8a9aa4;
  cursor: grab;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
}

.job-main {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.job-card strong {
  overflow-wrap: anywhere;
}

.job-card span {
  color: var(--muted);
  font-size: 13px;
}

.job-actions {
  display: flex;
  justify-content: flex-end;
}

.delete-job-btn {
  width: 28px;
  height: 28px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  color: var(--danger);
  font-size: 20px;
  font-weight: 800;
}

.delete-job-btn:hover,
.delete-job-btn:focus-visible {
  background: #fff1f0;
  outline: none;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
}

.status-strip {
  padding: 14px 16px;
  display: grid;
  gap: 10px;
}

.status-strip.failed {
  border-color: #f0b7b1;
  background: #fff7f6;
}

.status-strip.failed span {
  color: var(--danger);
  font-weight: 750;
}

.status-strip strong, .status-strip span {
  display: block;
}

.status-strip span {
  color: var(--muted);
  margin-top: 2px;
}

.status-progress-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  align-items: center;
  gap: 10px;
}

.progress-percent {
  color: var(--primary-strong);
  font-size: 13px;
  text-align: right;
}

.progress-track {
  height: 8px;
  background: #e2e8ed;
  border-radius: 999px;
  overflow: hidden;
}

#progressFill,
#uploadProgressFill {
  width: 0%;
  height: 100%;
  background: var(--primary);
  transition: width 180ms ease;
}

.progress-track.small {
  height: 7px;
}

.preview-editor {
  display: grid;
  grid-template-columns: minmax(420px, 1.05fr) minmax(360px, 0.95fr);
  gap: 14px;
  min-height: 0;
}

.video-column, .editor-column {
  display: grid;
  align-content: start;
  gap: 12px;
  min-width: 0;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 40px;
}

.settings-btn {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: #e5f3ef;
  color: var(--primary-strong);
  cursor: pointer;
  font-weight: 800;
}

.settings-btn:hover {
  background: #d5ebe6;
}

.subtitle-settings {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.subtitle-settings[hidden] {
  display: none;
}

.subtitle-settings label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  white-space: nowrap;
}

.subtitle-settings input {
  width: 140px;
  min-height: 28px;
  padding: 0;
}

.subtitle-settings output {
  min-width: 38px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.video-frame {
  position: relative;
  overflow: hidden;
  background: #0b1215;
  border-radius: 8px;
  border: 1px solid #0b1215;
  aspect-ratio: 16 / 9;
}

video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.subtitle-overlay {
  position: absolute;
  left: 7%;
  right: 7%;
  bottom: 9%;
  min-height: 44px;
  display: grid;
  place-items: center;
  color: #fff;
  text-align: center;
  font-size: 24px;
  line-height: 1.25;
  font-weight: 800;
  text-shadow: 0 2px 5px rgba(0, 0, 0, 0.95), 0 0 2px rgba(0, 0, 0, 0.9);
  white-space: pre-line;
  pointer-events: none;
}

.file-tabs, .downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.download-panel {
  display: grid;
  gap: 10px;
}

.download-panel[hidden] {
  display: none;
}

.download-panel summary {
  width: fit-content;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  color: #1d4ed8;
  cursor: pointer;
  font-weight: 850;
  list-style: none;
}

.download-panel summary::-webkit-details-marker {
  display: none;
}

.download-panel summary::before {
  content: ">";
  font-size: 14px;
  font-weight: 850;
  transition: transform 0.16s ease;
}

.download-panel[open] summary::before {
  transform: rotate(90deg);
}

.downloads {
  align-items: center;
}

.tab-btn {
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
  cursor: pointer;
  font-weight: 750;
}

.tab-btn.active {
  background: #dff2ef;
  border-color: var(--primary);
  color: var(--primary-strong);
}

.tab-btn.master {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.tab-btn.master.active {
  background: #dff2ef;
  border-color: var(--primary);
  color: var(--primary-strong);
  box-shadow: none;
}

.download-link {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
}

.download-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 40px;
  padding: 4px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
}

.download-group.master {
  border-color: #93c5fd;
  background: #eff6ff;
}

.download-lang {
  min-width: 38px;
  min-height: 30px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: #2563eb;
  color: #fff;
  font-size: 13px;
  font-weight: 850;
  text-align: center;
}

.download-group.master .download-lang {
  min-width: 82px;
  background: #2563eb;
}

.download-group .download-link {
  min-height: 30px;
  padding: 0 9px;
  font-size: 13px;
}

.zip-link {
  min-height: 40px;
  background: #e5f3ef;
  border-color: var(--primary);
  color: var(--primary-strong);
}

.editor-column {
  min-height: 0;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.master-notice {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: #e5f3ef;
  color: var(--primary-strong);
  font-weight: 800;
  line-height: 1.35;
}

.master-notice[hidden] {
  display: none;
}

.translation-reminder {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid #fdba74;
  border-radius: 8px;
  background: #fff7ed;
  color: #9a3412;
  font-weight: 800;
  line-height: 1.35;
}

.translation-reminder[hidden] {
  display: none;
}

.autosave-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}

.autosave-status[data-tone="saving"] {
  color: var(--warn);
}

.autosave-status[data-tone="saved"] {
  color: var(--success);
}

.autosave-status[data-tone="error"] {
  color: var(--danger);
}

.cue-list {
  overflow: auto;
  max-height: calc(100vh - 230px);
  display: grid;
  gap: 8px;
  padding-right: 4px;
}

.cue-row {
  display: grid;
  grid-template-columns: 126px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.cue-row.active {
  border-color: var(--primary);
  box-shadow: inset 3px 0 0 var(--primary);
}

.cue-time {
  min-height: 58px;
  border-radius: 6px;
  background: #eef4f6;
  color: #26343d;
  cursor: pointer;
  font-size: 12px;
  line-height: 1.35;
  font-weight: 800;
  white-space: pre-line;
}

.cue-text {
  min-height: 58px;
}

.cue-tools {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 8px;
}

.tiny-btn {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

.cue-quality {
  font-size: 12px;
  font-weight: 800;
}

.quality-ok { color: var(--success); }
.quality-warn { color: var(--warn); }
.quality-bad { color: var(--danger); }

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

  .preview-editor {
    grid-template-columns: 1fr;
  }

  .cue-list {
    max-height: none;
  }
}

@media (max-width: 620px) {
  .app-header {
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
  }

  .studio-layout {
    padding: 10px;
  }

  .cue-row {
    grid-template-columns: 1fr;
  }

  .cue-tools {
    grid-column: 1;
  }

  .subtitle-overlay {
    font-size: 18px;
  }
}
