/* Mobile Responsive Styles for InventoryHUB WASM Client */
/* This file contains all mobile-specific styling for tablets and smartphones */

/* ===================================
   MOBILE BREAKPOINTS
   =================================== */
/* 
   - Mobile: max-width: 480px
   - Tablet: 481px - 768px
   - Desktop: 769px and above
*/

/* ===================================
   GLOBAL MOBILE UTILITIES
   =================================== */

@media (max-width: 768px) {
    /* Hide elements on mobile */
    .mobile-hidden {
        display: none !important;
    }

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

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

    /* Reduce padding on mobile */
    .mobile-compact {
        padding: 0.5rem !important;
    }

    /* Stack elements vertically */
    .mobile-stack {
        flex-direction: column !important;
    }

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

    /* Smaller font sizes for mobile */
    .mobile-text-sm {
        font-size: 0.875rem !important;
    }

    /* Hide scrollbars on mobile for cleaner look */
    .mobile-hide-scroll {
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .mobile-hide-scroll::-webkit-scrollbar {
        display: none;
    }
}

/* Desktop only */
@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}

/* ===================================
   LAYOUT & NAVIGATION
   =================================== */

@media (max-width: 768px) {
    /* Adjust main page layout */
    .page {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    /* Sidebar becomes full width and collapsible */
    .sidebar-container {
        width: 100% !important;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
        max-height: 60px;
        overflow: visible;
        transition: max-height 0.3s ease-in-out;
        background-color: var(--sidebar-background-color);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .sidebar-container.expanded {
        max-height: 100vh;
        overflow-y: auto;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }

    /* Main content adjusts for fixed header */
    main {
        margin-top: 75px; /* Increased from 60px for more breathing room */
        padding: 0;
        min-height: calc(100vh - 75px);
        display: flex;
        flex-direction: column;
    }

    .content {
        padding: 1rem !important;
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    /* Navigation container on mobile */
    .nav-container {
        width: 100%;
    }

    /* Nav items styling */
    .nav-item {
        margin: 0;
    }

    ::deep .nav-link {
        padding: 1rem 1.5rem;
        margin: 0;
        border-radius: 0;
        border-bottom: 1px solid var(--border-color);
    }
}

/* ===================================
   PAGE HEADERS & TITLES
   =================================== */

@media (max-width: 768px) {
    .page-title {
        font-size: 1.5rem !important;
        margin-top: 0.75rem !important;
        margin-bottom: 0.5rem !important;
        padding: 0;
        line-height: 1.3;
    }

    .page-subtitle {
        font-size: 0.95rem !important;
        margin-bottom: 1rem !important;
        padding: 0;
    }
}

@media (max-width: 480px) {
    .page-title {
        font-size: 1.25rem !important;
    }

    .page-subtitle {
        font-size: 0.85rem !important;
    }
}

/* ===================================
   CARDS & CONTENT CONTAINERS
   =================================== */

@media (max-width: 768px) {
    .content-card {
        padding: 1rem !important;
        border-radius: 8px !important;
        margin-bottom: 1rem;
        flex: 1;
        display: flex;
        flex-direction: column;
    }

    .forecast-card {
        padding: 1rem !important;
        margin-bottom: 1rem;
    }

    .forecast-card-header {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.75rem;
    }

    .forecast-week-title {
        font-size: 1.1rem !important;
    }

    .forecast-actions {
        display: flex;
        gap: 0.5rem;
        width: 100%;
    }

    .forecast-actions button {
        flex: 1;
    }

    .weekly-forecasts-grid {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }
}

/* ===================================
   ACTION BARS & TOOLBARS
   =================================== */

@media (max-width: 768px) {
    .action-bar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
        margin-bottom: 1rem !important;
    }

    .search-input-group {
        max-width: 100% !important;
        width: 100%;
        margin-bottom: 0;
    }

    .action-buttons {
        display: flex;
        flex-direction: row;
        gap: 0.5rem;
        width: 100%;
    }

    .action-buttons button {
        flex: 1;
        font-size: 0.9rem;
        padding: 0.6rem 0.75rem;
    }

    .action-buttons button i {
        display: none; /* Hide icons on mobile to save space */
    }

    /* Dropdown adjustments */
    .dropdown-themed {
        width: 100%;
    }

    .dropdown-themed button {
        width: 100%;
        justify-content: space-between;
    }
}

/* ===================================
   TABLES - RESPONSIVE DESIGN
   =================================== */

@media (max-width: 768px) {
    /* Make tables horizontally scrollable */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .data-table {
        min-width: 600px; /* Prevent table from becoming too compressed */
        font-size: 0.85rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.5rem 0.75rem !important;
        white-space: nowrap;
    }

    /* Specific column adjustments */
    .toggle-column {
        width: 30px;
        padding: 0.5rem 0.25rem !important;
    }

    .actions-column-wide {
        white-space: nowrap;
    }

    .actions-column-wide button {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem !important;
        margin: 0.125rem;
    }

    /* Material description truncation */
    .material-description {
        max-width: 150px;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Nested tables in expandable rows */
    .nested-table-container {
        padding: 0.5rem;
    }

    .nested-table {
        font-size: 0.8rem;
    }

    .nested-table th,
    .nested-table td {
        padding: 0.4rem 0.5rem !important;
    }
}

/* Alternative: Card-based table layout for very small screens */
@media (max-width: 480px) {
    /* Optional: Convert tables to card layout on very small screens */
    .data-table.mobile-cards {
        display: block;
        min-width: 0;
    }

    .data-table.mobile-cards thead {
        display: none;
    }

    .data-table.mobile-cards tbody,
    .data-table.mobile-cards tr {
        display: block;
        width: 100%;
    }

    .data-table.mobile-cards tr {
        margin-bottom: 1rem;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 0.75rem;
        background-color: var(--card-background-color);
    }

    .data-table.mobile-cards td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem 0 !important;
        border: none !important;
        text-align: right;
    }

    .data-table.mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--subtle-text-color);
        text-align: left;
        flex: 1;
    }

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

/* ===================================
   PAGINATION
   =================================== */

@media (max-width: 768px) {
    .pagination-container {
        flex-direction: column;
        gap: 0.75rem;
        padding-top: 1rem !important;
    }

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

    .pagination-controls button {
        flex: 1;
        font-size: 0.875rem;
    }
}

/* ===================================
   MODALS
   =================================== */

@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100% - 1rem) !important;
    }

    .modal-dialog.modal-lg {
        max-width: calc(100% - 1rem) !important;
    }

    .modal-content {
        border-radius: 8px !important;
    }

    .modal-header {
        padding: 0.75rem 1rem !important;
    }

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

    .modal-body {
        padding: 1rem !important;
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }

    .modal-footer {
        padding: 0.75rem 1rem !important;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .modal-footer button {
        width: 100%;
        margin: 0 !important;
    }

    /* Form elements in modals */
    .modal-body .form-label {
        font-size: 0.85rem !important;
        margin-bottom: 0.25rem !important;
    }

    .modal-body .form-control,
    .modal-body .form-select {
        font-size: 0.9rem !important;
        padding: 0.5rem 0.75rem !important;
    }

    /* Modal tables */
    .modal-body .table-responsive {
        margin: 0 -1rem;
        padding: 0 1rem;
    }

    .modal-body table {
        font-size: 0.85rem;
    }

    .modal-body table th,
    .modal-body table td {
        padding: 0.5rem !important;
    }

    /* Row/column adjustments in modals */
    .modal-body .row {
        margin-left: 0;
        margin-right: 0;
    }

    .modal-body .row .col-md-2,
    .modal-body .row .col-md-3,
    .modal-body .row .col-md-4,
    .modal-body .row .col-md-7,
    .modal-body .row .col-md-8 {
        width: 100%;
        margin-bottom: 0.75rem;
        padding-left: 0;
        padding-right: 0;
    }
}

