@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

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

:root {
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --bg-card: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.15);
  --border: #e2e8f0;
  --border-light: #f1f5f9;
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.3);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.08);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --sidebar-width: 280px;
  --header-height: 64px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
  --bg-primary: #0b1120;
  --bg-secondary: #131c31;
  --bg-tertiary: #1a2540;
  --bg-card: #162033;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #818cf8;
  --accent-light: #a5b4fc;
  --accent-hover: #6366f1;
  --accent-glow: rgba(129, 140, 248, 0.2);
  --border: #1e2d4a;
  --border-light: #1a2540;
  --glass-bg: rgba(11, 17, 32, 0.8);
  --glass-border: rgba(30, 45, 74, 0.5);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.35);
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.4);
}

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  transition: background var(--transition), color var(--transition);
}

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

/* ─── Header ─── */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-height);
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  transition: background var(--transition);
}

.header-left { display: flex; align-items: center; gap: 16px; }

.menu-toggle {
  width: 40px; height: 40px; border: none; background: transparent;
  color: var(--text-primary); cursor: pointer; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.menu-toggle:hover { background: var(--bg-tertiary); }
.menu-toggle svg { width: 22px; height: 22px; }

.logo { display: flex; align-items: center; gap: 10px; text-decoration: none; }
.logo-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
}
.logo-icon svg { width: 20px; height: 20px; fill: white; }
.logo-text {
  font-size: 1.15rem; font-weight: 700; color: var(--text-primary);
  background: linear-gradient(135deg, #6366f1, #a855f7);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-right { display: flex; align-items: center; gap: 8px; }

.header-btn {
  width: 40px; height: 40px; border: none; border-radius: var(--radius-sm);
  background: transparent; color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); position: relative;
}
.header-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.header-btn svg { width: 20px; height: 20px; }

.back-btn {
  padding: 0 14px; gap: 6px; width: auto;
  font-size: 0.85rem; font-weight: 500; font-family: inherit;
}
.back-btn span { display: inline; }

/* ─── Sidebar ─── */
.sidebar {
  position: fixed; top: var(--header-height); left: 0; bottom: 0;
  width: var(--sidebar-width); z-index: 90;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transform: translateX(0);
  transition: transform var(--transition), background var(--transition);
  overflow: hidden;
}
.sidebar.collapsed { transform: translateX(calc(-1 * var(--sidebar-width))); }

.sidebar-search {
  padding: 16px;
  border-bottom: 1px solid var(--border-light);
}
.search-input-wrap {
  position: relative; display: flex; align-items: center;
}
.search-input-wrap svg {
  position: absolute; left: 12px;
  width: 16px; height: 16px; color: var(--text-muted);
  pointer-events: none;
}
.search-input {
  width: 100%; padding: 10px 12px 10px 38px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-tertiary); color: var(--text-primary);
  font-size: 0.875rem; font-family: inherit;
  transition: all var(--transition); outline: none;
}
.search-input:focus {
  border-color: var(--accent); background: var(--bg-secondary);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.search-input::placeholder { color: var(--text-muted); }

.sidebar-nav {
  flex: 1; overflow-y: auto; padding: 8px 0;
}
.nav-category {
  padding: 0 12px; margin-bottom: 4px;
}
.nav-category-title {
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.08em; color: var(--text-muted);
  padding: 12px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all var(--transition);
  color: var(--text-secondary); text-decoration: none;
  font-size: 0.875rem; font-weight: 450;
}
.nav-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-glow); color: var(--accent);
  font-weight: 500;
}
.nav-item-icon {
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; flex-shrink: 0;
}
.nav-item-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-footer {
  padding: 16px; border-top: 1px solid var(--border-light);
  font-size: 0.75rem; color: var(--text-muted); text-align: center;
}

/* ─── Main Content ─── */
.main {
  margin-left: var(--sidebar-width);
  margin-top: var(--header-height);
  height: calc(100vh - var(--header-height));
  transition: margin-left var(--transition);
  overflow: hidden; position: relative;
}
.main.expanded { margin-left: 0; }

/* ─── Dashboard View ─── */
.dashboard-view {
  padding: 32px;
  overflow-y: auto;
  height: 100%;
}

.dashboard-hero {
  margin-bottom: 32px;
}
.dashboard-hero h1 {
  font-size: 1.75rem; font-weight: 700; margin-bottom: 6px;
}
.dashboard-hero p {
  color: var(--text-secondary); font-size: 0.95rem;
}

.category-filter {
  display: flex; gap: 8px; margin-bottom: 28px; flex-wrap: wrap;
}
.filter-chip {
  padding: 7px 18px; border-radius: 100px;
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--text-secondary); font-size: 0.82rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition); font-family: inherit;
  white-space: nowrap;
}
.filter-chip:hover { border-color: var(--accent); color: var(--accent); }
.filter-chip.active {
  background: var(--accent); color: white; border-color: var(--accent);
}

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

