/* ============================================
   GOLD APP - MOBILE RESPONSIVE CSS
   ============================================ */

/* ===== ROOT & TYPOGRAPHY ===== */
:root {
    --primary-yellow: #eab308;
    --dark-yellow: #ca8a04;
    --text-dark: #1a1a1a;
    --text-light: #666;
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* ===== GLOBAL MOBILE FIXES ===== */
* {
    touch-action: manipulation;
}

body {
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
    overflow-x: hidden;
}

/* Ensure proper viewport on mobile */
html, body {
    width: 100%;
    max-width: 100%;
}

/* ===== BUTTON SIZING FOR TOUCH ===== */
button, a.btn, .btn-like {
    min-height: 44px;
    padding: 10px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
}

@media (max-width: 768px) {
    button, a.btn, .btn-like, input[type="button"], input[type="submit"] {
        min-height: 44px;
        padding: 10px 14px;
    }
}

/* ===== INPUT SIZING ===== */
input, textarea, select {
    font-size: 16px; /* Prevents zoom on iOS */
    min-height: 44px;
}

@media (min-width: 768px) {
    input, textarea, select {
        min-height: auto;
    }
}

/* ===== TABLE RESPONSIVE ===== */
/* Wrapper for automatic responsive table scroll */
.responsive-table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch; /* Smooth kinetic scrolling on iOS */
    margin-bottom: 1.5rem;
    position: relative;
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: #cbd5e1 #f1f5f9; /* Firefox */
}

/* Custom scrollbars for WebKit browsers (Chrome, Safari, Edge) */
.responsive-table-wrapper::-webkit-scrollbar {
    height: 6px;
}
.responsive-table-wrapper::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}
.responsive-table-wrapper::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}
.responsive-table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Base table style adjustments for responsiveness */
table {
    width: 100%;
    border-collapse: collapse;
}

/* Ensure table header and data alignments look clean on mobile scroll */
@media (max-width: 768px) {
    /* Fallback: Make all tables scrollable even if JS dynamic wrapping fails or is not present */
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Reset if wrapped inside our premium wrapper so it doesn't double-scroll */
    .responsive-table-wrapper table {
        display: table;
        overflow-x: visible;
    }

    /* Prevent table columns from squishing so layout is fully readable */
    .responsive-table-wrapper table:not([class*="min-w-"]) {
        min-width: 750px; /* Standard readable table width on mobile */
    }
    
    .responsive-table-wrapper table {
        width: 100%;
        table-layout: auto;
    }
    
    /* Ensure no text wraps awkwardly within headers and cells */
    .responsive-table-wrapper th,
    .responsive-table-wrapper td {
        white-space: nowrap;
        padding: 8px 12px !important;
        font-size: 13px !important;
    }
}


/* ===== GRID RESPONSIVE ===== */
.grid {
    gap: 12px;
}

@media (max-width: 768px) {
    .grid.grid-cols-2 {
        grid-template-columns: 1fr;
    }

    .grid.grid-cols-3 {
        grid-template-columns: 1fr 1fr;
    }

    .grid.grid-cols-4 {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 480px) {
    .grid.grid-cols-2,
    .grid.grid-cols-3,
    .grid.grid-cols-4 {
        grid-template-columns: 1fr;
    }
}

/* ===== SIDEBAR FIX ===== */
@media (max-width: 768px) {
    #sidebar {
        z-index: 40;
        width: 100%;
        max-width: 280px;
    }

    .md\:ml-64 {
        margin-left: 0 !important;
    }

    /* Overlay when sidebar is open */
    #sidebar:not(.-translate-x-full) ~ .sidebar-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 30;
    }
}

/* ===== MODAL RESPONSIVE ===== */
.modal, [class*="Modal"] {
    padding: 16px !important;
}

@media (max-width: 640px) {
    .modal, [class*="Modal"] {
        max-width: 100% !important;
        width: 100% !important;
        max-height: 90vh !important;
        border-radius: 12px 12px 0 0 !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
    }

    .modal-header, [class*="Modal"] > div:first-child {
        margin-bottom: 12px;
    }
}

/* ===== CARD SPACING ===== */
.bg-white, .rounded-lg, .shadow {
    margin-bottom: 12px;
}

@media (max-width: 768px) {
    .bg-white, .rounded-lg, .shadow {
        border-radius: 8px;
        padding: 12px;
    }
}

/* ===== TEXT SCALING ===== */
h1 {
    font-size: clamp(20px, 5vw, 32px);
}

h2 {
    font-size: clamp(18px, 4vw, 28px);
}

h3 {
    font-size: clamp(16px, 3vw, 24px);
}

