/**
 * Card Component System
 * Variants: default, elevated, bordered, interactive, gradient
 *
 * @author Amit Haridas, ConcreteInfo
 */

/* ============================================
   BASE CARD
   ============================================ */
.card {
  background-color: var(--bg-elevated);
  border-radius: var(--radius-card);
  box-shadow: var(--card-shadow, var(--shadow-1));
  overflow: hidden;
  transition: all var(--transition-normal);
}

/* Card variants */
.card--elevated {
  box-shadow: var(--shadow-md);
}

.card--soft {
  /* soft, diffuse ambient shadow — large blur radius */
  box-shadow: var(--shadow-soft);
}

.card--float {
  /* strong floating depth — max blur */
  box-shadow: var(--shadow-float);
}

.card--glow {
  /* accent-tinted blurred glow that follows the theme accent */
  box-shadow: var(--shadow-glow);
}

.card--glass {
  /* frosted glass surface — translucent + backdrop blur */
  background-color: rgba(255, 255, 255, 0.55);
  -webkit-backdrop-filter: blur(16px) saturate(150%);
  backdrop-filter: blur(16px) saturate(150%);
  border: 1px solid rgba(255, 255, 255, 0.4);
  box-shadow: var(--shadow-soft);
}

.card--bordered {
  box-shadow: none;
  border: 1px solid var(--border-subtle);
}

.card--interactive {
  cursor: pointer;
}

.card--interactive:hover {
  box-shadow: var(--shadow-xl);
  border-color: var(--color-brand-200);
}

/* ============================================
   CARD SECTIONS
   ============================================ */
.card__header {
  padding: var(--card-header-py, var(--spacing-2-5)) var(--card-header-px, var(--spacing-4));
  background: var(--card-header-bg);
  -webkit-backdrop-filter: blur(var(--card-header-blur, 0px)) saturate(var(--card-header-saturate, 1));
  backdrop-filter: blur(var(--card-header-blur, 0px)) saturate(var(--card-header-saturate, 1));
  color: var(--card-header-fg);
  border-bottom: 1px solid var(--card-header-border);
  box-shadow: var(--card-header-highlight, none);
  position: relative;
}

.card__header--subtle {
  background: var(--card-header-bg);
  color: var(--card-header-fg);
  border-bottom: 1px solid var(--card-header-border);
}

.card__header--transparent {
  background-color: transparent;
  border-bottom: none;
  padding-bottom: 0;
  /* A transparent header sits on the card body surface (--bg-elevated), so it
     must use body text colour — NOT the card theme's --card-header-fg, which is
     white for dark themes (aurora/neon/brand-duotone) and would be invisible on
     a light card body. This overrides the inherited `color: var(--card-header-fg)`
     from .card__header. */
  color: var(--text-primary);
}

/* Semantic tone headers — for sub-cards that need a fixed identity colour
   (e.g. distinguishing fine vs. coarse aggregate sections) rather than the
   user's selected card theme. Token-driven so they stay on-brand and track
   palette changes, unlike raw Tailwind utility colours. */
.card__header--tone-info {
  /* On-brand: follows the user's selected accent (was a hardcoded blue
     hsl(199,89%,34%) that ignored theming). Uses the darkened brand token
     for ~5.3:1 WCAG AA contrast with inverse text — the same darkened-recipe
     the original comment intended, now actually applied. Affects the IS 10262
     mix-design section headers + blend calculator. */
  background: var(--color-brand-dark);
  color: var(--text-inverse);
  border-bottom-color: var(--color-brand);
}

.card__header--tone-success {
  background: var(--color-success);
  color: var(--text-inverse);
  border-bottom-color: var(--color-success);
}

.card__header--tone-warning {
  /* --color-warning-light + --color-warning text measured ~1.9:1 — fails
     WCAG AA (4.5:1). Solid --color-warning + dark text measures ~4.8:1. */
  background: var(--color-warning);
  color: var(--color-gray-900);
  border-bottom-color: var(--color-warning);
}

.card__header--tone-dark {
  background: var(--color-gray-800);
  color: var(--text-inverse);
  border-bottom-color: var(--color-gray-800);
}

.card__title {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: inherit;
}

/* Fallback for headings inside .card__header that were never given the
   .card__title class (a widespread pattern — 588+ instances app-wide).
   base.css's `h1..h6 { color: var(--text-primary) }` is an explicit rule
   on the element itself, which wins over simple inheritance from the
   parent's `color: var(--card-header-fg)` regardless of specificity —
   inheritance always loses to any matching rule. Without this, those
   headings render in --text-primary (dark) against a colored/gradient
   header background, which happened to look fine in dark mode (where
   --text-primary is light) but is unreadable in light mode. */