/* ===================================
   BUTTONS
   =================================== */

@media (max-width: 768px) {
    .btn-primary-themed,
    .btn-secondary-themed,
    .btn-outline-primary-themed,
    .btn-outline-secondary-themed {
        font-size: 0.9rem;
        padding: 0.6rem 1rem !important;
    }

    .btn-edit-themed,
    .btn-danger-themed,
    .btn-info-themed {
        font-size: 0.75rem;
        padding: 0.35rem 0.6rem !important;
    }

    /* Icon buttons */
    .btn-close-themed {
        padding: 0.5rem;
    }

    /* Button groups */
    .btn-group {
        flex-direction: column;
        width: 100%;
    }

    .btn-group .btn {
        border-radius: 8px !important;
        margin-bottom: 0.5rem;
    }
}

/* ===================================
   FORMS & INPUTS
   =================================== */

@media (max-width: 768px) {
    .form-control,
    .form-select,
    .custom-input {
        font-size: 0.9rem !important;
        padding: 0.6rem 0.75rem !important;
    }

    .form-label {
        font-size: 0.85rem !important;
        margin-bottom: 0.25rem !important;
    }

    .form-check-label {
        font-size: 0.9rem;
    }

    /* Search inputs */
    .search-input-group input {
        font-size: 0.9rem;
        padding: 0.6rem 0.75rem !important;
    }

    .search-input-group button {
        font-size: 0.9rem;
        padding: 0.6rem 1rem !important;
    }
}

