/* ============================================================
   DESIGN SYSTEM MOBILE — Aceleres.ai
   Source of truth for all mobile styles (≤768px)
   Load AFTER app.css, BEFORE mobile-fixes.css
   ============================================================ */

/* ------------------------------------------------------------
   1. CSS Custom Properties
   ------------------------------------------------------------ */
:root {
    /* Spacing — base 4px */
    --space-0: 0px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* Typography */
    --text-xs: 12px;
    --text-sm: 13px;
    --text-base: 14px;
    --text-md: 15px;
    --text-lg: 16px;
    --text-xl: 18px;
    --text-2xl: 20px;
    --text-3xl: 24px;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Z-index — 10 tiers */
    --z-base: 0;
    --z-dropdown: 100;
    --z-sticky: 200;
    --z-fixed: 300;
    --z-overlay: 400;
    --z-modal: 500;
    --z-popover: 600;
    --z-toast: 700;
    --z-header: 800;
    --z-menu: 900;
    --z-max: 1000;

    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-xl: 0 8px 32px rgba(0, 0, 0, 0.16);

    /* Touch */
    --touch-min: 44px;
    --touch-comfortable: 48px;

    /* Layout Mobile */
    --mobile-header-height: 86px;
    --mobile-status-bar: 2.8rem;
    --mobile-header-total: calc(var(--mobile-header-height) + var(--mobile-status-bar));
    --mobile-bottom-bar-height: 4.25rem;
    --mobile-gutter: 16px;
    --sticky-bar-height: 0px; /* overridden by JS ResizeObserver on mobile */
}

/* ------------------------------------------------------------
   2. Mobile Base — Primary breakpoint (≤768px)
   ------------------------------------------------------------ */
