/**
 * ============================================================================
 *  MOBILE GLOBAL CSS v5.0 - FORMULARIOS MOBILE
 * ============================================================================
 *
 * Corrige problemas em mobile (< 640px):
 * 1. Wizard steps (transform scale, tamanho dos circulos)
 * 2. Card "Pronto para salvar" (layout dos botoes)
 * 3. FAB Salvar Mobile (posicionamento)
 * 4. Header do formulario (base_form.html)
 *
 * v5.0: Header mobile movido para componente independente:
 *       project/templates/componentes/header_mobile.html
 *       CSS do header agora e 100% encapsulado no componente.
 * ============================================================================
 */

/* =============================================================================
   1. WIZARD STEPS - MOBILE (< 640px)
   Seletor especifico: .mb-8.relative .grid.grid-cols-3
   Inclui .gap-3 para maior especificidade sobre notas_form.html
   ============================================================================= */

@media (max-width: 639px) {

    /* Container do wizard - gap reduzido */
    .mb-8.relative .grid.grid-cols-3,
    .mb-8.relative .grid.grid-cols-3.gap-3 {
        gap: 0.375rem !important;
    }

    /* Cards do wizard - remove transform scale */
    .mb-8.relative .grid.grid-cols-3 > div,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div {
        transform: none !important;
        -webkit-transform: none !important;
        padding: 0.5rem 0.375rem !important;
        border-width: 2px !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1) !important;
        z-index: 1 !important;
        min-height: 75px !important;
    }

    /* Circulo do numero - 36px */
    .mb-8.relative .grid.grid-cols-3 > div > div:first-child,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div > div:first-child {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        max-width: 36px !important;
        font-size: 0.875rem !important;
        border-width: 2.5px !important;
        margin-bottom: 0.25rem !important;
        box-shadow: none !important;
    }

    /* Icone check dentro do circulo */
    .mb-8.relative .grid.grid-cols-3 > div > div:first-child i,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div > div:first-child i {
        font-size: 1rem !important;
    }

    /* Titulo do step */
    .mb-8.relative .grid.grid-cols-3 > div .font-bold,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div .font-bold,
    .mb-8.relative .grid.grid-cols-3.gap-3 .font-bold.text-base {
        font-size: 0.625rem !important;
        line-height: 1.15 !important;
        margin: 0 !important;
    }

    /* Subtitulo - esconder */
    .mb-8.relative .grid.grid-cols-3 > div .text-xs.mt-1.hidden,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div .text-xs.mt-1.hidden {
        display: none !important;
    }

    /* Badge de status */
    .mb-8.relative .grid.grid-cols-3 > div .mt-2.inline-flex,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div .mt-2.inline-flex,
    .mb-8.relative .grid.grid-cols-3.gap-3 .mt-2.inline-flex {
        margin-top: 0.125rem !important;
        padding: 0.0625rem 0.25rem !important;
        font-size: 0.5rem !important;
        gap: 0.0625rem !important;
    }

    .mb-8.relative .grid.grid-cols-3 > div .mt-2.inline-flex i,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div .mt-2.inline-flex i,
    .mb-8.relative .grid.grid-cols-3.gap-3 .mt-2.inline-flex i {
        font-size: 0.5rem !important;
    }

    /* Linha de progresso - esconder em mobile */
    .mb-8.relative > .hidden.lg\:block {
        display: none !important;
    }

    /* Fix para inline styles do Alpine.js */
    .mb-8.relative .grid.grid-cols-3 > div[style],
    .mb-8.relative .grid.grid-cols-3.gap-3 > div[style] {
        transform: none !important;
    }

    .mb-8.relative .grid.grid-cols-3 > div > div[style]:first-child,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div > div[style]:first-child {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
    }
}

/* Telas muito pequenas (< 360px) */
@media (max-width: 359px) {
    .mb-8.relative .grid.grid-cols-3,
    .mb-8.relative .grid.grid-cols-3.gap-3 {
        gap: 0.25rem !important;
    }

    .mb-8.relative .grid.grid-cols-3 > div,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div {
        padding: 0.375rem 0.25rem !important;
        min-height: 65px !important;
        border-radius: 0.5rem !important;
    }

    .mb-8.relative .grid.grid-cols-3 > div > div:first-child,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div > div:first-child {
        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
        font-size: 0.75rem !important;
        border-width: 2px !important;
    }

    .mb-8.relative .grid.grid-cols-3 > div .font-bold,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div .font-bold,
    .mb-8.relative .grid.grid-cols-3.gap-3 .font-bold.text-base {
        font-size: 0.5625rem !important;
    }

    .mb-8.relative .grid.grid-cols-3 > div .mt-2.inline-flex,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div .mt-2.inline-flex,
    .mb-8.relative .grid.grid-cols-3.gap-3 .mt-2.inline-flex {
        display: none !important;
    }

    .mb-8.relative .grid.grid-cols-3 > div > div[style]:first-child,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div > div[style]:first-child {
        width: 30px !important;
        height: 30px !important;
        min-width: 30px !important;
    }
}