/* ===================================
   TABS
   =================================== */

@media (max-width: 768px) {
    .production-tabs .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-bottom: 1px solid var(--border-color);
    }

    .production-tabs .nav-link {
        font-size: 0.85rem;
        padding: 0.75rem 1rem;
        white-space: nowrap;
    }

    .production-tabs .tab-content {
        padding: 1rem 0;
    }
}

/* ===================================
   CALENDAR & DATE COMPONENTS
   =================================== */

@media (max-width: 768px) {
    .calendar-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .calendar-grid {
        min-width: 600px;
    }

    .calendar-cell {
        font-size: 0.8rem;
        padding: 0.5rem;
    }

    .calendar-header {
        font-size: 0.9rem;
        padding: 0.75rem;
    }
}

/* ===================================
   TOAST NOTIFICATIONS
   =================================== */

@media (max-width: 768px) {
    .toast-container {
        top: 70px !important; /* Below fixed nav */
        right: 0.5rem !important;
        left: 0.5rem !important;
        width: auto !important;
    }

    .toast {
        font-size: 0.9rem;
        max-width: 100%;
    }

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

    .toast-body {
        padding: 0.75rem;
    }
}

/* ===================================
   LOADING STATES
   =================================== */

@media (max-width: 768px) {
    .loading-container {
        padding: 2rem 1rem !important;
    }

    .spinner-themed {
        width: 2rem;
        height: 2rem;
    }
}

/* ===================================
   ERROR MESSAGES
   =================================== */

@media (max-width: 768px) {
    #blazor-error-ui {
        padding: 0.6rem 1rem;
        font-size: 0.85rem;
    }

    #blazor-error-ui a {
        display: block;
        margin: 0.25rem 0;
    }

    .blazor-error-boundary {
        padding: 0.75rem 1rem 0.75rem 3rem;
        font-size: 0.9rem;
    }

    .not-authorized-container {
        margin: 2rem 1rem;
        padding: 1.5rem;
    }

    .not-authorized-container h3 {
        font-size: 1.35rem !important;
    }
}

/* ===================================
   SPECIFIC COMPONENT ADJUSTMENTS
   =================================== */

