/* ============================================================================
   MedGrid Portal — On-brand restyle
   ----------------------------------------------------------------------------
   Replaces the previous "3D depth" template aesthetic (glassmorphism, gradient
   text headings, per-portal accent shuffling) with the same design tokens the
   public homepage uses (mg-design-system.css). All `.mg-*` class names are
   preserved so existing portal HTML doesn't change — only the visual treatment.

   Tokens mirror the homepage so /portal/* pages feel like the same product:
     navy headings, cobalt accent, paper background, pill buttons, soft shadow,
     Inter Tight display + Inter body + JetBrains Mono eyebrow.

   Loaded globally via hooks.web_include_css.
============================================================================ */

.mg-3d {
  /* ── Brand palette — mirrors mg-design-system.css ─────────────────────── */
  --mg-navy:        #0B0A4E;
  --mg-navy-deep:   #07063A;
  --mg-navy-soft:   #1A1A6E;
  --mg-cobalt:      #1E90FF;
  --mg-cobalt-soft: #4DA8FF;
  --mg-cobalt-deep: #0E6BD6;

  --mg-paper:       #FAFAF7;
  --mg-paper-2:     #F4F4EF;
  --mg-white:       #FFFFFF;
  --mg-ink-900:     #0A0B14;
  --mg-ink-700:     #1F2230;
  --mg-ink-500:     #4A4F62;
  --mg-ink-400:     #6E7488;
  --mg-ink-300:     #9AA0B4;
  --mg-ink-200:     #D5D8E2;
  --mg-ink-100:     #E8EAF0;
  --mg-ink-50:      #F2F3F7;

  --mg-line:        rgba(11,10,78,0.08);
  --mg-line-strong: rgba(11,10,78,0.16);

  /* Status colors — used sparingly, kept within the brand spectrum */
  --mg-success:     #0F9B6C;
  --mg-success-tint: rgba(15,155,108,0.10);
  --mg-warn:        #C77800;
  --mg-warn-tint:   rgba(199,120,0,0.10);
  --mg-danger:      #C82A2A;
  --mg-danger-tint: rgba(200,42,42,0.10);

  /* Aliases used by existing rules — point at brand colors */
  --mg-accent:      var(--mg-cobalt);
  --mg-accent-deep: var(--mg-cobalt-deep);
  --mg-card:        var(--mg-white);
  --mg-text:        var(--mg-ink-900);
  --mg-text-muted:  var(--mg-ink-500);

  /* Elevation (matches homepage) */
  --mg-shadow-1:    0 1px 2px rgba(11,10,78,0.06), 0 1px 0 rgba(11,10,78,0.04);
  --mg-shadow-2:    0 4px 16px rgba(11,10,78,0.06), 0 1px 2px rgba(11,10,78,0.04);
  --mg-shadow-3:    0 12px 40px rgba(11,10,78,0.10), 0 4px 12px rgba(11,10,78,0.06);
  --mg-shadow-lift: 0 24px 60px -12px rgba(11,10,78,0.22), 0 8px 24px -8px rgba(11,10,78,0.12);

  /* Radii — matches homepage */
  --mg-r-sm: 6px;
  --mg-r-md: 10px;
  --mg-r-lg: 16px;
  --mg-r-xl: 24px;

  /* Motion */
  --mg-easing: cubic-bezier(0.2, 0.7, 0.2, 1);
  --mg-motion: 220ms;

  /* Typography — matches homepage */
  --mg-font-display: "Inter Tight", "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mg-font-body:    "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --mg-font-mono:    "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  font-family: var(--mg-font-body);
  color: var(--mg-ink-900);
  background: var(--mg-paper);
  min-height: 100vh;
  padding: 48px 24px 80px;
}

/* Per-portal class hooks are kept for HTML compatibility but no longer
   shuffle the accent — every portal uses the same brand cobalt. Add a
   subtle paper tint instead so the user can tell pages apart. */
