/* Comprehensive Responsive Styles for HR Management System */

/* Base Responsive Rules - Apply to all screen sizes */
* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    overflow-x: hidden;
}

body {
    overflow-x: hidden;
    width: 100%;
    position: relative;
    margin: 0;
    padding: 0;
}

/* Specific overrides for public pages without sidebar */
body.apply-leave-page,
body.welcome-page,
body.login-page {
    margin-left: 0 !important;
    width: 100% !important;
}

/* Ensure containers are centered on public pages */
body.apply-leave-page .container,
body.welcome-page .welcome-card,
body.login-page .login-card {
    margin-left: auto;
    margin-right: auto;
}

/* Ensure proper width calculation - Base */
.main-content {
    box-sizing: border-box;
    overflow-x: hidden;
    position: relative;
}

/* Prevent horizontal overflow */
.container,
.container-fluid,
.row {
    max-width: 100%;
    box-sizing: border-box;
}

/* Ensure tables don't break layout */
.table-responsive {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Prevent cards from overflowing */
.card {
    max-width: 100%;
    box-sizing: border-box;
}

/* Ensure all content fits */
.col,
[class*="col-"] {
    max-width: 100%;
    box-sizing: border-box;
}

/* Fix for wide content */
.w-100 {
    max-width: 100%;
}

/* Extra Small Devices (phones, 576px and down) */
@media (max-width: 575.98px) {
    body {
        margin-left: 0 !important;
        font-size: 14px;
    }
    
    .main-content {
        padding: 15px !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin-left: 0 !important;
    }
    
    .stat-card h2 {
        font-size: 1.8rem !important;
    }
    
    .stat-card .card-body {
        padding: 15px !important;
    }
    
    .card-header {
        padding: 15px !important;
        font-size: 0.95rem !important;
    }
    
    .table {
        font-size: 0.85rem;
    }
    
    .table thead th {
        padding: 10px 8px !important;
        font-size: 0.75rem;
    }
    
    .table tbody td {
        padding: 10px 8px !important;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 0.875rem;
        min-height: 44px;
    }
    
    .quick-action-btn {
        min-height: 100px !important;
        padding: 15px !important;
    }
    
    .quick-action-btn i {
        font-size: 2rem !important;
    }
    
    .dropdown-menu {
        min-width: 200px !important;
        max-width: calc(100vw - 20px);
    }
    
    #accountDropdown {
        padding: 6px 12px !important;
        font-size: 0.8rem;
    }
    
    .position-fixed.top-0.end-0 {
        margin-right: 10px !important;
        margin-top: 10px !important;
    }
    
    .progress {
        width: 80px !important;
        height: 18px !important;
    }
    
    canvas {
        max-height: 200px !important;
    }
    
    h1 { font-size: 1.75rem !important; }
    h2 { font-size: 1.5rem !important; }
    h3 { font-size: 1.25rem !important; }
    h4 { font-size: 1.1rem !important; }
    h5 { font-size: 1rem !important; }
    h6 { font-size: 0.9rem !important; }
    
    .badge {
        font-size: 0.7rem;
        padding: 4px 8px;
    }
    
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }
    
    .modal-content {
        border-radius: 10px;
    }
    
    .modal-header,
    .modal-body,
    .modal-footer {
        padding: 15px !important;
    }
    
    .form-card,
    .welcome-card {
        margin: 10px !important;
        padding: 20px !important;
        max-width: calc(100% - 20px) !important;
    }
    
    .form-header i {
        font-size: 2rem !important;
    }
    
    .form-header h2 {
        font-size: 1.5rem !important;
    }
    
    .card-header h6 {
        font-size: 0.9rem !important;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    .btn {
        width: 100% !important;
    }
    
    .d-grid {
        gap: 0.75rem !important;
    }
    
    .welcome-section h3 {
        font-size: 1.5rem !important;
    }
    
    .welcome-section i {
        font-size: 2.5rem !important;
    }
}

