/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --font-display:  'Fraunces', Georgia, serif;
  --font-body:     'DM Sans', system-ui, sans-serif;
  --font-mono:     'JetBrains Mono', 'Courier New', monospace;

  /* Warm neutral palette */
  --bg:              #faf9f7;
  --bg-sidebar:      #ffffff;
  --bg-viewer:       #eceae5;
  --bg-card:         #ffffff;
  --bg-hover:        #f5f4f1;
  --bg-selected:     #eef3ff;

  --text-primary:    #1c1b18;
  --text-secondary:  #6b6660;
  --text-muted:      #a09a94;

  --accent:          #2d5be3;
  --accent-hover:    #1e46cc;
  --accent-subtle:   #eef3ff;

  --border:          #e8e5df;
  --border-strong:   #d0cdc6;

  --badge-yes-bg:    #f0fdf4;
  --badge-yes-text:  #15803d;
  --badge-yes-border:#bbf7d0;
  --badge-no-bg:     #fff1f2;
  --badge-no-text:   #be123c;
  --badge-no-border: #fecdd3;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 16px rgba(0,0,0,0.08);
  --shadow-focus: 0 0 0 3px rgba(45,91,227,0.15);

  --radius:    6px;
  --radius-sm: 4px;
  --sidebar-w: 300px;
  --details-h: 210px;
}

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

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── App shell ─────────────────────────────────────────────────────────────── */
#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

/* ── Sidebar ───────────────────────────────────────────────────────────────── */
#sidebar {
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  /* Sit above the viewer shadow */
  position: relative;
  z-index: 1;
}

.sidebar-header {
  padding: 22px 18px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-header h1 {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 4px;
}

.sidebar-header h1 .accent { color: var(--accent); }

.header-link {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radius-sm);
  transition: opacity 0.15s;
}

.header-link:hover { opacity: 0.75; }

.sidebar-header .subtitle {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Sidebar body ──────────────────────────────────────────────────────────── */
.sidebar-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-top: 14px;
}

/* Search */
.search-wrap {
  padding: 0 14px 12px;
  flex-shrink: 0;
}

#search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg);
  font-family: var(--font-body);
  font-size: 0.85rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

#search:focus {
  border-color: var(--accent);
  box-shadow: var(--shadow-focus);
}

#search::placeholder { color: var(--text-muted); }

/* Filters */
.filter-section {
  padding: 0 14px;
  margin-bottom: 12px;
  flex-shrink: 0;
}

.filter-section summary {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  padding: 5px 0;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  outline: none;
}

.filter-section summary::-webkit-details-marker { display: none; }

.filter-section summary::before {
  content: '▸';
  font-size: 0.6rem;
  color: var(--text-muted);
  transition: transform 0.15s;
  display: inline-block;
}

.filter-section[open] summary::before { transform: rotate(90deg); }

.filter-grid {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 0 4px;
}

.filter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.filter-row-label {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  flex-shrink: 0;
}

.tri-group {
  display: flex;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  flex-shrink: 0;
}

.tri-btn {
  padding: 4px 8px;
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 500;
  background: var(--bg);
  color: var(--text-secondary);
  border: none;
  border-right: 1px solid var(--border-strong);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  outline: none;
  white-space: nowrap;
}

.tri-btn:last-child { border-right: none; }

.tri-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tri-btn.active {
  background: var(--accent);
  color: white;
}

/* Sort */
.sort-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 10px;
  flex-shrink: 0;
}

.sort-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

/* Segmented sort control */
.sort-buttons {
  display: flex;
  flex: 1;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.sort-btn {
  flex: 1;
  padding: 5px 4px;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg);
  color: var(--text-secondary);
  border: none;
  border-right: 1px solid var(--border-strong);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  white-space: nowrap;
  outline: none;
}

.sort-btn:last-child { border-right: none; }

.sort-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sort-btn.active {
  background: var(--accent);
  color: white;
}

.sort-btn .arrow {
  font-size: 0.7rem;
  line-height: 1;
  min-width: 0.7em;
  display: inline-block;
}

