/* Estilo geral da página */
body {
    background-color: #0d1117; /* Um preto mais suave, inspirado no GitHub Dark */
    color: #c9d1d9;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* SPA wrapper — view-historico */
#view-historico {
    padding: 1.25rem 1rem calc(var(--app-footer-height, 70px) + 1.5rem);
    max-width: 520px;
    margin: 0 auto;
    box-sizing: border-box;
}

.historico-header-page {
    padding: 0 0.25rem;
    margin-bottom: 0.85rem;
}

.historico-header-page h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: #fff;
    margin: 0;
}

.tabs-container {
    display: flex;
    background-color: rgba(22, 27, 34, 0.7);
    border: 1px solid rgba(48, 54, 61, 0.8);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 1.25rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.tabs-container .tab-button {
    flex: 1;
    padding: 0.65rem;
    border: none;
    background: transparent;
    color: #8b949e;
    font-size: 0.92rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tabs-container .tab-button.active {
    background: #19b6a4;
    color: #ffffff;
    box-shadow: 0 0 15px rgba(25, 182, 164, 0.4);
}

.container {
    padding: 0 1rem 120px 1rem;
    max-width: 520px;
    margin: 0 auto;
}

.page-title {
    font-size: 1.8rem;
    font-weight: 700;
    color: #fff;
    text-align: center;
    margin-bottom: 2rem;
}

/* Abas de navegação */
.tabs {
    display: flex;
    background-color: rgba(22, 27, 34, 0.7);
    border: 1px solid rgba(48, 54, 61, 0.8);
    border-radius: 10px;
    padding: 5px;
    margin-bottom: 2rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.tab-button { /* Alterado de .tab-link para .tab-button para corresponder ao HTML */
    flex: 1;
    padding: 0.8rem;
    border: none;
    background: transparent;
    color: #8b949e;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab-button.active {
    background: #19b6a4;
    color: #ffffff;
    box-shadow: 0 0 15px rgba(25, 182, 164, 0.4);
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Mensagem de "Sem Agendamentos" */
.no-agendamentos {
    text-align: center;
    padding: 3rem 1rem;
    background: rgba(22, 27, 34, 0.5);
    border-radius: 15px;
    border: 1px solid #30363d;
}
.no-agendamentos p {
    font-size: 1rem;
    color: #8b949e;
    margin-bottom: 1.5rem;
}
.btn-agendar-agora {
    display: inline-block;
    padding: 0.8rem 1.5rem;
    background: linear-gradient(45deg, #19b6a4, #118b7c);
    color: #fff;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn-agendar-agora:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(25, 182, 164, 0.3);
}


/* --- NOVO DESIGN DO CARD "PASSE VIP" --- */

.agendamento-card-collapsible {
    display: flex;
    margin-bottom: 1rem;
    border-radius: 20px;
    background: rgba(22, 27, 34, 0.6); /* Fundo de vidro */
    border: 1px solid #30363d;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.16);
    transition: all 0.4s ease;
    overflow: hidden; /* Garante que os filhos respeitem o border-radius */
}

.agendamento-card-collapsible:hover {
    border-color: #8b949e;
    transform: translateY(-3px);
}

/* Parte Esquerda do "Ingresso" (Data) */
.card-stub {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0.85rem 0.7rem;
    background: rgba(0, 0, 0, 0.2);
    min-width: 78px;
    text-align: center;
    border-right: 2px dashed #30363d;
    position: relative;
}

.card-stub .dia-mes {
    font-size: 2rem;
    font-weight: 700;
    color: #fff;
    line-height: 1;
}

.card-stub .mes {
    font-size: 0.82rem;
    font-weight: 500;
    color: #8b949e;
    text-transform: uppercase;
}

.card-stub .dia-semana {
    margin-top: 0.45rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: #19b6a4;
    text-transform: uppercase;
}

/* Conteúdo Principal do Card */
.card-main {
    flex-grow: 1;
    display: grid; /* Usando grid para a animação */
    grid-template-rows: auto 0fr;
    transition: grid-template-rows 0.4s ease-in-out;
    min-width: 0;
}

.agendamento-card-collapsible.open .card-main {
    grid-template-rows: auto 1fr;
}

/* Cabeçalho Clicável */
.card-header-collapsible {
    padding: 1rem 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.header-main-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.servicos-summary {
    font-weight: 600;
    font-size: 1.05rem;
    color: #c9d1d9;
}

.horario-summary {
    font-size: 0.9rem;
    color: #8b949e;
    font-weight: 500;
}

.header-right-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chevron-indicator {
    color: #8b949e;
    transition: transform 0.3s ease;
}

.agendamento-card-collapsible.open .chevron-indicator {
    transform: rotate(180deg);
}

/* Corpo Colapsável */
.card-body-collapsible {
    overflow: hidden;
    padding: 0 1.2rem; /* Padding lateral para alinhar com o header */
}

.card-body-content {
    padding-bottom: 1.2rem; /* Padding inferior aplicado aqui para a animação funcionar */
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.card-divider {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, #30363d, transparent);
    margin: 0;
}

.info-section {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.info-item.align-right {
    align-items: flex-end;
}

.info-label {
    font-size: 0.8rem;
    color: #8b949e;
    text-transform: uppercase;
    font-weight: 500;
}

.info-value {
    font-size: 0.95rem;
    font-weight: 600;
    color: #c9d1d9;
}

.barbeiro-info-detailed {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-end;
}

.barbeiro-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #30363d;
}

.service-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
}
.service-name { color: #c9d1d9; }
.service-price { color: #8b949e; }

.total-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-end;
}
.total-item {
    display: flex;
    justify-content: space-between;
    width: 100%;
    max-width: 250px; /* Limita a largura para melhor alinhamento */
}
.total-label { font-size: 0.9rem; color: #8b949e; }
.total-value { font-size: 1.2rem; font-weight: 700; color: #fff; }
.original-price { text-decoration: line-through; color: #8b949e; font-size: 0.8rem; }
.discount-price { color: #2da042; font-size: 0.9rem; }


/* Botões de Ação */
.card-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.action-button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.7rem;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}
.action-button i { width: 16px; height: 16px; }

/* Botão Principal (Usar Crédito / Pagar) */
.btn-principal {
    grid-column: 1 / -1; /* Ocupa as duas colunas */
    background: linear-gradient(45deg, #19b6a4, #118b7c);
    color: #fff;
}
.btn-principal:hover {
    transform: scale(1.03);
    box-shadow: 0 0 15px rgba(25, 182, 164, 0.4);
}

/* Botões Secundários */
.btn-secondary {
    background-color: #21262d;
    color: #c9d1d9;
    border: 1px solid #30363d;
}
.btn-secondary:hover {
    border-color: #8b949e;
    color: #fff;
}

.btn-desmarcar {
    color: #f85149;
}
.btn-desmarcar:hover {
    background-color: rgba(248, 81, 73, 0.1);
    border-color: #f85149;
}


/* Badges de Status */
.status-badge {
    padding: 0.3rem 0.7rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border: 1px solid;
}

.status-confirmado {
    color: #3fb950;
    border-color: #3fb950;
    background-color: rgba(46, 160, 67, 0.1);
}
.status-concluido {
    color: #8b949e;
    border-color: #8b949e;
    background-color: rgba(139, 148, 158, 0.1);
}
.status-cancelado {
    color: #f85149;
    border-color: #f85149;
    background-color: rgba(248, 81, 73, 0.1);
}

/* --- NOVOS ESTILOS (AJUSTES FINOS) --- */

/* Efeito de "luz acesa" para o status agendado */
.status-agendado {
    color: #3fb950; /* Verde vivo */
    font-weight: 600;
    text-shadow: 0 0 8px rgba(63, 185, 80, 0.7);
}

.horario-texto {
    color: #c9d1d9;
}

/* Estilo de Nota Fiscal para Serviços */
.info-section-nota-fiscal {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: 100%;
}

.nota-fiscal-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: #8b949e;
    text-transform: uppercase;
    font-weight: 500;
    padding: 0 0.5rem;
    border-bottom: 1px dashed #30363d;
    padding-bottom: 0.5rem;
}

.nota-fiscal-body {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0 0.5rem;
}

/* Alinhamento do Total à Esquerda */
.total-section-left {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-start; /* Alinha tudo à esquerda */
    width: 100%;
}

.total-section-left .total-item {
    justify-content: space-between;
    width: 100%;
    max-width: none; /* Remove a largura máxima anterior */
}

/* Cor Dourada para o Valor Total */
.total-value-gold {
    font-size: 1.3rem;
    font-weight: 700;
    color: #FFD700; /* Cor de ouro */
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

/* Botões de Ação (Apenas Ícones) */
.card-actions-icons {
    display: flex;
    justify-content: flex-end; /* Alinha os ícones à direita */
    gap: 0.5rem; /* Espaço entre os ícones */
    margin-top: 0.5rem;
}

.action-button-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.6rem;
    border-radius: 50%; /* Círculo */
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid #30363d;
    background-color: #21262d;
    color: #c9d1d9;
}

.action-button-icon:hover {
    border-color: #8b949e;
    color: #fff;
    transform: translateY(-2px);
}

.action-button-icon i {
    width: 18px;
    height: 18px;
}

.btn-desmarcar {
    color: #f85149;
}

.btn-desmarcar:hover {
    background-color: rgba(248, 81, 73, 0.1);
    border-color: #f85149;
    color: #f85149;
}

/* Remove a seção de status antiga */
.status-badge {
    display: none;
}

.header-right-info .status-badge {
    display: inline-flex;
}

/* --- AJUSTES FINOS 2 --- */

/* Cor do texto do horário */
.horario-summary .horario-texto {
    color: #fff; /* Cor branca para o texto do horário */
}

/* Layout de Ações Misto */
.card-actions-mixed {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-top: 0.5rem;
}

.action-icons-group {
    display: flex;
    gap: 0.5rem;
}

/* Botão PIX Estilizado */
.action-button-pix {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.8rem;
    border-radius: 8px;
    text-decoration: none;
    font-size: 1rem;
    font-weight: 700;
    transition: all 0.2s ease;
    background: linear-gradient(45deg, #19b6a4, #118b7c);
    color: #fff;
    border: 1px solid #19b6a4;
}

.action-button-pix:hover {
    transform: scale(1.03);
    box-shadow: 0 0 15px rgba(25, 182, 164, 0.4);
}

.action-button-pix i {
    width: 18px;
    height: 18px;
}

/* Cor Amarela para o Botão Editar */
.btn-editar {
    color: #FFD700;
    border-color: #FFD700;
}

.btn-editar:hover {
    background-color: rgba(255, 215, 0, 0.1);
    color: #FFD700;
    border-color: #FFD700;
}

/* Cabeçalho com título centralizado */
.card-header-collapsible {
    padding: 0.95rem 1rem;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.8rem;
    align-items: center;
    cursor: pointer;
    position: relative;
}

.header-main-info {
    display: flex;
    flex-direction: column;
    gap: 0.12rem;
    z-index: 2;
    background: none;
    padding-right: 0;
    min-width: 56px;
}

.header-center-info {
    position: static;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 0.28rem;
    z-index: 1;
    min-width: 0;
}

.servicos-summary {
    font-weight: 600;
    font-size: 1rem;
    color: #c9d1d9;
    background: none;
    padding: 0;
    white-space: normal;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.line-left, .line-right {
    display: none;
}

.header-right-info {
    z-index: 2;
    background: none;
    padding-left: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.horario-summary {
    font-size: 0.98rem;
    font-weight: 700;
    color: #fff;
}

.horario-summary .horario-texto {
    color: #fff;
}

.status-badge {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0.28rem 0.56rem;
    border-radius: 999px;
    font-size: 0.64rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

.header-right-info .status-badge {
    display: inline-flex;
}

.chevron-indicator {
    width: 18px;
    height: 18px;
}

.card-body-collapsible {
    overflow: hidden;
    padding: 0 1rem;
}

.card-body-content {
    padding-bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.info-section {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
}

.info-item {
    min-width: 0;
}

.info-value {
    font-size: 0.92rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.nota-fiscal-header,
.nota-fiscal-body {
    padding-left: 0;
    padding-right: 0;
}

.service-item {
    gap: 0.85rem;
}

.service-name,
.service-price {
    line-height: 1.35;
}

.total-value-gold {
    font-size: 1.18rem;
}

.card-actions-mixed {
    margin-top: 0.2rem;
}

.action-icons-group {
    gap: 0.6rem;
}

.action-button-icon {
    width: 40px;
    height: 40px;
}

@media (max-width: 560px) {
    .agendamento-card-collapsible {
        border-radius: 18px;
        margin-bottom: 0.85rem;
    }

    .card-stub {
        min-width: 72px;
        padding: 0.8rem 0.55rem;
    }

    .card-stub .dia-mes {
        font-size: 1.85rem;
    }

    .card-stub .mes {
        font-size: 0.76rem;
    }

    .card-header-collapsible {
        grid-template-columns: 52px minmax(0, 1fr) auto;
        gap: 0.65rem;
        padding: 0.85rem 0.85rem 0.8rem;
    }

    .header-right-info {
        flex-direction: column-reverse;
        align-items: flex-end;
        gap: 0.3rem;
    }

    .servicos-summary {
        font-size: 0.92rem;
    }

    .horario-summary {
        font-size: 0.9rem;
    }

    .status-badge {
        font-size: 0.58rem;
        padding: 0.24rem 0.48rem;
    }

    .card-body-collapsible {
        padding: 0 0.85rem;
    }

    .card-body-content {
        gap: 0.75rem;
        padding-bottom: 0.9rem;
    }

    .info-section {
        grid-template-columns: 1fr;
        gap: 0.55rem;
    }

    .info-item.align-right {
        align-items: flex-start;
    }

    .info-label {
        font-size: 0.74rem;
    }

    .info-value {
        font-size: 0.88rem;
    }

    .service-item {
        font-size: 0.84rem;
    }

    .total-value-gold {
        font-size: 1.06rem;
    }

    .card-actions-mixed {
        justify-content: flex-end;
    }

    .action-icons-group {
        gap: 0.5rem;
    }

    .action-button-icon {
        width: 38px;
        height: 38px;
    }
}

/* Divisor pontilhado */
.card-divider-dotted {
    border: none;
    height: 1px;
    background-image: linear-gradient(to right, #4a4a4a 33%, rgba(255,255,255,0) 0%);
    background-position: bottom;
    background-size: 4px 1px;
    background-repeat: repeat-x;
    margin: 0.5rem 0;
}

/* Seção de Créditos */
.credit-section {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.5rem; /* Padding para alinhar com a nota fiscal */
}

.credit-toggle {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.credit-label {
    font-size: 0.9rem;
    font-weight: 500;
    color: #c9d1d9;
}

.credit-info {
    font-size: 0.9rem;
    color: #8b949e;
}

.credit-value {
    font-weight: 600;
    color: #19b6a4; /* Verde para destacar o saldo */
}

/* Estilo do Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #30363d;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: #19b6a4;
}

input:checked + .slider:before {
    transform: translateX(20px);
}

.slider.round { border-radius: 34px; }
.slider.round:before { border-radius: 50%; }


/* Ajuste nos botões de ação */
.card-actions-mixed {
    justify-content: flex-end; /* Alinha o grupo de ícones à direita */
}

.action-icons-group {
    display: flex;
    gap: 0.75rem; /* Espaço entre os ícones */
    align-items: center;
}

.action-button-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;  /* Largura fixa */
    height: 42px; /* Altura fixa */
    padding: 0; /* Remove padding para o tamanho ser controlado por width/height */
}
/* --- NOVO ESTILO BOTÃO PIX --- */
.action-button-pix {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #28a745; /* Verde PIX */
    color: #fff;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.9rem;
    padding: 0 1.5rem; /* Deixa o botão mais largo */
    height: 42px;
    border: none;
    transition: background-color 0.2s ease;
}

.action-button-pix:hover {
    background-color: #218838; /* Verde mais escuro no hover */
    transform: translateY(-1px);
}

/* --- SCRIPT DE ATUALIZAÇÃO DINÂMICA --- */
<script>
document.addEventListener('DOMContentLoaded', function() {
    function updateDynamicTitles() {
        const cards = document.querySelectorAll('.agendamento-card-collapsible[data-datetime]');
        if (cards.length === 0) return;

        const now = new Date();
        const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); // Meia-noite de hoje

        cards.forEach(card => {
            const agendamentoISO = card.dataset.datetime;
            if (!agendamentoISO) return;

            const agendamentoDate = new Date(agendamentoISO);
            // Ignora agendamentos que já passaram
            if (agendamentoDate < today) return;

            const agendamentoDay = new Date(agendamentoDate.getFullYear(), agendamentoDate.getMonth(), agendamentoDate.getDate());

            const diffTime = agendamentoDay - today;
            const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));

            const titleElement = card.querySelector('.servicos-summary');
            if (!titleElement) return;

            let newTitle = '';
            if (diffDays === 0) newTitle = 'É HOJE';
            else if (diffDays === 1) newTitle = 'É AMANHÃ';
            else if (diffDays > 1) newTitle = `FALTAM ${diffDays} DIAS`;

            if (newTitle && titleElement.textContent.trim() !== newTitle) {
                titleElement.textContent = newTitle;
            }
        });
    }

    updateDynamicTitles(); // Executa ao carregar a página
    setInterval(updateDynamicTitles, 5 * 60 * 1000); // Executa a cada 5 minutos
    document.addEventListener('visibilitychange', () => document.visibilityState === 'visible' && updateDynamicTitles()); // Executa ao voltar para a aba
});
</script>