/*
 * Design system compartilhado das telas do emissor fiscal (NFS-e/NF-e).
 * Usado por: notas-fiscais.php, notas-emitir.php, notas-empresas-emissoras.php,
 * notas-certificados.php, notas-produtos-servicos.php.
 * Mantém os nomes de classe já existentes nessas páginas — evite renomear
 * sem atualizar todas as telas que os usam.
 */

:root {
    --bg-main: #071224;
    --bg-card: #0f2038;
    --bg-card-soft: #0c1a2e;
    --input-bg: #081527;
    --primary: #3d7de0;
    --primary-hover: #5b93e8;
    --primary-soft: rgba(61, 125, 224, 0.14);
    --danger: #FF453A;
    --warning: #FFBF00;
    --text-white: #FFFFFF;
    --text-light: #EAF1FB;
    --text-muted: #93A7C2;
    --border: rgba(234, 241, 251, 0.12);
    --border-soft: rgba(234, 241, 251, 0.06);
    --notice-error-text: #FFD1CE;
    --notice-error-bg: rgba(255, 69, 58, 0.08);
    --notice-error-border: rgba(255, 69, 58, 0.35);
    --notice-warning-text: #FFE8A3;
    --notice-warning-bg: rgba(255, 191, 0, 0.08);
    --notice-warning-border: rgba(255, 191, 0, 0.35);
    --radius: 10px;
    --radius-sm: 6px;
    --shadow-card: 0 12px 30px rgba(2, 8, 20, 0.35);
    --shadow-pop: 0 24px 60px rgba(2, 8, 20, 0.5);
    --font-titles: 'Montserrat', sans-serif;
    --font-body: 'Inter', sans-serif;
    color-scheme: dark;
}

:root[data-theme="light"] {
    --bg-main: #F5F8FB;
    --bg-card: #FFFFFF;
    --bg-card-soft: #EEF3F9;
    --input-bg: #FFFFFF;
    --primary: #1E4079;
    --primary-hover: #163a63;
    --primary-soft: rgba(30, 64, 121, 0.10);
    --danger: #D6392F;
    --warning: #B5810A;
    --text-white: #0A1A35;
    --text-light: #16233A;
    --text-muted: #56637C;
    --border: rgba(10, 26, 53, 0.12);
    --border-soft: rgba(10, 26, 53, 0.06);
    --notice-error-text: #8A241C;
    --notice-error-bg: rgba(214, 57, 47, 0.1);
    --notice-error-border: rgba(214, 57, 47, 0.35);
    --notice-warning-text: #7A5600;
    --notice-warning-bg: rgba(181, 129, 10, 0.12);
    --notice-warning-border: rgba(181, 129, 10, 0.4);
    --shadow-card: 0 12px 30px rgba(10, 26, 53, 0.08);
    --shadow-pop: 0 24px 60px rgba(10, 26, 53, 0.16);
    color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
    background: var(--bg-main);
}

html, html * {
    transition: background-color 0.45s ease, border-color 0.45s ease, color 0.3s ease, box-shadow 0.45s ease;
}

body {
    min-height: 100vh;
    font-family: var(--font-body);
    background: var(--bg-main);
    color: var(--text-light);
    padding: 2rem;
}

.shell { width: min(1180px, 100%); margin: 0 auto; }

a { color: inherit; text-decoration: none; }

::selection { background: var(--primary); color: #0A0A0A; }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---------- Cabeçalho e navegação ---------- */

.topbar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.brand img { height: 34px; width: auto; display: block; }

.brand-logo {
    font-family: var(--font-titles);
    font-weight: 600;
    font-size: 1.15rem;
    letter-spacing: 0.01em;
    color: var(--text-white);
}

.brand-logo strong { color: var(--primary); font-weight: 800; }

.empresa-ativa-form {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.5rem 0.9rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s ease;
}

.empresa-ativa-form:focus-within,
.empresa-ativa-form:hover { border-color: rgba(61, 125, 224, 0.4); }

.empresa-ativa-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-muted);
    font-family: var(--font-titles);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.empresa-ativa-form select {
    width: auto;
    max-width: 320px;
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text-white);
    font-family: var(--font-body);
    font-size: 0.85rem;
    cursor: pointer;
}

