* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg: #080b10;
  --surface: #0f1318;
  --surface-hover: #161c24;
  --surface-alt: #111820;
  --border: #1a2230;
  --border-accent: #2a3548;
  --text: #e6edf3;
  --text-dim: #6b7a8d;
  --text-muted: #4a5568;
  --accent: #6c5ce7;
  --accent-light: #8b7cf7;
  --accent-glow: rgba(108, 92, 231, 0.2);
  --green: #00d68f;
  --green-bg: rgba(0, 214, 143, 0.08);
  --green-border: rgba(0, 214, 143, 0.2);
  --orange: #f5a623;
  --orange-bg: rgba(245, 166, 35, 0.08);
  --orange-border: rgba(245, 166, 35, 0.2);
  --red: #ff6b6b;
  --purple: #a78bfa;
  --purple-bg: rgba(167, 139, 250, 0.08);
  --cyan: #22d3ee;
  --cyan-bg: rgba(34, 211, 238, 0.08);
  --radius: 14px;
  --radius-sm: 10px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
header {
  background: linear-gradient(180deg, rgba(108, 92, 231, 0.06) 0%, var(--surface) 100%);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(16px);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.logo-icon {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 50%, var(--cyan) 100%);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 20px var(--accent-glow), inset 0 1px 0 rgba(255,255,255,0.15);
}

header h1 {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff 0%, var(--accent-light) 60%, var(--cyan) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle {
  font-size: 0.68rem;
  color: var(--text-dim);
  margin-top: 2px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px rgba(0, 214, 143, 0.5);
  animation: pulse 2s ease-in-out infinite;
}

.status-dot.offline {
  background: var(--red);
  box-shadow: 0 0 8px rgba(255, 107, 107, 0.5);
  animation: none;
}

.status-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-dot.offline ~ .status-label {
  color: var(--red);
}

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

#refresh-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
}

#refresh-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-glow);
}

#refresh-btn.spinning svg {
  animation: spin 0.6s ease;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Main */
main {
  flex: 1;
  padding: 1.25rem 1.5rem;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
}

/* Stats Bar */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.75rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  text-align: center;
  transition: all 0.2s;
  position: relative;
  overflow: hidden;
}

.stat::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  opacity: 0;
  transition: opacity 0.2s;
}

.stat:hover::after { opacity: 1; }
.stat-green::after { background: var(--green); }
.stat-purple::after { background: var(--purple); }
.stat-orange::after { background: var(--orange); }

.stat:hover {
  border-color: var(--border-accent);
  background: var(--surface-hover);
}

.stat span {
  display: block;
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.stat-green span { color: var(--green); }
.stat-purple span { color: var(--purple); }
.stat-orange span { color: var(--orange); }

.stat label {
  font-size: 0.68rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 3px;
  font-weight: 500;
}

/* Section */
.section {
  margin-bottom: 2rem;
}

.section-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.section-header h2 {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.section-badge {
  background: var(--accent-glow);
  color: var(--accent);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 10px;
}

/* Project Filter */
.filter-wrapper {
  margin-left: auto;
}

#project-filter {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  font-weight: 500;
  padding: 5px 28px 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236b7a8d' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  max-width: 260px;
  transition: all 0.2s;
}

#project-filter:hover {
  border-color: var(--accent);
  background-color: var(--surface-hover);
}

#project-filter:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

#project-filter option {
  background: var(--surface);
  color: var(--text);
}

/* Project Groups */
.project-group {
  margin-bottom: 1.25rem;
}

.project-group-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: linear-gradient(90deg, var(--surface-alt), transparent);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent);
}

.project-group-name {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--purple);
  font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
}

.project-group-count {
  font-size: 0.65rem;
  color: var(--text-dim);
  background: var(--surface);
  padding: 1px 7px;
  border-radius: 8px;
  font-weight: 600;
}

/* Agent Cards */
.agent-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 0.55rem;
  margin-left: 0.75rem;
  transition: all 0.25s;
  position: relative;
}

.agent-card::before {
  content: '';
  position: absolute;
  left: 0;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 2px;
  background: var(--border);
  transition: background 0.2s;
}

.agent-card:hover {
  border-color: var(--border-accent);
  background: var(--surface-hover);
}

.agent-card.active::before {
  background: var(--green);
  box-shadow: 0 0 8px rgba(0, 214, 143, 0.3);
}

