/* --- Mobile Responsive Reset & Variables --- */
:root {
    --sidebar-width: 260px;
    --primary-color: #4f46e5;
    --bg-light: #f8fafc;
}

/* --- Media Queries for Mobile (Under 768px) --- */
@media (max-width: 768px) {
    /* --- Layout Adjustments --- */
    body.sidebar-open {
        overflow: hidden; /* Prevent scrolling when menu is open */
    }

    .main {
        transition: margin-left 0.3s ease;
        padding: 10px;
        padding-bottom: 90px !important;
        width: 100%;
        box-sizing: border-box;
        margin-left: 0 !important;
        padding-top: 20px;
        overflow-x: hidden;
        overflow-y: auto !important;
        height: 100dvh !important;
        -webkit-overflow-scrolling: touch;
    }

    /* --- Hamburger Menu Button --- */
    .mobile-menu-toggle {
        display: block;
        position: fixed;
        top: 15px;
        left: 15px;
        z-index: 1001;
        background: var(--primary-color);
        border: none;
        border-radius: 8px;
        padding: 8px 10px;
        cursor: pointer;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }

    .hamburger {
        width: 22px;
        height: 2px;
        background-color: white;
        margin: 4px 0;
        transition: 0.3s;
    }

    /* --- Sidebar Mobile States --- */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: min(var(--sidebar-width), 85vw);
        height: 100dvh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        background: white;
        box-shadow: 2px 0 10px rgba(0,0,0,0.1);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        display: flex;
        flex-direction: column;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar .sidebar-header {
        position: sticky;
        top: 0;
        z-index: 2;
        flex-shrink: 0;
    }

    .sidebar .sidebar-user {
        margin-top: auto;
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
        z-index: 999;
    }

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

    /* --- Resource Tabs (Horizontal Scroll on Mobile) --- */
    .resource-tabs {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        gap: 8px !important;
        padding: 12px !important;
        margin-bottom: 20px;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: thin;
        background: white;
        border-radius: 12px;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }

    .resource-tabs::-webkit-scrollbar {
        height: 6px;
    }

    .resource-tabs::-webkit-scrollbar-track {
        background: #f1f5f9;
        border-radius: 10px;
    }

    .resource-tabs::-webkit-scrollbar-thumb {
        background: linear-gradient(135deg, #cbd5e1 0%, #94a3b8 100%);
        border-radius: 10px;
    }

    /* Show tab buttons with vertical layout on mobile */
    .tab-btn {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 6px !important;
        flex-shrink: 0 !important;
        min-width: 70px !important;
        padding: 10px 12px !important;
        background: transparent;
        border: 2px solid transparent;
        color: #64748b;
        border-radius: 10px;
        cursor: pointer;
        font-weight: 600;
        transition: all 0.3s;
    }

    .tab-btn span:first-child {
        font-size: 20px;
    }

    .tab-btn span:last-child {
        font-size: 11px;
        white-space: nowrap;
    }

    .tab-btn:hover {
        background: #f8fafc;
        color: #3b82f6;
    }

    .tab-btn.active {
        background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
        color: white;
        border-color: transparent;
        box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
    }

    .tab-dropdown {
        display: none;
    }

    /* --- Responsive Grid --- */
    .resource-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(100%, 1fr)); /* Stack on small screens */
        gap: 15px;
    }

    /* --- Modals (Full screen on mobile) --- */
    .modal-content {
        width: 95% !important;
        margin: 10px auto;
        padding: 20px;
        border-radius: 12px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .page-header h1 {
        font-size: 1.5rem;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .add-buttons-group {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        width: 100% !important;
        gap: 10px !important;
    }

    .add-btn {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        padding: 12px 8px !important;
        white-space: normal !important;
        min-width: auto !important;
        width: 100% !important;
    }

    .add-btn .btn-icon {
        font-size: 28px !important;
    }

    .add-btn .btn-text {
        font-size: 12px !important;
        font-weight: 600 !important;
        text-align: center !important;
    }

    /* Adjust resource card styling for mobile */
    .resource-card {
        padding: 15px;
    }

    /* --- Statistics Page Mobile Styles --- */
    .page-header {
        padding: 16px 14px !important;
        margin-bottom: 12px !important;
        border-radius: 12px !important;
    }

    .page-header h1 {
        font-size: 20px !important;
        margin-bottom: 6px !important;
    }

    .subtitle {
        font-size: 12px !important;
        line-height: 1.4 !important;
    }

    /* Stat cards — single column on mobile */
    .stats-overview,
    .shimmer-stats {
        grid-template-columns: 1fr  !important;
        gap: 10px !important;
    }

    /* Analytics Section Mobile */
    .analytics-section {
        padding: 12px 10px !important;
        margin-top: 12px !important;
        border-radius: 12px !important;
        overflow: visible !important;
    }

    .section-header {
        text-align: left !important;
        margin-bottom: 12px !important;
        padding-bottom: 12px !important;
    }

    .section-header h2 {
        font-size: 15.9px !important;
        margin-bottom: 4px !important;
    }

    .section-header p {
        font-size: 12px !important;
        margin: 0 !important;
    }

    /* Search & filter controls */
    #analyticsContent input[type="text"],
    #analyticsContent select {
        width: 100% !important;
        box-sizing: border-box !important;
        font-size: 14px !important;
    }

    /* Records count */
    #analyticsContent [style*="text-align: right"],
    #analyticsContent [style*="text-align:right"] {
        font-size: 12px !important;
    }

    /* Table wrapper — allow horizontal scroll so nothing gets cut */
    .table-wrapper,
    #analyticsContent .table-wrapper {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        border-radius: 10px !important;
        margin: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Shimmer wrapper — no scroll needed since columns are hidden */
    #analyticsShimmer .table-wrapper {
        overflow-x: hidden !important;
    }

    /* Table itself — fixed min-width so columns don't collapse */
    .modern-table,
    #analyticsContent .modern-table {
        min-width: 420px !important;
        width: 100% !important;
        font-size: 12px !important;
        table-layout: auto !important;
    }

    /* Shimmer table — no min-width, hide extra columns to match real table */
    #analyticsShimmer .modern-table {
        min-width: unset !important;
        width: 100% !important;
        table-layout: fixed !important;
    }
    #analyticsShimmer .modern-table thead tr th:nth-child(2),
    #analyticsShimmer .modern-table tbody tr td:nth-child(2),
    #analyticsShimmer .modern-table thead tr th:nth-child(4),
    #analyticsShimmer .modern-table tbody tr td:nth-child(4) {
        display: none !important;
    }

    .modern-table th,
    .modern-table td,
    #analyticsContent .modern-table th,
    #analyticsContent .modern-table td {
        padding: 10px 8px !important;
        font-size: 11px !important;
        white-space: nowrap !important;
    }

    /* Email column — allow wrap so it doesn't push table too wide */
    .customer-email {
        white-space: normal !important;
        word-break: break-all !important;
        max-width: 130px !important;
        font-size: 11px !important;
        font-weight: 600 !important;
        color: #1e293b !important;
        display: block !important;
        line-height: 1.3 !important;
    }

    .th-content {
        font-size: 10px !important;
        gap: 3px !important;
    }

    /* Customer Info Mobile */
    .customer-info {
        display: flex !important;
        align-items: flex-start !important;
        gap: 6px !important;
    }

    .customer-details {
        min-width: 0 !important;
    }

    .customer-id {
        font-size: 9px !important;
        color: #64748b !important;
    }

    .quantity-badge {
        background: #dbeafe !important;
        color: #3b82f6 !important;
        padding: 3px 7px !important;
        border-radius: 10px !important;
        font-size: 11px !important;
        font-weight: 600 !important;
        white-space: nowrap !important;
    }

    .amount-value {
        font-size: 12px !important;
        font-weight: 700 !important;
        color: #10b981 !important;
        white-space: nowrap !important;
    }

    /* Status badge */
    .status-badge,
    [class*="status"] {
        font-size: 10px !important;
        padding: 3px 7px !important;
        white-space: nowrap !important;
    }

    /* View button */
    .eye-btn {
        width: 52px !important;
        height: 26px !important;
        font-size: 10px !important;
    }

    .resources-list {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 3px !important;
    }

    .resource-tag {
        background: #f1f5f9 !important;
        color: #475569 !important;
        padding: 2px 5px !important;
        border-radius: 6px !important;
        font-size: 9px !important;
        font-weight: 500 !important;
        max-width: 100px !important;
        overflow: visible !important;
        text-overflow: ellipsis !important;
        white-space: nowrap !important;
    }

    .resource-tag.more {
        background: #fef3c7 !important;
        color: #d97706 !important;
    }

    /* Withdrawal button in header */
    .page-header a[href*="Withdrawal"] {
        font-size: 12px !important;
        padding: 8px 14px !important;
        white-space: nowrap !important;
    }
}