.card__header h1,
.card__header h2,
.card__header h3,
.card__header h4,
.card__header h5,
.card__header h6 {
  margin: 0;
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: inherit;
}

.card__subtitle {
  margin: var(--spacing-1) 0 0;
  font-size: var(--font-size-sm);
  /* Theme-aware: inherit so a subtitle inside a themed .card__header follows
     the card SKIN's --card-header-fg (chosen per-skin for AA on its bg — a
     page-theme token here puts dark slate on a charcoal skin, ~1.1:1).
     No opacity: it blends toward an unknown surface (see header note below). */
  color: inherit;
}

/* Subtitles that sit on the card BODY (a page-theme surface) keep the
   muted page token — there the surface decides the token source. */
.card__body .card__subtitle {
  color: var(--text-secondary);
}

/* Themed card headers own their text colours. Muted text inside a header
   must follow the header's --card-header-fg, not page-theme text tokens or
   Tailwind gray utilities (gray-500 on a charcoal skin ≈ 1.6:1). Hierarchy
   comes from size/weight, not dimming. */
.card__header .card__subtitle,
.card__header small,
.card__header .text-muted,
.card__header .text-gray-500,
.card__header .text-gray-400,
.card__header .text-gray-600 {
  color: inherit;
}

.card__body {
  padding: var(--spacing-4); /* 16px — CAMS2 card density (was 24px) */
}

/* Legacy alias — some templates still emit the flat Bootstrap-style name.
   Keep in sync with .card__body above. */
.card-body {
  padding: var(--spacing-4);
}

.card__body--compact {
  padding: var(--spacing-4);
}

.card__body--spacious {
  padding: var(--spacing-8);
}

.card__footer {
  padding: var(--spacing-4) var(--spacing-6);
  background-color: var(--bg-tertiary);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--spacing-3);
}

.card__image {
  width: 100%;
  height: auto;
  display: block;
}

.card__actions {
  display: flex;
  gap: var(--spacing-2);
  margin-top: var(--spacing-4);
}

/* ============================================
   STAT CARD
   ============================================ */
.stat-card {
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-4);
  padding: var(--spacing-5);
  background-color: var(--bg-elevated);
  border-radius: var(--radius-xl);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.stat-card:hover {
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(13, 11, 9, .06));
  border-color: var(--color-brand-100, #f6c9a8);
}

/* ============================================
   KPI CARD — unified with the hub-tile visual
   (no colored left strip; accent-aware hover).
   Use in place of per-page "border-l-4 border-{color}"
   stat-card / inline stacks. Theming merge: P4-4.
   ============================================ */
.kpi-card {
  display: flex;
  align-items: flex-start;
  gap: var(--spacing-4);
  padding: var(--spacing-5);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  box-shadow: 0 1px 2px rgba(13, 11, 9, .04), 0 4px 14px -4px rgba(13, 11, 9, .10);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal), border-color var(--transition-normal);
  position: relative;
}

.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 22px -8px rgba(13, 11, 9, .18);
  border-color: var(--color-brand-100, #f6c9a8);
}

/* One neutral token chip (26px, bg-tertiary, brand icon) — the app-wide
   KPI idiom. The old 56px gradient chips with colored shadows + bounce
   hover read as oversized/animated noise ("abnormal icons in cards").
   Variants keep ONLY a semantic exception: --danger for genuine alerts. */
