:root {
  color-scheme: dark;
  --bg: #0a0a0a;
  --bg-nav: #0d0d0d;
  --bg-sidebar: #111111;
  --bg-card: #171717;
  --bg-input: #0f0f0f;
  --bg-hover: #1a1a1a;
  --border: #262626;
  --border-light: #2a2a2a;
  --border-focus: #603cf7;
  --text: #fafafa;
  --text-secondary: #a3a3a3;
  --text-tertiary: #737373;
  --accent: #603cf7;
  --accent-hover: #7c5cfc;
  --accent-soft: rgba(96, 60, 247, 0.1);
  --accent-border: rgba(96, 60, 247, 0.3);
  --success: #27C93F;
  --warning: #eab308;
  --danger: #ef4444;
  --radius: 10px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "Fira Code", "Cascadia Code", "Consolas", monospace;
  --nav-height: 52px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button, input { font: inherit; color: inherit; }
a { color: var(--text-secondary); text-decoration: none; }
a:hover { color: var(--text); }

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ── Navbar ────────────────────── */
.navbar {
  height: var(--nav-height);
  background: var(--bg-nav);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 24px;
  -webkit-app-region: drag;
  z-index: 10;
  position: relative;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.01em;
}

.navbar-brand svg { width: 24px; height: 24px; flex-shrink: 0; }

.navbar-links { display: flex; align-items: center; gap: 2px; margin-left: 12px; }

.nav-link {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  transition: all 0.12s;
}

.nav-link:hover { color: var(--text); background: var(--bg-hover); }
.nav-link.active { color: var(--text); background: var(--bg-hover); }

.navbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-pill {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

/* ── Main layout ───────────────── */
.main-content {
  display: grid;
  grid-template-columns: 340px 1fr;
  height: calc(100vh - var(--nav-height));
  gap: 0;
}

/* ── Sidebar ───────────────────── */
.sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
}

.sidebar-section.livery-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 80px;
  overflow: hidden;
  border-bottom: none;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.count {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ── Search ────────────────────── */
.search-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-size: 12px;
  outline: none;
  transition: all 0.15s;
  margin-bottom: 8px;
}

.search-input::placeholder { color: var(--text-tertiary); }

.search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(96, 60, 247, 0.15);
}

/* ── Vehicle list ──────────────── */
.vehicle-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  max-height: 200px;
  overflow-y: auto;
}

.vehicle-category {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-tertiary);
  padding: 10px 0 4px;
}

.vehicle-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 8px 10px;
  text-align: left;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  transition: all 0.1s;
  font-size: 12px;
  border-left: 2px solid transparent;
  border-radius: 0;
}

.vehicle-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.vehicle-item.active {
  background: var(--accent-soft);
  color: var(--text);
  border-left-color: var(--accent);
}

.vehicle-item-info { flex: 1; min-width: 0; }

.vehicle-item-name {
  font-weight: 500;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.vehicle-item-subtitle {
  font-size: 10px;
  color: var(--text-tertiary);
  margin-top: 1px;
}

/* ── Colour section ────────────── */
.colour-controls { display: flex; flex-direction: column; gap: 10px; }

.colour-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.colour-row label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  min-width: 65px;
}

.colour-row input[type="color"] {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--bg-input);
  cursor: pointer;
  padding: 2px;
}

.hex-picker { display: flex; align-items: center; gap: 6px; }
.hex-swatch { width: 24px; height: 24px; border-radius: 4px; border: 1px solid var(--border); flex-shrink: 0; }
.hex-input {
  flex: 1; padding: 6px 8px; border-radius: var(--radius-xs);
  border: 1px solid var(--border); background: var(--bg-input);
  font-family: var(--font-mono); font-size: 11px; outline: none;
  transition: all 0.2s; width: 70px;
}
.hex-input:focus { border-color: var(--border-focus); box-shadow: 0 0 0 2px var(--accent-glow); }
.hex-input::placeholder { color: var(--text-tertiary); }
.cp-presets { display: flex; gap: 4px; flex-wrap: wrap; }
.cp-swatch {
  width: 18px; height: 18px; border-radius: 4px;
  border: 1px solid var(--border); cursor: pointer;
  transition: all 0.15s; flex-shrink: 0;
}
.cp-swatch:hover { border-color: var(--text); transform: scale(1.15); }

/* ── Buttons ───────────────────── */
.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.btn {
  padding: 8px 14px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.12s;
  text-align: center;
  white-space: nowrap;
}

.btn:hover { border-color: var(--border-light); background: var(--bg-hover); }

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

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

/* ── Livery panel list ─────────── */
.livery-list {
  flex: 1;
  overflow-y: auto;
  margin: -4px -8px;
  padding: 4px 8px;
}

