/**
 * =====================================================
 * ROTATRUCK v8.2.0 - SOS CSS
 * =====================================================
 * Fase 9: Alertas + Segurança
 * 
 * Seções:
 * 1. Botão SOS Flutuante
 * 2. Modal de Emergência
 * 3. Contatos de Emergência
 * 4. Rastreamento / Compartilhamento
 * 5. Animações
 * 6. Responsivo
 * =====================================================
 */

/* =====================================================
   1. BOTÃO SOS FLUTUANTE
   ===================================================== */
#sos-button {
    position: fixed;
    bottom: 170px; /* Acima dos FABs direita */
    right: 16px;
    z-index: var(--z-hud);
    display: none; /* Escondido por padrão, mostrar durante navegação */
    width: 56px;
    height: 56px;
    background: linear-gradient(145deg, #ff1744, #d50000);
    border: none;
    border-radius: 50%;
    box-shadow: 
        0 4px 15px rgba(213, 0, 0, 0.4),
        0 0 0 0 rgba(255, 23, 68, 0.4);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

#sos-button.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

#sos-button:hover {
    transform: scale(1.05);
    box-shadow: 
        0 6px 20px rgba(213, 0, 0, 0.5),
        0 0 0 0 rgba(255, 23, 68, 0.4);
}

#sos-button:active {
    transform: scale(0.95);
}

/* Texto SOS */
.sos-text {
    font-size: 16px;
    font-weight: 800;
    color: #ffffff;
    letter-spacing: 1px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Animação de pulsação contínua */
#sos-button.pulse {
    animation: sosPulse 2s ease-in-out infinite;
}

/* Estado de segurar (hold) */
#sos-button.holding {
    animation: sosHolding 3s linear forwards;
}

/* Ring de progresso ao segurar */
.sos-progress-ring {
    position: absolute;
    top: -4px;
    left: -4px;
    width: 68px;
    height: 68px;
    pointer-events: none;
}

.sos-progress-ring circle {
    fill: none;
    stroke: #ffffff;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-dasharray: 201; /* 2 * PI * 32 */
    stroke-dashoffset: 201;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke-dashoffset 3s linear;
}

#sos-button.holding .sos-progress-ring circle {
    stroke-dashoffset: 0;
}


/* =====================================================
   2. MODAL DE EMERGÊNCIA
   ===================================================== */
#sos-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: calc(var(--z-modal) + 2);
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    padding: 20px;
}

#sos-modal.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.sos-modal-content {
    width: 100%;
    max-width: 380px;
    background: linear-gradient(180deg, #2a0a0a 0%, #1a1a2e 100%);
    border-radius: 20px;
    border: 2px solid rgba(255, 23, 68, 0.3);
    overflow: hidden;
    animation: slideUp 0.3s ease-out;
}

/* Header do Modal */
.sos-modal-header {
    padding: 25px 20px;
    background: linear-gradient(145deg, #ff1744, #d50000);
    text-align: center;
}

.sos-modal-icon {
    font-size: 48px;
    margin-bottom: 10px;
}

.sos-modal-title {
    font-size: 24px;
    font-weight: 700;
    color: #ffffff;
    margin-bottom: 5px;
}

.sos-modal-subtitle {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.8);
}

/* Body do Modal */
.sos-modal-body {
    padding: 20px;
}

/* Localização */
.sos-location {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    margin-bottom: 20px;
}

.sos-location-icon {
    font-size: 24px;
    color: #4CAF50;
}

.sos-location-info {
    flex: 1;
}

