/* === Design tokens === */
:root {
  --bg: #0e1116;
  --bg-elev: #161b22;
  --bg-elev-2: #1f262e;
  --border: #2a323d;
  --text: #e6edf3;
  --text-dim: #8b96a3;
  --text-faint: #5c6773;
  --accent: #58a6ff;
  --accent-hover: #79b8ff;

  /* Status colors (matching xlsx encoding) */
  --status-none: #92D050;
  --status-soft: #FFC107;
  --status-limited: #FF9800;
  --status-hard: #F44336;
  --status-untested: #4a5460;
  --status-na: #2a323d;

  /* Lens type colors (matching xlsx legend) */
  --lens-ff_slr: #00B0F0;
  --lens-ff_rangefinder: #FF66FF;
  --lens-native_mf: #00FFFF;
  --lens-projection: #CC0099;
  --lens-exotic: #d6d6d6;

  --radius: 8px;
  --shadow: 0 4px 12px rgba(0,0,0,0.35);

  --topbar-h: 64px;
  --filters-w: 320px;
  --detail-w: 460px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
}

input, select {
  font-family: inherit;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 10px;
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus { border-color: var(--accent); }

/* === Topbar === */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--topbar-h);
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
}
.topbar-inner {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.2px;
}
.credit {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--text-dim);
}
.credit .sep { margin: 0 6px; opacity: 0.5; }
.donate {
  min-width: 0;
  padding: 6px 12px;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-dim);
}
.donate p { margin: 0; }
.donate strong { color: var(--text); font-weight: 600; overflow-wrap: anywhere; }
.donate-copy { margin-left: 6px; padding: 1px 8px; font-size: 11px; }

/* === Layout === */
body {
  display: grid;
  grid-template-columns: var(--filters-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar topbar"
    "filters main";
}
body.has-detail {
  grid-template-columns: var(--filters-w) 1fr var(--detail-w);
  grid-template-areas:
    "topbar topbar topbar"
    "filters main detail";
}
.topbar { grid-area: topbar; }
.filters { grid-area: filters; }
.main { grid-area: main; }
.detail-panel { grid-area: detail; }

/* === Filters sidebar === */
.filters {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 20px;
  overflow-y: auto;
  max-height: calc(100vh - var(--topbar-h));
  position: sticky;
  top: var(--topbar-h);
}
.filters-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.filters-header h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-dim);
}
.filter-group {
  margin-bottom: 18px;
}
.filter-group > label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-dim);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.filter-group input[type="search"],
.filter-group input[type="number"],
.filter-group select {
  width: 100%;
}
.range-inputs {
  display: flex;
  align-items: center;
  gap: 6px;
}
.range-inputs input {
  width: 100%;
  min-width: 0;
}
.range-inputs span { color: var(--text-faint); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}
.chip:hover { border-color: var(--accent); color: var(--text); }
.chip.active {
  background: var(--bg-elev-2);
  color: var(--text);
  border-color: var(--chip-color, var(--accent));
}
.chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--chip-color, var(--text-faint));
  flex-shrink: 0;
}
.chip-count {
  font-size: 10px;
  color: var(--text-faint);
  margin-left: 2px;
}

.filter-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.result-count {
  font-size: 12px;
  color: var(--text-dim);
}
.result-count strong { color: var(--text); }

button.ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 12px;
  transition: all 0.15s;
}
button.ghost:hover {
  border-color: var(--accent);
  color: var(--text);
}

