@import url('https://fonts.googleapis.com/css2?family=Mona+Sans:wght@300;400;500;600;700&display=swap');

:root {
    /* Prestaí - Paleta Oficial */
    --color-primary:    #1547FF;
    --color-accent:     #70FF00;
    --color-alert:      #FF5807;
    --color-white:      #FFFFFF;
    --color-black:      #000000;
    --color-blue-60:    #8EA3FF;
    --color-blue-30:    #C6D0FF;
    --color-blue-15:    #E3E8FF;
    --color-green-60:   #A8FF66;
    --color-green-30:   #D3FFAD;
    --color-beige:      #F5F0E8;

    /* Tipografia oficial */
    --font-heading:     'Ryker', 'Inter', sans-serif;
    --font-body:        'Mona Sans', 'Inter', system-ui, -apple-system, sans-serif;

    /* Aliases semânticos (mapeados para nova paleta) */
    --primary: var(--color-primary);
    --primary-hover: #0F38D9;
    --bg-main: var(--color-white);
    --bg-sidebar: var(--color-beige);
    --bg-card: var(--color-white);

    --text-primary: var(--color-black);
    --text-secondary: #6B6B6B;
    --text-muted: #94A3B8;

    --border-subtle: var(--color-blue-15);
    --border-light: var(--color-blue-30);

    --success: #16A34A;
    --warning: var(--color-alert);
    --error: var(--color-alert);

    /* Shadows - Extremely Soft */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.03), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.04), 0 4px 6px -2px rgba(0, 0, 0, 0.02);

    /* Layout */
    --sidebar-width: 260px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    --transition: 150ms ease-in-out;
}

/* Base Resets */
*,
*::after,
*::before {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    font-family: var(--font-heading);
}

#app {
    min-height: 100vh;
    display: flex;
}

/* Hamburger (visível só em mobile) */
.hamburger-btn {
    display: none;
    position: fixed;
    top: 0.875rem;
    left: 0.875rem;
    z-index: 1100;
    background: white;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 0.5rem 0.625rem;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.10);
    align-items: center;
    justify-content: center;
}
.hamburger-btn:hover { background: #f8fafc; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    z-index: 998;
}
.sidebar-overlay.active { display: block; }

/* Sidebar Styling */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow-y: auto;
    position: fixed;
    left: 0;
    top: 0;
    padding: 1.5rem 1rem;
    z-index: 100;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    padding: 0 0.75rem clamp(0.5rem, 4vh, 2rem);
    flex-shrink: 0;
}

.sidebar-logo-full,
.sidebar-logo-icon {
    height: clamp(20px, 3.2vh, 28px);
    width: auto;
}

.sidebar-logo-icon {
    display: none;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: clamp(0.05rem, 0.5vh, 0.25rem);
    flex: 1;
    min-height: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: clamp(0.35rem, 1.1vh, 0.75rem) 0.75rem;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: clamp(0.75rem, 1.6vh, 0.875rem);
    font-weight: 500;
    text-decoration: none;
    transition: var(--transition);
    cursor: pointer;
    flex-shrink: 0;
}

.nav-item svg {
    width: clamp(16px, 2.4vh, 20px);
    height: clamp(16px, 2.4vh, 20px);
    flex-shrink: 0;
}

.nav-item:hover {
    background-color: #ECECED;
    color: var(--text-primary);
}

.nav-item.active {
    background-color: #FFFFFF;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.sidebar-footer {
    padding-top: clamp(0.35rem, 1vh, 1rem);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: clamp(0.35rem, 1vh, 0.75rem);
    margin-bottom: clamp(0.15rem, 0.5vh, 0.5rem);
}

