/**
 * UX Polish - P10 Enhancements
 * WCAG AA compliance, icon normalization, mobile polish
 */

/* === WCAG AA CONTRAST FIXES === */

/* Fix primary button contrast: darken to meet 4.5:1 with white text */
.btn-primary {
    background: #1d4ed8 !important; /* Darker blue for 4.5:1+ contrast */
    color: #ffffff !important;
}

.btn-primary:hover {
    background: #1e40af !important; /* Even darker on hover */
    color: #ffffff !important;
}

/* Ensure all text meets 4.5:1 minimum contrast */
body, p, div, span, li, td, th, label {
    color: var(--text, #e7eaf0) !important;
}

/* Headings should have 3:1 contrast minimum (we exceed with 11.5:1) */
h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6,
.card-title, .modal-title {
    color: var(--text, #e7eaf0) !important;
}

/* Fix any dark-on-dark issues in badges */
.badge.bg-dark, .badge.bg-secondary {
    background: #374151 !important;
    color: #e7eaf0 !important;
}

/* Ensure button text is always readable */
.btn-dark {
    background: #1f2937 !important;
    color: #e7eaf0 !important;
    border-color: #374151 !important;
}

.btn-dark:hover {
    background: #111827 !important;
    color: #e7eaf0 !important;
}

/* Fix card header contrast on primary backgrounds */
.card-header.bg-primary,
.card-header.text-white {
    background: var(--primary) !important;
    color: #ffffff !important;
}

.card-header.bg-primary *,
.card-header.text-white * {
    color: #ffffff !important;
}

/* Ensure alert text is readable */
.alert {
    color: var(--text) !important;
}

.alert * {
    color: inherit !important;
}

/* Fix light backgrounds with proper contrast */
.bg-light, .alert-light {
    background: rgba(255, 255, 255, 0.95) !important;
    color: #0b1020 !important;
}

.bg-light *, .alert-light * {
    color: #0b1020 !important;
}

.bg-light .text-muted,
.alert-light .text-muted {
    color: #5b6577 !important;
}

/* === ICON NORMALIZATION === */

/* Standardize all icon sizes and alignment */
.bi, i.icon, i[class*="bi-"] {
    vertical-align: middle;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Consistent icon sizing across components */
.navbar .bi, .navbar i[class*="bi-"] {
    font-size: 1.125rem;
    width: 18px;
    height: 18px;
}

.dropdown-item .bi, .dropdown-item i[class*="bi-"] {
    font-size: 1rem;
    width: 16px;
    height: 16px;
    text-align: center;
}

.btn .bi, .btn i[class*="bi-"] {
    vertical-align: middle;
    margin-right: 0.25rem;
}

.btn:only-child .bi,
.btn i:only-child {
    margin-right: 0;
}

.card-title .bi, .card-title i[class*="bi-"] {
    font-size: 1.25rem;
    margin-right: 0.5rem;
}

/* Badge icons */
.badge .bi, .badge i[class*="bi-"] {
    font-size: 0.875rem;
    margin-right: 0.25rem;
}

/* List group icons */
.list-group-item .bi, .list-group-item i[class*="bi-"] {
    font-size: 1.125rem;
    margin-right: 0.75rem;
    opacity: 0.8;
}

/* Alert icons */
.alert .bi, .alert i[class*="bi-"] {
    font-size: 1.25rem;
    margin-right: 0.5rem;
}

/* === MOBILE POLISH === */

/* Sticky CTAs for mobile */
.sticky-cta {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--card);
    border-top: 2px solid var(--border);
    padding: 1rem;
    z-index: 1040;
    box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.3);
    transform: translateY(0);
    transition: transform 0.3s ease;
}

.sticky-cta.hidden {
    transform: translateY(100%);
}

.sticky-cta-mobile {
    display: none;
}

@media (max-width: 768px) {
    .sticky-cta-mobile {
        display: block;
    }
    
    .sticky-cta-desktop {
        display: none !important;
    }
    
    /* Add bottom padding to content to prevent overlap */
    .mobile-spacing {
        padding-bottom: 5rem;
    }
    
    .mobile-spacing-nav {
        padding-bottom: 7rem;
    }
}

/* Mobile touch targets (min 44x44px for accessibility) */
.touch-target {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.touch-friendly {
    padding: 0.75rem 1rem;
    font-size: 1rem;
    min-height: 44px;
}

/* Mobile-optimized buttons */
@media (max-width: 768px) {
    .btn {
        padding: 0.75rem 1.25rem;
        font-size: 1rem;
        min-height: 44px;
    }
    
    .btn-lg {
        padding: 1rem 1.5rem;
        font-size: 1.125rem;
        min-height: 52px;
    }
    
    .btn-sm {
        padding: 0.625rem 1rem;
        font-size: 0.875rem;
        min-height: 44px; /* Increased from 36px to meet accessibility standards */
    }
    
    /* Full-width buttons on mobile */
    .btn-block-mobile {
        width: 100%;
        display: block;
    }
}

/* === READABILITY IMPROVEMENTS === */

/* Ensure proper line height for readability */
p, .body, .body-lg {
    line-height: 1.7;
    margin-bottom: 1rem;
}

/* Improve link contrast */
a:not(.btn):not(.nav-link):not(.dropdown-item) {
    color: var(--primary);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}

a:not(.btn):not(.nav-link):not(.dropdown-item):hover {
    color: var(--primary-600);
    text-decoration-thickness: 2px;
}

/* Ensure form labels are readable */
.form-label {
    color: var(--text) !important;
    font-weight: 500;
    font-size: 0.9375rem;
    margin-bottom: 0.5rem;
}

/* Improve placeholder contrast */
.form-control::placeholder,
.form-select::placeholder {
    color: var(--muted) !important;
    opacity: 0.7;
}

/* === CONSISTENT SPACING === */

/* Card spacing consistency */
.card {
    margin-bottom: 1.5rem;
}

.card-body {
    padding: 1.5rem;
}

.card-header {
    padding: 1rem 1.5rem;
}

.card-footer {
    padding: 1rem 1.5rem;
}

/* Section spacing */
.section {
    padding: 3rem 0;
}

.section-sm {
    padding: 2rem 0;
}

.section-lg {
    padding: 4rem 0;
}

@media (max-width: 768px) {
    .section {
        padding: 2rem 0;
    }
    
    .section-lg {
        padding: 3rem 0;
    }
}

/* === FOCUS STATES (Accessibility) === */

/* Visible focus indicators for keyboard navigation */
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible,
.nav-link:focus-visible,
a:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

/* === LOADING STATES === */

/* Skeleton loading improvements */
.skeleton {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.05) 25%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: var(--radius);
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* === MOBILE NAVIGATION === */

/* Bottom navigation bar for mobile */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: none;
    justify-content: space-around;
    padding: 0.75rem 0;
    z-index: 1030;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.2);
}

