/* ============================================================
   FIGMENT PROFILES - Main Stylesheet
   Brand Colors: Black & Purple
   WCAG 2.0 Compliant
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
    /* Brand Colors */
    --color-primary: #7B2D8E;         /* Figment Purple */
    --color-primary-light: #9B4DBA;
    --color-primary-dark: #5A1D6B;
    --color-primary-subtle: #F3E8F7;
    
    --color-black: #1A1A2E;
    --color-dark: #16213E;
    --color-darker: #0F0F1A;
    
    /* Functional Colors */
    --color-success: #28A745;
    --color-warning: #FFC107;
    --color-danger: #DC3545;
    --color-info: #17A2B8;
    
    /* Neutrals */
    --color-white: #FFFFFF;
    --color-gray-50: #F8F9FA;
    --color-gray-100: #F1F3F5;
    --color-gray-200: #E9ECEF;
    --color-gray-300: #DEE2E6;
    --color-gray-400: #CED4DA;
    --color-gray-500: #ADB5BD;
    --color-gray-600: #6C757D;
    --color-gray-700: #495057;
    --color-gray-800: #343A40;
    --color-gray-900: #212529;
    
    /* Typography */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;
    --font-size-4xl: 2.5rem;
    
    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    --space-3xl: 4rem;
    
    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;
    
    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.12);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.2);
    --shadow-purple: 0 4px 20px rgba(123, 45, 142, 0.3);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 250ms ease;
    --transition-slow: 400ms ease;
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--color-gray-900);
    background-color: var(--color-gray-50);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
}

img {
    max-width: 100%;
    height: auto;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-light);
}

/* WCAG: Focus styles */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
}

/* ---------- Skip Link (WCAG) ---------- */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-md);
    background: var(--color-primary);
    color: var(--color-white);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    z-index: 10000;
    font-weight: 600;
}

.skip-link:focus {
    top: var(--space-md);
}

/* ---------- Navigation ---------- */
.main-nav {
    background: var(--color-darker);
    padding: 0 var(--space-lg);
    height: 64px;
    display: flex;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--shadow-md);
    border-top: 4px solid var(--product-color, var(--color-primary));
}

/* Per-product accent colors */
/* WCAG 1.4.3: nav-product-name-bottom uses --product-color over the dark nav (#0F0F1A).
   Brand Clinic blue #1A56A0 = 2.61:1 (fails AA); lightened to #5B9BD5 = 6.5:1 (passes AA)
   for the nav label only. Brand #1A56A0 remains untouched on white-bg surfaces. */
.nav-product-profiles { --product-color: #B574D1; }
.nav-product-teamlab  { --product-color: #0891b2; }
.nav-product-clinic   { --product-color: #5B9BD5; }

.nav-container {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0 0.5rem;
}

/* ─── Hamburger + collapsible wrap ─── desktop defaults
   On desktop, the hamburger is hidden and .nav-collapse is a flex row that
   fills the remaining space after the logo, so the app-switcher and
   nav-links-right lay out exactly as they did before (with .nav-links-right
   pushed to the far right via its own margin-left:auto). Mobile overrides
   live in the @media (max-width: 768px) block below. */
.nav-hamburger { display: none; }
.nav-collapse {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1 1 auto;
    min-width: 0;
}
.nav-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    flex-shrink: 0;
    margin-right: 0.75rem;
}

.logo-img {
    height: 36px;
    width: auto;
}

.nav-product-name {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
    border-left: 1px solid rgba(255,255,255,0.15);
    padding-left: 10px;
}

.nav-product-name-top {
    font-size: 0.6rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255,255,255,0.45);
}

.nav-product-name-bottom {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--product-color, var(--color-primary));
}

.nav-links-right {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    margin-left: auto;
}

.nav-link {
    color: var(--color-gray-300);
    font-weight: 500;
    font-size: var(--font-size-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: var(--space-sm) 0;
    border-bottom: 2px solid transparent;
    transition: all var(--transition-fast);
}

.nav-link:hover,
.nav-link.active {
    color: var(--color-white);
    border-bottom-color: var(--color-primary);
}

.nav-code-badge {
    background: var(--color-primary-dark);
    color: var(--color-primary-subtle);
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-full);
    font-size: var(--font-size-sm);
    font-weight: 500;
    font-family: monospace;
}

.nav-user-menu {
    position: relative;
}

.nav-user-btn {
    background: none;
    border: none;
    color: var(--color-gray-300);
    font-family: var(--font-family);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.nav-user-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--color-white);
}

.nav-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    background: var(--color-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 210px;
    overflow: hidden;
    z-index: 100;
}