/* --- Media Queries for very small screens (Under 480px) --- */
@media (max-width: 480px) {
    .add-buttons-group {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .add-btn {
        padding: 10px 6px !important;
    }

    .add-btn .btn-icon {
        font-size: 24px !important;
    }

    .add-btn .btn-text {
        font-size: 11px !important;
    }
}

/* ── Dark mode overrides for mobile-responsive hardcoded colors ── */
html.dark-mode .customer-email,
body.dark-mode .customer-email {
  color: #c9d1d9 !important;
}
html.dark-mode .customer-id,
body.dark-mode .customer-id {
  color: #484f58 !important;
}
html.dark-mode .quantity-badge,
body.dark-mode .quantity-badge {
  background: rgba(124,106,247,0.15) !important;
  color: #a78bfa !important;
}
html.dark-mode .amount-value,
body.dark-mode .amount-value {
  color: #3fb950 !important;
}
html.dark-mode .resource-tag,
body.dark-mode .resource-tag {
  background: #1c2333 !important;
  color: #a78bfa !important;
}
html.dark-mode .resource-tag.more,
body.dark-mode .resource-tag.more {
  background: rgba(124,106,247,0.15) !important;
  color: #a78bfa !important;
}
html.dark-mode .resource-tabs,
body.dark-mode .resource-tabs {
  background: #161b22 !important;
  border-color: #30363d !important;
}
html.dark-mode .customer-avatar,
body.dark-mode .customer-avatar {
  background: #1c2333 !important;
  color: #8b949e !important;
}