/* Count line */
.list-meta {
  padding: 0 14px 6px;
  flex-shrink: 0;
}

#model-count {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

/* ── Model list ────────────────────────────────────────────────────────────── */
#model-list {
  flex: 1;
  overflow-y: auto;
  border-top: 1px solid var(--border);
}

/* Thin scrollbar */
#model-list::-webkit-scrollbar { width: 4px; }
#model-list::-webkit-scrollbar-track { background: transparent; }
#model-list::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 2px;
}

.model-item {
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  border-left: 2px solid transparent;
}

.model-item:hover { background: var(--bg-hover); }

.model-item.selected {
  background: var(--bg-selected);
  border-left-color: var(--accent);
}

.item-name {
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}

.item-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 3px;
}

.meta-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.67rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.meta-fmt {
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* ── Main panel ────────────────────────────────────────────────────────────── */
#main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── 3D Viewer ─────────────────────────────────────────────────────────────── */
#viewer {
  flex: 1;
  position: relative;
  min-height: 0;
  background: var(--bg-viewer);
}

#viewer canvas { display: block; }

/* Placeholder */
#viewer-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.placeholder-inner {
  text-align: center;
  color: var(--text-muted);
  opacity: 0.5;
}

.placeholder-inner svg {
  margin-bottom: 12px;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.placeholder-inner p {
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

/* Loading overlay */
#viewer-loading {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(236, 234, 229, 0.75);
  backdrop-filter: blur(6px);
  color: var(--text-secondary);
  font-size: 0.82rem;
  letter-spacing: 0.03em;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.65s linear infinite;
}

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

/* Toolbar */
#viewer-toolbar {
  position: absolute;
  top: 12px;
  right: 12px;
}

#btn-wireframe {
  padding: 6px 14px;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-sm);
}

#btn-wireframe:hover {
  background: white;
  color: var(--text-primary);
  border-color: var(--accent);
}

#btn-wireframe.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* ── Details panel ─────────────────────────────────────────────────────────── */
#details {
  height: var(--details-h);
  flex-shrink: 0;
  padding: 16px 20px;
  overflow-y: auto;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.empty-details {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-style: italic;
  padding-top: 2px;
}

/* Details content */
.details-header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.details-name {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 400;
  color: var(--text-primary);
  line-height: 1.2;
}

.details-id {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-muted);
}

.details-meta {
  display: flex;
  gap: 20px;
  margin-bottom: 10px;
  font-size: 0.8rem;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.details-meta a {
  color: var(--accent);
  text-decoration: none;
}

.details-meta a:hover { text-decoration: underline; }

.btn-download {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  background: var(--accent);
  color: white !important;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  text-decoration: none !important;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-download:hover {
  background: var(--accent-hover) !important;
  text-decoration: none !important;
}

/* Badges */
.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.badge-yes {
  background: var(--badge-yes-bg);
  color: var(--badge-yes-text);
  border-color: var(--badge-yes-border);
}

.badge-no {
  background: var(--badge-no-bg);
  color: var(--badge-no-text);
  border-color: var(--badge-no-border);
}

/* ── Polygon dual-range slider (custom drag) ────────────────────────────────── */
.poly-range-wrap {
  padding: 10px 0 6px;
}

.dual-range {
  position: relative;
  height: 24px;
  display: flex;
  align-items: center;
  cursor: pointer;
  user-select: none;
}

.dual-range-track {
  position: absolute;
  left: 0; right: 0;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
}

.dual-range-fill {
  position: absolute;
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  pointer-events: none;
}

.dual-range-thumb {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  transform: translateX(-50%);
  cursor: grab;
  z-index: 2;
  transition: transform 0.1s;
}

.dual-range-thumb.dragging {
  cursor: grabbing;
  transform: translateX(-50%) scale(1.15);
  z-index: 3;
  transition: none;
}

.poly-range-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 0.67rem;
  color: var(--text-muted);
}

/* Geometry counts in the details panel */
.geo-stats {
  display: flex;
  gap: 20px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.geo-stat {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.geo-stat strong {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-primary);
  margin-left: 4px;
}
