/* =============================================
   Portal do Cliente - Overrides Pontuais
   Apenas regras que NÃO existem no admin.css
   e são específicas do contexto "portal cliente".
   ============================================= */

/* Safe areas iOS PWA */
.ios-safe-top {
    height: env(safe-area-inset-top, 0px);
    background: var(--bg-body);
}

body.portal {
    background-color: var(--bg-body);
}

/* Mobile bottom tab bar (iOS-style) - somente mobile */
.ios-tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1080;
    display: flex;
    justify-content: space-around;
    align-items: stretch;
    background: var(--bg-header);
    border-top: 1px solid var(--border-color);
    padding: 6px 0 calc(env(safe-area-inset-bottom, 0px) + 6px);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.05);
}

.ios-tab-item {
    flex: 1;
    background: transparent;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    padding: 6px 4px;
    transition: color 0.2s ease;
}

.ios-tab-item.active,
.ios-tab-item:hover {
    color: var(--bs-primary);
}

.ios-tab-icon {
    position: relative;
    font-size: 1.25rem;
    line-height: 1;
}

.ios-tab-badge {
    position: absolute;
    top: -6px;
    right: -10px;
    background: var(--bs-danger, #ef4444);
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    border-radius: 999px;
    min-width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* Mobile: esconder tab bar quando chat offcanvas aberto para evitar sobreposição */
body.chat-open .ios-tab-bar { display: none; }

/* No mobile, o main-content precisa de padding-bottom para o tab bar */
@media (max-width: 991.98px) {
    body.portal .main-content {
        padding-bottom: 70px;
    }
}

/* ===== Chat UI (utilizada em content/chat.php e offcanvas) ===== */

.ios-msg-row {
    display: flex;
    margin-bottom: 8px;
}

.ios-msg-row.sent {
    justify-content: flex-end;
}

.ios-msg-row.received {
    justify-content: flex-start;
}

.ios-msg-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 16px;
    background: var(--bg-light, #f3f4f6);
    color: var(--text-main);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    line-height: 1.4;
}

[data-theme="dark"] .ios-msg-bubble {
    background: #1F2937;
}

.ios-msg-row.sent .ios-msg-bubble {
    background: var(--bs-primary);
    color: #fff;
}

.ios-msg-row.sent .ios-msg-time {
    color: rgba(255, 255, 255, 0.75);
}

.ios-msg-time {
    font-size: 0.7rem;
    margin-top: 4px;
    opacity: 0.7;
}

/* Floating chat button (mobile) */
.ios-fab-chat {
    position: fixed;
    bottom: calc(70px + env(safe-area-inset-bottom, 0px) + 16px);
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    z-index: 1040;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}

/* Photo grid (em content/dashboard.php) */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.75rem;
}

.photo-grid .photo-item {
    aspect-ratio: 1;
    border-radius: 0.5rem;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.photo-grid .photo-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s;
}

.photo-grid .photo-item:hover img {
    transform: scale(1.05);
}

.photo-grid .photo-item .photo-category {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.6);
    color: #fff;
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    text-align: center;
}

@media (max-width: 768px) {
    .photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 0.5rem;
    }
}

/* Status badges - cores alinhadas com admin */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    border-radius: 100px;
    font-weight: 600;
    font-size: 0.75rem;
    line-height: 1;
}

.status-badge .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: currentColor;
}

.status-aguardando { background: #fef3c7; color: #92400e; }
.status-em_servico { background: #dbeafe; color: #1e40af; }
.status-em_analise { background: #dbeafe; color: #1e40af; }
.status-aguardando_aprovacao { background: #fce7f3; color: #9d174d; }
.status-em_reparo { background: #e0e7ff; color: #3730a3; }
.status-testes_finais { background: #d1fae5; color: #065f46; }
.status-finalizado { background: #d1fae5; color: #065f46; }
.status-entregue { background: #e0e7ff; color: #3730a3; }
.status-cancelado { background: #fee2e2; color: #991b1b; }
.status-orcamento_rejeitado { background: #fee2e2; color: #991b1b; }
.status-ativo { background: #d1fae5; color: #065f46; }
.status-suspenso { background: #fef3c7; color: #92400e; }
.status-aprovado { background: #d1fae5; color: #065f46; }
.status-aberto { background: #f3f4f6; color: #6b7280; }
.status-convertido { background: #dbeafe; color: #1e40af; }
.status-pendente { background: #fef3c7; color: #92400e; }
.status-pago { background: #d1fae5; color: #065f46; }
.status-recebido { background: #d1fae5; color: #065f46; }
.status-parcial { background: #dbeafe; color: #1e40af; }
.status-emitido { background: #dbeafe; color: #1e40af; }

[data-theme="dark"] .status-aguardando { background: #78350f; color: #fde68a; }
[data-theme="dark"] .status-em_servico { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .status-em_analise { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .status-aguardando_aprovacao { background: #5b1d3a; color: #f9a8d4; }
[data-theme="dark"] .status-em_reparo { background: #2d2a6e; color: #a5b4fc; }
[data-theme="dark"] .status-testes_finais { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .status-finalizado { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .status-entregue { background: #2d2a6e; color: #a5b4fc; }
[data-theme="dark"] .status-cancelado { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .status-orcamento_rejeitado { background: #7f1d1d; color: #fca5a5; }
[data-theme="dark"] .status-ativo { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .status-suspenso { background: #78350f; color: #fde68a; }
[data-theme="dark"] .status-aprovado { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .status-aberto { background: #374151; color: #d1d5db; }
[data-theme="dark"] .status-convertido { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .status-pendente { background: #78350f; color: #fde68a; }
[data-theme="dark"] .status-pago { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .status-recebido { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .status-parcial { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .status-emitido { background: #1e3a5f; color: #93c5fd; }

/* Timeline */
.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before {
    content: '';
    position: absolute;
    left: 0.4rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color, #e5e7eb);
}
.timeline-item { position: relative; padding-bottom: 1.25rem; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item .timeline-dot {
    position: absolute;
    left: -1.35rem;
    top: 0.25rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--bs-primary);
    border: 2px solid var(--bg-card, #fff);
    z-index: 1;
}
.timeline-item .timeline-time { font-size: 0.75rem; color: var(--text-muted); }

/* Mobile fine-tuning para header admin no portal */
@media (max-width: 991.98px) {
    body.portal .admin-header {
        padding: 0 1rem;
    }
}

/* Garante que o footer não sobreponha o conteúdo no desktop */
body.portal .content-area {
    padding-bottom: 60px;
}

/* ===== Loader de transição do SPA (portal do cliente) =====
   O portal-cliente-spa.js chama showLoading() que alterna #spa-loading.active.
   Sem este elemento/CSS o loader nunca aparecia. Overlay full-screen. */
#spa-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.72);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

#spa-loading.active {
    opacity: 1;
    pointer-events: all;
}

.spa-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid rgba(13, 110, 253, 0.2);
    border-top: 4px solid var(--bs-primary, #0d6efd);
    border-radius: 50%;
    animation: spaSpin 1s linear infinite;
    box-shadow: 0 0 20px rgba(13, 110, 253, 0.2);
}

@keyframes spaSpin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

[data-theme="dark"] #spa-loading {
    background: rgba(11, 17, 32, 0.82);
}
[data-theme="dark"] .spa-spinner {
    border-color: rgba(96, 165, 250, 0.25);
    border-top-color: #60a5fa;
}