.nav-dropdown.open {
    display: block;
}

.nav-dropdown a {
    display: block;
    padding: var(--space-sm) var(--space-lg);
    color: var(--color-gray-800);
    font-size: var(--font-size-sm);
    transition: background var(--transition-fast);
}

.nav-dropdown a:hover {
    background: var(--color-primary-subtle);
    color: var(--color-primary);
}


.nav-dropdown-divider {
    height: 1px;
    background: var(--color-gray-200);
    margin: 6px 12px;
}

.nav-dropdown-label {
    padding: 8px 14px 4px;
    font-size: 0.62rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-gray-400);
}

.nav-platform-link {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding-left: 14px !important;
    padding-right: 14px !important;
    font-size: 0.82rem !important;
    gap: 8px;
}

.nav-platform-current {
    font-weight: 600;
    color: var(--color-primary) !important;
    background: var(--color-primary-subtle);
    border-radius: 6px;
    margin: 1px 8px;
}

.nav-platform-current:hover {
    background: var(--color-primary-subtle) !important;
}

.nav-platform-check {
    font-size: 0.7rem;
    color: var(--color-primary);
    margin-left: auto;
    flex-shrink: 0;
}
/* ---------- Flash Messages ---------- */
.flash-container {
    max-width: 800px;
    margin: var(--space-md) auto;
    padding: 0 var(--space-lg);
}

.flash {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 500;
    animation: slideDown 0.3s ease;
}

.flash-success { background: #d4edda; color: #155724; border-left: 4px solid var(--color-success); }
.flash-error   { background: #f8d7da; color: #721c24; border-left: 4px solid var(--color-danger); }
.flash-warning { background: #fff3cd; color: #856404; border-left: 4px solid var(--color-warning); }
.flash-info    { background: #d1ecf1; color: #0c5460; border-left: 4px solid var(--color-info); }

.flash-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0.6;
    color: inherit;
}

.flash-close:hover { opacity: 1; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    line-height: 1.5;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-light);
    border-color: var(--color-primary-light);
    box-shadow: var(--shadow-purple);
    color: var(--color-white);
}

.btn-secondary {
    background: transparent;
    color: var(--color-primary);
    border-color: var(--color-primary);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-primary);
    color: var(--color-white);
}

.btn-dark {
    background: var(--color-black);
    color: var(--color-white);
    border-color: var(--color-black);
}

.btn-dark:hover:not(:disabled) {
    background: var(--color-dark);
    border-color: var(--color-dark);
}

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

.btn-lg {
    padding: var(--space-md) var(--space-xl);
    font-size: var(--font-size-lg);
    border-radius: var(--radius-lg);
}

.btn-sm {
    padding: var(--space-xs) var(--space-md);
    font-size: var(--font-size-sm);
}

.btn-full {
    width: 100%;
}

/* ---------- Forms ---------- */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    font-weight: 600;
    margin-bottom: var(--space-xs);
    color: var(--color-gray-800);
    font-size: var(--font-size-sm);
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--color-gray-300);
    border-radius: var(--radius-md);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    color: var(--color-gray-900);
    background: var(--color-white);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(123, 45, 142, 0.15);
    outline: none;
}

.form-input::placeholder {
    color: var(--color-gray-600);  /* WCAG 1.4.3: was gray-500 (#ADB5BD) = 2.07:1 fail; gray-600 = 4.69:1 pass */
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-input-code {
    font-family: 'Courier New', monospace;
    font-size: var(--font-size-2xl);
    font-weight: 700;
    text-align: center;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: var(--space-md);
}

.form-error {
    color: var(--color-danger);
    font-size: var(--font-size-sm);
    margin-top: var(--space-xs);
}

.form-hint {
    color: var(--color-gray-600);
    font-size: var(--font-size-sm);
    margin-top: var(--space-xs);
}

/* ---------- Cards ---------- */
.card {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: transform var(--transition-base), box-shadow var(--transition-base);
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.card-body {
    padding: var(--space-lg);
}

/* ---------- Profile Cards ---------- */
.profile-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-md);
    padding: var(--space-lg);
    max-width: 1400px;
    margin: 0 auto;
}

.profile-card {
    background: var(--color-white);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition-base);
    cursor: pointer;
    border: 2px solid transparent;
}

.profile-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-purple);
    border-color: var(--color-primary);
}

.profile-card-thumb {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    background: var(--color-gray-200);
}

.profile-card-thumb-wrap { position: relative; overflow: hidden; line-height: 0; }
.profile-card-thumb-wrap img { width: 100%; display: block; }

