/* UI-2 — hierarquia operacional da página Soluções.
   Este arquivo complementa a fundação visual da UI-1 sem alterar lógica. */

/* -------------------------------------------------------------------------- */
/* Contexto ativo                                                             */
/* -------------------------------------------------------------------------- */
#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] {
    position: relative;
    padding-top: 2.2rem !important;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo']::before {
    position: absolute;
    top: 0.7rem;
    left: 1rem;
    color: var(--cp-muted);
    content: 'CONTEXTO ATIVO';
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] > .grid {
    gap: 0.75rem !important;
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] label {
    margin-bottom: 0.3rem !important;
    color: var(--cp-muted) !important;
    font-size: 0.72rem !important;
    font-weight: 700 !important;
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] select {
    min-height: 2.35rem;
    padding-top: 0.45rem !important;
    padding-bottom: 0.45rem !important;
    font-weight: 600;
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] p {
    margin-top: 0.45rem !important;
    opacity: 0.86;
}

/* -------------------------------------------------------------------------- */
/* Cabeçalho e grid da página Soluções                                        */
/* -------------------------------------------------------------------------- */
#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) {
    width: min(100%, 90rem);
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > h2 {
    margin-bottom: 0 !important;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > h2::after {
    display: block;
    margin-top: 0.28rem;
    color: var(--cp-muted);
    content: 'Operações disponíveis para o cliente e a conta selecionados.';
    font-family: var(--cp-font-body);
    font-size: 0.84rem;
    font-weight: 500;
    letter-spacing: 0;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > h2 + p {
    margin: 0.75rem 0 1rem !important;
    border-left: 2px solid var(--cp-border-strong);
    padding-left: 0.65rem;
    color: var(--cp-muted) !important;
    font-size: 0.72rem !important;
    line-height: 1.45;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 1rem !important;
    align-items: start;
}

/* -------------------------------------------------------------------------- */
/* Cards de solução                                                           */
/* -------------------------------------------------------------------------- */
#app > .cp-topbar + div > main article[data-solution-id] {
    min-width: 0;
    max-width: none !important;
    padding: 1.1rem !important;
    overflow: hidden;
}

#app > .cp-topbar + div > main article[data-solution-id] > .flex.justify-between {
    align-items: flex-start;
    gap: 0.75rem !important;
    padding-bottom: 0.7rem;
    border-bottom: 1px solid var(--cp-border);
}

#app > .cp-topbar + div > main article[data-solution-id] > .flex.justify-between h3 {
    margin-top: 0.2rem !important;
    font-size: 1.05rem !important;
    line-height: 1.3;
}

#app > .cp-topbar + div > main article[data-solution-id] > .flex.justify-between p {
    color: var(--cp-primary) !important;
    font-size: 0.66rem !important;
    letter-spacing: 0.07em;
}

#app > .cp-topbar + div > main article[data-solution-id] > p.mt-4 {
    margin-top: 0.75rem !important;
    color: var(--cp-text-soft) !important;
    font-size: 0.84rem;
    line-height: 1.5;
}

#app > .cp-topbar + div > main article[data-solution-id] > p.mt-3.text-sm {
    margin-top: 0.55rem !important;
    color: var(--cp-muted) !important;
    font-size: 0.7rem !important;
}

/* Disponível: superfície normal com uma ênfase estrutural discreta. */
#app > .cp-topbar + div > main article[data-solution-id]:has(> .flex span.bg-green-100) {
    border-top: 2px solid #86efac !important;
}

/* Em execução: ênfase informativa sem alterar comportamento. */
#app > .cp-topbar + div > main article[data-solution-id]:has(> .flex span.bg-blue-100) {
    border-top: 2px solid #93c5fd !important;
}

/* Módulos futuros/bloqueados: continuam legíveis, porém com menor peso visual. */
#app > .cp-topbar + div > main article[data-solution-id]:not([data-solution-id='alert-migrator']):has(> .flex span.bg-amber-100),
#app > .cp-topbar + div > main article[data-solution-id]:not([data-solution-id='alert-migrator']):has(> .flex span.bg-gray-100) {
    background: var(--cp-surface-muted) !important;
    border-color: var(--cp-border) !important;
    box-shadow: none !important;
}

#app > .cp-topbar + div > main article[data-solution-id]:not([data-solution-id='alert-migrator']):has(> .flex span.bg-amber-100) > p,
#app > .cp-topbar + div > main article[data-solution-id]:not([data-solution-id='alert-migrator']):has(> .flex span.bg-gray-100) > p {
    color: var(--cp-muted) !important;
}

