/* ==========================================================================
   ClickAgenda PWA & Mobile UX Avançado
   Design nativo de aplicativo, ergonomia de toque e fluidez mobile completa
   ========================================================================== */

.ca-mobile-nav[hidden], .ca-install-banner[hidden] { display: none !important; }
.ca-mobile-nav { display: none; }

.ca-install-banner {
    position: fixed;
    right: 16px;
    bottom: 20px;
    z-index: 800;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: min(440px, calc(100vw - 32px));
    padding: 13px 15px;
    border-radius: 18px;
    background: #231d35;
    color: #fff;
    box-shadow: 0 12px 35px rgba(26, 20, 56, 0.35);
}
.ca-install-banner > div { display: flex; flex: 1; flex-direction: column; min-width: 0; }
.ca-install-banner strong { font-size: 14px; }
.ca-install-banner span { font-size: 12px; color: #d3cae0; }
.ca-install-button { background: #9864d9; color: white; border: 0; padding: 10px 14px; border-radius: 12px; font-weight: 700; cursor: pointer; }
.ca-install-dismiss { background: transparent; color: white; border: 0; font-size: 26px; padding: 5px; cursor: pointer; }

@media (max-width: 768px) {
    html { -webkit-text-size-adjust: 100%; }
    body {
        min-width: 0;
        overflow-x: hidden;
        -webkit-tap-highlight-color: transparent;
    }

    /* 1. Layout Base do Dashboard no Celular */
    .dashboard {
        padding: 0.8rem 0 calc(78px + env(safe-area-inset-bottom)) !important;
    }
    .dashboard > .container {
        padding: 0 12px !important;
        max-width: 100% !important;
    }
    .dashboard-container {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.75rem !important;
        max-width: 100% !important;
    }

    /* Oculta título redundante no celular para dar foco no conteúdo */
    .dashboard > .container > .section-title {
        display: none !important;
    }

    /* Esconde a barra lateral desktop quando o menu inferior PWA estiver na tela */
    .sidebar,
    #dashboard-barbeiro .sidebar,
    body.ca-pwa-dashboard-open .sidebar {
        display: none !important;
    }

    body.ca-pwa-dashboard-open {
        padding-bottom: calc(78px + env(safe-area-inset-bottom)) !important;
    }

    .main-content {
        width: 100% !important;
        min-width: 0 !important;
        padding: 0 !important;
    }

    /* 2. Topo / Navbar & Dropdowns no Celular */
    .navbar {
        padding: 0.6rem 0 !important;
    }
    .navbar .container {
        padding: 0 12px !important;
    }
    .nav-content {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
    }
    .navbar .logo {
        display: flex !important;
        align-items: center !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
    }
    .navbar .logo span {
        font-size: 1.15rem !important;
    }
    /* Ocultar badge de trial na navbar mobile: não sobrepor o perfil e não poluir as abas */
    #ca-trial-countdown-badge,
    #user-nav .ca-trial-countdown-badge {
        display: none !important;
    }
    #user-nav {
        display: flex !important;
        align-items: center !important;
        gap: 12px !important;
        margin-left: auto !important;
        flex-shrink: 0 !important;
    }
    .navbar .user-avatar {
        width: 38px !important;
        height: 38px !important;
        min-width: 38px !important;
        min-height: 38px !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        overflow: hidden !important;
        cursor: pointer !important;
    }
    .notification-wrapper {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
    .section-title {
        font-size: 1.45rem !important;
        line-height: 1.25 !important;
        margin-bottom: 0.75rem !important;
    }
    .section-subtitle {
        font-size: 0.88rem !important;
    }
    .notification-dropdown {
        position: fixed !important;
        top: 62px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: none !important;
        transform: none !important;
        max-height: 80vh !important;
        border-radius: 18px !important;
        box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28) !important;
        z-index: 99999 !important;
    }
    .profile-dropdown {
        position: fixed !important;
        top: 62px !important;
        left: 10px !important;
        right: 10px !important;
        width: auto !important;
        max-width: none !important;
        transform: none !important;
        border-radius: 18px !important;
        box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28) !important;
        z-index: 99999 !important;
    }

    /* Ajuste de Botões de Ação de Serviços */
    .ca-services-header > div {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        width: 100% !important;
    }
    .ca-services-header > div button:last-child {
        grid-column: span 2 !important;
    }

    /* 3. Barra Inferior Mobile (Estilo App Nativo) */
    .ca-mobile-nav:not([hidden]) {
        position: fixed !important;
        display: flex !important;
        left: 0;
        right: 0;
        bottom: 0;
        padding: 6px 4px calc(6px + env(safe-area-inset-bottom)) !important;
        gap: 2px;
        background: rgba(255, 255, 255, 0.98) !important;
        border-top: 1px solid #ebe5f5 !important;
        box-shadow: 0 -4px 20px rgba(34, 27, 53, 0.08) !important;
        backdrop-filter: blur(20px) !important;
        -webkit-backdrop-filter: blur(20px) !important;
        z-index: 9999 !important;
        justify-content: space-around;
    }

    .ca-mobile-item {
        min-width: 0;
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        border: 0;
        border-radius: 10px;
        padding: 6px 0;
        background: transparent;
        color: #7b718e;
        font: 700 9.5px/1.1 system-ui, -apple-system, sans-serif;
        cursor: pointer;
        touch-action: manipulation;
        transition: transform 0.1s ease, color 0.15s ease;
    }
    .ca-mobile-item:active {
        transform: scale(0.92);
    }
    .ca-mobile-item i {
        font-size: 17px;
    }
    .ca-mobile-item.active {
        background: #f3ecfb !important;
        color: #7244af !important;
    }

    /* Banner de Instalação */
    .ca-install-banner {
        bottom: calc(76px + env(safe-area-inset-bottom));
        left: 10px;
        right: 86px; /* Deixa espaço livre para o botão flutuante (+) de agendamento */
        max-width: none;
    }
    body:not(.ca-pwa-dashboard-open) .ca-install-banner {
        bottom: calc(18px + env(safe-area-inset-bottom));
        right: 86px;
    }

    /* 4. Estatísticas e Cards na Visão Geral */
    .stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px !important;
    }
    .stat-card {
        padding: 12px 14px !important;
        min-height: 110px !important;
        border-radius: 16px !important;
    }
    .stat-number {
        font-size: 1.45rem !important;
    }
    .stat-label {
        font-size: 0.72rem !important;
    }
    .ca-stat-icon {
        width: 32px !important;
        height: 32px !important;
        font-size: 13px !important;
        top: 10px !important;
        right: 10px !important;
    }
    .ca-overview-heading h3 {
        font-size: 1.25rem !important;
    }
    .ca-quick-action {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        width: 100% !important;
        min-height: 48px !important;
        border-radius: 14px !important;
        font-size: 0.98rem !important;
        font-weight: 700 !important;
        margin-top: 10px !important;
        padding: 12px 16px !important;
        text-align: center !important;
    }

    /* Centralização universal de botões e ícones no celular */
    .btn,
    .btn-primary,
    .btn-secondary,
    .modal form button[type="submit"],
    .ca-modal-footer .btn {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        text-align: center !important;
        vertical-align: middle !important;
    }
    .btn i,
    .btn-primary i,
    .btn-secondary i {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        margin: 0 !important;
        line-height: 1 !important;
    }

    /* Notificações Toast no Mobile (Sempre sobre qualquer modal) */
    #toast-container {
        top: calc(16px + env(safe-area-inset-top)) !important;
        left: 14px !important;
        right: 14px !important;
        max-width: calc(100% - 28px) !important;
        z-index: 200000 !important;
        pointer-events: none;
    }
    .toast {
        min-width: 0 !important;
        width: 100% !important;
        pointer-events: auto;
    }

    /* 5. Modais Estilo Bottom Sheet no Celular */
    .modal {
        align-items: flex-end !important;
        padding: 0 !important;
        z-index: 100000; /* Permite z-index dinamico via JS sem conflito de !important */
        background: rgba(15, 23, 42, 0.65) !important;
        backdrop-filter: blur(4px) !important;
        -webkit-backdrop-filter: blur(4px) !important;
    }
    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 24px 24px 0 0 !important;
        max-height: 90dvh !important;
        padding: 1.25rem 1.15rem calc(28px + env(safe-area-inset-bottom)) !important;
        margin: 0 !important;
        box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.28) !important;
        animation: caSheetUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        z-index: 100001;
    }
    .modal-content::before {
        content: '';
        display: block;
        width: 38px;
        height: 4px;
        background: #cbd5e1;
        border-radius: 99px;
        margin: -6px auto 14px auto;
    }
    /* Esconde barra inferior e banners quando houver modal aberto na tela */
    body.modal-open .ca-mobile-nav,
    body.has-modal-open .ca-mobile-nav,
    body:has(.modal.active) .ca-mobile-nav,
    body:has(.modal[style*="display: flex"]) .ca-mobile-nav,
    body:has(.modal.active) .ca-install-banner {
        display: none !important;
    }
    @keyframes caSheetUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }
    .modal-header {
        margin-bottom: 1rem !important;
        padding-bottom: 0.8rem !important;
        border-bottom: 1px solid #f0e9f7 !important;
    }
    .modal-header h2 {
        font-size: 1.2rem !important;
    }
    .close-modal {
        width: 36px !important;
        height: 36px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 50% !important;
        background: #f4ecfb !important;
        color: #7244af !important;
        font-size: 1.2rem !important;
    }

    .modal form button[type="submit"],
    .modal .modal-body button[type="submit"] {
        width: 100% !important;
        justify-content: center !important;
        min-height: 48px !important;
        font-size: 0.95rem !important;
        border-radius: 12px !important;
        margin-top: 8px !important;
    }

        /* 5.1 Aproveitamento de Espaço na Visão Geral */
    .appointment-item {
        padding: 0.85rem 0.9rem !important;
        margin-bottom: 0.6rem !important;
        gap: 0.75rem !important;
        border-radius: 14px !important;
    }
    .appointment-info {
        gap: 0.75rem !important;
        flex: 1 !important;
        min-width: 0 !important;
    }
    .appointment-time {
        font-size: 1.15rem !important;
        min-width: 52px !important;
    }
    .appointment-details {
        min-width: 0 !important;
        flex: 1 !important;
    }
    .appointment-details h4 {
        font-size: 0.95rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        margin-bottom: 2px !important;
    }
    .appointment-details p {
        font-size: 0.8rem !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

/* 6. Inputs e Formulários no Mobile */
    .main-content input:not([type="checkbox"]):not([type="radio"]),
    .main-content select,
    .main-content textarea,
    .modal input:not([type="checkbox"]):not([type="radio"]),
    .modal select,
    .modal textarea {
        min-height: 48px !important;
        font-size: 16px !important; /* Evita auto-zoom do Safari iOS */
        border-radius: 12px !important;
    }
    .form-group {
        margin-bottom: 1rem !important;
    }

    /* 7. Lista de Serviços no Mobile */
    #lista-de-servicos {
        display: flex !important;
        flex-direction: column !important;
        gap: 8px !important;
    }
    #lista-de-servicos .service-card.ca-service-item {
        padding: 12px 14px !important;
        min-height: auto !important;
        border-radius: 14px !important;
    }

    /* 8. Seção de Configurações e Abas */
    .settings-nav {
        display: flex !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        padding-bottom: 6px !important;
        gap: 6px !important;
    }
    .settings-nav::-webkit-scrollbar {
        display: none !important;
    }
    .settings-nav-btn {
        white-space: nowrap !important;
        padding: 8px 14px !important;
        font-size: 0.82rem !important;
        flex: none !important;
    }
    .settings-card {
        padding: 14px !important;
        border-radius: 16px !important;
    }

    /* 9. Grade de Horários de Funcionamento em Cards no Celular */
    .schedule-grid {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
    }
    .schedule-header {
        display: none !important;
    }
    .schedule-row {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
        background: #fbf9fd !important;
        border: 1px solid #f0e9f7 !important;
        border-radius: 14px !important;
        padding: 12px !important;
        box-sizing: border-box !important;
    }
    .day-label {
        grid-column: span 2 !important;
        font-weight: 800 !important;
        font-size: 0.95rem !important;
        color: #2e263d !important;
        margin: 0 !important;
        border: none !important;
        padding: 0 !important;
    }
    .day-status {
        grid-column: span 2 !important;
        margin-bottom: 2px !important;
    }

    /* 10. Botões e Ações */
    .main-content button, .main-content a {
        touch-action: manipulation;
    }
}

