/**
 * Custom CSS for FFC HR Performance Module
 * UI Polish, Responsive Fixes, Loading States, Accessibility
 * 
 * @copyright 2026 FFC - FirstFintech Corporation Pvt. Ltd.
 * @license   proprietary
 */

/* ============================================
   RESPONSIVE LAYOUT FIXES
   ============================================ */

/* Mobile-first responsive breakpoints */
@media (max-width: 575.98px) {
    /* Fix DataTable overflow on mobile */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Hide non-critical columns on small screens */
    .hide-on-mobile {
        display: none !important;
    }
    
    /* Stack cards on mobile */
    .card-columns {
        column-count: 1 !important;
    }
    
    /* Adjust padding on mobile */
    .app-content {
        padding: 15px !important;
    }
    
    /* Fix breadcrumb on mobile */
    .breadcrumb {
        flex-wrap: wrap;
    }
    
    /* Adjust form elements on mobile */
    .form-label {
        font-size: 0.875rem;
    }
    
    .form-control, .form-select {
        font-size: 0.875rem;
    }
    
    .btn {
        font-size: 0.875rem;
        padding: 0.25rem 0.5rem;
    }
}

/* Tablet landscape */
@media (min-width: 768px) and (max-width: 991.98px) {
    .app-sidebar {
        width: 200px;
    }
    
    .app-main {
        margin-left: 200px;
    }
}

/* Small desktop */
@media (min-width: 1280px) and (max-width: 1439.98px) {
    .app-sidebar {
        width: 250px;
    }
    
    .app-main {
        margin-left: 250px;
    }
}

/* Large desktop */
@media (min-width: 1440px) {
    .app-sidebar {
        width: 280px;
    }
    
    .app-main {
        margin-left: 280px;
    }
}

/* ============================================
   LOADING STATES - SKELETON LOADERS
   ============================================ */

/* Skeleton Loader Base */
.skeleton-loader {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s infinite;
    border-radius: 4px;
    position: relative;
    overflow: hidden;
}

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

/* Skeleton variations */
.skeleton-text {
    height: 1rem;
    width: 100%;
    margin-bottom: 0.75rem;
}

.skeleton-text.small {
    height: 0.75rem;
}

.skeleton-text.medium {
    height: 1.25rem;
}

.skeleton-text.large {
    height: 1.75rem;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: inline-block;
}

.skeleton-icon {
    width: 24px;
    height: 24px;
    display: inline-block;
}

.skeleton-bar {
    height: 20px;
    border-radius: 4px;
}

.skeleton-circle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: inline-block;
}

/* Chart Loading Spinner */
.chart-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.8);
    z-index: 10;
    border-radius: 10px;
}

.chart-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Table Loading States */
.table-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
}

/* ============================================
   AUTO-SAVE STATE INDICATORS
   ============================================ */

/* Auto-save spinner */
.auto-save-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 0.8s linear infinite;
    margin-left: 8px;
    vertical-align: middle;
}

/* Auto-save status container */
.auto-save-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    color: #6c757d;
}

/* Unsaved changes badge */
.unsaved-changes-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.125rem 0.375rem;
    background-color: #ffc107;
    color: #333;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    vertical-align: middle;
    margin-left: 8px;
}

/* Saving state */
.auto-save-saving {
    color: #667eea;
}

/* Saved state */
.auto-save-saved {
    color: #28a745;
}

/* Error state */
.auto-save-error {
    color: #dc3545;
}

/* ============================================
   FLASH MESSAGE STYLES
   ============================================ */

.flash-messages-container {
    position: fixed;
    top: 70px;
    right: 20px;
    z-index: 1000;
    max-width: 400px;
    width: 100%;
    pointer-events: none;
}