.sidebar-avatar {
    width: clamp(24px, 3.6vh, 32px);
    height: clamp(24px, 3.6vh, 32px);
    background: var(--border-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

/* Main Content Area */
.main-content {
    flex: 1;
    /* Sem isso, um item flex nunca encolhe abaixo da largura mínima do
       próprio conteúdo (ex.: <select> com opção de texto longo) — em telas
       estreitas isso força .main-content a ficar mais largo que a viewport,
       cortando cards/filtros/subtítulo em vez de empilhar (bug reportado
       pelo cliente no iPhone: dashboard todo cortado à direita). */
    min-width: 0;
    margin-left: var(--sidebar-width);
    padding: 2.5rem 3rem;
    min-height: 100vh;
}

.content-header {
    margin-bottom: 2.5rem;
    /* Cada tela define display:flex/justify-content inline, mas nenhuma
       define flex-wrap — sem isso, título longo + badge/botão à direita
       empurram o conteúdo pra fora da viewport em telas menores em vez de
       quebrar linha (mesma causa do corte reportado no DetailsView). */
    flex-wrap: wrap;
    row-gap: 0.75rem;
}

h1 {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin-bottom: 0.5rem;
}

.page-subtitle {
    font-size: 16px;
    /* Ajustado para 16px conforme pedido: Subtítulos 18px ou standard text 14, usei um meio termo confortável */
    color: var(--text-secondary);
    font-weight: 400;
}

/* Typography Scale */
.h2 {
    font-size: 18px;
    font-weight: 600;
}

.text-sm {
    font-size: 14px;
}

.text-xs {
    font-size: 12px;
    color: var(--text-muted);
}

/* Common Components */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.125rem;
    border-radius: var(--radius-sm);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    gap: 0.5rem;
    border: 1px solid transparent;
}

.btn-primary {
    background-color: var(--primary);
    color: #FFFFFF;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: #FFFFFF;
    border-color: var(--border-light);
    color: var(--text-secondary);
}

.btn-secondary:hover {
    background-color: var(--bg-sidebar);
    color: var(--text-primary);
}

/* Metrics Grid - Enhanced */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.metric-card {
    padding: 2rem 1.5rem;
}

.metric-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

.metric-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}


/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="date"],
input[type="number"],
select,
textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    background-color: #FFFFFF;
    font-size: 14px;
    color: var(--text-primary);
    transition: var(--transition);
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(21, 71, 255, 0.1);
}

/* <select> nativo com <optgroup> (ex.: rubricas agrupadas por produto) —
   cabeçalho do grupo em negrito, opções normais e indentadas por padrão
   do navegador. */
optgroup { font-weight: 700; font-style: normal; color: var(--text-secondary); }
optgroup option { font-weight: 400; color: var(--text-primary); }

/* Status Badges - SaaS Style */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 12px;
    font-weight: 500;
    gap: 0.375rem;
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
}

.status-pending {
    background-color: var(--color-blue-30);
    color: var(--color-primary);
}

.status-completed {
    background-color: var(--color-primary);
    color: var(--color-accent);
}

.status-error {
    background-color: var(--color-alert);
    color: var(--color-white);
}

.status-pending .badge-dot {
    background-color: var(--warning);
}

.status-completed .badge-dot {
    background-color: var(--success);
}

.status-error .badge-dot {
    background-color: var(--error);
}

/* Tables - Clean & High Contrast */
.data-table-container {
    background: #FFFFFF;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.data-table th {
    padding: 0.75rem 1rem;
    background: var(--bg-sidebar);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 14px;
    color: var(--text-primary);
}

.data-table tr:last-child td {
    border-bottom: none;
}