/* === Main view === */
.main {
  padding: 20px 24px;
  overflow-x: auto;
  min-width: 0;
}
.view-toolbar {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}
.view-tabs {
  display: inline-flex;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.view-tab {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 8px 14px;
  font-size: 13px;
}
.view-tab.active {
  background: var(--bg-elev-2);
  color: var(--text);
}

.state {
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
}
.state.error { color: #f88; }
.state .hint { color: var(--text-faint); font-size: 13px; }
.state code {
  background: var(--bg-elev-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

/* === Table === */
.table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
  max-height: calc(100vh - var(--topbar-h) - 100px);
}
.lens-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.lens-table thead {
  position: sticky;
  top: 0;
  background: var(--bg-elev-2);
  z-index: 1;
}
.lens-table th {
  padding: 10px 12px;
  font-weight: 500;
  font-size: 11px;
  color: var(--text-dim);
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.lens-table th.group-head {
  text-align: center;
  border-left: 1px solid var(--border);
}
.lens-table tr.subhead th {
  font-size: 10px;
  padding: 4px 12px;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
}
.lens-table th.sortable {
  cursor: pointer;
  user-select: none;
}
.lens-table th.sortable:hover { color: var(--text); }
.sort-arrow {
  font-size: 10px;
  margin-left: 4px;
  color: var(--accent);
}
.lens-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.lens-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}
.lens-table tbody tr:hover { background: var(--bg-elev-2); }
.lens-table tbody tr.selected { background: rgba(88, 166, 255, 0.08); }
.lens-table td.num {
  font-variant-numeric: tabular-nums;
  color: var(--text-dim);
  white-space: nowrap;
}
.lens-table td.name {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
}
.lens-type-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.lens-table td.type-cell {
  font-size: 11px;
  color: var(--text-faint);
  white-space: nowrap;
}
.iq-equiv {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-dim);
}

/* === Status pills === */
.status-pill {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--status-untested);
  vertical-align: middle;
  border: 1px solid rgba(255,255,255,0.06);
}
.status-pill[data-status="none"] { background: var(--status-none); }
.status-pill[data-status="soft"] { background: var(--status-soft); }
.status-pill[data-status="limited_range"] { background: var(--status-limited); }
.status-pill[data-status="hard"] { background: var(--status-hard); }
.status-pill[data-status="untested"] { background: var(--status-untested); }
.status-pill[data-status="n/a"] { background: var(--status-na); }

.pagination {
  text-align: center;
  padding: 16px;
}

/* === Grid view === */
.grid-view {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.grid-view .hint {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 0;
  margin-bottom: 12px;
}
.grid-canvas-wrap {
  overflow-x: auto;
}
.grid-canvas svg {
  display: block;
  width: 100%;
  min-width: 800px;
  height: auto;
}
.grid-canvas .grid-axis-line { stroke: var(--border); stroke-width: 1; }
.grid-canvas .grid-axis-text { fill: var(--text-dim); font-size: 11px; font-family: inherit; }
.grid-canvas .grid-row-label { fill: var(--text); font-size: 12px; font-family: inherit; }
.grid-canvas .grid-dot { cursor: pointer; transition: r 0.15s; }
.grid-canvas .grid-dot:hover { r: 6; }

/* === Detail panel === */
.detail-panel {
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  max-height: calc(100vh - var(--topbar-h));
  position: sticky;
  top: var(--topbar-h);
}
.detail-inner { padding: 20px; }
.detail-header {
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.detail-header h2 {
  margin: 0 30px 4px 0;
  font-size: 16px;
  font-weight: 600;
}
.detail-header .meta {
  margin: 0;
  font-size: 12px;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.detail-header .meta .sep { opacity: 0.5; }
.detail-header .close {
  position: absolute;
  top: 0;
  right: 0;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 22px;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.detail-header .close:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}
.detail-section {
  margin-bottom: 24px;
}
.detail-section h3 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
}
.detail-coverage {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.detail-coverage th {
  text-align: left;
  padding: 10px 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.detail-coverage th .ff-equiv {
  font-weight: 400;
  font-size: 11px;
  color: var(--text-dim);
  margin-left: 6px;
}
.detail-coverage td {
  padding: 6px 0;
  vertical-align: top;
}
.detail-coverage td:first-child {
  width: 90px;
  color: var(--text-dim);
  font-size: 12px;
}
.detail-coverage em {
  color: var(--text-faint);
  font-size: 12px;
  font-style: normal;
  display: block;
  margin-top: 2px;
}
.notes {
  font-size: 13px;
  color: var(--text);
  line-height: 1.6;
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}
.detail-footer {
  margin-top: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.dim { color: var(--text-faint); font-size: 11px; margin: 0; }

/* === Responsive === */
@media (max-width: 1100px) {
  /* The donation note wraps to a height that depends on the width, so the
     topbar stops being a fixed-height sticky bar here. */
  .topbar {
    position: static;
    height: auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px 16px;
  }
  body, body.has-detail {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "topbar"
      "filters"
      "main";
  }
  .filters {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .detail-panel {
    position: fixed;
    top: var(--topbar-h);
    right: 0;
    width: 100%;
    max-width: var(--detail-w);
    height: calc(100vh - var(--topbar-h));
    z-index: 100;
    box-shadow: var(--shadow);
  }
}