/* =============================================================================
   2. CARD "PRONTO PARA SALVAR" - MOBILE
   IMPORTANTE: O card esta DENTRO do #formulario-principal
   Estrutura: form > div.shadow-lg.mt-4 > div.h-1 + div.p-4 > div.flex.flex-col
   ============================================================================= */

@media (max-width: 639px) {

    /* Container do card - DENTRO do form, usando seletores multiplos para robustez */
    #formulario-principal > .shadow-lg.mt-4,
    #formulario-principal > .bg-white.shadow-lg,
    #formulario-principal > .rounded-xl.shadow-lg.border {
        margin-top: 0.75rem !important;
    }

    /* Padding interno do card - .p-4 dentro de shadow-lg */
    #formulario-principal > .shadow-lg .p-4 {
        padding: 0.75rem !important;
    }

    /* Flex container principal - identificado por .justify-between */
    #formulario-principal > .shadow-lg .flex.justify-between,
    #formulario-principal > .shadow-lg .flex.flex-col.items-center.justify-between {
        flex-direction: column !important;
        gap: 0.75rem !important;
        align-items: stretch !important;
    }

    /* Secao de texto com icone verde - identificado por .text-gray-600 */
    #formulario-principal > .shadow-lg .flex.items-center.gap-3.text-gray-600,
    #formulario-principal > .shadow-lg .flex.gap-3.text-gray-600 {
        width: 100% !important;
        justify-content: flex-start !important;
    }

    /* Icone check verde - .w-10.h-10.rounded-full */
    #formulario-principal > .shadow-lg .w-10.h-10.rounded-full,
    #formulario-principal > .shadow-lg .w-10.h-10 {
        width: 32px !important;
        height: 32px !important;
        min-width: 32px !important;
        flex-shrink: 0 !important;
    }

    #formulario-principal > .shadow-lg .w-10.h-10 i {
        font-size: 0.875rem !important;
    }

    /* Textos - "Pronto para salvar?" e descricao */
    #formulario-principal > .shadow-lg p.font-medium,
    #formulario-principal > .shadow-lg .font-medium.text-gray-700 {
        font-size: 0.8125rem !important;
    }

    #formulario-principal > .shadow-lg p.text-xs,
    #formulario-principal > .shadow-lg .text-xs.text-gray-500 {
        font-size: 0.6875rem !important;
    }

    /* Container dos botoes - .w-full indica que eh o container dos botoes */
    #formulario-principal > .shadow-lg .flex.items-center.gap-3.w-full {
        flex-direction: row !important;
        gap: 0.5rem !important;
        width: 100% !important;
    }

    /* Botao Cancelar - link com min-h-[48px] */
    #formulario-principal > .shadow-lg a[class*="min-h-"],
    #formulario-principal > .shadow-lg a.rounded-lg.border {
        min-width: 44px !important;
        max-width: 44px !important;
        min-height: 44px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }

    /* Esconde texto "Cancelar" - span com classe ml-1 */
    #formulario-principal > .shadow-lg a span.ml-1,
    #formulario-principal > .shadow-lg a[class*="min-h-"] span {
        display: none !important;
    }

    /* Botao Salvar - button com gradiente verde */
    #formulario-principal > .shadow-lg button[type="submit"],
    #formulario-principal > .shadow-lg button[class*="from-green"],
    #formulario-principal > .shadow-lg button.rounded-xl {
        flex: 1 !important;
        min-height: 48px !important;
        padding: 0.625rem 1rem !important;
        font-size: 0.875rem !important;
    }

    /* Icone dentro do botao salvar */
    #formulario-principal > .shadow-lg button i.text-xl {
        font-size: 1rem !important;
    }
}

/* =============================================================================
   3. FAB SALVAR MOBILE - Posicionamento correto
   ============================================================================= */

@media (max-width: 639px) {

    /* FAB - Posicao fixa no canto inferior direito */
    .fab-salvar-mobile {
        position: fixed !important;
        bottom: calc(1rem + env(safe-area-inset-bottom, 0px)) !important;
        right: 1rem !important;
        left: auto !important;
        width: 52px !important;
        height: 52px !important;
        min-width: 52px !important;
        min-height: 52px !important;
        z-index: 9999 !important;
    }

    .fab-salvar-mobile i {
        font-size: 1.25rem !important;
    }
}

