/* ============================================
   SISTEMA DE RESPONSIVIDADE GLOBAL - PAV SIMCO
   ============================================

   Breakpoints padronizados:
   - xs: 0 - 575px (mobile pequeno)
   - sm: 576px - 767px (mobile grande)
   - md: 768px - 991px (tablet)
   - lg: 992px - 1199px (laptop)
   - xl: 1200px - 1399px (desktop)
   - xxl: 1400px+ (desktop grande)

============================================ */

:root {
    /* Breakpoint Variables */
    --breakpoint-xs: 0;
    --breakpoint-sm: 576px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 992px;
    --breakpoint-xl: 1200px;
    --breakpoint-xxl: 1400px;

    /* Container widths */
    --container-sm: 540px;
    --container-md: 720px;
    --container-lg: 960px;
    --container-xl: 1140px;
    --container-xxl: 1320px;

    /* Spacing responsivo */
    --spacing-xs: 0.5rem;
    --spacing-sm: 1rem;
    --spacing-md: 1.5rem;
    --spacing-lg: 2rem;
    --spacing-xl: 3rem;

    /* Font sizes responsivos */
    --font-xs: clamp(0.75rem, 2vw, 0.875rem);
    --font-sm: clamp(0.875rem, 2.5vw, 1rem);
    --font-base: clamp(1rem, 3vw, 1.125rem);
    --font-lg: clamp(1.125rem, 3.5vw, 1.5rem);
    --font-xl: clamp(1.5rem, 4vw, 2rem);
    --font-xxl: clamp(2rem, 5vw, 3rem);

    /* Sidebar responsivo */
    --sidebar-width-desktop: 340px;
    --sidebar-width-tablet: 280px;
    --sidebar-width-collapsed: 60px;
}

/* ============================================
   UTILITIES - Classes Utilitárias
   ============================================ */

/* Display utilities */
.d-none { display: none !important; }
.d-block { display: block !important; }
.d-flex { display: flex !important; }
.d-grid { display: grid !important; }
.d-inline { display: inline !important; }
.d-inline-block { display: inline-block !important; }
.d-inline-flex { display: inline-flex !important; }

/* Flexbox utilities */
.flex-wrap { flex-wrap: wrap !important; }
.flex-nowrap { flex-wrap: nowrap !important; }
.flex-column { flex-direction: column !important; }
.flex-row { flex-direction: row !important; }
.justify-start { justify-content: flex-start !important; }
.justify-end { justify-content: flex-end !important; }
.justify-center { justify-content: center !important; }
.justify-between { justify-content: space-between !important; }
.justify-around { justify-content: space-around !important; }
.align-start { align-items: flex-start !important; }
.align-end { align-items: flex-end !important; }
.align-center { align-items: center !important; }
.align-stretch { align-items: stretch !important; }
.flex-1 { flex: 1 !important; }
.flex-grow-0 { flex-grow: 0 !important; }
.flex-grow-1 { flex-grow: 1 !important; }
.flex-shrink-0 { flex-shrink: 0 !important; }
.gap-1 { gap: 0.25rem !important; }
.gap-2 { gap: 0.5rem !important; }
.gap-3 { gap: 1rem !important; }
.gap-4 { gap: 1.5rem !important; }
.gap-5 { gap: 2rem !important; }

/* Width utilities */
.w-100 { width: 100% !important; }
.w-auto { width: auto !important; }
.max-w-100 { max-width: 100% !important; }
.min-w-0 { min-width: 0 !important; }

/* Overflow utilities */
.overflow-auto { overflow: auto !important; }
.overflow-hidden { overflow: hidden !important; }
.overflow-visible { overflow: visible !important; }
.overflow-x-auto { overflow-x: auto !important; }
.overflow-y-auto { overflow-y: auto !important; }
.overflow-x-hidden { overflow-x: hidden !important; }

/* Text utilities */
.text-center { text-align: center !important; }
.text-left { text-align: left !important; }
.text-right { text-align: right !important; }
.text-wrap { white-space: normal !important; }
.text-nowrap { white-space: nowrap !important; }
.text-truncate {
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}
.word-break { word-break: break-word !important; }

/* Visibility utilities */
.visible { visibility: visible !important; }
.invisible { visibility: hidden !important; }

