:root {
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-card: #1e293b;
  --bg-card-hover: #26354d;
  --border-color: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-amber: #f59e0b;
  --accent-emerald: #10b981;
  --accent-purple: #8b5cf6;
  --accent-red: #ef4444;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header & Top Bar */
.app-header {
  background: linear-gradient(180deg, #111827 0%, #0f172a 100%);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.35);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.arch-badges {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.arch-pill {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.65rem;
  border-radius: 9999px;
  background: rgba(59, 130, 246, 0.12);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.arch-pill.amber {
  background: rgba(245, 158, 11, 0.12);
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.3);
}

.arch-pill.emerald {
  background: rgba(16, 185, 129, 0.12);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.3);
}

/* Config Form Grid */
.config-bar {
  display: grid;
  grid-template-columns: 1.4fr 1.4fr 0.9fr auto;
  gap: 0.85rem;
  align-items: end;
  background: rgba(30, 41, 59, 0.55);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.85rem 1rem;
}

@media (max-width: 1200px) {
  .config-bar {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 768px) {
  .config-bar {
    grid-template-columns: 1fr;
  }
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.field-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

.text-link-btn {
  background: none;
  border: none;
  color: #60a5fa;
  font-size: 0.73rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.text-link-btn:hover {
  color: #93c5fd;
}

.input-control,
.select-control {
  width: 100%;
  background: #090d16;
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.55rem 0.75rem;
  border-radius: 7px;
  font-size: 0.85rem;
  font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input-control:focus,
.select-control:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.25);
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.58rem 1rem;
  border-radius: 7px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
  color: #ffffff;
  box-shadow: 0 2px 10px rgba(37, 99, 235, 0.35);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
}

.btn-secondary {
  background: #1e293b;
  color: #e2e8f0;
  border-color: #475569;
}

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

.btn-sm {
  font-size: 0.74rem;
  padding: 0.3rem 0.65rem;
  border-radius: 5px;
}

/* Preset Sub-bar */
.preset-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.65rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.preset-pills {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.preset-pill {
  background: rgba(30, 41, 59, 0.8);
  border: 1px solid var(--border-color);
  color: #cbd5e1;
  font-size: 0.74rem;
  font-weight: 500;
  padding: 0.25rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.preset-pill:hover,
.preset-pill.active {
  background: rgba(59, 130, 246, 0.18);
  border-color: #3b82f6;
  color: #ffffff;
}

/* Error Banner */
.error-banner {
  margin: 0.75rem 1.5rem 0;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  font-size: 0.84rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.hidden {
  display: none !important;
}

/* Main Workspace Split Grid */
.workspace-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 1.25rem;
  padding: 1.25rem 1.5rem;
  max-width: 1800px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 1100px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

/* Left Column: Video Stage & Schedule Timeline */
.player-column {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.video-stage-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

.video-viewport {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000000;
  overflow: hidden;
}

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

/* Top Status Overlay inside Video Viewport */
.player-overlay-top {
  position: absolute;
  top: 0.85rem;
  left: 0.85rem;
  right: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  pointer-events: none;
  z-index: 10;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  backdrop-filter: blur(8px);
  background: rgba(15, 23, 42, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.3);
  color: #e2e8f0;
}

.status-badge.mode-main {
  background: rgba(6, 78, 59, 0.88);
  border-color: rgba(16, 185, 129, 0.55);
  color: #a7f3d0;
}

.status-badge.mode-ad {
  background: rgba(120, 53, 15, 0.92);
  border-color: rgba(245, 158, 11, 0.7);
  color: #fde68a;
}

.format-live-badge {
  padding: 0.32rem 0.65rem;
  border-radius: 6px;
  font-size: 0.73rem;
  font-weight: 600;
  font-family: ui-monospace, monospace;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(59, 130, 246, 0.5);
  color: #93c5fd;
  backdrop-filter: blur(8px);
}

/* Ad Action Overlay (ClickThrough & Skip Ad) */
.ad-action-overlay {
  position: absolute;
  bottom: 3.4rem;
  left: 0.85rem;
  right: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 12;
  pointer-events: none;
}

.ad-cta-btn,
.ad-skip-btn {
  pointer-events: auto;
  padding: 0.45rem 0.9rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  backdrop-filter: blur(8px);
  transition: all 0.15s ease;
}

.ad-cta-btn {
  background: rgba(37, 99, 235, 0.9);
  border: 1px solid rgba(147, 197, 253, 0.5);
  color: #ffffff;
}

.ad-cta-btn:hover {
  background: rgba(29, 78, 216, 1);
}

.ad-skip-btn {
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid rgba(248, 250, 252, 0.4);
  color: #f8fafc;
}

.ad-skip-btn:disabled {
  opacity: 0.75;
  cursor: not-allowed;
}

.ad-skip-btn:not(:disabled):hover {
  background: #f59e0b;
  color: #000;
  border-color: #f59e0b;
}

/* Idle Placeholder Overlay */
.idle-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(30, 41, 59, 0.85) 0%, rgba(11, 15, 25, 0.96) 100%);
  text-align: center;
  padding: 2rem;
  z-index: 8;
}

.idle-overlay h3 {
  font-size: 1.15rem;
  margin-bottom: 0.4rem;
}

.idle-overlay p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  max-width: 460px;
  margin-bottom: 1.1rem;
}

/* Schedule & Timeline Bar below Video */
.timeline-panel {
  padding: 1rem 1.15rem;
  background: #0f172a;
  border-top: 1px solid var(--border-color);
}

.timeline-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.timeline-track-wrapper {
  position: relative;
  height: 12px;
  background: #1e293b;
  border-radius: 999px;
  margin: 0.75rem 0 1rem;
  overflow: visible;
}

.timeline-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 100%);
  border-radius: 999px;
  width: 0%;
  transition: width 0.15s linear;
}

.timeline-marker {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-amber);
  border: 2px solid #0f172a;
  cursor: pointer;
  z-index: 5;
  transition: transform 0.15s ease;
}

.timeline-marker:hover {
  transform: translate(-50%, -50%) scale(1.3);
}

.timeline-marker.completed {
  background: var(--accent-emerald);
}

.timeline-marker.playing {
  background: #fde047;
  box-shadow: 0 0 0 4px rgba(250, 204, 21, 0.35);
}

.ad-schedule-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.65rem;
}