.mg-3d--rep      { background: linear-gradient(180deg, var(--mg-paper) 0%, #F3F5FA 100%); }
.mg-3d--vendor   { background: linear-gradient(180deg, var(--mg-paper) 0%, #F2F7F4 100%); }
.mg-3d--admin    { background: linear-gradient(180deg, var(--mg-paper) 0%, #F0F4FA 100%); }
.mg-3d--insights { background: linear-gradient(180deg, var(--mg-paper) 0%, #FBF7F0 100%); }

/* ============================================================================
   Layout primitives
============================================================================ */
.mg-3d .mg-container { max-width: 1240px; margin: 0 auto; }

.mg-3d .mg-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 40px; gap: 16px;
}
.mg-3d .mg-header h1 {
  margin: 0;
  font-family: var(--mg-font-display);
  font-weight: 600;
  font-size: clamp(28px, 3vw, 40px);
  line-height: 1.05;
  letter-spacing: -0.025em;
  color: var(--mg-navy);
  /* NO gradient text — solid navy matches the homepage */
}
.mg-3d .mg-header .mg-sub {
  font-family: var(--mg-font-mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--mg-ink-400);
}

.mg-3d .mg-grid {
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}
.mg-3d .mg-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.mg-3d .mg-grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mg-3d .mg-grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 900px) {
  .mg-3d .mg-grid--3, .mg-3d .mg-grid--4, .mg-3d .mg-grid--2 {
    grid-template-columns: 1fr;
  }
}

/* ============================================================================
   Cards — flat, paper-weight elevation, soft hover. No glass, no gradients.
============================================================================ */
.mg-3d .mg-card {
  position: relative;
  background: var(--mg-white);
  border-radius: var(--mg-r-lg);
  border: 1px solid var(--mg-line);
  box-shadow: var(--mg-shadow-1);
  padding: 24px;
  transition:
    transform     var(--mg-motion) var(--mg-easing),
    box-shadow    var(--mg-motion) var(--mg-easing),
    border-color  var(--mg-motion) var(--mg-easing);
}
.mg-3d .mg-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--mg-shadow-2);
  border-color: var(--mg-line-strong);
}
.mg-3d .mg-card--interactive { cursor: pointer; }
.mg-3d .mg-card--accent {
  /* Solid brand navy — calmer than the previous gradient */
  background: var(--mg-navy);
  color: var(--mg-white);
  border-color: transparent;
}
.mg-3d .mg-card--accent h2,
.mg-3d .mg-card--accent h3,
.mg-3d .mg-card--accent .mg-kpi-label,
.mg-3d .mg-card--accent .mg-kpi-value { color: var(--mg-white); }
.mg-3d .mg-card--accent .mg-kpi-label { color: rgba(255,255,255,0.65); }
.mg-3d .mg-card--accent .mg-pill { background: rgba(255,255,255,0.12); color: var(--mg-white); }

/* KPI card — matches the homepage stat tile vibe */
.mg-3d .mg-kpi { display: flex; flex-direction: column; gap: 6px; }
.mg-3d .mg-kpi-label {
  font-family: var(--mg-font-mono);
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--mg-ink-400);
}
.mg-3d .mg-kpi-value {
  font-family: var(--mg-font-display);
  font-weight: 600;
  font-size: clamp(28px, 3vw, 36px);
  letter-spacing: -0.025em; line-height: 1.05;
  color: var(--mg-navy);
}
.mg-3d .mg-kpi-delta {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; font-weight: 600;
}
.mg-3d .mg-kpi-delta--up   { color: var(--mg-success); }
.mg-3d .mg-kpi-delta--down { color: var(--mg-danger);  }

/* ============================================================================
   Pills, badges, chips
============================================================================ */
.mg-3d .mg-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: 999px;
  font-family: var(--mg-font-mono);
  font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
  background: var(--mg-ink-50); color: var(--mg-ink-700);
  font-weight: 500;
}
.mg-3d .mg-pill--success { background: var(--mg-success-tint); color: var(--mg-success); }
.mg-3d .mg-pill--warn    { background: var(--mg-warn-tint);    color: var(--mg-warn); }
.mg-3d .mg-pill--danger  { background: var(--mg-danger-tint);  color: var(--mg-danger); }
.mg-3d .mg-pill--accent  { background: rgba(30,144,255,0.10);  color: var(--mg-cobalt-deep); }

/* Achievement badge — flat, no rotate-on-hover gimmick */
.mg-3d .mg-badge {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px;
  padding: 18px 12px; border-radius: var(--mg-r-md);
  background: var(--mg-white);
  border: 1px solid var(--mg-line);
  text-align: center; font-size: 12px; font-weight: 500;
  color: var(--mg-ink-400);
  transition: border-color var(--mg-motion) var(--mg-easing),
              box-shadow var(--mg-motion) var(--mg-easing);
}
.mg-3d .mg-badge:hover { border-color: var(--mg-line-strong); }
.mg-3d .mg-badge--earned {
  color: var(--mg-ink-900);
  background: var(--mg-white);
  border-color: var(--mg-cobalt);
  box-shadow: 0 0 0 3px rgba(30,144,255,0.08);
}
.mg-3d .mg-badge .mg-badge-icon {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--mg-ink-50); color: var(--mg-ink-300);
  font-size: 20px;
}
.mg-3d .mg-badge--earned .mg-badge-icon {
  background: var(--mg-cobalt); color: var(--mg-white);
}

/* ============================================================================
   Progress bar
============================================================================ */
.mg-3d .mg-progress {
  position: relative; width: 100%; height: 8px;
  background: var(--mg-ink-100); border-radius: 999px;
  overflow: hidden;
}
.mg-3d .mg-progress-fill {
  position: absolute; inset: 0 auto 0 0; height: 100%;
  background: var(--mg-cobalt);
  border-radius: 999px;
  transition: width 700ms var(--mg-easing);
}

/* ============================================================================
   Tables
============================================================================ */
.mg-3d .mg-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  background: var(--mg-white); border-radius: var(--mg-r-md);
  overflow: hidden;
  border: 1px solid var(--mg-line);
  box-shadow: var(--mg-shadow-1);
}
.mg-3d .mg-table th,
.mg-3d .mg-table td {
  padding: 14px 16px; text-align: left; vertical-align: middle;
  font-size: 14px; border-bottom: 1px solid var(--mg-line);
}
.mg-3d .mg-table th {
  font-family: var(--mg-font-mono);
  font-size: 10.5px; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--mg-ink-400); font-weight: 500;
  background: var(--mg-paper-2);
}
.mg-3d .mg-table tbody tr {
  transition: background var(--mg-motion) var(--mg-easing);
}
.mg-3d .mg-table tbody tr:hover { background: var(--mg-ink-50); }
.mg-3d .mg-table tbody tr:last-child td { border-bottom: none; }