/* CTAs indisponíveis deixam de dominar o card. */
#app > .cp-topbar + div > main article[data-solution-id]:not([data-solution-id='alert-migrator']):has(> .flex span.bg-amber-100) > button:disabled,
#app > .cp-topbar + div > main article[data-solution-id]:not([data-solution-id='alert-migrator']):has(> .flex span.bg-gray-100) > button:disabled {
    width: auto !important;
    min-width: 11rem;
    margin-top: 0.85rem !important;
    border: 1px solid var(--cp-border) !important;
    background: #eef2f7 !important;
    padding: 0.5rem 0.8rem !important;
    color: var(--cp-muted) !important;
    font-size: 0.75rem !important;
    box-shadow: none !important;
}

/* -------------------------------------------------------------------------- */
/* Inventário                                                                 */
/* -------------------------------------------------------------------------- */
#app > .cp-topbar + div > main article[data-solution-id='inventory'] fieldset {
    margin-top: 0.9rem !important;
}

#app > .cp-topbar + div > main article[data-solution-id='inventory'] fieldset legend {
    color: var(--cp-text-soft) !important;
    font-size: 0.72rem !important;
}

#app > .cp-topbar + div > main article[data-solution-id='inventory'] fieldset label {
    border-color: var(--cp-border) !important;
    background: var(--cp-surface-muted);
    padding: 0.42rem 0.62rem !important;
    font-size: 0.76rem !important;
}

#app > .cp-topbar + div > main article[data-solution-id='inventory'] > div.mt-4.rounded-lg.border {
    margin-top: 0.8rem !important;
    border-color: var(--cp-border) !important;
    background: var(--cp-surface-muted) !important;
    padding: 0.75rem 0.85rem !important;
}

#app > .cp-topbar + div > main article[data-solution-id='inventory'] #run-inventory {
    margin-top: 0.9rem !important;
    min-height: 2.55rem;
}

/* -------------------------------------------------------------------------- */
/* Migração de alertas                                                        */
/* -------------------------------------------------------------------------- */
#app > .cp-topbar + div > main article[data-solution-id='alert-migrator'] {
    grid-column: 1 / -1;
    padding: 1.2rem !important;
}

#app > .cp-topbar + div > main article[data-solution-id='alert-migrator'] > .flex.justify-between {
    padding-bottom: 0.8rem;
}

#app > .cp-topbar + div > main article[data-solution-id='alert-migrator'] > p.mt-4 {
    margin-top: 0.75rem !important;
}

/* Não interfere na lista, tabelas, seleção ou stepper internos. */
#app > .cp-topbar + div > main article[data-solution-id='alert-migrator'] ol,
#app > .cp-topbar + div > main article[data-solution-id='alert-migrator'] table,
#app > .cp-topbar + div > main article[data-solution-id='alert-migrator'] [data-alarm-name] {
    max-width: none;
}

/* -------------------------------------------------------------------------- */
/* Desktop: duas colunas para módulos compactos, migração sempre ampla.        */
/* -------------------------------------------------------------------------- */
@media (min-width: 1100px) {
    #app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #app > .cp-topbar + div > main article[data-solution-id='alert-migrator'] {
        grid-column: 1 / -1;
    }
}

@media (max-width: 767px) {
    #app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] {
        padding-top: 2rem !important;
    }

    #app > .cp-topbar + div > main article[data-solution-id] {
        padding: 0.95rem !important;
    }

    #app > .cp-topbar + div > main article[data-solution-id]:not([data-solution-id='alert-migrator']):has(> .flex span.bg-amber-100) > button:disabled,
    #app > .cp-topbar + div > main article[data-solution-id]:not([data-solution-id='alert-migrator']):has(> .flex span.bg-gray-100) > button:disabled {
        width: 100% !important;
    }
}


/* -------------------------------------------------------------------------- */
/* UI-2.1 — contexto operacional fixo + hierarquia final dos módulos          */
/* -------------------------------------------------------------------------- */

/* Cliente + Conta AWS passam a funcionar como contexto global persistente. */
#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] {
    position: sticky;
    top: 4rem;
    z-index: 35;
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: center;
    gap: 0.9rem;
    margin-bottom: 1.15rem !important;
    padding: 0.65rem 0.85rem !important;
    border-radius: 0 0 var(--cp-radius-md) var(--cp-radius-md) !important;
    background: rgb(255 255 255 / 0.97) !important;
    box-shadow: 0 8px 18px rgb(15 23 42 / 0.06) !important;
    backdrop-filter: blur(10px);
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo']::before {
    position: static;
    align-self: center;
    color: var(--cp-muted);
    content: 'CONTEXTO ATIVO';
    font-size: 0.66rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] > .grid {
    display: grid !important;
    grid-template-columns: minmax(12rem, 0.8fr) minmax(18rem, 1.2fr) !important;
    align-items: end;
    gap: 0.75rem !important;
    min-width: 0;
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] label {
    margin-bottom: 0.2rem !important;
    font-size: 0.66rem !important;
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] select {
    min-height: 2.15rem;
    padding-top: 0.35rem !important;
    padding-bottom: 0.35rem !important;
    font-size: 0.8rem;
}