/* Position utilities */
.position-relative { position: relative !important; }
.position-absolute { position: absolute !important; }
.position-fixed { position: fixed !important; }
.position-sticky { position: sticky !important; }

/* ============================================
   RESPONSIVE UTILITIES - Por Breakpoint
   ============================================ */

/* Extra small devices (phones, less than 576px) */
@media (max-width: 575.98px) {
    .d-xs-none { display: none !important; }
    .d-xs-block { display: block !important; }
    .d-xs-flex { display: flex !important; }
    .flex-xs-column { flex-direction: column !important; }
    .text-xs-center { text-align: center !important; }
    .w-xs-100 { width: 100% !important; }
    .px-xs-2 { padding-left: 0.5rem !important; padding-right: 0.5rem !important; }
    .py-xs-2 { padding-top: 0.5rem !important; padding-bottom: 0.5rem !important; }
    .mx-xs-auto { margin-left: auto !important; margin-right: auto !important; }
    .gap-xs-2 { gap: 0.5rem !important; }
}

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) and (max-width: 767.98px) {
    .d-sm-none { display: none !important; }
    .d-sm-block { display: block !important; }
    .d-sm-flex { display: flex !important; }
    .flex-sm-row { flex-direction: row !important; }
    .w-sm-auto { width: auto !important; }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) and (max-width: 991.98px) {
    .d-md-none { display: none !important; }
    .d-md-block { display: block !important; }
    .d-md-flex { display: flex !important; }
    .flex-md-row { flex-direction: row !important; }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) and (max-width: 1199.98px) {
    .d-lg-none { display: none !important; }
    .d-lg-block { display: block !important; }
    .d-lg-flex { display: flex !important; }
}

/* Extra large devices (large desktops, 1200px and up) */
@media (min-width: 1200px) {
    .d-xl-none { display: none !important; }
    .d-xl-block { display: block !important; }
    .d-xl-flex { display: flex !important; }
}

/* ============================================
   CONTAINER RESPONSIVO
   ============================================ */

.container-fluid {
    width: 100%;
    padding-right: var(--spacing-sm);
    padding-left: var(--spacing-sm);
    margin-right: auto;
    margin-left: auto;
}

.container-responsive {
    width: 100%;
    padding-right: var(--spacing-sm);
    padding-left: var(--spacing-sm);
    margin-right: auto;
    margin-left: auto;
}

@media (min-width: 576px) {
    .container-responsive {
        max-width: var(--container-sm);
    }
}

@media (min-width: 768px) {
    .container-responsive {
        max-width: var(--container-md);
    }
}

@media (min-width: 992px) {
    .container-responsive {
        max-width: var(--container-lg);
    }
}

@media (min-width: 1200px) {
    .container-responsive {
        max-width: var(--container-xl);
    }
}

@media (min-width: 1400px) {
    .container-responsive {
        max-width: var(--container-xxl);
    }
}

/* ============================================
   GRID RESPONSIVO
   ============================================ */

.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: calc(var(--spacing-sm) * -0.5);
    margin-left: calc(var(--spacing-sm) * -0.5);
}

.col {
    flex: 1 0 0%;
    padding-right: calc(var(--spacing-sm) * 0.5);
    padding-left: calc(var(--spacing-sm) * 0.5);
}

.col-12 { flex: 0 0 100%; max-width: 100%; }
.col-6 { flex: 0 0 50%; max-width: 50%; }
.col-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
.col-3 { flex: 0 0 25%; max-width: 25%; }

@media (min-width: 576px) {
    .col-sm-12 { flex: 0 0 100%; max-width: 100%; }
    .col-sm-6 { flex: 0 0 50%; max-width: 50%; }
    .col-sm-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
    .col-sm-3 { flex: 0 0 25%; max-width: 25%; }
}

@media (min-width: 768px) {
    .col-md-12 { flex: 0 0 100%; max-width: 100%; }
    .col-md-6 { flex: 0 0 50%; max-width: 50%; }
    .col-md-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
    .col-md-3 { flex: 0 0 25%; max-width: 25%; }
}