/* ---------- Alternador de tema claro/escuro ---------- */

.theme-toggle {
    margin-left: auto;
    padding: 0;
    border: none;
    background: none;
    cursor: pointer;
    line-height: 0;
}

.theme-toggle-track {
    position: relative;
    display: inline-flex;
    align-items: center;
    width: 56px;
    height: 30px;
    padding: 3px;
    border-radius: 999px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: background 0.35s ease, border-color 0.35s ease;
}

:root[data-theme="light"] .theme-toggle-track {
    box-shadow: inset 0 1px 3px rgba(20, 24, 26, 0.12);
}

.theme-toggle-thumb {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
    transform: translateX(0);
    transition: transform 0.4s cubic-bezier(.65, -0.4, .35, 1.4), background 0.35s ease;
}

:root[data-theme="light"] .theme-toggle-thumb { transform: translateX(26px); }

.theme-toggle-thumb i {
    position: absolute;
    font-size: 0.68rem;
    color: #0A0A0A;
    transition: opacity 0.25s ease, transform 0.4s ease;
}

.theme-icon-sun { opacity: 0; transform: rotate(-90deg) scale(0.4); }
.theme-icon-moon { opacity: 1; transform: rotate(0deg) scale(1); }

:root[data-theme="light"] .theme-icon-sun { opacity: 1; transform: rotate(0deg) scale(1); }
:root[data-theme="light"] .theme-icon-moon { opacity: 0; transform: rotate(90deg) scale(0.4); }

.theme-toggle:hover .theme-toggle-track { border-color: rgba(61, 125, 224, 0.4); }

.theme-toggle.girando .theme-toggle-thumb { transform: translateX(0) rotate(360deg); }
:root[data-theme="light"] .theme-toggle.girando .theme-toggle-thumb { transform: translateX(26px) rotate(360deg); }

.menu-hamburguer { position: relative; }

.menu-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    display: none;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 240px;
    padding: 0.6rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
    z-index: 60;
    animation: menu-pop 0.12s ease;
}

@keyframes menu-pop {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

.menu-dropdown.aberto { display: flex; }
.menu-dropdown .btn { justify-content: flex-start; width: 100%; }

.header-menus {
    order: 10;
    flex: 0 0 100%;
    display: flex;
    align-items: stretch;
    gap: 0;
    width: 100%;
    margin-left: 0;
    padding: 0 0.35rem;
    background: var(--primary);
    border-radius: var(--radius-sm);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.2);
}

.header-menus > .btn,
.header-menu > .header-menu-toggle {
    min-height: 48px;
    padding: 0.8rem 1rem;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #fff;
    white-space: nowrap;
}

.header-menus > .btn:hover,
.header-menu > .header-menu-toggle:hover,
.header-menu > .header-menu-toggle[aria-expanded="true"] {
    background: rgba(0, 0, 0, 0.14);
    color: #fff;
}

.header-menu > .menu-dropdown { left: 0; right: auto; min-width: 230px; }
.menu-chevron { font-size: 0.65rem; transition: transform 0.15s ease; }
.header-menu-toggle[aria-expanded="true"] .menu-chevron { transform: rotate(180deg); }
.header-logout { margin-left: auto; }

@media (max-width: 1100px) {
    .header-menus { overflow-x: auto; }
    .header-menu > .menu-dropdown { left: 0; right: auto; }
}

@media (max-width: 640px) {
    .header-menus { display: flex; overflow-x: auto; padding: 0; border-radius: 0; }
    .header-menus > .btn, .header-menu > .header-menu-toggle { min-height: 44px; padding: 0.7rem 0.8rem; }
    .header-logout { margin-left: 0; }
    .header-menu > .menu-dropdown { position: fixed; left: 1rem; right: 1rem; top: auto; min-width: 0; }
}

