/* ========================================
   PROVA MODELAGEM - MOBILE FIRST STYLES
   Complete Mobile Optimization
   ======================================== */

/* ========================================
   BREAKPOINTS SYSTEM
   Mobile First Approach
   ======================================== */

:root {
    /* Z-index layers */
    --z-bottom-nav: 1000;
    --z-fixed: 1020;
    --z-sticky: 1030;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-toast: 1060;

    /* Mobile spacing */
    --mobile-spacing-xs: 0.5rem;
    --mobile-spacing-sm: 0.75rem;
    --mobile-spacing-md: 1rem;
    --mobile-spacing-lg: 1.25rem;

    /* Touch targets */
    --touch-target-min: 44px;
    --touch-target-comfortable: 48px;
}

/* ========================================
   BASE MOBILE STYLES (< 640px)
   Applied to all mobile devices first
   ======================================== */

/* Hide desktop navbar on mobile */
@media (max-width: 639px) {
    .navbar {
        position: sticky;
        top: 0;
        z-index: var(--z-fixed);
        padding: 0.5rem 0 !important;
    }

    .navbar-brand span {
        display: none;
    }

    .navbar-brand img {
        height: 32px !important;
    }

    /* Add padding to bottom for bottom nav */
    body {
        padding-bottom: 80px;
    }

    .main-container {
        padding: 0.75rem 0.5rem;
        margin-bottom: 0;
    }
}

/* ========================================
   BOTTOM NAVIGATION BAR (Mobile Only)
   ======================================== */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: white;
    display: none;
    justify-content: space-around;
    align-items: center;
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
    border-top: 1px solid rgba(236, 72, 153, 0.1);
    z-index: var(--z-bottom-nav);
    padding: 0 0.5rem;
}

@media (max-width: 639px) {
    .bottom-nav {
        display: flex;
    }
}

.bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: #9ca3af;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.5rem;
    border-radius: 12px;
    transition: all 0.2s ease;
    min-height: var(--touch-target-min);
    gap: 4px;
    position: relative;
}

.bottom-nav-item i {
    font-size: 1.3rem;
    margin-bottom: 2px;
}

.bottom-nav-item.active {
    color: #ec4899;
    background: rgba(236, 72, 153, 0.08);
}

.bottom-nav-item:hover {
    color: #ec4899;
    text-decoration: none;
}

