/**
 * Pharma Edge - Mobile PWA Enhancements
 * Touch-friendly, responsive styles for mobile devices
 */

/* ===========================
   CSS CUSTOM PROPERTIES FOR MOBILE
   =========================== */
:root {
    /* Safe area insets for notched devices */
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-left: env(safe-area-inset-left, 0px);
    --safe-area-right: env(safe-area-inset-right, 0px);
    
    /* Touch-friendly sizing */
    --touch-target-min: 44px;
    --touch-spacing: 8px;
    
    /* Mobile typography */
    --mobile-font-base: 16px;
    --mobile-font-sm: 14px;
    --mobile-font-lg: 18px;
}

/* ===========================
   VIEWPORT & SAFE AREAS
   =========================== */
@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-top: var(--safe-area-top);
        padding-bottom: var(--safe-area-bottom);
        padding-left: var(--safe-area-left);
        padding-right: var(--safe-area-right);
    }
    
    /* Fixed headers need safe area */
    .navbar-fixed, 
    .fixed-top,
    header.fixed,
    .navbar {
        padding-top: var(--safe-area-top);
    }

    /* Sticky headers need safe area offset so they don't hide behind the status bar */
    .top-bar {
        top: var(--safe-area-top);
        z-index: 1060;
        position: sticky;
    }
    
    /* Fixed footers/bottom bars */
    .fixed-bottom,
    .pos-bottom-bar,
    .mobile-bottom-nav {
        padding-bottom: var(--safe-area-bottom);
    }
}

/* ===========================
   TOUCH-FRIENDLY ELEMENTS
   =========================== */

/* Minimum touch target size (44x44px per Apple HIG) */
.btn,
.nav-link,
.dropdown-item,
.list-group-item {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
}

/* Better touch feedback */
@media (hover: none) and (pointer: coarse) {
    .btn {
        transition: transform 0.1s ease, opacity 0.1s ease;
    }
    
    .btn:active {
        transform: scale(0.97);
        opacity: 0.9;
    }
    
    /* Remove hover states on touch devices */
    .btn:hover {
        transform: none;
    }
    
    /* Larger click areas for links */
    a {
        padding: 4px;
        margin: -4px;
    }
}

/* ===========================
   MOBILE FORMS
   =========================== */
@media (max-width: 768px) {
    /* Prevent zoom on input focus (iOS) */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="search"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
    
    /* Larger form controls */
    .form-control,
    .form-select {
        padding: 12px 16px;
        font-size: 16px;
        border-radius: 10px;
    }
    
    /* Better checkbox/radio sizing for touch devices */
    input[type="checkbox"],
    input[type="radio"],
    .form-check-input {
        min-height: 24px;
        min-width: 24px;
        width: 24px;
        height: 24px;
    }
    
    .form-check-label {
        padding-left: 8px;
        font-size: 16px;
    }
    
    /* Stack form labels on mobile */
    .form-label {
        font-size: 14px;
        font-weight: 600;
        margin-bottom: 6px;
    }
}

/* ===========================
   MOBILE NAVIGATION
   =========================== */
@media (max-width: 768px) {
    /* Full-width navbar items */
    .navbar-nav {
        width: 100%;
    }
    
    .navbar-nav .nav-link {
        padding: 14px 20px;
        font-size: 16px;
        border-bottom: 1px solid var(--border-light);
    }
    
    /* Mobile hamburger menu */
    .navbar-toggler {
        padding: 10px;
        border: none;
    }
    
    .navbar-toggler:focus {
        box-shadow: none;
        outline: 2px solid var(--primary-lighter);
        outline-offset: 2px;
    }
}

/* ===========================
   BOTTOM NAVIGATION BAR (Mobile)
   =========================== */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-light);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.1);
    z-index: 1050;
    padding-bottom: var(--safe-area-bottom);
}

@media (max-width: 768px) {
    .mobile-bottom-nav {
        display: flex;
        justify-content: space-around;
        align-items: stretch;
    }
    
    /* Add padding to body to prevent content hiding */
    body.has-bottom-nav {
        padding-bottom: calc(70px + var(--safe-area-bottom));
    }
}