/* Barra de abas das telas fiscais — mostra em qual tela o usuário está. */
.notas-nav {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    padding: 0.4rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.notas-nav a {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.6rem 0.9rem;
    border-radius: 7px;
    font-family: var(--font-titles);
    font-size: 0.76rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    color: var(--text-muted);
    white-space: nowrap;
    transition: color 0.15s ease, background 0.15s ease;
}

.notas-nav a:hover { color: var(--text-white); background: rgba(255, 255, 255, 0.05); }

.notas-nav a.ativo {
    color: #0A0A0A;
    background: var(--primary);
    box-shadow: 0 4px 14px rgba(61, 125, 224, 0.35);
}

@media (max-width: 820px) {
    .notas-nav { overflow-x: auto; flex-wrap: nowrap; justify-content: flex-start; }
}

/* ---------- Estrutura básica ---------- */

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-card);
}

/* Atalhos de emissão em destaque (ex.: topo de notas-fiscais.php) */
.quick-actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.quick-action-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.4rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.quick-action-card:hover {
    border-color: rgba(61, 125, 224, 0.4);
    transform: translateY(-2px);
    box-shadow: 0 16px 34px rgba(0, 0, 0, 0.32);
}

.quick-action-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 1.15rem;
    flex: none;
}

.quick-action-texto { display: grid; gap: 0.15rem; flex: 1; }
.quick-action-texto strong {
    font-family: var(--font-titles);
    color: var(--text-white);
    text-transform: uppercase;
    font-size: 0.95rem;
    letter-spacing: 0.01em;
}
.quick-action-texto .muted { font-size: 0.8rem; }

.quick-action-seta { color: var(--text-muted); transition: transform 0.15s ease, color 0.15s ease; }
.quick-action-card:hover .quick-action-seta { color: var(--primary); transform: translateX(3px); }

/* Select solto fora de .field (ex.: filtro de status na listagem) */
.select-filtro {
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text-white);
    font-family: var(--font-body);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.15s ease;
}
.select-filtro:hover { border-color: rgba(255, 255, 255, 0.22); }
.select-filtro:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

h1, h2, h3 {
    font-family: var(--font-titles);
    color: var(--text-white);
    text-transform: uppercase;
}

h1 { font-size: clamp(2rem, 5vw, 3.2rem); margin-bottom: 0.8rem; }
h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.55rem;
}
h2 i { color: var(--primary); font-size: 0.95em; }
h3 { font-size: 1rem; margin-bottom: 0.75rem; }
.muted { color: var(--text-muted); line-height: 1.6; }

/* Marca campos obrigatórios ao lado do rótulo */
.marca-obrigatoria { color: var(--danger); margin-left: 0.2rem; }

/* ---------- Botões ---------- */

.btn {
    border: 0;
    border-radius: var(--radius-sm);
    padding: 0.85rem 1rem;
    color: #0A0A0A;
    background: var(--primary);
    font-family: var(--font-titles);
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:hover { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(61, 125, 224, 0.25); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-outline {
    background: transparent;
    color: var(--text-white);
    border: 1px solid var(--border);
}

.btn-outline:hover { background: rgba(255, 255, 255, 0.06); box-shadow: none; border-color: rgba(255, 255, 255, 0.2); }

.btn-danger {
    background: transparent;
    color: var(--notice-error-text);
    border: 1px solid var(--notice-error-border);
}

.btn-danger:hover { background: rgba(255, 69, 58, 0.1); box-shadow: none; }

.btn-small { padding: 0.55rem 0.75rem; font-size: 0.72rem; white-space: nowrap; }

/* ---------- Avisos ---------- */

.notice {
    margin-bottom: 1rem;
    padding: 1rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid rgba(61, 125, 224, 0.3);
    background: rgba(61, 125, 224, 0.08);
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    line-height: 1.55;
}

.notice i { margin-top: 0.2rem; font-size: 0.95rem; }

.notice.error {
    border-color: var(--notice-error-border);
    background: var(--notice-error-bg);
    color: var(--notice-error-text);
}

.notice.warning {
    border-color: var(--notice-warning-border);
    background: var(--notice-warning-bg);
    color: var(--notice-warning-text);
}

/* ---------- Formulários ---------- */

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.field { display: grid; gap: 0.4rem; }
.field label { color: var(--text-muted); font-size: 0.85rem; font-weight: 700; }

/* Botão de informação (ícone "i") que abre uma caixa de texto explicativa ao lado do campo */
.info-tooltip-wrap { position: relative; display: inline-flex; margin-left: 0.35rem; vertical-align: middle; }
.info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.15rem;
    height: 1.15rem;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-muted);
    font-size: 0.68rem;
    cursor: pointer;
    line-height: 1;
}
.info-btn:hover, .info-btn[aria-expanded="true"] { background: var(--primary-soft); color: var(--primary); }
.info-tooltip-box {
    display: none;
    position: absolute;
    z-index: 30;
    top: 140%;
    left: 0;
    width: 280px;
    max-width: min(320px, 80vw);
    padding: 0.75rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-card);
    box-shadow: var(--shadow-pop);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 400;
    line-height: 1.55;
    white-space: normal;
}
.info-tooltip-box.aberto { display: block; }
/* Quando o campo fica perto da borda direita do painel, a caixa é ancorada
   pela direita (em vez da esquerda) via JS, para não ser cortada pela tela. */