.flash-message {
    margin-bottom: 10px;
    pointer-events: auto;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-left: 4px solid transparent;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.flash-message.dismiss {
    animation: slideOut 0.3s ease-out forwards;
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

.flash-message.alert-success {
    border-left-color: #198754;
    background: #d4edda;
}

.flash-message.alert-danger {
    border-left-color: #dc3545;
    background: #f8d7da;
}

.flash-message.alert-warning {
    border-left-color: #ffc107;
    background: #fff3cd;
}

.flash-message.alert-info {
    border-left-color: #0dcaf0;
    background: #cff4fc;
}

.flash-message-content {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
}

.flash-message-icon {
    flex-shrink: 0;
    font-size: 20px;
    margin-top: 2px;
}

.flash-message-body {
    flex: 1;
}

.flash-message-title {
    font-weight: 600;
    margin-bottom: 4px;
    display: block;
}

.flash-message-text {
    font-size: 0.9rem;
    color: #212529;
}

.flash-message-close {
    flex-shrink: 0;
    padding: 4px 8px;
    margin: -4px -8px -4px auto;
    background: transparent;
    border: none;
    color: inherit;
    font-size: 18px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
}

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

/* ============================================
   FORM VALIDATION STYLES (Bootstrap 5)
   ============================================ */

/* Validated form styling */
.form-control.is-valid, .form-select.is-valid {
    border-color: #198754;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.form-control.is-invalid, .form-select.is-invalid {
    border-color: #dc3545;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* Inline validation feedback */
.invalid-feedback, .valid-feedback {
    display: block;
    font-size: 0.875rem;
    margin-top: 0.25rem;
}

.invalid-feedback {
    color: #dc3545;
}

.valid-feedback {
    color: #198754;
}

/* ============================================
   ACCESSIBILITY ENHANCEMENTS
   ============================================ */

/* Skip to main content link */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: #667eea;
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.3s;
    text-decoration: none;
    font-weight: 600;
}

.skip-link:focus {
    top: 0;
}

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

/* Focus styles for accessibility */
*:focus-visible {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .form-control, .form-select {
        border-width: 2px;
    }
    
    .btn {
        font-weight: 600;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .auto-save-spinner,
    .chart-loading-spinner,
    .skeleton-loader,
    .flash-message,
    .flash-message.dismiss {
        animation: none;
    }
    
    * {
        transition: none !important;
    }
}

/* ============================================
   BADGE TEXT ALTERNATIVES (Color + Icon)
   ============================================ */

/* Ensure badges have text alternatives */
.badge-success::before {
    content: "[Success] ";
}

.badge-danger::before {
    content: "[Error] ";
}

.badge-warning::before {
    content: "[Warning] ";
}

.badge-info::before {
    content: "[Info] ";
}

/* ============================================
   DATATABLES RESPONSIVE FIXES
   ============================================ */

/* DataTable horizontal scroll on mobile */
.dataTables_wrapper {
    overflow-x: auto;
}

/* Hide columns below 576px for responsive tables */
@media (max-width: 575.98px) {
    .dataTables_wrapper .dtr-inline.collapsed {
        display: none;
    }
}

/* DataTable row details for collapsed view */
.dtr-data {
    font-weight: 600;
}

.dtr-title {
    font-weight: 400;
    color: #6c757d;
}

/* ============================================
   MODAL RESPONSIVE FIXES
   ============================================ */

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
    }
    
    .modal-content {
        border-radius: 0;
    }
}

/* ============================================
   UTILITIES
   ============================================ */

/* Text ellipsis for long content */
.text-ellipsis {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Hover effects */
.hover-effect:hover {
    transform: translateY(-2px);
    transition: transform 0.2s ease;
}

/* Loading spinner icon */
.spinner-icon {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(102, 126, 234, 0.3);
    border-radius: 50%;
    border-top-color: #667eea;
    animation: spin 0.8s linear infinite;
}

/* Icon buttons */
.btn-icon-only {
    padding: 0.375rem 0.75rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-only i {
    margin: 0;
}

/* ============================================
   DARK MODE SUPPORT
   ============================================ */

[data-bs-theme="dark"] {
    /* Flash messages */
    .flash-message.alert-success {
        background: #1e3d2d;
        border-left-color: #28a745;
    }
    
    .flash-message.alert-danger {
        background: #4a2020;
        border-left-color: #dc3545;
    }
    
    .flash-message.alert-warning {
        background: #4a421a;
        border-left-color: #ffc107;
    }
    
    .flash-message.alert-info {
        background: #1a3d4a;
        border-left-color: #0dcaf0;
    }
    
    /* Skeleton loader */
    .skeleton-loader {
        background: linear-gradient(90deg, #3a3a3a 25%, #4a4a4a 50%, #3a3a3a 75%);
        background-size: 200% 100%;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .app-sidebar,
    .pc-header,
    .no-print {
        display: none !important;
    }
    
    .app-main {
        margin-left: 0;
    }
    
    .card {
        break-inside: avoid;
    }
}