/* Make the `hidden` HTML attribute actually hide elements that have a
   non-default `display` rule. Without this, `el.hidden = true` does
   nothing on `.calc-grid` (display: grid), `.calc-active-filters`
   (display: flex), etc. */
[hidden] { display: none !important; }

.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--s-5);
  margin: var(--s-8) auto;
  max-width: 1080px;
}

.calc-footnote { max-width: 1080px; margin-left: auto; margin-right: auto; }

.calc-card {
  display: flex; flex-direction: column;
  padding: var(--s-6);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  text-decoration: none;
  color: inherit;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.calc-card:hover {
  border-color: var(--c-primary);
  box-shadow: var(--shadow-md);
  text-decoration: none;
  transform: translateY(-2px);
}
.calc-card:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

.calc-card-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 48px; height: 48px;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  border-radius: var(--r-md);
  margin-bottom: var(--s-4);
}

.calc-card h2 {
  font-size: var(--text-lg);
  font-weight: 700;
  margin: 0 0 var(--s-2);
  color: var(--c-text);
}
.calc-card p {
  font-size: var(--text-sm);
  color: var(--c-text-secondary);
  margin: 0 0 var(--s-4);
  flex: 1;
  line-height: 1.5;
}
.calc-card-cta {
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--c-primary);
}

.calc-footnote {
  text-align: center;
  color: var(--c-text-secondary);
  font-size: var(--text-sm);
  margin: var(--s-6) 0 var(--s-10);
}
.calc-footnote-btn {
  background: none; border: none; padding: 0;
  color: var(--c-primary); font: inherit; cursor: pointer;
  font-weight: 600;
}
.calc-footnote-btn:hover { text-decoration: underline; }

/* ── Page wrapper ───────────────────────────────────────────────
   Constrain the new toolbar + content area to the same width as
   the old grid so the page feels balanced. */
.calc-toolbar,
.calc-active-filters,
.calc-result-count,
.calc-content {
  max-width: 1080px;
  margin-left: auto;
  margin-right: auto;
}
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Toolbar (search · sort · view toggle) ─────────────────── */
.calc-toolbar {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  margin: var(--s-6) auto var(--s-3);
  padding: 0 var(--s-2);
  flex-wrap: wrap;
}

.calc-toolbar-search {
  position: relative;
  flex: 1 1 280px;
  min-width: 0;
}
.calc-search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-secondary);
  pointer-events: none;
}
.calc-search-input {
  width: 100%;
  height: 44px;
  padding: 0 38px 0 38px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  font: inherit;
  font-size: 15px;
  background: var(--c-surface);
  color: var(--c-text);
}
.calc-search-input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}
.calc-search-input::placeholder { color: var(--c-text-secondary); }
.calc-search-clear {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 32px; height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-radius: 999px;
  color: var(--c-text-secondary);
  cursor: pointer;
}
.calc-search-clear:hover { background: var(--c-border-light); color: var(--c-text); }
.calc-search-clear:focus-visible { outline: 2px solid var(--c-primary); }

.calc-toolbar-controls {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
}

/* Sort */
.calc-sort-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 44px;
  padding: 0 4px 0 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  background: var(--c-surface);
}
.calc-sort-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text-secondary);
}
.calc-sort-select {
  height: 36px;
  padding: 0 8px;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  color: var(--c-text);
  cursor: pointer;
}
.calc-sort-select:focus { outline: none; }
.calc-sort-wrap:focus-within { border-color: var(--c-primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }

/* View toggle */
.calc-view-toggle {
  display: inline-flex;
  height: 44px;
  padding: 4px;
  background: var(--c-border-light);
  border-radius: var(--r-md);
  gap: 2px;
}
.calc-view-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 12px;
  background: transparent;
  border: none;
  border-radius: 6px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-text-secondary);
  cursor: pointer;
  transition: background 120ms var(--ease), color 120ms var(--ease);
}
.calc-view-btn:hover { color: var(--c-text); }
.calc-view-btn.is-active {
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.calc-view-btn:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }

/* ── Active filters bar ────────────────────────────────────── */
.calc-active-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 auto var(--s-3);
  padding: 0 var(--s-2);
}
.calc-active-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text-secondary);
}
.calc-active-chips {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}
.calc-active-chip { padding-right: 4px !important; }
.calc-active-chip-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  margin-left: 2px;
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
  color: inherit;
  opacity: 0.7;
}
.calc-clear-all {
  background: none;
  border: none;
  padding: 6px 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-primary);
  cursor: pointer;
  border-radius: 6px;
  min-height: 32px;
}
.calc-clear-all:hover { background: var(--c-primary-soft); }
.calc-clear-all:focus-visible { outline: 2px solid var(--c-primary); }

/* ── Result count ──────────────────────────────────────────── */
.calc-result-count {
  margin: 0 auto var(--s-2);
  padding: 0 var(--s-2);
  font-size: 13px;
  color: var(--c-text-secondary);
}

