:root {
  --bg-dark: #0f0f0f;
  --bg-panel: #1a1a1a;
  --bg-hover: #2a2a2a;
  --accent: #e82127; /* Tesla Red */
  --text-main: #ffffff;
  --text-dim: #aaaaaa;
  --border: #333333;
  
  /* Timeline Colors */
  --color-front: #3498db;
  --color-rear: #e74c3c;
  --color-left: #2ecc71;
  --color-right: #f1c40f;
}

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

body {
  background: var(--bg-dark);
  color: var(--text-main);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100vh;
  overflow: hidden;
}

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Header */
.top-bar {
  height: 60px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 20px;
  z-index: 100;
}

.logo {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.logo span { color: var(--accent); }
.logo .version {
  font-size: 10px;
  color: #666;
  margin-left: 4px;
}

.btn-icon-only {
  background: transparent;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  margin-left: 8px;
}
.btn-icon-only:hover {
  color: var(--text-main);
  background: var(--bg-hover);
}

.header-controls {
  display: flex;
  gap: 10px;
  margin-left: auto; /* Push controls to the right */
  align-items: center;
}

.btn-primary, .header-select {
  background: var(--text-main);
  color: var(--bg-dark);
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
  height: 36px; /* Fixed height for alignment */
}
.btn-primary:hover, .header-select:hover { opacity: 0.9; }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.header-select {
  appearance: none; /* Remove native styling */
  -webkit-appearance: none;
  padding-right: 30px; /* Space for arrow */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%230f0f0f' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

.producer-dot {
  width: 8px;
  height: 8px;
  background: #666;
  border-radius: 50%;
}

.status-text {
  color: var(--text-dim);
  font-size: 14px;
  margin-left: 20px; /* Add some spacing from buttons */
}
.status-area {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: 10px;
}
.activity-pill {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
  user-select: none;
}
.activity-pill:hover { border-color: var(--text-main); }
.activity-pill:active { transform: translateY(1px); }

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

.player-area {
  flex: 1;
  background: #000;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}
.player-status {
  position: absolute;
  bottom: 12px;
  left: 16px;
  background: rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  color: #e5e5e5;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}
.dot-separator { opacity: 0.6; }

/* Analysis Overlay */
.analysis-overlay {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0,0,0,0.8);
  padding: 20px;
  border-radius: 12px;
  border: 1px solid #333;
  text-align: center;
  width: 300px;
  z-index: 100;
  position: absolute;
}
.analysis-cancel {
  position: absolute;
  top: 8px;
  right: 8px;
  background: transparent;
  color: #aaa;
}
.analysis-cancel:hover { color: #fff; }
.analysis-title {
  color: white;
  font-weight: 600;
  margin-bottom: 10px;
}
.analysis-bar-container {
  height: 4px;
  background: #333;
  border-radius: 2px;
  overflow: hidden;
}
.analysis-bar {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 0.2s;
}
.analysis-status {
  color: #888;
  font-size: 12px;
  margin-top: 8px;
}
.analysis-steps {
  color: #666;
  font-size: 11px;
  margin-top: 4px;
}

/* Video JS Overrides - Global */
.video-js {
  width: 100%;
  height: 100%;
  background-color: #000;
}
.video-js .vjs-tech {
  object-fit: contain;
}
.vjs-control-bar { background: rgba(0,0,0,0.7) !important; }

/* Sidebar */
.sidebar {
  width: 360px;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 0.3s ease;
}

.sidebar-section {
  padding: 16px;
}

/* Thumbnails Grid */
.thumbnails-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-dark);
}

.thumb {
  position: relative;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.thumb:hover { border-color: #555; }
.thumb.active { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(232, 33, 39, 0.2); }

/* Thumbnail specific video sizing */
.thumb .thumb-video {
  width: 100%;
  height: 100%;
  object-fit: contain; /* Ensure entire video is visible */
  display: block;
}

.thumb .label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0,0,0,0.7);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  pointer-events: none;
  z-index: 10; /* Ensure label is on top of video */
}

/* IMMERSIVE MODE STYLES */
body.immersive-mode .sidebar {
  width: 300px; /* Keep sidebar for clips */
}

body.immersive-mode .thumbnails-grid {
  display: block;
  position: absolute;
  inset: 0;
  background: transparent;
  border: none;
  pointer-events: none;
  padding: 20px;
  z-index: 20;
}

body.immersive-mode .thumb {
  position: absolute;
  width: 200px;
  aspect-ratio: 4/3;
  pointer-events: auto;
  box-shadow: 0 4px 20px rgba(0,0,0,0.6);
  border: 1px solid rgba(255,255,255,0.1);
  background: #000;
  opacity: 0.6;
  transition: opacity 0.3s ease, transform 0.3s ease, border-color 0.3s;
}

body.immersive-mode .thumb:hover {
  opacity: 1;
  transform: scale(1.1);
  z-index: 30;
  border-color: var(--accent);
}
body.immersive-mode .thumb.active {
  display: none;
}

/* Immersive Sides Layout */
body.immersive-mode.layout-sides .thumb[data-cam="left_pillar"] { top: 20px; left: 20px; }
body.immersive-mode.layout-sides .thumb[data-cam="right_pillar"] { top: 20px; right: 20px; }
body.immersive-mode.layout-sides .thumb[data-cam="left_repeater"] { bottom: 20px; left: 20px; }
body.immersive-mode.layout-sides .thumb[data-cam="right_repeater"] { bottom: 20px; right: 20px; }
body.immersive-mode.layout-sides .thumb[data-cam="front"] { 
  bottom: 20px; 
  left: 50%; 
  transform: translateX(-50%); 
  top: auto;
}
body.immersive-mode.layout-sides .thumb[data-cam="back"] { 
  bottom: 20px; 
  left: 50%; 
  transform: translateX(-50%); 
  top: auto;
  right: auto; 
}
body.immersive-mode.layout-sides.active-cam-left_pillar .thumb[data-cam="back"]   { top: 20px; left: 20px; bottom: auto; transform: none; }
body.immersive-mode.layout-sides.active-cam-right_pillar .thumb[data-cam="back"]  { top: 20px; right: 20px; bottom: auto; left: auto; transform: none; }
body.immersive-mode.layout-sides.active-cam-left_repeater .thumb[data-cam="back"] { bottom: 20px; left: 20px; top: auto; transform: none; }
body.immersive-mode.layout-sides.active-cam-right_repeater .thumb[data-cam="back"]{ bottom: 20px; right: 20px; top: auto; left: auto; transform: none; }

/* Immersive Bottom Layout */
body.immersive-mode.layout-bottom .thumb {
  bottom: 20px; 
  width: 18%;
  aspect-ratio: 4/3;
  top: auto;
}
body.immersive-mode.layout-bottom .thumbnails-grid {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 12px;
  padding-bottom: 20px;
  width: 100%;
}
body.immersive-mode.layout-bottom .thumb {
  position: relative;
  transform: none;
  left: auto; right: auto; top: auto; bottom: auto;
  opacity: 0.7;
}
body.immersive-mode.layout-bottom .thumb[data-cam="left_pillar"] { order: 1; }
body.immersive-mode.layout-bottom .thumb[data-cam="left_repeater"] { order: 2; }
body.immersive-mode.layout-bottom .thumb[data-cam="back"] { order: 3; }
body.immersive-mode.layout-bottom .thumb[data-cam="front"] { order: 3; }
body.immersive-mode.layout-bottom .thumb[data-cam="right_repeater"] { order: 4; }
body.immersive-mode.layout-bottom .thumb[data-cam="right_pillar"] { order: 5; }

/* Clip List */
.clip-list-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: 0;
}

.list-header {
  padding: 16px 0 10px 0;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas:
    "label filters"
    "category filters";
  gap: 8px 12px;
  align-items: center;
}
.list-header h3 {
  grid-area: label;
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
}
.clip-count-badge {
  display: inline-block;
  background: var(--bg-hover);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 2px 6px;
  font-size: 10px;
  margin-left: 6px;
}
.list-filters {
  grid-area: filters;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.input-compact {
  background: var(--bg-dark);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 12px;
  height: 30px;
}
#clip-search { width: 140px; }
#clip-sort { width: 90px; }

.input {
  background: var(--bg-dark);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-size: 14px;
}

/* Activity Drawer */
.activity-drawer {
  position: fixed;
  top: 0;
  right: -360px;
  width: 320px;
  height: 100vh;
  background: var(--bg-panel);
  border-left: 1px solid var(--border);
  box-shadow: -4px 0 20px rgba(0,0,0,0.4);
  z-index: 3000;
  display: flex;
  flex-direction: column;
  transition: right 0.2s ease;
}
.activity-drawer.open {
  right: 0;
}
.activity-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 2999;
}
.activity-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.activity-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--text-main);
}
.activity-subtitle {
  font-size: 11px;
  color: var(--text-dim);
}
.activity-actions {
  display: flex;
  gap: 6px;
}
.activity-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.activity-item {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  background: var(--bg-dark);
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.activity-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-dim);
}
.activity-tag {
  padding: 2px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.tag-info { background: rgba(52,152,219,0.15); color: #8ac4f7; }
.tag-warn { background: rgba(241,196,15,0.15); color: #f1c40f; }
.tag-error { background: rgba(231,76,60,0.2); color: #ff6b6b; }
.activity-message {
  color: var(--text-main);
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}
.activity-actions-row {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
}
.btn-text {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 11px;
  cursor: pointer;
}
.btn-text:hover { color: var(--text-main); text-decoration: underline; }

.overlay-group {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  gap: 12px;
}
.overlay-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.overlay-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-dim);
}
.overlay-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.overlay-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}
.overlay-fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.overlay-field {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 8px;
  align-items: center;
}
.overlay-field .overlay-input {
  width: 100%;
}

@media (max-width: 700px) {
  .overlay-controls {
    grid-template-columns: repeat(2, minmax(0,1fr));
  }
  .overlay-field {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .list-header {
    grid-template-columns: 1fr;
    grid-template-areas:
      "label"
      "category"
      "filters";
  }
  .list-filters {
    align-items: flex-start;
    flex-direction: row;
    flex-wrap: wrap;
  }
}

#category-filter {
  background: var(--bg-dark);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  outline: none;
}

.clip-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.clip-item {
  padding: 10px 12px;
  background: var(--bg-hover);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: background 0.2s;
}
.clip-item:hover { background: #333; }
.clip-item.active { background: #333; border-left: 3px solid var(--accent); }

.clip-time { font-weight: 600; font-size: 14px; }
.clip-date { font-size: 12px; color: var(--text-dim); }
.clip-type { 
  font-size: 10px; 
  display: inline-block; 
  padding: 2px 4px; 
  border-radius: 3px; 
  background: #444; 
  margin-top: 4px; 
  width: fit-content;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 40px 20px;
  font-size: 14px;
}

/* Modal Styles */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 500px;
  max-width: 90%;
  max-height: 85vh;
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
}
/* Modal Sizes */
.modal-content.small { width: 400px; }
.modal-content.medium { width: 600px; }
.modal-content.large { width: 700px; }

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

.modal-header h3 { font-size: 16px; font-weight: 600; }

.btn-icon {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 24px;
  cursor: pointer;
  padding: 0 4px;
}
.btn-icon:hover { color: var(--text-main); }

.modal-body {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
}

select, .checkbox-label {
  background: var(--bg-dark);
  color: var(--text-main);
  border: 1px solid var(--border);
  padding: 10px;
  border-radius: 6px;
  font-size: 14px;
}

/* Full width inputs/selects */
.full-width { width: 100%; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}
.checkbox-subtext {
  font-size: 10px;
  color: #666;
  margin-left: 26px;
  margin-top: -4px;
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

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

.grid-configurator {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}

.grid-slot {
  font-size: 12px;
  padding: 8px;
  background: var(--bg-dark);
}

.grid-hint {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

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

/* About Content Styling (Dynamic) */
.about-content h1 {
  font-size: 20px;
  margin-bottom: 10px;
  color: var(--text-main);
}
.about-content h2 {
  font-size: 16px;
  margin-top: 15px;
  margin-bottom: 8px;
  color: var(--text-main);
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}
.about-content h3 { font-size: 14px; font-weight: 700; margin-top: 10px; }
.about-content li {
  margin-left: 20px;
  margin-bottom: 4px;
}
.about-content a { color: var(--accent); text-decoration: none; }
.about-content a:hover { text-decoration: underline; }

/* Notifications */
.notification {
  padding: 10px;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 10px;
}
.notification-warning {
  background: rgba(232, 33, 39, 0.1);
  color: #ff4d4d;
  border: 1px solid rgba(232, 33, 39, 0.3);
}

/* Auto Director Settings */
.focus-strength-container {
  margin-top: 10px;
  display: none;
  padding-left: 10px;
  border-left: 2px solid var(--border);
}
.focus-strength-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 6px;
}
.focus-strength-label { font-size: 10px; color: var(--text-dim); }
.focus-strength-value { font-size: 10px; color: var(--accent); font-weight: bold; }

.aggression-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: #666;
}
.aggression-desc {
  font-size: 12px;
  color: #aaa;
  line-height: 1.4;
}

/* Preset Buttons */
.preset-buttons {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.btn-preset {
  flex: 1;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 6px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-preset:hover {
  border-color: var(--text-dim);
  color: var(--text-main);
}
.btn-preset.active {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--text-main);
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 10px;
}
.stats-summary {
  text-align: center;
  margin-bottom: 20px;
}
.stats-flavor {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 4px;
}
.stats-sub {
  font-size: 12px;
  color: var(--text-dim);
}

.stat-card {
  background: var(--bg-dark);
  padding: 12px;
  border-radius: 6px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
}

.stat-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-top: 4px;
}

/* Timeline Visualization */
.timeline-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 8px;
  display: block;
}
.timeline-vis {
  height: 24px;
  width: 100%;
  background: var(--bg-dark);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  margin-top: 4px;
}

.timeline-legend {
  display: flex;
  gap: 12px;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 6px;
  justify-content: center;
}
.legend-item { display: flex; align-items: center; gap: 4px; }
.legend-dot { width: 8px; height: 8px; border-radius: 2px; }
.color-front { background: var(--color-front); }
.color-rear { background: var(--color-rear); }
.color-left { background: var(--color-left); }
.color-right { background: var(--color-right); }

/* Producer Mode State */
#btn-producer-mode.producer-active {
  background: #333;
  border: 1px solid var(--accent);
}
#btn-producer-mode.producer-active .producer-dot {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #444; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #666; }