.app-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  cursor: pointer;
  transition: all var(--transition);
  position: relative; overflow: hidden;
}
.app-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--card-accent);
  opacity: 0; transition: opacity var(--transition);
}
.app-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent);
}
.app-card:hover::before { opacity: 1; }

.app-card-icon {
  width: 48px; height: 48px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; margin-bottom: 16px;
  background: var(--icon-bg);
  transition: transform var(--transition);
}
.app-card:hover .app-card-icon { transform: scale(1.08); }

.app-card-title {
  font-size: 1rem; font-weight: 600; margin-bottom: 6px;
  color: var(--text-primary);
}
.app-card-desc {
  font-size: 0.82rem; color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}
.app-card-badge {
  position: absolute; top: 16px; right: 16px;
  font-size: 0.65rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 3px 8px; border-radius: 100px;
  background: var(--accent-glow); color: var(--accent);
}

/* ─── App View (iframe) ─── */
.app-view {
  display: none; width: 100%; height: 100%;
  position: relative;
}
.app-view.active { display: block; }

.app-iframe {
  width: 100%; height: 100%; border: none;
  background: var(--bg-primary);
}

.app-loading {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background: var(--bg-primary); gap: 16px;
  z-index: 5;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.app-loading-text { color: var(--text-secondary); font-size: 0.9rem; }

/* ─── Fullscreen button ─── */
.fullscreen-btn {
  position: absolute; top: 12px; right: 12px; z-index: 10;
  width: 36px; height: 36px; border: none; border-radius: var(--radius-sm);
  background: var(--glass-bg); backdrop-filter: blur(10px);
  color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition); border: 1px solid var(--border);
}
.fullscreen-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.fullscreen-btn svg { width: 16px; height: 16px; }

/* ─── Empty / No Results ─── */
.no-results {
  grid-column: 1 / -1; text-align: center;
  padding: 60px 20px; color: var(--text-muted);
}
.no-results svg { width: 48px; height: 48px; margin-bottom: 16px; opacity: 0.4; }
.no-results h3 { font-size: 1.1rem; margin-bottom: 6px; color: var(--text-secondary); }
.no-results p { font-size: 0.85rem; }

/* ─── Activity Panel ─── */
.recent-section { margin-top: 48px; }
.recent-section h2 {
  font-size: 1.1rem; font-weight: 600; margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
}
.recent-list { display: flex; flex-direction: column; gap: 8px; }
.recent-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius-md);
  background: var(--bg-secondary); border: 1px solid var(--border-light);
  cursor: pointer; transition: all var(--transition);
}
.recent-item:hover { border-color: var(--accent); }
.recent-item-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
}
.recent-item-info { flex: 1; }
.recent-item-name { font-size: 0.85rem; font-weight: 500; }
.recent-item-time { font-size: 0.72rem; color: var(--text-muted); }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(calc(-1 * var(--sidebar-width))); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .back-btn span { display: inline; }
}

@media (max-width: 640px) {
  .dashboard-view { padding: 20px 16px; }
  .app-grid { grid-template-columns: 1fr; }
  .dashboard-hero h1 { font-size: 1.35rem; }
  .logo-text { display: none; }
  .header { padding: 0 12px; }
}

/* ─── Overlay for mobile sidebar ─── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 85;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.active { display: block; }

/* ─── Animations ─── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.app-card { animation: fadeInUp 0.4s ease both; }
.app-card:nth-child(2) { animation-delay: 0.05s; }
.app-card:nth-child(3) { animation-delay: 0.1s; }
.app-card:nth-child(4) { animation-delay: 0.15s; }
.app-card:nth-child(5) { animation-delay: 0.2s; }
.app-card:nth-child(6) { animation-delay: 0.25s; }
.app-card:nth-child(7) { animation-delay: 0.3s; }
.app-card:nth-child(8) { animation-delay: 0.35s; }

/* ─── Install PWA Banner ─── */
.pwa-banner {
  display: none; position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-xl); z-index: 200;
  max-width: 340px;
}
.pwa-banner.show { display: block; animation: fadeInUp 0.4s ease; }
.pwa-banner h4 { font-size: 0.95rem; margin-bottom: 4px; }
.pwa-banner p { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 12px; }
.pwa-banner-actions { display: flex; gap: 8px; }
.pwa-install-btn {
  padding: 8px 20px; border: none; border-radius: var(--radius-sm);
  background: var(--accent); color: white; font-size: 0.82rem;
  font-weight: 500; cursor: pointer; font-family: inherit;
  transition: background var(--transition);
}
.pwa-install-btn:hover { background: var(--accent-hover); }
.pwa-dismiss-btn {
  padding: 8px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: transparent; color: var(--text-secondary); font-size: 0.82rem;
  cursor: pointer; font-family: inherit; transition: all var(--transition);
}
.pwa-dismiss-btn:hover { background: var(--bg-tertiary); }
