:root {
  --brand-teal:    #10586E;
  --brand-teal-dk: #104D5F;
  --brand-teal-lt: #0B7777;
  --yellow:        #FDD504;
  --lime:          #8DC05B;

  /* Fluent neutrals */
  --n0:   #ffffff;
  --n20:  #faf9f8;
  --n30:  #f3f2f1;
  --n40:  #edebe9;
  --n60:  #e1dfdd;
  --n80:  #c8c6c4;
  --n100: #b3b0ad;
  --n130: #8a8886;
  --n160: #605e5c;
  --n190: #323130;
  --n200: #201f1e;

  /* Fluent accent (Microsoft blue fallback) */
  --accent: #10586E;
  --accent-hover: #104D5F;
  --accent-light: #E5F1F4;

  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 8px;

  --shadow-4:  0 1.6px 3.6px rgba(0,0,0,.132), 0 0.3px 0.9px rgba(0,0,0,.108);
  --shadow-8:  0 3.2px 7.2px rgba(0,0,0,.132), 0 0.6px 1.8px rgba(0,0,0,.108);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  overflow-y: scroll;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--n20);
  color: var(--n190);
  font-size: 14px;
}

/* ── CONTROL CARD (pivot + search + filters, one card) ── */
.control-card {
  background: var(--n0);
  border: 1px solid var(--n60);
  border-radius: var(--radius-lg);
  margin-bottom: 12px;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px 0 4px;
  height: 40px;
}

.filter-row {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px;
  border-top: 1px solid var(--n60);
}
.filter-row.visible { display: flex; }

/* Pivot tabs */
.pivot {
  display: flex;
  align-items: stretch;
  height: 100%;
  flex-shrink: 0;
}
.pivot-btn {
  background: none; border: none;
  font-family: inherit; font-size: 13px; font-weight: 400;
  color: var(--n160); padding: 0 14px;
  cursor: pointer;
  position: relative;
  transition: color 0.1s, background 0.1s;
  white-space: nowrap;
}
.pivot-btn::after {
  content: ''; position: absolute;
  bottom: 0; left: 0; right: 0; height: 2px;
  background: transparent;
  transition: background 0.1s;
}
.pivot-btn:hover { color: var(--n190); background: var(--n30); }
.pivot-btn.active { color: var(--accent); font-weight: 600; }
.pivot-btn.active::after { background: var(--accent); }

.toolbar-sep {
  width: 1px; height: 20px;
  background: var(--n80);
  flex-shrink: 0;
}

/* Search */
.search-wrap {
  flex: 1;
  position: relative;
}
.search-wrap svg {
  position: absolute; left: 9px; top: 50%;
  transform: translateY(-50%);
  color: var(--n130); pointer-events: none;
}
.search-wrap input {
  width: 100%;
  padding: 5px 10px 5px 30px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px; font-family: inherit;
  color: var(--n190); background: transparent;
  outline: none;
  height: 32px;
}
.search-wrap input::placeholder { color: var(--n130); }

/* ── MAIN ── */
main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

/* ══════════════════════════════════════
   OVERVIEW VIEW
══════════════════════════════════════ */
.groups-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.group-card {
  background: var(--n0);
  border-radius: var(--radius-lg);
  border: 1px solid var(--n60);
  transition: box-shadow 0.15s;
}
.group-card:hover { box-shadow: var(--shadow-8); }

.group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--n60);
}
.group-title {
  font-size: 12px; font-weight: 600;
  color: var(--n160);
}
.group-count {
  margin-left: auto;
  font-size: 11px; color: var(--n100);
}

.group-links {
  list-style: none;
  padding: 8px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 4px;
}

.group-links li { min-width: 0; position: relative; }

.tile-row {
  position: relative;
  display: flex;
  align-items: stretch;
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--n40);
  background: var(--n30);
  overflow: hidden;
  transition: border-color 0.1s, background 0.1s;
}
.tile-row:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.tile-link {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  padding: 0 8px;
  text-decoration: none;
  color: var(--n190);
  font-size: 11px; font-weight: 600;
  line-height: 1.3;
  overflow: hidden;
}
.tile-link:hover { color: var(--accent); }
.tile-link.has-related { padding-right: 26px; }

