/* ========================================
   RESPONSIVE MOBILE-FIRST ENHANCEMENTS
   For Mware.Stocka Application
   ======================================== */

/* ===== MOBILE NAVIGATION ENHANCEMENTS ===== */
.mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 14px;
    z-index: 10001;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 0;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    transition: all 0.2s ease;
    font-size: 19px;
    line-height: 1;
    align-items: center;
    justify-content: center;
}

.mobile-menu-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 168, 132, 0.3);
}

.mobile-menu-toggle.active {
    background: #dc2626;
}

.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* ===== RESPONSIVE TABLE ENHANCEMENTS ===== */
.responsive-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 20px;
}

/* Mobile Card View for Tables */
@media (max-width: 768px) {
    .table-container {
        padding: 8px;
    }

    .table thead {
        display: none;
    }

    .table, .table tbody, .table tr, .table td {
        display: block;
        width: 100%;
    }

    .table tr {
        margin-bottom: 15px;
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 12px;
        background: var(--surface);
        box-shadow: var(--shadow-sm);
    }

    .table td {
        text-align: right;
        padding: 10px 12px;
        border-bottom: 1px solid var(--line-soft);
        position: relative;
        padding-left: 50%;
    }

    .table td:last-child {
        border-bottom: none;
    }

    .table td::before {
        content: attr(data-label);
        position: absolute;
        left: 12px;
        font-weight: 600;
        color: var(--ink-600);
        text-align: left;
    }

    .table td:not([data-label])::before {
        display: none;
    }

    /* Actions column full width */
    .table td .actions,
    .table td .action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: flex-end;
        width: 100%;
    }

    .table td .actions .btn,
    .table td .action-buttons .btn {
        flex: 0 0 auto;
        min-width: 80px;
    }

    /* Card view stacks the table, so horizontal scroll isn't needed.
       Dropping the scroll containers also stops them from clipping the
       absolutely-positioned actions dropdown — note overflow-x:auto also
       makes overflow-y compute to auto, which was cutting off the menu
       (e.g. on the last card). Both wrappers must be visible. */
    .responsive-table-wrapper,
    .table-container {
        overflow: visible;
    }

    /* Give the Actions cell its own full-width row with the label stacked
       above the buttons, so they don't overlap the "Actions" label. */
    .table td:has(.actions),
    .table td:has(.action-buttons) {
        padding-left: 12px;
        text-align: left;
    }

    .table td:has(.actions)::before,
    .table td:has(.action-buttons)::before {
        position: static;
        display: block;
        margin-bottom: 10px;
    }

    .table td .actions,
    .table td .action-buttons {
        justify-content: flex-start;
    }

    /* The actions button sits at the left of the full-width cell, so open
       the "⋯" menu rightward (left-aligned) to keep it on-screen instead of
       clipping off the left edge. */
    .table td .actions .dropdown-menu {
        left: 0;
        right: auto;
        max-width: calc(100vw - 32px);
    }
}

/* ===== MOBILE NAVIGATION ===== */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: flex;
    }

    .dashboard-page {
        margin: 0;
        width: 100%;
        border-radius: 0;
        min-height: 100vh;
    }

    .dashboard-header {
        height: auto;
        min-height: 56px;
        padding: 10px 16px 10px 64px;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
    }

    .dashboard-header img {
        max-width: 130px;
        height: 34px !important;
    }

    .user-menu {
        flex-direction: row;
        gap: 10px;
        align-items: center;
    }

    .user-menu span {
        font-size: 11px;
        max-width: 110px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .logout-btn {
        font-size: 11px;
        padding: 5px 10px;
    }

    .dashboard-main {
        flex-direction: column;
        min-height: auto;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        width: 282px;
        max-width: 86vw;
        height: 100%;
        background: var(--surface);
        z-index: 9999;
        transition: left 0.28s ease;
        box-shadow: 6px 0 24px rgba(15, 23, 42, 0.18);
        padding: 72px 12px 20px;
        overflow-y: auto;
    }

    .sidebar.active {
        left: 0;
    }

    .sidebar-nav a {
        padding: 13px 16px;
        font-size: 14px;
    }

    .sidebar-nav i {
        margin-right: 12px;
        width: 18px;
    }

    .content {
        padding: 16px;
    }

    /* Page headers */
    .page-header-flex {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 16px;
    }

    .page-header-flex h2 {
        font-size: 20px;
    }

    .page-header-flex .btn {
        width: 100%;
        text-align: center;
    }
}

/* ===== RESPONSIVE MODALS ===== */
@media (max-width: 768px) {
    .modal-content {
        max-width: 95%;
        padding: 20px 16px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-header h3 {
        font-size: 16px;
    }

    .modal-actions,
    .modal-footer {
        flex-direction: column;
        gap: 10px;
    }

    .modal-actions .btn,
    .modal-footer .btn {
        width: 100%;
        padding: 12px;
        font-size: 14px;
    }

    /* Payment modal specific */
    .payment-details .detail-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 4px;
    }

    .balance-info p,
    .warning-notice p {
        font-size: 12px;
    }
}

/* ===== RESPONSIVE FORMS ===== */
@media (max-width: 768px) {
    .form-group {
        margin-bottom: 16px;
    }

    .form-group label {
        font-size: 13px;
        margin-bottom: 6px;
    }

    .form-input,
    .material-select {
        padding: 12px 14px;
        font-size: 14px;
        border-radius: 8px;
    }

    .btn {
        padding: 12px 16px;
        font-size: 14px;
        border-radius: 8px;
    }

    .btn-full-width {
        padding: 14px;
        font-size: 15px;
    }
}

