/* BioStack Desktop Layout */
@media (min-width: 1024px) {
  body.app-shell { background: #f1f5f9; }

  .desktop-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: calc(100vh - 57px);
    max-width: 100%;
    width: 100%;
    margin: 0 auto;
  }

  .desktop-sidebar {
    display: flex;
    flex-direction: column;
    background: linear-gradient(180deg, #0f172a 0%, #1e3a5f 100%);
    color: #e2e8f0;
    padding: 1.5rem 0;
    position: sticky;
    top: 57px;
    height: calc(100vh - 57px);
    overflow-y: auto;
  }

  .desktop-sidebar-brand {
    padding: 0 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 1rem;
  }

  .desktop-sidebar-brand .user-name {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    margin-top: 0.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .desktop-sidebar-brand .user-level {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
  }

  .desktop-sidebar-nav {
    flex: 1;
    padding: 0 0.75rem;
  }

  .desktop-sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: 0.65rem;
    font-size: 13px;
    font-weight: 500;
    color: #94a3b8;
    text-decoration: none;
    transition: all 0.15s;
    margin-bottom: 2px;
  }

  .desktop-sidebar-nav a:hover {
    background: rgba(255,255,255,0.06);
    color: #e2e8f0;
  }

  .desktop-sidebar-nav a.active {
    background: rgba(59, 130, 246, 0.2);
    color: #fff;
    font-weight: 600;
  }

  .desktop-sidebar-nav a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    opacity: 0.85;
  }

  .desktop-sidebar-nav a.active svg { opacity: 1; }

  .desktop-sidebar-footer {
    padding: 1rem 0.75rem 0;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: auto;
  }

  .desktop-sidebar-footer a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: 0.65rem;
    font-size: 13px;
    color: #f87171;
    text-decoration: none;
  }

  .desktop-sidebar-footer a:hover { background: rgba(248,113,113,0.1); }

  .desktop-content-area {
    min-width: 0;
    padding: 0;
  }

  .desktop-content-area .app-main {
    max-width: none;
    margin: 0;
    padding: 1.75rem 2rem 2.5rem;
  }

  /* Hide compact top nav links when sidebar present */
  .has-desktop-sidebar .desktop-nav-links { display: none !important; }

  /* Gamification panel */
  .game-panel {
    background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
    border-radius: 1.25rem;
    padding: 1.5rem;
    color: white;
    position: relative;
    overflow: hidden;
  }

  .game-panel::before {
    content: '';
    position: absolute;
    top: -40px; right: -40px;
    width: 120px; height: 120px;
    background: rgba(16, 185, 129, 0.15);
    border-radius: 50%;
  }

  .game-xp-bar {
    height: 8px;
    background: rgba(255,255,255,0.15);
    border-radius: 9999px;
    overflow: hidden;
    margin-top: 0.75rem;
  }

  .game-xp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #10b981);
    border-radius: 9999px;
    transition: width 0.6s ease;
  }

  .heatmap-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
    margin-top: 0.75rem;
  }

  .heatmap-cell {
    aspect-ratio: 1;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 600;
    background: rgba(255,255,255,0.08);
    color: rgba(255,255,255,0.5);
  }

  .heatmap-cell[data-pct="0"] { background: rgba(255,255,255,0.06); }
  .heatmap-cell[data-pct="1"], .heatmap-cell[data-pct="2"], .heatmap-cell[data-pct="3"] { background: rgba(59,130,246,0.25); color: #93c5fd; }
  .heatmap-cell[data-pct="4"], .heatmap-cell[data-pct="5"] { background: rgba(59,130,246,0.45); color: #bfdbfe; }
  .heatmap-cell[data-pct="6"], .heatmap-cell[data-pct="7"], .heatmap-cell[data-pct="8"], .heatmap-cell[data-pct="9"] { background: rgba(16,185,129,0.35); color: #6ee7b7; }
  .heatmap-cell[data-pct="10"] { background: rgba(16,185,129,0.7); color: #fff; }

  .achievement-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .achievement-badge {
    aspect-ratio: 1;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    opacity: 0.35;
    filter: grayscale(1);
    transition: all 0.2s;
    cursor: default;
    position: relative;
  }

  .achievement-badge.unlocked {
    opacity: 1;
    filter: none;
    background: rgba(255,255,255,0.12);
    border-color: rgba(16,185,129,0.4);
  }

  .achievement-badge .ab-title {
    font-size: 8px;
    font-weight: 600;
    color: rgba(255,255,255,0.7);
    margin-top: 4px;
    text-align: center;
    line-height: 1.2;
    padding: 0 2px;
  }

  .dashboard-desktop-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 1.5rem;
    align-items: start;
  }

  .dashboard-main-col { min-width: 0; }

  .day-calendar {
    min-height: 480px;
  }
  .day-calendar-track {
    min-height: 480px;
  }

  /* Stack page desktop: two columns */
  .stack-desktop-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    gap: 1.5rem;
    align-items: start;
  }

  .toast-xp {
    position: fixed;
    top: 72px;
    right: 24px;
    z-index: 200;
    background: linear-gradient(135deg, #1e40af, #10b981);
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
    animation: toastIn 0.4s ease, toastOut 0.4s ease 2.6s forwards;
  }

  @keyframes toastIn { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
  @keyframes toastOut { to { opacity: 0; transform: translateY(-8px); } }
}

@media (min-width: 1280px) {
  .desktop-shell {
    max-width: 1560px;
    grid-template-columns: 260px 1fr;
  }
  .dashboard-desktop-grid {
    grid-template-columns: 1fr 380px;
    gap: 2rem;
  }
  .stack-desktop-grid {
    grid-template-columns: 1fr 380px;
    gap: 2rem;
  }
  .desktop-content-area .app-main {
    padding: 2rem 2.5rem 3rem;
  }
}

@media (min-width: 1536px) {
  .desktop-shell {
    max-width: 1720px;
    grid-template-columns: 280px 1fr;
  }
  .desktop-content-area .app-main {
    padding: 2.25rem 3rem 3.5rem;
  }
  .dashboard-desktop-grid {
    grid-template-columns: 1fr 400px;
  }
}

@media (max-width: 1023px) {
  .desktop-shell { display: block; }
  .desktop-sidebar { display: none; }
  .dashboard-desktop-grid,
  .stack-desktop-grid { display: block; }
  .game-panel-mobile { margin-bottom: 1.5rem; }
}

@media (min-width: 1024px) {
  .protocols-grid-desktop {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Gamification on mobile too */
.game-panel {
  background: linear-gradient(135deg, #1e3a5f 0%, #0f172a 100%);
  border-radius: 1.25rem;
  padding: 1.25rem;
  color: white;
  position: relative;
  overflow: hidden;
}
.game-xp-bar { height: 8px; background: rgba(255,255,255,0.15); border-radius: 9999px; overflow: hidden; margin-top: 0.75rem; }
.game-xp-bar-fill { height: 100%; background: linear-gradient(90deg, #3b82f6, #10b981); border-radius: 9999px; transition: width 0.6s ease; }
.heatmap-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 0.75rem; }
.heatmap-cell { aspect-ratio: 1; border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 9px; font-weight: 600; background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.5); }
.heatmap-cell[data-level="0"] { background: rgba(255,255,255,0.06); }
.heatmap-cell[data-level="1"] { background: rgba(59,130,246,0.25); color: #93c5fd; }
.heatmap-cell[data-level="2"] { background: rgba(59,130,246,0.45); color: #bfdbfe; }
.heatmap-cell[data-level="3"] { background: rgba(16,185,129,0.35); color: #6ee7b7; }
.heatmap-cell[data-level="4"] { background: rgba(16,185,129,0.7); color: #fff; }
.achievement-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.achievement-badge { aspect-ratio: 1; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 18px; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.08); opacity: 0.35; filter: grayscale(1); }
.achievement-badge.unlocked { opacity: 1; filter: none; background: rgba(255,255,255,0.12); border-color: rgba(16,185,129,0.4); }
.achievement-badge .ab-title { font-size: 8px; font-weight: 600; color: rgba(255,255,255,0.7); margin-top: 4px; text-align: center; line-height: 1.2; }
