/* ============================================================
   KM Skin v1 · modernização visual do painel
   Camada carregada DEPOIS do bundle compilado do tema: nada aqui
   toca no app.css nem nos blades das telas. Regras de COR ficam
   escopadas fora do modo escuro (html:not(.theme-dark)); regras
   estruturais (rolagem, espaçamento, raio) valem sempre.
   ============================================================ */

:root {
    --km-border: #e4e9e7;
    --km-bg: #f4f6f5;
    --km-mut: #6b7280;
    --km-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .07);
}

/* ---------- base ---------- */
body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif !important;
    -webkit-font-smoothing: antialiased;
}

/* a página nunca rola de lado; quem rola é o contêiner da tabela */
main {
    overflow-x: hidden;
}

/* o conteúdo vive num grid; sem isto a largura mínima de uma tabela
   larga propaga (min-width:auto) e estoura a página no celular */
main .container.grid {
    grid-template-columns: minmax(0, 1fr);
}

main .container.grid > * {
    min-width: 0;
    max-width: 100%;
}

html:not(.theme-dark) .bg-gray-50 {
    background-color: var(--km-bg) !important;
}

/* barras de rolagem finas em tudo */
* {
    scrollbar-width: thin;
    scrollbar-color: #c6cfcb transparent;
}

*::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

