/* Remover seleção de texto ao tocar (apenas em elementos interativos) */
button, .btn, .mode-btn, .stat-card, .metric-card, th {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Permitir seleção de texto em áreas de conteúdo */
td, p, label, .metric-value, .stat-number {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Melhorar área de toque dos botões */
@media (max-width: 768px) {
    button, .btn, a, input[type="checkbox"] {
        position: relative;
        min-height: 44px;
        min-width: 44px;
    }

    /* Aumentar área de clique visualmente */
    button::before, .btn::before {
        content: '';
        position: absolute;
        top: -5px;
        right: -5px;
        bottom: -5px;
        left: -5px;
    }
}

/* Scroll suave em toda a aplicação */
* {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
}

/* Ocultar scrollbar em mobile mas manter funcionalidade */
@media (max-width: 768px) {
    .table-container {
        scrollbar-width: thin;
        scrollbar-color: #888 #f1f1f1;
    }

    /* Indicador visual de scroll */
    .table-container::after {
        content: '⟵  Arraste para ver mais  ⟶';
        display: block;
        text-align: center;
        padding: 10px;
        background: linear-gradient(90deg, transparent, rgba(76, 175, 80, 0.1), transparent);
        color: #666;
        font-size: 12px;
        position: sticky;
        bottom: 0;
        left: 0;
        width: 100%;
        animation: fadeIn 1s ease-in-out;
    }

    @keyframes fadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }
}

/* Loading spinner mais visível em mobile */
@media (max-width: 768px) {
    .loading {
        padding: 40px 20px;
    }

    .loading .spinner {
        width: 40px;
        height: 40px;
    }
}

/* Animações de feedback de toque */
@media (max-width: 768px) {
    .btn:active,
    .mode-btn:active,
    button:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }

    .stat-card:active,
    .metric-card:active {
        transform: scale(0.99);
        transition: transform 0.1s ease;
    }
}

/* Pull to refresh indicator (visual apenas) */
@media (max-width: 768px) {
    body::before {
        content: '';
        position: fixed;
        top: -50px;
        left: 50%;
        transform: translateX(-50%);
        width: 30px;
        height: 30px;
        border: 3px solid #f3f3f3;
        border-top: 3px solid #4CAF50;
        border-radius: 50%;
        opacity: 0;
        transition: all 0.3s;
        pointer-events: none;
        z-index: 9999;
    }

    body.pulling::before {
        top: 10px;
        opacity: 1;
        animation: spin 1s linear infinite;
    }
}

/* Otimização de inputs para mobile */
@media (max-width: 768px) {
    input[type="text"],
    input[type="password"],
    input[type="email"],
    input[type="number"],
    select {
        font-size: 16px; /* Previne zoom no iOS */
        appearance: none;
        -webkit-appearance: none;
    }

    /* Melhorar aparência dos selects em mobile */
    select {
        background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        background-position: right 12px center;
        padding-right: 35px;
    }
}

/* Orientação paisagem em mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .header {
        padding: 10px;
    }

    .header h1 {
        font-size: 18px;
    }

    .header p {
        font-size: 11px;
    }

    .logo {
        height: 40px;
    }

    .metrics-section {
        padding: 10px;
    }

    .controls {
        padding: 10px;
    }

    .stat-card {
        padding: 12px;
    }

    .stat-number {
        font-size: 24px;
    }
}

/* Mensagem de orientação para telas muito pequenas */
@media (max-width: 320px) {
    body::after {
        content: 'Para melhor experiência, use o modo paisagem';
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, 0.9);
        color: white;
        padding: 8px;
        text-align: center;
        font-size: 11px;
        z-index: 10000;
    }
}

/* Dark mode ajustes para mobile */
@media (max-width: 768px) {
    body.dark-mode {
        background: #1a1a1a;
    }

    body.dark-mode .container {
        background: #2d2d2d;
        color: #e0e0e0;
    }

    body.dark-mode .control-group select,
    body.dark-mode .control-group input {
        background: #3d3d3d;
        color: #e0e0e0;
        border-color: #555;
    }

    body.dark-mode table {
        background: #2d2d2d;
    }

    body.dark-mode td {
        border-color: #444;
    }

    body.dark-mode tr:hover {
        background: #3d3d3d;
    }
}

/* Acessibilidade - Aumentar contraste em modo escuro */
@media (max-width: 768px) and (prefers-color-scheme: dark) {
    .metric-value,
    .stat-number {
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }
}

/* Indicador de conexão mais visível em mobile */
@media (max-width: 768px) {
    .connection-status {
        font-size: 11px;
    }

    .status-dot-conn {
        width: 10px;
        height: 10px;
    }
}

/* Feedback visual para ações de arrasto */
@media (max-width: 768px) {
    .table-container {
        cursor: grab;
    }

    .table-container:active {
        cursor: grabbing;
    }
}

/* Otimização de performance para animações em mobile */
@media (max-width: 768px) {
    .btn,
    .stat-card,
    .metric-card,
    .mode-btn {
        will-change: transform;
        transform: translateZ(0);
        backface-visibility: hidden;
    }
}

/* Espaçamento seguro para notch/safe area em dispositivos iOS */
@supports (padding: max(0px)) {
    .container {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }

    .header {
        padding-top: max(15px, env(safe-area-inset-top));
    }

    @media (max-width: 768px) {
        body {
            padding-bottom: max(5px, env(safe-area-inset-bottom));
        }
    }
}

/* Badge de "Novo" para funcionalidades mobile */
.mobile-feature-badge {
    display: none;
}

@media (max-width: 768px) {
    .mobile-feature-badge {
        display: inline-block;
        background: #4CAF50;
        color: white;
        font-size: 10px;
        padding: 2px 6px;
        border-radius: 10px;
        margin-left: 5px;
        font-weight: bold;
    }
}

/* Ajuste de FAB (Floating Action Button) para ações rápidas em mobile */
@media (max-width: 768px) {
    .fab-mobile {
        position: fixed;
        bottom: 20px;
        right: 20px;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: #4CAF50;
        color: white;
        border: none;
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
        cursor: pointer;
        z-index: 999;
        transition: all 0.3s;
    }

    .fab-mobile:active {
        transform: scale(0.9);
    }

    .fab-mobile:hover {
        box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    }
}
