/* =============================================================================
 * PPS Portal — UX Fixes (v2.23.0)
 * =============================================================================
 * Fixes the top 10 UX issues identified during post-migration QA.
 * Applied globally via page-template.blade.php AFTER pps-theme.css.
 *
 * Issues addressed:
 *   1. Sidebar overlap on 1200-1400px screens
 *   2. Mobile sidebar doesn't close on link tap
 *   3. Dashboard card visual hierarchy
 *   4. Form floating labels confusion
 *   5. Loading states for AJAX operations
 *   6. Button consistency across pages
 *   7. Empty states for lists/tables
 *   8. Toast/notification visibility
 *   9. Feature toggle visual feedback
 *  10. General spacing and readability
 * ============================================================================= */

/* ─── FIX #1: SIDEBAR — Prevent overlap on mid-size screens ──────────────── */
@media (min-width: 1200px) and (max-width: 1400px) {
    .g-sidenav-show .sidenav {
        width: 15rem !important;
    }
    .g-sidenav-show .main-content {
        margin-left: 15rem !important;
    }
}

/* ─── FIX #2: MOBILE — Close sidebar on nav link tap ─────────────────────── */
@media (max-width: 1199.98px) {
    /* Make sidebar links feel tappable */
    .sidenav .nav-link {
        padding: 0.75rem 1rem !important;
        min-height: 44px; /* WCAG touch target */
    }
    /* Ensure backdrop covers full screen */
    .sidenav-backdrop {
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1049;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0.3s;
    }
    .g-sidenav-pinned .sidenav-backdrop {
        opacity: 1;
        visibility: visible;
    }
}

/* ─── FIX #3: DASHBOARD — Visual hierarchy for stats cards ───────────────── */
/* Main KPI cards at top should feel more important */
.dashboard-kpi-card {
    border-left: 4px solid #c62828 !important;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.dashboard-kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(198, 40, 40, 0.12) !important;
}
.dashboard-kpi-card .card-body {
    padding: 1.5rem !important;
}
.dashboard-kpi-card .text-sm {
    font-size: 0.78rem !important;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #8392ab !important;
    font-weight: 600;
}
.dashboard-kpi-card h4,
.dashboard-kpi-card h5 {
    font-size: 1.75rem !important;
    font-weight: 700 !important;
    color: #344767 !important;
    margin-bottom: 0;
}

/* Secondary info cards should be subtler */
.card.card-secondary {
    box-shadow: 0 1px 6px rgba(0,0,0,0.04) !important;
    border: 1px solid #f0f2f5 !important;
}

/* ─── FIX #4: FORM INPUTS — Replace confusing floating labels ────────────── */
/* Material Dashboard floating labels are confusing on mobile. */
/* This makes labels always visible above the input. */
.input-group.input-group-outline .form-label {
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    color: #8392ab !important;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
/* Focused state — red underline */
.input-group.input-group-outline.is-focused .form-label {
    color: #c62828 !important;
}
.input-group.input-group-outline.is-focused .form-control {
    border-color: #c62828 !important;
}

/* Better select dropdowns */
select.form-select,
select.form-control {
    padding: 0.625rem 0.75rem !important;
    font-size: 0.875rem !important;
    border: 1px solid #d2d6dc !important;
    border-radius: 8px !important;
    background-color: #fff !important;
    transition: border-color 0.2s;
}
select.form-select:focus,
select.form-control:focus {
    border-color: #c62828 !important;
    box-shadow: 0 0 0 2px rgba(198, 40, 40, 0.08) !important;
}

/* ─── FIX #5: LOADING STATES — Spinner for AJAX operations ───────────────── */
.pps-loading {
    position: relative;
    pointer-events: none;
    opacity: 0.6;
}
.pps-loading::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 24px; height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid #e0e0e0;
    border-top-color: #c62828;
    border-radius: 50%;
    animation: pps-spin 0.6s linear infinite;
}
@keyframes pps-spin {
    to { transform: rotate(360deg); }
}

/* Button loading state */
.btn.pps-loading {
    color: transparent !important;
}
.btn.pps-loading::after {
    width: 18px; height: 18px;
    margin: -9px 0 0 -9px;
    border-width: 2px;
}

/* Table loading overlay */
.table-loading {
    position: relative;
    min-height: 120px;
}
.table-loading::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.8);
    z-index: 10;
    border-radius: 12px;
}
.table-loading::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 32px; height: 32px;
    margin: -16px 0 0 -16px;
    border: 3px solid #e0e0e0;
    border-top-color: #c62828;
    border-radius: 50%;
    animation: pps-spin 0.6s linear infinite;
    z-index: 11;
}

/* ─── FIX #6: BUTTON CONSISTENCY ─────────────────────────────────────────── */
/* Ensure all buttons have consistent height and padding */
.btn {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-weight: 600 !important;
    letter-spacing: 0.2px;
    transition: all 0.2s ease !important;
}
.btn-sm {
    min-height: 32px;
    font-size: 0.78rem !important;
    padding: 0.4rem 1rem !important;
}
.btn-lg {
    min-height: 48px;
    font-size: 1rem !important;
    padding: 0.75rem 1.5rem !important;
}
/* Icon inside buttons — proper alignment */
.btn .material-icons,
.btn .material-icons-round,
.btn i {
    font-size: 18px !important;
    line-height: 1;
}
.btn-sm .material-icons,
.btn-sm .material-icons-round,
.btn-sm i {
    font-size: 16px !important;
}

