/*
  KEYSYS Case Study Library — public proof grid
  Scope all styles under .cs-library for drop-in use.
*/

.cs-library {
  --cs-dark: #283847;
  --cs-blue: #0197D6;
  --cs-green: #7AC142;
  --cs-text: var(--cs-dark);
  --cs-muted: rgba(40, 56, 71, 0.68);
  --cs-faint: rgba(40, 56, 71, 0.45);
  --cs-border: rgba(40, 56, 71, 0.12);
  --cs-surface: #ffffff;
  --cs-bg: #f4f6f8;
  --cs-shadow: 0 1px 2px rgba(40, 56, 71, 0.05), 0 4px 16px rgba(40, 56, 71, 0.06);
  --cs-shadow-hover: 0 8px 28px rgba(40, 56, 71, 0.1), 0 2px 8px rgba(1, 151, 214, 0.08);
  --cs-card-min-h: 300px;
  --cs-result-h: 66px;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--cs-text);
  background: #fafafa;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  box-sizing: border-box;
  padding-block: clamp(28px, 4vw, 48px) clamp(64px, 8vw, 96px);
  padding-inline: clamp(32px, 5vw, 96px);
  overflow-x: clip;
}

.cs-library__inner {
  width: 100%;
  max-width: none;
  margin: 0 auto;
}

.cs-library__header {
  max-width: 720px;
  margin-bottom: clamp(24px, 4vw, 36px);
}

.cs-library__title {
  font-size: clamp(2rem, 3.5vw, 2.75rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.12;
  margin: 0 0 12px;
}

.cs-library__subhead {
  font-size: clamp(1.05rem, 1.8vw, 1.25rem);
  font-weight: 600;
  line-height: 1.45;
  color: var(--cs-text);
  margin: 0 0 12px;
}

.cs-library__intro {
  font-size: clamp(14px, 1.6vw, 16px);
  line-height: 1.65;
  color: var(--cs-muted);
  margin: 0;
}

/* Toolbar */
.cs-library__toolbar {
  position: sticky;
  top: 69px;
  z-index: 40;
  margin-bottom: clamp(16px, 2.5vw, 24px);
  background: rgba(244, 246, 248, 0.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  padding: 12px 0 14px;
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}

.cs-library__toolbar.is-stuck {
  border-bottom-color: var(--cs-border);
}

.cs-library__search-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.cs-library__search {
  flex: 1;
  min-width: 0;
  position: relative;
}

.cs-library__search input {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  padding: 11px 14px 11px 38px;
  border: 1px solid var(--cs-border);
  border-radius: 10px;
  background: var(--cs-surface);
  color: var(--cs-text);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.cs-library__search input:focus {
  outline: none;
  border-color: rgba(1, 151, 214, 0.45);
  box-shadow: 0 0 0 3px rgba(1, 151, 214, 0.1);
}

.cs-library__search input::placeholder {
  color: var(--cs-faint);
}

.cs-library__search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--cs-faint);
  pointer-events: none;
}

.cs-library__mobile-filter-btn {
  display: none;
  flex-shrink: 0;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--cs-border);
  background: var(--cs-surface);
  color: var(--cs-text);
  cursor: pointer;
  white-space: nowrap;
}

/* Filter bar */
.cs-library__filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.cs-library__dropdowns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.cs-library__count {
  font-size: 13px;
  font-weight: 600;
  color: var(--cs-muted);
  white-space: nowrap;
  margin: 0;
}

.cs-library__dropdown {
  position: relative;
}

.cs-library__dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--cs-border);
  background: var(--cs-surface);
  color: var(--cs-text);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
  white-space: nowrap;
}

.cs-library__dropdown-trigger:hover {
  border-color: rgba(1, 151, 214, 0.35);
  color: var(--cs-blue);
}

.cs-library__dropdown-trigger.is-open,
.cs-library__dropdown-trigger.has-selection {
  border-color: rgba(1, 151, 214, 0.35);
  color: var(--cs-blue);
}

.cs-library__dropdown-trigger.has-selection {
  background: rgba(1, 151, 214, 0.06);
}

.cs-library__dropdown-chevron {
  font-size: 10px;
  opacity: 0.55;
  line-height: 1;
}

.cs-library__dropdown-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 220px;
  max-height: 280px;
  overflow-y: auto;
  background: var(--cs-surface);
  border: 1px solid var(--cs-border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(40, 56, 71, 0.12);
  padding: 6px;
  z-index: 50;
}

.cs-library__dropdown-panel.is-open {
  display: block;
}

.cs-library__dropdown-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  padding: 9px 10px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--cs-muted);
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}

.cs-library__dropdown-option:hover {
  background: rgba(1, 151, 214, 0.06);
  color: var(--cs-text);
}

.cs-library__dropdown-option.is-selected {
  color: var(--cs-blue);
  font-weight: 600;
  background: rgba(1, 151, 214, 0.08);
}

.cs-library__dropdown-check {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  border-radius: 4px;
  border: 1.5px solid rgba(40, 56, 71, 0.2);
  display: grid;
  place-items: center;
  font-size: 10px;
  color: #fff;
  transition: background 0.12s, border-color 0.12s;
}