.info-tooltip-box.alinhar-direita { left: auto; right: 0; }

/* Campo somente leitura: mostra um valor definido em outro lugar (ex.: empresa emissora no cabeçalho) */
.campo-fixo {
    width: 100%;
    padding: 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-soft);
    background: var(--bg-card-soft);
    color: var(--text-light);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 0.85rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text-white);
    font-family: var(--font-body);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:hover,
.field select:hover,
.field textarea:hover { border-color: rgba(255, 255, 255, 0.22); }

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.field input:disabled,
.field select:disabled,
.field textarea:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.field textarea { resize: vertical; min-height: 4.5rem; }

/* Remove o "x" nativo de type=search do navegador — não combina com o tema escuro */
.field input[type="search"]::-webkit-search-cancel-button,
.field input[type="search"]::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 1.9rem;
    color: var(--text-muted);
    font-weight: 700;
}

/* Autocomplete de município / catálogos fiscais */
.municipio-autocomplete,
.catalogo-autocomplete { position: relative; }

.municipio-sugestoes,
.catalogo-sugestoes {
    position: absolute;
    z-index: 30;
    top: calc(100% - 1.2rem);
    left: 0;
    right: 0;
    display: none;
    max-height: 18rem;
    overflow-y: auto;
    padding: 0.35rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    background: var(--bg-card);
    box-shadow: var(--shadow-pop);
    /* Sem isso, o navegador desenha a barra de rolagem padrão, que destoa
       do tema (claro ou escuro) e "vaza" visualmente para fora dos cantos arredondados. */
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.municipio-sugestoes::-webkit-scrollbar,
.catalogo-sugestoes::-webkit-scrollbar { width: 8px; }
.municipio-sugestoes::-webkit-scrollbar-track,
.catalogo-sugestoes::-webkit-scrollbar-track { background: transparent; }
.municipio-sugestoes::-webkit-scrollbar-thumb,
.catalogo-sugestoes::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
}
.municipio-sugestoes::-webkit-scrollbar-thumb:hover,
.catalogo-sugestoes::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

.municipio-sugestoes.aberto,
.catalogo-sugestoes.aberto { display: grid; }

.municipio-opcao,
.catalogo-opcao {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 0;
    border-radius: 0.45rem;
    color: var(--text-light);
    background: transparent;
    text-align: left;
    cursor: pointer;
}

.municipio-opcao:hover,
.municipio-opcao:focus,
.catalogo-opcao:hover,
.catalogo-opcao:focus { background: rgba(61, 125, 224, 0.16); outline: none; }

.catalogo-opcao-exemplo {
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 400;
    line-height: 1.4;
}

/* Seções recolhíveis de cadastro (ex.: cadastro rápido de cliente) */
details.panel summary {
    cursor: pointer;
    font-family: var(--font-titles);
    color: var(--text-white);
    text-transform: uppercase;
    font-size: 1.1rem;
    list-style: none;
}

details.panel summary::-webkit-details-marker { display: none; }
details.panel[open] summary { margin-bottom: 1rem; }

