/* ========= MOBILE RESPONSIVE STYLES ========= */
/* Breakpoints: 
   - Mobile: < 768px
   - Tablet: 768px - 1024px
   - Desktop: > 1024px
*/

/* ========= GLOBAL MOBILE FIXES ========= */
@media (max-width: 767.98px) {
    html, body {
        overflow-x: hidden;
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }

    /* Prevent horizontal scroll */
    * {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* Improve touch scrolling */
    body {
        -webkit-overflow-scrolling: touch;
    }

    /* Better font rendering on mobile */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* Remove tap highlight */
    * {
        -webkit-tap-highlight-color: transparent;
    }

    /* Better focus states for accessibility */
    button:focus,
    a:focus,
    input:focus,
    select:focus,
    textarea:focus {
        outline: 2px solid #57e0c4;
        outline-offset: 2px;
    }

    /* Force all columns to full width on mobile */
    [class*="col-"] {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
}

/* ========= SIDEBAR - MOBILE ========= */
@media (max-width: 991.98px) {
    /* Hide sidebar by default on mobile/tablet */
    nav.menu-gradient {
        position: fixed !important;
        left: -250px !important;
        top: 0;
        bottom: 0;
        width: 250px;
        transition: left 0.3s ease-in-out;
        z-index: 1050 !important; /* Sidebar phải ở trên overlay */
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        border-radius: 0 !important;
    }

    /* Show sidebar when active */
    nav.menu-gradient.sidebar-open {
        left: 0 !important;
        z-index: 1050 !important;
    }

    /* Overlay when sidebar is open - che toàn bộ màn hình ngoại trừ sidebar */
    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 1040; /* Dưới sidebar (1050) và hamburger (1060) */
        backdrop-filter: blur(2px);
        transition: opacity 0.3s ease;
        pointer-events: auto;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Hamburger menu button */
    .hamburger-menu {
        display: flex !important;
        position: fixed;
        top: 1rem;
        left: 1rem;
        z-index: 1060;
        width: 44px;
        height: 44px;
        background: linear-gradient(135deg, #57e0c4 0%, #44bedd 100%);
        border: none;
        border-radius: 0.5rem;
        align-items: center;
        justify-content: center;
        cursor: pointer;
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
        color: white;
        font-size: 1.25rem;
        transition: all 0.3s ease;
    }

    .hamburger-menu:hover,
    .hamburger-menu:focus {
        box-shadow: 0 4px 12px rgba(0,0,0,0.2);
        transform: translateY(-1px);
        outline: none;
    }

    .hamburger-menu:active {
        transform: translateY(0);
    }

    /* Adjust main content margin */
    main {
        margin-left: 0 !important;
        padding-top: 4rem; /* Space for hamburger menu */
    }

    /* Sidebar header adjustments */
    nav.menu-gradient .text-center.py-4 {
        padding-top: 4rem !important; /* Space for hamburger */
    }
}

@media (min-width: 992px) {
    /* Hide hamburger on desktop */
    .hamburger-menu {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

/* ========= DASHBOARD WRAPPER - MOBILE ========= */
@media (max-width: 767.98px) {
    .dashboard-wrapper {
        padding: 1rem !important;
    }

    /* Page header */
    .page-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem !important;
        margin-bottom: 1rem !important;
    }

    .page-header h2 {
        font-size: 1.5rem !important;
    }

    .page-header-time {
        margin-left: 0 !important;
        font-size: 0.85rem !important;
    }

    .page-header-icon {
        font-size: 1.5rem !important;
    }
}

/* ========= STATS GRID - MOBILE ========= */
@media (max-width: 767.98px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }

    .stat-card {
        padding: 1.25rem !important;
    }

    .stat-card-value {
        font-size: 1.75rem !important;
    }
}

@media (min-width: 768px) and (max-width: 991.98px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ========= ACTIVITY SECTION - MOBILE ========= */
@media (max-width: 767.98px) {
    .activity-section {
        padding: 1rem !important;
        border-radius: 1rem !important;
    }

    .activity-section h5 {
        font-size: 1rem !important;
        margin-bottom: 1rem !important;
    }
}

/* ========= TABLES - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Horizontal scroll for tables */
    .table-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: -1rem;
        padding: 1rem;
        position: relative;
    }

    .activity-table {
        min-width: 700px; /* Minimum width to prevent too much compression */
        font-size: 0.85rem !important;
        width: 100%;
    }

    .activity-table th,
    .activity-table td {
        padding: 0.75rem 0.5rem !important;
        white-space: nowrap;
        vertical-align: middle;
    }

    .activity-table th {
        font-size: 0.75rem !important;
        font-weight: 600;
        background: #f8f9fa;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    .activity-table td {
        font-size: 0.8rem !important;
    }

    /* Make some columns more flexible */
    .activity-table td:nth-child(2),
    .activity-table th:nth-child(2) {
        min-width: 150px;
        white-space: normal;
        word-break: break-word;
    }

    /* Status badges in tables */
    .activity-table .status-badge {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
        white-space: nowrap;
    }

    /* Action column */
    .activity-table th:last-child,
    .activity-table td:last-child {
        position: sticky;
        right: 0;
        background: white;
        z-index: 5;
        box-shadow: -2px 0 4px rgba(0,0,0,0.1);
    }

    .activity-table tbody tr:hover td:last-child {
        background: #f8f9fa;
    }

    /* Alternative: Card layout for tables (optional) */
    .table-card-view {
        display: none; /* Hidden by default, can be toggled */
    }
}

/* ========= BUTTONS - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Action buttons stack */
    .d-flex.justify-content-between:not(.pagination-controls):not(.modal-footer) {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch !important;
    }

    .d-flex.justify-content-between:not(.pagination-controls):not(.modal-footer) > * {
        width: 100%;
    }

    /* Primary action buttons - full width */
    .btn-primary:not(.btn-sm):not(.pagination-controls .btn) {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Button groups stack vertically */
    .btn-group:not(.pagination-controls) {
        display: flex;
        flex-direction: column;
        width: 100%;
    }

    .btn-group:not(.pagination-controls) .btn {
        border-radius: 0.5rem !important;
        margin-bottom: 0.5rem;
        width: 100%;
    }

    /* Small buttons in tables - keep inline but smaller */
    .activity-table .btn,
    table .btn {
        padding: 0.3rem 0.6rem;
        font-size: 0.75rem;
        min-width: auto;
        white-space: nowrap;
    }

    /* Action buttons in action bars */
    .page-header + .mb-3 .btn,
    .activity-section > .mb-3 .btn {
        width: 100%;
    }

    /* Button spacing */
    .btn + .btn {
        margin-left: 0;
        margin-top: 0.5rem;
    }

    /* Inline buttons wrap */
    .d-inline-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* ========= FORMS - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Form rows stack */
    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .row > [class*="col-"] {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-bottom: 1rem;
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }

    /* Form controls */
    .form-control,
    .form-select,
    textarea,
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="date"],
    input[type="datetime-local"] {
        font-size: 16px !important; /* Prevent zoom on iOS */
        padding: 0.75rem !important;
        width: 100% !important;
        box-sizing: border-box;
    }

    .form-label {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
        font-weight: 600;
        display: block;
    }

    /* Form groups */
    .form-group,
    .mb-3 {
        margin-bottom: 1.25rem;
    }

    /* Checkboxes and radios */
    .form-check {
        margin-bottom: 1rem;
        padding-left: 1.75rem;
    }

    .form-check-input {
        margin-top: 0.25rem;
        margin-left: -1.75rem;
        width: 1.25rem;
        height: 1.25rem;
    }

    .form-check-label {
        padding-left: 0.5rem;
    }

    /* Textarea */
    textarea.form-control {
        min-height: 120px;
        resize: vertical;
    }

    /* Input groups */
    .input-group {
        flex-wrap: wrap;
    }

    .input-group > .form-control,
    .input-group > .form-select {
        width: 100% !important;
        margin-bottom: 0.5rem;
    }

    .input-group-text {
        width: 100%;
        justify-content: center;
    }

    /* Form validation */
    .invalid-feedback {
        font-size: 0.85rem;
        display: block;
    }

    /* File inputs */
    input[type="file"] {
        font-size: 16px !important;
        padding: 0.5rem;
    }
}

/* ========= LOGIN PAGE - MOBILE ========= */
@media (max-width: 991.98px) {
    .login-wrapper {
        padding: 1rem !important;
    }

    .login-container {
        flex-direction: column;
        min-height: auto !important;
        max-width: 100% !important;
    }

    .login-left-panel {
        width: 100% !important;
        padding: 2rem 1.5rem !important;
        border-radius: 1.5rem 1.5rem 0 0;
    }

    .login-right-panel {
        padding: 2rem 1.5rem !important;
    }

    .login-box {
        max-width: 100% !important;
    }

    .feature-list {
        gap: 0.75rem !important;
    }

    .feature-box {
        padding: 0.875rem !important;
    }

    .feature-icon {
        width: 2.5rem !important;
        height: 2.5rem !important;
        font-size: 1.2rem !important;
    }

    .login-header h1 {
        font-size: 1.25rem !important;
    }

    .login-logo {
        font-size: 2rem !important;
    }
}

/* ========= MODALS - MOBILE ========= */
@media (max-width: 767.98px) {
    .modal {
        padding: 0 !important;
    }

    .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        height: 100vh !important;
        max-height: 100vh !important;
    }

    .modal-content {
        border-radius: 0 !important;
        height: 100vh !important;
        max-height: 100vh !important;
        display: flex;
        flex-direction: column;
        border: none;
    }

    .modal-header {
        border-radius: 0 !important;
        padding: 1rem;
        border-bottom: 1px solid #dee2e6;
        flex-shrink: 0;
    }

    .modal-title {
        font-size: 1.1rem !important;
        font-weight: 600;
    }

    .modal-body {
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding: 1rem;
        -webkit-overflow-scrolling: touch;
    }

    .modal-footer {
        border-radius: 0 !important;
        padding: 1rem;
        flex-wrap: wrap;
        gap: 0.5rem;
        border-top: 1px solid #dee2e6;
        flex-shrink: 0;
    }

    .modal-footer .btn {
        flex: 1;
        min-width: calc(50% - 0.25rem);
        margin: 0;
    }

    /* Modal table scroll */
    .modal-body .table-wrapper {
        margin: -1rem;
        padding: 1rem;
    }

    /* Close button */
    .modal-header .btn-close {
        margin: 0;
        padding: 0.5rem;
    }
}