/* ============================================================================
   Buttons — pill-shaped, matching .btn-cobalt from mg-design-system.css
============================================================================ */
.mg-3d .mg-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 12px 22px; border-radius: 999px;
  font-family: var(--mg-font-body);
  font-weight: 500; font-size: 14px;
  letter-spacing: -0.005em;
  background: var(--mg-cobalt); color: var(--mg-white);
  border: 1px solid transparent; cursor: pointer;
  box-shadow: 0 8px 24px -8px rgba(30,144,255,0.55), inset 0 1px 0 rgba(255,255,255,0.18);
  transition: background var(--mg-motion) var(--mg-easing),
              transform  var(--mg-motion) var(--mg-easing);
}
.mg-3d .mg-btn:hover {
  background: var(--mg-cobalt-deep);
  transform: translateY(-1px);
}
.mg-3d .mg-btn:active { transform: translateY(0); }
.mg-3d .mg-btn--ghost {
  background: transparent; color: var(--mg-navy);
  border-color: var(--mg-line-strong);
  box-shadow: none;
}
.mg-3d .mg-btn--ghost:hover {
  background: var(--mg-white);
  border-color: var(--mg-navy);
}
.mg-3d .mg-btn--primary {
  background: var(--mg-navy);
  box-shadow: 0 8px 24px -8px rgba(11,10,78,0.40);
}
.mg-3d .mg-btn--primary:hover { background: var(--mg-navy-deep); }