/* Telas muito pequenas */
@media (max-width: 359px) {
    .fab-salvar-mobile {
        bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px)) !important;
        right: 0.75rem !important;
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        min-height: 48px !important;
    }

    .fab-salvar-mobile i {
        font-size: 1.125rem !important;
    }
}

/* =============================================================================
   4. HEADER DO FORMULARIO - MOBILE
   Layout: [Icone+Titulo] ---- [Voltar] [Imprimir?] [Salvar] [Novo]
   ============================================================================= */

@media (max-width: 639px) {

    /* Card do header - padding e margem reduzidos */
    #form-header-sticky {
        margin-bottom: 0.75rem !important;
        border-radius: 0.75rem !important;
    }

    /* Toggle sticky - ESCONDER em mobile */
    #form-header-sticky > .flex.justify-center.-mt-2,
    #form-header-sticky .flex.justify-center.-mt-2.mb-2 {
        display: none !important;
    }

    /* Container principal - layout em LINHA */
    #form-header-sticky > .flex.flex-col,
    #form-header-sticky > div > .flex.flex-col {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 0.75rem !important;
        gap: 0.5rem !important;
    }

    /* Secao do titulo - compacta */
    #form-header-sticky .w-full.sm\:w-auto:first-child,
    #form-header-sticky > .flex > .w-full:first-child {
        width: auto !important;
        flex: 1 !important;
        min-width: 0 !important;
    }

    /* Titulo h1 - linha unica com truncate */
    #form-header-sticky h1,
    #form-header-sticky h1.text-xl {
        font-size: 0.9375rem !important;
        line-height: 1.2 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        margin-right: 0 !important;
    }

    /* Icone do titulo - 28px */
    #form-header-sticky h1 > .w-10.h-10,
    #form-header-sticky h1 > .w-12.h-12,
    #form-header-sticky h1 .rounded-lg.bg-gradient-to-br {
        width: 28px !important;
        height: 28px !important;
        min-width: 28px !important;
        margin-right: 0.5rem !important;
        border-radius: 0.375rem !important;
    }

    #form-header-sticky h1 > .w-10.h-10 i,
    #form-header-sticky h1 > .w-12.h-12 i,
    #form-header-sticky h1 .rounded-lg i {
        font-size: 0.75rem !important;
    }

    /* Texto do titulo - truncate (calc: viewport - icon 28px - gap - actions ~120px) */
    #form-header-sticky h1 > span.truncate {
        max-width: calc(100vw - 200px) !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* Auto-save indicator - compacto */
    #form-header-sticky h1 span[x-show*="autoSaveStatus"],
    #form-header-sticky h1 template + span,
    #form-header-sticky h1 .inline-flex.items-center {
        margin-left: 0.25rem !important;
        padding: 0.125rem 0.375rem !important;
        font-size: 0.5625rem !important;
    }

    #form-header-sticky h1 .inline-flex.items-center span.hidden {
        display: none !important;
    }

    /* Descricao - ESCONDER em mobile */
    #form-header-sticky p.text-gray-500,
    #form-header-sticky p.text-sm,
    #form-header-sticky .w-full.sm\:w-auto p {
        display: none !important;
    }

    /* Container de acoes - compacto em linha */
    #form-header-sticky .flex.items-center.flex-wrap,
    #form-header-sticky > .flex > .flex.items-center:last-child {
        flex-wrap: nowrap !important;
        gap: 0.25rem !important;
        width: auto !important;
        justify-content: flex-end !important;
    }

    /* Grupos de botoes - sem separador */
    #form-header-sticky .flex.items-center.gap-2,
    #form-header-sticky .flex.items-center.gap-3 {
        gap: 0.25rem !important;
    }

    /* Separador visual - ESCONDER */
    #form-header-sticky .flex-1.flex.justify-center,
    #form-header-sticky .hidden.sm\:flex.items-center.gap-1 {
        display: none !important;
    }

    /* Botoes de acao - tamanho touch minimo 44x44px (Apple HIG) */
    #form-header-sticky .form-action-icon {
        min-width: 44px !important;
        min-height: 44px !important;
        width: 44px !important;
        height: 44px !important;
        padding: 0.5rem !important;
        border-radius: 0.5rem !important;
    }

    #form-header-sticky .form-action-icon svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* Tooltips - esconder em mobile */
    #form-header-sticky .form-action-tooltip {
        display: none !important;
    }
}

