/* ZIcon — Global icon embed system for AI-generated animated SVGs
 * Usage: Include this CSS on any page that uses ZIcon components
 * Loader: /components/zicon/zicon-loader.js (auto-replaces <zicon> elements)
 * API: /api/icons/serve/:id (raw SVG), /api/icons/catalog (JSON catalog)
 */

/* Base container — all zicons use this */
.zicon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--zicon-size, 64px);
  height: var(--zicon-size, 64px);
  overflow: visible;
  vertical-align: middle;
  line-height: 0;
  transition: transform 0.2s ease;
}

.zicon svg {
  width: 100%;
  height: 100%;
  display: block;
}

/* Size variants */
.zicon--xs { --zicon-size: 16px; }
.zicon--sm { --zicon-size: 32px; }
.zicon--md { --zicon-size: 64px; }
.zicon--lg { --zicon-size: 96px; }
.zicon--xl { --zicon-size: 128px; }
.zicon--2xl { --zicon-size: 192px; }
.zicon--3xl { --zicon-size: 256px; }

/* Custom size via attribute: <div class="zicon" style="--zicon-size: 48px"> */

/* Animation control */
.zicon--paused svg * {
  animation-play-state: paused !important;
}

.zicon--hover svg * {
  animation-play-state: paused;
}
.zicon--hover:hover svg * {
  animation-play-state: running;
}

/* Color override for simple icons */
.zicon--primary svg { fill: var(--primary-9, #6366f1); }
.zicon--success svg { fill: var(--success, #22c55e); }
.zicon--warning svg { fill: var(--warning, #f59e0b); }
.zicon--danger svg { fill: var(--danger, #ef4444); }
.zicon--white svg { fill: #ffffff; }
.zicon--dark svg { fill: #1e293b; }

/* Glow effects */
.zicon--glow {
  filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.4));
}
.zicon--glow:hover {
  filter: drop-shadow(0 0 12px rgba(99, 102, 241, 0.6));
}

/* Spin utility */
.zicon--spin {
  animation: zicon-spin 2s linear infinite;
}
@keyframes zicon-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Pulse utility */
.zicon--pulse {
  animation: zicon-pulse 1.5s ease-in-out infinite;
}
@keyframes zicon-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.1); opacity: 0.8; }
}

/* Hover scale */
.zicon--interactive:hover {
  transform: scale(1.15);
  cursor: pointer;
}

/* Loading state — shown before SVG is fetched */
.zicon--loading {
  background: linear-gradient(135deg, rgba(99,102,241,0.1), rgba(99,102,241,0.05));
  border-radius: 12px;
  animation: zicon-shimmer 1.5s ease-in-out infinite;
}
@keyframes zicon-shimmer {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

/* Error state */
.zicon--error {
  background: rgba(239, 68, 68, 0.1);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.zicon--error::after {
  content: '⚠';
  font-size: calc(var(--zicon-size, 64px) * 0.4);
  color: rgba(239, 68, 68, 0.6);
}

/* Card-style container for icon display with info */
.zicon-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 16px;
  border-radius: 12px;
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid rgba(99, 102, 241, 0.2);
  transition: all 0.2s ease;
}
.zicon-card:hover {
  border-color: rgba(99, 102, 241, 0.5);
  background: rgba(30, 41, 59, 0.8);
}
.zicon-card__label {
  font-size: 12px;
  color: rgba(148, 163, 184, 0.8);
  text-align: center;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Grid layout for icon galleries */
.zicon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
  padding: 16px;
}
.zicon-grid--compact {
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 8px;
  padding: 8px;
}

/* Dark/light theme compatibility */
@media (prefers-color-scheme: light) {
  .zicon-card {
    background: rgba(241, 245, 249, 0.8);
    border-color: rgba(99, 102, 241, 0.15);
  }
  .zicon-card:hover {
    background: rgba(241, 245, 249, 1);
  }
  .zicon-card__label { color: rgba(71, 85, 105, 0.8); }
}