/* Empty State */
.empty-state {
    padding: 4rem 2rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.empty-state-icon {
    width: 64px;
    height: 64px;
    background: var(--bg-sidebar);
    color: var(--text-muted);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 0.5rem;
}

/* Upload Area */
.upload-area {
    border: 2px dashed var(--border-light);
    background: var(--bg-sidebar);
    border-radius: var(--radius-lg);
    padding: 4rem;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.upload-area:hover {
    border-color: var(--primary);
    background: #FFFFFF;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.view-content {
    animation: fadeIn 200ms ease-out;
}

/* Redesenho da mesma tela (ex.: atualização da nota aberta): sem repetir a entrada. */
.view-content.sem-animacao {
    animation: none;
}

/* Redesign mobile do Dashboard (M1) — classes novas, inertes no desktop.
   O que cada uma vira em telas estreitas está no @media 768px logo abaixo. */
.dashboard-filtros-toggle {
    display: none;
}

.dashboard-filtros-painel {
    display: contents;
}

.doc-cards-mobile {
    display: none;
}

.doc-card-mobile {
    background: #FFFFFF;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 0.9rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.fab-enviar-nota {
    display: none;
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
    .sidebar {
        width: 80px;
        padding: 1.5rem 0.5rem;
    }

    .nav-item span {
        display: none;
    }

    .sidebar-logo-full {
        display: none;
    }

    .sidebar-logo-icon {
        display: block;
    }

    .main-content {
        margin-left: 80px;
        padding: 2rem;
    }
}

@media (max-width: 768px) {
    /* A página nunca rola na horizontal — conteúdo largo (tabelas) rola
       dentro do próprio container (.data-table-container / .glass-card). */
    html, body {
        overflow-x: hidden;
    }

    /* Tabelas: célula compacta e nomes longos quebram linha, encurtando a
       largura total; a última coluna (Ações) fica fixa na borda direita,
       sempre visível sem arrastar. */
    .data-table th,
    .data-table td {
        padding: 0.6rem;
    }

    .data-table td {
        max-width: 45vw;
        overflow-wrap: anywhere;
    }

    /* .m2-table/.inner-table/.solic-table/.edit-table/.hist-table/.history-table
       ficam de fora daqui — a partir de 900px (mais largo que este
       breakpoint, então sempre ativo junto) elas viram cartões empilhados
       (ver @media 900px), o que torna o sticky de última coluna redundante
       pra essas classes. */
    .data-table th:last-child, .data-table td:last-child {
        position: sticky;
        right: 0;
        background: #FFFFFF;
        box-shadow: -8px 0 8px -8px rgba(0, 0, 0, 0.18);
    }

    .data-table th:last-child {
        background: var(--bg-sidebar);
    }

    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4,0,0.2,1);
        width: var(--sidebar-width) !important;
        padding: 1.5rem 1rem !important;
        /* Acima do .sidebar-overlay (998) — senão a máscara cobre a própria
           sidebar aberta e qualquer toque a fecha. Abaixo do hamburger (1100)
           e dos modais (2000+). */
        z-index: 1000;
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
        box-shadow: 8px 0 40px rgba(0,0,0,0.18);
    }

    .nav-item span {
        display: inline !important;
    }

    .sidebar-logo-full {
        display: block !important;
    }

    .sidebar-logo-icon {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        /* Bottom maior que o padrão pra caber a FAB "Enviar nota" (Dashboard)
           sem cobrir o último item da lista — inofensivo nas demais telas. */
        padding: 4.5rem 1rem 5.5rem !important;
    }

    .hamburger-btn {
        display: flex !important;
    }

    /* Dashboard (M1) mobile — cards de métrica fixos em 2 colunas (nunca
       menos, mesmo quando os cards condicionais de aviso aparecem: eles só
       formam mais uma linha no grid). */
    .metrics-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
    }

    .metric-card {
        padding: 1.1rem 1rem;
    }

    .metric-value {
        font-size: 24px;
    }

    /* Filtros escondidos atrás do botão "Filtros", ao lado da busca. */
    .dashboard-filtros-toggle {
        display: inline-flex;
    }

    .dashboard-filtros-painel {
        display: none;
        flex-direction: column;
        width: 100%;
        gap: 0.75rem;
        margin-top: 0.25rem;
    }

    .dashboard-filtros-painel.is-open {
        display: flex;
    }

    /* Lista de notas vira cards; a tabela (mantida no DOM para o desktop)
       fica oculta. */
    .data-table-container table.data-table {
        display: none;
    }

    .doc-cards-mobile {
        display: grid;
        gap: 0.75rem;
    }

    #btn-enviar-nota-desktop {
        display: none;
    }

    .fab-enviar-nota {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        position: fixed;
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
        height: 52px;
        border: none;
        border-radius: var(--radius-md);
        background: var(--color-primary);
        color: #FFFFFF;
        font-weight: 600;
        font-size: 0.95rem;
        box-shadow: 0 8px 24px rgba(21, 71, 255, 0.3);
        z-index: 900;
        cursor: pointer;
    }
}

/* Entre 1024px (onde só a sidebar encolhe) e 768px (mobile) não havia
   proteção nenhuma: em notebook comum (1280–1366px) tabelas largas
   (contratos, despesas, evidências) estouram a área útil e a coluna de
   Ações sai da tela. Mesmo tratamento do breakpoint mobile — coluna de
   Ações fixa na borda direita — sem mexer no espaçamento das células. */
@media (max-width: 1400px) {
    /* Mesma garantia do breakpoint mobile: a página nunca rola na
       horizontal, conteúdo largo rola dentro do próprio container. */
    html, body {
        overflow-x: hidden;
    }

    .glass-card {
        overflow-x: auto;
    }

    /* .m2-table e .inner-table ficam de fora: usam border-collapse: separate
       (.m2-table) e o sticky em th/td simplesmente não gruda nesse caso —
       limitação do navegador, não bug de CSS. Essas duas usam a abordagem
       de caber-na-tela abaixo (ver @media 1500px / 1200px). */
    .data-table th:last-child, .data-table td:last-child,
    .solic-table th:last-child, .solic-table td:last-child,
    .edit-table th:last-child, .edit-table td:last-child,
    .hist-table th:last-child, .hist-table td:last-child,
    .history-table th:last-child, .history-table td:last-child {
        position: sticky;
        right: 0;
        background: #FFFFFF;
        box-shadow: -8px 0 8px -8px rgba(0, 0, 0, 0.18);
    }

    .data-table th:last-child,
    .solic-table th:last-child,
    .edit-table th:last-child,
    .hist-table th:last-child,
    .history-table th:last-child {
        background: var(--bg-sidebar);
    }
}