.agent-card.recent::before {
  background: var(--orange);
}

.agent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.agent-identity {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.agent-avatar {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.agent-avatar.active {
  background: linear-gradient(135deg, var(--green), #00b377);
  animation: agent-pulse 2s ease-in-out infinite;
}

.agent-avatar.recent {
  background: linear-gradient(135deg, var(--orange), #e09415);
}

.agent-avatar.inactive {
  background: var(--surface-hover);
  color: var(--text-dim);
}

@keyframes agent-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 214, 143, 0.3); }
  50% { box-shadow: 0 0 0 6px rgba(0, 214, 143, 0); }
}

.agent-id {
  font-family: 'SF Mono', SFMono-Regular, Consolas, monospace;
  font-size: 0.72rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.62rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.badge-active {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green-border);
}

.badge-active::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.5s ease-in-out infinite;
}

.badge-recent {
  background: var(--orange-bg);
  color: var(--orange);
  border: 1px solid var(--orange-border);
}

.badge-inactive {
  background: rgba(107, 122, 141, 0.08);
  color: var(--text-muted);
  border: 1px solid rgba(107, 122, 141, 0.15);
}

.agent-task {
  font-size: 0.8rem;
  color: var(--text);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin-bottom: 0.45rem;
  padding-left: 2.4rem;
}

.agent-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem;
  font-size: 0.68rem;
  color: var(--text-dim);
  padding-left: 2.4rem;
}

.agent-meta span {
  display: flex;
  align-items: center;
  gap: 4px;
}

.meta-icon {
  font-size: 0.75rem;
  opacity: 0.8;
}

/* Apps Grid */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.6rem;
}

.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem 0.7rem;
  text-align: center;
  cursor: default;
  transition: all 0.25s;
  position: relative;
  overflow: hidden;
}

.app-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  opacity: 0;
  transition: opacity 0.2s;
}

.app-card:hover {
  border-color: var(--border-accent);
  background: var(--surface-hover);
  transform: translateY(-2px);
}

.app-card:hover::before {
  opacity: 1;
}

.app-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  margin: 0 auto 0.5rem;
}

.app-name {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.2rem;
}

.app-desc {
  font-size: 0.62rem;
  color: var(--text-dim);
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Category colors */
.app-icon.comm { background: rgba(0, 214, 143, 0.12); color: var(--green); }
.app-icon.google { background: var(--cyan-bg); color: var(--cyan); }
.app-icon.work { background: var(--orange-bg); color: var(--orange); }
.app-icon.system { background: rgba(108, 92, 231, 0.12); color: var(--accent); }
.app-icon.docs { background: var(--purple-bg); color: var(--purple); }
.app-icon.info { background: rgba(255, 107, 107, 0.1); color: var(--red); }

/* Loading & Error */
.loading {
  text-align: center;
  color: var(--text-dim);
  padding: 2.5rem 1rem;
  font-size: 0.82rem;
  grid-column: 1 / -1;
}

.error {
  text-align: center;
  color: var(--red);
  padding: 1.5rem 1rem;
  background: var(--surface);
  border: 1px solid rgba(255, 107, 107, 0.2);
  border-radius: var(--radius);
  font-size: 0.82rem;
  grid-column: 1 / -1;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.empty-state-icon {
  font-size: 2rem;
  margin-bottom: 0.5rem;
  opacity: 0.5;
}

/* Footer */
footer {
  text-align: center;
  padding: 1rem;
  color: var(--text-muted);
  font-size: 0.68rem;
  border-top: 1px solid var(--border);
  letter-spacing: 0.02em;
}

/* Responsive */
@media (max-width: 768px) {
  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
  }

  .apps-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}

@media (max-width: 480px) {
  header {
    padding: 0.75rem 1rem;
  }

  header h1 {
    font-size: 1.15rem;
  }

  .status-label {
    display: none;
  }

  main {
    padding: 0.75rem;
  }

  .stats-bar {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.5rem;
  }

  .stat {
    padding: 0.65rem;
  }

  .stat span {
    font-size: 1.5rem;
  }

  .apps-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 0.5rem;
  }

  .agent-card {
    margin-left: 0.4rem;
  }

  .agent-task,
  .agent-meta {
    padding-left: 0;
  }

  .agent-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .agent-id {
    max-width: 100%;
  }
}