@media (min-width: 992px) {
    .col-lg-12 { flex: 0 0 100%; max-width: 100%; }
    .col-lg-6 { flex: 0 0 50%; max-width: 50%; }
    .col-lg-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
    .col-lg-3 { flex: 0 0 25%; max-width: 25%; }
}

/* ============================================
   TABELAS RESPONSIVAS
   ============================================ */

.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive > table {
    width: 100%;
    margin-bottom: 0;
}

@media (max-width: 767.98px) {
    .table-responsive-stack {
        display: block;
    }

    .table-responsive-stack thead {
        display: none;
    }

    .table-responsive-stack tbody tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid var(--gray-200);
        border-radius: 8px;
        padding: 0.5rem;
    }

    .table-responsive-stack tbody td {
        display: flex;
        justify-content: space-between;
        padding: 0.5rem;
        border: none;
        border-bottom: 1px solid var(--gray-100);
    }

    .table-responsive-stack tbody td:last-child {
        border-bottom: none;
    }

    .table-responsive-stack tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        margin-right: 1rem;
        color: var(--gray-600);
    }
}

/* ============================================
   MODAIS RESPONSIVOS
   ============================================ */

.modal-responsive {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-sm);
    z-index: 9999;
}

.modal-content-responsive {
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 12px;
}

@media (max-width: 575.98px) {
    .modal-content-responsive {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
        margin: 0;
    }

    .modal-responsive {
        padding: 0;
    }
}

@media (min-width: 576px) and (max-width: 767.98px) {
    .modal-content-responsive {
        max-width: 90%;
    }
}

@media (min-width: 768px) {
    .modal-content-responsive {
        max-width: 600px;
    }
}

@media (min-width: 992px) {
    .modal-lg-responsive {
        max-width: 800px;
    }

    .modal-xl-responsive {
        max-width: 1000px;
    }
}

/* ============================================
   FORMULÁRIOS RESPONSIVOS
   ============================================ */

.form-responsive input,
.form-responsive select,
.form-responsive textarea {
    width: 100%;
    max-width: 100%;
    font-size: 16px; /* Previne zoom no iOS */
}

.form-row-responsive {
    display: flex;
    flex-wrap: wrap;
    gap: var(--spacing-sm);
}

.form-row-responsive > * {
    flex: 1 1 200px;
    min-width: 0;
}

@media (max-width: 575.98px) {
    .form-row-responsive > * {
        flex: 1 1 100%;
    }
}

/* ============================================
   BOTÕES RESPONSIVOS
   ============================================ */

.btn-responsive {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    white-space: nowrap;
    transition: all 0.3s ease;
}

@media (max-width: 575.98px) {
    .btn-responsive {
        width: 100%;
        padding: 1rem;
    }

    .btn-group-responsive {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }

    .btn-group-responsive .btn-responsive {
        width: 100%;
    }
}

@media (min-width: 576px) {
    .btn-group-responsive {
        display: flex;
        flex-direction: row;
        gap: 0.75rem;
    }
}

/* ============================================
   CARDS RESPONSIVOS
   ============================================ */