#app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] > p {
    display: none;
}

/* Ordem visual por utilidade atual: operações primeiro, futuras depois. */
#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id='inventory'] {
    order: 1;
    grid-column: 1 / -1;
    position: relative;
    margin-top: 1.7rem;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id='alert-migrator'] {
    order: 2;
    grid-column: 1 / -1;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id]:not([data-solution-id='inventory']):not([data-solution-id='alert-migrator']) {
    order: 3;
}

/* Rótulos visuais de seção sem alterar IDs, listeners ou catálogo. */
#app > .cp-topbar + div > main article[data-solution-id='inventory']::before {
    position: absolute;
    top: -1.35rem;
    left: 0;
    color: var(--cp-muted);
    content: 'OPERAÇÕES DISPONÍVEIS';
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article:nth-child(2):not([data-solution-id='alert-migrator']) {
    position: relative;
    margin-top: 1.7rem;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article:nth-child(2):not([data-solution-id='alert-migrator'])::before {
    position: absolute;
    top: -1.35rem;
    left: 0;
    color: var(--cp-muted);
    content: 'EM DESENVOLVIMENTO';
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

/* Inventário e migração usam a largura operacional total. */
#app > .cp-topbar + div > main article[data-solution-id='inventory'],
#app > .cp-topbar + div > main article[data-solution-id='alert-migrator'] {
    width: 100%;
}

/* Cards futuros ficam pareados, compactos e alinhados no desktop. */
@media (min-width: 1100px) {
    #app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id='inventory'],
    #app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id='alert-migrator'] {
        grid-column: 1 / -1;
    }

    #app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id]:not([data-solution-id='inventory']):not([data-solution-id='alert-migrator']) {
        height: 100%;
    }
}

@media (max-width: 900px) {
    #app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] {
        grid-template-columns: 1fr;
        gap: 0.45rem;
        padding: 0.65rem 0.75rem !important;
    }

    #app > .cp-topbar + div > main > section[aria-label='Contexto ativo']::before {
        display: block;
    }

    #app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] > .grid {
        grid-template-columns: 1fr !important;
    }
}

@media (max-width: 767px) {
    #app > .cp-topbar + div > main > section[aria-label='Contexto ativo'] {
        top: 4rem;
        border-radius: 0 0 var(--cp-radius-sm) var(--cp-radius-sm) !important;
    }

    #app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id='inventory'],
    #app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id='alert-migrator'],
    #app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id]:not([data-solution-id='inventory']):not([data-solution-id='alert-migrator']) {
        grid-column: 1 / -1;
    }
}


/* -------------------------------------------------------------------------- */
/* UI-2.2 — fechamento visual da hierarquia de Soluções                       */
/* -------------------------------------------------------------------------- */

/* Os rótulos de seção pertencem ao grid, não aos cards. Assim não são
   recortados pelo overflow dos módulos e a separação continua puramente visual. */
#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid::before,
#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid::after {
    grid-column: 1 / -1;
    color: var(--cp-muted);
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    line-height: 1;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid::before {
    order: 0;
    content: 'OPERAÇÕES DISPONÍVEIS';
    margin-bottom: -0.2rem;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid::after {
    order: 3;
    content: 'EM DESENVOLVIMENTO';
    margin-top: 0.45rem;
    margin-bottom: -0.15rem;
}

/* Remove a primeira tentativa de rótulos posicionados acima dos cards. */
#app > .cp-topbar + div > main article[data-solution-id='inventory']::before,
#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article:nth-child(2):not([data-solution-id='alert-migrator'])::before {
    content: none !important;
}

/* Ordem final: rótulo → operações atuais → rótulo → capacidades futuras. */
#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id='inventory'] {
    order: 1;
    margin-top: 0 !important;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id='alert-migrator'] {
    order: 2;
}

#app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id]:not([data-solution-id='inventory']):not([data-solution-id='alert-migrator']) {
    order: 4;
    margin-top: 0 !important;
    align-self: stretch;
}

/* Grafana e Teste de carga começam exatamente na mesma linha no desktop. */
@media (min-width: 1100px) {
    #app > .cp-topbar + div > main > div:has(> .grid > article[data-solution-id]) > .grid > article[data-solution-id]:not([data-solution-id='inventory']):not([data-solution-id='alert-migrator']) {
        min-height: 100%;
    }
}
