/* Mobile Optimizations for Gestão de Compras */

/* Mobile Navigation */
@media (max-width: 640px) {
    /* Mobile Menu Toggle */
    #mobile-menu-toggle {
        transition: all 0.3s ease;
    }
    
    #mobile-menu-toggle:hover {
        transform: scale(1.02);
    }
    
    /* Navigation Container */
    .nav-container {
        max-height: 0;
        overflow: hidden;
        transition: all 0.3s ease;
        background: white;
        border-radius: 0.5rem;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        margin-top: 0.5rem;
        opacity: 0;
        visibility: hidden;
        transform: translateY(-10px);
        display: block;
    }
    
    .nav-container.show {
        max-height: 600px;
        border: 1px solid #e5e7eb;
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
        display: block;
    }
    
    /* Mobile Menu Toggle Active State */
    #mobile-menu-toggle.active {
        background: #1d4ed8;
        transform: scale(0.98);
    }
    
    #mobile-menu-toggle.active i {
        transform: rotate(90deg);
        transition: transform 0.3s ease;
    }
    
    /* Mobile Navigation Buttons */
    .mobile-nav-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        color: #64748b;
        transition: all 0.2s ease;
    }
    
    .mobile-nav-btn.active {
        background: #3b82f6;
        color: white;
        border-color: #3b82f6;
    }
    
    .mobile-nav-btn:hover {
        background: #e2e8f0;
        transform: translateY(-1px);
    }
    
    .mobile-nav-btn.active:hover {
        background: #2563eb;
    }
    
    /* Mobile Icons */
    .mobile-nav-btn i {
        font-size: 1.2rem;
        margin-bottom: 0.25rem;
    }
    
    .mobile-nav-btn span {
        font-size: 0.7rem;
        font-weight: 500;
    }
    
    /* Navigation Buttons inside mobile container */
    .nav-container .nav-button {
        display: block;
        width: 100%;
        padding: 0.75rem 1rem;
        margin: 0.25rem 0;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 0.5rem;
        color: #374151;
        font-size: 0.875rem;
        font-weight: 500;
        text-align: left;
        transition: all 0.2s ease;
        cursor: pointer;
    }
    
    .nav-container .nav-button:hover {
        background: #e5e7eb;
        border-color: #d1d5db;
        transform: translateY(-1px);
    }
    
    .nav-container .nav-button.active {
        background: #3b82f6;
        color: white;
        border-color: #3b82f6;
    }
    
    .nav-container .nav-button.active:hover {
        background: #2563eb;
    }
}