.mobile-bottom-nav .nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 8px 4px;
    min-height: 60px;
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.2s ease;
}

.mobile-bottom-nav .nav-item.active {
    color: var(--primary);
}

.mobile-bottom-nav .nav-item .nav-icon {
    font-size: 22px;
    margin-bottom: 4px;
}

.mobile-bottom-nav .nav-item .nav-label {
    font-size: 11px;
    font-weight: 500;
}

/* ===========================
   MOBILE CARDS & LISTS
   =========================== */
@media (max-width: 768px) {
    .card {
        border-radius: 12px;
        margin-bottom: 12px;
    }
    
    .card-body {
        padding: 16px;
    }
    
    .card-header {
        padding: 14px 16px;
    }
    
    /* Swipeable list items */
    .list-group-item {
        padding: 14px 16px;
        border-left: none;
        border-right: none;
    }
    
    .list-group-item:first-child {
        border-top: none;
    }
}

/* ===========================
   MOBILE TABLES (Responsive)
   =========================== */
@media (max-width: 768px) {
    /* Card-style tables on mobile */
    .table-mobile-cards {
        border: none;
    }
    
    .table-mobile-cards thead {
        display: none;
    }
    
    .table-mobile-cards tbody tr {
        display: block;
        margin-bottom: 12px;
        background: var(--bg-card);
        border-radius: 10px;
        box-shadow: var(--shadow-sm);
        padding: 12px;
    }
    
    .table-mobile-cards tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border: none;
        border-bottom: 1px solid var(--border-light);
    }
    
    .table-mobile-cards tbody td:last-child {
        border-bottom: none;
    }
    
    .table-mobile-cards tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        font-size: 13px;
    }
    
    /* Horizontal scroll for complex tables */
    .table-responsive-mobile {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }
}

/* ===========================
   MOBILE MODALS & SHEETS
   =========================== */
@media (max-width: 768px) {
    /* Bottom sheet style modals */
    .modal-mobile-sheet .modal-dialog {
        margin: 0;
        max-width: 100%;
        height: auto;
        max-height: 90vh;
    }
    
    .modal-mobile-sheet .modal-content {
        border: none;
        border-radius: 20px 20px 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
    }
    
    .modal-mobile-sheet .modal-header {
        border-radius: 20px 20px 0 0;
        padding: 16px 20px;
    }
    
    /* Sheet drag indicator */
    .modal-mobile-sheet .modal-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--border-default);
        border-radius: 2px;
    }
    
    .modal-mobile-sheet .modal-body {
        max-height: 60vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Full-screen modals on mobile */
    .modal-fullscreen-mobile .modal-dialog {
        margin: 0;
        max-width: 100%;
        width: 100%;
        height: 100%;
    }
    
    .modal-fullscreen-mobile .modal-content {
        height: 100%;
        border: none;
        border-radius: 0;
    }
}

/* ===========================
   MOBILE BUTTONS
   =========================== */
@media (max-width: 768px) {
    .btn {
        padding: 12px 20px;
        font-size: 16px;
        border-radius: 10px;
    }
    
    .btn-sm {
        padding: 10px 16px;
        font-size: 14px;
    }
    
    .btn-lg {
        padding: 16px 28px;
        font-size: 18px;
    }
    
    /* Full-width buttons on mobile */
    .btn-block-mobile {
        width: 100%;
        display: block;
    }
    
    /* Floating action button */
    .fab {
        position: fixed;
        bottom: calc(80px + var(--safe-area-bottom));
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 1040;
    }
    
    .fab i {
        font-size: 24px;
    }
}

/* ===========================
   POS MOBILE OPTIMIZATIONS
   =========================== */
