/* ============================================
   CMMS Industrial - Responsive Design v2.1
   Melhorias: Desktop spacing, Mobile touch, Layout consistente
   CORREÇÕES APLICADAS: Abas 2x2, Botões de Ação 3 Lado a Lado, Desbloqueio Scroll (touch), Borda nos Cards
   ============================================ */

/* ========== BASE ========== */
* {
    -webkit-tap-highlight-color: transparent;
}

body {
    overflow-x: hidden;
}

/* ========== MOBILE (< 480px) ========== */
@media (max-width: 480px) {
    
    /* ===== HEADER RECOLHIVEL ===== */
    .cmd-header {
        padding: 0 12px;
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        position: sticky;
        top: 0;
        z-index: 1000;
        gap: 8px;
        transition: all var(--transition-normal);
        background: var(--bg-secondary);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    }
    
    .cmd-header.expanded {
        height: auto;
        flex-wrap: wrap;
        padding: 12px;
        gap: 8px;
    }
    
    .btn-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 40px;
        height: 40px;
        padding: 0;
        font-size: 18px;
        flex-shrink: 0;
        background: transparent;
        border: none;
        color: var(--text-primary);
        cursor: pointer;
        transition: all var(--transition-fast);
        border-radius: 8px;
    }
    
    .btn-menu-toggle:active {
        background: rgba(255, 255, 255, 0.1);
        transform: scale(0.96);
    }
    
    .header-logo {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
    }
    
    .header-logo i {
        font-size: 22px;
        color: var(--accent-blue);
    }
    
    .header-logo h1 {
        font-size: 18px;
        font-weight: 700;
        color: var(--text-primary);
    }
    
    .badge-grupo {
        display: none;
    }
    
    .cmd-header.expanded .badge-grupo {
        display: flex;
        font-size: 11px;
        padding: 6px 12px;
        order: 5;
        width: 100%;
        justify-content: center;
        margin-top: 4px;
    }
    
    .header-center {
        display: none;
    }
    
    .cmd-header.expanded .header-center {
        display: flex;
        justify-content: center;
        width: 100%;
        order: 6;
    }
    
    .datetime {
        font-size: 12px;
        gap: 6px;
    }
    
    .header-right {
        display: flex;
        align-items: center;
        gap: 8px;
        flex-shrink: 0;
        margin-left: auto;
    }
    
    .user-info {
        display: flex;
        align-items: center;
        gap: 6px;
    }
    
    .user-info i {
        font-size: 18px;
        color: var(--accent-blue);
    }
    
    .user-info #headerUserName,
    .user-info #headerXPBadge {
        display: none;
    }
    .user-info #headerAvatarContainer {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .btn-logout {
        padding: 6px;
        width: 36px;
        height: 36px;
        display: flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
    }
    
    .btn-kpi-config {
        display: none;
    }
    
    /* ===== HEADER OVERLAY ===== */
    .header-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.4);
        z-index: 999;
        backdrop-filter: blur(2px);
    }
    
    .header-overlay.active {
        display: block;
    }
    
    /* ===== SIDEBAR ===== */
    .cmd-sidebar {
        position: fixed;
        left: -300px;
        top: 56px;
        width: 280px;
        height: calc(100vh - 56px);
        z-index: 1001;
        transition: left var(--transition-normal);
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.3);
        background: var(--bg-secondary);
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        padding-bottom: 20px;
    }
    
    .cmd-sidebar.expanded {
        left: 0;
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 56px;
        left: 0;
        width: 100%;
        height: calc(100vh - 56px);
        background: rgba(0, 0, 0, 0.6);
        z-index: 1000;
        backdrop-filter: blur(3px);
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    .nav-item {
        padding: 14px 20px;
        font-size: 15px;
        min-height: 50px;
        display: flex;
        align-items: center;
        gap: 14px;
        cursor: pointer;
        color: var(--text-muted);
        border-left: 3px solid transparent;
        margin: 2px 8px;
        border-radius: 8px;
        transition: all var(--transition-fast);
    }
    
    .nav-item:active {
        background: var(--bg-hover);
        transform: scale(0.98);
    }
    
    .nav-item.active {
        background: rgba(59, 130, 246, 0.15);
        color: var(--accent-blue);
        border-left-color: var(--accent-blue);
    }
    
    .nav-item i {
        font-size: 20px;
        width: 28px;
        text-align: center;
    }
    
    .nav-text {
        display: inline-block;
        font-size: 14px;
    }
    
    /* ===== LAYOUT PRINCIPAL ===== */
    .cmd-layout {
        min-height: calc(100vh - 56px);
        padding-top: 0;
    }
    
    .cmd-content {
        padding: 12px;
        margin: 0;
        width: 100%;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    /* ===== KPIs - 2 COLUNAS NO MOBILE ===== */
    .kpi-panel {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 16px;
        width: 100%;
    }
    
    .kpi-card {
        padding: 12px 8px;
        gap: 6px;
        border-radius: 12px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        min-height: 90px;
        background: var(--bg-card);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
        text-align: center;
        transition: transform 0.1s ease;
    }
    
    .kpi-card:active {
        transform: scale(0.98);
    }
    
    .kpi-icon-wrapper {
        width: 36px;
        height: 36px;
        font-size: 16px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    .kpi-info {
        width: 100%;
    }
    
    .kpi-info h3 {
        font-size: 10px;
        margin-bottom: 4px;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        color: var(--text-muted);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .kpi-value {
        font-size: 20px;
        font-weight: 800;
        color: var(--text-primary);
        line-height: 1.2;
    }
    
    .kpi-info small {
        display: none;
    }
    
    /* ===== ALERTAS ===== */
    .alerts-panel {
        padding: 12px;
        margin-bottom: 16px;
        border-radius: 12px;
        background: var(--bg-card);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    }
    
    .alerts-header {
        margin-bottom: 10px;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .alerts-header h2 {
        font-size: 14px;
    }
    
    .alert-item {
        padding: 10px 12px;
        font-size: 12px;
        gap: 8px;
        border-radius: 8px;
        margin-bottom: 6px;
    }
    
    .btn-dismiss-all {
        font-size: 11px;
        padding: 5px 12px;
    }
    
    /* ===== MODULE CONTAINER ===== */
    .module-container {
        padding: 0;
        min-height: 300px;
        width: 100%;
    }
    
    .module-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        margin-bottom: 16px;
    }
    
    .module-title h2 {
        font-size: 18px;
    }
    
    .module-title p {
        font-size: 12px;
    }
    
    .module-actions {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .module-actions button {
        flex: 1;
        min-width: 0;
        font-size: 12px;
        padding: 10px 8px;
    }
    
    .module-filters {
        flex-direction: column;
        gap: 10px;
        margin-bottom: 16px;
    }
    
    .module-filters .form-group {
        width: 100%;
    }
    
    .module-filters .form-control {
        width: 100%;
    }
    
    /* ===== BOTOES E INTERACOES ===== */
    .btn-primary, .btn-secondary, .btn-danger {
        padding: 10px 16px;
        font-size: 14px;
        min-height: 44px;
        border-radius: 8px;
    }
    
    .btn-icon {
        width: 40px;
        height: 40px;
        min-width: 40px;
    }
    
    /* ===== FORMULARIOS ===== */
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-group label {
        font-size: 13px;
        margin-bottom: 6px;
        display: block;
    }
    
    .form-control {
        padding: 12px 14px;
        font-size: 16px;
        border-radius: 8px;
        width: 100%;
    }
    
    .form-row {
        display: flex;
        flex-direction: column;
        gap: 12px;
        margin-bottom: 16px;
    }
    
    /* ===== LOGIN ===== */
    .login-background {
        padding: 16px;
    }
    
    .login-grid {
        flex-direction: column;
        width: 100%;
        border-radius: 20px;
        overflow: hidden;
    }
    
    .login-branding {
        display: none;
    }
    
    .login-form-container {
        padding: 30px 20px;
    }
    
    .login-card {
        max-width: 100%;
    }
    
    .login-header i {
        font-size: 40px;
    }
    
    .login-header h2 {
        font-size: 22px;
    }
    
    /* ===== MODAIS - CORRIGIDO PARA TELA CHEIA ===== */
    .modal {
        padding: 0;
        align-items: center;
        overscroll-behavior: contain;
        touch-action: auto; /* CORREÇÃO: Permite deslizar a tela livremente */
    }
    
    .modal-dialog {
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    
    .modal-content {
        height: 100%;
        max-height: 100dvh;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        border: none;
    }
    
    .modal-header {
        padding: 16px;
        position: sticky;
        top: 0;
        background: var(--bg-card);
        z-index: 10;
        border-radius: 0;
    }
    
    .modal-header h2 {
        font-size: 18px;
    }
    
    .modal-body {
        padding: 16px;
        flex: 1;
        max-height: none;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }

    .modal-body iframe {
        width: 100%;
        height: 100%;
        min-height: 75vh;
        border-radius: 8px;
    }
    
    /* CORREÇÃO: Rodapé Mobile Otimizado (Sem bordas enormes) */
    .modal-footer {
        padding: 8px 12px;
        gap: 8px;
        flex-direction: row;
        flex-wrap: nowrap;
        position: sticky;
        bottom: 0;
        background: var(--bg-card);
        border-top: 1px solid var(--border-color);
        width: 100%;
        align-items: center;
    }

    .modal-footer > div {
        display: flex;
        flex: 1;
        gap: 6px;
    }
    
    .modal-footer button {
        flex: 1;
        padding: 10px 4px;
        font-size: 11px;
        margin: 0;
        white-space: nowrap;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
    }
    
    /* ===== TOAST ===== */
    .toast-container {
        left: 12px;
        right: 12px;
        bottom: 20px;
        top: auto;
    }
    
    .toast {
        font-size: 13px;
        padding: 12px 16px;
        border-radius: 12px;
        margin-bottom: 8px;
    }
    
    /* ===== INSTALL BANNER ===== */
    .install-banner {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        z-index: 1500;
        width: auto;
        max-width: 480px;
        min-width: 280px;
        animation: resp-slideUp 0.3s ease-out;
    }
    
    .install-banner-content {
        display: flex;
        align-items: center;
        gap: 12px;
        background: var(--bg-secondary);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
        border-radius: 12px;
        padding: 12px 16px;
        box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    }
    
    .install-banner-icon {
        font-size: 24px;
        color: var(--accent-blue);
        flex-shrink: 0;
    }
    
    .install-banner-text {
        flex: 1;
    }
    
    .install-banner-text strong {
        display: block;
        font-size: 14px;
        color: var(--text-primary);
        font-weight: 600;
    }
    
    .install-banner-text span {
        font-size: 11px;
        color: var(--text-muted);
        display: block;
    }
    
    .install-banner .btn-sm {
        padding: 8px 16px;
        font-size: 12px;
        flex-shrink: 0;
        border-radius: 8px;
    }
    
    .install-banner #btnInstall {
        background: var(--accent-blue);
        color: white;
        border: none;
        cursor: pointer;
        transition: all 0.2s ease;
    }
    
    .install-banner #btnInstall:hover {
        background: var(--accent-cyan);
    }
    
    .install-banner #btnDismissInstall {
        background: transparent;
        border: none;
        color: var(--text-muted);
        cursor: pointer;
        padding: 4px 8px;
        font-size: 16px;
        flex-shrink: 0;
        transition: color 0.2s ease;
    }
    
    .install-banner #btnDismissInstall:hover {
        color: var(--danger);
    }
    
    /* ===== TOUCH ===== */
    .nav-item, 
    .btn-primary, 
    .btn-secondary,
    .btn-icon, 
    .tab-item, 
    .btn-menu-toggle,
    .pcm-tab, 
    .module-tab {
        min-height: 48px;
        touch-action: manipulation;
    }
    
    /* ===== SCROLL ===== */
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    
    ::-webkit-scrollbar-track {
        background: var(--bg-primary);
        border-radius: 4px;
    }
    
    ::-webkit-scrollbar-thumb {
        background: var(--border-color);
        border-radius: 4px;
    }
}

/* ========== TABLET E MOBILE EXTENDIDO (481px - 768px) ========== */
@media (min-width: 481px) and (max-width: 768px) {
    
    .cmd-header {
        padding: 0 20px;
        height: 60px;
    }
    
    .btn-menu-toggle {
        display: flex;
        width: 40px;
        height: 40px;
    }
    
    .cmd-sidebar {
        position: fixed;
        left: -280px;
        top: 60px;
        width: 280px;
        height: calc(100vh - 60px);
        z-index: 1001;
        transition: left var(--transition-normal);
        background: var(--bg-secondary);
    }
    
    .cmd-sidebar.expanded {
        left: 0;
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 60px;
        left: 0;
        width: 100%;
        height: calc(100vh - 60px);
        background: rgba(0, 0, 0, 0.6);
        z-index: 1000;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    .nav-text {
        display: inline-block;
    }
    
    .cmd-content {
        padding: 16px;
        margin: 0;
    }
    
    .kpi-panel {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }
    
    .kpi-card {
        padding: 14px 12px;
    }
    
    .kpi-value {
        font-size: 24px;
    }
    
    .module-filters {
        display: flex;
        flex-wrap: wrap;
        gap: 12px;
    }
    
    .module-filters .form-group {
        flex: 1;
        min-width: 150px;
    }

    .modal {
        padding: 0;
        align-items: center;
        overscroll-behavior: contain;
        touch-action: auto; /* CORREÇÃO: Permite deslizar a tela */
    }
    .modal-dialog {
        width: 100%;
        max-width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    .modal-content {
        height: 100%;
        max-height: 100dvh;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }
    .modal-body {
        flex: 1;
        overflow-y: auto;
        overscroll-behavior: contain;
        -webkit-overflow-scrolling: touch;
    }
    .modal-body iframe {
        width: 100%;
        height: 100%;
        min-height: 70vh;
    }
    
    /* CORREÇÃO: Rodapé Mobile Otimizado (Tablet Mínimo) */
    .modal-footer {
        padding: 10px 16px;
        gap: 10px;
        flex-direction: row;
        flex-wrap: nowrap;
        align-items: center;
    }
    .modal-footer > div {
        display: flex;
        flex: 1;
        gap: 8px;
    }
    .modal-footer button {
        flex: 1;
        padding: 10px 8px;
        font-size: 13px;
        margin: 0;
    }

    .toast-container {
        top: 80px;
        right: 20px;
        bottom: auto;
        max-width: 350px;
    }
}

/* ============================================
   CORREÇÃO GLOBAL ABAS (TABS) NO MOBILE E TABLET (2x2)
   ============================================ */
@media (max-width: 768px) {
    #osTabs {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
        padding: 12px 16px 0;
        border-bottom: none;
        background: var(--bg-card);
    }
    #osTabs .module-tab {
        width: 100%;
        margin: 0;
        border: 1px solid var(--border-color);
        border-radius: 6px;
        padding: 10px 4px;
        font-size: 11px;
        white-space: normal;
        line-height: 1.2;
        min-height: 48px;
        text-align: center;
        background: var(--bg-secondary);
    }
    #osTabs .module-tab.active {
        background: rgba(59, 130, 246, 0.1);
        border-color: var(--accent-blue);
        color: var(--accent-blue);
    }
}