/* Mobile Cards and Layout */
@media (max-width: 640px) {
    /* KPI Cards */
    .kpi-card {
        min-height: 120px;
    }
    
    /* Dashboard Header */
    .dashboard-header {
        padding: 1rem;
    }
    
    .dashboard-header h2 {
        font-size: 1.5rem;
        line-height: 1.2;
    }
    
    /* Filters */
    .dashboard-filters {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .dashboard-filter-btn {
        width: 100%;
        text-align: center;
        padding: 0.75rem;
    }
    
    /* Action Buttons */
    .action-btn {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
    
    /* Tables */
    .mobile-table {
        font-size: 0.75rem;
    }
    
    .mobile-table th,
    .mobile-table td {
        padding: 0.5rem 0.25rem;
    }
    
    /* Modals */
    .modal-backdrop {
        z-index: 9999 !important;
        background: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(4px);
    }
    
    .modal-content {
        margin: 1rem;
        max-height: calc(100vh - 2rem);
        overflow-y: auto;
        width: calc(100vw - 2rem);
        max-width: 500px;
        border-radius: 1rem;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    }
    
    .mobile-modal-body {
        padding: 1rem;
        max-height: calc(100vh - 8rem);
        overflow-y: auto;
    }
    
    /* Modal Close Button */
    .modal-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
        z-index: 10000;
        background: rgba(255, 255, 255, 0.9);
        border-radius: 50%;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        font-weight: bold;
        color: #374151;
        border: none;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .modal-close:hover {
        background: rgba(255, 255, 255, 1);
        transform: scale(1.1);
    }
    
    /* Forms */
    .form-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .form-input {
        padding: 0.75rem;
        font-size: 1rem;
    }
    
    /* Buttons */
    .btn-mobile {
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        min-height: 44px; /* Touch target size */
    }
    
    /* Status Badges */
    .status-badge {
        font-size: 0.7rem;
        padding: 0.25rem 0.5rem;
    }
}

/* Mobile Typography */
@media (max-width: 640px) {
    h1 {
        font-size: 1.5rem;
        line-height: 1.2;
    }
    
    h2 {
        font-size: 1.25rem;
        line-height: 1.3;
    }
    
    h3 {
        font-size: 1.125rem;
        line-height: 1.4;
    }
    
    p {
        font-size: 0.875rem;
        line-height: 1.5;
    }
    
    .text-xs {
        font-size: 0.7rem;
    }
    
    .text-sm {
        font-size: 0.8rem;
    }
}

/* Mobile Spacing */
@media (max-width: 640px) {
    .mobile-spacing {
        padding: 1rem;
        margin: 0.5rem;
    }
    
    .mobile-gap {
        gap: 0.75rem;
    }
    
    .mobile-margin {
        margin: 0.5rem 0;
    }
}

/* Mobile Touch Targets */
@media (max-width: 640px) {
    button, 
    .btn,
    [role="button"] {
        min-height: 44px;
        min-width: 44px;
    }
    
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 24px;
        min-height: 24px;
    }
    
    select {
        min-height: 44px;
        padding: 0.75rem;
    }
}

/* Mobile Scroll Optimization */
@media (max-width: 640px) {
    .mobile-scroll {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
    }
    
    .mobile-scroll::-webkit-scrollbar {
        width: 4px;
    }
    
    .mobile-scroll::-webkit-scrollbar-track {
        background: #f1f5f9;
    }
    
    .mobile-scroll::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 2px;
    }
}

/* Mobile Loading States */
@media (max-width: 640px) {
    .mobile-loading {
        padding: 2rem 1rem;
        text-align: center;
    }
    
    .mobile-loading i {
        font-size: 2rem;
        margin-bottom: 1rem;
    }
}

/* Mobile Empty States */
@media (max-width: 640px) {
    .mobile-empty {
        padding: 3rem 1rem;
        text-align: center;
    }
    
    .mobile-empty i {
        font-size: 3rem;
        margin-bottom: 1rem;
        opacity: 0.5;
    }
}