@media (max-width: 768px) {

    /* -- Safe fallback for --sticky-bar-height before JS measures */
    html body.page-with-home {
        --sticky-bar-height: 190px;
    }

    /* -- Touch Targets ---------------------------------------- */
    html body.page-with-home button:not(.tab-info-btn),
    html body.page-with-home a.btn,
    html body.page-with-home .btn:not(.tab-info-btn),
    html body.page-with-home select,
    html body.page-with-home [role="button"]:not(.tab-info-btn),
    html body.page-with-home [role="tab"] {
        min-height: var(--touch-min);
    }

    html body.page-with-home input[type="text"],
    html body.page-with-home input[type="email"],
    html body.page-with-home input[type="password"],
    html body.page-with-home input[type="search"],
    html body.page-with-home input[type="tel"],
    html body.page-with-home input[type="url"],
    html body.page-with-home input[type="number"],
    html body.page-with-home input[type="date"],
    html body.page-with-home textarea,
    html body.page-with-home select {
        font-size: var(--text-lg); /* 16px — prevents iOS zoom */
        min-height: var(--touch-min);
    }

    /* -- Home Header, Bottom Bar — hidden on mobile */
    html body.page-with-home .home-header,
    .home-header,
    html body.page-with-home .chat-bottom-bar,
    .chat-bottom-bar {
        display: none !important;
    }

    /* -- Home Sticky Bar — minimal container for tabs only */
    html body.page-with-home .home-sticky-bar,
    .home-sticky-bar {
        position: fixed;
        top: 1rem;
        left: 0;
        right: 0;
        z-index: var(--z-fixed);
        padding: 0 var(--space-5);
        padding-top: calc(env(safe-area-inset-top, 0px) + 100px);
        padding-bottom: var(--space-2);
        margin: 0;
        background: var(--bg-primary, #ffffff);
        border: none;
        box-shadow: none;
        pointer-events: none;
    }

    /* -- Home Tabs — 2×2 grid on mobile */
    html body.page-with-home .home-tabs,
    .home-tabs {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-1);
        padding: var(--space-1);
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: var(--radius-lg);
        pointer-events: auto;
        box-shadow: var(--shadow-sm);
    }

    html body.page-with-home .home-tab,
    .home-tab {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-1);
        padding: var(--space-2) var(--space-3);
        font-size: var(--text-xs);
        font-weight: 500;
        min-height: 36px;
        border-radius: var(--radius-md);
        border: none;
        border-bottom: none;
        background: transparent;
        color: var(--text-secondary);
        white-space: nowrap;
        text-decoration: none;
        cursor: pointer;
    }

    html body.page-with-home .home-tab.active,
    .home-tab.active {
        background: var(--bg-primary);
        color: var(--accent-color);
        font-weight: 600;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
        border-bottom: none;
    }

    html body.page-with-home .home-tab i,
    .home-tab i {
        width: 14px;
        height: 14px;
        flex-shrink: 0;
    }

    html body.page-with-home .home-tab span,
    .home-tab span {
        display: inline;
    }

    /* Back button inside sticky-bar needs pointer-events */
    html body.page-with-home .home-sticky-bar .nav-tabs-back,
    .home-sticky-bar .nav-tabs-back {
        pointer-events: auto;
    }

    /* -- Chat Input — source of truth for mobile --------------- */
    html body.page-with-home .chat-input-container {
        position: fixed;
        bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-3));
        left: var(--space-3);
        right: var(--space-3);
        width: auto;
        max-width: none;
        z-index: var(--z-fixed);
        margin: 0;
        padding: 0;
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
        border-radius: 24px;
        box-sizing: border-box;
        background: transparent;
        border: none;
        box-shadow: none;
    }

    html body.page-with-home .chat-form {
        max-width: 100%;
    }

    html body.page-with-home .input-wrapper {
        display: flex;
        flex-direction: column;
        min-height: var(--touch-min);
        padding: 0;
        border-radius: 24px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    }

    html body.page-with-home .input-wrapper.input-wrapper--inline {
        flex-direction: row;
        align-items: center;
        min-height: auto;
        padding: 4px 6px;
        gap: 4px;
    }

    html body.page-with-home .input-wrapper.input-wrapper--inline .message-input {
        padding: 4px 0;
        margin: 0;
        min-height: 32px;
        line-height: 24px;
        font-size: 16px; /* prevents iOS zoom */
    }

    html body.page-with-home .input-wrapper:focus-within {
        border-color: var(--text-tertiary);
    }

    html body.page-with-home .message-input {
        font-size: var(--text-lg); /* 16px — prevents iOS zoom */
        padding: 12px 16px 4px;
    }

    html body.page-with-home .input-actions {
        position: static;
        display: flex;
        align-items: center;
        gap: 2px;
        padding: 4px 8px 8px;
    }

    html body.page-with-home .input-actions .action-btn {
        min-width: var(--touch-min);
        min-height: var(--touch-min);
        width: 30px;
        height: 30px;
        border-radius: 50%;
    }

    html body.page-with-home .input-actions .action-btn:active {
        opacity: 0.7;
    }

    html body.page-with-home .input-actions .action-btn i,
    html body.page-with-home .input-actions .action-btn [data-lucide] {
        width: 16px;
        height: 16px;
    }

    html body.page-with-home .input-actions .send-button,
    html body.page-with-home .send-button {
        min-width: var(--touch-min);
        min-height: var(--touch-min);
        width: 30px;
        height: 30px;
        border-radius: 50%;
        margin-left: auto;
    }

    html body.page-with-home .input-actions .send-button:active,
    html body.page-with-home .send-button:active {
        opacity: 0.7;
    }

    html body.page-with-home .input-actions .send-button i,
    html body.page-with-home .send-button i,
    html body.page-with-home .input-actions .send-button [data-lucide],
    html body.page-with-home .send-button [data-lucide] {
        width: 16px;
        height: 16px;
    }

    html body.page-with-home .input-footer {
        display: none;
    }

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

    html body.page-with-home .chat-messages .home-screen {
        padding: 0;
        margin-top: 0;
        gap: 0;
        max-width: 100%;
        overflow-x: hidden;
        box-sizing: border-box;
    }

    html body.page-with-home .chat-messages .home-screen .quick-shortcuts {
        padding-top: var(--space-4);
    }

    /* Sticky-bar is position:fixed — no extra margin from flow */
    html body.page-with-home .chat-messages .home-screen > .home-sticky-bar {
        margin: 0;
        min-height: 0;
    }

    html body.page-with-home .chat-messages {
        overflow-x: hidden;
    }

    /* -- Modals ---------------------------------------------- */
    /* Generic modals — centered with margins */
    html body.page-with-home .modal-dialog {
        width: calc(100vw - 32px);
        max-width: calc(100vw - 32px);
        max-height: calc(100dvh - 64px);
        margin: 32px auto;
        overflow-y: auto;
        z-index: var(--z-modal);
    }

    html body.page-with-home .modal-backdrop {
        z-index: var(--z-overlay);
    }

    html body.page-with-home .modal-footer {
        flex-direction: column;
        gap: var(--space-2);
    }

    html body.page-with-home .modal-footer .btn {
        width: 100%;
    }

    /* Bottom-sheet modals — config, profile */
    html body.page-with-home .config-modal,
    html body.page-with-home .profile-modal {
        z-index: 10000;
    }

    html body.page-with-home .config-modal-content,
    html body.page-with-home .profile-modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 85vh;
        margin: 0;
        border-radius: 20px 20px 0 0;
        padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 20px)) 20px;
    }

    /* Centered popups — jornada, rotina */
    html body.page-with-home .jornada-config-popup__content,
    html body.page-with-home .rotina-modal {
        width: calc(100vw - 32px);
        max-width: calc(100vw - 32px);
        max-height: calc(100dvh - 64px);
        overflow-y: auto;
    }

    /* -- Toasts ---------------------------------------------- */
    html body.page-with-home .toast-container,
    html body.page-with-home [class*="toast"],
    html body.page-with-home [class*="notification-popup"] {
        z-index: var(--z-toast);
    }

    /* -- Mobile Header --------------------------------------- */
    html body.page-with-home .mobile-header {
        z-index: var(--z-header);
        min-height: var(--mobile-header-height);
        height: auto;
    }

    /* -- Mobile Menu ----------------------------------------- */
    html body.page-with-home .mobile-menu-overlay {
        z-index: var(--z-menu);
    }

    html body.page-with-home .mobile-menu-sidebar {
        z-index: var(--z-menu);
    }

    /* -- Overflow guard — prevent horizontal scroll ----------- */
    html body.page-with-home,
    html body.page-with-home * {
        max-width: 100%;
        box-sizing: border-box;
    }

    /* -- Safe Area ------------------------------------------- */
    html body.page-with-home {
        padding-bottom: env(safe-area-inset-bottom, 0px);
        overflow-x: hidden;
    }

    @supports (padding-top: env(safe-area-inset-top)) {
        html body.page-with-home .mobile-bottom-bar {
            padding-bottom: env(safe-area-inset-bottom, 0px);
        }
    }

    /* -- Grids ----------------------------------------------- */
    .mobile-grid-1 {
        display: grid;
        grid-template-columns: 1fr;
        gap: var(--space-3);
    }

    .mobile-grid-2 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }

    /* -- Utility Classes ------------------------------------- */
    .mobile-stack {
        display: flex;
        flex-direction: column;
    }

    .mobile-full-width {
        width: 100%;
    }

    .mobile-hidden {
        display: none;
    }

    .mobile-gutter {
        padding-left: var(--mobile-gutter);
        padding-right: var(--mobile-gutter);
    }

    .mobile-scroll-x {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .mobile-scroll-x::-webkit-scrollbar {
        display: none;
    }

    .mobile-text-truncate {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .btn-mobile {
        min-height: var(--touch-min);
        padding: var(--space-2) var(--space-4);
        font-size: var(--text-base);
        border-radius: var(--radius-md);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    .btn-mobile-icon {
        min-width: var(--touch-min);
        min-height: var(--touch-min);
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: var(--space-2);
        border-radius: var(--radius-md);
    }

    .touch-target {
        min-width: var(--touch-min);
        min-height: var(--touch-min);
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

} /* end @media 768px */

/* ------------------------------------------------------------
   3. Small phones (≤480px)
   ------------------------------------------------------------ */
@media (max-width: 480px) {

    .mobile-grid-2 {
        grid-template-columns: 1fr;
    }

    /* -- Chat Input — tighter on small phones ---------------- */
    html body.page-with-home .chat-input-container {
        left: var(--space-2);
        right: var(--space-2);
    }
}

/* ------------------------------------------------------------
   4. Extra-small phones (≤374px) — iPhone SE, small Android
   ------------------------------------------------------------ */
@media (max-width: 374px) {

    html body.page-with-home .modal-dialog,
    html body.page-with-home .jornada-config-popup__content,
    html body.page-with-home .rotina-modal {
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
        margin: 8px auto;
    }
}

/* ----------------------------------------------------------------
   Quick Tabs FAB — Mobile only (page-atalhos-rapidos)
   ---------------------------------------------------------------- */

/* Hidden on desktop */
.quick-tabs-fab,
.quick-tabs-overlay,
.quick-tabs-panel {
    display: none;
}

@media (max-width: 768px) {

    /* FAB button */
    .quick-tabs-fab {
        display: flex;
        align-items: center;
        justify-content: center;
        position: fixed;
        bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
        right: var(--space-4, 16px);
        width: 48px;
        height: 48px;
        border-radius: 50%;
        border: none;
        background: linear-gradient(135deg, var(--accent-color, #FF5757), var(--accent-hover, #E04848));
        color: #ffffff;
        box-shadow: 0 4px 16px rgba(var(--accent-color-rgb, 255,87,87), 0.4);
        cursor: pointer;
        z-index: var(--z-fixed, 300);
        transition: transform 0.2s ease, box-shadow 0.2s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .quick-tabs-fab:active {
        transform: scale(0.92);
    }

    .quick-tabs-fab.active {
        transform: rotate(45deg);
    }

    /* Overlay */
    .quick-tabs-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(6px);
        -webkit-backdrop-filter: blur(6px);
        z-index: calc(var(--z-header, 800) + 1);
    }

    .quick-tabs-overlay.active {
        display: block;
    }

    /* Panel */
    .quick-tabs-panel {
        display: none;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: #ffffff;
        border-radius: 20px 20px 0 0;
        padding: var(--space-5, 20px) var(--space-4, 16px);
        padding-top: calc(var(--space-5, 20px) + 12px);
        padding-bottom: calc(env(safe-area-inset-bottom, 0px) + var(--space-5, 20px));
        z-index: calc(var(--z-header, 800) + 2);
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    /* Drag handle */
    .quick-tabs-panel::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(0, 0, 0, 0.2);
        border-radius: 2px;
    }

    .quick-tabs-panel.active {
        display: block;
        transform: translateY(0);
    }

    .quick-tabs-panel__title {
        font-size: var(--text-sm, 14px);
        font-weight: 600;
        color: var(--text-secondary, #666);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: var(--space-3, 12px);
        padding: 0 var(--space-1, 4px);
    }

    .quick-tabs-panel__grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-2, 8px);
    }

    .quick-tabs-panel__link {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: var(--space-2, 8px);
        padding: var(--space-3, 12px) var(--space-3, 12px);
        font-size: var(--text-sm, 14px);
        font-weight: 500;
        color: var(--text-primary, #333);
        background: var(--bg-secondary, #f5f5f5);
        border-radius: var(--radius-md, 8px);
        text-decoration: none;
        min-height: 44px;
        transition: background 0.15s ease;
        -webkit-tap-highlight-color: transparent;
    }

    .quick-tabs-panel__link:active {
        background: var(--bg-tertiary, #eee);
    }

    .quick-tabs-panel__link.active {
        background: linear-gradient(135deg, var(--accent-color, #FF5757), var(--accent-hover, #E04848));
        color: #ffffff;
        font-weight: 600;
    }

    .quick-tabs-panel__link i {
        width: 18px;
        height: 18px;
        flex-shrink: 0;
    }

    /* Dark theme */
    html[data-theme="dark"] .quick-tabs-panel {
        background: var(--bg-secondary, #1a1a1a);
    }

    html[data-theme="dark"] .quick-tabs-panel__link {
        background: rgba(255, 255, 255, 0.08);
        color: var(--text-primary, #eee);
    }

    html[data-theme="dark"] .quick-tabs-panel__link:active {
        background: rgba(255, 255, 255, 0.15);
    }

    html[data-theme="dark"] .quick-tabs-panel__link.active {
        background: linear-gradient(135deg, var(--accent-color, #FF5757), var(--accent-hover, #E04848));
        color: #ffffff;
    }
}
