/* ============================================
   COMPREHENSIVE RESPONSIVE STYLES
   Mobile, Tablet, and Desktop Support
   ============================================ */

/* ============================================
   GLOBAL RESPONSIVE BASE
   ============================================ */

html {
    font-size: 14px;
    position: relative;
    min-height: 100%;
}

@media (min-width: 768px) {
    html {
        font-size: 16px;
    }
}

/* ============================================
   SIDEBAR RESPONSIVE
   ============================================ */

.app-sidebar {
    width: 250px;
    background: #0d1224;
    color: #fff;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 0;
    justify-content: flex-start;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

/* Mobile: Hide sidebar by default, show as overlay */
@media (max-width: 991.98px) {
    .app-shell {
        position: relative;
    }
    
    .app-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1050;
        transform: translateX(-100%);
        width: 280px;
        max-width: 85vw;
        transition: transform 0.3s ease;
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .app-sidebar.show {
        transform: translateX(0);
    }
    
    /* Sidebar overlay */
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1049;
        display: none;
        transition: opacity 0.3s ease;
    }
    
    .sidebar-overlay.show {
        display: block;
        opacity: 1;
    }
    
    /* Mobile menu button */
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        top: 16px;
        left: 16px;
        z-index: 1051;
        background: #0d1224;
        color: #fff;
        border: none;
        padding: 10px 14px;
        border-radius: 6px;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
        transition: all 0.2s ease;
    }
    
    .language-selector-top {
        position: fixed;
        top: 16px;
        right: 16px;
        z-index: 1050;
    }
    
    .mobile-menu-btn:hover {
        background: #1a2332;
        transform: scale(1.05);
    }
    
    .mobile-menu-btn:active {
        transform: scale(0.95);
    }
    
    .mobile-menu-btn svg {
        width: 20px;
        height: 20px;
    }
}