/* ========== DESKTOP (> 768px) ========== */
@media (min-width: 769px) {
    
    .cmd-header {
        padding: 0 24px;
        height: var(--header-height);
    }
    
    .btn-menu-toggle {
        display: none;
    }
    
    .cmd-sidebar {
        width: var(--sidebar-width-desktop);
        position: relative;
        left: 0;
        min-height: calc(100vh - var(--header-height));
        transition: width var(--transition-normal);
    }
    
    body.sidebar-collapsed .cmd-sidebar {
        width: var(--sidebar-width-collapsed);
    }
    
    body.sidebar-collapsed .nav-text,
    body.sidebar-collapsed .sidebar-header span,
    body.sidebar-collapsed .sidebar-footer {
        display: none;
    }
    
    body.sidebar-collapsed .nav-item {
        justify-content: center;
        padding: 14px 0;
    }
    
    body.sidebar-collapsed .nav-item i {
        margin: 0;
        font-size: 20px;
    }
    
    .cmd-layout {
        display: flex;
        width: 100%;
    }
    
    .cmd-content {
        flex: 1;
        padding: 24px;
        margin: 0;
        overflow-x: auto;
    }
    
    .sidebar-overlay,
    .header-overlay {
        display: none;
    }
    
    .kpi-panel {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
        margin-bottom: 24px;
    }
    
    .kpi-card {
        padding: 20px 16px;
        transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    }
    
    .kpi-card:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-md);
    }
    
    .kpi-value {
        font-size: 28px;
    }
    
    .badge-grupo {
        display: inline-flex;
    }
    
    .header-center {
        display: flex;
    }
    
    .user-info span {
        display: inline-block;
    }
    
    .module-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 24px;
        flex-wrap: wrap;
        gap: 16px;
    }
    
    .module-filters {
        display: flex;
        flex-wrap: wrap;
        gap: 16px;
        align-items: flex-end;
        margin-bottom: 24px;
    }
    
    .module-filters .form-group {
        margin-bottom: 0;
        min-width: 180px;
    }
    
    .form-row {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 16px;
    }
    
    /* Modais Desktop */
    .modal-dialog {
        width: 90%;
        max-width: 800px;
        margin: 50px auto;
    }
    
    .modal-sm { max-width: 400px; }
    .modal-md { max-width: 600px; }
    .modal-lg { max-width: 900px; }
    .modal-xl { max-width: 1200px; }

    #osModalDynamic .modal-dialog {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
    }
    
    .modal-content {
        border-radius: 16px;
    }
    
    .modal-footer {
        flex-direction: row;
        justify-content: flex-end;
    }
    
    .modal-footer button {
        width: auto;
        min-width: 120px;
    }
    
    .btn-primary:hover,
    .btn-secondary:hover {
        transform: translateY(-1px);
    }
    
    .nav-item:hover {
        background: var(--bg-hover);
        border-radius: 8px;
        margin: 2px 12px;
        padding: 12px 16px;
    }

    .install-banner {
        bottom: 34px;
        left: 50%;
        transform: translateX(-50%);
        max-width: 820px;
        width: calc(100% - 200px);
        z-index: 1000;
    }

    .install-banner-content {
        padding: 16px 20px;
        gap: 16px;
        border-radius: 14px;
        box-shadow: 0 20px 50px rgba(0,0,0,0.35);
        background: linear-gradient(90deg, rgba(255,255,255,0.98), rgba(248,249,250,0.98));
    }

    .install-banner-icon {
        font-size: 28px;
        width: 56px;
        height: 56px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: var(--accent-blue);
        color: #fff;
        border-radius: 10px;
        flex-shrink: 0;
    }

    .install-banner-text strong {
        font-size: 18px;
    }

    .install-banner-text span {
        font-size: 13px;
    }

    .install-banner .btn-sm {
        padding: 10px 18px;
        font-size: 14px;
        border-radius: 10px;
    }
}

