:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --ink: #1c2230;
  --muted: #5b6472;
  --line: #e3e7ee;
  --accent: #2563eb;
  --accent-soft: #e8f0fe;
  --radius: 8px;
  --header-h: 64px;
}

* { box-sizing: border-box; }

/* Ensure the `hidden` attribute always wins, even on elements we style with
   display:flex (otherwise the class rule overrides the UA `[hidden]` rule). */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* Header */
.site-header {
  height: var(--header-h);
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 0 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.site-header h1 { font-size: 20px; margin: 0; letter-spacing: -0.01em; }
.tagline { color: var(--muted); margin: 0; font-size: 13px; }

/* Layout: sidebar + viewer */
.layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  height: calc(100vh - var(--header-h));
}

/* Sidebar */
.sidebar {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--panel);
  min-height: 0; /* allow inner scroll */
}
.search-box { padding: 14px 14px 10px; }
#q {
  width: 100%;
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  outline: none;
}
#q:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 14px 10px;
}
.chip {
  font-size: 12px;
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip[aria-pressed="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.result-count {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.results {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.results li {
  padding: 9px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.results li:hover { background: #f3f6fc; }
.results li[aria-selected="true"] { background: var(--accent-soft); }
.results .name { display: block; }
.results .name mark { background: #fff3bf; padding: 0 1px; border-radius: 2px; }
.results .cat {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.results .no-csv { font-style: italic; opacity: 0.7; }

/* Viewer */
.viewer {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.viewer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.viewer-meta { min-width: 0; }
.viewer-meta h2 {
  font-size: 16px;
  margin: 2px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge {
  display: inline-block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 999px;
}
.viewer-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn {
  font-size: 13px;
  padding: 7px 12px;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.05); }
.btn-ghost { background: #fff; color: var(--accent); border: 1px solid var(--line); }

.plot-frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #fff;
}

.viewer-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: var(--muted);
  padding: 24px;
}
.viewer-empty h2 { color: var(--ink); margin-top: 0; }
.category-summary {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
  display: inline-grid;
  gap: 6px;
  text-align: left;
}
.category-summary b { color: var(--ink); }

/* Mobile: stack, and let the selected plot take over */
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .results { max-height: 45vh; }
  .plot-frame { min-height: 70vh; }
}