/* Telas muito pequenas (< 360px) */
@media (max-width: 359px) {
    #form-header-sticky h1 > span.truncate {
        max-width: calc(100vw - 180px) !important;
    }

    #form-header-sticky h1 > .w-10.h-10,
    #form-header-sticky h1 > .w-12.h-12,
    #form-header-sticky h1 .rounded-lg.bg-gradient-to-br {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        margin-right: 0.375rem !important;
    }

    #form-header-sticky h1 > .w-10.h-10 i,
    #form-header-sticky h1 .rounded-lg i {
        font-size: 0.625rem !important;
    }

    #form-header-sticky h1 {
        font-size: 0.8125rem !important;
    }

    /* Auto-save - esconder texto */
    #form-header-sticky h1 .inline-flex.items-center span {
        display: none !important;
    }

    #form-header-sticky .form-action-icon {
        min-width: 32px !important;
        min-height: 32px !important;
        width: 32px !important;
        height: 32px !important;
    }

    #form-header-sticky .form-action-icon svg {
        width: 16px !important;
        height: 16px !important;
    }
}

/* =============================================================================
   5. INDICADOR DE PROGRESSO MOBILE - Compactar
   ============================================================================= */

@media (max-width: 639px) {

    /* Card do indicador de progresso */
    [x-show="etapasTotal > 1"].bg-white.rounded-xl,
    div[x-show="etapasTotal > 1"].bg-white {
        padding: 0.75rem !important;
        margin-bottom: 0.75rem !important;
    }

    /* Navegacao entre etapas */
    [x-show="etapasTotal > 1"] .lg\:hidden .text-lg,
    div[x-show="etapasTotal > 1"] .text-lg {
        font-size: 1rem !important;
    }
}

/* =============================================================================
   6. SAFE AREA - iPhones com notch
   ============================================================================= */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    @media (max-width: 639px) {
        /* Padding inferior no formulario */
        #formulario-principal {
            padding-bottom: max(20px, env(safe-area-inset-bottom, 0px)) !important;
        }
    }
}

/* =============================================================================
   7. LANDSCAPE MOBILE
   ============================================================================= */

@media (max-height: 500px) and (orientation: landscape) and (max-width: 900px) {
    .mb-8.relative .grid.grid-cols-3 > div,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div {
        min-height: 55px !important;
        padding: 0.25rem 0.125rem !important;
    }

    .mb-8.relative .grid.grid-cols-3 > div > div:first-child,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div > div:first-child {
        width: 26px !important;
        height: 26px !important;
        min-width: 26px !important;
        font-size: 0.625rem !important;
    }

    .mb-8.relative .grid.grid-cols-3 > div .mt-2.inline-flex,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div .mt-2.inline-flex {
        display: none !important;
    }

    .fab-salvar-mobile {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        bottom: 0.5rem !important;
        right: 0.5rem !important;
    }
}

/* =============================================================================
   8. ESPACAMENTO PARA BOTTOM NAVIGATION
   Garante que o conteudo nao fique escondido atras da navegacao inferior
   Bottom nav altura: ~64px + safe-area
   ============================================================================= */

@media (max-width: 639px) {

    /* Container principal do formulario - padding inferior para bottom nav */
    .animate-fadeIn,
    div[x-data*="formController"],
    div[x-show="isReady"] {
        padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)) !important;
    }

    /* Form principal */
    #formulario-principal {
        margin-bottom: 1rem !important;
    }

    /* Card Pronto para salvar - margem inferior adequada */
    #formulario-principal > .shadow-lg {
        margin-bottom: 0.5rem !important;
    }

    /* Wizard container - margem inferior */
    .mb-8.relative {
        margin-bottom: 1rem !important;
    }

    /* Container de campos - padding adequado */
    #formulario-principal > .rounded-xl.shadow-sm {
        margin-bottom: 0.75rem !important;
    }

    /* Tabelas dentro de cards — scroll horizontal no mobile */
    .spotlight-card table,
    .form-content-card table,
    .rounded-xl table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
}

/* =============================================================================
   9. ANIMACOES REDUZIDAS (Acessibilidade)
   ============================================================================= */

@media (prefers-reduced-motion: reduce) {
    .mb-8.relative .grid.grid-cols-3 > div,
    .mb-8.relative .grid.grid-cols-3.gap-3 > div,
    .mb-8.relative .grid.grid-cols-3 > div > div:first-child,
    .fab-salvar-mobile {
        transition: none !important;
        transform: none !important;
    }
}

/* =============================================================================
   10. BOTTOM NAVIGATION - Nota
   ============================================================================= */

/* NOTA: Footer/Bottom Navigation Mobile agora e um componente independente:
   project/templates/componentes/footer_mobile.html

   O componente tem CSS 100% encapsulado (scoped), portanto NAO precisa
   de regras de estilo neste arquivo.

   ID do componente: #footer-mobile-component
*/

/* =============================================================================
   FIM DO ARQUIVO - v5.0
   ============================================================================= */
