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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Shared button styles ── */
.btn {
  padding: 9px 18px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition:
    opacity 0.15s,
    background 0.15s;
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.btn-primary {
  background: #3b82f6;
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: #2563eb;
}
.btn-ghost {
  background: #1a1f2e;
  color: #94a3b8;
  border: 1px solid #2d3448;
}
.btn-ghost:hover:not(:disabled) {
  background: #232a3d;
}

/* ════════════════════════════════════════
   MAIN APP
════════════════════════════════════════ */
#appScreen {
  display: flex;
  flex-direction: column;
  flex: 1;
}

header {
  padding: 12px 20px;
  border-bottom: 1px solid #1e2330;
  display: flex;
  align-items: center;
  gap: 12px;
}
header h1 {
  font-size: 16px;
  font-weight: 600;
  color: #f8fafc;
}
header .tag {
  font-size: 11px;
  background: #1e3a5f;
  color: #60a5fa;
  padding: 2px 8px;
  border-radius: 999px;
}

.main {
  flex: 1;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto 1fr;
  height: calc(100vh - 49px);
}

/* ── Status bar ── */
.status-bar {
  grid-column: 1 / -1;
  padding: 5px 20px;
  font-size: 12px;
  color: #64748b;
  background: #0f1117;
  border-bottom: 1px solid #1a1f2e;
  min-height: 26px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.status-bar .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #334155;
  flex-shrink: 0;
}
.status-bar.done .dot {
  background: #22c55e;
}
.status-bar.error .dot {
  background: #ef4444;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Panels ── */
.panel-video {
  width: calc((100vh - 49px - 26px - 59px) * 9 / 16);
  min-width: 180px;
  max-width: 340px;
  border-right: 1px solid #1e2330;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-label {
  padding: 8px 16px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
  border-bottom: 1px solid #1a1f2e;
  background: #131720;
}

.video-container {
  flex: 1;
  background: #080a10;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.video-container iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.video-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  color: #2d3748;
}
.video-placeholder svg {
  width: 48px;
  height: 48px;
  opacity: 0.35;
}
.video-placeholder p {
  font-size: 12px;
}

.video-meta {
  padding: 8px 16px;
  font-size: 11px;
  color: #64748b;
  border-top: 1px solid #1a1f2e;
  background: #0f1117;
  min-height: 32px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel-right {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.panel-transcript {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 0 0 325px;
  border-bottom: 1px solid #1e2330;
}

.transcript-toolbar {
  padding: 7px 16px;
  background: #131720;
  border-bottom: 1px solid #1a1f2e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}
.transcript-toolbar .left {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
}
.transcript-toolbar .right {
  display: flex;
  gap: 5px;
  align-items: center;
}
.char-count {
  font-size: 11px;
  color: #475569;
  padding: 3px 6px;
}

textarea {
  flex: 1;
  resize: none;
  background: #0f1117;
  border: none;
  outline: none;
  color: #e2e8f0;
  font-family:
    "Be Vietnam Pro",
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  font-size: 17px;
  line-height: 1.85;
  padding: 20px 24px;
  letter-spacing: 0.01em;
}
textarea::placeholder {
  color: #2d3748;
}

/* ── References ── */
.ref-zone {
  padding: 8px 16px 10px;
  background: #0f1117;
  border-bottom: 1px solid #1a1f2e;
  flex-shrink: 0;
}
.ref-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
  margin-bottom: 6px;
}
.ref-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 6px;
  min-height: 0;
}
.ref-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #1e2d45;
  color: #93c5fd;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
}
.ref-pill-text {
  cursor: pointer;
}
.ref-pill-text:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}
.ref-pill-edit {
  background: #0f1117;
  border: 1px solid #3b82f6;
  border-radius: 3px;
  color: #e2e8f0;
  font-size: 11px;
  padding: 1px 5px;
  outline: none;
  min-width: 120px;
}
.ref-pill button {
  background: none;
  border: none;
  cursor: pointer;
  color: #60a5fa;
  font-size: 12px;
  line-height: 1;
  padding: 0 1px;
  opacity: 0.6;
}
.ref-pill button:hover {
  opacity: 1;
  color: #ef4444;
}
.ref-input-row {
  display: flex;
  gap: 6px;
}
.ref-input-row input {
  flex: 1;
  background: #1a1f2e;
  border: 1px solid #2d3448;
  border-radius: 5px;
  padding: 5px 10px;
  color: #e2e8f0;
  font-size: 12px;
  outline: none;
}
.ref-input-row input:focus {
  border-color: #3b82f6;
}
.ref-input-row input::placeholder {
  color: #334155;
}
.ref-input-row button {
  background: #1a2540;
  border: 1px solid #2d3860;
  color: #60a5fa;
  border-radius: 5px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}