/* Primary action button in center */
.bottom-nav-item-primary {
    color: white !important;
    background: linear-gradient(135deg, #ec4899, #8b5cf6);
    border-radius: 50%;
    width: 56px;
    height: 56px;
    flex: 0 0 56px;
    margin-top: -20px;
    box-shadow: 0 4px 12px rgba(236, 72, 153, 0.4);
}

.bottom-nav-item-primary i {
    font-size: 1.75rem;
    margin-bottom: 0;
}

.bottom-nav-item-primary span {
    display: none;
}

.bottom-nav-item-primary:hover {
    color: white !important;
    transform: scale(1.05);
}

/* ========================================
   MOBILE OPTIMIZATIONS
   ======================================== */

/* Touch-friendly buttons */
@media (max-width: 639px) {
    .btn {
        min-height: var(--touch-target-comfortable);
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .btn:not(.btn-sm):not(.btn-lg):not(.view-toggle-btn):not(.btn-check + .btn):not(.btn-group .btn) {
        width: 100%;
        justify-content: center;
    }

    .btn-sm {
        min-height: var(--touch-target-min);
        padding: 0.5rem 0.75rem;
    }

    .btn-lg {
        min-height: 56px;
        padding: 1rem 1.5rem;
    }
}

/* Forms mobile optimization */
@media (max-width: 639px) {
    .form-control,
    .form-select {
        font-size: 16px !important; /* Prevents iOS zoom */
        min-height: var(--touch-target-comfortable);
        padding: 0.75rem;
    }

    textarea.form-control {
        min-height: 120px;
    }

    .form-label {
        font-size: 0.875rem;
        font-weight: 600;
        margin-bottom: 0.5rem;
    }

    .form-check {
        min-height: var(--touch-target-min);
        padding-left: 2rem;
    }

    .form-check-input {
        width: 1.25rem;
        height: 1.25rem;
        margin-left: -2rem;
    }
}

/* Cards responsive */
@media (max-width: 639px) {
    .card {
        border-radius: 12px;
        margin-bottom: 1rem;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.875rem 1rem;
        font-size: 0.95rem;
    }

    .card-footer {
        padding: 0.875rem 1rem;
    }
}

/* Tables to scroll */
@media (max-width: 639px) {
    .table-responsive {
        position: relative;
        border-radius: 8px;
        margin: 0 -0.5rem;
        padding: 0 0.5rem;
    }

    .table {
        font-size: 0.8rem;
        margin-bottom: 0;
    }

    .table thead {
        display: none; /* Hide headers on very small screens */
    }

    .table td {
        display: block;
        padding: 0.5rem;
        border: none;
        position: relative;
        padding-left: 50%;
    }

    .table td::before {
        content: attr(data-label);
        position: absolute;
        left: 0.5rem;
        width: 45%;
        padding-right: 0.5rem;
        font-weight: 600;
        color: #6b7280;
        font-size: 0.75rem;
    }

    .table tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        background: white;
    }
}

/* Alternative: Horizontal scroll for tables */
.table-scroll-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

@media (max-width: 639px) {
    .table-scroll-mobile {
        margin: 0 -0.5rem;
        padding: 0 0.5rem;
    }

    .table-scroll-mobile::after {
        content: '→ Deslize';
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        background: linear-gradient(to left, white 30%, transparent);
        padding: 0.5rem 1rem;
        color: #9ca3af;
        font-size: 0.75rem;
        pointer-events: none;
    }

    .table-scroll-mobile::-webkit-scrollbar {
        height: 4px;
    }

    .table-scroll-mobile::-webkit-scrollbar-thumb {
        background: #e5e7eb;
        border-radius: 4px;
    }
}

/* Modals mobile */
@media (max-width: 639px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal-content {
        border-radius: 12px;
    }

    .modal-header {
        padding: 1rem;
        flex-direction: row;
        align-items: center;
    }

    .modal-title {
        font-size: 1.1rem;
    }

    .modal-body {
        padding: 1rem;
        max-height: 60vh;
        overflow-y: auto;
    }

    .modal-footer {
        padding: 1rem;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .modal-footer .btn {
        width: 100%;
        margin: 0;
    }

    .modal-footer form {
        width: 100%;
        display: flex;
        flex-direction: column-reverse;
        gap: 0.5rem;
    }

    .modal-footer form .btn {
        width: 100%;
    }

    /* Full screen modal option */
    .modal-fullscreen-sm-down {
        max-width: 100%;
        margin: 0;
        height: 100vh;
    }

    .modal-fullscreen-sm-down .modal-content {
        height: 100%;
        border-radius: 0;
        border: none;
    }

    .modal-fullscreen-sm-down .modal-body {
        max-height: none;
        overflow-y: auto;
    }
}

/* Alerts mobile */
@media (max-width: 639px) {
    .alert {
        padding: 0.875rem;
        font-size: 0.875rem;
        margin-bottom: 1rem;
        border-radius: 10px;
    }

    .alert i {
        font-size: 1rem;
    }
}

/* Badges mobile */
@media (max-width: 639px) {
    .badge {
        font-size: 0.7rem;
        padding: 0.35rem 0.7rem;
    }
}

/* Navigation tabs mobile */
@media (max-width: 639px) {
    .nav-tabs {
        overflow-x: auto;
        overflow-y: hidden;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        margin: 0 -0.5rem;
        padding: 0 0.5rem;
        scrollbar-width: none;
        border-bottom: 2px solid #e5e7eb;
    }

    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .nav-tabs .nav-link {
        white-space: nowrap;
        flex-shrink: 0;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
        min-width: auto;
    }
}

/* Grid layouts mobile */
@media (max-width: 639px) {
    .row {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
    }

    .row > * {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    /* Force single column */
    [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Except when explicitly using col-6 for 2 columns */
    .col-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* Images responsive */
@media (max-width: 639px) {
    img {
        max-width: 100%;
        height: auto;
    }

    .img-thumbnail {
        padding: 0.25rem;
        border-radius: 8px;
    }
}

/* Typography mobile */
@media (max-width: 639px) {
    body {
        font-size: 0.9375rem;
        line-height: 1.5;
    }

    h1 {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }

    h2 {
        font-size: 1.35rem;
        margin-bottom: 0.75rem;
    }

    h3 {
        font-size: 1.2rem;
        margin-bottom: 0.5rem;
    }

    h4 {
        font-size: 1.1rem;
        margin-bottom: 0.5rem;
    }

    h5 {
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }

    h6 {
        font-size: 0.9rem;
        margin-bottom: 0.5rem;
    }

    p {
        margin-bottom: 0.75rem;
    }
}

/* ========================================
   DASHBOARD MOBILE SPECIFIC
   ======================================== */

@media (max-width: 639px) {
    /* Dashboard header */
    .dashboard-header {
        flex-direction: column;
        text-align: center;
        padding: 1.25rem 1rem;
        gap: 1rem;
    }

    .dashboard-header-content h1 {
        font-size: 1.25rem;
    }

    .dashboard-header-content p {
        font-size: 0.8rem;
    }

    .btn-new-report {
        width: 100%;
        justify-content: center;
        padding: 0.875rem 1rem;
    }

    /* Stats grid */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        margin-bottom: 1rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-icon {
        width: 42px;
        height: 42px;
        font-size: 1.1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.7rem;
    }

    .stat-detail {
        font-size: 0.65rem;
        margin-top: 0.5rem;
        padding-top: 0.5rem;
    }

    /* Filters section */
    .filters-section-premium {
        margin-bottom: 1rem;
        border-radius: 12px;
    }

    .filters-header-premium {
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }

    .filters-toggle-btn {
        font-size: 0.875rem;
        padding: 0.75rem;
    }

    .clear-filters-btn-premium {
        margin-left: 0;
        width: 100%;
        justify-content: center;
    }

    .filters-body-premium {
        padding: 1rem;
    }

    .filter-group-premium {
        margin-bottom: 1rem;
        padding-bottom: 1rem;
    }

    .filter-label-premium {
        font-size: 0.8rem;
    }

    .filter-pills-premium {
        gap: 0.5rem;
    }

    .filter-pill-premium .pill-content {
        font-size: 0.75rem;
        padding: 0.5rem 0.875rem;
    }

    /* Reports section */
    .reports-section {
        border-radius: 12px;
    }

    .reports-header {
        flex-wrap: wrap;
        padding: 1rem;
        gap: 0.75rem;
    }

    .section-title {
        font-size: 0.95rem;
    }

    .reports-count {
        font-size: 0.7rem;
        padding: 0.25rem 0.75rem;
    }

    .view-toggle {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .view-toggle-btn {
        flex: 1;
        padding: 0.5rem;
    }

    /* Reports grid */
    .reports-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
        padding: 1rem;
    }

    .report-card {
        padding: 1rem;
    }

    .report-image img {
        height: 200px;
    }

    .report-title {
        font-size: 0.9rem;
    }

    .report-meta {
        gap: 0.5rem;
    }

    .meta-item {
        font-size: 0.75rem;
    }

    .report-actions {
        flex-direction: row;
        gap: 0.5rem;
    }

    .btn-view {
        flex: 1;
        font-size: 0.8rem;
        padding: 0.625rem;
    }

    .btn-export {
        padding: 0.625rem 0.75rem;
    }

    /* Search */
    .search-wrapper {
        max-width: 100%;
    }

    .search-input {
        font-size: 16px; /* Prevent iOS zoom */
    }

    /* Empty state */
    .empty-state {
        padding: 2rem 1rem;
    }

    .empty-icon {
        width: 64px;
        height: 64px;
    }

    .empty-icon i {
        font-size: 1.75rem;
    }

    .empty-state h3 {
        font-size: 1.1rem;
    }

    .empty-state p {
        font-size: 0.875rem;
    }
}

/* ========================================
   ANALYTICS MOBILE SPECIFIC
   ======================================== */

@media (max-width: 639px) {
    .analytics-header {
        padding: 1.25rem 1rem;
        border-radius: 12px;
    }

    .analytics-header h1 {
        font-size: 1.25rem;
    }

    .analytics-header p {
        font-size: 0.8rem;
    }

    .filter-card {
        padding: 1rem;
        border-radius: 12px;
    }

    .filter-card .form-label {
        font-size: 0.8rem;
    }

    .filter-card .form-select,
    .filter-card .form-control {
        font-size: 0.875rem;
    }

    .chart-card {
        padding: 1rem;
        margin-bottom: 1rem;
        border-radius: 12px;
    }

    .chart-card h5 {
        font-size: 0.95rem;
    }

    .insight-card {
        padding: 0.875rem 1rem;
        font-size: 0.85rem;
    }

    .data-table-container {
        padding: 1rem;
        border-radius: 12px;
        overflow-x: auto;
    }

    .export-btn {
        width: 100%;
        padding: 0.75rem 1rem;
        font-size: 0.875rem;
    }
}

/* ========================================
   TOUCH DEVICE OPTIMIZATIONS
   ======================================== */

@media (hover: none) and (pointer: coarse) {
    /* All interactive elements */
    a,
    button,
    .btn,
    [role="button"],
    label {
        min-height: var(--touch-target-min);
        min-width: var(--touch-target-min);
    }

    /* Tap highlight */
    a,
    button,
    .btn,
    [role="button"] {
        -webkit-tap-highlight-color: rgba(236, 72, 153, 0.2);
    }

    /* Remove hover effects on touch devices */
    .btn:hover,
    .card:hover,
    a:hover {
        transform: none;
    }

    /* Active state for touch feedback */
    .btn:active {
        transform: scale(0.98);
    }

    /* Larger dropdown items */
    .dropdown-item {
        padding: 0.875rem 1.25rem;
        font-size: 0.9rem;
    }

    /* Ensure links are tappable */
    .nav-link {
        min-height: var(--touch-target-min);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Better spacing for stacked buttons */
    .btn-group-vertical .btn {
        margin-bottom: 0.5rem;
    }

    .btn-group-vertical .btn:last-child {
        margin-bottom: 0;
    }
}

/* ========================================
   TABLET (640px - 1024px)
   ======================================== */

@media (min-width: 640px) and (max-width: 1023px) {
    /* Hide bottom nav */
    .bottom-nav {
        display: none;
    }

    body {
        padding-bottom: 0;
    }

    .main-container {
        padding: 1.5rem 1rem;
    }

    /* Stats grid - 2 columns */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    /* Reports grid - 2 columns */
    .reports-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }

    /* Forms side by side when possible */
    .row .col-md-6 {
        flex: 0 0 50%;
        max-width: 50%;
    }
}

/* ========================================
   DESKTOP (1024px+)
   ======================================== */

@media (min-width: 1024px) {
    /* Hide bottom nav */
    .bottom-nav {
        display: none;
    }

    body {
        padding-bottom: 0;
    }

    /* Stats grid - 4 columns */
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    /* Reports grid - 3+ columns */
    .reports-grid {
        grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    }
}

/* ========================================
   LARGE DESKTOP (1280px+)
   ======================================== */

@media (min-width: 1280px) {
    .container,
    .main-container {
        max-width: 1400px;
    }

    .reports-grid {
        grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    }
}

/* ========================================
   LANDSCAPE MOBILE
   ======================================== */

@media (max-width: 896px) and (orientation: landscape) {
    .navbar {
        padding: 0.25rem 0 !important;
    }

    .navbar-brand img {
        height: 28px !important;
    }

    .main-container {
        padding: 0.5rem;
    }

    .modal-dialog {
        margin: 0.5rem auto;
        max-height: 90vh;
    }

    .modal-body {
        max-height: 60vh;
        overflow-y: auto;
    }

    .dashboard-header {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card {
        padding: 0.75rem;
    }

    .bottom-nav {
        height: 56px;
        padding: 0 0.25rem;
    }

    .bottom-nav-item {
        font-size: 0.65rem;
    }

    .bottom-nav-item i {
        font-size: 1.1rem;
    }

    .bottom-nav-item-primary {
        width: 48px;
        height: 48px;
        margin-top: -16px;
    }
}

/* ========================================
   VERY SMALL MOBILE (< 375px)
   ======================================== */

@media (max-width: 374px) {
    body {
        font-size: 0.875rem;
    }

    .main-container {
        padding: 0.5rem 0.25rem;
    }

    .card-body {
        padding: 0.875rem;
    }

    h1 {
        font-size: 1.25rem;
    }

    h2 {
        font-size: 1.15rem;
    }

    h3 {
        font-size: 1.05rem;
    }

    .btn {
        font-size: 0.85rem;
        padding: 0.625rem 0.875rem;
    }

    .stat-card {
        padding: 0.875rem;
    }

    .stat-value {
        font-size: 1.35rem;
    }

    .stat-label {
        font-size: 0.65rem;
    }

    .badge {
        font-size: 0.65rem;
        padding: 0.3rem 0.6rem;
    }

    .bottom-nav {
        height: 56px;
    }

    .bottom-nav-item {
        font-size: 0.65rem;
    }

    .bottom-nav-item i {
        font-size: 1.1rem;
    }

    .bottom-nav-item-primary {
        width: 48px;
        height: 48px;
        margin-top: -16px;
    }

    .bottom-nav-item-primary i {
        font-size: 1.5rem;
    }
}

/* ========================================
   REDUCED MOTION
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ========================================
   PRINT STYLES
   ======================================== */

@media print {
    .navbar,
    .bottom-nav,
    .btn,
    .filter-card,
    .filters-section-premium,
    .no-print {
        display: none !important;
    }

    body {
        padding-bottom: 0;
    }

    .card {
        break-inside: avoid;
    }
}

/* ========================================
   UTILITY CLASSES
   ======================================== */

/* Show/hide based on screen size */
.hide-mobile {
    display: block;
}

@media (max-width: 639px) {
    .hide-mobile {
        display: none !important;
    }
}

.show-mobile {
    display: none;
}

@media (max-width: 639px) {
    .show-mobile {
        display: block !important;
    }
}

.show-mobile-inline {
    display: none;
}

@media (max-width: 639px) {
    .show-mobile-inline {
        display: inline !important;
    }
}

.show-mobile-flex {
    display: none;
}

@media (max-width: 639px) {
    .show-mobile-flex {
        display: flex !important;
    }
}

/* Text sizing utilities */
.text-mobile-sm {
    font-size: 1rem;
}

@media (max-width: 639px) {
    .text-mobile-sm {
        font-size: 0.875rem;
    }
}

.text-mobile-xs {
    font-size: 1rem;
}

@media (max-width: 639px) {
    .text-mobile-xs {
        font-size: 0.75rem;
    }
}

/* Spacing utilities for mobile */
@media (max-width: 639px) {
    .mb-mobile-0 {
        margin-bottom: 0 !important;
    }

    .mb-mobile-1 {
        margin-bottom: 0.5rem !important;
    }

    .mb-mobile-2 {
        margin-bottom: 0.75rem !important;
    }

    .mb-mobile-3 {
        margin-bottom: 1rem !important;
    }

    .p-mobile-0 {
        padding: 0 !important;
    }

    .p-mobile-1 {
        padding: 0.5rem !important;
    }

    .p-mobile-2 {
        padding: 0.75rem !important;
    }

    .p-mobile-3 {
        padding: 1rem !important;
    }
}