/* ========== LARGE DESKTOP (> 1200px) ========== */
@media (min-width: 1201px) {
    .cmd-content {
        padding: 32px;
    }
    
    .kpi-panel {
        gap: 24px;
    }
    
    .kpi-card {
        padding: 24px;
    }
    
    .kpi-value {
        font-size: 32px;
    }
    
    .module-filters .form-group {
        min-width: 200px;
    }
}

/* ========== TOUCH SCREEN OTIMIZACOES ========== */
@media (hover: none) and (pointer: coarse) {
    .cmd-content,
    .modal-body,
    .gantt-table-container {
        -webkit-overflow-scrolling: touch;
        scroll-behavior: smooth;
        overscroll-behavior: contain;
    }
    
    .nav-item, 
    button, 
    .btn, 
    .tab-item,
    .module-tab,
    .pcm-tab {
        cursor: pointer;
        touch-action: manipulation;
    }
    
    .kpi-card:hover,
    .btn-primary:hover,
    .nav-item:hover {
        transform: none;
    }
}

/* ========== SAFE AREA (iPhone X+) ========== */
@supports (padding: env(safe-area-inset-bottom)) {
    .cmd-layout { 
        padding-bottom: env(safe-area-inset-bottom);
    }
    
    .install-banner { 
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
    
    .toast-container { 
        bottom: calc(20px + env(safe-area-inset-bottom));
    }
    
    .cmd-header { 
        padding-top: env(safe-area-inset-top);
        min-height: calc(56px + env(safe-area-inset-top));
    }
    
    .modal-dialog {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ========== ANIMACOES ========== */
@keyframes fadeOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(100%); }
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes resp-fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes resp-slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal.active .modal-dialog {
    animation: slideInUp 0.3s ease-out;
}

.toast {
    animation: slideInUp 0.3s ease-out;
}

.install-banner {
    animation: resp-slideUp 0.3s ease-out;
}

/* ========== REDUCED MOTION ========== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms;
        animation-iteration-count: 1;
        transition-duration: 0.01ms;
        scroll-behavior: auto;
    }
}

/* ========== PRINT ========== */
@media print {
    .cmd-sidebar, 
    .cmd-header, 
    .alerts-panel,
    .btn-primary, 
    .btn-icon, 
    .btn-secondary,
    .install-banner,
    .toast-container, 
    .btn-menu-toggle,
    .header-overlay, 
    .sidebar-overlay,
    .module-actions,
    .pcm-actions {
        display: none;
    }
    
    .cmd-content { 
        padding: 0; 
        margin: 0;
        overflow: visible;
    }
    
    body { 
        background: white; 
        color: black;
    }
    
    .data-table {
        border: 1px solid #ccc;
    }
    
    .data-table th {
        background: #f0f0f0;
        color: #000;
    }
    
    a {
        text-decoration: none;
        color: #000;
    }
}

/* ========================================================
   CORRECAO GLOBAL: TABELAS RESPONSIVAS MOBILE
   ======================================================== */
@media (max-width: 768px) {
    .data-table,
    .table-responsive table {
        width: 100%;
        border-collapse: collapse;
    }
    
    .data-table tbody tr,
    .table-responsive tbody tr {
        display: block;
        margin-bottom: 16px;
        background: var(--bg-card);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
        border: 1px solid var(--border-color); /* CORREÇÃO: Borda/Quadro nos cards adicionado */
        border-radius: 12px;
        padding: 12px;
    }
    
    .data-table thead,
    .table-responsive thead {
        display: none;
    }
    
    .data-table td,
    .table-responsive td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        text-align: right;
        gap: 16px;
    }
    
    .data-table td:last-child,
    .table-responsive td:last-child {
        border-bottom: none;
    }
    
    .data-table td::before,
    .table-responsive td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
        flex: 1;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }
    
    .data-table td > *,
    .table-responsive td > * {
        text-align: right;
        flex: 1;
    }
    
    .data-table td .action-buttons,
    .table-responsive td .action-buttons {
        display: flex;
        gap: 8px;
        justify-content: flex-end;
    }
    
    .status-badge {
        display: inline-block;
        padding: 4px 10px;
        font-size: 11px;
    }
}