/* Very small screens - adjust sidebar width */
@media (max-width: 640px) {
    .app-sidebar {
        width: 260px;
        max-width: 80vw;
        padding: 20px 12px;
    }
    
    .sidebar-brand {
        font-size: 18px;
        word-wrap: break-word;
    }
    
    .sidebar-link {
        padding: 8px 10px;
        font-size: 13px;
        word-wrap: break-word;
        overflow-wrap: break-word;
        white-space: normal;
    }
    
    .sidebar-label {
        font-size: 11px;
    }
    
    .sidebar-profile {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .sidebar-avatar {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }
    
    .sidebar-name {
        font-size: 13px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .sidebar-role {
        font-size: 11px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
    
    .sidebar-footer {
        padding-top: 16px;
    }
    
    .btn-sm {
        font-size: 12px;
        padding: 6px 12px;
    }
}

@media (min-width: 992px) {
    .mobile-menu-btn {
        display: none;
    }
}

/* Tablet adjustments */
@media (min-width: 768px) and (max-width: 991.98px) {
    .app-sidebar {
        width: 240px;
        padding: 20px 14px;
    }
}

/* Desktop adjustments */
@media (min-width: 992px) {
    .app-sidebar {
        width: 250px;
        position: relative;
        transform: none;
    }
    
    .app-content {
        margin-left: 0;
    }
    
    .sidebar-overlay {
        display: none !important;
    }
    
    .mobile-menu-btn {
        display: none !important;
    }
}

/* ============================================
   MAIN CONTENT AREA RESPONSIVE
   ============================================ */

.app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 32px;
    transition: margin-left 0.3s ease;
    min-width: 0;
    width: 100%;
    position: relative;
}

/* Language selector in top-right */
.language-selector-top {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 100;
}

.language-selector-top .btn-group {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border-radius: 6px;
    overflow: hidden;
}

.language-selector-top .btn {
    border: none;
    padding: 8px 16px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.language-selector-top .btn-primary {
    background-color: #4285f4;
    color: #fff;
}

.language-selector-top .btn-outline-primary {
    background-color: #fff;
    color: #4285f4;
    border: 1px solid #4285f4;
}

.language-selector-top .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

@media (max-width: 991.98px) {
    .app-content {
        padding: 16px;
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        flex: 1 1 100%;
    }
    
    .app-shell {
        flex-direction: row;
        position: relative;
    }
    
    .app-main {
        width: 100%;
        max-width: 100%;
    }
    
    .language-selector-top {
        top: 12px;
        right: 12px;
    }
    
    .language-selector-top .btn {
        padding: 6px 12px;
        font-size: 0.875rem;
    }
}

@media (min-width: 768px) and (max-width: 991.98px) {
    .app-content {
        padding: 24px;
    }
    
    .language-selector-top {
        top: 20px;
        right: 20px;
    }
}

.app-main {
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 30px rgba(15, 23, 42, 0.08);
}

@media (max-width: 767.98px) {
    .app-main {
        padding: 16px;
        border-radius: 12px;
    }
}

/* ============================================
   HEADER RESPONSIVE
   ============================================ */

.main-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

@media (max-width: 575.98px) {
    .main-header {
        flex-direction: column;
        align-items: stretch;
    }
    
    .header-actions {
        width: 100%;
        justify-content: space-between;
    }
}

/* ============================================
   TABLES RESPONSIVE
   ============================================ */

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.table {
    width: 100%;
    margin-bottom: 0;
}

/* Table styling */
.card.shadow-sm {
    box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.15) !important;
    border: none;
    border-radius: 0.5rem;
}

.table thead th {
    background-color: #B8CCE4 !important;
    border: none;
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.table tbody tr {
    transition: background-color 0.15s ease-in-out;
}

.table tbody tr:hover {
    background-color: #f8f9fa !important;
}

.table td {
    border-color: #dee2e6;
    vertical-align: middle;
}

/* Employee table specific */
.table-responsive[style*="overflow-x"] {
    overflow-x: auto !important;
}

.table[style*="min-width"] {
    min-width: 1200px;
}

/* Mobile table adjustments */
@media (max-width: 767.98px) {
    .table {
        font-size: 0.8rem;
    }
    
    .table thead th {
        font-size: 0.75rem;
        padding: 0.5rem 0.75rem !important;
    }
    
    .table td {
        padding: 0.5rem 0.75rem !important;
    }
    
    .table[style*="min-width"] {
        min-width: 800px;
    }
}

/* Table column widths */
.table th.px-3,
.table td.px-3 {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

.table th.px-4,
.table td.px-4 {
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Action column */
.table td:last-child {
    white-space: nowrap;
}

.table td[style*="text-overflow"] {
    cursor: help;
}

/* Info column with ellipsis */
.table td[style*="max-width"] {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================
   BUTTONS RESPONSIVE
   ============================================ */

.btn-group {
    display: inline-flex;
    vertical-align: middle;
}

.btn-group .btn {
    margin-right: 0.25rem;
    border-radius: 0.375rem;
    font-weight: 500;
    transition: all 0.15s ease-in-out;
    white-space: nowrap;
    min-width: fit-content;
}

.btn-group .btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.2);
}

.btn-group .btn:last-child {
    margin-right: 0;
}

/* Mobile button groups */
@media (max-width: 575.98px) {
    .btn-group {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-group .btn {
        width: 100%;
        margin-right: 0;
        margin-bottom: 0.25rem;
    }
    
    .btn-group .btn:last-child {
        margin-bottom: 0;
    }
    
    /* Stack action buttons on mobile */
    .table td:last-child .btn-group {
        flex-direction: column;
    }
}

/* Button colors */
.btn-primary {
    background-color: #4285f4;
    border-color: #4285f4;
}

.btn-info {
    background-color: #17a2b8;
    border-color: #17a2b8;
}

.btn-danger {
    background-color: #dc3545;
    border-color: #dc3545;
}

/* ============================================
   CARDS RESPONSIVE
   ============================================ */

.card {
    margin-bottom: 1.5rem;
}

.card-body {
    padding: 1.5rem;
}

@media (max-width: 767.98px) {
    .card-body {
        padding: 1rem;
    }
}

/* ============================================
   FORMS RESPONSIVE
   ============================================ */

.form-control,
.form-select {
    width: 100%;
}

@media (max-width: 575.98px) {
    .form-control,
    .form-select {
        font-size: 16px; /* Prevents zoom on iOS */
    }
}

/* Form groups */
.form-group {
    margin-bottom: 1rem;
}

/* Row columns responsive */
@media (max-width: 767.98px) {
    .row > [class*="col-"] {
        margin-bottom: 1rem;
    }
}

/* ============================================
   MODALS RESPONSIVE
   ============================================ */

.modal-dialog {
    margin: 1.75rem auto;
}

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-content {
        border-radius: 0.5rem;
    }
    
    .modal-body {
        padding: 1rem;
    }
    
    .modal-header {
        padding: 1rem;
    }
    
    .modal-footer {
        padding: 1rem;
        flex-direction: column;
    }
    
    .modal-footer .btn {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .modal-footer .btn:last-child {
        margin-bottom: 0;
    }
}

/* ============================================
   PLANNING PAGE RESPONSIVE
   ============================================ */

.planning-cell {
    position: relative;
    vertical-align: top !important;
    min-height: 60px;
    color: #212529 !important;
    background-color: #ffffff !important;
}

/* Ensure all text in planning cells is visible */
.planning-cell small {
    color: #6c757d !important;
}

.planning-cell .add-shift-hint {
    color: #6c757d !important;
}

.planning-cell .add-shift-hint small {
    color: #6c757d !important;
}

.planning-cell .shift-item small {
    color: #495057 !important;
}

.planning-cell-clickable {
    transition: background-color 0.2s ease;
    cursor: pointer;
    min-width: 140px;
}

.planning-table-header {
    min-width: 280px;
}

/* Mobile planning */
@media (max-width: 575.98px) {
    .planning-cell {
        min-width: 80px !important;
        font-size: 0.7rem;
    }
    
    .planning-cell-clickable {
        min-width: 100px !important;
    }
    
    .planning-table-header {
        min-width: 200px !important;
    }
    
    .shift-item .badge {
        font-size: 0.7rem !important;
        padding: 0.25rem 0.4rem !important;
    }
}

/* Tablet planning */
@media (min-width: 576px) and (max-width: 767.98px) {
    .planning-cell {
        min-width: 100px !important;
        font-size: 0.75rem;
    }
    
    .planning-table-header {
        min-width: 220px !important;
    }
}

/* Desktop planning */
@media (min-width: 992px) {
    .planning-cell {
        min-width: 140px;
    }
    
    .planning-table-header {
        min-width: 280px;
    }
}

/* Planning navigation buttons */
.input-group .btn.btn-primary {
    background-color: #0d6efd !important;
    color: #ffffff !important;
    border-color: #0d6efd !important;
    min-width: 50px !important;
    font-weight: bold !important;
    font-size: 1.5rem !important;
    padding: 0.6rem 0.75rem !important;
    line-height: 1 !important;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2) !important;
}

@media (max-width: 575.98px) {
    .input-group .btn.btn-primary {
        min-width: 35px !important;
        font-size: 1rem !important;
        padding: 0.4rem 0.5rem !important;
    }
}

/* ============================================
   DASHBOARD RESPONSIVE
   ============================================ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

@media (max-width: 575.98px) {
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

@media (min-width: 576px) and (max-width: 991.98px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
   SUMMARY TABLES RESPONSIVE
   ============================================ */

.summary-table {
    width: 100%;
}

.summary-table thead th {
    background-color: #B8CCE4 !important;
    border: none;
    font-weight: 600;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.summary-table tbody tr {
    transition: background-color 0.15s ease-in-out;
}

.summary-table tbody tr:hover {
    background-color: #f8f9fa !important;
}

.summary-table td {
    border-color: #dee2e6;
    vertical-align: middle;
}

@media (max-width: 575.98px) {
    .summary-table {
        font-size: 0.75rem;
    }
    
    .summary-table thead th {
        font-size: 0.7rem;
        padding: 0.5rem !important;
    }
    
    .summary-table td {
        padding: 0.5rem !important;
    }
}

/* Status styles */
.status-normal {
    background-color: #f8f9fa !important;
}

.status-absense {
    background-color: #f8d7da !important;
    color: #721c24 !important;
    font-weight: 600 !important;
}

.status-out {
    background-color: #d1ecf1 !important;
    color: #0c5460;
    font-weight: 500;
}

.status-in {
    background-color: #fff3cd !important;
    color: #664d03;
    font-weight: 500;
}

.normal {
    background: #f8f9fa !important;
}

.out {
    background: #ffebee !important;
    color: #c62828;
    font-weight: 500;
}

/* ============================================
   TOOLBAR RESPONSIVE
   ============================================ */

.d-flex.justify-content-between {
    flex-wrap: wrap;
    gap: 1rem;
}

@media (max-width: 575.98px) {
    .d-flex.justify-content-between {
        flex-direction: column;
    }
    
    .d-flex.justify-content-between > * {
        width: 100%;
    }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

/* Hide on mobile */
.hide-mobile {
    display: none;
}

@media (min-width: 768px) {
    .hide-mobile {
        display: block;
    }
}

/* Show only on mobile */
.show-mobile {
    display: block;
}

@media (min-width: 768px) {
    .show-mobile {
        display: none;
    }
}

/* Text alignment responsive */
@media (max-width: 767.98px) {
    .text-md-start {
        text-align: center !important;
    }
    
    .text-md-end {
        text-align: center !important;
    }
}

/* ============================================
   NOTIFICATION TOAST RESPONSIVE
   ============================================ */

.toast-container {
    z-index: 9999;
}

.toast {
    min-width: 350px;
    border-left: 4px solid;
}

@media (max-width: 575.98px) {
    .toast {
        min-width: calc(100vw - 2rem);
        max-width: calc(100vw - 2rem);
    }
    
    .toast-container {
        left: 1rem;
        right: 1rem;
        padding: 0;
    }
}

/* ============================================
   DIALOG RESPONSIVE
   ============================================ */

#dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    padding: 20px;
    border: 1px solid #ccc;
    box-shadow: 0px 2px 10px rgba(0, 0, 0, 0.1);
    z-index: 10000 !important;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
}

@media (max-width: 575.98px) {
    #dialog {
        padding: 16px;
        max-width: 95vw;
    }
}

#settingMail {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent overlay */
    display: none; /* Hidden by default */
    justify-content: center;
    align-items: center;
    padding: 20px;
    z-index: 10001 !important;
}

#settingMail:not(.hidden) {
    display: flex; /* Show when not hidden */
}

@media (max-width: 767.98px) {
    #settingMail {
        top: 10%;
        left: 5%;
        right: 5%;
        width: auto;
    }
}

.dialog-content {
    text-align: center;
    background-color: white;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.dialog-content-scrollable {
    text-align: left;
    background-color: white !important;
    padding: 30px;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    max-height: 80vh;
    overflow-y: auto;
    overflow-x: visible;
    width: 100%;
    max-width: 600px;
    border: none !important;
    position: relative;
}

/* Allow timepicker dropdown to overflow the modal */
.dialog-content-scrollable .ui-timepicker-container {
    z-index: 10002 !important;
}

/* Ensure schedule list items don't clip the timepicker */
#scheduleList {
    overflow: visible !important;
}

#scheduleList li {
    overflow: visible !important;
    position: relative;
}