.cs-library__dropdown-option.is-selected .cs-library__dropdown-check {
  background: var(--cs-blue);
  border-color: var(--cs-blue);
}

/* Active filters */
.cs-library__active-row {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}

.cs-library__active-row.is-visible {
  display: flex;
}

.cs-library__active-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cs-faint);
  flex-shrink: 0;
}

.cs-library__active-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.cs-library__active-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px 4px 10px;
  border-radius: 100px;
  background: rgba(1, 151, 214, 0.1);
  color: var(--cs-blue);
  border: 1px solid rgba(1, 151, 214, 0.18);
}

.cs-library__active-tag button {
  font: inherit;
  font-size: 14px;
  line-height: 1;
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.7;
}

.cs-library__active-tag button:hover {
  opacity: 1;
}

.cs-library__clear {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--cs-blue);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  flex-shrink: 0;
}

/* Mobile drawer */
.cs-library__drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(40, 56, 71, 0.4);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.25s;
}

.cs-library__drawer-backdrop.is-open {
  display: block;
  opacity: 1;
}

.cs-library__drawer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 85vh;
  background: var(--cs-surface);
  border-radius: 16px 16px 0 0;
  z-index: 201;
  transform: translateY(100%);
  transition: transform 0.28s ease;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -8px 40px rgba(40, 56, 71, 0.15);
}

.cs-library__drawer.is-open {
  transform: translateY(0);
}

.cs-library__drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--cs-border);
}

.cs-library__drawer-head h3 {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}

.cs-library__drawer-close {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border: none;
  background: none;
  color: var(--cs-blue);
  cursor: pointer;
  padding: 4px;
}

.cs-library__drawer-body {
  overflow-y: auto;
  padding: 16px 20px 24px;
}

.cs-library__drawer-section {
  margin-bottom: 20px;
}

.cs-library__drawer-section h4 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cs-faint);
  margin: 0 0 10px;
}

.cs-library__drawer-options {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cs-library__drawer-option {
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 100px;
  border: 1px solid var(--cs-border);
  background: var(--cs-surface);
  color: var(--cs-muted);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}

.cs-library__drawer-option.is-selected {
  background: var(--cs-blue);
  border-color: var(--cs-blue);
  color: #fff;
}

.cs-library__drawer-apply {
  display: block;
  width: calc(100% - 40px);
  margin: 0 20px 20px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 14px;
  border: none;
  border-radius: 10px;
  background: var(--cs-blue);
  color: #fff;
  cursor: pointer;
}

/* Grid */
.cs-library__grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-rows: 1fr;
  align-items: stretch;
  gap: clamp(12px, 1.5vw, 18px);
  list-style: none;
  margin: 0;
  padding: 0;
}

@media (min-width: 600px) {
  .cs-library__grid {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
  }
}

@media (min-width: 900px) {
  .cs-library__grid {
    grid-template-columns: repeat(3, minmax(220px, 1fr));
  }
}

@media (min-width: 1200px) {
  .cs-library__grid {
    grid-template-columns: repeat(4, minmax(220px, 1fr));
  }
}

@media (min-width: 1600px) {
  .cs-library__grid {
    grid-template-columns: repeat(5, minmax(220px, 1fr));
  }
}

/* Card */
.cs-card {
  width: 100%;
  min-width: 0;
  height: 100%;
  display: flex;
}

.cs-card__link {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  width: 100%;
  min-height: var(--cs-card-min-h);
  height: 100%;
  background: var(--cs-surface);
  border: 1px solid var(--cs-border);
  border-radius: 12px;
  box-shadow: var(--cs-shadow);
  padding: 16px 16px 0;
  text-decoration: none;
  color: inherit;
  box-sizing: border-box;
  overflow: hidden;
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
}

.cs-card__link:hover {
  transform: translateY(-2px);
  box-shadow: var(--cs-shadow-hover);
  border-color: rgba(1, 151, 214, 0.2);
}

.cs-card__link:focus-visible {
  outline: 2px solid var(--cs-blue);
  outline-offset: 3px;
}

.cs-card__header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 10px;
}

.cs-card__logo-wrap {
  flex-shrink: 0;
  width: 80px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: #fff;
  border: 1px solid rgba(40, 56, 71, 0.1);
  padding: 6px 10px;
  box-sizing: border-box;
}

