/* SearchKit Box
 * Palette, spacing, borders, radius and shadows all come from the active
 * CiviCRM theme (RiverLea --crm-* custom properties) with Greenwich-safe
 * fallbacks, so cards follow the theme's stream and dark mode automatically.
 * Only the grid geometry uses extension-local vars (--box-*).
 */

/* ── Grid: configurable cards-per-row ───────────────────────────────────── */
.crm-search-display-box .crm-search-box-grid {
  display: grid;
  gap: var(--crm-flex-gap, 1rem);
  align-items: start;
}
.crm-search-box-grid.is-count {
  grid-template-columns: repeat(var(--box-cols, 3), minmax(0, 1fr));
}
.crm-search-box-grid.is-auto {
  grid-template-columns: repeat(auto-fill, minmax(var(--box-min, 240px), 1fr));
}
/* Fixed-count grids degrade gracefully on narrower viewports. */
@media (max-width: 900px) {
  .crm-search-box-grid.is-count {
    grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr));
  }
}
@media (max-width: 560px) {
  .crm-search-box-grid.is-count {
    grid-template-columns: 1fr;
  }
}

/* ── Card ───────────────────────────────────────────────────────────────── */
/* The <crm-search-box-card> component element is transparent to layout, so the
 * inner card div is placed directly by the grid (or the host container). */
crm-search-box-card {
  display: contents;
}
/* overflow stays visible so kebab dropdowns can escape the card; the image
 * slot clips its own corners instead. */
