/* ======================================================
   AppScope — Dark Theme Dashboard Styles
   ====================================================== */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #0f1117;
  color: #e5e7eb;
  line-height: 1.6;
  min-height: 100vh;
}

/* ---- Header ---- */
.header {
  background: #1a1d27;
  border-bottom: 1px solid #2a2d37;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #6366f1, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.store-select {
  background: #0f1117;
  color: #e5e7eb;
  border: 1px solid #2a2d37;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.store-select:focus {
  border-color: #6366f1;
}

/* ---- Scan Status Bar ---- */
.scan-status-bar {
  max-width: 1400px;
  margin: 0 auto;
  padding: 8px 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #9ca3af;
}

.scan-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.scan-dot.green {
  background: #22c55e;
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.scan-dot.amber {
  background: #f59e0b;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.4);
}

.scan-dot.red {
  background: #ef4444;
  box-shadow: 0 0 6px rgba(239, 68, 68, 0.4);
}

/* ---- Tab Navigation ---- */
.tab-nav {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 4px;
  border-bottom: 1px solid #2a2d37;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  background: none;
  border: none;
  color: #9ca3af;
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color 0.2s, border-color 0.2s;
}

.tab-btn:hover {
  color: #e5e7eb;
}

.tab-btn.active {
  color: #a78bfa;
  border-bottom-color: #6366f1;
}

/* ---- Main Content ---- */
.main-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* ---- Tab Panels ---- */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ---- Cards ---- */
.card {
  background: #1a1d27;
  border: 1px solid #2a2d37;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  position: relative;
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.card-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: #e5e7eb;
}

.card-body {
  min-height: 40px;
}

/* ---- Stat Cards Row ---- */
.stat-cards-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.stat-card {
  background: #1a1d27;
  border: 1px solid #2a2d37;
  border-radius: 12px;
  padding: 20px;
  position: relative;
}

.stat-label {
  font-size: 13px;
  color: #9ca3af;
  margin-bottom: 8px;
  font-weight: 500;
}

.stat-value {
  font-size: 32px;
  font-weight: 700;
  color: #e5e7eb;
  line-height: 1.2;
}

.stat-delta {
  font-size: 13px;
  margin-top: 6px;
  font-weight: 500;
}

.stat-delta.positive {
  color: #22c55e;
}

.stat-delta.negative {
  color: #ef4444;
}

/* ---- Two Column Row ---- */
.two-col-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}

/* ---- Data Tables ---- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.data-table thead th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  color: #9ca3af;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid #2a2d37;
}

.data-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(42, 45, 55, 0.5);
  color: #e5e7eb;
}

.data-table tbody tr:hover {
  background: rgba(99, 102, 241, 0.05);
}

/* ---- App Rows (expandable) ---- */
.app-row {
  padding: 12px 0;
  border-bottom: 1px solid rgba(42, 45, 55, 0.5);
  cursor: pointer;
  transition: background 0.15s;
}

.app-row:hover {
  background: rgba(99, 102, 241, 0.05);
}

.app-row .app-name {
  font-weight: 500;
  color: #e5e7eb;
}

.app-row .app-meta {
  font-size: 13px;
  color: #9ca3af;
  margin-top: 2px;
}

.app-row .app-detail {
  display: none;
  padding: 12px 0 4px;
  font-size: 13px;
  color: #9ca3af;
  line-height: 1.8;
}

.app-row.expanded .app-detail {
  display: block;
}

/* ---- Horizontal Scroll Row ---- */
.horizontal-scroll-row {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #2a2d37 transparent;
}

.horizontal-scroll-row::-webkit-scrollbar {
  height: 6px;
}

.horizontal-scroll-row::-webkit-scrollbar-track {
  background: transparent;
}

.horizontal-scroll-row::-webkit-scrollbar-thumb {
  background: #2a2d37;
  border-radius: 3px;
}

.new-app-card {
  flex: 0 0 220px;
  background: #232636;
  border: 1px solid #2a2d37;
  border-radius: 10px;
  padding: 16px;
  min-height: 140px;
}

.new-app-card .app-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  background: #2a2d37;
  margin-bottom: 10px;
}

.new-app-card .app-name {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #e5e7eb;
}

.new-app-card .app-meta {
  font-size: 12px;
  color: #9ca3af;
}

/* ---- Category Grid ---- */
.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

.category-card {
  background: #1a1d27;
  border: 1px solid #2a2d37;
  border-radius: 12px;
  padding: 20px;
  min-height: 140px;
}

.category-card .category-name {
  font-size: 16px;
  font-weight: 600;
  color: #e5e7eb;
  margin-bottom: 10px;
}