.livery-empty {
  padding: 16px;
  text-align: center;
  color: var(--text-tertiary);
  font-size: 11px;
}

.livery-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}

.livery-item:last-child { border-bottom: none; }

.livery-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.livery-item-name {
  font-weight: 700;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--text);
}

.livery-item-badge {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 7px;
  border-radius: 10px;
  background: rgba(234, 179, 8, 0.1);
  color: var(--warning);
}

.livery-input-row {
  display: flex;
  gap: 6px;
}

.livery-input-row input {
  flex: 1;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--bg-input);
  font-family: var(--font-mono);
  font-size: 11px;
  outline: none;
  transition: all 0.15s;
}

.livery-input-row input::placeholder {
  color: var(--text-tertiary);
  font-family: var(--font);
  font-size: 10px;
}

.livery-input-row input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 2px rgba(96, 60, 247, 0.12);
}

.livery-input-row .open-btn {
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--bg-card);
  cursor: pointer;
  font-size: 10px;
  font-weight: 600;
  transition: all 0.12s;
  color: var(--text-secondary);
  white-space: nowrap;
}

.livery-input-row .open-btn:hover:not(:disabled) {
  border-color: var(--border-light);
  color: var(--text);
}

.livery-input-row .open-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.livery-preview-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 6px;
}

.thumb-box {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  border: 1px solid var(--border);
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(255,255,255,0.03) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.03) 75%),
    linear-gradient(45deg, rgba(255,255,255,0.03) 25%, transparent 25%, transparent 75%, rgba(255,255,255,0.03) 75%);
  background-position: 0 0, 5px 5px;
  background-size: 10px 10px;
  flex-shrink: 0;
}

.thumb-box img { width: 100%; height: 100%; object-fit: cover; display: none; }

.livery-hint { font-size: 10px; color: var(--text-tertiary); line-height: 1.3; }

/* ── Viewer ────────────────────── */
.viewer-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-nav);
  z-index: 2;
  gap: 16px;
}

.viewer-header-left { display: flex; align-items: center; gap: 12px; }

.viewer-header h2 {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
}

.viewer-status { display: flex; align-items: center; gap: 8px; }

.viewer-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-tertiary);
  flex-shrink: 0;
}

.viewer-status-dot.ready { background: var(--success); box-shadow: 0 0 6px rgba(39,201,63,0.4); }
.viewer-status-dot.loading { background: var(--warning); animation: pulse 1.2s infinite; }
.viewer-status-dot.error { background: var(--danger); }

.viewer-status-text { font-size: 11px; color: var(--text-secondary); }

.viewer-canvas-wrap { flex: 1; position: relative; overflow: hidden; }

.viewer-canvas { position: absolute; inset: 0; }

/* ── Loading ───────────────────── */
.viewer-loading {
  position: absolute;
  left: 16px;
  bottom: 16px;
  z-index: 3;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: rgba(13, 13, 13, 0.95);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  min-width: 180px;
  font-size: 12px;
}

.viewer-loading.hidden { display: none; }

.loading-spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(96, 60, 247, 0.2);
  border-top-color: var(--accent);
  animation: spin 0.6s linear infinite;
  margin-bottom: 6px;
}

.loading-label { color: var(--text-secondary); font-size: 11px; }

.loading-bar {
  margin-top: 8px;
  height: 3px;
  border-radius: 2px;
  overflow: hidden;
  background: rgba(255,255,255,0.05);
}

.loading-fill {
  display: none;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 2px;
  transition: width 0.15s;
}

/* ── Variant panel ─────────────── */
.lv-variant-panel {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 240px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(13, 13, 13, 0.95);
  backdrop-filter: blur(12px);
  padding: 12px;
}

.lv-variant-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-weight: 700;
  font-size: 12px;
}

.lv-variant-toggle-btn {
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  border-radius: var(--radius-xs);
  width: 26px;
  height: 26px;
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.12s;
}

.lv-variant-toggle-btn:hover { border-color: var(--border-light); background: var(--bg-hover); }

.lv-variant-body { display: flex; flex-direction: column; gap: 4px; }

.lv-variant-cat {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-tertiary);
  margin-top: 6px;
}

.lv-variant-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 2px 0;
}

.lv-variant-row input[type="checkbox"] { accent-color: var(--accent); }

.lv-variant-default-badge {
  margin-left: 6px;
  font-size: 9px;
  color: var(--accent);
  font-weight: 600;
}

/* ── Animations ────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Mobile ────────────────────── */
@media (max-width: 1024px) {
  .main-content { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 45vh; overflow-y: auto; }
  .sidebar-section.livery-section { flex: none; min-height: 120px; }
  .viewer-canvas-wrap { min-height: 55vh; }
  .vehicle-list { max-height: 140px; }
}
