:root {
  --primary: #0078d4;
  --primary-dark: #005a9e;
  --primary-light: #50e6ff;
  --secondary: #6c757d;
  --surface: #ffffff;
  --surface-secondary: #f3f3f3;
  --bg: #f5f5f5;
  --border: #e1e1e1;
  --text: #262626;
  --text-secondary: #616161;
  --text-tertiary: #a19f9f;
  --success: #16a34a;
  --warning: #ea8c55;
  --danger: #d13438;
  --radius: 4px;
  --radius-lg: 8px;
  --shadow-1: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-2: 0 2px 8px rgba(0,0,0,0.15);
  --shadow-3: 0 8px 16px rgba(0,0,0,0.15);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Segoe UI Variable", Roboto, sans-serif;
  --transition: 0.15s ease-in-out;
}

html[data-theme="dark"] {
  --surface: #1f1f1f;
  --surface-secondary: #2d2d2d;
  --bg: #1a1a1a;
  --border: #3c3c3c;
  --text: #f0f0f0;
  --text-secondary: #c3c3c3;
  --text-tertiary: #8a8a8a;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; }
::selection { background: rgba(0, 120, 212, 0.3); }

/* ===== LAYOUT ===== */

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: 52px 1fr;
  grid-template-areas: "topbar topbar" "sidebar main";
  min-height: 100vh;
  transition: grid-template-columns 0.2s ease;
}

.topbar {
  grid-area: topbar;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 40;
  box-shadow: var(--shadow-1);
}

.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 16px;
  color: var(--primary);
  white-space: nowrap;
}

.topbar .brand-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: white;
  border-radius: 4px;
  font-weight: bold;
  overflow: hidden;
}

.topbar .brand-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.hamburger-btn {
  display: none;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--surface-secondary);
  cursor: pointer;
  border-radius: var(--radius);
  color: var(--text);
  transition: background 0.2s ease;
}

.hamburger-btn:hover {
  background: var(--border);
}

.topbar .search {
  flex: 1;
  max-width: 420px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 12px;
  transition: border-color 0.2s ease;
}

.topbar .search:focus-within {
  border-color: var(--primary);
  background: var(--surface);
}

.topbar .search svg {
  flex-shrink: 0;
  opacity: 0.6;
  color: var(--text-secondary);
}

.topbar .search input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 13px;
  color: var(--text);
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

.icon-btn:hover {
  background: var(--surface-secondary);
  border-color: var(--text-tertiary);
}

/* ===== SIDEBAR ===== */

.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  white-space: nowrap;
}

.nav-link:hover {
  background: var(--surface-secondary);
  color: var(--text);
}

.nav-link.active {
  background: rgba(0, 120, 212, 0.1);
  color: var(--primary);
  font-weight: 600;
}

.nav-link svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-link span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

main {
  grid-area: main;
  padding: 30px 40px;
  overflow-y: auto;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* ===== PAGE HEADER ===== */

.page-header {
  margin-bottom: 30px;
}

.page-header h1 {
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--text);
  font-weight: 600;
}

.page-header p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ===== CARDS & COMPONENTS ===== */

.app-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-1);
}

.app-card:hover {
  box-shadow: var(--shadow-2);
  border-color: var(--primary);
  transform: translateY(-2px);
}

.app-card-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.app-icon {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary), #50e6ff);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: bold;
  font-size: 24px;
  flex-shrink: 0;
  box-shadow: var(--shadow-2);
  overflow: hidden;
}

.app-icon img,
.detail-icon-large img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}

.app-meta {
  flex: 1;
}

.app-meta h3 {
  font-size: 15px;
  margin-bottom: 4px;
  color: var(--text);
  font-weight: 600;
}

.app-developer {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.app-rating {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
}

.stars {
  color: #ffc107;
  letter-spacing: -2px;
}

.rating-count {
  color: var(--text-tertiary);
}

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

.app-category {
  display: inline-block;
  background: rgba(0, 120, 212, 0.1);
  color: var(--primary);
  padding: 4px 8px;
  border-radius: var(--radius);
  font-size: 11px;
  font-weight: 600;
}

.app-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.btn {
  border: none;
  border-radius: var(--radius-lg);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  flex: 1;
  text-align: center;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--surface-secondary);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn:active {
  transform: scale(0.98);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.btn-ghost {
  background: transparent;
  color: var(--danger, #d13438);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: rgba(209, 52, 56, 0.08);
}

.installed-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--success, #107c10);
}

.pwa-install-btn {
  display: none;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 15px;
}

/* ===== DETAIL PAGE ===== */

.detail-container {
  max-width: 900px;
}

.detail-header {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 30px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 30px;
  margin-bottom: 30px;
  box-shadow: var(--shadow-1);
}

.detail-icon-large {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--primary), #50e6ff);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 48px;
  font-weight: bold;
  box-shadow: var(--shadow-2);
}

.detail-info h1 {
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--text);
}

