/* ============================================================
   e2008 – Neon Observatory Theme
   ============================================================ */

:root {
  color-scheme: dark;
  --bg:          #080c1a;
  --bg-sec:      #0d1225;
  --surface:     #111827;
  --surface-2:   #161f35;
  --line:        rgba(255,255,255,0.07);
  --line-accent: rgba(124,58,237,0.35);
  --text:        #f1f5f9;
  --muted:       #94a3b8;
  --faint:       #475569;
  --purple:      #7c3aed;
  --purple-l:    #a78bfa;
  --teal:        #06b6d4;
  --teal-l:      #67e8f9;
  --pink:        #ec4899;
  --green:       #10b981;
  --orange:      #f59e0b;
  --danger:      #ef4444;
  --blue:        #3b82f6;
  --shadow:      0 8px 32px rgba(0,0,0,0.45);
  --radius:      10px;
  --radius-lg:   14px;
}

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

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}

button, input, select, textarea { font: inherit; }
h1, h2, h3, p { margin: 0; }

/* ── App shell ─────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Stars background ──────────────────────────────── */
.stars-bg {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 0; overflow: hidden;
}
.star {
  position: absolute; border-radius: 50%; background: #fff;
  animation: twinkle var(--d) infinite; opacity: 0;
}
@keyframes twinkle {
  0%,100% { opacity:0 }
  50%      { opacity: var(--o) }
}

/* ── Sidebar ───────────────────────────────────────── */
.sidebar {
  position: relative; z-index: 10;
  width: 220px; flex-shrink: 0;
  background: var(--bg-sec);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 22px 0;
}

.sidebar-brand {
  padding: 0 20px 18px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 10px;
}
.brand-logo {
  display: flex; align-items: center; gap: 9px; margin-bottom: 4px;
}
.brand-hex {
  width: 26px; height: 26px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--purple), var(--teal));
  clip-path: polygon(50% 0%,100% 25%,100% 75%,50% 100%,0% 75%,0% 25%);
}
.brand-name {
  font-size: 14px; font-weight: 700; color: var(--purple-l); letter-spacing: .3px;
}
.brand-sub {
  font-size: 9px; color: var(--faint);
  letter-spacing: 2px; text-transform: uppercase; margin-left: 35px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 20px; margin: 1px 10px;
  border-radius: var(--radius);
  cursor: pointer; text-decoration: none;
  font-size: 13px; color: var(--muted);
  border: 1px solid transparent;
  transition: all .18s;
}
.nav-item:hover {
  background: rgba(124,58,237,.08); color: var(--text);
}
.nav-item.active {
  background: linear-gradient(135deg, rgba(124,58,237,.22), rgba(6,182,212,.07));
  color: var(--purple-l); border-color: var(--line-accent);
}
.nav-icon { font-size: 15px; width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-bottom {
  margin-top: auto; padding: 16px;
  border-top: 1px solid var(--line);
}
.new-btn {
  width: 100%; padding: 10px;
  background: linear-gradient(135deg, var(--purple), #4f46e5);
  border: none; border-radius: var(--radius-lg);
  color: #fff; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: all .2s; letter-spacing: .3px;
}
.new-btn:hover { filter: brightness(1.15); transform: translateY(-1px); }
.new-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ── Main column ───────────────────────────────────── */
.main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; overflow: hidden;
  position: relative; z-index: 1;
}

/* ── Topbar ────────────────────────────────────────── */
.topbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px;
  background: var(--bg-sec); border-bottom: 1px solid var(--line);
}

.topbar-left { display: flex; align-items: center; gap: 14px; }

.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  border-radius: 20px; padding: 7px 14px; width: 240px;
  transition: border-color .2s;
}
.search-bar:focus-within { border-color: var(--line-accent); }
.search-bar input {
  background: none; border: none; outline: none;
  color: var(--muted); font-size: 13px; width: 100%;
  min-height: unset; padding: 0; border-radius: 0; box-shadow: none;
}
.search-icon { color: var(--faint); font-size: 14px; }

.topbar-right { display: flex; align-items: center; gap: 12px; }