.stat-card__icon {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 7px;
  font-size: 13px;
  background: var(--bg-tertiary, #f3f4f6);
  color: var(--color-brand, #e5461f);
  transition: background 150ms ease;
}

.stat-card:hover .stat-card__icon {
  background: hsl(var(--color-brand-h, 14) var(--color-brand-s, 82%) var(--color-brand-l, 49%) / 0.12);
}

.stat-card__icon--primary,
.stat-card__icon--secondary,
.stat-card__icon--success,
.stat-card__icon--info,
.stat-card__icon--warning {
  background: var(--bg-tertiary, #f3f4f6);
  color: var(--color-brand, #e5461f);
  box-shadow: none;
}

.stat-card__icon--danger {
  background: color-mix(in srgb, var(--color-danger, hsl(0, 84%, 47%)) 12%, transparent);
  color: var(--color-danger, hsl(0, 84%, 47%));
  box-shadow: none;
}

.stat-card__content {
  flex: 1;
  min-width: 0;
}

.stat-card__value {
  font-size: 20px;
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  color: var(--text-primary);
}

.stat-card__value--sm {
  font-size: var(--font-size-xl);
}

.stat-card__label {
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--letter-spacing-wider);
  margin-top: var(--spacing-1);
}

.stat-card__trend {
  display: inline-flex;
  align-items: center;
  gap: var(--spacing-1);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-semibold);
  padding: var(--spacing-1) var(--spacing-2);
  border-radius: var(--radius-full);
  margin-top: var(--spacing-2);
}

.stat-card__trend--up {
  background-color: var(--color-success-light);
  color: var(--color-success);
}

.stat-card__trend--down {
  background-color: var(--color-danger-light);
  color: var(--color-danger);
}

/* ============================================
   ACTION CARD
   ============================================ */
.action-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-8) var(--spacing-5);
  background-color: var(--bg-elevated);
  border-radius: var(--radius-xl);
  border: 2px solid transparent;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  text-align: center;
  transition: all var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.action-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, var(--color-brand), var(--color-brand-light));
  opacity: 0;
  transition: opacity var(--transition-normal);
  z-index: 0;
}

.action-card > * {
  position: relative;
  z-index: 1;
}

.action-card:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: var(--shadow-xl);
  border-color: var(--color-brand);
}

.action-card:hover::after {
  opacity: 0.05;
}

.action-card__icon {
  width: 4rem;
  height: 4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xl);
  font-size: var(--font-size-2xl);
  margin-bottom: var(--spacing-4);
  transition: all var(--transition-bounce);
  background-color: var(--color-brand-100);
  color: var(--color-brand);
}

.action-card:hover .action-card__icon {
  background: linear-gradient(135deg, var(--color-brand), var(--color-brand-light));
  color: white;
  transform: scale(1.15) rotate(-10deg);
  box-shadow: var(--shadow-primary);
}

.action-card__title {
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--spacing-2);
  transition: color var(--transition-fast);
}

.action-card:hover .action-card__title {
  color: var(--color-brand);
}

.action-card__description {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  line-height: var(--line-height-normal);
}

/* Action card color variants */
.action-card[data-variant="blue"] .action-card__icon {
  background-color: var(--color-info-light);
  color: var(--color-info);
}

.action-card[data-variant="blue"]:hover .action-card__icon {
  background: linear-gradient(135deg, var(--color-info), hsl(199, 89%, 55%));
  color: white;
}

.action-card[data-variant="green"] .action-card__icon {
  background-color: var(--color-success-light);
  color: var(--color-success);
}

.action-card[data-variant="green"]:hover .action-card__icon {
  background: linear-gradient(135deg, var(--color-success), hsl(142, 76%, 45%));
  color: white;
}

.action-card[data-variant="yellow"] .action-card__icon {
  background-color: var(--color-warning-light);
  color: var(--color-warning);
}

.action-card[data-variant="yellow"]:hover .action-card__icon {
  background: linear-gradient(135deg, var(--color-warning), hsl(45, 93%, 55%));
  color: white;
}

.action-card[data-variant="teal"] .action-card__icon {
  background-color: #ccfbf1;
  color: #0d9488;
}

.action-card[data-variant="teal"]:hover .action-card__icon {
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  color: white;
}

.action-card[data-variant="purple"] .action-card__icon {
  background-color: #f3e8ff;
  color: #9333ea;
}

.action-card[data-variant="purple"]:hover .action-card__icon {
  background: linear-gradient(135deg, #a855f7, #9333ea);
  color: white;
}

.action-card[data-variant="gray"] .action-card__icon {
  background-color: var(--color-gray-100);
  color: var(--color-gray-600);
}

.action-card[data-variant="gray"]:hover .action-card__icon {
  background: linear-gradient(135deg, var(--color-gray-600), var(--color-gray-700));
  color: white;
}

/* ============================================
   CARD GRID
   ============================================ */
.card-grid {
  display: grid;
  gap: var(--spacing-6);
}

.card-grid--2 {
  grid-template-columns: repeat(2, 1fr);
}

.card-grid--3 {
  grid-template-columns: repeat(3, 1fr);
}

.card-grid--4 {
  grid-template-columns: repeat(4, 1fr);
}

@media (max-width: 1024px) {
  .card-grid--4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .card-grid--2,
  .card-grid--3,
  .card-grid--4 {
    grid-template-columns: 1fr;
  }
}