/* ========= PAGINATION - MOBILE ========= */
@media (max-width: 767.98px) {
    .pagination-wrapper {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch !important;
    }

    .pagination-info {
        text-align: center;
        font-size: 0.85rem !important;
    }

    .pagination-controls {
        justify-content: center;
        flex-wrap: wrap;
    }

    .pagination-controls .btn {
        min-width: 36px;
        height: 36px;
        font-size: 0.85rem;
        padding: 0.5rem;
    }
}

/* ========= FILTERS - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Filter section */
    .activity-section .row,
    .row.filter-row,
    .filter-section .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .activity-section [class*="col-"],
    .filter-section [class*="col-"] {
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin-bottom: 1rem;
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }

    /* Filter labels */
    .form-label {
        font-weight: 600;
        margin-bottom: 0.5rem;
        font-size: 0.9rem;
    }

    /* Filter inputs */
    .activity-section .form-select,
    .activity-section .form-control,
    .filter-section .form-select,
    .filter-section .form-control {
        width: 100% !important;
    }
}

/* ========= STATUS BADGES - MOBILE ========= */
@media (max-width: 767.98px) {
    .status-badge {
        padding: 0.25rem 0.65rem !important;
        font-size: 0.75rem !important;
    }
}

/* ========= CODE EDITOR - MOBILE ========= */
@media (max-width: 767.98px) {
    .code-editor,
    textarea.code-editor,
    #sourceQueryTextarea,
    #targetInsertQueryTextarea {
        font-size: 14px !important;
        padding: 0.75rem !important;
        width: 100% !important;
        box-sizing: border-box;
        font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
        line-height: 1.5;
        resize: vertical;
        border: 1px solid #dee2e6;
        border-radius: 0.5rem;
    }

    textarea.code-editor {
        min-height: 200px;
        max-height: 400px;
    }

    /* SQL editor wrapper */
    .code-editor-wrapper {
        width: 100%;
        overflow-x: auto;
        margin-bottom: 1rem;
    }

    /* Editor action buttons */
    .code-editor-actions {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 0.5rem;
        margin-bottom: 1rem;
    }

    .code-editor-actions .btn {
        width: 100%;
        margin: 0;
    }

    /* Format and AutoETL buttons */
    .btn-group.code-action-buttons {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.5rem;
    }

    .btn-group.code-action-buttons .btn {
        width: 100%;
        margin: 0;
    }
}