/* Seções do formulário de emissão em accordion */
details.form-section {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card-soft);
    margin-bottom: 0.85rem;
    transition: border-color 0.15s ease;
    scroll-margin-top: 1rem;
    /* Sem "overflow: hidden" (removido de propósito): esse corte clipava os
       dropdowns de autocomplete (município/cIndOp/cClassTrib) sempre que o
       campo ficava perto do fim da seção. O arredondamento dos cantos é
       preservado aplicando o próprio border-radius no summary/corpo abaixo. */
}

details.form-section:hover { border-color: rgba(255, 255, 255, 0.16); }
details.form-section[open] { border-color: rgba(61, 125, 224, 0.3); }

details.form-section > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.95rem 1.1rem;
    font-family: var(--font-titles);
    color: var(--text-white);
    text-transform: uppercase;
    font-size: 0.88rem;
    letter-spacing: 0.02em;
    border-radius: var(--radius) var(--radius) 0 0;
    transition: background 0.15s ease;
}

details.form-section:not([open]) > summary { border-radius: var(--radius); }

details.form-section > summary::-webkit-details-marker { display: none; }

details.form-section > summary .form-section-titulo {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

details.form-section > summary .form-section-titulo i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.85rem;
    height: 1.85rem;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 0.82rem;
}

details.form-section > summary .fa-chevron-down {
    color: var(--text-muted);
    transition: transform 0.15s ease;
    font-size: 0.8rem;
}

details.form-section[open] > summary .fa-chevron-down { transform: rotate(180deg); }

details.form-section > summary:hover { background: rgba(255, 255, 255, 0.03); }

.form-section-corpo {
    padding: 0.4rem 1.1rem 1.4rem;
    animation: form-section-fade 0.18s ease;
}

@keyframes form-section-fade {
    from { opacity: 0; transform: translateY(-4px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Chips de navegação rápida entre as seções do formulário */
.form-jump {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
    padding: 0.6rem;
    background: var(--bg-card-soft);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    position: sticky;
    top: 0.75rem;
    z-index: 20;
    backdrop-filter: blur(6px);
}

.form-jump button {
    border: 1px solid var(--border);
    background: var(--bg-main);
    color: var(--text-muted);
    font-family: var(--font-body);
    font-size: 0.76rem;
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease;
}

.form-jump button:hover { color: var(--text-white); border-color: rgba(61, 125, 224, 0.5); }

.form-jump button.ativo {
    color: #0A0A0A;
    background: var(--primary);
    border-color: var(--primary);
    font-weight: 700;
}

@media (max-width: 820px) {
    .form-jump { position: static; }
}

/* ---------- Tabelas ---------- */

.table-wrap { overflow-x: auto; }

table.lista,
.panel table {
    width: 100%;
    min-width: 780px;
    border-collapse: collapse;
    font-size: 0.9rem;
}

table.lista th, table.lista td,
.panel table th, .panel table td {
    padding: 0.85rem 0.8rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

table.lista th,
.panel table th {
    color: var(--text-white);
    font-family: var(--font-titles);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

table.lista tbody tr,
.panel table tbody tr { transition: background 0.12s ease; }

table.lista tbody tr:hover,
.panel table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }

.itens-table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
.itens-table th, .itens-table td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); text-align: left; }
.itens-table th { color: var(--text-white); font-size: 0.72rem; text-transform: uppercase; font-family: var(--font-titles); }
.itens-table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.itens-table input, .itens-table select { width: 100%; padding: 0.5rem; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--input-bg); color: var(--text-white); transition: border-color 0.15s ease, box-shadow 0.15s ease; }
.itens-table input:focus, .itens-table select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.65rem 0.3rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
}
.status-pill::before { content: ''; width: 0.4rem; height: 0.4rem; border-radius: 50%; background: currentColor; flex: none; }
.status-rascunho { background: rgba(161, 161, 166, 0.18); color: var(--text-muted); }
.status-pendente_envio { background: var(--notice-warning-bg); color: var(--notice-warning-text); }
.status-autorizada { background: rgba(61, 125, 224, 0.15); color: var(--primary); }
.status-rejeitada,
.status-cancelada { background: var(--notice-error-bg); color: var(--notice-error-text); }