/* .contracts-table / .inner-table (tabelas de contratos.html — a segunda
   não é usada em mais nenhuma página, mas .m2-table sim, daí a classe extra
   pra não truncar/esconder colunas de outras tabelas que usam layout
   diferente): sticky não funciona nelas (ver acima), e a página não pode
   rolar na horizontal — a tabela precisa caber na largura da tela, não
   conviver com o estouro. Botões de ação viram ícone-só (texto em title=,
   .btn-label escondido) e as colunas de texto livre truncam com ellipsis em
   vez de quebrar em várias linhas e esticar a linha inteira. */
@media (max-width: 1500px) {
    .btn-inline .btn-label {
        display: none;
    }

    .btn-inline {
        padding: 0.4rem;
    }

    .contracts-table td, .inner-table td {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 160px;
    }

    .contracts-table td:nth-child(2) { max-width: 130px; } /* Nº */
    .contracts-table td:nth-child(4) { max-width: 180px; } /* Objeto */
}

/* Mesmo com o truncamento acima, 8 colunas ainda não cabem abaixo de
   1200px — Objeto é a candidata natural: o conteúdo completo já está no
   card expandido do contrato. */
@media (max-width: 1200px) {
    .contracts-table th:nth-child(4), .contracts-table td:nth-child(4) {
        display: none;
    }
}

/* Abaixo de 900px (tablet/celular), truncar colunas não resolve mais —
   viram cartões empilhados, um por linha, com rótulo (data-label de cada
   <td>) acima do valor. Cobre .m2-table/.inner-table/.solic-table/
   .edit-table/.hist-table/.history-table; .data-table (M1) mantém a coluna
   de Ações fixa (ver @media 768px).

   Label-ao-lado-do-valor (justify-content: space-between numa linha só)
   quebrava sempre que uma célula tinha mais de um filho direto (badge de
   status + botões de ação, por exemplo — comum em Status/Ações): o
   space-between distribui TODOS os itens da linha, não só label+valor,
   e os botões/ícones ficavam espalhados e cortados pela largura do
   cartão. Rótulo empilhado ACIMA do valor evita esse problema pra
   qualquer quantidade de filhos, sem precisar mexer no HTML de cada
   tabela — só a célula de Ações mantém os botões em linha (mais natural
   pra um grupo de botões). */
@media (max-width: 900px) {
    .m2-table, .inner-table, .solic-table, .edit-table, .hist-table, .history-table,
    .m2-table thead, .inner-table thead, .solic-table thead, .edit-table thead, .hist-table thead, .history-table thead,
    .m2-table tbody, .inner-table tbody, .solic-table tbody, .edit-table tbody, .hist-table tbody, .history-table tbody,
    .m2-table th, .inner-table th, .solic-table th, .edit-table th, .hist-table th, .history-table th,
    .m2-table td, .inner-table td, .solic-table td, .edit-table td, .hist-table td, .history-table td,
    .m2-table tr, .inner-table tr, .solic-table tr, .edit-table tr, .hist-table tr, .history-table tr {
        display: block;
    }

    /* Cabeçalho original escondido -- o rótulo vem do data-label em cada célula */
    .m2-table thead tr, .inner-table thead tr, .solic-table thead tr,
    .edit-table thead tr, .hist-table thead tr, .history-table thead tr {
        position: absolute;
        left: -9999px;
    }

    .m2-table tr, .inner-table tr, .solic-table tr, .edit-table tr, .hist-table tr, .history-table tr {
        border: 1px solid var(--border-light);
        border-radius: var(--radius-md);
        margin-bottom: 0.75rem;
        padding: 0.5rem 0;
        background: #FFFFFF;
    }

    .m2-table td, .inner-table td, .solic-table td, .edit-table td, .hist-table td, .history-table td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
        padding: 0.5rem 0.85rem;
        border: none;
        text-align: left;
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        max-width: none;
    }

    /* .contracts-table td:nth-child(2)/(4) (@media 1500px) trava max-width
       em 130/180px com especificidade maior que a regra acima — sem isso
       o cartão herdava esse limite e o valor (ex.: número do contrato)
       vinha cortado/espremido junto com o rótulo. */
    .contracts-table td:nth-child(2), .contracts-table td:nth-child(4) {
        max-width: none;
        overflow: visible;
        text-overflow: clip;
        white-space: normal;
    }

    .m2-table td::before, .inner-table td::before, .solic-table td::before,
    .edit-table td::before, .hist-table td::before, .history-table td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 0.75rem;
        color: var(--text-secondary);
        text-transform: uppercase;
    }

    /* Célula de ações não precisa repetir o rótulo, e os botões ficam em
       linha (não empilhados um por um), quebrando pra próxima linha se
       precisar. */
    .m2-table td[data-label="Ações"], .inner-table td[data-label="Ações"] {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: flex-end;
        align-items: center;
        width: 100%;
    }

    .m2-table td[data-label="Ações"]::before,
    .inner-table td[data-label="Ações"]::before {
        content: "";
    }

    /* Ícone-só (ver @media 1500px, .btn-inline .btn-label) só faz sentido
       quando falta espaço horizontal — em cartão sobra largura de sobra,
       e sem o texto visível (e sem hover em touch) o botão vira um ícone
       sem identificação nenhuma. */
    .btn-inline .btn-label {
        display: inline;
    }
}