/* ── Tag chips (table + grid) ──────────────────────────────── */
.tag-chip {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  background: var(--c-border-light);
  color: var(--c-text-secondary);
  cursor: pointer;
  transition: filter 120ms var(--ease), border-color 120ms var(--ease);
  white-space: nowrap;
}
.tag-chip:hover { filter: brightness(0.96); }
.tag-chip:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }
.tag-chip.is-active {
  border-color: currentColor;
  filter: brightness(0.95);
}
.tag-chip-specialty { background: rgba(37, 99, 235, 0.10); color: #1d4ed8; }
.tag-chip-useCase   { background: rgba(13, 148, 136, 0.10); color: #0f766e; }
.tag-chip-age       { background: rgba(217, 119, 6, 0.12); color: #b45309; }
.tag-chip-setting   { background: rgba(75, 85, 99, 0.12); color: #374151; }
.tag-chip-other     { background: var(--c-border-light); color: var(--c-text-secondary); }

/* ── Table view ────────────────────────────────────────────── */
.calc-table-wrap {
  margin: 0 auto var(--s-6);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  background: var(--c-surface);
  overflow: hidden;
}
.calc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.calc-table thead {
  background: var(--c-border-light);
}
.calc-table th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--c-text-secondary);
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-border);
}
.calc-th-name { width: 38%; }
.calc-th-tags { width: 38%; }
.calc-th-source { width: 24%; }
.calc-table tbody tr {
  border-bottom: 1px solid var(--c-border);
  transition: background 120ms var(--ease);
}
.calc-table tbody tr:last-child { border-bottom: none; }
.calc-table tbody tr:hover { background: rgba(37, 99, 235, 0.025); }
.calc-table td {
  padding: 14px 16px;
  vertical-align: top;
}

.calc-cell-name { min-width: 200px; }
.calc-name-link {
  display: inline-block;
  font-weight: 600;
  font-size: 15px;
  color: var(--c-text);
  text-decoration: none;
  min-height: 24px;
}
.calc-name-link:hover { color: var(--c-primary); text-decoration: none; }
.calc-name-link:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; border-radius: 2px; }
.calc-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--c-text-secondary);
  line-height: 1.5;
}

.calc-cell-tags { min-width: 200px; }
.calc-tag-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.calc-cell-source { min-width: 160px; }
.calc-source-link {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 500;
  color: var(--c-primary);
  text-decoration: none;
  line-height: 1.4;
}
.calc-source-link:hover { text-decoration: underline; }
.calc-source-link:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; border-radius: 2px; }
.calc-source-ext { display: inline-flex; opacity: 0.7; flex-shrink: 0; }

/* ── Empty state ───────────────────────────────────────────── */
.calc-empty {
  margin: var(--s-8) auto;
  padding: var(--s-8);
  text-align: center;
  border: 1px dashed var(--c-border);
  border-radius: var(--r-lg);
  color: var(--c-text-secondary);
}
.calc-empty p { margin: 0 0 var(--s-3); }

/* ── Grid view: tag row addition ───────────────────────────── */
.calc-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 var(--s-3);
}
.calc-card .calc-card-tags + .calc-card-cta { margin-top: var(--s-2); }
/* Cards rendered by JS no longer have the SVG icon block — collapse the
   margin reserved for it on the grid layout. */
.calc-card > h2:first-child { margin-top: 0; }

/* ── Mobile: stacked-card table ────────────────────────────── */
@media (max-width: 600px) {
  .calc-toolbar {
    gap: var(--s-2);
    padding: 0;
  }
  .calc-toolbar-search { flex: 1 1 100%; }
  .calc-toolbar-controls {
    width: 100%;
    justify-content: space-between;
    gap: var(--s-2);
  }
  .calc-sort-wrap { flex: 1 1 auto; min-width: 0; }
  .calc-sort-select { width: 100%; }
  .calc-view-toggle { flex-shrink: 0; }
  .calc-view-btn span { display: none; }   /* icon-only on small screens */
  .calc-view-btn { padding: 0 10px; }

  .calc-active-filters,
  .calc-result-count {
    padding: 0;
  }

  /* Stack table rows as cards */
  .calc-table-wrap {
    border: none;
    background: transparent;
    overflow: visible;
  }
  .calc-table { display: block; }
  .calc-table thead { display: none; }
  .calc-table tbody { display: block; }
  .calc-table tr {
    display: block;
    margin-bottom: var(--s-3);
    padding: var(--s-4);
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--r-lg);
  }
  .calc-table tr:last-child { margin-bottom: 0; }
  .calc-table td {
    display: block;
    padding: 0;
    border: none;
  }
  .calc-cell-name { margin-bottom: var(--s-2); }
  .calc-cell-tags { margin-bottom: var(--s-2); }
  .calc-cell-source { padding-top: var(--s-2); border-top: 1px solid var(--c-border); }
  .calc-cell-source::before {
    content: "Source: ";
    font-size: 11px;
    font-weight: 600;
    color: var(--c-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    display: block;
    margin-bottom: 2px;
  }

  /* Larger touch targets */
  .calc-name-link { font-size: 16px; padding: 4px 0; min-height: 28px; }
  .tag-chip { height: 28px; font-size: 12px; padding: 0 12px; }
}

/* Slightly tighter on very small phones */
@media (max-width: 360px) {
  .calc-table tr { padding: var(--s-3); }
}