.cs-card__logo {
  display: block;
  max-width: 100%;
  max-height: 28px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.cs-card__logo-fallback {
  font-size: 13px;
  font-weight: 800;
  color: var(--cs-blue);
  letter-spacing: -0.02em;
  line-height: 1;
  text-transform: uppercase;
}

.cs-card__identity {
  min-width: 0;
  flex: 1;
}

.cs-card__title {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.01em;
  margin: 0 0 3px;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.cs-card__industry {
  font-size: 12px;
  line-height: 1.35;
  color: var(--cs-faint);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cs-card__problem {
  font-size: 13px;
  line-height: 1.5;
  color: var(--cs-muted);
  margin: 0 0 10px;
  min-height: 2.95em;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

/* Typographic proof module */
.cs-card__result {
  display: flex;
  flex-direction: column;
  justify-content: center;
  margin-bottom: 10px;
  padding: 10px 11px 10px 12px;
  border-left: 3px solid rgba(40, 56, 71, 0.09);
    border-top: 1px solid rgba(40, 56, 71, 0.09);
    border-right: 1px solid rgba(40, 56, 71, 0.09);
    border-bottom: 1px solid rgba(40, 56, 71, 0.09);
    border-radius: 4px;
    background: linear-gradient(135deg, rgba(1, 151, 214, .07), rgba(122, 193, 66, .07));
  min-height: var(--cs-result-h);
  max-height: var(--cs-result-h);
  box-sizing: border-box;
  overflow: hidden;
  transition: border-color 0.22s ease, background 0.22s ease;
}

.cs-card__link:hover .cs-card__result,
.cs-card__link:focus-visible .cs-card__result {
  border-left-color: var(--cs-green);
  border-top-color: rgba(40, 56, 71, 0.12);
  border-bottom-color: rgba(40, 56, 71, 0.12);
  background: #e9efe3;
}

.cs-card__signal-verb {
  display: block;
  font-size: 8px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(62, 96, 44, 0.68);
  margin: 0 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1;
}

.cs-card__outcome {
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.26;
  letter-spacing: -0.02em;
  color: #222b34;
  margin: 0;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.cs-card__outcome-metric {
  font-weight: 800;
  color: #2f5420;
}

.cs-card__meta {
  align-self: end;
  padding-top: 10px;
  min-height: 38px;
}

.cs-card__meta-row {
  font-size: 11px;
  line-height: 1.45;
  color: rgba(40, 56, 71, 0.46);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cs-card__meta-row + .cs-card__meta-row {
  margin-top: 3px;
}

.cs-card__meta-row strong {
  font-weight: 600;
  color: rgba(40, 56, 71, 0.72);
}

.cs-card__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin: 12px -16px 0;
  padding: 11px 16px;
  border-top: 1px solid rgba(40, 56, 71, 0.08);
  background: transparent;
  transition: background 0.2s ease;
}

.cs-card__link:hover .cs-card__footer {
  background: rgba(1, 151, 214, 0.05);
}

.cs-card__cta {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  font-weight: 700;
  color: #007eb3;
  letter-spacing: -0.01em;
  transition: color 0.22s ease;
}

.cs-card__cta-arrow {
  display: inline-block;
  transition: transform 0.22s ease;
}

.cs-card__link:hover .cs-card__cta,
.cs-card__link:focus-visible .cs-card__cta {
  color: #005f8a;
}

.cs-card__link:hover .cs-card__cta-arrow,
.cs-card__link:focus-visible .cs-card__cta-arrow {
  transform: translateX(2px);
}

@media (prefers-reduced-motion: reduce) {
  .cs-card__link,
  .cs-card__cta,
  .cs-card__cta-arrow,
  .cs-card__result {
    transition: none !important;
  }

  .cs-card__link:hover,
  .cs-card__link:focus-visible {
    transform: none;
  }

  .cs-card__link:hover .cs-card__cta-arrow,
  .cs-card__link:focus-visible .cs-card__cta-arrow {
    transform: none;
  }
}

/* Empty state */
.cs-library__empty {
  display: none;
  text-align: center;
  padding: clamp(40px, 6vw, 64px) 20px;
  background: var(--cs-surface);
  border: 1px dashed var(--cs-border);
  border-radius: 12px;
}

.cs-library__empty.is-visible {
  display: block;
}

.cs-library__empty h3 {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 8px;
}

.cs-library__empty p {
  font-size: 14px;
  color: var(--cs-muted);
  margin: 0 0 16px;
  line-height: 1.6;
  max-width: 420px;
  margin-left: auto;
  margin-right: auto;
}

.cs-library__empty button {
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--cs-blue);
  background: none;
  border: none;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (max-width: 767px) {
  .cs-library__toolbar {
    top: 64px;
  }

  .cs-library__mobile-filter-btn {
    display: inline-flex;
    align-items: center;
  }

  .cs-library__filter-bar .cs-library__dropdowns {
    display: none;
  }

  .cs-library__filter-bar {
    margin-bottom: 0;
  }

  .cs-library__count--desktop {
    display: none;
  }

  .cs-library__count--mobile {
    display: block;
    font-size: 12px;
    margin-bottom: 8px;
  }
}

@media (min-width: 768px) {
  .cs-library__count--mobile {
    display: none;
  }

  .cs-library__drawer-backdrop,
  .cs-library__drawer {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cs-card__link,
  .cs-library__drawer,
  .cs-library__drawer-backdrop,
  .cs-card__cta-arrow {
    transition: none;
  }

  .cs-card__link:hover .cs-card__cta-arrow {
    transform: none;
  }
}

.cs-library__header--embedded .cs-library__subhead {
  font-size: clamp(1.1rem, 1.6vw, 1.35rem);
  font-weight: 700;
  margin: 0 0 8px;
}
.cs-library__header--embedded .cs-library__intro {
  margin: 0;
}