/* ============================================
   CORRECAO DO MODULO HISTORICO
   ============================================ */

@media (max-width: 768px) {
    .history-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 16px;
    }
    
    .history-filters {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        padding: 16px;
    }
    
    .history-filters .form-group {
        margin-bottom: 0;
    }
    
    .btn-filter-wrapper {
        grid-column: span 2;
    }
    
    .btn-filter-wrapper button {
        width: 100%;
    }
    
    .indicator-main-cards {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .indicator-main-card {
        padding: 14px;
        gap: 12px;
    }
    
    .indicator-icon {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }
    
    .indicator-value {
        font-size: 22px;
    }
    
    .history-tabs {
        overflow-x: auto;
        display: flex;
        flex-wrap: nowrap;
        gap: 2px;
    }
    
    .history-tab {
        padding: 10px 14px;
        font-size: 11px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    .history-tab i {
        display: none;
    }
    
    .matriz-grid {
        display: grid;
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .matriz-card {
        padding: 16px;
    }
    
    .pert-diagram {
        flex-direction: column;
        gap: 8px;
        padding: 20px;
    }
    
    .pert-arrow {
        transform: rotate(90deg);
    }
    
    .pert-node {
        padding: 10px 18px;
        font-size: 12px;
    }
    
    .indicator-detail-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }
    
    .agrupado-stats {
        flex-direction: column;
        gap: 8px;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .history-filters {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .btn-filter-wrapper {
        grid-column: auto;
    }
    
    .indicator-main-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .matriz-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
   CORRECAO DO MODULO DASHBOARDS
   ============================================ */

.dashboard-section {
    background: var(--bg-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: 0;
    padding: 20px;
    margin-bottom: 20px;
}

.dashboard-section h3 {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-left: 3px solid var(--accent-blue);
    padding-left: 12px;
}

.dashboard-status-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}

.dashboard-status-card {
    background: var(--bg-secondary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: 0;
    padding: 16px;
    text-align: center;
}

.dashboard-status-card strong {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dashboard-status-card span {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
}

.dashboard-chart-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-top: 16px;
}

.dashboard-chart-item {
    background: var(--bg-secondary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: 0;
    padding: 16px;
}

.dashboard-chart-item span {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-align: center;
}

.dashboard-chart-bar {
    height: 8px;
    background: var(--accent-blue);
    border-radius: 0;
    margin: 10px 0;
    transition: width 0.5s ease;
}

.dashboard-chart-item strong {
    display: block;
    font-size: 14px;
    color: var(--text-primary);
    text-align: center;
    margin-top: 8px;
}

.dashboard-bar-chart {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.bar-chart-item {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.bar-chart-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    min-width: 120px;
    font-size: 13px;
    color: var(--text-secondary);
}

.bar-chart-label span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.bar-chart-track {
    flex: 1;
    background: var(--bg-primary);
    border-radius: 0;
    height: 8px;
    overflow: hidden;
}

.bar-chart-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan));
    border-radius: 0;
    transition: width 0.5s ease;
}

.dashboard-nav {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.dashboard-tab {
    padding: 10px 20px;
    background: var(--bg-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    border-radius: 0;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dashboard-tab:hover {
    background: var(--bg-hover);
    transform: translateY(-1px);
}

.dashboard-tab.active {
    background: var(--accent-blue);
    color: white;
}

.dashboard-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
    padding: 16px;
    background: var(--bg-card);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
    border-radius: 0;
}

.dashboard-filter-row .filter-group {
    flex: 1;
    min-width: 150px;
}

.dashboard-filter-row label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.dashboard-filter-row select {
    width: 100%;
    padding: 10px;
    background: var(--bg-input);
    border: none;
    border-radius: 0;
    color: var(--text-primary);
}

@media (max-width: 768px) {
    .dashboard-status-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .dashboard-status-card {
        padding: 12px;
    }
    
    .dashboard-status-card span {
        font-size: 22px;
    }
    
    .dashboard-status-card strong {
        font-size: 10px;
    }
    
    .dashboard-chart-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .bar-chart-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .bar-chart-label {
        width: 100%;
        justify-content: space-between;
    }
    
    .bar-chart-track {
        width: 100%;
    }
    
    .dashboard-nav {
        gap: 8px;
    }
    
    .dashboard-tab {
        flex: 1;
        text-align: center;
        font-size: 12px;
        padding: 8px 12px;
    }
    
    .dashboard-filter-row {
        flex-direction: column;
        gap: 12px;
    }
    
    .dashboard-filter-row .filter-group {
        width: 100%;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .dashboard-status-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .dashboard-chart-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ============================================
   CORRECAO DO MODULO DE ORDENS DE SERVICO
   ============================================ */

@media (max-width: 768px) {
    .operacional-module .module-filters {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    
    .operacional-module .module-filters .form-group {
        margin-bottom: 0;
    }
    
    .operacional-module .module-filters .btn-block {
        grid-column: span 2;
    }
}

@media (max-width: 480px) {
    .operacional-module .module-filters {
        grid-template-columns: 1fr;
    }
    
    .operacional-module .module-filters .btn-block {
        grid-column: auto;
    }
}

/* ============================================
   CORRECAO DO MODULO PCM
   ============================================ */

@media (max-width: 768px) {
    .pcm-summary {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

/* ============================================
   CORRECAO DOS LABELS DAS TABELAS
   ============================================ */

@media (max-width: 768px) {
    .cadastros-module .data-table td:nth-child(1)::before { content: "ID"; }
    .cadastros-module .data-table td:nth-child(2)::before { content: "Nome"; }
    .cadastros-module .data-table td:nth-child(3)::before { content: "Tag"; }
    .cadastros-module .data-table td:nth-child(4)::before { content: "Tipo"; }
    .cadastros-module .data-table td:nth-child(5)::before { content: "Localizacao"; }
    .cadastros-module .data-table td:nth-child(6)::before { content: "Marca"; }
    .cadastros-module .data-table td:nth-child(7)::before { content: "Modelo"; }
    .cadastros-module .data-table td:nth-child(8)::before { content: "Patrimonio"; }
    .cadastros-module .data-table td:nth-child(9)::before { content: "Descricao"; }
    .cadastros-module .data-table td:nth-child(10)::before { content: "Acoes"; }
    
    #listaUsuariosAtivosBody td:nth-child(1)::before { content: "Nome"; }
    #listaUsuariosAtivosBody td:nth-child(2)::before { content: "Matricula"; }
    #listaUsuariosAtivosBody td:nth-child(3)::before { content: "Cargo"; }
    #listaUsuariosAtivosBody td:nth-child(4)::before { content: "Status"; }
    #listaUsuariosAtivosBody td:nth-child(5)::before { content: "Acao"; }
    
    #listaAuthBody td:nth-child(1)::before { content: "Matricula"; }
    #listaAuthBody td:nth-child(2)::before { content: "Nome"; }
    #listaAuthBody td:nth-child(3)::before { content: "Cargo Atribuido"; }
    #listaAuthBody td:nth-child(4)::before { content: "Acao"; }
}

/* ============================================
   MELHORIAS DA TABELA DE EQUIPAMENTOS NO MOBILE
   ============================================ */

@media (max-width: 768px) {
    .cadastros-module .data-table thead {
        display: none;
    }
    
    .cadastros-module .data-table tbody tr {
        display: block;
        margin-bottom: 12px;
        background: var(--bg-card);
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
        padding: 16px;
        border: 1px solid var(--border-color); /* CORREÇÃO: Borda inserida */
        border-radius: 12px;
    }
    
    .cadastros-module .data-table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        padding: 10px 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        text-align: right;
        gap: 16px;
    }
    
    .cadastros-module .data-table td:last-child {
        border-bottom: none;
    }
    
    .cadastros-module .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
        flex: 1;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }
    
    .cadastros-module .data-table td > * {
        text-align: right;
        flex: 1;
    }
    
    /* CORREÇÃO: Ações Lado a Lado no Cadastros */
    .cadastros-module .action-buttons {
        display: flex;
        gap: 6px;
        justify-content: space-between;
        flex-direction: row;
        flex-wrap: nowrap;
        width: 100%;
        margin-top: 10px;
    }
    
    .cadastros-module .btn-icon {
        flex: 1;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-direction: column; /* Ícone acima do texto p/ caber melhor */
        gap: 6px;
        padding: 10px 4px;
        background: var(--bg-secondary);
        box-shadow: 0 2px 8px rgba(0,0,0,0.15);
        border-radius: 6px;
        font-size: 12px;
        color: var(--text-primary);
        min-width: 0; /* Permite quebrar se tela for minúscula */
    }
    
    .cadastros-module .btn-icon i {
        font-size: 16px;
        margin: 0;
    }
    
    .cadastros-module .btn-text {
        display: inline-block;
        margin-left: 0;
        font-size: 10px;
        font-weight: 500;
    }
    
    .cadastros-module .btn-edit {
        color: var(--accent-blue);
        border-color: rgba(59, 130, 246, 0.3);
    }
    
    .cadastros-module .btn-delete {
        color: var(--danger);
        border-color: rgba(239, 68, 68, 0.3);
    }
    
    .cadastros-module .btn-qr {
        color: var(--success);
        border-color: rgba(16, 185, 129, 0.3);
    }
}

/* ============================================
   REMOVER SCROLL HORIZONTAL DA TABELA DE EQUIPAMENTOS
   ============================================ */

@media (max-width: 768px) {
    .cadastros-module .table-responsive {
        overflow-x: visible;
        overflow-y: visible;
    }
    
    .cadastros-module .data-table {
        min-width: 100%;
        width: 100%;
    }
}

/* ============================================
   CORRECAO DO LEITOR QR CODE - TELA CHEIA
   ============================================ */

#qrModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000000;
    z-index: 1000;
    padding: 0;
    margin: 0;
}

#qrModal .modal-dialog {
    width: 100%;
    height: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

#qrModal .modal-content {
    width: 100%;
    height: 100%;
    background: #000000;
    border-radius: 0;
    border: none;
}

#qrModal .modal-body {
    padding: 0;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #000000;
}

#qr-reader {
    width: 100%;
    height: 100%;
    max-width: 100%;
}

#qr-reader video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#qrModal .modal-header {
    display: none;
}

#qrModal .btn-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0,0,0,0.6);
    color: white;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    border: 1px solid rgba(255,255,255,0.3);
    cursor: pointer;
}

#qrModal .btn-close:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

@media (max-width: 480px) {
    #qrModal .btn-close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 20px;
    }
}

/* ============================================
   GARANTIR LABELS DO MODAL DE EQUIPAMENTO
   ============================================ */

.modal-body .form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 13px;
}

.modal-body .form-group input,
.modal-body .form-group select,
.modal-body .form-group textarea {
    display: block;
    width: 100%;
}

.modal-body .tab-btn {
    display: inline-block;
    padding: 10px 16px;
    font-size: 13px;
}

.modal-body .tab-content {
    display: none;
}

.modal-body .tab-content.active {
    display: block;
}

/* ============================================
   MELHORIA GERAL - BOTOES COM TAMANHO PADRAO
   ============================================ */

@media (max-width: 768px) {
    .module-actions button,
    .history-actions button,
    .pcm-actions button,
    .almox-actions button,
    .inventory-actions button {
        min-height: 44px;
        border-radius: 6px;
    }
}

/* ============================================
   CORRECAO PARA O GANTT NO MOBILE
   ============================================ */

@media (max-width: 768px) {
    .gantt-container {
        overflow-x: auto;
    }
    
    .gantt-table {
        min-width: 650px;
    }
    
    .gantt-table th,
    .gantt-table td {
        padding: 8px 4px;
        font-size: 11px;
    }
    
    .gantt-day-header {
        font-size: 10px;
        min-width: 32px;
    }
    
    .gantt-bar {
        height: 16px;
        min-width: 8px;
    }
}

/* ============================================
   CORRECAO PARA DROPDOWNS E SELECTS
   ============================================ */

@media (max-width: 768px) {
    select.form-control,
    input.form-control,
    textarea.form-control {
        font-size: 16px;
    }
    
    select option {
        font-size: 14px;
    }
}

/* ============================================
   ALMOXARIFADO - GARANTIA MOBILE
   ============================================ */
@media (max-width: 768px) {
    .almox-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        width: 100%;
    }

    .almox-actions button {
        flex: 1 1 calc(50% - 10px);
        font-size: 12px;
        padding: 12px 8px;
        text-align: center;
        justify-content: center;
        white-space: normal;
        min-height: 44px;
    }

    .almox-tabs {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        border-bottom: none;
    }

    .tab-btn {
        flex: 1 1 calc(33.333% - 8px);
        justify-content: center;
        text-align: center;
        white-space: normal;
        word-break: break-word;
        padding: 10px 6px;
        font-size: 11px;
        min-height: 48px;
        background: var(--almox-bg-card);
        border-radius: 0px;
    }

    .tab-btn i {
        display: inline-block;
        margin-right: 4px;
    }

    .almox-header {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }

    .almox-title {
        justify-content: center;
        flex-direction: column;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .tab-btn {
        flex: 1 1 calc(50% - 8px);
        font-size: 10px;
        padding: 8px 4px;
        min-height: 44px;
    }
}

@media (max-width: 350px) {
    .tab-btn {
        flex: 1 1 100%;
    }
}

/* ============================================
   FORÇAR TELA CHEIA PARA MODAL DE OS (DESKTOP)
   ============================================ */
@media (min-width: 769px) {
    #osModalDynamic .modal-dialog {
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
    }
}