/* Ensure the modal container allows overflow for timepicker */
#settingMail {
    overflow: visible !important;
}

#settingMail .dialog-content-scrollable {
    overflow-y: auto;
    overflow-x: visible;
}

.dialog-content-scrollable h1 {
    margin: 0 0 20px 0;
    font-size: 1.75rem;
    font-weight: 600;
    color: #333;
}

.dialog-text-left {
    margin-bottom: 20px;
}

.dialog-text-bold {
    font-weight: 600;
    color: #333;
    margin: 0;
}

.dialog-text-muted {
    color: #6c757d;
    font-size: 0.9rem;
    margin-top: 8px;
    margin-bottom: 0;
}

.dialog-flex-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.dialog-button-spacing {
    margin-right: 10px;
}

.dialog-button-spacing-left {
    margin-left: 10px;
}

#scheduleList {
    list-style: none;
    padding: 0;
    margin: 20px 0;
}

#scheduleList li {
    margin-bottom: 15px;
    padding: 10px;
    background-color: #f8f9fa;
    border-radius: 4px;
}

.dialog-checkbox-spacing {
    margin-left: 10px;
}

@media (max-width: 575.98px) {
    .dialog-content-scrollable {
        padding: 20px;
        max-width: 100%;
    }
    
    .dialog-content-scrollable h1 {
        font-size: 1.5rem;
    }
}

@media (max-width: 575.98px) {
    .dialog-content {
        padding: 16px;
    }
    
    .dialog-content-scrollable {
        padding: 16px;
    }
}

/* ============================================
   MAP/GEO LOCATION RESPONSIVE
   ============================================ */

.modalMap {
    width: 100%;
    min-height: 400px;
    height: 70vh;
    border-radius: 16px;
    overflow: hidden;
    background: #cfe1f6;
    border: 1px solid #dbe5f1;
}

@media (max-width: 767.98px) {
    .modalMap {
        height: 50vh;
        min-height: 300px;
    }
}

.modalMap .ol-viewport {
    border-radius: 16px;
}

/* ============================================
   CONTAINER RESPONSIVE
   ============================================ */

.container-fluid {
    width: 100%;
    padding-right: 15px;
    padding-left: 15px;
    margin-right: auto;
    margin-left: auto;
}

@media (min-width: 1200px) {
    .container-fluid {
        max-width: 1400px;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .app-sidebar,
    .mobile-menu-btn,
    .btn,
    .header-actions {
        display: none !important;
    }
    
    .app-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    
    .app-main {
        box-shadow: none !important;
        border-radius: 0 !important;
    }
}
