/* ==========================================================================
   Responsive & HP (Mobile) Mode Styles (≤ 768px, ≤ 480px)
   ========================================================================== */

@media (max-width: 1024px) {
    .fiori-minimal-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 900px) {
    .fiori-horizontal-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    /* Main Layout & Content Padding */
    .fiori-content {
        padding: 12px 8px !important;
    }

    .fiori-content h1 {
        font-size: 18px !important;
        margin-bottom: 6px !important;
    }

    .fiori-content p {
        font-size: 13px !important;
        margin-bottom: 16px !important;
    }

    .fiori-minimal-card {
        padding: 14px 12px !important;
        margin-bottom: 14px !important;
        border-radius: 6px !important;
    }

    .fiori-dashboard-grid {
        grid-template-columns: 1fr;
    }

    .fiori-so-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    /* Grids & Layout Containers */
    .fiori-horizontal-grid,
    .fiori-horizontal-grid-single,
    .fiori-narrow-grid {
        grid-template-columns: 1fr !important;
        width: 100% !important;
        max-width: 100% !important;
        gap: 12px !important;
        margin-bottom: 12px !important;
    }

    /* Minimal Groups in Mobile Mode: Stacked vertically */
    .fiori-horizontal-grid .fiori-minimal-group,
    .fiori-horizontal-grid-single .fiori-minimal-group,
    .fiori-minimal-group {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 4px !important;
        width: 100% !important;
    }

    /* Mobile Text Alignment: Left-aligned labels */
    .fiori-horizontal-grid .fiori-minimal-group label,
    .fiori-horizontal-grid-single .fiori-minimal-group label,
    .fiori-minimal-group label {
        min-width: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        text-align: left !important;
        padding-right: 0 !important;
        white-space: normal !important;
        margin-bottom: 2px !important;
        font-size: 12px !important;
    }

    .fiori-horizontal-grid .fiori-minimal-group label::after,
    .fiori-horizontal-grid-single .fiori-minimal-group label::after {
        content: ':' !important;
        margin-left: 2px !important;
    }

    /* Inputs & Search Groups take full width on Mobile */
    .fiori-horizontal-grid .fiori-minimal-input,
    .fiori-horizontal-grid .fiori-minimal-search-group,
    .fiori-horizontal-grid-single .fiori-minimal-input,
    .fiori-horizontal-grid-single .fiori-minimal-search-group,
    .fiori-minimal-search-group,
    .fiori-minimal-input {
        width: 100% !important;
        flex: auto !important;
    }

    /* Form Bottom Actions */
    .form-actions {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
        text-align: left !important;
    }

    .form-actions button {
        width: 100% !important;
    }

    /* Header Bar & Logo on Mobile */
    .fiori-header {
        padding: 0 10px !important;
    }

    .fiori-header-left {
        gap: 8px !important;
    }

    .fiori-header-right {
        gap: 10px !important;
    }

    .fiori-logo img {
        height: 26px !important;
    }

    .fiori-dropdown-selector {
        font-size: 12px !important;
    }

    /* Navigation Bar: Enable horizontal scroll on small screens */
    .fiori-navbar {
        padding: 0 8px !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    .fiori-nav-list {
        flex-wrap: nowrap !important;
        gap: 4px !important;
    }

    .fiori-nav-item a {
        padding: 10px 12px !important;
        font-size: 12px !important;
        white-space: nowrap !important;
    }

    /* Table Toolbar Search & Actions */
    .fiori-minimal-table-toolbar {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        gap: 8px !important;
    }

    .fiori-minimal-table-toolbar .actions-area {
        width: auto !important;
    }

    .fiori-minimal-table-toolbar input[type="text"],
    #report-search,
    #fiori-search-help-search {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Table Scrollability & Minimum Width for Table Columns on Mobile */
    .table-responsive {
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        display: block !important;
        border-radius: 6px !important;
    }

    /* Items Table in SO Form */
    #so-items-table {
        min-width: 680px !important;
        width: 100% !important;
    }

    #so-items-table th:nth-child(1) {
        width: 50px !important;
        min-width: 50px !important;
    }

    #so-items-table th:nth-child(2) {
        width: 220px !important;
        min-width: 200px !important;
    }

    #so-items-table th:nth-child(3) {
        width: 90px !important;
        min-width: 80px !important;
    }

    #so-items-table th:nth-child(4) {
        width: 90px !important;
        min-width: 80px !important;
    }

    #so-items-table th:nth-child(5) {
        width: 110px !important;
        min-width: 100px !important;
    }

    #so-items-table th:nth-child(6) {
        width: 90px !important;
        min-width: 80px !important;
    }

    #so-items-table th:nth-child(7) {
        width: 50px !important;
        min-width: 45px !important;
    }

    /* Items Table in PR Form */
    #pr-items-table {
        min-width: 1280px !important;
        width: 100% !important;
    }

    #pr-items-table th:nth-child(1), #pr-items-table td:nth-child(1) { width: 55px !important; min-width: 50px !important; }
    #pr-items-table th:nth-child(2), #pr-items-table td:nth-child(2) { width: 190px !important; min-width: 170px !important; }
    #pr-items-table th:nth-child(3), #pr-items-table td:nth-child(3) { width: 170px !important; min-width: 150px !important; }
    #pr-items-table th:nth-child(4), #pr-items-table td:nth-child(4) { width: 95px !important; min-width: 85px !important; }
    #pr-items-table th:nth-child(5), #pr-items-table td:nth-child(5) { width: 85px !important; min-width: 75px !important; }
    #pr-items-table th:nth-child(6), #pr-items-table td:nth-child(6) { width: 145px !important; min-width: 135px !important; }
    #pr-items-table th:nth-child(7), #pr-items-table td:nth-child(7) { width: 130px !important; min-width: 120px !important; }
    #pr-items-table th:nth-child(8), #pr-items-table td:nth-child(8) { width: 120px !important; min-width: 110px !important; }
    #pr-items-table th:nth-child(9), #pr-items-table td:nth-child(9) { width: 120px !important; min-width: 110px !important; }
    #pr-items-table th:nth-child(10), #pr-items-table td:nth-child(10) { width: 120px !important; min-width: 110px !important; }
    #pr-items-table th:nth-child(11), #pr-items-table td:nth-child(11) { width: 50px !important; min-width: 45px !important; }

    /* Input sizing inside tables on mobile for touch readability */
    .fiori-minimal-table input.fiori-minimal-input {
        font-size: 13px !important;
        height: 34px !important;
        padding: 4px 8px !important;
    }

    .fiori-minimal-table .fiori-minimal-search-group {
        height: 34px !important;
    }

    /* Report SO Table with 14 Columns */
    .table-responsive .fiori-report-table,
    #report-so-table {
        min-width: 100% !important;
        width: max-content !important;
    }

    .fiori-report-table th,
    .fiori-report-table td {
        white-space: nowrap !important;
    }

    /* Table Pagination Bar */
    .fiori-pagination-bar {
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        text-align: center !important;
    }

    .pagination-info {
        text-align: center !important;
    }

    .pagination-controls {
        width: 100% !important;
        justify-content: center !important;
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    /* Modals & Dialogs */
    .fiori-modal-content {
        width: 94% !important;
        max-width: 100% !important;
        min-width: 0 !important;
        margin: 10px !important;
    }

    .summary-details-grid {
        grid-template-columns: 1fr !important;
        gap: 8px !important;
    }

    .fiori-modal-footer {
        flex-direction: column-reverse !important;
        gap: 8px !important;
    }

    .fiori-modal-footer button,
    .fiori-modal-footer a {
        width: 100% !important;
        text-align: center !important;
        box-sizing: border-box !important;
    }

    /* Toast Notification on Mobile */
    .fiori-toast-container {
        top: 12px !important;
        right: 12px !important;
        left: 12px !important;
    }

    .fiori-toast {
        min-width: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }
}

@media (max-width: 640px) {
    .fiori-minimal-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .fiori-minimal-card h3 {
        font-size: 14px !important;
    }

    .fiori-minimal-input {
        font-size: 12px !important;
    }

    /* Logon / Connection Page Mobile Responsiveness */
    body.page-connection {
        padding: 12px !important;
    }

    .login-wrapper {
        max-width: 100% !important;
        width: 100% !important;
    }

    .login-card {
        padding: 20px 16px !important;
        border-radius: 8px !important;
    }

    .login-card-footer {
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        text-align: center !important;
        gap: 10px !important;
    }

    .login-card-footer .forgot-link {
        text-align: center !important;
    }

    .login-footer-info {
        align-items: center !important;
        text-align: center !important;
        gap: 4px !important;
        width: 100% !important;
    }

    .created-by-text {
        font-size: 11px !important;
        white-space: normal !important;
        text-align: center !important;
        justify-content: center !important;
        flex-wrap: wrap !important;
    }

    .app-brand-text {
        text-align: center !important;
    }
}