/* DB indicator */
.db-indicator {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 30px; padding: 5px 12px;
  border: 1px solid var(--line); border-radius: 20px;
  background: rgba(255,255,255,.04);
  color: var(--muted); font-size: 12px; font-weight: 700;
  white-space: nowrap; transition: all .3s;
}
.db-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 3px rgba(100,116,139,.15);
  transition: all .3s;
}
.db-indicator.online  { color: var(--green); border-color: rgba(16,185,129,.3); }
.db-indicator.online  .db-dot { background: var(--green); box-shadow: 0 0 0 3px rgba(16,185,129,.18); animation: pulse 2s infinite; }
.db-indicator.offline { color: var(--danger); border-color: rgba(239,68,68,.3); }
.db-indicator.offline .db-dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(239,68,68,.18); }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.4;transform:scale(.75)} }

.icon-btn {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,.04); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--muted);
  transition: all .2s;
}
.icon-btn:hover { border-color: var(--line-accent); color: var(--purple-l); }

.user-info { display: flex; align-items: center; gap: 9px; cursor: pointer; }
.user-text { text-align: right; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 10px; color: var(--faint); }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--teal));
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; flex-shrink: 0;
}

/* eyebrow legacy */
.eyebrow { margin: 0 0 3px; color: var(--teal-l); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px; }

/* ── Scrollable content ─────────────────────────────── */
.content {
  flex: 1; overflow-y: auto; padding: 24px 26px 44px;
}
.content::-webkit-scrollbar { width: 4px; }
.content::-webkit-scrollbar-thumb { background: var(--line-accent); border-radius: 2px; }

/* ── Page header ────────────────────────────────────── */
.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 22px;
}
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.5px; }
.page-subtitle { font-size: 13px; color: var(--muted); margin-top: 4px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ── Metric / KPI cards ─────────────────────────────── */
.dashboard-hero {
  display: grid;
  grid-template-columns: minmax(220px,.85fr) minmax(360px,1.35fr) minmax(300px,.95fr);
  gap: 16px;
  align-items: stretch;
  margin-bottom: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 12px; margin-bottom: 18px;
}
.hero-metrics {
  grid-template-columns: 1fr;
  margin-bottom: 0;
}
.metric {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 18px;
  display: grid; gap: 8px;
  position: relative; overflow: hidden;
  transition: border-color .2s;
}
.metric:hover { border-color: rgba(124,58,237,.2); }
.metric::before {
  content: ''; position: absolute; top:0; left:0; right:0; height: 2px;
}
.metric:nth-child(1)::before { background: linear-gradient(90deg, var(--purple), transparent); }
.metric:nth-child(2)::before { background: linear-gradient(90deg, var(--teal),   transparent); }
.metric:nth-child(3)::before { background: linear-gradient(90deg, var(--pink),   transparent); }
.metric:nth-child(4)::before { background: linear-gradient(90deg, var(--green),  transparent); }

.metric span { color: var(--muted); font-size: 12px; }
.metric strong {
  font-size: clamp(20px,2vw,28px); font-weight: 700; letter-spacing: -.5px;
  line-height: 1.1;
}
.metric:nth-child(1) strong { color: var(--purple-l); }
.metric:nth-child(2) strong { color: var(--teal-l); }
.metric:nth-child(3) strong { color: var(--pink); }
.metric:nth-child(4) strong { color: var(--green); }

/* ── Animated vehicle stage ─────────────────────────── */
.vehicle-stage {
  position: relative;
  min-height: 344px;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 42%, rgba(103,232,249,.18), transparent 34%),
    radial-gradient(circle at 18% 78%, rgba(16,185,129,.12), transparent 28%),
    linear-gradient(180deg, #101729 0%, #08101f 100%);
}
.vehicle-stage canvas {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  display: block;
  transition: opacity .3s ease;
}
.vehicle-360-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  opacity: 0;
  transition: opacity .35s ease;
}
.vehicle-stage.viewer-loaded {
  background: #fff;
}
.vehicle-stage.viewer-loaded canvas {
  opacity: 0;
  pointer-events: none;
}
.vehicle-stage.viewer-loaded .vehicle-360-frame {
  opacity: 1;
}
.vehicle-stage.viewer-loaded .vehicle-stage-label {
  opacity: 0;
}
.vehicle-stage-label {
  position: absolute; left: 18px; bottom: 16px;
  display: grid; gap: 3px;
  pointer-events: none;
  transition: opacity .25s ease;
}
.vehicle-stage-label span {
  color: var(--teal-l); font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 1px;
}
.vehicle-stage-label strong {
  color: var(--text); font-size: 22px; line-height: 1;
}