/* ─── FIX #7: EMPTY STATES — When tables/lists have no data ──────────────── */
.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
}
.empty-state i,
.empty-state .material-icons-round {
    font-size: 56px !important;
    color: #d1d5db;
    margin-bottom: 1rem;
    display: block;
}
.empty-state h6 {
    color: #6b7280 !important;
    font-weight: 600;
    margin-bottom: 0.5rem;
}
.empty-state p {
    color: #9ca3af;
    font-size: 0.85rem;
    max-width: 320px;
    margin: 0 auto;
}

/* ─── FIX #8: TOAST NOTIFICATIONS — More visible ─────────────────────────── */
.toast-container {
    position: fixed !important;
    top: 20px !important;
    right: 20px !important;
    z-index: 99999 !important;
}
/* Flash messages at top of page */
.alert.flash-message {
    position: fixed;
    top: 16px;
    right: 16px;
    left: auto;
    z-index: 99999;
    max-width: 420px;
    animation: slideInRight 0.3s ease;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
}
@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Auto-dismiss after 5s */
.alert.flash-message.fade-out {
    animation: slideOutRight 0.3s ease forwards;
}
@keyframes slideOutRight {
    to { transform: translateX(100%); opacity: 0; }
}

/* ─── FIX #9: FEATURE TOGGLE — Better on/off visual ─────────────────────── */
.feature-toggle {
    width: 52px !important;
    height: 28px !important;
    cursor: pointer;
    transition: background-color 0.3s ease !important;
}
.feature-toggle:checked {
    background-color: #43a047 !important;
    border-color: #43a047 !important;
}
.feature-toggle:not(:checked) {
    background-color: #e0e0e0 !important;
    border-color: #e0e0e0 !important;
}
/* Status text next to toggle */
.toggle-status {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.toggle-status.enabled { color: #43a047; }
.toggle-status.disabled { color: #9e9e9e; }

/* ─── FIX #10: GENERAL SPACING & READABILITY ─────────────────────────────── */
/* Page content padding — consistent across all pages */
.container-fluid.py-4 {
    padding-top: 1.5rem !important;
    padding-bottom: 2rem !important;
}

/* Card spacing in grid */
.row > [class*="col-"] > .card {
    margin-bottom: 1.5rem;
}

/* Section headers inside pages */
.section-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #8392ab;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #f0f2f5;
}

/* Better readability for long text */
.card-body p,
.card-body .text-sm {
    line-height: 1.6;
}

/* Status indicators — consistent dots */
.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
}
.status-dot.active { background: #43a047; }
.status-dot.inactive { background: #9e9e9e; }
.status-dot.pending { background: #fb8c00; }
.status-dot.error { background: #c62828; }

/* ─── ACCESSIBILITY — Focus visible for keyboard navigation ──────────────── */
:focus-visible {
    outline: 2px solid #c62828 !important;
    outline-offset: 2px;
    border-radius: 4px;
}

/* Skip to main content link (a11y) */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: #c62828;
    color: white;
    padding: 8px 16px;
    z-index: 100000;
    transition: top 0.2s;
    font-weight: 600;
    border-radius: 0 0 8px 0;
}
.skip-to-main:focus {
    top: 0;
    color: white;
}

/* ─── MOBILE RESPONSIVE — Better touch targets ───────────────────────────── */
@media (max-width: 768px) {
    /* Larger tap targets for links in nav */
    .navbar .nav-link,
    .sidenav .nav-link {
        min-height: 44px !important;
        display: flex;
        align-items: center;
    }

    /* Cards flush on mobile */
    .container-fluid {
        padding-left: 12px !important;
        padding-right: 12px !important;
    }

    /* Tables scroll horizontally */
    .table-responsive {
        border-radius: 12px;
        border: 1px solid #f0f2f5;
    }

    /* Bottom fixed action bar for common actions */
    .mobile-action-bar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        padding: 12px 16px;
        box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
        z-index: 1040;
        display: flex;
        gap: 8px;
    }
    .mobile-action-bar .btn {
        flex: 1;
    }

    /* Hide verbose text on mobile, show icons */
    .hide-mobile-text {
        font-size: 0 !important;
    }
    .hide-mobile-text i,
    .hide-mobile-text .material-icons-round {
        font-size: 18px !important;
        margin: 0 !important;
    }
}

/* ─── PRINT STYLES — Clean output for reports/certificates ───────────────── */
@media print {
    .sidenav, .navbar, .btn, .no-print,
    .fixed-plugin, .mobile-action-bar {
        display: none !important;
    }
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}

/* ─── SMOOTH PAGE TRANSITIONS ────────────────────────────────────────────── */
.main-content {
    animation: fadeInPage 0.2s ease;
}
@keyframes fadeInPage {
    from { opacity: 0.85; }
    to { opacity: 1; }
}