@media (max-width: 768px) {
    .bottom-nav {
        display: flex;
    }
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    padding: 0.5rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
    min-width: 60px;
    min-height: 44px;
}

.bottom-nav-item:hover,
.bottom-nav-item.active {
    color: var(--primary);
    text-decoration: none;
}

.bottom-nav-item i {
    font-size: 1.5rem;
}

.bottom-nav-item span {
    font-size: 0.625rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* === FAB BUTTON === */

/* Floating Action Button for mobile */
.fab-button {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    z-index: 1020;
    transition: all 0.2s;
    cursor: pointer;
}

.fab-button:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(59, 130, 246, 0.5);
}

.fab-button:active {
    transform: scale(0.95);
}

@media (max-width: 768px) {
    .fab-button {
        bottom: 5rem;
    }
}

/* === RESPONSIVE TABLES === */

@media (max-width: 768px) {
    .table-responsive {
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }
    
    .table thead {
        display: none;
    }
    
    .table tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--border);
        border-radius: var(--radius);
    }
    
    .table tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.75rem 1rem;
        border: none;
        border-bottom: 1px solid var(--border);
    }
    
    .table tbody td:last-child {
        border-bottom: none;
    }
    
    .table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        margin-right: 1rem;
    }
}

/* === ACCESSIBILITY IMPROVEMENTS === */

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    left: -9999px;
    z-index: 9999;
    padding: 1rem;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
}

.skip-to-main:focus {
    left: 0;
    top: 0;
}

/* === SMOOTH SCROLLING === */

html {
    scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
    html {
        scroll-behavior: auto;
    }
    
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* === UTILITY CLASSES === */

/* Text utilities with proper contrast */
.text-contrast-high {
    color: var(--text) !important;
}

.text-contrast-medium {
    color: var(--muted) !important;
}

/* Spacing utilities */
.gap-xs { gap: 0.25rem; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.gap-lg { gap: 1.5rem; }
.gap-xl { gap: 2rem; }

/* Flex utilities */
.flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.flex-start {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.flex-end {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}