/* Mobile Notifications */
@media (max-width: 640px) {
    .mobile-notification {
        position: fixed;
        top: 1rem;
        left: 1rem;
        right: 1rem;
        z-index: 9999;
        padding: 1rem;
        border-radius: 0.5rem;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
        animation: slideInDown 0.3s ease;
    }
    
    @keyframes slideInDown {
        from {
            transform: translateY(-100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
}

/* Mobile Search */
@media (max-width: 640px) {
    .mobile-search {
        position: relative;
        margin-bottom: 1rem;
    }
    
    .mobile-search input {
        width: 100%;
        padding: 0.75rem 2.5rem 0.75rem 1rem;
        border-radius: 0.5rem;
        border: 1px solid #d1d5db;
    }
    
    .mobile-search i {
        position: absolute;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
        color: #6b7280;
    }
}

/* Mobile Filters */
@media (max-width: 640px) {
    .mobile-filters {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        margin-bottom: 1rem;
    }
    
    .mobile-filter-btn {
        padding: 0.5rem 1rem;
        border-radius: 1rem;
        font-size: 0.75rem;
        white-space: nowrap;
    }
}

/* Mobile Charts */
@media (max-width: 640px) {
    .mobile-chart {
        height: 200px;
        margin: 1rem 0;
    }
    
    .mobile-chart canvas {
        max-height: 200px;
    }
}

/* Mobile Tables */
@media (max-width: 640px) {
    .mobile-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .mobile-table {
        min-width: 600px;
    }
    
    .mobile-table-responsive {
        display: block;
    }
    
    .mobile-table-responsive thead {
        display: none;
    }
    
    .mobile-table-responsive tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e5e7eb;
        border-radius: 0.5rem;
        padding: 1rem;
    }
    
    .mobile-table-responsive td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border: none;
    }
    
    .mobile-table-responsive td::before {
        content: attr(data-label) ": ";
        font-weight: 600;
        color: #374151;
    }
}

/* Mobile Modals */
@media (max-width: 640px) {
    .mobile-modal {
        padding: 1rem;
    }
    
    .mobile-modal-header {
        padding-bottom: 1rem;
        border-bottom: 1px solid #e5e7eb;
        margin-bottom: 1rem;
    }
    
    .mobile-modal-body {
        max-height: calc(100vh - 200px);
        overflow-y: auto;
    }
    
    .mobile-modal-footer {
        padding-top: 1rem;
        border-top: 1px solid #e5e7eb;
        margin-top: 1rem;
        display: flex;
        gap: 0.5rem;
    }
    
    .mobile-modal-footer button {
        flex: 1;
    }
}

/* Mobile Forms */
@media (max-width: 640px) {
    .mobile-form-group {
        margin-bottom: 1rem;
    }
    
    .mobile-form-label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 500;
        color: #374151;
    }
    
    .mobile-form-input {
        width: 100%;
        padding: 0.75rem;
        border: 1px solid #d1d5db;
        border-radius: 0.5rem;
        font-size: 1rem;
    }
    
    .mobile-form-input:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }
    
    .mobile-form-select {
        width: 100%;
        padding: 0.75rem;
        border: 1px solid #d1d5db;
        border-radius: 0.5rem;
        font-size: 1rem;
        background-color: white;
    }
    
    .mobile-form-textarea {
        width: 100%;
        padding: 0.75rem;
        border: 1px solid #d1d5db;
        border-radius: 0.5rem;
        font-size: 1rem;
        resize: vertical;
        min-height: 100px;
    }
}

/* Mobile Actions */
@media (max-width: 640px) {
    .mobile-actions {
        position: fixed;
        bottom: 1rem;
        left: 1rem;
        right: 1rem;
        z-index: 1000;
        display: flex;
        gap: 0.5rem;
    }
    
    .mobile-action-btn {
        flex: 1;
        padding: 1rem;
        border-radius: 0.5rem;
        font-weight: 600;
        text-align: center;
        box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    }
    
    .mobile-action-btn.primary {
        background: #3b82f6;
        color: white;
    }
    
    .mobile-action-btn.secondary {
        background: #6b7280;
        color: white;
    }
    
    .mobile-action-btn.danger {
        background: #ef4444;
        color: white;
    }
}

/* Mobile Utilities */
@media (max-width: 640px) {
    .mobile-hidden {
        display: none !important;
    }
    
    .mobile-block {
        display: block !important;
    }
    
    .mobile-flex {
        display: flex !important;
    }
    
    .mobile-grid {
        display: grid !important;
    }
    
    .mobile-text-center {
        text-align: center !important;
    }
    
    .mobile-text-left {
        text-align: left !important;
    }
    
    .mobile-text-right {
        text-align: right !important;
    }
    
    .mobile-w-full {
        width: 100% !important;
    }
    
    .mobile-h-full {
        height: 100% !important;
    }
    
    .mobile-p-0 {
        padding: 0 !important;
    }
    
    .mobile-m-0 {
        margin: 0 !important;
    }
}