.detail-developer {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.detail-rating {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-rating .stars {
  font-size: 16px;
}

.detail-rating .score {
  font-size: 14px;
  font-weight: 600;
}

.detail-rating .count {
  font-size: 13px;
  color: var(--text-secondary);
}

.detail-actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.detail-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 20px;
}

.detail-stat {
  background: var(--surface-secondary);
  padding: 12px;
  border-radius: var(--radius-lg);
  text-align: center;
}

.detail-stat-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--primary);
}

.detail-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.detail-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-1);
}

.detail-section h2 {
  font-size: 16px;
  margin-bottom: 16px;
  color: var(--text);
  font-weight: 600;
}

.detail-section p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
  margin-bottom: 12px;
}

.screenshots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 16px;
}

.screenshot {
  aspect-ratio: 9 / 16;
  background: linear-gradient(135deg, rgba(0,120,212,0.1), rgba(80,230,255,0.1));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  overflow: hidden;
  position: relative;
}

.screenshot:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-2);
}

.screenshot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ===== SCREENSHOT LIGHTBOX ===== */

.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.lightbox-overlay.open {
  display: flex;
}

.lightbox-img {
  max-width: 85vw;
  max-height: 85vh;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  object-fit: contain;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 24px;
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: #fff;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 28px;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s ease;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox-prev {
  left: 20px;
}

.lightbox-next {
  right: 20px;
}

.lightbox-counter {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.1);
  padding: 6px 14px;
  border-radius: 20px;
}

.features-list {
  list-style: none;
  margin-top: 12px;
}

.features-list li {
  font-size: 13px;
  color: var(--text-secondary);
  padding-left: 24px;
  position: relative;
  margin-bottom: 10px;
  line-height: 1.6;
}

.features-list li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--success);
  font-weight: bold;
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

.back-link:hover {
  opacity: 0.8;
}

/* ===== RESPONSIVE ===== */

@media (max-width: 768px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 52px;
    bottom: 0;
    width: 260px;
    background: var(--surface);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 30;
    box-shadow: var(--shadow-3);
    border-right: 1px solid var(--border);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 25;
  }

  .sidebar-overlay.open {
    display: block;
  }

  .hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  main {
    padding: 20px 16px;
  }

  .topbar .search {
    display: none;
  }

  .detail-header {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .detail-icon-large {
    width: 100px;
    height: 100px;
    font-size: 40px;
  }

  .detail-stats {
    grid-template-columns: 1fr 1fr;
  }

  .grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 16px;
  }
}

@media (max-width: 480px) {
  .topbar {
    padding: 0 12px;
    gap: 12px;
  }

  .topbar .brand {
    font-size: 14px;
  }

  main {
    padding: 16px 12px;
  }

  .page-header h1 {
    font-size: 22px;
  }

  .detail-header {
    padding: 20px;
  }

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

  .app-card {
    padding: 12px;
  }

  .app-card-header {
    gap: 10px;
  }

  .app-icon {
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}

/* ===== BOUTONS — variantes additionnelles ===== */

.btn-sm {
  flex: 0 0 auto;
  padding: 6px 12px;
  font-size: 12px;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #a82a2e;
}

/* ===== PAGE STOCKAGE ===== */

.storage-summary {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 24px;
  margin-bottom: 24px;
}

.storage-total-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
}

.storage-total-label {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 2px;
}

.storage-quota {
  margin-top: 18px;
}

.storage-quota-bar {
  width: 100%;
  height: 8px;
  border-radius: 4px;
  background: var(--surface-secondary);
  overflow: hidden;
}

.storage-quota-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.storage-quota-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 6px;
}

.storage-section-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin: 28px 0 12px;
}

.storage-row {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 16px;
  margin-bottom: 10px;
}

.storage-row-shell {
  background: var(--surface-secondary);
}

.storage-row-info {
  flex: 1;
  min-width: 0;
}

.storage-row-name {
  font-weight: 600;
  color: var(--text);
  font-size: 14px;
}

.storage-row-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.storage-row-size {
  font-weight: 600;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}

/* ===== PAGE ANALYSE ===== */

.analytics-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 8px;
}

.analytics-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 18px;
  text-align: center;
}

.analytics-stat-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--primary);
}

.analytics-stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.analytics-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.analytics-bar-label {
  width: 110px;
  flex-shrink: 0;
  font-size: 13px;
  color: var(--text);
}

.analytics-bar-track {
  flex: 1;
  height: 10px;
  border-radius: 5px;
  background: var(--surface-secondary);
  overflow: hidden;
}

.analytics-bar-fill {
  height: 100%;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  border-radius: 5px;
  transition: width 0.3s ease;
}

.analytics-bar-value {
  width: 24px;
  text-align: right;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

/* ===== PAGE PARAMÈTRES ===== */

.settings-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.settings-section h2 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 14px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.settings-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.settings-row-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.settings-row-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* Interrupteur (switch) */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  transition: background 0.2s ease;
}

.switch-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-slider {
  background: var(--primary);
}

.switch input:checked + .switch-slider::before {
  transform: translateX(20px);
}