@media (max-width: 768px) {
    /* Stack POS layout vertically */
    .pos-container {
        flex-direction: column;
    }
    
    .pos-products,
    .pos-cart {
        width: 100%;
        height: auto;
    }
    
    /* Smaller product cards grid */
    .pos-products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
        padding: 8px;
    }
    
    .pos-product-card {
        padding: 10px;
    }
    
    .pos-product-card .product-name {
        font-size: 13px;
        line-height: 1.3;
    }
    
    .pos-product-card .product-price {
        font-size: 14px;
    }
    
    /* Fixed cart at bottom */
    .pos-cart-mobile {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-surface);
        border-top: 1px solid var(--border-light);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
        z-index: 1000;
        padding-bottom: var(--safe-area-bottom);
    }
    
    /* Collapsible cart */
    .pos-cart-summary {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 12px 16px;
        cursor: pointer;
    }
    
    .pos-cart-items {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .pos-cart-mobile.expanded .pos-cart-items {
        max-height: 50vh;
        overflow-y: auto;
    }
}

/* ===========================
   PULL TO REFRESH
   =========================== */
.pull-to-refresh {
    position: absolute;
    top: -50px;
    left: 0;
    right: 0;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
}

.pull-to-refresh .spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-light);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ===========================
   MOBILE SEARCH
   =========================== */
@media (max-width: 768px) {
    .search-mobile {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1060;
        background: var(--bg-surface);
        padding: 12px 16px;
        padding-top: calc(12px + var(--safe-area-top));
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        transform: translateY(-100%);
        transition: transform 0.3s ease;
    }
    
    .search-mobile.active {
        transform: translateY(0);
    }
    
    .search-mobile .form-control {
        padding-left: 44px;
        padding-right: 44px;
    }
    
    .search-mobile .search-icon {
        position: absolute;
        left: 28px;
        top: 50%;
        transform: translateY(-50%);
        color: var(--text-muted);
    }
    
    .search-mobile .search-close {
        position: absolute;
        right: 28px;
        top: 50%;
        transform: translateY(-50%);
        background: none;
        border: none;
        color: var(--text-muted);
        padding: 8px;
    }
}

/* ===========================
   MOBILE NOTIFICATIONS/TOASTS
   =========================== */
@media (max-width: 768px) {
    .toast-container {
        bottom: calc(80px + var(--safe-area-bottom)) !important;
        left: 16px !important;
        right: 16px !important;
    }
    
    .toast {
        width: 100%;
        border-radius: 12px;
    }
}

/* ===========================
   SWIPE GESTURES SUPPORT
   =========================== */
.swipe-container {
    touch-action: pan-y;
    overflow-x: hidden;
}

.swipe-item {
    position: relative;
    overflow: hidden;
}

.swipe-item .swipe-actions {
    position: absolute;
    top: 0;
    bottom: 0;
    right: 0;
    display: flex;
    transform: translateX(100%);
    transition: transform 0.2s ease;
}

.swipe-item.swiped .swipe-actions {
    transform: translateX(0);
}

.swipe-action-btn {
    width: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
}

.swipe-action-btn.delete {
    background: var(--danger);
}

.swipe-action-btn.edit {
    background: var(--primary);
}

/* ===========================
   INSTALL PROMPT BANNER
   =========================== */
.pwa-install-banner {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg-surface);
    padding: 16px;
    padding-bottom: calc(16px + var(--safe-area-bottom));
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
    z-index: 1100;
    display: none;
    border-top: 1px solid var(--border-light);
}

.pwa-install-banner.show {
    display: block;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.pwa-install-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.pwa-install-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    flex-shrink: 0;
}

.pwa-install-text {
    flex: 1;
}

.pwa-install-text h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.pwa-install-text p {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--text-muted);
}

.pwa-install-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ===========================
   PWA INSTALL MODAL
   =========================== */