.ref-input-row button:hover {
  background: #1e3060;
}

/* ── Dataset table ── */
.panel-dataset {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.dataset-toolbar {
  padding: 7px 16px;
  background: #131720;
  border-bottom: 1px solid #1a1f2e;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.dataset-toolbar .left {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
  display: flex;
  align-items: center;
  gap: 8px;
}
.dataset-count {
  font-size: 11px;
  color: #334155;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.autosave-indicator {
  font-size: 10px;
  color: #334155;
}
.autosave-indicator.saved {
  color: #22c55e;
}

.dataset-table-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
}
.dataset-table-wrap::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}
.dataset-table-wrap::-webkit-scrollbar-track {
  background: #0f1117;
}
.dataset-table-wrap::-webkit-scrollbar-thumb {
  background: #2d3448;
  border-radius: 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
thead th {
  position: sticky;
  top: 0;
  background: #131720;
  padding: 7px 12px;
  text-align: left;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #475569;
  border-bottom: 1px solid #1e2330;
  white-space: nowrap;
}
tbody tr {
  border-bottom: 1px solid #1a1f2e;
  cursor: pointer;
  transition: background 0.1s;
}
tbody tr:hover {
  background: #131720;
}
tbody tr.active {
  background: #1a2540;
}
tbody td {
  padding: 7px 12px;
  color: #94a3b8;
  vertical-align: middle;
}
tbody td.td-num {
  color: #475569;
  width: 32px;
  text-align: center;
}
tbody td.td-title {
  color: #cbd5e1;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
tbody td.td-script {
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #64748b;
}
tbody td.td-refs {
  max-width: 160px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #475569;
  font-size: 11px;
}
tbody td.td-actions {
  width: 60px;
  white-space: nowrap;
}
.td-actions button {
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 5px;
  color: #475569;
  font-size: 12px;
  border-radius: 4px;
}
.td-actions button:hover {
  color: #ef4444;
  background: #1f1a1a;
}
.empty-state {
  padding: 24px;
  text-align: center;
  color: #334155;
  font-size: 12px;
}

/* ── Status badges ── */
.status-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.status-none      { background: #1a1f2e; color: #475569; border: 1px solid #2d3448; }
.status-extracted { background: #1e2d45; color: #60a5fa; border: 1px solid #2d4a7a; }
.status-verified  { background: #14532d; color: #86efac; border: 1px solid #166534; }

/* ── Pagination ── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 8px 12px;
  background: #0f1117;
  border-top: 1px solid #1a1f2e;
  flex-shrink: 0;
}
.pg-btn {
  background: #1a1f2e;
  border: 1px solid #2d3448;
  color: #64748b;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  min-width: 28px;
  line-height: 1.4;
}
.pg-btn:hover:not(:disabled) {
  background: #232a3d;
  color: #94a3b8;
}
.pg-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.pg-btn.pg-active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: #fff;
}
.pg-ellipsis {
  color: #475569;
  font-size: 12px;
  padding: 0 2px;
}