/* Mobile Modal Optimizations */
@media (max-width: 640px) {
    /* Modais */
    .modal-backdrop {
        z-index: 9999 !important;
        background: rgba(0, 0, 0, 0.8);
        backdrop-filter: blur(4px);
        padding: 1rem;
    }
    
    .modal-content {
        margin: 0;
        max-height: calc(100vh - 2rem);
        overflow-y: auto;
        width: 100%;
        max-width: none;
        border-radius: 1rem;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
        position: relative;
    }
    
    .modal-header {
        padding: 1rem;
        position: sticky;
        top: 0;
        background: white;
        z-index: 1;
        border-bottom: 1px solid #e5e7eb;
    }
    
    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 8rem);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .modal-footer {
        padding: 1rem;
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid #e5e7eb;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .modal-footer button {
        width: 100%;
        min-height: 44px;
    }
    
    /* Modal Close Button */
    .modal-close {
        position: absolute;
        top: 1rem;
        right: 1rem;
        z-index: 10000;
        background: rgba(255, 255, 255, 0.9);
        border: 1px solid #e5e7eb;
        border-radius: 50%;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.2rem;
        color: #6b7280;
        transition: all 0.2s ease;
    }
    
    .modal-close:hover {
        background: white;
        color: #374151;
        transform: scale(1.1);
    }
    
    /* Garantir que modais apareçam corretamente */
    .modal-backdrop:not(.hidden) {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    /* Melhorar scroll em modais */
    .modal-body::-webkit-scrollbar {
        width: 4px;
    }
    
    .modal-body::-webkit-scrollbar-track {
        background: #f1f5f9;
        border-radius: 2px;
    }
    
    .modal-body::-webkit-scrollbar-thumb {
        background: #cbd5e1;
        border-radius: 2px;
    }
    
    .modal-body::-webkit-scrollbar-thumb:hover {
        background: #94a3b8;
    }
    
    /* Garantir que inputs não causem zoom no iOS */
    .modal-body input,
    .modal-body select,
    .modal-body textarea {
        font-size: 16px;
    }
    
    /* Melhorar espaçamento em formulários */
    .modal-body .form-group {
        margin-bottom: 1rem;
    }
    
    .modal-body label {
        display: block;
        margin-bottom: 0.5rem;
        font-weight: 500;
        color: #374151;
    }
    
    .modal-body input,
    .modal-body select,
    .modal-body textarea {
        width: 100%;
        padding: 0.75rem;
        border: 1px solid #d1d5db;
        border-radius: 0.5rem;
        font-size: 16px;
        transition: border-color 0.2s ease;
    }
    
    .modal-body input:focus,
    .modal-body select:focus,
    .modal-body textarea:focus {
        outline: none;
        border-color: #3b82f6;
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }
    
    /* Melhorar botões em modais */
    .modal-footer .btn {
        min-height: 44px;
        font-size: 0.875rem;
        font-weight: 500;
        border-radius: 0.5rem;
        transition: all 0.2s ease;
    }
    
    .modal-footer .btn:active {
        transform: scale(0.98);
    }
    
    /* Garantir que tabelas sejam responsivas em modais */
    .modal-body .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 0.5rem;
        border: 1px solid #e5e7eb;
    }
    
    .modal-body table {
        min-width: 600px;
        font-size: 0.875rem;
    }
    
    .modal-body th,
    .modal-body td {
        padding: 0.75rem 0.5rem;
        white-space: nowrap;
    }
    
    /* Melhorar espaçamento de listas em modais */
    .modal-body ul,
    .modal-body ol {
        padding-left: 1.5rem;
        margin-bottom: 1rem;
    }
    
    .modal-body li {
        margin-bottom: 0.5rem;
    }
    
    /* Garantir que checkboxes e radios sejam tocáveis */
    .modal-body input[type="checkbox"],
    .modal-body input[type="radio"] {
        min-width: 20px;
        min-height: 20px;
    }
    
    /* Melhorar espaçamento de grupos de campos */
    .modal-body .grid {
        gap: 1rem;
    }
    
    .modal-body .grid-cols-1 {
        grid-template-columns: 1fr;
    }
    
    .modal-body .grid-cols-2 {
        grid-template-columns: 1fr;
    }
    
    /* Garantir que tooltips e popovers funcionem */
    .modal-body [data-tooltip] {
        position: relative;
    }
    
    .modal-body [data-tooltip]:hover::after {
        content: attr(data-tooltip);
        position: absolute;
        bottom: 100%;
        left: 50%;
        transform: translateX(-50%);
        background: #1f2937;
        color: white;
        padding: 0.5rem;
        border-radius: 0.25rem;
        font-size: 0.75rem;
        white-space: nowrap;
        z-index: 1000;
    }
}

