/* ═══════════════════════════════════════
   Diagram CMS — Design System
   Dark theme matching portal aesthetic
   ═══════════════════════════════════════ */

/* ═══ RESET ═══ */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ═══ VARIABLES ═══ */
:root {
  --bg-0: #06080c;
  --bg-1: #0b0e14;
  --bg-2: #10141c;
  --bg-3: #151b28;
  --border-1: #1a2030;
  --border-2: #222e42;
  --border-3: #2a3a55;
  --text-0: #e2e8f0;
  --text-1: #c8cdd5;
  --text-2: #8b97a8;
  --text-3: #5a6577;
  --accent-green: #22c55e;
  --accent-indigo: #6366f1;
  --accent-cyan: #22d3ee;
  --accent-purple: #a78bfa;
  --accent-blue: #60a5fa;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: 0.2s ease;
}

/* ═══ BASE ═══ */
body {
  font-family: 'Inter', -apple-system, system-ui, sans-serif;
  background: var(--bg-0);
  color: var(--text-1);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ═══ HEADER ═══ */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 32px;
  gap: 20px;
  flex-wrap: wrap;
}

.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text-0);
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.02em;
}

.logo-icon {
  font-size: 1.5rem;
  background: linear-gradient(135deg, var(--accent-indigo), var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 0.78rem;
  color: var(--text-3);
  margin-top: 4px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* ═══ SEARCH ═══ */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  color: var(--text-3);
  pointer-events: none;
}

.search-box input {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  padding: 8px 12px 8px 34px;
  color: var(--text-1);
  font-family: inherit;
  font-size: 0.82rem;
  width: 240px;
  outline: none;
  transition: border-color var(--transition);
}

.search-box input:focus {
  border-color: var(--border-3);
}

.search-box input::placeholder {
  color: var(--text-3);
}

.count {
  font-size: 0.72rem;
  color: var(--text-3);
  font-variant-numeric: tabular-nums;
}

/* ═══ GALLERY GRID ═══ */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

/* ═══ DIAGRAM CARD ═══ */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: all var(--transition);
  display: flex;
  flex-direction: column;
}

.card:hover {
  border-color: var(--border-2);
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.card-preview {
  width: 100%;
  height: 180px;
  background: var(--bg-1);
  display: flex;
  align-items: center;
  justify-content: center;
  border-bottom: 1px solid var(--border-1);
  overflow: hidden;
  position: relative;
}

.card-preview iframe {
  width: 400%;
  height: 400%;
  border: none;
  transform: scale(0.25);
  transform-origin: top left;
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
}

.card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-preview .placeholder {
  font-size: 2.5rem;
  color: var(--border-2);
}

.card-body {
  padding: 16px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.card-title {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-0);
  margin-bottom: 4px;
  letter-spacing: -0.01em;
}

.card-desc {
  font-size: 0.75rem;
  color: var(--text-2);
  line-height: 1.5;
  margin-bottom: 12px;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.68rem;
  color: var(--text-3);
}

.card-version {
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  border-radius: 4px;
  padding: 2px 8px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.65rem;
}

.card-tags {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag {
  background: rgba(99, 102, 241, 0.1);
  color: var(--accent-indigo);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 0.62rem;
  font-weight: 500;
}

/* ═══ LOADING ═══ */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 80px 0;
  color: var(--text-3);
  font-size: 0.82rem;
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border-1);
  border-top-color: var(--accent-indigo);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ═══ EMPTY STATE ═══ */
.empty {
  text-align: center;
  padding: 80px 0;
  color: var(--text-3);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.3;
}

/* ═══ DIAGRAM VIEW ═══ */
.diagram-view {
  position: fixed;
  inset: 0;
  background: var(--bg-0);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.diagram-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border-1);
  flex-shrink: 0;
}

.back-btn {
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  color: var(--text-2);
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all var(--transition);
  flex-shrink: 0;
}

.back-btn:hover {
  background: var(--bg-1);
  border-color: var(--border-2);
  color: var(--text-0);
}

.diagram-info {
  flex: 1;
  min-width: 0;
}

.diagram-info h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diagram-info p {
  font-size: 0.7rem;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.diagram-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.version-select {
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  color: var(--text-1);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.72rem;
  cursor: pointer;
  outline: none;
}

.action-group {
  display: flex;
  background: var(--bg-3);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.action-link {
  padding: 6px 12px;
  color: var(--text-2);
  font-family: inherit;
  font-size: 0.72rem;
  text-decoration: none;
  display: flex;
  align-items: center;
  transition: all var(--transition);
  font-weight: 500;
}

.action-link:hover {
  background: var(--bg-1);
  color: var(--text-0);
}

.action-copy {
  padding: 6px 10px;
  background: transparent;
  color: var(--text-2);
  border: none;
  border-left: 1px solid var(--border-1);
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all var(--transition);
}

.action-copy:hover {
  background: var(--bg-1);
  color: var(--text-0);
}

.action-copy.copied {
  color: var(--accent-green);
}

.diagram-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--bg-1);
}

/* ═══ RESPONSIVE ═══ */
@media (max-width: 640px) {
  .app {
    padding: 20px 16px;
  }

  .header {
    flex-direction: column;
  }

  .search-box input {
    width: 100%;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .diagram-header {
    flex-wrap: wrap;
  }

  .diagram-info {
    order: 3;
    width: 100%;
  }
}

/* ═══ SCROLLBAR ═══ */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-2);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--border-3);
}