.sos-location-label {
    font-size: 12px;
    color: var(--text-secondary, #b0b0b0);
    margin-bottom: 2px;
}

.sos-location-coords {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary, #ffffff);
    font-family: 'Monaco', 'Consolas', monospace;
}

.sos-location-accuracy {
    font-size: 11px;
    color: var(--text-secondary, #b0b0b0);
    margin-top: 2px;
}


/* =====================================================
   3. CONTATOS DE EMERGÊNCIA
   ===================================================== */
.sos-contacts {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sos-contact-btn {
    display: flex;
    align-items: center;
    gap: 15px;
    width: 100%;
    padding: 16px 18px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    text-decoration: none;
    transition: background 0.2s ease, transform 0.2s ease;
}

.sos-contact-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateX(5px);
}

.sos-contact-btn:active {
    transform: scale(0.98);
}

.sos-contact-icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    flex-shrink: 0;
}

/* Cores por serviço */
.sos-contact-btn.policia .sos-contact-icon {
    background: linear-gradient(145deg, #1976D2, #0D47A1);
}

.sos-contact-btn.bombeiros .sos-contact-icon {
    background: linear-gradient(145deg, #F44336, #B71C1C);
}

.sos-contact-btn.samu .sos-contact-icon {
    background: linear-gradient(145deg, #FF9800, #E65100);
}

.sos-contact-btn.prf .sos-contact-icon {
    background: linear-gradient(145deg, #388E3C, #1B5E20);
}

.sos-contact-info {
    flex: 1;
    text-align: left;
}

.sos-contact-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary, #ffffff);
    margin-bottom: 2px;
}

.sos-contact-number {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent-color, #00d4ff);
}

.sos-contact-arrow {
    font-size: 20px;
    color: var(--text-secondary, #b0b0b0);
}


/* =====================================================
   4. RASTREAMENTO / COMPARTILHAMENTO
   ===================================================== */
.sos-share-section {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sos-share-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary, #b0b0b0);
    margin-bottom: 12px;
    text-align: center;
}

.sos-share-buttons {
    display: flex;
    gap: 10px;
}

.sos-share-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    color: var(--text-primary, #ffffff);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sos-share-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.sos-share-btn .icon {
    font-size: 20px;
}

/* WhatsApp */
.sos-share-btn.whatsapp {
    background: rgba(37, 211, 102, 0.2);
    border-color: rgba(37, 211, 102, 0.3);
    color: #25D366;
}

.sos-share-btn.whatsapp:hover {
    background: rgba(37, 211, 102, 0.3);
}

/* Copiar Link */
.sos-share-btn.copy {
    background: rgba(0, 212, 255, 0.1);
    border-color: rgba(0, 212, 255, 0.2);
}

.sos-share-btn.copy:hover {
    background: rgba(0, 212, 255, 0.2);
}

.sos-share-btn.copy.copied {
    background: rgba(76, 175, 80, 0.2);
    border-color: rgba(76, 175, 80, 0.3);
    color: #4CAF50;
}

/* Link de rastreamento */
.sos-tracking-link {
    margin-top: 15px;
    padding: 12px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 12px;
    color: var(--accent-color, #00d4ff);
    word-break: break-all;
    text-align: center;
}

/* Footer do Modal */
.sos-modal-footer {
    padding: 15px 20px 20px;
}

.sos-close-btn {
    width: 100%;
    padding: 16px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    color: var(--text-primary, #ffffff);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

.sos-close-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}


/* =====================================================
   5. ANIMAÇÕES
   ===================================================== */
@keyframes sosPulse {
    0%, 100% {
        box-shadow: 
            0 4px 15px rgba(213, 0, 0, 0.4),
            0 0 0 0 rgba(255, 23, 68, 0.4);
    }
    50% {
        box-shadow: 
            0 4px 15px rgba(213, 0, 0, 0.4),
            0 0 0 15px rgba(255, 23, 68, 0);
    }
}

@keyframes sosHolding {
    0% {
        transform: scale(1);
        background: linear-gradient(145deg, #ff1744, #d50000);
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        background: linear-gradient(145deg, #ffffff, #ff1744);
    }
}

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

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

@keyframes emergency-flash {
    0%, 50%, 100% {
        opacity: 1;
    }
    25%, 75% {
        opacity: 0.5;
    }
}

/* Flash de emergência quando modal abre */
#sos-modal.active .sos-modal-header {
    animation: emergency-flash 1s ease-in-out 2;
}


/* =====================================================
   6. RESPONSIVO
   ===================================================== */
@media (max-width: 480px) {
    #sos-button {
        width: 55px;
        height: 55px;
        bottom: 85px;
        right: 10px;
    }
    
    .sos-text {
        font-size: 14px;
    }
    
    .sos-progress-ring {
        width: 63px;
        height: 63px;
    }
    
    .sos-modal-content {
        max-width: 100%;
        border-radius: 15px;
    }
    
    .sos-modal-header {
        padding: 20px 15px;
    }
    
    .sos-modal-icon {
        font-size: 40px;
    }
    
    .sos-modal-title {
        font-size: 20px;
    }
    
    .sos-modal-body {
        padding: 15px;
    }
    
    .sos-contact-btn {
        padding: 14px 15px;
    }
    
    .sos-contact-icon {
        width: 42px;
        height: 42px;
        font-size: 20px;
    }
    
    .sos-contact-name {
        font-size: 14px;
    }
    
    .sos-contact-number {
        font-size: 18px;
    }
}

@media (max-width: 360px) {
    #sos-button {
        width: 50px;
        height: 50px;
    }
    
    .sos-text {
        font-size: 12px;
    }
    
    .sos-share-buttons {
        flex-direction: column;
    }
    
    .sos-share-btn {
        width: 100%;
    }
}

/* Landscape */
@media (max-height: 500px) and (orientation: landscape) {
    #sos-button {
        bottom: auto;
        top: 60px;
        right: 10px;
        width: 50px;
        height: 50px;
    }
    
    .sos-modal-content {
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .sos-modal-header {
        padding: 15px;
    }
    
    .sos-modal-icon {
        font-size: 32px;
        margin-bottom: 5px;
    }
    
    .sos-modal-title {
        font-size: 18px;
    }
    
    .sos-contacts {
        flex-direction: row;
        flex-wrap: wrap;
    }
    
    .sos-contact-btn {
        flex: 1 1 45%;
        min-width: 150px;
    }
}

/* Safe area para iPhones com notch */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #sos-button {
        bottom: calc(90px + env(safe-area-inset-bottom));
    }
    
    @media (max-width: 480px) {
        #sos-button {
            bottom: calc(85px + env(safe-area-inset-bottom));
        }
    }
}