.link-name {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.group-type-label {
  flex-shrink: 0;
  font-size: 9.5px;
  font-weight: 500;
  color: var(--n100);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Related-links expand button + popover (shared: grid tiles & list rows).
   The primary tile/row is always a plain link with its own url; the button is a
   separate, independently clickable element absolutely positioned over a gutter
   that's reserved on EVERY tile/row (not just ones with related links), so the
   type label/badge always lines up whether or not a given item has one. ── */
.expand-btn {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 24px;
  border: none;
  background: transparent;
  color: var(--n130);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.expand-btn:hover { background: var(--accent-light); color: var(--accent); }
.expand-btn.open { background: var(--accent); color: var(--n0); }
.expand-btn svg { transition: transform 0.15s; }
.expand-btn.open svg { transform: rotate(180deg); }

.related-popover {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--n0);
  border: 1px solid var(--n60);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-8);
  padding: 4px;
  z-index: 20;
  min-width: 150px;
  max-width: 220px;
  width: max-content;
}
.related-popover.open { display: block; }
.related-popover a {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 7px 9px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--n190);
  font-size: 12.5px; font-weight: 600;
}
.related-popover a:hover { background: var(--accent-light); color: var(--accent); }
.related-popover .rp-type {
  font-size: 10px; font-weight: 500; color: var(--n100); flex-shrink: 0;
}

/* ══════════════════════════════════════
   LIST VIEW
══════════════════════════════════════ */
#view-list { display: none; }

.filter-chip {
  display: inline-flex; align-items: center;
  padding: 3px 12px;
  border-radius: 100px;
  border: 1px solid var(--n80);
  background: var(--n0);
  font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: inherit;
  color: var(--n160);
  transition: all 0.1s; white-space: nowrap;
  height: 28px;
}
.filter-chip:hover:not(.active) { border-color: var(--n130); color: var(--n190); background: var(--n30); }
.filter-chip.active { background: var(--accent); color: var(--n0); border-color: var(--accent); }

/* Custom dropdown */
.dd-wrap { position: relative; flex-shrink: 0; }
.dd-trigger {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 10px 0 12px;
  border: 1px solid var(--n80); border-radius: 100px;
  font-size: 12px; font-weight: 600; font-family: inherit;
  color: var(--n160); background: var(--n0);
  cursor: pointer; outline: none; white-space: nowrap;
  transition: border-color 0.1s, color 0.1s;
}
.dd-trigger:hover { border-color: var(--n130); color: var(--n190); }
.dd-trigger.open { border-color: var(--accent); color: var(--n190); }
.dd-trigger svg { flex-shrink: 0; transition: transform 0.15s; }
.dd-trigger.open svg { transform: rotate(180deg); }

.dd-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px); left: 0;
  min-width: 100%;
  background: var(--n0);
  border: 1px solid var(--n60);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-8);
  padding: 4px;
  z-index: 200;
}
.dd-menu.open { display: block; }
.dd-item {
  display: block; width: 100%;
  padding: 5px 10px;
  border: none; border-radius: var(--radius-sm);
  background: none; text-align: left;
  font-size: 12px; font-weight: 600; font-family: inherit;
  color: var(--n160); cursor: pointer;
  transition: background 0.1s, color 0.1s;
  white-space: nowrap;
}
.dd-item:hover { background: var(--n30); color: var(--n190); }
.dd-item.selected { color: var(--accent); background: var(--accent-light); }

.filter-sep {
  width: 1px; height: 20px;
  background: var(--n80);
  flex-shrink: 0; margin: 0 2px;
}

.aud-row { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }

.results-count {
  font-size: 12px; color: var(--n130);
  margin-bottom: 6px; padding-left: 2px;
}

.link-list { display: flex; flex-direction: column; gap: 2px; }

.list-row-wrap { position: relative; }

.list-row {
  position: relative;
  display: flex; align-items: stretch;
  background: var(--n0);
  border: 1px solid var(--n60);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.list-row:hover {
  border-color: var(--accent);
  box-shadow: var(--shadow-4);
}

.link-item {
  flex: 1; min-width: 0;
  padding: 7px 12px;
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: var(--n190);
}
.link-item:hover { color: var(--accent); }
.link-item.has-related { padding-right: 26px; }
.link-name-text {
  flex: 1; min-width: 0;
  font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tag-badge {
  padding: 1px 7px; border-radius: 2px;
  font-size: 11px; font-weight: 500;
  flex-shrink: 0;
  background: var(--n40);
  color: var(--n160);
}

.no-results {
  text-align: center; padding: 40px 20px;
  color: var(--n100); font-size: 14px;
}

/* ── RESPONSIVE ── */
@media (max-width: 1250px) {
  .groups-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
  main { padding: 12px 10px 36px; }
  .groups-grid { grid-template-columns: 1fr; gap: 10px; }
  .group-links { grid-template-columns: repeat(2, 1fr); }
}