.card-lock-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,.42);
    display: flex; align-items: center; justify-content: center;
    transition: background .2s;
}
.profile-card-locked:hover .card-lock-overlay { background: rgba(0,0,0,.55); }
.card-lock-icon { font-size: 2rem; filter: drop-shadow(0 2px 6px rgba(0,0,0,.5)); transition: transform .2s; }
.profile-card-locked:hover .card-lock-icon { transform: scale(1.12); }


.profile-card-body {
    padding: var(--space-sm) var(--space-md);
}

.profile-card-name {
    font-size: var(--font-size-sm);
    font-weight: 700;
    color: var(--color-black);
    margin-bottom: 2px;
}

.profile-card-subtitle {
    color: var(--color-primary);
    font-weight: 500;
    font-size: 0.75rem;
    margin-bottom: var(--space-xs);
}

.profile-card-desc {
    color: var(--color-gray-600);
    font-size: 0.75rem;
    line-height: 1.4;
}

.profile-card-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: var(--space-sm);
}

.badge-free {
    background: #d4edda;
    color: #155724;
}

.badge-premium {
    background: var(--color-primary-subtle);
    color: var(--color-primary-dark);
}

.badge-locked {
    background: var(--color-gray-200);
    color: var(--color-gray-700);  /* WCAG 1.4.3: was gray-600 = 3.95:1 fail; gray-700 = 7.0:1 pass */
}

.profile-card-unlock-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    margin-top: var(--space-sm);
    padding: 4px 12px;
    background: var(--color-primary);
    color: white !important;
    font-size: 0.72rem;
    font-weight: 700;
    text-align: center;
    text-decoration: none !important;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    border-radius: var(--radius-full);
    white-space: nowrap;
    transition: background var(--transition-fast);
    cursor: pointer;
}
.profile-card-unlock-btn:hover {
    background: var(--color-primary-dark);
}

/* ---------- Landing / Login Page ---------- */
.landing-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, var(--color-darker) 0%, var(--color-black) 50%, var(--color-primary-dark) 100%);
}

.landing-hero {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
}

.landing-container {
    width: 100%;
    max-width: 480px;
    text-align: center;
}

.landing-logo {
    height: 60px;
    margin-bottom: var(--space-xl);
}

.landing-title {
    color: var(--color-white);
    font-size: var(--font-size-3xl);
    font-weight: 700;
    margin-bottom: var(--space-sm);
}

.landing-subtitle {
    color: var(--color-gray-400);
    font-size: var(--font-size-lg);
    margin-bottom: var(--space-3xl);
}

.code-entry-box {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    backdrop-filter: blur(10px);
}

.code-entry-box .form-label {
    color: var(--color-gray-300);
    text-align: left;
}

.code-entry-box .form-input-code {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
    color: var(--color-white);
}

.code-entry-box .form-input-code::placeholder {
    color: rgba(255, 255, 255, 0.3);
    letter-spacing: 0.04em;
    font-size: var(--font-size-lg);
    font-weight: 400;
}

.code-entry-box .form-input-code:focus {
    border-color: var(--color-primary);
    background: rgba(255, 255, 255, 0.15);
}

.landing-divider {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    color: var(--color-gray-500);
    margin: var(--space-xl) 0;
    font-size: var(--font-size-sm);
}

.landing-divider::before,
.landing-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
}

.login-link-section {
    text-align: center;
}

.login-link-section a {
    color: var(--color-primary-light);
    font-weight: 500;
    text-decoration: underline;  /* WCAG 1.4.3: light purple on dark = 3.77:1 fails AA; underline ensures the link is identifiable without relying on color contrast alone */
    text-underline-offset: 2px;
}

.login-link-section a:hover {
    color: var(--color-white);
}

/* ---------- Page Containers ---------- */
.page-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-lg);
}

.page-header {
    margin-bottom: var(--space-xl);
}

.page-title {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    color: var(--color-black);
}

.page-subtitle {
    color: var(--color-gray-600);
    font-size: var(--font-size-lg);
    margin-top: var(--space-xs);
}

/* ---------- Search Bar ---------- */
.search-bar {
    position: relative;
    max-width: 600px;
    margin: var(--space-lg) auto var(--space-xl);
}

.search-bar input {
    width: 100%;
    padding: var(--space-md) var(--space-lg);
    padding-left: 48px;
    border: 2px solid var(--color-gray-300);
    border-radius: var(--radius-full);
    font-size: var(--font-size-base);
    background: var(--color-white);
}

.search-bar input:focus {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-purple);
}

.search-bar-icon {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-gray-500);
}