.crm-search-box-card {
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--crm-container-bg-color, #fff);
  color: var(--crm-text-color, #34303b);
  border: var(--crm-border, 1px solid #cad5d7);
  border-radius: var(--crm-l-radius, 4px);
  box-shadow: var(--crm-shadow-block, 0 2px 8px rgba(0, 0, 0, 0.06));
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}
.crm-search-box-card:hover {
  box-shadow: var(--crm-shadow-popup, 0 3px 18px rgba(48, 40, 40, 0.18));
  transform: translateY(-1px);
}

/* ── Left-edge accent ───────────────────────────────────────────────────── */
/* The accent-bar element carries the display cssRules class (bg-<family>), so
 * the theme colors this 4px strip directly — no whole-box recolor, so the box
 * surface is free for the background tint below. Badges/dots keep their own
 * colors (they are not this element). */
.crm-search-box-accent {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  border-radius: var(--crm-l-radius, 4px) 0 0 var(--crm-l-radius, 4px);
  pointer-events: none;
}

/* ── Whole-box background tint by field value ───────────────────────────── */
/* A separate rule set tints the whole box. A soft color-mix of the theme's
 * semantic family color with the surface keeps it subtle and legible; both
 * inputs are theme vars, so the tint follows the stream and flips in dark mode,
 * and the text keeps --crm-text-color (which pairs with the surface).
 * Independent of the accent above (distinct class + element). */
.crm-search-box-card.crm-search-box-bg-primary {
  background-color: color-mix(in srgb, var(--crm-primary-color, #005893) 14%, var(--crm-container-bg-color, #fff));
  border-color: color-mix(in srgb, var(--crm-primary-color, #005893) 32%, var(--crm-border-color, #cad5d7));
}
.crm-search-box-card.crm-search-box-bg-secondary {
  background-color: color-mix(in srgb, var(--crm-secondary-color, #5d677b) 14%, var(--crm-container-bg-color, #fff));
  border-color: color-mix(in srgb, var(--crm-secondary-color, #5d677b) 32%, var(--crm-border-color, #cad5d7));
}
.crm-search-box-card.crm-search-box-bg-success {
  background-color: color-mix(in srgb, var(--crm-success-color, #2e562e) 14%, var(--crm-container-bg-color, #fff));
  border-color: color-mix(in srgb, var(--crm-success-color, #2e562e) 32%, var(--crm-border-color, #cad5d7));
}
.crm-search-box-card.crm-search-box-bg-info {
  background-color: color-mix(in srgb, var(--crm-info-color, #20576f) 14%, var(--crm-container-bg-color, #fff));
  border-color: color-mix(in srgb, var(--crm-info-color, #20576f) 32%, var(--crm-border-color, #cad5d7));
}
.crm-search-box-card.crm-search-box-bg-warning {
  background-color: color-mix(in srgb, var(--crm-warning-color, #983b01) 14%, var(--crm-container-bg-color, #fff));
  border-color: color-mix(in srgb, var(--crm-warning-color, #983b01) 32%, var(--crm-border-color, #cad5d7));
}
.crm-search-box-card.crm-search-box-bg-danger {
  background-color: color-mix(in srgb, var(--crm-danger-color, #91223c) 14%, var(--crm-container-bg-color, #fff));
  border-color: color-mix(in srgb, var(--crm-danger-color, #91223c) 32%, var(--crm-border-color, #cad5d7));
}

/* ── Header (title/subtitle main + menu/avatar aside) ───────────────────── */
.crm-search-box-header {
  display: flex;
  align-items: flex-start;
  gap: var(--crm-l-small, 0.4rem);
  padding: var(--crm-padding-reg, 1rem) var(--crm-padding-reg, 1rem) 0;
}
.crm-search-box-header-main {
  flex: 1 1 auto;
  min-width: 0;
}
.crm-search-box-header-aside {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: var(--crm-l-small, 0.35rem);
}
.crm-search-box-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: var(--crm-contact-image-border, 2px solid var(--crm-paper, #fff));
  box-shadow: var(--crm-shadow-block, 0 1px 3px rgba(0, 0, 0, 0.15));
  /* override inline sizing from the core image column type */
  max-width: 40px !important;
  block-size: 40px !important;
}
.crm-search-box-menu .btn {
  padding: 2px 8px;
}

/* ── Footer (split left / right) ────────────────────────────────────────── */
.crm-search-box-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--crm-l-small, 0.4rem);
  margin-top: auto;
  padding: var(--crm-padding-medium, 0.75rem) var(--crm-padding-reg, 1rem);
  border-top: var(--crm-border, 1px solid #cad5d7);
}
.crm-search-box-footer-left,
.crm-search-box-footer-right {
  display: flex;
  align-items: center;
  gap: var(--crm-l-small, 0.4rem);
}
.crm-search-box-footer-right { margin-left: auto; }
.crm-search-box-footer .crm-search-box-badgerow,
.crm-search-box-footer .crm-search-box-statusrow,
.crm-search-box-footer .crm-search-box-iconrow { margin-top: 0; }

/* ── Image slot ─────────────────────────────────────────────────────────── */
.crm-search-box-image-wrap {
  width: 100%;
  overflow: hidden;
  border-radius: var(--crm-l-radius, 4px) var(--crm-l-radius, 4px) 0 0;
  background: var(--crm-layer1-bg-color, #f3f4f6);
}
.crm-search-box-img {
  display: block;
  width: 100%;
  height: 180px;
  object-fit: cover;
  /* override any inline sizing from the core image column type */
  max-width: 100% !important;
  block-size: 180px !important;
}
.crm-search-box-img-placeholder {
  width: 100%;
  height: 180px;
  background: var(--crm-layer2-bg-color, #e9edf2);
}

/* ── Content ────────────────────────────────────────────────────────────── */
.crm-search-box-content {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  padding: var(--crm-padding-medium, 0.75rem) var(--crm-padding-reg, 1rem);
}
.crm-search-box-title {
  font-family: var(--crm-font, inherit);
  font-size: var(--crm-font-medium-size, 1.1em);
  font-weight: 700;
  line-height: 1.3;
  color: var(--crm-text-color, #34303b);
}
.crm-search-box-title a { color: inherit; text-decoration: none; }
.crm-search-box-title a:hover { text-decoration: underline; }
.crm-search-box-subtitle {
  margin-top: 0.15rem;
  font-size: 0.9em;
  color: var(--crm-inactive-color, #696969);
}
.crm-search-box-field {
  margin-top: 0.3rem;
  font-size: 0.875em;
  color: var(--crm-text-color, #34303b);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2em 0.4em;
}
.crm-search-box-field-label {
  margin: 0;
  font-weight: 600;
  font-size: 0.82em;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  white-space: nowrap;
  color: var(--crm-inactive-color, #696969);
}

/* ── Icon metadata rows ─────────────────────────────────────────────────── */
.crm-search-box-iconrow {
  display: flex;
  align-items: baseline;
  gap: 0.45em;
  margin-top: 0.3rem;
  font-size: 0.875em;
  color: var(--crm-inactive-color, #696969);
}
.crm-search-box-iconrow .crm-i {
  color: var(--crm-inactive-color, #696969);
  width: 1em;
  text-align: center;
  flex: 0 0 auto;
}

/* ── Badges (reuse core .badge shape + .bg-* theme colors) ──────────────── */
.crm-search-box-badgerow {
  margin-top: 0.4rem;
  display: flex;
  align-items: center;
  gap: 0.4em;
}
.crm-search-box-badge {
  font-weight: 600;
}
.crm-search-box-badge .crm-search-field-value { color: inherit; }

/* ── Status dot ─────────────────────────────────────────────────────────── */
.crm-search-box-statusrow {
  display: flex;
  align-items: center;
  gap: 0.4em;
  margin-top: 0.35rem;
  font-size: 0.875em;
  color: var(--crm-text-color, #34303b);
}
.crm-search-box-dot {
  flex: 0 0 auto;
  width: 0.7em;
  height: 0.7em;
  border-radius: 50%;
  /* default color; a cssRules .bg-* class overrides via #bootstrap-theme */
  background-color: var(--crm-inactive-color, #919297);
}
.crm-search-box-dot-label .crm-search-field-value { color: inherit; }

/* ── Style presets (structure/density only — palette stays theme-driven) ─── */
/* Compact + Board: denser padding, smaller cover, tighter rows. */
.crm-search-box-style-compact .crm-search-box-header,
.crm-search-box-style-board .crm-search-box-header {
  padding: var(--crm-padding-medium, 0.6rem) var(--crm-padding-medium, 0.75rem) 0;
}
.crm-search-box-style-compact .crm-search-box-content,
.crm-search-box-style-board .crm-search-box-content {
  padding: var(--crm-padding-small, 0.4rem) var(--crm-padding-medium, 0.75rem);
}
.crm-search-box-style-compact .crm-search-box-footer,
.crm-search-box-style-board .crm-search-box-footer {
  padding: var(--crm-padding-small, 0.4rem) var(--crm-padding-medium, 0.75rem);
}
.crm-search-box-style-compact .crm-search-box-title,
.crm-search-box-style-board .crm-search-box-title {
  font-size: var(--crm-font-size, 1em);
}
.crm-search-box-style-compact .crm-search-box-img,
.crm-search-box-style-board .crm-search-box-img {
  height: 120px;
  block-size: 120px !important;
}
.crm-search-box-style-compact .crm-search-box-field,
.crm-search-box-style-board .crm-search-box-field {
  margin-top: 0.15rem;
  font-size: 0.82em;
}

/* Single-line ellipsised title for the dense presets. */
.crm-search-box-style-compact .crm-search-box-title,
.crm-search-box-style-compact .crm-search-box-title a,
.crm-search-box-style-board .crm-search-box-title,
.crm-search-box-style-board .crm-search-box-title a {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Board: thin border + subtle shadow, smaller avatar. */
.crm-search-box-style-board .crm-search-box-card {
  box-shadow: var(--crm-shadow-block, 0 1px 3px rgba(0, 0, 0, 0.08));
}
.crm-search-box-style-board .crm-search-box-avatar {
  width: 28px;
  height: 28px;
  max-width: 28px !important;
  block-size: 28px !important;
}
.crm-search-box-style-board .crm-search-box-subtitle {
  margin-top: 0;
}

/* Outlined: flat, border-only. */
.crm-search-box-style-outlined .crm-search-box-card {
  box-shadow: none;
}
.crm-search-box-style-outlined .crm-search-box-card:hover {
  box-shadow: none;
  transform: none;
  border-color: var(--crm-primary-color, #005893);
}

/* ── Loading skeleton ───────────────────────────────────────────────────── */
.crm-search-box-card-loading .crm-search-box-img-placeholder { height: 180px; }
.crm-search-box-loading-title {
  height: 1.1em;
  width: 75%;
  margin-bottom: 0.55em;
  border-radius: var(--crm-l-radius, 3px);
}
.crm-search-box-loading-body {
  height: 0.8em;
  width: 90%;
  margin-bottom: 0.4em;
  border-radius: var(--crm-l-radius, 3px);
}