/* ========= PROFILE PAGE - MOBILE ========= */
@media (max-width: 767.98px) {
    .profile-avatar-wrapper {
        width: 100px !important;
        height: 100px !important;
    }

    .profile-avatar-icon {
        font-size: 3rem !important;
    }

    .profile-info-item {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }
}

/* ========= NAVIGATION MENU - MOBILE ========= */
@media (max-width: 991.98px) {
    .nav-menu-item {
        padding: 0.75rem 1rem !important;
        font-size: 0.95rem !important;
    }

    .sidebar-profile {
        padding: 1rem !important;
    }

    .sidebar-profile .btn {
        width: 90% !important;
    }
}

/* ========= ACTION BAR - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Action bar with buttons */
    .mb-3 .btn-primary,
    .page-header + div .btn-primary,
    .activity-section > div .btn-primary {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    /* Inline action buttons */
    .d-flex.gap-2,
    .d-flex.gap-1 {
        flex-wrap: wrap;
        gap: 0.5rem !important;
    }

    .d-flex.gap-2 .btn,
    .d-flex.gap-1 .btn {
        flex: 1;
        min-width: calc(50% - 0.25rem);
    }

    /* Action buttons in headers */
    .page-header + .mb-3 {
        margin-bottom: 1rem !important;
    }

    /* Filter section */
    .activity-section .row {
        margin: 0;
    }

    .activity-section .row > div {
        margin-bottom: 1rem;
    }
}