*::-webkit-scrollbar-thumb {
    background: #c6cfcb;
    border-radius: 8px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

/* ---------- cartões ---------- */
.rounded-lg {
    border-radius: 12px !important;
}

.rounded-md {
    border-radius: 8px !important;
}

html:not(.theme-dark) .shadow,
html:not(.theme-dark) .shadow-md {
    box-shadow: var(--km-shadow) !important;
}

html:not(.theme-dark) .border {
    border-color: var(--km-border) !important;
}

/* ---------- cabeçalho ---------- */
html:not(.theme-dark) header.shadow-md {
    box-shadow: none !important;
    border-bottom: 1px solid var(--km-border);
}

html:not(.theme-dark) header input[type=text] {
    background: #f3f6f4 !important;
    border: 1px solid transparent !important;
    border-radius: 9999px !important;
    transition: background .15s, border-color .15s, box-shadow .15s;
}

html:not(.theme-dark) header input[type=text]:focus {
    background: #fff !important;
    border-color: #86efac !important;
    box-shadow: 0 0 0 3px rgba(22, 163, 74, .12) !important;
}

/* ---------- shell v5: sidebar clara (linguagem Grok/Cloudflare) ----------
   A marca sai da parede e fica no tile do logo + botões primários.
   Tudo por cima da estrutura existente: nenhum blade muda. */

aside[class*="bg-primary-500"] {
    background: #ffffff !important;
    border-right: 1px solid var(--km-border);
}

/* o logo é o ÚNICO lugar da lateral com a marca cheia */
aside > div > a:first-child {
    background: #17402c;
    border-radius: 12px;
    margin: 12px 12px 8px 12px !important;
    padding: 10px 12px;
}

aside > div > a:first-child img {
    width: 40px !important;
    height: 40px !important;
}

/* itens: texto cinza, hover suave, ativo com acento verde */
aside li.relative {
    padding: 2px 10px !important;
    transition: none;
}

aside li.relative > a {
    color: #374151 !important;
    font-weight: 500 !important;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 13.5px !important;
}

aside li.relative > a:hover {
    background: #f3f4f6;
    color: #111827 !important;
}

/* a barrinha branca de ativo vira acento verde... */
aside li.relative > span[aria-hidden] {
    background: #16a34a !important;
    width: 3px !important;
    border-radius: 0 4px 4px 0;
}

/* ...e o item ativo ganha fundo e peso */
aside li.relative:has(> span[aria-hidden]) > a {
    background: #e9f4ee;
    color: #14532d !important;
    font-weight: 700 !important;
}

/* grupos (título clicável) */
aside p.cursor-pointer {
    color: #374151 !important;
    padding: 8px 10px !important;
    margin: 2px 10px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 500;
}

aside p.cursor-pointer:hover {
    background: #f3f4f6;
    color: #111827 !important;
}

/* o bloco do submenu (era verde-escuro) vira painel cinza claro */
aside div[class*="bg-primary-800"] {
    background: #f8faf9 !important;
    border-radius: 10px;
    margin: 0 10px 4px 10px;
    padding: 2px 0;
}

aside div[class*="bg-primary-800"] li.relative {
    padding: 1px 6px !important;
}

/* rótulos de seção: minúsculos e discretos, como nas referências */
aside p[class*="tracking-widest"] {
    color: #9ca3af !important;
    padding-left: 22px;
    margin-top: 18px !important;
}

/* divisores antigos */
aside hr {
    border-color: var(--km-border) !important;
    margin: 6px 16px;
}

aside {
    scrollbar-width: thin;
    scrollbar-color: #d6dedb transparent;
}

/* ---------- header claro e compacto ---------- */
header.shadow-md {
    padding-top: 6px !important;
    padding-bottom: 6px !important;
}

header .container {
    color: #4b5563 !important;
}

header .container p {
    font-size: 14px;
}

/* ---------- datatable: o contêiner rola, a página não ---------- */
div.align-middle.min-w-full {
    overflow-x: auto !important;
    border: 1px solid var(--km-border);
    border-radius: 12px !important;
    -webkit-overflow-scrolling: touch;
}

html:not(.theme-dark) div.align-middle.min-w-full {
    background: #fff;
    box-shadow: var(--km-shadow) !important;
}

/* cabeçalho da tabela: menor, sem gritar */
table thead th {
    padding: 10px 14px !important;
    font-size: 11px !important;
    letter-spacing: .05em;
    white-space: nowrap;
}

html:not(.theme-dark) table thead th {
    background: #f8faf9 !important;
    color: var(--km-mut) !important;
    border-bottom: 1px solid var(--km-border);
}

/* células: densidade de ferramenta de trabalho */
table tbody td {
    padding: 8px 14px !important;
    font-size: 13px !important;
}

html:not(.theme-dark) table tbody tr {
    transition: background .1s;
}

html:not(.theme-dark) table tbody tr:hover {
    background: #f4faf6 !important;
}

/* ---------- botões de ação nas linhas: chips suaves ---------- */
td .flex.items-center.p-2 {
    padding: 6px !important;
    border-radius: 8px !important;
}

html:not(.theme-dark) td [class*="bg-green-600"] {
    background: #dcfce7 !important;
    color: #15803d !important;
}

html:not(.theme-dark) td [class*="bg-red-600"] {
    background: #fee2e2 !important;
    color: #b91c1c !important;
}

html:not(.theme-dark) td [class*="bg-blue-600"] {
    background: #dbeafe !important;
    color: #1d4ed8 !important;
}

html:not(.theme-dark) td [class*="bg-yellow-500"],
html:not(.theme-dark) td [class*="bg-yellow-600"] {
    background: #fef3c7 !important;
    color: #92400e !important;
}

html:not(.theme-dark) td [class*="bg-gray-700"],
html:not(.theme-dark) td [class*="bg-gray-800"],
html:not(.theme-dark) td [class*="bg-gray-900"],
html:not(.theme-dark) td [class*="bg-black"] {
    background: #eef2f1 !important;
    color: #374151 !important;
}

html:not(.theme-dark) td [class*="bg-primary-500"],
html:not(.theme-dark) td [class*="bg-primary-600"],
html:not(.theme-dark) td [class*="bg-primary-700"] {
    background: #e3efe7 !important;
    color: #14532d !important;
}

/* chips de estado nas linhas (Online/Offline/etc.): tinta suave no
   lugar do sólido berrante, mantendo a cor como significado */
html:not(.theme-dark) td span[class*="bg-red-500"],
html:not(.theme-dark) td span[class*="bg-red-400"] {
    background: #fee2e2 !important;
    color: #b91c1c !important;
}

html:not(.theme-dark) td span[class*="bg-green-500"] {
    background: #dcfce7 !important;
    color: #15803d !important;
}

html:not(.theme-dark) td span[class*="bg-blue-500"] {
    background: #dbeafe !important;
    color: #1d4ed8 !important;
}

html:not(.theme-dark) td span[class*="bg-yellow-400"],
html:not(.theme-dark) td span[class*="bg-orange-500"] {
    background: #fef3c7 !important;
    color: #92400e !important;
}

/* contadores das filas (Precisa de você): branco sobre amarelo-500
   não tem contraste; âmbar escuro resolve sem mudar o significado */
a span.rounded-full.text-white[class*="bg-yellow-500"] {
    background: #d97706 !important;
}

/* ---------- formulários ---------- */
html:not(.theme-dark) input:not([type=checkbox]):not([type=radio]),
html:not(.theme-dark) select,
html:not(.theme-dark) textarea {
    border-radius: 10px !important;
    border-color: #d7dedb !important;
    font-size: 14px;
}

html:not(.theme-dark) input:not([type=checkbox]):not([type=radio]):focus,
html:not(.theme-dark) select:focus,
html:not(.theme-dark) textarea:focus {
    border-color: #4ade80 !important;
    box-shadow: 0 0 0 3px rgba(22, 163, 74, .12) !important;
    outline: none;
}

/* ---------- v6: o CONTEÚDO na mesma língua do shell ---------- */

/* título de página: menor e mais firme, como nos consoles de referência */
main .text-2xl {
    font-size: 20px !important;
    font-weight: 700 !important;
    letter-spacing: -.01em;
    color: #111827;
}

/* botão primário do conteúdo (Novo, salvar, enviar): verde vivo, cantos
   suaves, sombra leve; a marca aparece AQUI, não na parede */
main a[class*="bg-primary-6"]:not(table *),
main button[class*="bg-primary-6"]:not(table *),
main a[class*="bg-primary-5"]:not(table *),
main button[class*="bg-primary-5"]:not(table *) {
    background: #15803d !important;
    border-radius: 10px !important;
    border: 0 !important;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .10);
}