/* Auth Screens */
.login-view {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f8fafc;
    padding: 2rem;
    min-height: 100vh;
}

.login-card {
    width: 100%;
    max-width: 420px;
    padding: 3rem !important;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-light);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    animation: fadeIn 300ms ease-out;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-weight: 700;
    color: var(--primary);
}

.login-footer {
    margin-top: 2rem;
    text-align: center;
    font-size: 14px;
    color: var(--text-secondary);
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--border-light);
    color: var(--text-secondary);
}

.btn-ghost:hover {
    background: rgba(0, 0, 0, 0.02);
    color: var(--text-primary);
}

/* Supplier Portal Layout */
.header {
    height: 70px;
    background: #FFFFFF;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.dashboard-view {
    padding: 2.5rem 0;
    background: #F8FAFC;
    min-height: calc(100vh - 70px);
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 1.5rem;
}

/* Utilities */
.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.mt-4 {
    margin-top: 1rem;
}

/* File List Styles */
.file-info {
    display: flex;
    flex-direction: column;
}

.file-name {
    font-weight: 600;
    color: var(--text-primary);
}

.file-size {
    font-size: 11px;
    color: var(--text-muted);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    background: white;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: min(320px, calc(100vw - 3rem));
    max-width: min(450px, calc(100vw - 3rem));
    border-left: 4px solid var(--primary);
    pointer-events: auto;
    animation: toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.toast.toast-success {
    border-left-color: var(--success);
}

.toast.toast-error {
    border-left-color: var(--error);
}

.toast.toast-warning {
    border-left-color: var(--warning);
}

.toast.fade-out {
    opacity: 0;
    transform: translateX(100%);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(100%) scale(0.9);
    }

    to {
        opacity: 1;
        transform: translateX(0) scale(1);
    }
}

.toast-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
}

.toast-content {
    flex: 1;
}