.status-active { color: var(--primary); font-weight: 700; }
.status-inactive { color: var(--danger); font-weight: 700; }

.row-actions { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.totais { text-align: right; font-family: var(--font-titles); font-size: 1.1rem; color: var(--text-white); }

.delete-confirm {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--danger);
    font-family: var(--font-titles);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    background: transparent;
    white-space: nowrap;
}

.delete-question {
    color: var(--text-muted);
    font-size: 0.78rem;
    white-space: nowrap;
}

.delete-confirm input {
    width: 16px;
    height: 16px;
    accent-color: var(--danger);
}

/* Menu "mais ações" por linha de tabela — mesma lógica do menu hambúrguer */
.acoes-menu { position: relative; }

.acoes-menu-dropdown {
    /* position/top/left ficam por conta do JS (position: fixed, calculado a partir do botão) —
       o menu vive dentro de .table-wrap (overflow-x: auto), que corta qualquer coisa posicionada
       como "absolute" perto da borda inferior da tabela. Os valores abaixo são só o fallback caso
       o JS não rode. */
    position: fixed;
    top: 0;
    left: 0;
    display: none;
    flex-direction: column;
    gap: 0.35rem;
    min-width: 210px;
    padding: 0.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-pop);
    z-index: 50;
    animation: menu-pop 0.12s ease;
}

.acoes-menu-dropdown.aberto { display: flex; }
.acoes-menu-dropdown form { display: block; }
.acoes-menu-dropdown .btn,
.acoes-menu-dropdown form .btn { justify-content: flex-start; width: 100%; }

/* ---------- Buscadores fiscais (NFS-e/NF-e) ---------- */

.panel-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.25rem;
}
.panel-header-row h2 { margin-bottom: 0; }

.panel-subtitulo { margin-top: -0.6rem; margin-bottom: 1.25rem; font-size: 0.88rem; }

/* Formulário de filtro/ação em linha: campos rotulados que crescem lado a lado,
   com o botão sempre alinhado à base (mesma altura que os campos, não o rótulo). */
.filtro-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 1rem;
}
.filtro-form .field { flex: 1 1 190px; min-width: 160px; margin-bottom: 0; }
.filtro-form .field-sm { flex: 0 1 130px; }
.filtro-form .field-lg { flex: 1 1 260px; }
.filtro-form .campo-ate { padding-bottom: 0.85rem; white-space: nowrap; }
.filtro-form .btn { flex: none; }

.secao-descricao { margin-bottom: 1.25rem; font-size: 0.88rem; }

details.acoes-secundarias { margin-top: 1.5rem; padding-top: 1.25rem; border-top: 1px solid var(--border-soft); }
details.acoes-secundarias summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 700;
}
details.acoes-secundarias summary::-webkit-details-marker { display: none; }
details.acoes-secundarias summary::before {
    content: '\f105';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 0.7rem;
    transition: transform 0.15s ease;
}
details.acoes-secundarias[open] summary::before { transform: rotate(90deg); }
details.acoes-secundarias .corpo { margin-top: 1rem; display: grid; gap: 1rem; }
details.acoes-secundarias .filtro-form { padding: 1rem; background: var(--bg-card-soft); border: 1px solid var(--border-soft); border-radius: var(--radius); }

/* Célula de tabela com valor principal + uma linha secundária menor (ex.: nome + CNPJ) */
.cel-principal { display: block; }
.cel-sub { display: block; margin-top: 0.25rem; color: var(--text-muted); font-size: 0.74rem; }

.resultado-contagem { margin-bottom: 0.9rem; color: var(--text-muted); font-size: 0.85rem; }

.tabela-acoes { display: flex; gap: 0.4rem; flex-wrap: nowrap; }

.paginacao { display: flex; justify-content: center; align-items: center; flex-wrap: wrap; gap: 0.35rem; margin-top: 1.5rem; }
.paginacao .reticencias { padding: 0 0.3rem; color: var(--text-muted); }

