/* ==========================================================================
   Cart — Phase 29
   Cart page styles + navbar cart badge.
   Loads on cart.html only (except .cart-badge which is injected by
   student-shell.js and therefore applies to ALL student pages).
   ========================================================================== */

/* ---- Navbar cart badge (loaded on all student pages via student-shell) --- */

.student-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
}

.cart-nav-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
  text-decoration: none;
}
.cart-nav-btn:hover {
  color: var(--color-text);
  background: rgba(255, 255, 255, 0.06);
}

.cart-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-accent-500), #a855f7);
  color: #fff;
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.55);
  pointer-events: none;
  transition: transform 0.2s var(--ease), opacity 0.2s var(--ease);
}
.cart-badge--hidden {
  opacity: 0;
  transform: scale(0.6);
  pointer-events: none;
}

/* ---- Cart page layout ---------------------------------------------------- */

.cart-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: var(--space-8);
  align-items: start;
}

@media (max-width: 768px) {
  .cart-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .cart-summary-col {
    order: -1; /* summary above items on mobile */
  }
}

/* ---- Items column -------------------------------------------------------- */

.cart-items-col {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.cart-items-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-2);
}
.cart-items-count {
  margin: 0;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
  font-weight: 500;
}
.cart-clear-btn {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-md);
  transition: color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.cart-clear-btn:hover {
  color: var(--color-danger);
  background: rgba(248, 113, 113, 0.08);
}
.cart-clear-btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* ---- Cart item card ------------------------------------------------------ */

.cart-item {
  display: grid;
  grid-template-columns: auto 120px minmax(0, 1fr);
  align-items: start;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--surface-glass), var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color 0.2s var(--ease);
  animation: card-in 0.35s var(--ease) both;
}
.cart-item:hover {
  border-color: rgba(139, 92, 246, 0.4);
}

.cart-item-select {
  display: flex;
  align-items: center;
  height: 100%;
  padding-top: var(--space-1);
}
.cart-item-select .cart-item-checkbox,
.cart-item-checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--color-accent-500, #8b5cf6);
  cursor: pointer;
  flex-shrink: 0;
}

.cart-select-all {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
  user-select: none;
}
.cart-select-all input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--color-accent-500, #8b5cf6);
  cursor: pointer;
}

.cart-selection-note {
  margin: var(--space-2) 0 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}
.cart-item.is-unavailable {
  opacity: 0.65;
}
.cart-item.is-unavailable .cart-item-thumb {
  filter: grayscale(40%);
}

.cart-item-thumb {
  aspect-ratio: 16 / 9;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--color-surface-2);
  flex-shrink: 0;
}
.cart-item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.cart-item-thumb .thumb-fallback {
  font-size: 1.5rem;
}

.cart-item-body {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  min-width: 0;
}

.cart-item-title {
  margin: 0;
  font-size: var(--font-size-base);
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: -0.01em;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.cart-item-title a {
  color: var(--color-text);
  text-decoration: none;
}
.cart-item-title a:hover {
  color: var(--color-accent-700);
}

.cart-item-instructor {
  margin: 0;
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
}

.cart-item-unavailable-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  background: rgba(248, 113, 113, 0.1);
  color: var(--color-danger);
  border: 1px solid rgba(248, 113, 113, 0.35);
  align-self: flex-start;
}

.cart-item-pricing {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  margin-top: auto;
}
.cart-item-price {
  font-size: var(--font-size-lg);
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--color-text);
}
.cart-item-original {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  text-decoration: line-through;
}
.cart-item-free {
  font-size: var(--font-size-base);
  font-weight: 600;
  color: var(--color-success);
}

.cart-item-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-top: var(--space-2);
  flex-wrap: wrap;
}
.cart-item-remove {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  transition: color 0.15s var(--ease);
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.cart-item-remove:hover {
  color: var(--color-danger);
}
.cart-item-remove:disabled {
  opacity: 0.5;
  cursor: wait;
}
.cart-item-view {
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-accent-700);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
}
.cart-item-view:hover {
  color: #fff;
}

/* ---- Skeletons ----------------------------------------------------------- */

.cart-item-skeleton {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: var(--space-4);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}
.cart-skeleton-thumb {
  border-radius: var(--radius-md);
  aspect-ratio: 16 / 9;
}
.cart-skeleton-lines {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-top: var(--space-2);
}
.cart-skeleton-line {
  border-radius: var(--radius-sm);
  height: 14px;
}
.cart-skeleton-line.is-short {
  width: 55%;
}
.cart-skeleton-line.is-price {
  width: 25%;
  height: 20px;
}

/* ---- Summary column ------------------------------------------------------ */

.cart-summary-col {
  position: sticky;
  top: calc(var(--header-h) + var(--space-4));
}

.cart-summary {
  background: var(--surface-glass), var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.cart-summary-title {
  margin: 0;
  font-size: var(--font-size-xl);
  font-weight: 600;
  letter-spacing: -0.02em;
}

.cart-summary-rows {
  display: flex;
  flex-direction: column;
  gap: 0;
  border-top: 1px solid var(--color-border);
}
.cart-summary-row {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--color-border);
  font-size: var(--font-size-sm);
}
.cart-summary-row dt {
  color: var(--color-text-muted);
  font-weight: 400;
}
.cart-summary-row dd {
  margin: 0;
  font-weight: 500;
  text-align: right;
}
.cart-summary-row.is-total {
  border-bottom: none;
  padding-top: var(--space-4);
}
.cart-summary-row.is-total dt {
  font-size: var(--font-size-base);
  font-weight: 500;
  color: var(--color-text);
}
.cart-summary-row.is-total dd {
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fff, var(--color-accent-700));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.cart-unavailable-notice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.25);
  font-size: 0.8125rem;
  color: var(--color-danger);
  line-height: 1.5;
}
.cart-unavailable-notice[hidden] { display: none; }

.cart-checkout-btn {
  width: 100%;
  justify-content: center;
  gap: var(--space-2);
}

.cart-summary-note {
  margin: 0;
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  text-align: center;
}

/* ---- Empty state --------------------------------------------------------- */

.cart-empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--space-4);
  padding: var(--space-20) var(--space-6);
  border: 1px dashed rgba(139, 92, 246, 0.35);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(500px 200px at 50% 0%, rgba(124, 58, 237, 0.1), transparent 70%),
    rgba(255, 255, 255, 0.012);
}
.cart-empty[hidden] { display: none; }
.cart-empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: rgba(124, 58, 237, 0.14);
  color: var(--color-accent-700);
  margin-bottom: var(--space-2);
}
.cart-empty h2 {
  margin: 0;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.025em;
}
.cart-empty p {
  margin: 0;
  color: var(--color-text-muted);
  max-width: 40ch;
  font-size: var(--font-size-lg);
}

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

@media (max-width: 480px) {
  .cart-item {
    grid-template-columns: 96px minmax(0, 1fr);
    gap: var(--space-3);
  }
  .cart-item-skeleton {
    grid-template-columns: 96px minmax(0, 1fr);
    gap: var(--space-3);
  }
  .cart-summary-col {
    position: static;
  }
}

@media (max-width: 768px) {
  .cart-nav-btn {
    /* On mobile the student nav is hidden, but the cart btn remains visible
       in the header actions cluster (between the theme toggle and the mobile
       hamburger). Keep it accessible. */
    display: inline-flex;
  }
}