.category-card .category-meta {
  font-size: 13px;
  color: #9ca3af;
  line-height: 1.8;
}

.category-card .saturation-label {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  margin-top: 8px;
}

.saturation-label.high {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.saturation-label.medium {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}

.saturation-label.low {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

/* ---- Store Badges ---- */
.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.badge-ios {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.badge-android {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

/* ---- Alerts Feed ---- */
.alerts-feed {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.alert-item {
  padding: 14px 16px;
  border-radius: 8px;
  background: #232636;
  border-left: 4px solid #2a2d37;
  font-size: 14px;
}

.alert-item.rating_drop {
  border-left-color: #ef4444;
}

.alert-item.new_app {
  border-left-color: #22c55e;
}

.alert-item.stale_app {
  border-left-color: #f59e0b;
}

.alert-item.rank_jump {
  border-left-color: #3b82f6;
}

.alert-item .alert-title {
  font-weight: 600;
  color: #e5e7eb;
  margin-bottom: 4px;
}

.alert-item .alert-body {
  color: #9ca3af;
  font-size: 13px;
}

.alert-item .alert-time {
  font-size: 11px;
  color: #6b7280;
  margin-top: 6px;
}

/* ---- Data Timestamps ---- */
.data-timestamp {
  display: block;
  text-align: right;
  font-size: 11px;
  color: #6b7280;
  margin-top: 12px;
}

/* ---- Controls Row ---- */
.controls-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.period-selector {
  display: flex;
  gap: 4px;
}

.period-btn {
  background: #1a1d27;
  border: 1px solid #2a2d37;
  border-radius: 8px;
  color: #9ca3af;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 14px;
  cursor: pointer;
  transition: all 0.2s;
}

.period-btn:hover {
  color: #e5e7eb;
  border-color: #6366f1;
}

.period-btn.active {
  background: #6366f1;
  border-color: #6366f1;
  color: #fff;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: 13px;
  color: #9ca3af;
  white-space: nowrap;
}

.filter-input {
  background: #0f1117;
  color: #e5e7eb;
  border: 1px solid #2a2d37;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 14px;
  font-family: inherit;
  width: 120px;
  outline: none;
  transition: border-color 0.2s;
}

.filter-input:focus {
  border-color: #6366f1;
}

/* ---- Search Bar ---- */
.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
}

.search-input {
  flex: 1;
  background: #1a1d27;
  color: #e5e7eb;
  border: 1px solid #2a2d37;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: #6366f1;
}

.search-input::placeholder {
  color: #6b7280;
}

/* ---- Buttons ---- */
.btn {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.btn-primary {
  background: #6366f1;
  color: #fff;
}

.btn-primary:hover {
  background: #4f46e5;
}

/* ---- Chart Container ---- */
.chart-container {
  position: relative;
  height: 320px;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #9ca3af;
  font-size: 14px;
}

.empty-state code {
  background: #232636;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 13px;
  color: #a78bfa;
}

.hidden {
  display: none !important;
}

/* ---- Skeleton / Shimmer ---- */
.skeleton {
  background: #232636;
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}

.skeleton.shimmer::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.04) 50%,
    transparent 100%
  );
  animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

.skeleton-row {
  margin-bottom: 10px;
}

.skeleton-row .skeleton {
  height: 18px;
  width: 100%;
}

/* Skeleton stat value */
.stat-value.skeleton {
  width: 80px;
  height: 38px;
  color: transparent;
}

/* Skeleton new-app cards */
.new-app-card.skeleton {
  background: #232636;
}

/* Skeleton category cards */
.category-card.skeleton {
  background: #232636;
}

/* ---- Responsive Breakpoints ---- */

/* Tablet */
@media (max-width: 1024px) {
  .stat-cards-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .two-col-row {
    grid-template-columns: 1fr;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .header-inner {
    padding: 0 16px;
  }

  .scan-status-bar {
    padding: 8px 16px;
  }

  .tab-nav {
    padding: 0 16px;
  }

  .main-content {
    padding: 16px;
  }

  .stat-cards-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .stat-value {
    font-size: 24px;
  }

  .controls-row {
    flex-direction: column;
    align-items: flex-start;
  }

  .search-bar {
    flex-direction: column;
  }

  .category-grid {
    grid-template-columns: 1fr;
  }

  .new-app-card {
    flex: 0 0 180px;
  }

  .chart-container {
    height: 240px;
  }
}

/* Small mobile */
@media (max-width: 480px) {
  .stat-cards-row {
    grid-template-columns: 1fr;
  }

  .header-inner {
    height: 48px;
  }

  .logo {
    font-size: 18px;
  }
}
