/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Theme tokens ──────────────────────────────────────────────────────────── */
:root {
  --bg:            #09090b;
  --surface:       #111113;
  --surface-2:     #18181b;
  --surface-3:     #1c1c20;
  --border:        #27272a;
  --border-2:      #3f3f46;
  --text-1:        #fafafa;
  --text-2:        #a1a1aa;
  --text-3:        #52525b;
  --shadow-sm:     rgba(0,0,0,0.35);
  --shadow-md:     rgba(0,0,0,0.55);
  --shadow-lg:     rgba(0,0,0,0.70);
  --header-bg:     rgba(9,9,11,0.80);
  --header-h:      60px;
  --card-r:        14px;
  --ease:          cubic-bezier(0.16,1,0.3,1);
  --t:             0.18s ease;
}

body.light {
  --bg:        #f1f1f4;
  --surface:   #ffffff;
  --surface-2: #f7f7fa;
  --surface-3: #efeff3;
  --border:    #e4e4e7;
  --border-2:  #d1d1d7;
  --text-1:    #09090b;
  --text-2:    #52525b;
  --text-3:    #a1a1aa;
  --shadow-sm: rgba(0,0,0,0.06);
  --shadow-md: rgba(0,0,0,0.10);
  --shadow-lg: rgba(0,0,0,0.16);
  --header-bg: rgba(241,241,244,0.80);
}

/* ── Base ──────────────────────────────────────────────────────────────────── */
html { color-scheme: dark; }
body.light { color-scheme: light; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text-1);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--header-h);
  background: var(--header-bg);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.25px;
  color: var(--text-1);
  flex-shrink: 0;
  user-select: none;
}

.brand-logo {
  width: 26px;
  height: 26px;
  color: var(--text-1);
  flex-shrink: 0;
}

.header-center {
  flex: 1;
  display: flex;
  justify-content: center;
}

.search-wrapper {
  position: relative;
  width: 100%;
  max-width: 380px;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-3);
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 8px 12px 8px 36px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-1);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--t), box-shadow var(--t), background var(--t);
  appearance: none;
  -webkit-appearance: none;
}
#search::placeholder { color: var(--text-3); }
#search:focus {
  background: var(--surface);
  border-color: var(--border-2);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.14);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--t), border-color var(--t), color var(--t);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text-1); border-color: var(--border-2); }

/* ── Main ──────────────────────────────────────────────────────────────────── */
main {
  padding: calc(var(--header-h) + 32px) 32px 64px;
  max-width: 1440px;
  margin: 0 auto;
}

/* ── Stats bar ─────────────────────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

.stat {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-3);
}

.stat.online  { color: #10b981; }
.stat.offline { color: var(--text-3); }

.stat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.stat.online .stat-dot {
  animation: pulse-dot 2.4s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.stat-count { font-weight: 600; color: inherit; }
.stat-label { color: var(--text-3); }

.stats-divider {
  width: 1px;
  height: 14px;
  background: var(--border);
}

/* ── Filters ───────────────────────────────────────────────────────────────── */
.filters {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 5px 13px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--t), border-color var(--t), color var(--t);
  white-space: nowrap;
}
.filter-pill:hover {
  background: var(--surface-2);
  color: var(--text-1);
  border-color: var(--border-2);
}
.filter-pill.active {
  background: var(--surface-3);
  border-color: var(--border-2);
  color: var(--text-1);
}

/* ── Grid ──────────────────────────────────────────────────────────────────── */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--card-r);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  cursor: pointer;
  animation: card-in 0.4s var(--ease) both;
  transition: transform var(--t), box-shadow var(--t), border-color var(--t);
  position: relative;
}
.app-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--card-r);
  opacity: 0;
  transition: opacity var(--t);
  background: linear-gradient(135deg, rgba(255,255,255,0.03) 0%, transparent 60%);
}
.app-card:hover {
  transform: translateY(-3px);
  border-color: var(--border-2);
  box-shadow: 0 12px 36px var(--shadow-md), 0 2px 8px var(--shadow-sm);
}
.app-card:hover::before { opacity: 1; }

@keyframes card-in {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Coloured top accent bar */
.card-accent {
  height: 3px;
  background: var(--app-color, #6366f1);
  opacity: 0.7;
  transition: opacity var(--t);
}
.app-card:hover .card-accent { opacity: 1; }

.card-top {
  padding: 18px 18px 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.app-icon-wrap {
  width: 46px;
  height: 46px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #fff;
}
.app-icon-wrap svg { width: 22px; height: 22px; }

/* Status badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.25px;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-3);
  flex-shrink: 0;
  white-space: nowrap;
  transition: color var(--t), border-color var(--t);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.status-badge.online  { color: #10b981; border-color: rgba(16,185,129,0.25); }
.status-badge.offline { color: var(--text-3); }

.status-badge.online .status-dot {
  animation: status-pulse 2s ease-in-out infinite;
}

@keyframes status-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16,185,129,0.4); }
  50%       { box-shadow: 0 0 0 5px rgba(16,185,129,0); }
}

/* Card body */
.card-body {
  padding: 14px 18px 0;
  flex: 1;
}

.app-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--text-1);
  margin-bottom: 5px;
}

.app-category {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 5px;
  margin-bottom: 10px;
}

.app-description {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.55;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Card footer */
.card-footer {
  padding: 14px 18px 18px;
}

.launch-btn {
  width: 100%;
  padding: 9px 14px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-1);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--t), border-color var(--t), color var(--t), box-shadow var(--t);
}
.launch-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.launch-btn:hover {
  background: var(--app-color, #6366f1);
  border-color: var(--app-color, #6366f1);
  color: #fff;
  box-shadow: 0 4px 18px rgba(0,0,0,0.3);
}
.launch-btn:active {
  transform: scale(0.98);
}

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 80px 20px;
  color: var(--text-3);
}
.empty-state svg { opacity: 0.5; }
.empty-state p { font-size: 15px; color: var(--text-3); }

/* ── Error state ───────────────────────────────────────────────────────────── */
.error-state {
  grid-column: 1 / -1;
  padding: 48px 24px;
  text-align: center;
  color: #f87171;
  font-size: 14px;
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  main { padding: calc(var(--header-h) + 20px) 16px 40px; }
  header { padding: 0 16px; }
  .app-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .brand span { display: none; }
  .header-center { margin: 0; }
  .stats-divider,
  .stat:nth-child(n+4) { display: none; }
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 3px; }