@media (max-width: 480px) {
    h1 { font-size: 20px; }
    h2 { font-size: 18px; }
    h3 { font-size: 16px; }
}

/* ===== FLEX RESPONSIVE ===== */
.flex {
    flex-wrap: wrap;
    gap: 8px;
}

@media (max-width: 768px) {
    .flex-col.md\:flex-row {
        flex-direction: column;
    }

    .items-start.md\:items-center {
        align-items: flex-start;
    }
}

/* ===== PADDING & MARGINS ===== */
@media (max-width: 768px) {
    .p-6 { padding: 12px !important; }
    .p-4 { padding: 10px !important; }
    .px-6 { padding-left: 12px !important; padding-right: 12px !important; }
    .px-4 { padding-left: 10px !important; padding-right: 10px !important; }
    .py-6 { padding-top: 12px !important; padding-bottom: 12px !important; }
    .py-4 { padding-top: 10px !important; padding-bottom: 10px !important; }
    
    .mb-6 { margin-bottom: 12px !important; }
    .mb-4 { margin-bottom: 10px !important; }
    .mt-6 { margin-top: 12px !important; }
    .mt-4 { margin-top: 10px !important; }
}

/* ===== GAP RESPONSIVE ===== */
.gap-6 { gap: 12px; }
.gap-4 { gap: 10px; }

@media (max-width: 768px) {
    .gap-6 { gap: 8px !important; }
    .gap-4 { gap: 6px !important; }
}

/* ===== FORM RESPONSIVE ===== */
form {
    display: flex;
    flex-direction: column;
}

form > div {
    margin-bottom: 12px;
}

@media (max-width: 768px) {
    .grid.grid-cols-1.md\:grid-cols-2,
    .grid.grid-cols-1.md\:grid-cols-3 {
        grid-template-columns: 1fr;
    }

    label {
        font-size: 14px;
        margin-bottom: 6px;
    }

    input, select, textarea {
        width: 100%;
        padding: 10px 12px;
        font-size: 16px;
    }
}

/* ===== PRINT INVOICE RESPONSIVE ===== */
.page {
    padding: 8mm !important;
    margin: 10px auto !important;
}

@media (max-width: 768px) {
    .page {
        width: 100% !important;
        max-width: 100% !important;
        padding: 6mm !important;
        margin: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
    }

    .info-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    .summary-area {
        flex-direction: column !important;
        gap: 10px !important;
    }

    .summary-details,
    .summary-amounts {
        width: 100% !important;
    }

    .items-table {
        font-size: 8pt !important;
    }

    .items-table th,
    .items-table td {
        padding: 6px 8px !important;
    }
}

/* ===== NAVBAR/TOPBAR RESPONSIVE ===== */
.top-bar, [class*="topbar"], [class*="navbar"] {
    padding: 10px 12px;
    z-index: 50;
}

@media (max-width: 768px) {
    .top-bar, [class*="topbar"], [class*="navbar"] {
        padding: 8px 10px;
        flex-wrap: wrap;
    }
}

/* ===== UTILITY CLASSES FOR MOBILE ===== */
.mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .mobile-only {
        display: block;
    }

    .desktop-only {
        display: none;
    }

    .hide-mobile {
        display: none !important;
    }

    .show-mobile {
        display: block !important;
    }
}

/* ===== FONT SIZE SCALING ===== */
.text-xs { font-size: clamp(11px, 2.5vw, 12px); }
.text-sm { font-size: clamp(13px, 2.8vw, 14px); }
.text-base { font-size: clamp(14px, 3vw, 16px); }
.text-lg { font-size: clamp(16px, 3.5vw, 18px); }

/* ===== SCROLL SMOOTH ===== */
html {
    scroll-behavior: smooth;
}

/* ===== SAFE AREA INSETS (for notched devices) ===== */
@supports (padding: max(0px)) {
    body {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
}

/* ===== IMAGE RESPONSIVE ===== */
img {
    max-width: 100%;
    height: auto;
}

.img-thumbnail, [class*="image"] {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

/* ===== CARD HOVER EFFECTS DISABLED ON MOBILE ===== */
@media (hover: none) and (pointer: coarse) {
    button:hover,
    a:hover,
    .stat-card:hover {
        transform: none !important;
    }
}

/* ===== LANDSCAPE ORIENTATION FIX ===== */
@media (max-height: 500px) and (orientation: landscape) {
    body {
        padding-top: 56px;
    }

    .md\:ml-64 {
        margin-top: 56px;
    }
}

/* ===== ANIMATION PERFORMANCE ===== */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