main a[class*="bg-primary-6"]:not(table *):hover,
main button[class*="bg-primary-6"]:not(table *):hover,
main a[class*="bg-primary-5"]:not(table *):hover,
main button[class*="bg-primary-5"]:not(table *):hover {
    background: #166534 !important;
}

/* cartões pastel de estatística viram cartões brancos: a cor fica no
   número e no ícone, não no fundo (linguagem Grok/Cloudflare) */
html:not(.theme-dark) main div[class*="bg-blue-100"],
html:not(.theme-dark) main div[class*="bg-green-100"],
html:not(.theme-dark) main div[class*="bg-yellow-100"],
html:not(.theme-dark) main div[class*="bg-orange-100"],
html:not(.theme-dark) main div[class*="bg-teal-100"],
html:not(.theme-dark) main div[class*="bg-gray-100"],
html:not(.theme-dark) main div[class*="bg-gray-200"] {
    background: #ffffff !important;
    border: 1px solid var(--km-border);
    box-shadow: var(--km-shadow);
}

/* tabelas: zebra fora; linhas brancas com fio de cabelo e hover */
html:not(.theme-dark) tbody tr[class*="bg-gray-50"] {
    background: #ffffff !important;
}

html:not(.theme-dark) table thead th {
    background: #ffffff !important;
}

/* toolbar do datatable (busca/filtros/colunas/por página): alinhada */
[wire\:id] div[class*="md:justify-between"] input,
[wire\:id] div[class*="md:justify-between"] select,
[wire\:id] div[class*="md:justify-between"] button {
    min-height: 38px;
    border-radius: 10px !important;
    font-size: 13px;
}