@media (max-width: 380px) {
    .ca-mobile-item {
        font-size: 8.5px;
    }
    .ca-mobile-item i {
        font-size: 15px;
    }
    .stats-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Modais Responsivos no Mobile */
.ca-modal-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
@media (max-width: 580px) {
    .ca-modal-grid-2 {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }
}


/* Card de Status do Período de Teste na Visão Geral */
.ca-trial-overview-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 18px;
    margin-bottom: 1.25rem;
    border-radius: 16px;
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    border: 1px solid #fde68a;
    box-shadow: 0 4px 14px rgba(245, 158, 11, 0.08);
}
.ca-trial-card-body {
    display: flex;
    align-items: center;
    gap: 12px;
}
.ca-trial-card-icon {
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 12px;
    background: #f59e0b;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    box-shadow: 0 3px 10px rgba(245, 158, 11, 0.3);
}
.ca-trial-card-text strong {
    display: block;
    font-size: 0.95rem;
    color: #92400e;
    margin-bottom: 2px;
}
.ca-trial-card-text p {
    margin: 0;
    font-size: 0.84rem;
    color: #78350f;
    line-height: 1.35;
}
.ca-trial-card-actions .ca-trial-btn-assinar {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    padding: 9px 18px !important;
    font-size: 0.86rem !important;
    font-weight: 700 !important;
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%) !important;
    color: #ffffff !important;
    border: none !important;
    border-radius: 10px !important;
    white-space: nowrap !important;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(180, 83, 9, 0.25) !important;
    transition: transform 0.2s, box-shadow 0.2s;
}
@media (max-width: 768px) {
    .ca-trial-overview-card {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
        padding: 14px;
        margin-top: 10px;
        margin-bottom: 1rem;
    }
    .ca-trial-card-actions .ca-trial-btn-assinar {
        width: 100% !important;
        padding: 11px 16px !important;
    }
}
