:root {
  --color-bg: #161826;
  --color-surface: #232532;
  --color-surface-2: #1c1e2b;
  --color-text: #e9e9ed;
  --color-accent: #9184d9;
  --color-accent-dim: rgba(145, 132, 217, 0.35);
  --color-divider: rgba(233, 233, 237, 0.16);
  --color-muted: rgba(233, 233, 237, 0.60);
  --color-danger: #d97a7a;
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
  --shadow-md: 0 4px 12px rgba(0,0,0,.55);
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --sidebar-w: 280px;
}

* { box-sizing: border-box; }
/* Any element with `hidden` should be invisible regardless of our own
   display: rules on it. Browser default is `[hidden]{display:none}`, but any
   more specific selector on the element (e.g. `.block { display: block }`)
   wins by specificity. `!important` here so the attribute always wins. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

.topbar {
  padding: 16px 24px 12px;
  border-bottom: 1px solid var(--color-divider);
  display: flex;
  align-items: baseline;
  gap: 14px;
}
.brand {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.brand-sub {
  color: var(--color-muted);
  font-size: 12px;
}
.topbar-spacer { flex: 1; }
.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: rgba(233, 233, 237, 0.06);
  border: 1px solid var(--color-divider);
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
}
.user-email {
  font-size: 12px;
  color: var(--color-muted);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-logout {
  background: transparent;
  border: none;
  color: var(--color-accent);
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 999px;
}
.user-logout:hover { background: rgba(145, 132, 217, 0.15); }

.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  gap: 20px;
  padding: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- sidebar ---------- */

.sidebar { display: grid; gap: 16px; }

.side-panel {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.side-panel h2 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.7px;
}

.status {
  margin-top: 10px;
  font-size: 12px;
  color: var(--color-muted);
}

.ingest-block { margin-top: 12px; }
.ingest-meta {
  display: flex;
  gap: 6px;
  margin: 2px 0 8px;
  font-size: 12px;
  color: var(--color-muted);
}
.ingest-meta .dot { opacity: 0.5; }

.progress-wrap {
  height: 5px;
  background: rgba(233, 233, 237, 0.08);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 10px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--color-accent);
  transition: width 200ms ease-out;
}

/* ---------- filters ---------- */

.filter-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.filter-header h2 { margin: 0; }
.linky {
  background: none;
  border: none;
  color: var(--color-accent);
  font-family: inherit;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  cursor: pointer;
  padding: 0;
}
.linky:hover { text-decoration: underline; }

.filter-group {
  padding: 8px 0;
  border-top: 1px solid var(--color-divider);
}
.filter-group:first-of-type { border-top: none; padding-top: 4px; }

.filter-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--color-muted);
  margin-bottom: 6px;
}

.chip {
  display: inline-block;
  background: rgba(145, 132, 217, 0.15);
  color: var(--color-accent);
  padding: 1px 6px;
  border-radius: 10px;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 11px;
  margin-left: auto;
}

.range-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.range-row input {
  width: 0;
  flex: 1;
  min-width: 0;
}
.range-dash {
  color: var(--color-muted);
  font-size: 11px;
}

/* form-control common look */
.filter-group input[type="number"],
.filter-group input[type="text"],
.filter-group select {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--color-divider);
  color: var(--color-text);
  padding: 5px 8px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 12.5px;
}
.filter-group input:focus,
.filter-group select:focus { outline: 1px solid var(--color-accent); }
.filter-group select.wide { display: block; width: 100%; }

/* Range slider tuning — thin track, purple thumb */
.filter-group input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  background: rgba(233, 233, 237, 0.12);
  border-radius: 2px;
  outline: none;
}
.filter-group input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid var(--color-surface);
}
.filter-group input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-accent);
  cursor: pointer;
  border: 2px solid var(--color-surface);
}

/* ---------- buttons ---------- */

button.primary, button.secondary {
  background: var(--color-accent);
  color: #14131f;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}
button.primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
button.secondary {
  background: transparent;
  color: var(--color-text);
  border: 1px solid var(--color-divider);
}
button.secondary.danger {
  color: var(--color-danger);
  border-color: rgba(217, 122, 122, 0.4);
}
button.block { display: block; width: 100%; }
button.block + button.block { margin-top: 8px; }

/* ---------- main panel ---------- */

.main { display: grid; gap: 20px; align-items: start; }
.panel {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  box-shadow: var(--shadow-sm);
}

.library-toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}
.library-toolbar .search-wrap {
  position: relative;
  flex: 1;
  display: flex;
}
.library-toolbar input {
  flex: 1;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--color-divider);
  color: var(--color-text);
  padding: 7px 34px 7px 12px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 13px;
}
.library-toolbar input:focus { outline: 1px solid var(--color-accent); }
.library-toolbar input::-webkit-search-cancel-button { display: none; }

.search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(233, 233, 237, 0.12);
  border: none;
  color: var(--color-text);
  width: 22px;
  height: 22px;
  border-radius: 50%;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.search-clear:hover { background: rgba(233, 233, 237, 0.22); }
.search-clear[hidden] { display: none; }

/* ---------- table ---------- */

.table-scroll {
  overflow-x: auto;
  max-height: 70vh;
  overflow-y: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
th, td {
  text-align: left;
  padding: 7px 10px;
  border-bottom: 1px solid var(--color-divider);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 340px;
}
th {
  color: var(--color-muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--color-surface);
  position: sticky;
  top: 0;
  user-select: none;
}
th.sortable {
  cursor: pointer;
}
th.sortable:hover { color: var(--color-text); }
th.sort-asc::after  { content: " ↑"; color: var(--color-accent); }
th.sort-desc::after { content: " ↓"; color: var(--color-accent); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.err td { color: var(--color-danger); }

/* ---------- diagnostics ---------- */

/* ---------- sign-in overlay ---------- */

.signin-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.signin-card {
  width: min(380px, 92vw);
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: 32px 32px 24px;
  box-shadow: var(--shadow-md);
  text-align: center;
}
.signin-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.signin-sub {
  color: var(--color-muted);
  font-size: 13px;
  margin-bottom: 22px;
}
.signin-google {
  width: 100%;
  background: #fff;
  color: #1f1f1f;
  border: none;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.signin-google:hover { background: #f2f2f2; }
.signin-google:disabled { opacity: 0.5; cursor: not-allowed; }
.signin-google .g-mark {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: conic-gradient(from -45deg, #4285f4, #ea4335 25%, #fbbc05 50%, #34a853 75%, #4285f4);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.signin-err {
  color: var(--color-danger);
  font-size: 12px;
  min-height: 18px;
  margin-top: 12px;
  line-height: 1.4;
}
.signin-foot {
  color: var(--color-muted);
  font-size: 11px;
  margin-top: 18px;
}

.diag pre {
  margin: 0;
  max-height: 200px;
  overflow: auto;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
  font-size: 11px;
  color: var(--color-muted);
  white-space: pre-wrap;
}