.schedule-slot-card {
  background: rgba(30, 41, 59, 0.65);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.65rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
}

.schedule-slot-card.active {
  border-color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.1);
}

.schedule-slot-card.completed {
  border-color: rgba(16, 185, 129, 0.45);
}

.slot-top-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
}

.slot-title {
  font-weight: 700;
  color: #f1f5f9;
}

.slot-status {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  background: #334155;
  color: #cbd5e1;
}

.slot-status.playing {
  background: rgba(245, 158, 11, 0.25);
  color: #fcd34d;
}

.slot-status.completed {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

/* Right Column: Live Workshop Inspector */
.inspector-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  max-height: 780px;
}

.inspector-header {
  padding: 0.9rem 1.15rem 0;
  background: #0f172a;
  border-bottom: 1px solid var(--border-color);
}

.inspector-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.inspector-title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.inspector-tabs {
  display: flex;
  gap: 0.35rem;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.55rem 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: #60a5fa;
  border-bottom-color: #3b82f6;
}

.tab-count {
  font-size: 0.68rem;
  padding: 0.08rem 0.42rem;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.inspector-body {
  padding: 1rem 1.15rem;
  overflow-y: auto;
  flex: 1;
}

/* Tab 1: VAST Chain Cards */
.chain-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.chain-hop-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 9px;
  padding: 0.8rem 0.95rem;
}

.chain-hop-card.hop-wrapper {
  border-left: 4px solid var(--accent-amber);
}

.chain-hop-card.hop-inline {
  border-left: 4px solid var(--accent-emerald);
}

.chain-hop-card.hop-config {
  border-left: 4px solid var(--accent-blue);
}

.hop-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.hop-badge {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
}

.hop-badge.config {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.hop-badge.wrapper {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

.hop-badge.inline {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

.hop-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.74rem;
  color: var(--text-secondary);
  margin: 0.35rem 0;
}

.hop-url {
  font-family: ui-monospace, monospace;
  font-size: 0.73rem;
  color: #cbd5e1;
  background: #090d16;
  padding: 0.35rem 0.55rem;
  border-radius: 5px;
  word-break: break-all;
  margin: 0.35rem 0;
}

.chain-connector {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.78rem;
  padding: 0.1rem 0;
}

/* Tab 2: 4 Transcoded MediaFiles */
.mediafiles-grid {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
}

.mediafile-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 9px;
  padding: 0.8rem 0.95rem;
  transition: all 0.15s ease;
}

.mediafile-card.active-format {
  border-color: var(--accent-emerald);
  background: rgba(16, 185, 129, 0.08);
  box-shadow: 0 0 0 1px rgba(16, 185, 129, 0.35);
}

.mf-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.mf-title {
  font-weight: 700;
  font-size: 0.86rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mf-specs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-bottom: 0.45rem;
}

.spec-chip {
  font-size: 0.7rem;
  font-family: ui-monospace, monospace;
  padding: 0.15rem 0.48rem;
  border-radius: 4px;
  background: #0f172a;
  border: 1px solid #334155;
  color: #cbd5e1;
}

/* Tab 3: Telemetry Event Log */
.telemetry-list {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.telemetry-item {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 7px;
  padding: 0.55rem 0.75rem;
  font-size: 0.76rem;
}

.telemetry-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.telemetry-event-badge {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  font-size: 0.7rem;
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.18);
  color: #93c5fd;
}

.telemetry-event-badge.impression,
.telemetry-event-badge.start,
.telemetry-event-badge.complete {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

.telemetry-event-badge.firstQuartile,
.telemetry-event-badge.midpoint,
.telemetry-event-badge.thirdQuartile {
  background: rgba(245, 158, 11, 0.2);
  color: #fcd34d;
}

.telemetry-urls {
  margin-top: 0.3rem;
  font-family: ui-monospace, monospace;
  font-size: 0.69rem;
  color: #64748b;
  word-break: break-all;
}

/* Modal for XML / Config JSON Inspection */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}

.modal-window {
  background: #0f172a;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  width: 94vw;
  max-width: 1560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
}

.modal-header {
  padding: 0.9rem 1.2rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 1rem 1.2rem;
  overflow-y: auto;
  flex: 1;
}

.code-viewer,
.code-editor {
  width: 100%;
  min-height: 520px;
  background: #090d16;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 1rem;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre;
  overflow-x: auto;
}
