/**
 * Student Menu - Dropdown Component Styles
 * Feature: F-047 Student Menu
 *
 * Glassmorphism dropdown triggered by a single profile icon.
 * Consolidates: theme toggle, gamification badges, auth, report card, edit details.
 */

/* ============================================================================
   TRIGGER BUTTON
   ============================================================================ */

.student-menu-trigger {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  background: transparent;
  border: 1.5px solid var(--border-default, #334155);
  border-radius: var(--radius-full, 9999px);
  color: var(--text-secondary, #94a3b8);
  cursor: pointer;
  transition: all var(--duration-fast, 150ms) var(--ease-in-out);
  overflow: hidden;
}

.student-menu-trigger:hover {
  border-color: var(--color-primary, #2563EB);
  color: var(--text-primary, #f1f5f9);
  background: var(--bg-interactive, #475569);
}

.student-menu-trigger:focus-visible {
  outline: 2px solid var(--color-primary, #2563EB);
  outline-offset: 2px;
}

.student-menu-trigger[aria-expanded="true"] {
  border-color: var(--color-primary, #2563EB);
  background: var(--bg-interactive, #475569);
}

/* Avatar initial circle */
.student-menu-trigger .menu-avatar-initial {
  font-size: var(--text-sm, 0.875rem);
  font-weight: var(--font-semibold, 600);
  line-height: 1;
  text-transform: uppercase;
  color: var(--text-inverse, #0f172a);
  background: var(--color-primary, #2563EB);
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full, 9999px);
}

/* Guest icon (no initial) */
.student-menu-trigger .menu-guest-icon {
  display: flex;
  align-items: center;
  justify-content: center;
}

.student-menu-trigger .menu-guest-icon svg {
  width: 20px;
  height: 20px;
}

/* ============================================================================
   DROPDOWN PANEL
   ============================================================================ */

.student-menu-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 260px;
  max-width: 300px;
  z-index: 200;

  /* Glassmorphism */
  background: var(--glass-bg, rgba(30, 41, 59, 0.7));
  backdrop-filter: blur(var(--glass-blur, 10px));
  -webkit-backdrop-filter: blur(var(--glass-blur, 10px));
  border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
  border-radius: var(--radius-xl, 1rem);
  box-shadow: var(--shadow-xl, 0 20px 25px -5px rgba(0, 0, 0, 0.3));

  /* Animation */
  opacity: 0;
  visibility: hidden; /* Remove from layout — prevents iOS Safari scrollbar */
  transform: translateY(-8px) scale(0.97);
  pointer-events: none;
  transition: opacity var(--duration-fast, 150ms) var(--ease-out),
              transform var(--duration-fast, 150ms) var(--ease-out),
              visibility 0s var(--duration-fast, 150ms);

  overflow: hidden;
}

.student-menu-dropdown.open {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--duration-fast, 150ms) var(--ease-out),
              transform var(--duration-fast, 150ms) var(--ease-out),
              visibility 0s;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ============================================================================
   MENU SECTIONS
   ============================================================================ */

.student-menu-section {
  padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
}

.student-menu-section + .student-menu-section {
  border-top: 1px solid var(--border-subtle, rgba(255, 255, 255, 0.06));
}

/* ============================================================================
   PROFILE SECTION (top)
   ============================================================================ */

.student-menu-profile {
  display: flex;
  align-items: center;
  gap: var(--space-3, 0.75rem);
  padding: var(--space-4, 1rem);
}

.student-menu-profile-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full, 9999px);
  background: var(--color-primary, #2563EB);
  color: var(--text-inverse, white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-lg, 1.125rem);
  font-weight: var(--font-bold, 700);
  flex-shrink: 0;
  text-transform: uppercase;
}

.student-menu-profile-info {
  overflow: hidden;
}

.student-menu-profile-name {
  font-size: var(--text-sm, 0.875rem);
  font-weight: var(--font-semibold, 600);
  color: var(--text-primary, #f1f5f9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.student-menu-profile-email {
  font-size: var(--text-xs, 0.75rem);
  color: var(--text-muted, #64748b);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Guest header (no avatar) */
.student-menu-guest-header {
  display: flex;
  align-items: center;
  gap: var(--space-2, 0.5rem);
  padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
  color: var(--text-secondary, #94a3b8);
  font-size: var(--text-sm, 0.875rem);
  font-weight: var(--font-medium, 500);
}

.student-menu-guest-header svg {
  width: 18px;
  height: 18px;
  opacity: 0.7;
}

/* ============================================================================
   SCORES SECTION (3-column gamification stats)
   ============================================================================ */

.student-menu-scores {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-2, 0.5rem);
  text-align: center;
  padding: var(--space-3, 0.75rem) var(--space-4, 1rem);
}

.score-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.score-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-md, 0.5rem);
  margin-bottom: 2px;
}

.score-icon svg {
  width: 18px;
  height: 18px;
}

.score-icon--xp {
  background: rgba(234, 179, 8, 0.15);
  color: #eab308;
}

.score-icon--streak {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.score-icon--mastery {
  background: rgba(59, 130, 246, 0.15);
  color: #2563EB;
}

/* Mastery level number overlaid on shield */
.score-icon .mastery-level {
  position: absolute;
  font-size: 9px;
  font-weight: 700;
  color: #2563EB;
  margin-top: 1px;
}

.score-label {
  font-size: 10px;
  color: var(--text-muted, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1;
}

.score-value {
  font-size: var(--text-xs, 0.75rem);
  font-weight: var(--font-semibold, 600);
  color: var(--text-primary, #f1f5f9);
  line-height: 1;
  white-space: nowrap;
}

/* ============================================================================
   MENU ITEMS (actions)
   ============================================================================ */

.student-menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3, 0.75rem);
  width: 100%;
  padding: var(--space-2, 0.5rem) var(--space-4, 1rem);
  min-height: 44px;
  background: transparent;
  border: none;
  border-radius: 0;
  color: var(--text-secondary, #94a3b8);
  font-size: var(--text-sm, 0.875rem);
  font-family: inherit;
  cursor: pointer;
  transition: background var(--duration-fast, 150ms) var(--ease-in-out),
              color var(--duration-fast, 150ms) var(--ease-in-out);
  text-decoration: none;
  text-align: left;
}

.student-menu-item:hover,
.student-menu-item:focus-visible {
  background: var(--bg-interactive, rgba(255, 255, 255, 0.06));
  color: var(--text-primary, #f1f5f9);
}

.student-menu-item:focus-visible {
  outline: 2px solid var(--color-primary, #2563EB);
  outline-offset: -2px;
}

.student-menu-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.7;
}

.student-menu-item:hover svg {
  opacity: 1;
}

.student-menu-item-label {
  flex: 1;
}

/* Theme toggle has a value indicator */
.student-menu-item .theme-value {
  font-size: var(--text-xs, 0.75rem);
  color: var(--text-muted, #64748b);
  margin-left: auto;
}

/* Sign out - slightly different styling */
.student-menu-item--signout {
  color: var(--color-error, #ef4444);
}

.student-menu-item--signout:hover {
  color: var(--color-error, #ef4444);
  background: rgba(239, 68, 68, 0.1);
}

.student-menu-item--signout svg {
  opacity: 0.8;
}

/* Sign in / Get Started - primary styling */
.student-menu-item--signin {
  color: var(--color-primary, #2563EB);
}

.student-menu-item--signin:hover {
  color: var(--color-primary, #2563EB);
  background: rgba(59, 130, 246, 0.1);
}

/* ============================================================================
   ALPHA CODE (inline menu item)
   ============================================================================ */

.student-menu-alpha-code {
  cursor: pointer;
}

.student-menu-alpha-code .alpha-code-value {
  margin-left: auto;
}

.alpha-code-copy {
  display: inline-flex;
  align-items: center;
  border: none;
  background: none;
  padding: 2px 8px;
  border-radius: var(--radius-sm, 0.25rem);
  cursor: pointer;
  margin-left: auto;
  transition: background 150ms ease;
}

.alpha-code-copy:hover {
  background: rgba(37, 99, 235, 0.1);
}

.alpha-code-copy:active {
  transform: scale(0.95);
}

.alpha-code-value {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: var(--text-xs, 0.75rem);
  font-weight: 600;
  color: var(--color-primary, #2563EB);
  letter-spacing: 0.04em;
}

.alpha-code-copy--copied .alpha-code-value {
  color: var(--color-success, #22c55e);
}

/* ============================================================================
   LIGHT THEME OVERRIDES
   ============================================================================ */

[data-theme="light"] .student-menu-dropdown {
  background: var(--glass-bg, rgba(255, 255, 255, 0.85));
  border-color: var(--glass-border, rgba(0, 0, 0, 0.08));
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .student-menu-section + .student-menu-section {
  border-top-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .student-menu-item:hover,
[data-theme="light"] .student-menu-item:focus-visible {
  background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .student-menu-item--signout:hover {
  background: rgba(239, 68, 68, 0.08);
}

[data-theme="light"] .student-menu-item--signin:hover {
  background: rgba(59, 130, 246, 0.08);
}

[data-theme="light"] .alpha-code-copy:hover {
  background: rgba(37, 99, 235, 0.06);
}

/* ============================================================================
   RESPONSIVE - MOBILE
   ============================================================================ */

@media (max-width: 480px) {
  .student-menu-dropdown {
    /* Stay as top-right dropdown, just stretch wider */
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    left: auto;
    bottom: auto;
    min-width: calc(100vw - 32px);
    max-width: calc(100vw - 32px);
    max-height: 70vh;
    overflow-y: auto;
    border-radius: var(--radius-xl, 1rem);
  }

  /* Mobile overlay backdrop */
  .student-menu-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
    opacity: 0;
    transition: opacity var(--duration-fast, 150ms) var(--ease-in-out);
  }

  .student-menu-overlay.open {
    display: block;
    opacity: 1;
  }
}

@media (min-width: 481px) {
  .student-menu-overlay {
    display: none !important;
  }
}

/* ============================================================================
   REDUCED MOTION
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .student-menu-dropdown {
    transition: none;
  }

  .student-menu-trigger {
    transition: none;
  }

  .student-menu-overlay {
    transition: none;
  }
}

/* ============================================================================
   LINK ACCOUNT MODAL (F-085)
   ============================================================================ */

.link-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: link-modal-fade-in 200ms ease;
}

@keyframes link-modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.link-modal {
  position: relative;
  background: var(--bg-primary, #fff);
  border-radius: var(--radius-xl, 1rem);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  max-width: 420px;
  width: 100%;
  padding: 28px 24px 24px;
  animation: link-modal-slide-up 250ms ease;
}

@keyframes link-modal-slide-up {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.link-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border: none;
  background: none;
  font-size: 22px;
  color: var(--text-secondary, #64748b);
  cursor: pointer;
  border-radius: var(--radius-sm, 0.25rem);
  display: flex;
  align-items: center;
  justify-content: center;
}

.link-modal-close:hover {
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-primary, #1e293b);
}

.link-modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary, #1e293b);
  margin: 0 0 6px;
}

.link-modal-desc {
  font-size: 0.875rem;
  color: var(--text-secondary, #64748b);
  margin: 0 0 20px;
  line-height: 1.5;
}

.link-modal-section {
  margin-bottom: 20px;
}

.link-modal-section:last-child {
  margin-bottom: 0;
}

.link-modal-step {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  margin: 0 0 4px;
}

.link-modal-hint {
  font-size: 0.8125rem;
  color: var(--text-secondary, #64748b);
  margin: 0 0 10px;
  line-height: 1.4;
}

.link-modal-code-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-secondary, #f1f5f9);
  border-radius: var(--radius-md, 0.5rem);
  padding: 10px 14px;
}

.link-modal-code {
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-primary, #2563EB);
  letter-spacing: 0.05em;
}

.link-modal-copy-btn {
  margin-left: auto;
  padding: 6px 14px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--bg-primary, #fff);
  border-radius: var(--radius-sm, 0.25rem);
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--text-primary, #1e293b);
  cursor: pointer;
  min-width: 64px;
  text-align: center;
}

.link-modal-copy-btn:hover {
  background: var(--bg-secondary, #f1f5f9);
}

.link-modal-input-row {
  display: flex;
  gap: 8px;
}

.link-modal-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--border, #e2e8f0);
  border-radius: var(--radius-md, 0.5rem);
  font-size: 0.9375rem;
  color: var(--text-primary, #1e293b);
  background: var(--bg-primary, #fff);
}

/* Email inputs shouldn't be monospace or uppercase */
.link-modal-input[type="email"] {
  font-family: inherit;
  text-transform: none;
  letter-spacing: normal;
}

/* Code inputs keep monospace styling */
.link-modal-input[type="text"] {
  font-family: 'SF Mono', 'Fira Code', monospace;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.link-modal-input:focus {
  outline: none;
  border-color: var(--color-primary, #2563EB);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.link-modal-input::placeholder {
  color: var(--text-tertiary, #94a3b8);
  text-transform: none;
}

.link-modal-submit-btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-md, 0.5rem);
  font-size: 0.9375rem;
  font-weight: 600;
  color: #fff;
  background: var(--color-primary, #2563EB);
  cursor: pointer;
  min-width: 72px;
}

.link-modal-submit-btn:hover:not(:disabled) {
  background: var(--color-primary-hover, #1d4ed8);
}

.link-modal-submit-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.link-modal-cancel-btn {
  padding: 10px 20px;
  border: 1.5px solid var(--border, #e2e8f0);
  border-radius: var(--radius-md, 0.5rem);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  background: transparent;
  cursor: pointer;
  min-width: 72px;
}

.link-modal-cancel-btn:hover {
  background: var(--bg-secondary, #f1f5f9);
  color: var(--text-primary, #1e293b);
}

.link-modal-status {
  font-size: 0.8125rem;
  margin-top: 8px;
  min-height: 20px;
}

.link-modal-status--success {
  color: var(--color-success, #16a34a);
  font-weight: 500;
}

.link-modal-status--error {
  color: var(--color-error, #dc2626);
  font-weight: 500;
}

/* Dark mode */
[data-theme="dark"] .link-modal {
  background: var(--bg-primary, #1e293b);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

[data-theme="dark"] .link-modal-code-row {
  background: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .link-modal-copy-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text-primary, #e2e8f0);
}

[data-theme="dark"] .link-modal-input {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
  color: var(--text-primary, #e2e8f0);
}

/* F-085: Link notification banner (shown on student pages when parent sends request) */
.link-notification-banner {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.08), rgba(139, 92, 246, 0.06));
  border: 1px solid rgba(59, 130, 246, 0.18);
  border-radius: var(--radius-md, 8px);
  padding: 16px 20px;
  margin: 12px auto;
  max-width: var(--content-max, 800px);
  box-sizing: border-box;
}
[data-theme="dark"] .link-notification-banner {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(139, 92, 246, 0.08));
  border-color: rgba(59, 130, 246, 0.25);
}
.link-notification-banner__inner {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.link-notification-banner__text {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text-primary);
  flex: 1;
  min-width: 200px;
}
.link-notification-banner__code-row {
  display: flex;
}
.link-notification-banner__code-row .link-modal-input {
  max-width: 160px;
  padding: 6px 10px;
  font-size: 0.85rem;
}
.link-notification-banner__actions {
  display: flex;
  gap: 8px;
}
.link-notification-banner__status {
  font-size: 0.82rem;
  min-height: 1.2em;
  width: 100%;
  text-align: center;
}
.link-notification-banner .link-btn-accept {
  padding: 6px 16px;
  background: var(--color-success, #16a34a);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm, 6px);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 200ms;
  white-space: nowrap;
}
.link-notification-banner .link-btn-accept:hover:not(:disabled) {
  background: #15803d;
}
.link-notification-banner .link-btn-accept:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.link-notification-banner .link-btn-decline {
  padding: 6px 16px;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 6px);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 200ms;
  white-space: nowrap;
}
.link-notification-banner .link-btn-decline:hover:not(:disabled) {
  background: rgba(220, 38, 38, 0.06);
  color: var(--color-error, #dc2626);
  border-color: var(--color-error, #dc2626);
}
/* Mobile: stack vertically */
@media (max-width: 600px) {
  .link-notification-banner__inner {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }
  .link-notification-banner__code-row .link-modal-input {
    max-width: 100%;
    width: 100%;
  }
  .link-notification-banner__actions {
    justify-content: center;
  }
}