/* ── Panels ─────────────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 20px;
  transition: border-color .2s;
}
.panel:hover { border-color: rgba(124,58,237,.15); }

.panel-heading {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; min-height: 34px; margin-bottom: 14px;
}
h2 { font-size: 15px; font-weight: 600; }

/* ── Workspace grid ──────────────────────────────────── */
.workspace {
  display: grid;
  grid-template-columns: minmax(0,2fr) minmax(300px,.9fr);
  gap: 16px; margin-bottom: 18px;
}
.dashboard-chart { grid-template-columns: 1fr; }

/* ── Chart ───────────────────────────────────────────── */
.panel-wide canvas { display: block; width: 100%; height: 260px; }

/* ── Segmented control ───────────────────────────────── */
.segmented {
  display: flex; overflow: hidden;
  border: 1px solid var(--line); border-radius: 8px;
}
.segment {
  min-height: 30px; padding: 5px 13px; border: 0; border-radius: 0;
  background: rgba(255,255,255,.04); color: var(--muted);
  cursor: pointer; font-size: 12px; font-weight: 600; transition: all .18s;
}
.segment + .segment { border-left: 1px solid var(--line); }
.segment.active { background: var(--purple); color: #fff; }
.segment:hover:not(.active) { background: rgba(124,58,237,.12); color: var(--purple-l); }

/* ── Pill / badge ────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; min-height: 24px;
  padding: 3px 10px; border-radius: 999px;
  background: rgba(6,182,212,.1); color: var(--teal-l);
  font-size: 12px; font-weight: 700; border: 1px solid rgba(6,182,212,.2);
}

/* ── Comparison panel ─────────────────────────────────── */
.comparison-panel { background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%); }
.hero-comparison { min-height: 344px; }

.comparison-list { display: grid; gap: 10px; margin-top: 12px; }
.comparison-item {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 12px; border: 1px solid var(--line);
  border-radius: var(--radius); background: rgba(255,255,255,.03);
  transition: border-color .2s;
}
.comparison-item:hover { border-color: rgba(124,58,237,.2); }
.comparison-item div { display: grid; gap: 3px; }
.comparison-item span { color: var(--muted); font-size: 12px; }

/* ── Table ────────────────────────────────────────────── */
.table-panel { overflow: hidden; }
.table-wrap { width: 100%; overflow-x: auto; }
.table-wrap::-webkit-scrollbar { height: 4px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--line-accent); border-radius: 2px; }

table { width: 100%; border-collapse: collapse; min-width: 760px; }
.compact-table table { min-width: 360px; }

th {
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  text-align: left; white-space: nowrap;
  color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
}
td {
  padding: 11px 10px; border-bottom: 1px solid rgba(255,255,255,.03);
  text-align: left; white-space: nowrap; font-size: 13px;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(255,255,255,.015); }
td.muted { color: var(--muted); font-size: 12px; }

.empty { color: var(--muted); font-size: 13px; padding: 16px 0; display: block; }
.price-cell { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.price-evolution {
  display: inline-flex; align-items: center; gap: 3px;
  font-size: 12px; font-weight: 800; line-height: 1;
}
.trend-arrow { font-size: 13px; }
.price-up   { color: var(--danger); font-weight: 700; }
.price-down { color: var(--green);  font-weight: 700; }
.positive   { color: var(--green); }
.negative   { color: var(--danger); }

/* ── Status text ─────────────────────────────────────── */
.status { color: var(--muted); font-size: 12px; }

/* ── Buttons ─────────────────────────────────────────── */
.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; border-radius: var(--radius);
  padding: 7px 14px; cursor: pointer; font-weight: 700;
  text-decoration: none; border: 1px solid transparent;
  transition: all .18s; white-space: nowrap; font-size: 13px;
}
.button:disabled { opacity: .5; cursor: not-allowed; }