.card-grid-responsive {
    display: grid;
    gap: var(--spacing-md);
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

@media (max-width: 575.98px) {
    .card-grid-responsive {
        grid-template-columns: 1fr;
        gap: var(--spacing-sm);
    }
}

@media (min-width: 992px) {
    .card-grid-responsive-4 {
        grid-template-columns: repeat(4, 1fr);
    }

    .card-grid-responsive-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* ============================================
   SIDEBAR RESPONSIVO - Colapsável
   ============================================ */

.sidebar-responsive {
    width: var(--sidebar-width-desktop);
    transition: all 0.3s ease;
}

@media (max-width: 991.98px) {
    .sidebar-responsive {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
    }

    .sidebar-responsive.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
    }

    .sidebar-responsive.open + .sidebar-overlay {
        display: block;
    }

    .main-content-responsive {
        margin-left: 0 !important;
    }

    .sidebar-toggle-btn {
        display: flex !important;
    }
}

@media (min-width: 992px) {
    .sidebar-toggle-btn {
        display: none !important;
    }

    .main-content-responsive {
        margin-left: var(--sidebar-width-desktop);
    }
}

/* ============================================
   HEADER RESPONSIVO
   ============================================ */

.header-responsive {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    flex-wrap: wrap;
    gap: 1rem;
}

@media (max-width: 767.98px) {
    .header-responsive {
        flex-direction: column;
        align-items: stretch;
    }

    .header-left-responsive,
    .header-center-responsive,
    .header-right-responsive {
        width: 100%;
    }

    .header-center-responsive {
        order: 3;
    }

    .header-right-responsive {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 0.5rem;
    }
}

/* ============================================
   CHARTS RESPONSIVOS
   ============================================ */

.chart-container-responsive {
    position: relative;
    width: 100%;
    min-height: 200px;
}

.chart-container-responsive canvas {
    width: 100% !important;
    height: auto !important;
    max-height: 300px;
}

@media (max-width: 575.98px) {
    .chart-container-responsive {
        min-height: 180px;
    }

    .chart-container-responsive canvas {
        max-height: 200px;
    }
}

@media (min-width: 768px) {
    .chart-container-responsive canvas {
        max-height: 350px;
    }
}

/* ============================================
   TIPOGRAFIA RESPONSIVA
   ============================================ */

.heading-responsive {
    font-size: var(--font-xl);
    line-height: 1.2;
}

.subheading-responsive {
    font-size: var(--font-lg);
    line-height: 1.3;
}

.text-responsive {
    font-size: var(--font-base);
    line-height: 1.6;
}

.small-text-responsive {
    font-size: var(--font-sm);
    line-height: 1.5;
}

/* ============================================
   IMAGENS RESPONSIVAS
   ============================================ */

.img-responsive {
    max-width: 100%;
    height: auto;
    display: block;
}

.img-cover {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.img-contain {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ============================================
   SCROLL SUAVE
   ============================================ */

@media (prefers-reduced-motion: no-preference) {
    html {
        scroll-behavior: smooth;
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
    .no-print {
        display: none !important;
    }

    .sidebar-responsive,
    .header-responsive {
        display: none !important;
    }

    .main-content-responsive {
        margin-left: 0 !important;
    }

    body {
        background: white !important;
    }
}

/* ============================================
   SAFE AREAS (Notch, etc.)
   ============================================ */

@supports (padding: env(safe-area-inset-top)) {
    .safe-area-top {
        padding-top: env(safe-area-inset-top);
    }

    .safe-area-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .safe-area-left {
        padding-left: env(safe-area-inset-left);
    }

    .safe-area-right {
        padding-right: env(safe-area-inset-right);
    }
}

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

@media (hover: none) and (pointer: coarse) {
    /* Aumenta área de toque para dispositivos touch */
    .touch-target {
        min-height: 44px;
        min-width: 44px;
    }

    button,
    [role="button"],
    a {
        min-height: 44px;
    }
}

/* ============================================
   LANDSCAPE ESPECÍFICO
   ============================================ */

@media (max-height: 500px) and (orientation: landscape) {
    .modal-content-responsive {
        max-height: 95vh;
    }

    .header-responsive {
        padding: 0.5rem 1rem;
    }
}

/* ============================================
   MOBILE OVERFLOW PREVENTION
   ============================================ */

@media (max-width: 991.98px) {
    html, body {
        overflow-x: hidden;
        max-width: 100vw;
    }
}

/* ============================================
   SCROLL HORIZONTAL MOBILE
   ============================================ */

.scroll-x-mobile {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}

.scroll-x-mobile::-webkit-scrollbar {
    display: none;
}

/* ============================================
   FILTER STACKING MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    .filter-stack-mobile {
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .filter-stack-mobile > * {
        width: 100%;
        min-width: 0;
    }
}

/* ============================================
   BOTÕES ICON-ONLY MOBILE
   ============================================ */

@media (max-width: 767.98px) {
    .btn-icon-mobile span {
        display: none;
    }

    .btn-icon-mobile {
        padding: 10px 12px;
    }
}

/* ============================================
   TEXT SAFE (Cards)
   ============================================ */

.text-safe {
    overflow: hidden;
    text-overflow: ellipsis;
    word-break: break-word;
    min-width: 0;
}

/* ============================================
   DARK MODE OVERRIDES
   ============================================ */

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        /* Auto dark mode se não houver preferência salva */
    }
}