/* ========= TOAST NOTIFICATIONS - MOBILE ========= */
@media (max-width: 767.98px) {
    .toast-container {
        left: 0.5rem !important;
        right: 0.5rem !important;
        width: auto !important;
        max-width: calc(100% - 1rem) !important;
        top: 5rem !important; /* Below hamburger menu */
    }

    .toast {
        max-width: 100% !important;
        font-size: 0.9rem;
        padding: 0.75rem;
    }

    .toast-header {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }

    .toast-body {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
}

/* ========= CONFIRMATION DIALOG - MOBILE ========= */
@media (max-width: 767.98px) {
    .confirmation-dialog {
        width: calc(100% - 2rem) !important;
        max-width: 100% !important;
        margin: 1rem !important;
    }

    .confirmation-dialog .modal-content {
        border-radius: 0.5rem;
        max-height: 90vh;
    }

    .confirmation-dialog .modal-header {
        padding: 1rem;
        border-bottom: 1px solid #dee2e6;
    }

    .confirmation-dialog .modal-body {
        padding: 1rem;
        font-size: 0.9rem;
        overflow-y: auto;
    }

    .confirmation-dialog .modal-footer {
        flex-direction: column;
        padding: 1rem;
        gap: 0.5rem;
        border-top: 1px solid #dee2e6;
    }

    .confirmation-dialog .modal-footer .btn {
        width: 100%;
        margin: 0;
    }
}

/* ========= JOB DETAILS MODAL - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Job details table */
    .job-details-table {
        font-size: 0.85rem;
    }

    .job-details-table th {
        width: 40% !important;
        padding: 0.5rem !important;
        font-size: 0.8rem !important;
    }

    .job-details-table td {
        padding: 0.5rem !important;
        word-break: break-word;
    }
}

/* ========= SCHEDULER TABLE - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Scheduler actions */
    .activity-table .text-end,
    .activity-table td.text-end {
        text-align: left !important;
    }

    .activity-table .btn-group {
        display: flex;
        flex-direction: column;
        width: 100%;
        gap: 0.25rem;
    }

    .activity-table .btn-group .btn {
        width: 100%;
        min-width: auto;
        font-size: 0.75rem;
        padding: 0.4rem 0.5rem;
        margin: 0;
    }

    /* Action column in tables */
    .activity-table th:last-child,
    .activity-table td:last-child {
        width: auto;
        min-width: 100px;
    }

    /* Multiple buttons in cell */
    .activity-table td .btn + .btn {
        margin-left: 0;
        margin-top: 0.25rem;
        display: block;
        width: 100%;
    }
}