/* ---------- Collections ---------- */
.collection-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    background: var(--color-primary-subtle);
    border-radius: var(--radius-lg);
    cursor: pointer;
    margin-bottom: var(--space-md);
    transition: background var(--transition-fast);
}

.collection-header:hover {
    background: #e8d4f0;
}

.collection-title {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--color-primary-dark);
}

.collection-toggle {
    font-size: 1.5rem;
    color: var(--color-primary);
    transition: transform var(--transition-base);
}

.collection-toggle.open {
    transform: rotate(180deg);
}

.collection-cases {
    display: none;
    padding: 0 var(--space-md);
}

.collection-cases.open {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--space-xl);
    padding-bottom: var(--space-xl);
}

/* ---------- Modal ---------- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    z-index: 5000;
    align-items: center;
    justify-content: center;
    padding: var(--space-lg);
}

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

.modal {
    background: var(--color-white);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: var(--space-lg);
    border-bottom: 1px solid var(--color-gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: var(--font-size-xl);
    color: var(--color-black);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--color-gray-600);
    padding: var(--space-xs);
}

.modal-body {
    padding: var(--space-lg);
}

.modal-footer {
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--color-gray-200);
    display: flex;
    justify-content: flex-end;
    gap: var(--space-sm);
}

/* ---------- Loading Spinner ---------- */
.spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--color-gray-300);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.spinner-lg {
    width: 48px;
    height: 48px;
    border-width: 4px;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: var(--space-md);
    z-index: 9999;
}

/* ---------- Animations ---------- */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 5px rgba(123, 45, 142, 0.3); }
    50%      { box-shadow: 0 0 20px rgba(123, 45, 142, 0.6); }
}

/* ---------- Utility Classes ---------- */
.text-center { text-align: center; }
.text-right  { text-align: right; }
.text-muted  { color: var(--color-gray-600); }
.text-small  { font-size: var(--font-size-sm); }
.text-purple  { color: var(--color-primary); }

.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mt-xl { margin-top: var(--space-xl); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }

.hidden { display: none !important; }

/* WCAG: visually-hidden but available to screen readers.
   Used for icon-only buttons whose visible text label is hidden on mobile (.ban-btn .bl). */
.sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* WCAG 4.1.2: button styled as a text link (used in login flow + other places
   where href="#" + onclick was being used as a button). The thorough reset
   below clears every browser-default button artifact so the element renders
   identically to a real <a> link. */