/* formulários das telas de configuração */
main label {
    font-size: 12.5px;
    color: #4b5563;
}

main hr {
    border-color: var(--km-border) !important;
}

/* ---------- atendimento no conceito WhatsApp ----------
   A página não rola: o diálogo é o principal e rola sozinho. */
.km-chat-wrap {
    position: relative;
    display: flex;
    height: calc(100vh - 112px);
    min-height: 480px;
    margin-top: 12px;
    background: #fff;
    border: 1px solid var(--km-border);
    border-radius: 14px;
    overflow: hidden;
}

.km-chat-list {
    width: 320px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--km-border);
    min-height: 0;
}

.km-chat-list-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.km-chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: #efeae2;
}

.km-chat-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: #f8faf9;
    border-bottom: 1px solid var(--km-border);
}

.km-chat-scroll {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    padding: 16px 8%;
    display: flex;
    flex-direction: column;
}

/* bolhas */
.km-bolha {
    max-width: 72%;
    border-radius: 10px;
    padding: 6px 10px 4px 10px;
    margin-bottom: 6px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, .08);
}

.km-bolha-user {
    background: #fff;
    align-self: flex-start;
    border-top-left-radius: 2px;
}

.km-bolha-ia {
    background: #e7f0fa;
    align-self: flex-start;
    border-top-left-radius: 2px;
}

.km-bolha-op {
    background: #d9fdd3;
    align-self: flex-end;
    border-top-right-radius: 2px;
}

.km-bolha-interna {
    background: #fef9c3;
    align-self: flex-end;
    border: 1px dashed #f59e0b;
    box-shadow: none;
}

.km-bolha-sys {
    align-self: center;
    background: #fff;
    border: 1px solid var(--km-border);
    border-radius: 9999px;
    padding: 3px 14px;
    margin: 4px 0 10px 0;
    font-size: 11px;
    color: #6b7280;
    max-width: 88%;
    text-align: center;
}

.km-hora {
    font-size: 10px;
    color: #9ca3af;
    text-align: right;
    margin-top: 1px;
}

/* compositor */
.km-chat-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 12px;
    background: #f0f2f5;
    border-top: 1px solid var(--km-border);
}

.km-enviar {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 9999px;
    background: #15803d;
    color: #fff;
    font-size: 15px;
    cursor: pointer;
}

.km-enviar:hover {
    background: #166534;
}

.km-icone {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 9999px;
    background: transparent;
    color: #6b7280;
    font-size: 15px;
    cursor: pointer;
}

.km-icone:hover {
    background: rgba(0, 0, 0, .06);
}

.km-avatar {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 9999px;
    font-weight: 700;
    font-size: 15px;
}

/* SLA estourado pulsa: impossível ignorar */
@keyframes km-pulsar {
    0%, 100% { opacity: 1; }
    50% { opacity: .45; }
}

.km-pulse {
    animation: km-pulsar 1.1s ease-in-out infinite;
}

.km-pontinho {
    flex-shrink: 0;
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 9999px;
}

.km-chat-info {
    width: 300px;
    flex-shrink: 0;
    border-left: 1px solid var(--km-border);
    background: #fff;
    overflow-y: auto;
    min-height: 0;
}

.km-so-mobile {
    display: none;
}

@media (max-width: 1023px) {
    .km-chat-wrap {
        height: calc(100vh - 96px);
    }

    .km-chat-list {
        width: 100%;
        border-right: 0;
    }

    .km-some-mobile {
        display: none !important;
    }

    .km-so-mobile {
        display: block;
    }

    .km-chat-info {
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        z-index: 30;
        box-shadow: -8px 0 24px rgba(16, 24, 40, .15);
    }

    .km-chat-scroll {
        padding: 12px 12px;
    }
}