/* ========= HISTORY LOG - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Log details */
    .log-details-table {
        font-size: 0.8rem;
        table-layout: fixed;
        width: 100%;
    }

    .log-details-table th,
    .log-details-table td {
        padding: 0.5rem 0.25rem !important;
        font-size: 0.75rem !important;
        word-break: break-word;
        overflow-wrap: break-word;
    }

    .log-details-table th {
        width: 35%;
        font-weight: 600;
        vertical-align: top;
    }

    /* Pre-formatted text */
    pre,
    .log-details-table pre,
    .modal-body pre {
        font-size: 0.7rem !important;
        padding: 0.75rem !important;
        overflow-x: auto;
        white-space: pre-wrap;
        word-break: break-word;
        overflow-wrap: break-word;
        background: #f8f9fa;
        border-radius: 0.25rem;
        border: 1px solid #dee2e6;
    }

    /* Details tag */
    details {
        width: 100%;
    }

    details summary {
        padding: 0.5rem;
        cursor: pointer;
        font-weight: 600;
        background: #f8f9fa;
        border-radius: 0.25rem;
        margin-bottom: 0.5rem;
    }
}

/* ========= DATA QUALITY - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Quality score badges */
    .quality-score {
        font-size: 1.25rem !important;
        padding: 0.5rem 1rem !important;
    }

    /* Filter section in data quality */
    .data-quality-filters {
        margin-bottom: 1rem;
    }

    .data-quality-filters .row {
        margin: 0;
    }

    .data-quality-filters .row > div {
        margin-bottom: 1rem;
    }
}

/* ========= ALERTS AND BADGES - MOBILE ========= */
@media (max-width: 767.98px) {
    .alert {
        padding: 0.75rem 1rem !important;
        font-size: 0.9rem;
        margin-bottom: 1rem;
        border-radius: 0.5rem;
    }

    .alert .oi {
        margin-right: 0.5rem;
        font-size: 1rem;
    }

    .badge {
        font-size: 0.75rem;
        padding: 0.35rem 0.65rem;
        white-space: normal;
        word-break: break-word;
    }

    /* Alert dismissible */
    .alert-dismissible .btn-close {
        padding: 0.75rem 1rem;
        font-size: 1rem;
    }
}

/* ========= CARDS - MOBILE ========= */
@media (max-width: 767.98px) {
    .card {
        margin-bottom: 1rem;
        border-radius: 0.75rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
        font-size: 0.95rem;
    }

    .card-body {
        padding: 1rem;
    }

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

/* ========= UTILITY CLASSES - MOBILE ========= */
@media (max-width: 767.98px) {
    /* Hide on mobile */
    .d-none-mobile {
        display: none !important;
    }

    /* Show only on mobile */
    .d-mobile-only {
        display: block !important;
    }

    /* Full width on mobile */
    .w-100-mobile {
        width: 100% !important;
    }

    /* Stack on mobile */
    .flex-column-mobile {
        flex-direction: column !important;
    }

    /* Center text on mobile */
    .text-center-mobile {
        text-align: center !important;
    }

    /* Remove margins on mobile */
    .m-0-mobile {
        margin: 0 !important;
    }

    .p-0-mobile {
        padding: 0 !important;
    }

    /* Small text on mobile */
    .text-small-mobile {
        font-size: 0.85rem !important;
    }
}

@media (min-width: 768px) {
    .d-mobile-only {
        display: none !important;
    }
}

/* ========= TOUCH FRIENDLY ========= */
@media (max-width: 767.98px) {
    /* Larger touch targets */
/*    .btn,
    .nav-menu-item,
    .form-check-input {
        min-height: 44px;
        min-width: 44px;
    }*/

    /* Better spacing for touch */
    .nav-menu-item {
        padding: 0.875rem 1rem !important;
    }

    /* Input fields */
    .form-control,
    .form-select {
        min-height: 44px;
    }
}

/* ========= LANDSCAPE ORIENTATION ========= */
@media (max-width: 991.98px) and (orientation: landscape) {
    .login-container {
        max-height: 100vh;
        overflow-y: auto;
    }

    .login-left-panel {
        padding: 1.5rem !important;
    }

    .login-right-panel {
        padding: 1.5rem !important;
    }
}

/* ========= PRINT STYLES ========= */
@media print {
    nav.menu-gradient,
    .hamburger-menu,
    .sidebar-overlay,
    .btn,
    .pagination-wrapper,
    .page-header-time {
        display: none !important;
    }

    main {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .dashboard-wrapper {
        padding: 0 !important;
    }

    .activity-section {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
}