@media (max-width: 820px) {
    body { padding: 1rem; }
    .topbar { flex-direction: column; align-items: flex-start; }
    .empresa-ativa-form { width: 100%; }
    .empresa-ativa-form select { max-width: none; }
    .form-grid { grid-template-columns: 1fr; }
    .btn { width: 100%; }
    .filtro-form { flex-direction: column; align-items: stretch; }
    .filtro-form .field, .filtro-form .field-sm, .filtro-form .field-lg { flex: 1 1 auto; }
    .filtro-form .campo-ate { padding-bottom: 0; text-align: center; }
    .filtro-form .btn { width: 100%; }
}

/* ---------- Responsividade global ---------- */
body {
    padding: clamp(0.75rem, 2vw, 2rem);
    overflow-x: hidden;
}

.shell { min-width: 0; }
img, svg { max-width: 100%; }
.mobile-menu-toggle { display: none; }
.table-wrap {
    width: 100%;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
}

@media (max-width: 820px) {
    body { padding: 0.75rem; }
    .topbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 0.75rem;
    }
    .topbar > .brand { grid-column: 1; grid-row: 1; min-width: 0; }
    .topbar > .theme-toggle { grid-column: 2; grid-row: 1; margin-left: 0; }
    .empresa-ativa-form {
        grid-column: 1 / -1;
        grid-row: 2;
        width: 100%;
        min-width: 0;
    }
    .empresa-ativa-form select {
        width: 100%;
        min-width: 0;
        max-width: none;
    }
    .mobile-menu-toggle {
        grid-column: 1 / -1;
        grid-row: 3;
        display: inline-flex;
        width: 100%;
        min-height: 46px;
        justify-content: space-between;
    }
    .header-menus {
        grid-column: 1 / -1;
        grid-row: 4;
        display: none;
        flex-direction: column;
        width: 100%;
        padding: 0.4rem;
        overflow: visible;
        border: 1px solid var(--border);
        border-radius: var(--radius);
        background: var(--bg-card);
    }
    .header-menus.aberto { display: flex; }
    .header-menu, .header-menus > .btn { width: 100%; }
    .header-menus > .btn,
    .header-menu > .header-menu-toggle {
        width: 100%;
        min-height: 46px;
        justify-content: flex-start;
        border-radius: var(--radius-sm);
        color: var(--text-light);
    }
    .header-menu > .header-menu-toggle .menu-chevron { margin-left: auto; }
    .header-menu > .menu-dropdown {
        position: static;
        width: 100%;
        min-width: 0;
        max-height: none;
        margin: 0.25rem 0 0.5rem;
        box-shadow: none;
    }
    .header-logout { margin-left: 0; }
    .panel { padding: clamp(1rem, 4vw, 1.5rem); }
    h1 {
        font-size: clamp(1.65rem, 8vw, 2.35rem);
        overflow-wrap: anywhere;
    }
    h2 {
        font-size: 1.05rem;
        overflow-wrap: anywhere;
    }
    .field, .field input, .field select, .field textarea { min-width: 0; }
    .field input, .field select, .field textarea { font-size: 16px; }
    .row-actions .btn,
    .table-wrap .btn,
    .paginacao .btn { width: auto; min-height: 42px; }
    .quick-actions { grid-template-columns: 1fr; }
    .quick-action-card { min-width: 0; padding: 1.1rem; }
    .notice { overflow-wrap: anywhere; }
    .form-jump {
        flex-wrap: nowrap;
        overflow-x: auto;
        justify-content: flex-start;
        -webkit-over-scrolling: touch;
    }
    .form-jump button { flex: none; }
}

@media (max-width: 480px) {
    body { padding: 0.625rem; }
    .panel { padding: 1rem; margin-bottom: 1rem; }
    .brand-logo { font-size: 1.05rem; }
    .empresa-ativa-form {
        align-items: stretch;
        flex-direction: column;
    }
    .empresa-ativa-label { white-space: normal; }
    .notas-nav { margin-bottom: 1rem; }
    .quick-action-card { gap: 0.75rem; }
    .quick-action-icon { width: 2.6rem; height: 2.6rem; }
    .info-tooltip-box {
        position: fixed;
        left: 0.75rem !important;
        right: 0.75rem !important;
        top: 20vh;
        width: auto;
        max-width: none;
    }
}