.pwa-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1200;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.pwa-modal-overlay.show {
    display: flex;
    animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.pwa-modal {
    background: var(--bg-surface, #fff);
    border-radius: 20px;
    max-width: 380px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
    animation: modalSlideUp 0.3s ease;
}

@keyframes modalSlideUp {
    from {
        transform: translateY(30px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.pwa-modal-header {
    text-align: center;
    padding: 28px 24px 16px;
    position: relative;
    background: linear-gradient(135deg, #173269 0%, #1a4a9e 100%);
    color: #fff;
}

.pwa-modal-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    font-size: 22px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background 0.2s;
}

.pwa-modal-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.pwa-modal-app-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: #fff;
    padding: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    margin-bottom: 12px;
}

.pwa-modal-header h3 {
    margin: 0 0 4px;
    font-size: 20px;
    font-weight: 700;
}

.pwa-modal-header p {
    margin: 0;
    font-size: 14px;
    opacity: 0.85;
}

.pwa-modal-body {
    padding: 20px 24px 24px;
}

.pwa-features {
    list-style: none;
    margin: 0 0 20px;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.pwa-features li {
    display: flex;
    align-items: center;
    gap: 14px;
    font-size: 15px;
    color: var(--text-primary, #1f2937);
}

.pwa-feat-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.pwa-feat-icon.speed {
    background: #fff3e0;
    color: #e65100;
}

.pwa-feat-icon.offline {
    background: #e3f2fd;
    color: #1565c0;
}

.pwa-feat-icon.notify {
    background: #f3e5f5;
    color: #7b1fa2;
}

[data-theme="dark"] .pwa-feat-icon.speed {
    background: rgba(230, 81, 0, 0.15);
}

[data-theme="dark"] .pwa-feat-icon.offline {
    background: rgba(21, 101, 192, 0.15);
}

[data-theme="dark"] .pwa-feat-icon.notify {
    background: rgba(123, 31, 162, 0.15);
}

.pwa-modal-actions {
    display: flex;
    gap: 10px;
}

.pwa-btn {
    flex: 1;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.pwa-btn-later {
    background: var(--bg-surface-secondary, #f3f4f6);
    color: var(--text-secondary, #6b7280);
}

.pwa-btn-later:hover {
    background: var(--bg-surface-hover, #e5e7eb);
}

.pwa-btn-install {
    background: linear-gradient(135deg, #173269 0%, #1a4a9e 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(23, 50, 105, 0.3);
}

.pwa-btn-install:hover {
    box-shadow: 0 6px 20px rgba(23, 50, 105, 0.4);
    transform: translateY(-1px);
}

.pwa-btn-install:active {
    transform: translateY(0);
}

/* ===========================
   SKELETON LOADING (Mobile)
   =========================== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-surface-secondary) 25%, var(--bg-surface-hover) 50%, var(--bg-surface-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.skeleton-text {
    height: 16px;
    margin-bottom: 8px;
}

.skeleton-text.sm {
    height: 12px;
    width: 60%;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.skeleton-card {
    height: 120px;
    border-radius: 10px;
}

/* ===========================
   HAPTIC FEEDBACK INDICATOR
   =========================== */
@media (max-width: 768px) {
    .haptic-feedback {
        position: relative;
    }
    
    .haptic-feedback::after {
        content: '';
        position: absolute;
        inset: 0;
        background: var(--primary);
        opacity: 0;
        border-radius: inherit;
        pointer-events: none;
        transition: opacity 0.1s ease;
    }
    
    .haptic-feedback:active::after {
        opacity: 0.1;
    }
}

/* ===========================
   LANDSCAPE MODE ADJUSTMENTS
   =========================== */
@media (max-height: 500px) and (orientation: landscape) {
    .mobile-bottom-nav {
        flex-direction: column;
        width: 70px;
        height: 100%;
        bottom: auto;
        top: 0;
        left: 0;
        right: auto;
        border-top: none;
        border-right: 1px solid var(--border-light);
    }
    
    body.has-bottom-nav {
        padding-bottom: 0;
        padding-left: 70px;
    }
    
    .pos-products-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===========================
   DARK MODE MOBILE ADJUSTMENTS
   =========================== */
[data-theme="dark"] .mobile-bottom-nav {
    background: var(--bg-surface);
    border-color: var(--border-light);
}

[data-theme="dark"] .pwa-install-banner {
    background: var(--bg-surface);
    border-color: var(--border-light);
}

[data-theme="dark"] .search-mobile {
    background: var(--bg-surface);
}

/* ===========================
   GLOBAL RESPONSIVE CONTAINERS
   =========================== */
@media (max-width: 992px) {
    /* Master admin sidebar responsive */
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1050;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    /* Shift main content when sidebar hidden */
    .main-content {
        margin-left: 0 !important;
        padding: 16px !important;
    }
    
    /* Sidebar overlay — start below the top-bar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: calc(68px + var(--safe-area-top, 0px));
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1040;
    }
    
    .sidebar.open ~ .sidebar-overlay,
    .sidebar-overlay.active {
        display: block;
    }
    
    /* Stats grid tablet — 2 columns */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }
    
    /* Plans grid */
    .plans-grid {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)) !important;
    }
}

@media (max-width: 768px) {
    /* ---- Body & Container ---- */
    body {
        padding: 12px !important;
    }
    
    .container {
        max-width: 100% !important;
        padding: 0 !important;
    }
    
    /* ---- Page Headers ---- */
    .header,
    .page-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
        padding: 16px !important;
        border-radius: 10px;
    }
    
    .header h1,
    .page-header h1,
    .header h2,
    .page-header h2 {
        font-size: 1.3rem !important;
    }
    
    .header-left {
        flex-wrap: wrap;
        gap: 10px !important;
    }
    
    .header-actions {
        flex-wrap: wrap;
        gap: 8px !important;
        width: 100%;
    }
    
    .header-actions .btn {
        flex: 1;
        min-width: 0;
        text-align: center;
    }
    
    /* ---- Stats Grid Mobile — single column ---- */
    .stats-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
    
    .stat-card {
        padding: 14px !important;
    }
    
    .stat-card .stat-value,
    .stat-card .value {
        font-size: 1.4rem !important;
    }
    
    .stat-card .stat-label,
    .stat-card .label {
        font-size: 0.8rem !important;
    }
    
    /* ---- Filter Bars ---- */
    .filters,
    .filter-bar {
        flex-direction: column !important;
        gap: 8px !important;
    }
    
    .filters input,
    .filters select,
    .filter-bar input,
    .filter-bar select {
        width: 100% !important;
    }
    
    /* ---- Tables (auto responsive) ---- */
    table {
        font-size: 13px;
    }
    
    /* Make all tables horizontally scrollable */
    .card-body,
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Hide less important columns on mobile */
    table th:nth-child(n+5),
    table td:nth-child(n+5) {
        display: none;
    }
    
    /* But show action columns (usually last) */
    table th:last-child,
    table td:last-child {
        display: table-cell;
    }
    
    table th,
    table td {
        padding: 10px 8px !important;
        white-space: nowrap;
    }
    
    /* ---- Cards ---- */
    .card-header {
        flex-direction: column !important;
        gap: 10px;
    }
    
    /* ---- Plans Grid ---- */
    .plans-grid {
        grid-template-columns: 1fr !important;
    }
    
    .plan-card {
        margin-bottom: 12px;
    }
    
    .plan-stats {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* ---- Modal Adjustments ---- */
    .modal {
        padding: 12px !important;
    }
    
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 12px !important;
    }
    
    /* ---- Pagination ---- */
    .pagination {
        flex-wrap: wrap;
        justify-content: center;
        gap: 4px;
    }
    
    .pagination .page-link {
        padding: 8px 12px;
        font-size: 13px;
    }
    
    /* ---- Alerts ---- */
    .alert {
        font-size: 14px;
        padding: 12px 14px;
        border-radius: 10px;
    }
    
    /* ---- Empty State ---- */
    .empty-state {
        padding: 40px 20px !important;
    }
    
    .empty-state i {
        font-size: 48px !important;
    }
    
    /* ---- Nav Tabs ---- */
    .nav-tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .nav-tabs::-webkit-scrollbar {
        display: none;
    }
    
    .nav-tabs .nav-link {
        white-space: nowrap;
        padding: 10px 16px;
        font-size: 14px;
    }
    
    /* ---- Badges ---- */
    .badge {
        font-size: 11px;
        padding: 4px 8px;
    }
    
    /* ---- Breadcrumbs ---- */
    .breadcrumb {
        font-size: 13px;
        flex-wrap: wrap;
        padding: 8px 0;
    }
    
    /* ---- Action Buttons (in tables/cards) ---- */
    .action-buttons,
    .btn-group {
        flex-wrap: wrap;
        gap: 4px;
    }
    
    .action-buttons .btn,
    .btn-group .btn {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
    
    /* ---- Form Layouts ---- */
    .form-row,
    .row {
        flex-direction: column !important;
    }
    
    .form-row > [class*="col"],
    .row > [class*="col"] {
        width: 100% !important;
        max-width: 100% !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }
    
    /* ---- Sidebar (mobile off-canvas) ---- */
    .sidebar {
        position: fixed !important;
        width: 260px !important;
        /* Sit below the top-bar header (68px + safe area) */
        top: calc(68px + var(--safe-area-top, 0px)) !important;
        height: calc(100vh - 68px - var(--safe-area-top, 0px)) !important;
        left: 0;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1050;
        box-shadow: none;
        overflow-y: auto;
    }
    
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.15);
    }
    
    /* ---- Mobile cards alternative (show on mobile) ---- */
    .mobile-cards {
        display: block !important;
    }
    
    /* ---- Finance-specific ---- */
    .account-tree,
    .chart-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* ---- Report layout ---- */
    .report-header {
        flex-direction: column !important;
        gap: 12px;
    }
    
    .report-filters {
        flex-direction: column !important;
        gap: 8px;
    }
    
    /* ---- Delivery / Transfer grid ---- */
    .transfer-grid,
    .delivery-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* ---- Two-column details ---- */
    .detail-grid,
    .info-grid,
    .details-grid {
        grid-template-columns: 1fr !important;
    }
    
    /* ---- Customer/Supplier Detail ---- */
    .detail-header {
        flex-direction: column !important;
        text-align: center;
    }
    
    .detail-header .avatar {
        margin: 0 auto 12px;
    }
}

/* ===========================
   SMALL PHONES (480px and below)
   =========================== */
@media (max-width: 480px) {
    body {
        padding: 8px !important;
    }
    
    .header,
    .page-header {
        padding: 12px !important;
    }
    
    .header h1,
    .page-header h1 {
        font-size: 1.1rem !important;
    }
    
    .stat-card {
        padding: 10px !important;
    }
    
    .stat-card .stat-value,
    .stat-card .value {
        font-size: 1.2rem !important;
    }
    
    .card-body {
        padding: 12px !important;
    }
    
    .card-header {
        padding: 10px 12px !important;
    }
    
    table th,
    table td {
        padding: 8px 6px !important;
        font-size: 12px;
    }
    
    /* Hide more columns on very small screens */
    table th:nth-child(n+4),
    table td:nth-child(n+4) {
        display: none;
    }
    
    table th:last-child,
    table td:last-child {
        display: table-cell;
    }
    
    .btn {
        padding: 10px 14px !important;
        font-size: 13px !important;
    }
    
    .btn-sm {
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
    
    /* Stack action buttons vertically */
    .header-actions {
        flex-direction: column !important;
    }
    
    .header-actions .btn {
        width: 100%;
    }
    
    /* Plans grid */
    .plan-stats {
        grid-template-columns: 1fr !important;
    }
    
    /* Modal - fully full screen */
    .modal-content {
        border-radius: 0 !important;
        min-height: 100vh;
    }
}

/* ===========================
   TABLET LANDSCAPE (769px - 1024px)
   =========================== */
@media (min-width: 769px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    .plans-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    
    /* Tables: hide 6th+ columns */
    table th:nth-child(n+6),
    table td:nth-child(n+6) {
        display: none;
    }
    
    table th:last-child,
    table td:last-child {
        display: table-cell;
    }
}

/* ===========================
   PRINT MEDIA (Hide Mobile Elements)
   =========================== */
@media print {
    .mobile-bottom-nav,
    .pwa-install-banner,
    .fab,
    .search-mobile,
    .sidebar-overlay {
        display: none !important;
    }
    
    /* Reset all mobile-specific styles for print */
    .main-content {
        margin-left: 0 !important;
    }
    
    table th,
    table td {
        display: table-cell !important;
    }
}