.btn-link {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background: transparent;
    background-color: transparent;
    border: 0;
    border-radius: 0;
    padding: 0;
    margin: 0;
    box-shadow: none;
    text-shadow: none;
    color: var(--color-primary);
    font: inherit;
    line-height: inherit;
    letter-spacing: inherit;
    text-align: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
    display: inline;
    vertical-align: baseline;
}
.btn-link::-moz-focus-inner { border: 0; padding: 0; }
.btn-link:hover { color: var(--color-primary-light); text-decoration-thickness: 2px; }
.btn-link:active { color: var(--color-primary-dark); }
.btn-link:focus { outline: none; }
.btn-link:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; border-radius: 2px; }
.login-link-section .btn-link { color: var(--color-primary-light); }
.login-link-section .btn-link:hover { color: var(--color-white); }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    /* ─── Bleed fix: keep the nav inside the viewport on mobile ─────── */
    body { overflow-x: hidden; }
    .main-nav {
        max-width: 100vw;
        /* NOTE: intentionally NOT setting overflow-x:hidden here.
           The dropdown panel (.nav-collapse) is position:absolute and lives
           outside .main-nav's box; clipping here would hide it. The body-level
           overflow-x:hidden above is enough to stop horizontal bleed. */
    }
    .nav-container {
        max-width: 100%;
        padding: 0 8px;
        gap: 0.25rem;
        flex-wrap: nowrap;
        position: relative; /* anchor for .nav-collapse dropdown */
    }

    /* ─── Hamburger menu ─── show only on mobile */
    .nav-hamburger {
        display: flex;
        flex-direction: column;
        justify-content: space-around;
        width: 36px;
        height: 32px;
        padding: 6px 4px;
        margin-left: auto;
        background: transparent;
        border: 1px solid rgba(255,255,255,0.25);
        border-radius: 6px;
        cursor: pointer;
        flex-shrink: 0;
    }
    .nav-hamburger:hover,
    .nav-hamburger[aria-expanded="true"] {
        background: rgba(255,255,255,0.10);
        border-color: rgba(255,255,255,0.4);
    }
    .nav-hamburger-bar {
        display: block;
        width: 100%;
        height: 2px;
        background: #fff;
        border-radius: 2px;
        transition: transform 0.2s, opacity 0.2s;
    }
    /* Optional: morph to X when open */
    .nav-hamburger[aria-expanded="true"] .nav-hamburger-bar:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }
    .nav-hamburger[aria-expanded="true"] .nav-hamburger-bar:nth-child(2) {
        opacity: 0;
    }
    .nav-hamburger[aria-expanded="true"] .nav-hamburger-bar:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    /* ─── Collapsible area ─── hide by default, reveal when .open */
    .nav-collapse {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
        padding: 12px;
        background: var(--color-darker);
        border-top: 1px solid rgba(255,255,255,0.08);
        box-shadow: var(--shadow-lg);
        z-index: 999;
        max-height: calc(100vh - 64px);
        overflow-y: auto;
    }
    .nav-collapse.open {
        display: flex;
    }
    /* App switcher inside the panel: full-width row of three buttons */
    .nav-collapse .app-switcher {
        display: flex;
        justify-content: stretch;
        gap: 6px;
        padding-bottom: 10px;
        border-bottom: 1px solid rgba(255,255,255,0.10);
    }
    .nav-collapse .app-sw-btn {
        flex: 1;
        min-width: 0;
    }
    /* Right-side links stack vertically at full width */
    .nav-collapse .nav-links-right {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        margin-left: 0;
    }
    .nav-collapse .nav-link {
        display: block;
        padding: 10px 8px;
        font-size: 0.95rem;
        border-bottom: 1px solid rgba(255,255,255,0.06);
    }
    .nav-collapse .nav-link:last-child { border-bottom: none; }
    .nav-collapse .nav-credit-badge {
        align-self: flex-start;
        margin: 8px 0;
    }
    /* Flatten the nested user-menu dropdown: show its items inline */
    .nav-collapse .nav-user-menu { position: static; }
    .nav-collapse .nav-user-btn { display: none; }
    .nav-collapse .nav-dropdown {
        display: block !important;
        position: static;
        background: transparent;
        box-shadow: none;
        min-width: 0;
        border-radius: 0;
        overflow: visible;
        border-top: 1px solid rgba(255,255,255,0.10);
        margin-top: 4px;
        padding-top: 4px;
    }
    .nav-collapse .nav-dropdown a {
        color: var(--color-gray-200);
        padding: 10px 8px;
        font-size: 0.95rem;
    }
    .nav-collapse .nav-dropdown a:hover {
        background: rgba(255,255,255,0.08);
        color: #fff;
    }

    .nav-links-right {
        flex-shrink: 1;
        min-width: 0;
    }

    .nav-links-right {
        gap: var(--space-md);
    }
    
    .nav-link {
        font-size: 0.75rem;
    }

    .profile-grid,
    .collection-cases.open {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        padding: var(--space-md);
        gap: var(--space-sm);
    }

    .landing-title {
        font-size: var(--font-size-2xl);
    }
    
    .page-title {
        font-size: var(--font-size-2xl);
    }
}

@media (max-width: 480px) {
    .profile-grid,
    .collection-cases.open {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .nav-links-right {
        gap: var(--space-sm);
    }
}

/* ============================================================
   APP SWITCHER — persistent cross-app navigation
   ============================================================ */
.app-switcher {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.app-sw-btn {
    display: inline-flex !important;
    flex-direction: column !important;
    align-items: center;
    justify-content: center;
    padding: 0.25rem 0.75rem;
    border-radius: 6px;
    text-decoration: none;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.18);
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    min-width: 62px;
    gap: 0.1rem;
    white-space: nowrap;
}
a.app-sw-btn {
    display: inline-flex !important;
    flex-direction: column !important;
}
a.app-sw-btn:hover {
    background: rgba(255,255,255,0.22);
    border-color: rgba(255,255,255,0.4);
    color: #fff;
    text-decoration: none;
}
.app-sw-btn.app-sw-current {
    background: #1A56A0;
    border-color: transparent;
    color: #fff;
    cursor: default;
    font-weight: 600;
}
.app-sw-btn.app-sw-locked {
    opacity: 0.32;
    cursor: not-allowed;
}
.app-sw-figment {
    display: block !important;
    width: 100%;
    text-align: center;
    font-size: 0.5rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: rgba(255,255,255,0.5) !important;
    text-transform: uppercase;
    line-height: 1;
}
.app-sw-current .app-sw-figment {
    color: rgba(255,255,255,0.65);
}
.app-sw-label {
    display: block !important;
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
    color: inherit;
}
@media (max-width: 640px) {
    .app-sw-figment { display: none; }
    .app-sw-btn { padding: 5px 7px; min-width: unset; }
}