.toast-message {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Budget & Rubric Styling */
.budget-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.etapa-section {
    animation: fadeIn 300ms ease-out;
}

.etapa-title {
    margin-bottom: 1.5rem;
    padding: 0.75rem 1.25rem;
    background: #f8fafc;
    border-radius: 10px;
    border-left: 4px solid var(--primary);
    font-size: 1.1rem;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}

.local-group {
    padding-left: 1.5rem;
    border-left: 2px solid var(--border-subtle);
}

.rubric-card {
    border: 1px solid var(--border-subtle);
    background: white;
    transition: all 0.2s ease;
}

.rubric-card:hover {
    transform: translateY(-2px);
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
}

.text-error {
    color: var(--error);
}

.text-primary {
    color: var(--primary);
}

.text-success {
    color: var(--success);
}

.color-error {
    color: var(--error);
}

.color-success {
    color: var(--success);
}

.font-bold {
    font-weight: 700;
}

.font-semibold {
    font-weight: 600;
}

.uppercase {
    text-transform: uppercase;
}

.tracking-wider {
    letter-spacing: 0.05em;
}

.mb-6 {
    margin-bottom: 1.5rem;
}

.mb-3 {
    margin-bottom: 0.75rem;
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

.spin {
    animation: spin 1s linear infinite;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2rem;
    max-width: 550px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: #f1f5f9;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Steps List */
.steps-list {
    list-style: none;
    margin-top: 1.5rem;
}

.step-item {
    display: flex;
    gap: 1.25rem;
    margin-bottom: 1.25rem;
    align-items: flex-start;
}

.step-number {
    width: 28px;
    height: 28px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 4px 10px rgba(21, 71, 255, 0.2);
}

.step-text {
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.6;
}

/* Import Card Upload */
.upload-card-interactive {
    background: white;
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 1.5rem;
}

.upload-card-interactive:hover {
    border-color: var(--primary);
    background: rgba(21, 71, 255, 0.02);
}

.upload-card-interactive.active {
    border-color: var(--primary);
    background: rgba(21, 71, 255, 0.05);
}

.help-link {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    color: var(--primary);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
}

.help-link:hover {
    text-decoration: underline;
}
/* Anima��es de Carregamento */
@keyframes loading {
    0% { transform: translateX(-100%); }
    50% { transform: translateX(0); }
    100% { transform: translateX(100%); }
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes flash-highlight {
    0% { opacity: 0.4; }
    100% { opacity: 1; }
}
.details-flash {
    animation: flash-highlight 200ms ease-out;
}

.spin {
    animation: spin 1s linear infinite;
}
.salic-batch-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 900px;
    margin: 0 auto;
}

/* Barra de Progresso */
.salic-progress-box {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

.salic-progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.salic-progress-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.salic-progress-percentage {
    font-size: 0.875rem;
    font-weight: 700;
    color: var(--primary);
}

.salic-progress-bar {
    width: 100%;
    height: 10px;
    background: var(--border-subtle);
    border-radius: 999px;
    overflow: hidden;
    position: relative;
}

.salic-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #10B981 0%, #059669 100%);
    border-radius: 999px;
    width: 0%;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

/* Fila de Itens */
.salic-queue-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 450px;
    overflow-y: auto;
    padding-right: 0.5rem;
}

.salic-queue-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1.25rem;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
}

.salic-queue-item-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.salic-queue-item-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--border-subtle);
    color: var(--text-secondary);
}

.salic-queue-item-details {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.salic-queue-item-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.salic-queue-item-error-msg {
    font-size: 0.75rem;
    color: var(--error);
    margin-top: 0.25rem;
}

.salic-queue-item-status {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* Modificadores de Estado */
.salic-queue-item.pending {
    border-left: 4px solid var(--text-muted);
}
.salic-queue-item.pending .salic-queue-item-status {
    background: var(--border-subtle);
    color: var(--text-secondary);
}

.salic-queue-item.sending {
    border-left: 4px solid var(--primary);
    border-color: var(--primary);
    animation: salic-pulse 1.5s infinite ease-in-out;
    background: #eff6ff;
}
.salic-queue-item.sending .salic-queue-item-icon {
    background: #dbeafe;
    color: var(--primary);
}
.salic-queue-item.sending .salic-queue-item-status {
    background: #dbeafe;
    color: var(--primary);
}

.salic-queue-item.success {
    border-left: 4px solid var(--success);
    background: #f0fdf4;
}
.salic-queue-item.success .salic-queue-item-icon {
    background: #dcfce7;
    color: var(--success);
}
.salic-queue-item.success .salic-queue-item-status {
    background: #dcfce7;
    color: var(--success);
}

.salic-queue-item.error {
    border-left: 4px solid var(--error);
    background: #fef2f2;
}
.salic-queue-item.error .salic-queue-item-icon {
    background: #fee2e2;
    color: var(--error);
}
.salic-queue-item.error .salic-queue-item-status {
    background: #fee2e2;
    color: var(--error);
}

/* Animação de Pulse */
@keyframes salic-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.15);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.3);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.15);
    }
}

/* ─────────────────────────────────────────────────────────────────────────────
   COMBOBOX DE RUBRICAS (M1)
   Substitui o <datalist> nos 3 seletores de rubrica. O <datalist> não aceita
   <optgroup>, então rubricas homônimas (mesmo nome, produtos diferentes) ficavam
   indistinguíveis. Este painel agrupa por PRODUTO com cabeçalho + itens indentados,
   mantendo a busca por digitação.
   O painel é fixed e vive no <body> para não ser recortado por overflow de tabela
   nem apagado pelo app.innerHTML de cada render.
   ───────────────────────────────────────────────────────────────────────────── */
.rubrica-combo-panel {
    position: fixed;
    z-index: 9999;
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0, 0, 0, 0.03);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 0.25rem 0;
}