.button.primary {
  background: linear-gradient(135deg, var(--purple), #4f46e5); color: #fff;
}
.button.primary:hover:not(:disabled) { filter: brightness(1.12); transform: translateY(-1px); }

.button.secondary {
  background: linear-gradient(135deg, var(--teal), #0891b2); color: #fff;
}
.button.secondary:hover:not(:disabled) { filter: brightness(1.12); }

.button.ghost {
  background: rgba(255,255,255,.05); border-color: var(--line); color: var(--muted);
}
.button.ghost:hover:not(:disabled) { border-color: var(--line-accent); color: var(--purple-l); }

.button.active-link { background: var(--purple); color: #fff; }

.icon-button {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px;
  border: 1px solid var(--line); border-radius: 999px;
  background: rgba(255,255,255,.05); color: var(--text);
  cursor: pointer; font-size: 22px; line-height: 1; transition: all .2s;
}
.icon-button:hover { border-color: var(--line-accent); }

/* ── Forms ────────────────────────────────────────────── */
.forms-grid {
  display: grid;
  grid-template-columns: minmax(340px,1.1fr) minmax(280px,.8fr) minmax(280px,.8fr);
  gap: 16px; align-items: start;
}
.configuration-grid {
  grid-template-columns: repeat(2, minmax(320px,1fr));
}
.form-panel { display: grid; gap: 12px; }
.form-row   { display: flex; align-items: flex-start; gap: 12px; }
.form-row .field { flex: 1; }

.field { display: grid; gap: 6px; }
.field > span { color: var(--muted); font-size: 12px; font-weight: 500; }
.field.compact { max-width: 210px; }

input, select, textarea {
  width: 100%; min-height: 40px;
  border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius);
  background: rgba(255,255,255,.05); color: var(--text);
  padding: 8px 11px; outline: none; transition: border-color .18s, box-shadow .18s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
textarea { min-height: 82px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--purple); box-shadow: 0 0 0 3px rgba(124,58,237,.18);
}
select option { background: #1e1b4b; color: var(--text); }

/* ── Vehicle list items ──────────────────────────────── */
.list { display: grid; gap: 8px; }
.list-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px; border: 1px solid var(--line);
  border-radius: var(--radius); background: rgba(255,255,255,.03);
}
.list-item div { display: grid; gap: 3px; }
.list-item span { color: var(--muted); font-size: 12px; }
.db-note { color: var(--faint); font-size: 12px; margin-top: 4px; }

/* ── Modal ────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: none; align-items: center; justify-content: center; padding: 18px;
}
.modal.open { display: flex; }
.modal-backdrop {
  position: absolute; inset: 0; border: 0;
  background: rgba(5,8,20,.75); cursor: pointer; backdrop-filter: blur(4px);
}
.modal-dialog {
  position: relative; z-index: 1;
  width: min(760px,100%); max-height: min(860px,calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--line-accent); border-radius: var(--radius-lg);
  background: var(--bg-sec); padding: 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,.65);
}
.modal-actions { display: flex; align-items: center; gap: 10px; }

/* ── Legacy actions row ─────────────────────────────── */
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* ── Page footer ─────────────────────────────────────── */
.page-footer { text-align: center; font-size: 11px; color: var(--faint); margin-top: 28px; opacity: .5; }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 1120px) {
  .dashboard-hero {
    grid-template-columns: minmax(0,1fr) minmax(320px,1.15fr);
  }
  .hero-comparison { grid-column: 1 / -1; min-height: auto; }
  .hero-metrics { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .metrics, .workspace, .forms-grid, .configuration-grid {
    grid-template-columns: repeat(2, minmax(0,1fr));
  }
  .panel-wide, .table-panel { grid-column: 1 / -1; }
}

@media (max-width: 800px) {
  .sidebar { width: 60px; }
  .brand-name, .brand-sub, .nav-label-text { display: none; }
  .search-bar { display: none; }
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
    padding: 14px 18px;
  }
  .actions {
    width: 100%;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 3px;
  }
  .actions .button, .actions .db-indicator {
    flex: 0 0 auto;
  }
}

@media (max-width: 640px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; flex-direction: row; padding: 10px 0; }
  .dashboard-hero { grid-template-columns: 1fr; }
  .hero-metrics { grid-template-columns: 1fr; }
  .vehicle-stage { min-height: 280px; }
  .metrics, .workspace, .forms-grid { grid-template-columns: 1fr; }
  .comparison-item { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; }
}