@media (max-width: 768px) {
    /* Mobile clickable table rows */
    .mobile-clickable-row {
        cursor: pointer;
        transition: background-color 0.2s ease;
        -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    }

    .mobile-clickable-row:hover,
    .mobile-clickable-row:active {
        background-color: var(--hover-background-color);
    }

    .mobile-clickable-row:active {
        opacity: 0.9;
        transform: scale(0.99);
    }

    /* Mobile table wrapper */
    .mobile-show {
        overflow-x: hidden; /* Changed from auto to prevent horizontal scroll */
        -webkit-overflow-scrolling: touch;
        margin: 0;
        padding: 0 1rem;
        flex: 1;
        overflow-y: auto;
        max-height: calc(100vh - 380px); /* Allow vertical scrolling */
    }

    .mobile-show::-webkit-scrollbar {
        height: 8px;
        width: 8px;
    }

    .mobile-show::-webkit-scrollbar-track {
        background: var(--app-background-color);
        border-radius: 4px;
    }

    .mobile-show::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 4px;
    }

    .mobile-show::-webkit-scrollbar-thumb:hover {
        background: var(--subtle-text-color);
    }

    /* Hide pagination on mobile */
    .pagination-container {
        display: none !important;
    }

    /* Forecast cards on mobile */
    .weekly-forecasts-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }

    .forecast-card {
        margin-bottom: 0 !important;
        cursor: pointer;
        transition: transform 0.2s ease, box-shadow 0.2s ease;
    }

    .forecast-card:active {
        transform: scale(0.98);
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
    }

    .mobile-forecast-summary {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 1rem;
        border-top: 1px solid var(--border-color);
    }

    .mobile-forecast-summary .product-count {
        color: var(--subtle-text-color);
        font-size: 0.9rem;
    }

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

    .forecast-card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .forecast-week-title {
        font-size: 1.1rem !important;
    }

    .forecast-actions {
        width: 100%;
        display: flex;
        gap: 0.5rem;
    }

    .forecast-actions button {
        flex: 1;
    }

    /* Simplify forecast tables on mobile */
    .forecast-card-body .table-responsive {
        overflow-x: visible !important;
    }

    .forecast-card-body table {
        font-size: 0.85rem !important;
    }

    .forecast-card-body table th,
    .forecast-card-body table td {
        padding: 0.5rem !important;
    }

    /* Dashboard on mobile */
    .dashboard-title {
        font-size: 1.75rem !important;
        margin-top: 0.5rem !important;
        margin-bottom: 1rem !important;
    }

    .dashboard-card {
        margin-bottom: 1rem !important;
    }

    .dashboard-card-header-title {
        font-size: 1.1rem !important;
    }

    .dashboard-table {
        font-size: 0.85rem !important;
    }

    .dashboard-table th,
    .dashboard-table td {
        padding: 0.5rem 0.25rem !important;
    }

    .dashboard-table th:first-child,
    .dashboard-table td:first-child {
        display: none; /* Hide PO # on mobile */
    }

    .inventory-value-header {
        font-size: 1rem !important;
    }

    /* Hide chart on mobile to save space */
    .dashboard-card-body .mb-4 {
        display: none !important;
    }
}
}

    /* Simplified mobile tables */
    .mobile-materials-table,
    .mobile-products-table {
        width: 100%;
        min-width: 100%;
    }

    /* Total materials card */
    .total-materials-card {
        font-size: 0.85rem;
        padding: 0.75rem;
    }

    /* Material info displays */
    .material-link {
        font-size: 0.85rem;
    }

    /* Expandable table rows */
    .parent-row {
        cursor: pointer;
    }

    .detail-row td {
        padding: 0 !important;
    }

    /* PDF Export buttons */
    .ms-auto {
        margin-top: 0.5rem;
        width: 100%;
    }

    .ms-auto button {
        width: 100%;
    }

    /* Login display */
    .login-display {
        padding: 1rem 1.5rem;
        border-top: 1px solid var(--border-color);
    }
}

/* ===================================
   LANDSCAPE ORIENTATION (TABLETS)
   =================================== */

@media (min-width: 481px) and (max-width: 768px) and (orientation: landscape) {
    .sidebar-container {
        width: 200px !important;
        position: relative;
        max-height: none;
    }

    main {
        margin-top: 0;
    }

    .page {
        flex-direction: row;
    }

    .nav-toggler {
        display: none !important;
    }

    .nav-menu {
        display: flex !important;
    }
}

/* ===================================
   TOUCH INTERACTIONS
   =================================== */

@media (hover: none) and (pointer: coarse) {
    /* Larger touch targets */
    button,
    a,
    .nav-link,
    .btn {
        min-height: 44px;
        min-width: 44px;
    }

    /* Remove hover effects on touch devices */
    .btn-primary-themed:hover,
    .btn-secondary-themed:hover,
    .btn-edit-themed:hover {
        transform: none;
    }

    /* Increase tap area for table rows */
    .data-table tr {
        cursor: pointer;
    }
}

/* ===================================
   ACCESSIBILITY IMPROVEMENTS
   =================================== */

@media (max-width: 768px) {
    /* Ensure text is readable */
    body {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }

    /* Focus indicators */
    *:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }

    /* Skip link for accessibility */
    .skip-link {
        position: absolute;
        top: -40px;
        left: 0;
        background: var(--primary-color-darker);
        color: white;
        padding: 8px;
        z-index: 100;
    }

    .skip-link:focus {
        top: 0;
    }
}

/* ===================================
   PRINT STYLES
   =================================== */

@media print {
    .sidebar-container,
    .nav-toggler,
    .action-bar,
    .pagination-container,
    button,
    .btn {
        display: none !important;
    }

    main {
        margin: 0;
        padding: 0;
    }

    .content-card {
        box-shadow: none;
        border: 1px solid #000;
    }

    .data-table {
        font-size: 10pt;
    }
}