.rubrica-combo-panel.is-open {
    display: block;
}

.rubrica-combo-group {
    position: sticky;
    top: 0;
    background: var(--bg-sidebar);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    padding: 0.45rem 0.75rem;
    border-top: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
}

.rubrica-combo-panel .rubrica-combo-group:first-child {
    border-top: none;
}

.rubrica-combo-item {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0.75rem 0.45rem 1.5rem;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
}

.rubrica-combo-item:hover,
.rubrica-combo-item.is-active {
    background: var(--bg-sidebar);
}

.rubrica-combo-item.is-active {
    box-shadow: inset 3px 0 0 var(--primary);
}

.rubrica-combo-num {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.rubrica-combo-nome {
    flex: 1;
    min-width: 0;
}

.rubrica-combo-valor {
    color: var(--text-muted);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.rubrica-combo-item mark {
    background: rgba(37, 99, 235, 0.16);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

.rubrica-combo-empty {
    padding: 0.75rem;
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
}

/* Progresso do envio em lote (#153) -------------------------------------- */
/* Quadro fixo no topo da area de conteudo enquanto o lote e enviado; abaixo da sidebar
   mobile (1000), do hamburger (1100) e dos modais (2000). Fundo opaco para a fila nao
   aparecer por tras ao rolar. */
.lote-progresso-envio {
    position: sticky;
    top: 0.75rem;
    z-index: 50;
    background: var(--bg-card, #FFFFFF);
}

@media (max-width: 768px) {
    /* Deixa o hamburger (fixo no canto superior esquerdo) livre. */
    .lote-progresso-envio { top: 3.75rem; }
}

/* Um segmento por documento. */
.lote-segmentos {
    display: flex;
    gap: 3px;
    height: 10px;
}

.lote-seg {
    flex: 1 1 0;
    min-width: 4px;
    border-radius: 999px;
    background: var(--border-subtle);
    position: relative;
    overflow: hidden;
}

.lote-seg-ok { background: var(--success); }
.lote-seg-falha { background: var(--error); }

/* Documento atual: faixa em movimento continuo, so indica atividade (nao e percentual). */
.lote-seg-atual::after,
.lote-barra-indet > span {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    width: 40%;
    border-radius: inherit;
    background: var(--primary);
    animation: lote-corre 1.3s ease-in-out infinite;
}

/* Barra fina indeterminada abaixo do selo "Subindo...". */
.lote-barra-indet {
    position: relative;
    height: 3px;
    margin-top: 6px;
    min-width: 90px;
    max-width: 140px;
    border-radius: 999px;
    background: var(--border-subtle);
    overflow: hidden;
}

@keyframes lote-corre {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(250%); }
}

/* Sem animacao: o segmento atual fica cheio na cor de destaque e a barra fina some; o selo
   continua mostrando os segundos em texto. */
@media (prefers-reduced-motion: reduce) {
    .lote-seg-atual { background: var(--primary); }
    .lote-seg-atual::after,
    .lote-barra-indet > span { animation: none; }
    .lote-seg-atual::after { display: none; }
    .lote-barra-indet { display: none; }
}

/* Os breakpoints de 1400px e 768px usam overflow-x: hidden em html e body, o que faz o body virar
   um container de rolagem proprio e anula o position: sticky de qualquer filho (o quadro de
   progresso ficava na posicao original). overflow-x: clip corta o mesmo conteudo sem criar
   container de rolagem; navegador sem suporte mantem o hidden e perde so o sticky. */
@supports (overflow: clip) {
    html, body { overflow-x: clip; }
}

/* ── Tela de detalhes da nota (#130): etapas clicáveis, painel da etapa e coluna lateral ── */
.detalhe-cabecalho { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-start; gap: 1rem; }
.detalhe-etapas-card { padding: 1.25rem 1.5rem; }
.detalhe-etapas-rolagem { overflow-x: auto; }
.detalhe-etapas { display: flex; align-items: flex-start; min-width: 560px; }
.detalhe-etapa {
    flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 0.375rem;
    background: transparent; border: 0; padding: 0.25rem 0.125rem; font: inherit; cursor: pointer; color: var(--text-secondary);
    min-height: 44px; border-radius: var(--radius-sm);
}
.detalhe-etapa:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.detalhe-etapa-trilho { display: flex; align-items: center; width: 100%; }
.detalhe-etapa-linha { flex: 1; height: 2px; background: var(--border-light); }
.detalhe-etapa:first-child .detalhe-etapa-linha.antes,
.detalhe-etapa:last-child .detalhe-etapa-linha.depois { background: transparent; }
.detalhe-etapa.feita .detalhe-etapa-linha,
.detalhe-etapa.atual .detalhe-etapa-linha.antes,
.detalhe-etapa.erro .detalhe-etapa-linha.antes { background: var(--success); }
.detalhe-etapa-circulo {
    width: 32px; height: 32px; border-radius: 50%; box-sizing: border-box; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: #FFF; border: 2px solid var(--border-light); color: var(--text-muted);
}
.detalhe-etapa.feita .detalhe-etapa-circulo { background: var(--success); border-color: var(--success); color: #FFF; }
.detalhe-etapa.atual .detalhe-etapa-circulo { background: var(--primary); border-color: var(--primary); color: #FFF; }
.detalhe-etapa.erro .detalhe-etapa-circulo { background: var(--error); border-color: var(--error); color: #FFF; }
.detalhe-etapa.vendo .detalhe-etapa-circulo { box-shadow: 0 0 0 3px #FFF, 0 0 0 5px var(--primary); }
.detalhe-etapa-nome { font-size: 11px; font-weight: 600; text-align: center; }
.detalhe-etapa.atual .detalhe-etapa-nome, .detalhe-etapa.vendo .detalhe-etapa-nome { color: var(--text-primary); font-weight: 700; }
.detalhe-etapa.erro .detalhe-etapa-nome { color: var(--error); }
.detalhe-etapa-tag { font-size: 10px; font-weight: 600; min-height: 13px; color: var(--primary); }
.detalhe-etapa.erro .detalhe-etapa-tag { color: var(--error); }

.detalhe-colunas { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-start; }
.detalhe-coluna-principal { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 1.5rem; }
.detalhe-coluna-lateral { flex: 1 1 300px; min-width: 0; display: flex; flex-direction: column; gap: 1.5rem; }

.detalhe-painel { display: flex; flex-direction: column; gap: 1.25rem; scroll-margin-top: 1rem; }
.detalhe-painel.atual { border: 2px solid var(--primary); }
.detalhe-painel.atual.erro { border-color: var(--error); }
.detalhe-painel-topo { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 0.5rem; }
.detalhe-painel-tag { font-size: 12px; font-weight: 600; color: var(--text-secondary); }
.detalhe-painel-tag.atual { color: var(--primary); }
.detalhe-painel-tag.erro { color: var(--error); }
.detalhe-painel-tag.ok { color: var(--success); }
.detalhe-situacao { color: var(--text-secondary); line-height: 1.5; margin: 0; }
.detalhe-futura { background: var(--bg-sidebar); border-radius: var(--radius-sm); padding: 0.875rem 1rem; display: flex; flex-direction: column; gap: 0.25rem; }
.detalhe-bloco { display: flex; flex-direction: column; gap: 0.5rem; }
.detalhe-bloco-titulo { margin: 0; font-size: 11px; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
/* Cartões que já existiam e agora ficam dentro do painel: sem sombra de cartão sobre cartão. */
.detalhe-painel .card { box-shadow: none; margin-top: 0 !important; margin-bottom: 0 !important; }

.detalhe-historico { border-top: 1px solid var(--border-subtle); padding-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.detalhe-historico-linha { display: flex; gap: 0.75rem; font-size: 12px; line-height: 1.5; }
.detalhe-historico-quando { color: var(--text-secondary); width: 118px; flex-shrink: 0; }

.detalhe-concluida { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; padding: 0.75rem 0; border-top: 1px solid var(--border-subtle); }

.detalhe-previa-arquivo { height: 160px; background: var(--bg-sidebar); border: 1px solid var(--border-light); border-radius: var(--radius-sm); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; padding: 0 1rem; }
.detalhe-metadados summary { cursor: pointer; color: var(--primary); font-weight: 600; min-height: 32px; display: flex; align-items: center; }

@media (max-width: 768px) {
    /* Celular: as 6 etapas cabem na largura, sem rolagem que esconda a etapa atual. */
    .detalhe-etapas-card { padding: 1rem 0.75rem; }
    .detalhe-etapas { min-width: 0; }
    .detalhe-etapa-circulo { width: 26px; height: 26px; }
    .detalhe-etapa-nome { font-size: 9px; line-height: 1.2; overflow-wrap: anywhere; }
    .detalhe-etapa-tag { font-size: 9px; }
    .detalhe-historico-linha { flex-direction: column; gap: 0.125rem; }
    .detalhe-historico-quando { width: auto; }
}