/* ============================================================================
   Leaderboard row
============================================================================ */
.mg-3d .mg-leader {
  display: grid; grid-template-columns: 32px 36px 1fr auto;
  align-items: center; gap: 12px;
  padding: 10px 14px; border-radius: var(--mg-r-sm);
  transition: background var(--mg-motion) var(--mg-easing);
}
.mg-3d .mg-leader:hover { background: var(--mg-ink-50); }
.mg-3d .mg-leader-rank {
  font-family: var(--mg-font-mono);
  font-size: 13px; font-weight: 600; color: var(--mg-ink-400);
}
.mg-3d .mg-leader-rank--podium { color: var(--mg-cobalt); font-size: 15px; font-weight: 700; }
.mg-3d .mg-leader-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--mg-navy);
  color: var(--mg-white); font-weight: 600; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.mg-3d .mg-leader-name { font-weight: 500; font-size: 14px; color: var(--mg-ink-900); }
.mg-3d .mg-leader-metric {
  font-family: var(--mg-font-mono);
  font-weight: 600; font-size: 14px; color: var(--mg-cobalt-deep);
}

/* ============================================================================
   Empty state
============================================================================ */
.mg-3d .mg-empty {
  text-align: center; padding: 64px 24px;
  color: var(--mg-ink-400);
}
.mg-3d .mg-empty .mg-empty-icon {
  font-size: 48px; opacity: 0.4; margin-bottom: 12px;
}

/* ============================================================================
   Section headers
============================================================================ */
.mg-3d .mg-section-h {
  display: flex; align-items: center; gap: 10px;
  margin: 40px 0 18px; padding: 0 4px;
}
.mg-3d .mg-section-h h2 {
  margin: 0;
  font-family: var(--mg-font-display);
  font-size: 22px; font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--mg-navy);
}
.mg-3d .mg-section-h .mg-section-h-tag {
  font-family: var(--mg-font-mono);
  font-size: 10px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--mg-ink-400);
  padding: 3px 8px; border-radius: 999px;
  background: var(--mg-ink-50);
}

/* ============================================================================
   Sparkline placeholder
============================================================================ */
.mg-3d .mg-spark {
  height: 48px; margin-top: 8px;
  background: linear-gradient(180deg, rgba(30,144,255,0.14) 0%, transparent 100%);
  border-radius: var(--mg-r-sm);
}

/* ============================================================================
   Certificates page (the only other portal page with bespoke styles)
============================================================================ */
.mg-3d .mg-portal-section { padding: 48px 0; }
.mg-3d .mg-portal-head {
  display: flex; flex-direction: column; gap: 8px;
  margin-bottom: 32px;
}
.mg-3d .mg-portal-head h1 {
  margin: 0; font-family: var(--mg-font-display);
  font-size: clamp(28px, 3vw, 36px); font-weight: 600;
  color: var(--mg-navy); letter-spacing: -0.025em;
}
.mg-3d .mg-portal-sub {
  color: var(--mg-ink-500); font-size: 15px; line-height: 1.55;
}
.mg-3d .mg-back-link {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--mg-font-mono);
  font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--mg-ink-400); text-decoration: none;
  padding-bottom: 4px; border-bottom: 1px solid transparent;
  transition: color var(--mg-motion) var(--mg-easing),
              border-color var(--mg-motion) var(--mg-easing);
}
.mg-3d .mg-back-link:hover { color: var(--mg-navy); border-bottom-color: var(--mg-line-strong); }
.mg-3d .mg-cert-grid {
  display: grid; gap: 20px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.mg-3d .mg-cert-card {
  background: var(--mg-white); border: 1px solid var(--mg-line);
  border-radius: var(--mg-r-lg); padding: 20px;
  box-shadow: var(--mg-shadow-1);
}
.mg-3d .mg-cert-meta { font-size: 13px; color: var(--mg-ink-500); margin-bottom: 12px; }
.mg-3d .mg-cert-actions { margin-top: 16px; display: flex; gap: 8px; }
.mg-3d .mg-mono { font-family: var(--mg-font-mono); font-size: 12px; }
.mg-3d .mg-empty-state {
  text-align: center; padding: 80px 24px;
  color: var(--mg-ink-400);
  background: var(--mg-white); border: 1px solid var(--mg-line);
  border-radius: var(--mg-r-lg);
}

/* ============================================================================
   Motion-reduced + print
============================================================================ */
@media (prefers-reduced-motion: reduce) {
  .mg-3d * { transition: none !important; animation: none !important; }
}

@media print {
  .mg-3d * { box-shadow: none !important; }
  .mg-3d .mg-card { border: 1px solid #ccc; break-inside: avoid; }
}
