/* Obsidian Bases views — table + card rendering, themed via site CSS vars. */

.base-view {
  margin: 1.5rem 0;
  font-size: 0.9rem;
}

/* Toolbar: tabs + search row + active-filter chips */
.base-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.6rem;
}

.base-tabs {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.base-search-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  /* auto basis: content-sized height when the toolbar stacks to a column
     (mobile), full width when it's a row (desktop) */
  flex: 1 1 auto;
  min-width: 240px;
  flex-wrap: wrap;
}

.base-tab {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.base-tab:hover { background: var(--bg-secondary); color: var(--text); border-color: var(--accent); }
.base-tab.active {
  background: var(--bg-secondary);
  color: var(--text);
  border-color: var(--accent);
  font-weight: 600;
}

.base-filter {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  min-width: 140px;
  flex: 1 1 160px;
}
.base-filter:focus { outline: none; border-color: var(--accent); }

/* Filter button */
.base-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.base-filter-btn:hover { border-color: var(--accent); }
.base-filter-btn[aria-expanded="true"] { border-color: var(--accent); }
.base-filter-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 600;
}
/* Flex/inline-flex display above would override the HTML `hidden` attribute */
.base-filter-badge[hidden],
.base-active-filters[hidden] { display: none; }

.base-count-label {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
}

/* Filter popup */
.base-filter-popup {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.4rem;
  z-index: 20;
  width: min(320px, 90vw);
  max-height: 60vh;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
}
.base-filter-popup-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
  font-weight: 600;
  font-size: 0.85rem;
}
.base-filter-clear {
  background: none;
  border: none;
  color: var(--link);
  font: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  padding: 0;
}
.base-filter-clear:hover { text-decoration: underline; }

/* Custom multi-select: a header (summary) that expands to a checklist */
.base-facet { margin-bottom: 0.45rem; border: 1px solid var(--border-light); border-radius: 6px; overflow: hidden; }
.base-facet-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg);
  border: none;
  padding: 0.4rem 0.6rem;
  font: inherit;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}
.base-facet-head:hover { background: var(--bg-secondary); }
.base-facet-name { flex: 0 0 auto; font-size: 0.68rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.base-facet-summary { flex: 1 1 auto; min-width: 0; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.base-facet-summary.is-empty { color: var(--text-muted); }
.base-facet-chevron { flex: 0 0 auto; color: var(--text-muted); transition: transform 0.15s; }
.base-facet-head[aria-expanded="true"] .base-facet-chevron { transform: rotate(180deg); }
.base-facet-options { display: flex; flex-direction: column; max-height: 230px; overflow-y: auto; border-top: 1px solid var(--border-light); }
/* `display: flex` above would override the HTML `hidden` attribute */
.base-facet-options[hidden] { display: none; }
.base-facet-opt {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  background: none;
  border: none;
  padding: 0.32rem 0.6rem;
  font: inherit;
  font-size: 0.82rem;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.base-facet-opt:hover { background: var(--bg-secondary); }
.base-facet-opt-check { flex: 0 0 1em; width: 1em; color: var(--accent); font-weight: 700; }
.base-facet-opt[aria-checked="true"] .base-facet-opt-check::before { content: "\2713"; }
.base-facet-opt[aria-checked="true"] { font-weight: 600; }

/* Active-filter chips */
.base-active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  flex-basis: 100%;
}
.base-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--border-light);
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}
.base-chip:hover { border-color: var(--accent); }
.base-chip-x { font-size: 0.95rem; line-height: 1; color: var(--text-muted); }
.base-chip:hover .base-chip-x { color: var(--text); }

/* --- Table --- */
.base-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-light);
  border-radius: 8px;
}

.base-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.85rem;
  /* Override the global markdown-table rules: `margin: 1rem 0` (empty space
     above the header) and `display: block` (which leaves the grid at content
     width inside a 100%-wide block, i.e. empty space on the right). */
  margin: 0;
  display: table;
}