/* Small Devices (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) {
    body {
        margin-left: 0 !important;
    }
    
    .main-content {
        padding: 20px !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin-left: 0 !important;
    }
    
    .stat-card h2 {
        font-size: 2rem !important;
    }
    
    .table {
        font-size: 0.9rem;
    }
    
    .quick-action-btn {
        min-height: 120px !important;
    }
    
    .form-card,
    .welcome-card {
        margin: 15px !important;
        padding: 25px !important;
        max-width: calc(100% - 30px) !important;
    }
    
    .card-header h6 {
        font-size: 0.95rem !important;
    }
    
    .btn {
        width: auto !important;
    }
}

/* Medium Devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991.98px) {
    body {
        margin-left: 0 !important;
    }
    
    .main-content {
        padding: 25px !important;
        width: 100% !important;
        max-width: 100vw !important;
        margin-left: 0 !important;
    }
    
    .stat-card h2 {
        font-size: 2.2rem;
    }
    
    .col-md-6 {
        margin-bottom: 20px;
    }
}

/* Large Devices (desktops, 992px and up) */
@media (min-width: 992px) and (max-width: 1199.98px) {
    body {
        margin-left: 250px !important;
    }
    
    .main-content {
        padding: 30px !important;
        width: calc(100% - 250px) !important;
        max-width: calc(100vw - 250px) !important;
        margin-left: 0 !important;
    }
    
    body.sidebar-collapsed .main-content {
        width: calc(100% - 70px) !important;
        max-width: calc(100vw - 70px) !important;
    }
}

/* Extra Large Devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    body {
        margin-left: 250px !important;
    }
    
    .main-content {
        padding: 30px !important;
        width: calc(100% - 250px) !important;
        max-width: calc(100vw - 250px) !important;
        margin-left: 0 !important;
    }
    
    body.sidebar-collapsed .main-content {
        width: calc(100% - 70px) !important;
        max-width: calc(100vw - 70px) !important;
    }
}

/* Sidebar Responsive - Critical for mobile */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%) !important;
        z-index: 1040;
        transition: transform 0.3s ease;
    }
    
    .sidebar.show {
        transform: translateX(0) !important;
    }
    
    .sidebar.collapsed {
        width: 250px !important;
    }
    
    #sidebarCollapse {
        display: none !important;
    }
    
    body {
        margin-left: 0 !important;
    }
    
    /* Sidebar overlay */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1039;
        animation: fadeIn 0.3s ease;
    }
    
    .sidebar.show ~ .sidebar-overlay,
    body.sidebar-open .sidebar-overlay {
        display: block;
    }
}

/* Desktop Sidebar */
@media (min-width: 992px) {
    .sidebar {
        transform: translateX(0) !important;
    }
    
    .sidebar-overlay {
        display: none !important;
    }
}

/* Table Responsive Improvements */
@media (max-width: 767.98px) {
    .table-responsive {
        border-radius: 8px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        -ms-overflow-style: -ms-autohiding-scrollbar;
    }
    
    .table {
        min-width: 600px;
        margin-bottom: 0;
    }
    
    .table thead th {
        white-space: nowrap;
    }
    
    .table tbody td {
        white-space: nowrap;
    }
}

/* Form Responsive */
@media (max-width: 767.98px) {
    .form-control,
    .form-select {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }
    
    .file-upload-area {
        padding: 30px 15px !important;
    }
    
    .input-group {
        flex-wrap: wrap;
    }
    
    .input-group > .form-control,
    .input-group > .form-select {
        width: 100% !important;
        margin-bottom: 10px;
    }
}

/* Card Responsive */
@media (max-width: 767.98px) {
    .card {
        margin-bottom: 15px;
    }
    
    .card-body {
        padding: 15px !important;
    }
    
    .row.g-4 {
        --bs-gutter-y: 1rem;
    }
    
    .row.g-3 {
        --bs-gutter-y: 0.75rem;
    }
}

/* Chart Responsive */
@media (max-width: 991.98px) {
    canvas {
        max-height: 250px !important;
    }
}