/* ---------- autenticação (login, recuperar senha, registro) ---------- */
.min-h-screen form button[type=submit] {
    background: #15803d !important;
    border-radius: 10px !important;
    border: 0 !important;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .10);
}

.min-h-screen form button[type=submit]:hover {
    background: #166534 !important;
}

.min-h-screen .shadow-xl {
    box-shadow: 0 8px 30px rgba(16, 24, 40, .10) !important;
    border: 1px solid var(--km-border);
    border-radius: 16px !important;
}

/* cartões de conta demo: cartão branco no lugar do pastel forte */
html:not(.theme-dark) .min-h-screen div[class*="bg-red-100"],
html:not(.theme-dark) .min-h-screen div[class*="bg-purple-100"],
html:not(.theme-dark) .min-h-screen div[class*="bg-green-100"] {
    background: #ffffff !important;
    border: 1px solid var(--km-border);
}

/* ---------- widgets arrastáveis do dashboard ---------- */
.km-widget {
    position: relative;
}

/* a alça aparece no hover, no canto do widget */
.km-grip {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--km-border);
    color: #9ca3af;
    cursor: grab;
    opacity: 0;
    transition: opacity .12s;
    box-shadow: var(--km-shadow);
}

.km-widget:hover .km-grip {
    opacity: 1;
}

.km-grip:active {
    cursor: grabbing;
}

/* fantasma do arrasto (SortableJS) */
.sortable-ghost {
    opacity: .35;
}

.sortable-ghost .km-grip {
    opacity: 1;
}

/* no toque (celular) a alça fica sempre visível */
@media (hover: none) {
    .km-grip {
        opacity: .8;
    }
}

/* ---------- células clipadas + popover de cópia (skin.js) ---------- */
.km-clip {
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
}

.km-clip:hover {
    text-decoration: underline dotted;
    text-underline-offset: 3px;
}

.km-popover {
    position: fixed;
    z-index: 9999;
    max-width: 340px;
    background: #111827;
    color: #f9fafb;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    box-shadow: 0 8px 24px rgba(16, 24, 40, .25);
    display: flex;
    align-items: center;
    gap: 10px;
}

.km-popover-texto {
    word-break: break-all;
    line-height: 1.35;
}

.km-popover-copiar {
    flex-shrink: 0;
    background: #16a34a;
    color: #fff;
    border: 0;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
}

.km-popover-copiar:hover {
    background: #15803d;
}

/* ---------- modais: respiro e cantos consistentes ---------- */
html:not(.theme-dark) .fixed.inset-0 .bg-white.rounded-lg,
html:not(.theme-dark) .fixed.inset-0 .bg-white.rounded-md,
html:not(.theme-dark) .fixed.inset-0 .bg-white.rounded {
    border-radius: 14px !important;
    box-shadow: 0 12px 40px rgba(16, 24, 40, .18) !important;
}

.fixed.inset-0 .bg-white .grid.grid-cols-2 {
    gap: 10px 16px;
}

/* linhas rótulo/valor (subtotal, total etc.) dentro de modais e
   painéis de resumo: alinhamento e respiro uniformes */
.fixed.inset-0 .flex.justify-between,
.fixed.inset-0 .flex.items-center.justify-between {
    padding-top: 4px;
    padding-bottom: 4px;
}

/* ---------- celular ---------- */
@media (max-width: 767px) {

    /* barra de busca/filtros do datatable empilha sem estourar */
    [wire\:id] .p-6 {
        padding: 12px !important;
    }

    [wire\:id] input,
    [wire\:id] select,
    [wire\:id] button {
        max-width: 100%;
    }

    /* títulos um degrau menores */
    main .text-2xl {
        font-size: 20px !important;
    }

    /* filas com contador: o número não escapa do cartão */
    a.flex.items-center.justify-between > span:first-child {
        min-width: 0;
    }

    a.flex.items-center.justify-between > span:last-child {
        flex-shrink: 0;
        margin-left: 8px;
    }
}