/* ===== RESPONSIVE SEARCH & FILTERS ===== */
@media (max-width: 768px) {
    .filters-section {
        margin-bottom: 16px;
    }

    .search-container {
        width: 100%;
        margin-bottom: 12px;
    }

    .search-input {
        width: 100%;
        padding: 12px 40px 12px 14px;
        font-size: 14px;
    }
}

/* ===== RESPONSIVE CARDS & STATS ===== */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 20px;
    }

    .stat-card {
        padding: 16px;
    }

    .stat-card h3 {
        font-size: 11px;
    }

    .stat-card .value {
        font-size: 24px;
    }
}

/* ===== RESPONSIVE DROPDOWNS ===== */
@media (max-width: 768px) {
    .dropdown-menu {
        min-width: 160px;
        right: auto;
        left: 0;
    }

    .dropdown-item {
        padding: 10px 14px;
        font-size: 13px;
    }

    .dropdown-item i {
        width: 16px;
        height: 16px;
    }
}

/* ===== RESPONSIVE IMAGES ===== */
@media (max-width: 768px) {
    .image-viewer-modal {
        max-width: 95vw;
        max-height: 85vh;
    }

    .image-viewer-img {
        max-height: 60vh;
    }

    .existing-images {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 8px;
    }
}

/* ===== RESPONSIVE ALERTS ===== */
@media (max-width: 768px) {
    .low-stock-alert {
        margin: 10px;
    }

    .alert-header {
        padding: 12px 16px;
        flex-direction: row;
    }

    .alert-title {
        font-size: 14px;
    }

    .alert-content {
        padding: 16px;
    }

    .low-stock-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .reorder-info {
        margin-left: 0;
    }
}

/* ===== ORDER CONTAINER RESPONSIVE ===== */
@media (max-width: 992px) {
    .order-container {
        grid-template-columns: 1fr;
        gap: 16px;
        height: auto;
    }

    .order-summary-panel {
        position: relative;
        top: 0;
        order: -1;
        /* Let the panel grow with its content so the total + Save button
           are never clipped. The items list below has its own scroll. */
        max-height: none;
    }

    /* Bound the items list only, keeping the Grand Total and Save button
       pinned and visible no matter how many items are added. */
    .order-summary-panel .order-items-container {
        max-height: 320px;
    }

    .available-items-panel {
        height: auto;
    }

    .inventory-grid {
        max-height: none;
    }
}

/* ===== TOUCH-FRIENDLY ENHANCEMENTS ===== */
@media (max-width: 768px) {
    /* Increase touch targets */
    .btn-sm {
        padding: 10px 14px;
        font-size: 13px;
        min-height: 40px;
    }

    .dropdown-toggle {
        min-width: 36px;
        height: 36px;
        font-size: 16px;
    }

    /* Better spacing for touch */
    .actions {
        gap: 10px;
    }

    /* Pagination */
    .pagination-container {
        flex-direction: column;
        gap: 12px;
        padding: 16px;
    }

    .pagination-controls {
        width: 100%;
        justify-content: center;
    }

    .pagination-controls .btn {
        flex: 1;
        max-width: 120px;
    }
}

/* ===== RESPONSIVE TYPOGRAPHY ===== */
@media (max-width: 768px) {
    h1 {
        font-size: 24px;
    }

    h2 {
        font-size: 20px;
    }

    h3 {
        font-size: 18px;
    }

    h4 {
        font-size: 16px;
    }

    p {
        font-size: 14px;
    }
}

/* ===== LANDSCAPE MOBILE OPTIMIZATIONS ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .dashboard-header {
        padding: 50px 16px 12px;
    }

    .sidebar {
        padding-top: 60px;
    }
}

/* ===== SMALL MOBILE (< 480px) ===== */
@media (max-width: 480px) {
    .dashboard-page {
        border-radius: 0;
        margin: 0;
        width: 100%;
        min-height: 100vh;
    }

    .content {
        padding: 12px;
    }

    .table-container {
        padding: 4px;
    }

    .table tr {
        padding: 10px;
        margin-bottom: 12px;
    }

    .table td {
        padding: 8px 10px;
        font-size: 13px;
    }

    .modal-content {
        max-width: 100%;
        border-radius: 12px 12px 0 0;
        max-height: 95vh;
    }
}

/* ===== UTILITY CLASSES ===== */
.mobile-only {
    display: none !important;
}

.desktop-only {
    display: block !important;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block !important;
    }

    .desktop-only {
        display: none !important;
    }

    .mobile-flex {
        display: flex !important;
    }

    .mobile-hide {
        display: none !important;
    }
}

/* ===== ACCESSIBILITY ENHANCEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible for keyboard navigation */
*:focus-visible {
    outline: 2px solid #00A884;
    outline-offset: 2px;
}

/* ===== PRINT STYLES ===== */
@media print {
    .sidebar,
    .mobile-menu-toggle,
    .dashboard-header,
    .btn,
    .actions,
    .dropdown,
    .mobile-overlay {
        display: none !important;
    }

    .dashboard-page {
        box-shadow: none;
        margin: 0;
        width: 100%;
    }

    .content {
        padding: 0;
    }

    .table {
        font-size: 10px;
    }

    .table th,
    .table td {
        padding: 6px;
    }
}