/* Button Groups Responsive */
@media (max-width: 575.98px) {
    .btn-group,
    .btn-group-vertical {
        display: flex;
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn,
    .btn-group-vertical .btn {
        width: 100%;
        margin-bottom: 5px;
        border-radius: 5px !important;
    }
}

/* Navigation Responsive */
@media (max-width: 991.98px) {
    .sidebar {
        box-shadow: 2px 0 10px rgba(0,0,0,0.3);
    }
    
    .sidebar .nav-link {
        padding: 15px;
    }
}

/* Account Dropdown Responsive */
@media (max-width: 575.98px) {
    .position-fixed.top-0.end-0 {
        margin-right: 10px !important;
        margin-top: 10px !important;
    }
    
    .dropdown-menu {
        right: 10px !important;
        left: auto !important;
        max-width: calc(100vw - 20px);
        margin-top: 5px !important;
    }
}

@media (min-width: 576px) and (max-width: 767.98px) {
    .position-fixed.top-0.end-0 {
        margin-right: 15px !important;
    }
}

/* Progress Bar Responsive */
@media (max-width: 767.98px) {
    .progress {
        height: 20px !important;
    }
    
    .progress-bar {
        font-size: 0.75rem;
    }
}

/* Grid Improvements */
@media (max-width: 991.98px) {
    .row.g-4 > * {
        margin-bottom: 1rem;
    }
}

/* Spacing Responsive */
@media (max-width: 767.98px) {
    .mb-4 { margin-bottom: 1.5rem !important; }
    .mb-3 { margin-bottom: 1rem !important; }
    .p-4 { padding: 1.5rem !important; }
    .p-3 { padding: 1rem !important; }
    .px-4 { padding-left: 1rem !important; padding-right: 1rem !important; }
    .py-4 { padding-top: 1rem !important; padding-bottom: 1rem !important; }
}

/* Text Alignment Responsive */
@media (max-width: 767.98px) {
    .text-md-start {
        text-align: center !important;
    }
    
    .text-md-end {
        text-align: center !important;
    }
    
    .d-md-flex {
        display: flex !important;
    }
}

/* Flexbox Responsive */
@media (max-width: 575.98px) {
    .flex-wrap {
        flex-direction: column;
    }
    
    .gap-2 > * {
        margin-bottom: 0.5rem;
    }
}

/* Print Styles */
@media print {
    .sidebar,
    #accountDropdown,
    #sidebarToggle,
    .btn,
    .dropdown,
    .sidebar-overlay {
        display: none !important;
    }
    
    body {
        margin-left: 0 !important;
    }
    
    .main-content {
        padding: 0 !important;
        width: 100% !important;
    }
    
    .card {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}

/* Landscape Orientation */
@media (orientation: landscape) and (max-height: 500px) {
    .main-content {
        padding: 15px !important;
    }
    
    .stat-card h2 {
        font-size: 1.8rem !important;
    }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .nav-link,
    .dropdown-item {
        min-height: 44px;
        min-width: 44px;
    }
    
    .stat-card:hover {
        transform: none;
    }
    
    .card:hover {
        transform: none;
    }
    
    .table tbody tr:hover {
        transform: none;
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Utility Classes */
.mobile-full-width {
    width: 100% !important;
}

@media (max-width: 767.98px) {
    .mobile-full-width {
        width: 100% !important;
    }
    
    .mobile-hide {
        display: none !important;
    }
    
    .mobile-center {
        text-align: center !important;
    }
    
    .mobile-stack {
        flex-direction: column !important;
    }
}

/* Fix for overflow issues */
.container-fluid {
    padding-left: 15px;
    padding-right: 15px;
}

@media (max-width: 575.98px) {
    .container-fluid {
        padding-left: 10px;
        padding-right: 10px;
    }
}

/* Critical: Prevent all horizontal overflow */
html, body {
    max-width: 100vw;
    overflow-x: hidden;
}

/* Ensure all elements respect container bounds */
* {
    max-width: 100%;
}

img, video, iframe {
    max-width: 100%;
    height: auto;
}

/* Fix for tables in cards */
.card .table-responsive {
    margin: 0 -1rem;
    padding: 0 1rem;
}

@media (max-width: 767.98px) {
    .card .table-responsive {
        margin: 0 -0.75rem;
        padding: 0 0.75rem;
    }
}