.base-table th,
.base-table td {
  text-align: left;
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.base-table thead th {
  position: sticky;
  top: 0;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-weight: 600;
  white-space: nowrap;
  z-index: 1;
}

.base-th.sortable { cursor: pointer; user-select: none; }
.base-th.sortable:hover { color: var(--text); }

.base-sort-arrow {
  display: inline-block;
  width: 0.7em;
  margin-left: 0.25em;
  opacity: 0.4;
}
.base-th[data-sort-dir="asc"] .base-sort-arrow::after { content: "▲"; opacity: 1; }
.base-th[data-sort-dir="desc"] .base-sort-arrow::after { content: "▼"; opacity: 1; }

.base-row:hover { background: var(--callout-bg); }
.base-row:last-child td { border-bottom: none; }

.base-table[data-rowheight="tall"] td { padding-top: 0.7rem; padding-bottom: 0.7rem; }
.base-table[data-rowheight="short"] td { padding-top: 0.3rem; padding-bottom: 0.3rem; }

.base-group-row td {
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--text-secondary);
}
.base-group-count {
  color: var(--text-muted);
  font-weight: 400;
  font-size: 0.8em;
  margin-left: 0.3em;
}

.base-cell-img {
  display: block;
  max-width: 56px;
  height: auto;
  border-radius: 4px;
}

.base-check { color: var(--accent); font-weight: 700; }
.base-cell-number, .base-summary-cell { font-variant-numeric: tabular-nums; }

.base-summary-row td {
  background: var(--bg-secondary);
  font-weight: 600;
  border-top: 2px solid var(--border);
}

/* Pills for categorical / list-valued properties */
.base-pill {
  display: inline-block;
  background: var(--tag-bg);
  color: var(--tag-text);
  border: 1px solid var(--border-light);
  border-radius: 4px;
  padding: 0.05rem 0.4rem;
  margin: 0.1rem 0.2rem 0.1rem 0;
  font-size: 0.78rem;
  white-space: nowrap;
}
/* Clickable pills set the matching facet filter */
.base-pill-filter { cursor: pointer; transition: border-color 0.12s, background 0.12s, color 0.12s; }
.base-pill-filter:hover,
.base-pill-filter:focus-visible {
  border-color: var(--accent);
  color: var(--text);
  outline: none;
}

/* --- Cards --- */
.base-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-size, 200px), 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.base-card {
  border: 1px solid var(--border-light);
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-secondary);
  transition: border-color 0.15s, transform 0.15s;
}
.base-card:hover { border-color: var(--accent); transform: translateY(-2px); }

.base-card-cover { display: block; }
.base-card-cover:hover { opacity: 0.92; }

.base-card-img {
  width: 100%;
  background: var(--code-bg);
  display: flex;
  align-items: center;
  justify-content: center;
}
.base-card-img img {
  width: 100%;
  height: 100%;
  object-fit: var(--fit, cover);
}
.base-card-img-empty::after {
  content: "🎮";
  font-size: 2rem;
  opacity: 0.3;
}

.base-card-body { padding: 0.6rem 0.7rem; }
.base-card-title { font-weight: 600; margin-bottom: 0.35rem; line-height: 1.25; }
.base-card-title a { text-decoration: none; }
.base-card-title a:hover { text-decoration: underline; }

.base-card-fields {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.78rem;
}
.base-field { display: flex; gap: 0.4rem; align-items: baseline; }
.base-field-label { color: var(--text-muted); flex: 0 0 auto; min-width: 4.5em; }
.base-field-value { color: var(--text-secondary); min-width: 0; overflow-wrap: anywhere; }
/* Long values (e.g. "Universal Interactive Studios") wrap inside the fixed-width card */
.base-card-fields .base-pill { font-size: 0.72rem; white-space: normal; }

.base-group-label {
  font-size: 1rem;
  margin: 1rem 0 0.6rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--border-light);
}

/* --- List --- */
.base-list { list-style: none; padding: 0; margin: 0; }
.base-list-item { padding: 0.3rem 0; border-bottom: 1px solid var(--border-light); }

@media (max-width: 600px) {
  .base-toolbar { flex-direction: column; align-items: stretch; }
  .base-filter { flex: 1 1 auto; }
  .base-cell-img { max-width: 40px; }
}
