/**
 * Layout Responsivo para Páginas Internas
 * Header mobile com logo e menu sanduíche
 * Uses design-system-mobile.css variables
 */

/* ==========================================================================
   MOBILE HEADER (<= 768px)
   ========================================================================== */

@media (max-width: 768px) {

    /* Desabilitar pull-to-refresh em todo o app mobile */
    html, body {
        overscroll-behavior-y: none;
        overscroll-behavior: none;
    }

    /* Barra vermelha atrás da status bar — só funciona em PWA (black-translucent) */
    body::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: env(safe-area-inset-top, 0px);
        background: #FF5757;
        z-index: 9999;
        pointer-events: none;
    }

    /* Barra vermelha fixa no topo (acima do header) */
    .mobile-status-bar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--mobile-status-bar, 2.8rem);
        background: #FF5757;
        z-index: 10000;
        pointer-events: none;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    /* Esconder barra vermelha quando sidebar mobile está aberto */
    body.mobile-menu-open .mobile-status-bar {
        opacity: 0;
        visibility: hidden;
    }

    /* Ocultar sidebar no mobile */
    html body .chat-sidebar {
        display: none;
    }

    /* Ocultar ::before dos botões de configuração e perfil no mobile */
    html body .preferences-btn::before,
    html body .switch-profile-btn::before,
    html body .admin-panel-btn::before {
        display: none;
    }

    /* Home sticky bar — hidden via design-system-mobile.css */

    /* Garantir que o home-screen apareça */
    html body.page-with-home .chat-messages .home-screen {
        display: block;
    }

    /* Garantir que quick-shortcuts apareça - 1 coluna no mobile */
    html body.page-with-home .quick-shortcuts {
        display: grid;
        grid-template-columns: 1fr;
        gap: 0.75rem;
        padding: 0;
    }

    /* Botões de atalho em tela cheia no mobile (1 coluna) */
    html body.page-with-home .quick-shortcut-btn {
        width: 100%;
        justify-content: flex-start;
    }

    /* Ajustar o padding do chat-messages — espaço para input fixo no bottom */
    html body.page-with-home .chat-messages {
        padding-left: var(--mobile-gutter);
        padding-right: var(--mobile-gutter);
        padding-top: calc(var(--mobile-header-total) + var(--sticky-bar-height) + env(safe-area-inset-top, 0px));
        padding-bottom: calc(200px + env(safe-area-inset-bottom, 0px));
    }

    /* Header Mobile */
    .mobile-header {
        display: flex;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: var(--z-header);
        background: var(--bg-secondary);
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        border-bottom: 4px solid #d3d3d3;
        padding: calc(env(safe-area-inset-top, 12px) + 2.5rem) var(--mobile-gutter) var(--space-3) var(--mobile-gutter);
        align-items: center;
        justify-content: flex-start;
        min-height: var(--mobile-header-height);
        box-sizing: border-box;
    }

    [data-theme="dark"] .mobile-header {
        background: var(--bg-primary, #1a1a1a);
    }

    /* Logo no header */
    .mobile-header-logo {
        display: flex;
        align-items: center;
        gap: 10px;
        text-decoration: none;
    }

    .mobile-header-logo img {
        height: 20px;
        width: auto;
    }

    .mobile-header-logo span {
        color: #ffffff;
        font-size: var(--text-base);
        font-weight: 700;
        letter-spacing: -0.5px;
    }

    /* Link wrapper da mini logo */
    .mobile-header-logo-mini-link {
        flex: 1;
        display: flex;
        justify-content: center;
    }

    /* Mini logo ao lado do botão menu */
    .mobile-header-logo-mini {
        height: 16px;
        width: auto;
        opacity: 0.45;
        filter: grayscale(100%);
        user-select: none;
    }

    [data-theme="dark"] .mobile-header-logo-mini {
        filter: grayscale(100%) invert(1);
        opacity: 0.35;
    }

    /* Header actions container */
    .mobile-header-actions {
        display: flex;
        align-items: center;
        gap: 10px;
        flex-shrink: 0;
    }

    /* FAB inline dentro do header */
    html body .mobile-header .mobile-header-actions .quick-tabs-fab.quick-tabs-fab--inline {
        position: static !important;
        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
        max-width: 30px !important;
        min-height: 30px !important;
        max-height: 30px !important;
        border-radius: 50% !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: #FF5757 !important;
        color: #fff !important;
        border: none !important;
        cursor: pointer;
        box-shadow: none !important;
        z-index: auto !important;
        bottom: auto !important;
        right: auto !important;
        font-size: 0.875rem;
        transform: none !important;
    }

    .mobile-header-actions .quick-tabs-fab--inline .quick-tabs-fab__label {
        display: none;
    }

    /* Botão Notificação */
    .mobile-header-notification-btn {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--touch-min);
        height: var(--touch-min);
        background: transparent;
        border: none;
        border-radius: var(--radius-lg);
        color: var(--text-primary);
        cursor: pointer;
        transition: all 0.2s ease;
        position: relative;
        flex-shrink: 0;
    }

    .mobile-header-notification-btn:hover,
    .mobile-header-notification-btn:active {
        background: var(--bg-tertiary, rgba(0, 0, 0, 0.06));
        transform: scale(0.95);
    }

    .notification-badge {
        position: absolute;
        top: 6px;
        right: 6px;
        min-width: 16px;
        height: 16px;
        padding: 0 4px;
        background: #ef4444;
        color: #fff;
        font-size: 10px;
        font-weight: 700;
        line-height: 16px;
        text-align: center;
        border-radius: var(--radius-full);
        pointer-events: none;
    }

    /* Notification Dropdown — mesmo visual do .notif-dropdown web */
    .notification-dropdown {
        position: fixed;
        top: calc(var(--mobile-header-total, 60px) - 10px);
        left: 50%;
        right: auto;
        transform: translateX(-50%) translateY(-4px);
        width: calc(100vw - 32px);
        max-width: 378px;
        max-height: calc(100vh - var(--mobile-header-total, 60px) - 40px);
        background: var(--bg-primary, #fff);
        color: var(--text-primary, #1a1a1a);
        border: 1px solid var(--border-color, #e5e7eb);
        border-radius: 12px;
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15), 0 2px 10px rgba(0, 0, 0, 0.08);
        z-index: calc(var(--z-header) + 1);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.2s ease;
        pointer-events: none;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .notification-dropdown.active {
        opacity: 1;
        visibility: visible;
        transform: translateX(-50%) translateY(0);
        pointer-events: auto;
    }

    [data-theme="dark"] .notification-dropdown {
        background: #1a1a1a;
        border-color: #333;
    }

    .notification-dropdown-header {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.75rem 1rem;
        border-bottom: 1px solid var(--border-color, #e5e7eb);
        flex-shrink: 0;
    }

    [data-theme="dark"] .notification-dropdown-header {
        border-color: #333;
    }

    .notification-dropdown-title {
        margin: 0;
        font-size: 0.9375rem;
        font-weight: 700;
        color: var(--text-primary);
        flex: 1;
    }

    .notification-dropdown-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 28px;
        height: 28px;
        background: transparent;
        border: none;
        border-radius: 6px;
        color: var(--text-secondary, #6b7280);
        cursor: pointer;
        transition: background 0.15s ease;
        padding: 0;
    }

    .notification-dropdown-close:hover {
        background: rgba(0, 0, 0, 0.06);
    }

    .notification-dropdown-body {
        padding: 0.75rem;
        max-height: 320px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Estado vazio */
    .notification-empty {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 2rem 1rem;
        color: var(--text-secondary, #9ca3af);
        gap: 0.75rem;
    }

    .notification-empty p {
        margin: 0;
        font-size: 0.875rem;
    }

    /* Items de notificação — estilo card igual web */
    .notification-item {
        display: flex;
        gap: 0.75rem;
        padding: 1rem;
        border-radius: 12px;
        background: var(--bg-secondary, #f9fafb);
        border: 1px solid var(--border-color, #e5e7eb);
        margin-bottom: 0.5rem;
        transition: background 0.15s ease;
    }

    .notification-item:last-child {
        margin-bottom: 0;
    }

    .notification-item-icon {
        flex-shrink: 0;
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: 10px;
        background: rgba(255, 87, 87, 0.1);
        color: #FF5757;
    }

    [data-theme="dark"] .notification-item-icon {
        background: rgba(255, 87, 87, 0.15);
    }

    .notification-item-content {
        flex: 1;
        min-width: 0;
    }

    .notification-item-title {
        font-size: var(--text-sm);
        font-weight: 600;
        color: var(--text-primary);
        margin: 0 0 2px;
        line-height: 1.3;
    }

    .notification-item-desc {
        font-size: var(--text-xs);
        color: var(--text-secondary, #6b7280);
        margin: 0;
        line-height: 1.4;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    .notification-item-time {
        font-size: 10px;
        color: var(--text-secondary, #9ca3af);
        margin-top: 4px;
    }

    .notification-item-content strong {
        font-size: 0.9375rem;
        font-weight: 600;
        color: var(--text-primary);
        display: block;
        margin-bottom: 0.5rem;
    }

    .notification-item-content p {
        font-size: 0.875rem;
        color: var(--text-secondary, #6b7280);
        margin: 0 0 0.75rem;
        line-height: 1.5;
    }

    .notification-item-action {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 0.5rem 1.5rem;
        border-radius: 50px;
        font-size: 0.8125rem;
        font-weight: 600;
        text-decoration: none;
        border: none;
        background: linear-gradient(135deg, #FF5757 0%, #E04848 100%);
        color: white;
        transition: filter 0.2s;
    }

    .notification-item-action:hover {
        filter: brightness(1.05);
    }

    /* Esconder mensagem vazia quando há notificações */
    .notification-dropdown-body:has(.notification-item) .notification-empty {
        display: none;
    }

    /* Overlay */
    .notification-dropdown-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.2);
        z-index: var(--z-header);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }

    .notification-dropdown-overlay.active {
        opacity: 1;
        visibility: visible;
    }

    /* Botão Menu Sanduíche */
    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--touch-min);
        height: var(--touch-min);
        background: transparent;
        border: none;
        border-radius: var(--radius-lg);
        color: #000000;
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .mobile-menu-toggle:hover,
    .mobile-menu-toggle:active {
        background: transparent;
        transform: scale(0.95);
    }

    .mobile-menu-toggle i,
    .mobile-menu-toggle svg {
        width: 24px;
        height: 24px;
        color: #000000;
        stroke: #000000;
        stroke-linecap: round;
        stroke-linejoin: round;
        transition: all 0.3s ease;
    }

    /* Estado aberto - transformar em X */
    .mobile-menu-toggle.active i {
        transform: rotate(45deg);
    }

    .mobile-menu-toggle.active i::before,
    .mobile-menu-toggle.active i::after {
        content: '';
        position: absolute;
        background: #ffffff;
    }

    /* Animação das linhas do menu virando X */
    .mobile-menu-toggle.active .lucide-menu {
        display: none;
    }

    .mobile-menu-toggle.active::after {
        content: '';
        position: absolute;
        width: 24px;
        height: 24px;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'/%3E%3Cline x1='6' y1='6' x2='18' y2='18'/%3E%3C/svg%3E") no-repeat center;
        background-size: contain;
    }

    /* Menu Mobile Overlay */
    .mobile-menu-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: var(--z-menu);
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }

    .mobile-menu-overlay.active {
        opacity: 1;
        visibility: visible;
        z-index: 10000;
    }

    /* Menu Mobile Sidebar */
    .mobile-menu-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        max-height: 100vh;
        background: rgba(30, 30, 30, 0.98);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        z-index: 10001;
        transition: transform 0.3s ease, opacity 0.3s ease;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: var(--space-5);
        padding-top: calc(env(safe-area-inset-top, 0px) + 50px);
        transform: translateY(-100%);
        opacity: 0;
        visibility: hidden;
    }

    [data-theme="dark"] .mobile-menu-sidebar {
        background: rgba(20, 20, 20, 0.98);
    }

    /* Esconder Mundo Hoje do sidebar mobile */
    .mobile-menu-sidebar .mobile-menu-link[href*="mundo-hoje"] {
        display: none;
    }

    .mobile-menu-sidebar.active {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
    }

    /* Topo do menu — logo + botão fechar */
    .mobile-menu-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        margin-bottom: var(--space-6);
        padding-bottom: var(--space-4);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    }

    .mobile-menu-logo {
        display: flex;
        align-items: center;
        justify-content: center;
        flex: 1;
    }

    .mobile-menu-logo img {
        height: 18px;
        width: auto;
    }

    .mobile-menu-close {
        display: flex;
        align-items: center;
        justify-content: center;
        width: var(--touch-min);
        height: var(--touch-min);
        background: rgba(255, 255, 255, 0.1);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: var(--radius-lg);
        color: #ffffff;
        cursor: pointer;
    }

    .mobile-menu-close:active {
        background: rgba(255, 255, 255, 0.2);
        transform: scale(0.95);
    }

    /* Menu Header - Oculto no dropdown */
    .mobile-menu-header {
        display: none;
    }

    /* Menu Sections */
    .mobile-menu-section {
        margin-bottom: var(--space-6);
    }

    .mobile-menu-section:last-child {
        margin-bottom: 0;
    }

    .mobile-menu-title {
        color: var(--accent-color);
        font-size: var(--text-xs);
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 1px;
        margin-bottom: var(--space-3);
        padding-left: var(--space-1);
    }

    /* Menu Links */
    .mobile-menu-link {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        padding: 14px var(--mobile-gutter);
        color: #ffffff;
        text-decoration: none;
        border-radius: var(--radius-lg);
        margin-bottom: var(--space-1);
        transition: all 0.2s ease;
        background: transparent;
        border: 1px solid transparent;
        min-height: var(--touch-min);
    }

    .mobile-menu-link:hover {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.15);
    }

    .mobile-menu-link i {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
        opacity: 0.7;
    }

    .mobile-menu-link span {
        font-size: var(--text-md);
        font-weight: 500;
    }

    .mobile-menu-link.active {
        background: rgba(255, 255, 255, 0.12);
        border-color: rgba(255, 255, 255, 0.25);
    }

    .mobile-menu-link.active i {
        opacity: 1;
        color: #ffffff;
    }

    .mobile-menu-link.active span {
        color: #ffffff;
        font-weight: 600;
    }

    .mobile-menu-link.mobile-logout-btn {
        color: var(--accent-color, #FF5757);
        margin-top: var(--space-2, 8px);
    }

    .mobile-menu-link.mobile-logout-btn i {
        opacity: 1;
        color: var(--accent-color, #FF5757);
    }

    /* Divider */
    .mobile-menu-divider {
        height: 1px;
        background: rgba(255, 255, 255, 0.1);
        margin: var(--space-5) 0;
    }

    /* Mobile Menu Dropdown */
    .mobile-menu-dropdown {
        margin-bottom: var(--space-1);
    }

    .mobile-menu-dropdown-toggle {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        width: 100%;
        padding: 14px var(--mobile-gutter);
        color: #ffffff;
        background: transparent;
        border: 1px solid transparent;
        border-radius: var(--radius-lg);
        cursor: pointer;
        transition: all 0.2s ease;
        text-align: left;
        font-size: var(--text-md);
        font-weight: 500;
        min-height: var(--touch-min);
    }

    .mobile-menu-dropdown-toggle:hover {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.15);
    }

    .mobile-menu-dropdown-toggle i:first-child {
        width: 20px;
        height: 20px;
        flex-shrink: 0;
        opacity: 0.7;
    }

    .mobile-menu-dropdown-toggle span {
        flex: 1;
    }

    .mobile-menu-dropdown-toggle .dropdown-arrow {
        width: 16px;
        height: 16px;
        flex-shrink: 0;
        transition: transform 0.3s ease;
    }

    .mobile-menu-dropdown.active .dropdown-arrow {
        transform: rotate(180deg);
    }

    .mobile-menu-dropdown-content {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        padding-left: var(--mobile-gutter);
    }

    .mobile-menu-dropdown.active .mobile-menu-dropdown-content {
        max-height: 500px;
        padding-top: var(--space-1);
        padding-bottom: var(--space-1);
    }

    .mobile-menu-dropdown-content .mobile-menu-link {
        padding: 10px var(--mobile-gutter);
        font-size: var(--text-base);
    }

    .mobile-menu-dropdown-content .mobile-menu-link i {
        width: 18px;
        height: 18px;
    }

    .mobile-menu-dropdown-content .mobile-menu-link span {
        font-size: var(--text-base);
    }

    /* Safe Area para iPhone X+ */
    @supports (padding: max(0px)) {
        .mobile-header {
            padding-top: calc(max(12px, env(safe-area-inset-top, 12px)) + 2.5rem);
            padding-left: max(var(--mobile-gutter), env(safe-area-inset-left));
            padding-right: max(var(--mobile-gutter), env(safe-area-inset-right));
        }

        html body.page-with-home .chat-messages {
            padding-top: calc(var(--mobile-header-total) + var(--sticky-bar-height) + env(safe-area-inset-top, 0px));
        }

        .mobile-menu-sidebar {
            padding-top: max(50px, calc(50px + env(safe-area-inset-top)));
            padding-left: max(var(--space-5), env(safe-area-inset-left));
            padding-right: max(var(--space-5), env(safe-area-inset-right));
            padding-bottom: max(var(--space-5), env(safe-area-inset-bottom));
        }
    }
}

/* ==========================================================================
   DESKTOP - Ocultar elementos mobile
   ========================================================================== */

@media (min-width: 769px) {
    .mobile-status-bar,
    .mobile-header,
    .mobile-menu-overlay,
    .mobile-menu-sidebar,
    .notification-dropdown,
    .notification-dropdown-overlay {
        display: none !important;
    }
}

/* Fullscreen pages — hide mobile header */
body.page-jarvis-meeting .mobile-header,
body.page-jarvis-sales .mobile-header,
body.page-treinamento-vendas .mobile-header {
    display: none !important;
}

@media (max-width: 768px) {
    body.page-jarvis-sales .chat-container,
    body.page-jarvis-meeting .jarvis-page,
    body.page-treinamento-vendas .chat-container {
        padding-top: 50px;
    }
}
