/* Emissor NFS-e — camada da aplicação sobre o Eye3D Design System.
   Componentes (botão, campo, badge, alerta, abas, card, tabela) vêm de eye3d/bundle.css.
   Aqui ficam apenas layout e extensões que o DS não cobre (sidebar, toast, modal, gráfico,
   linha do tempo), sempre com tokens Eye3D — nenhum hex fixo. Tema: data-theme no <html>. */

@font-face { font-family: 'Roboto'; font-style: normal; font-weight: 400; font-display: swap; src: url('/fonts/roboto-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Roboto'; font-style: normal; font-weight: 500; font-display: swap; src: url('/fonts/roboto-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Roboto'; font-style: normal; font-weight: 700; font-display: swap; src: url('/fonts/roboto-latin-700-normal.woff2') format('woff2'); }

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font-roboto);
  font-size: 16px; line-height: 24px; /* body */
  background: var(--surface-alt);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-blue); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, [tabindex]:focus-visible, summary:focus-visible,
select:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--brand-blue); outline-offset: 2px; }

/* Tipografia (tokens type: display, h1–h3, body, small, label) */
h1, .t-h1 { font-size: 32px; line-height: 40px; font-weight: 700; margin: 0; }
h2, .t-h2 { font-size: 24px; line-height: 32px; font-weight: 500; margin: 0 0 var(--space-4); }
h3, .t-h3 { font-size: 18px; line-height: 26px; font-weight: 500; margin: 0 0 var(--space-2); }
.t-small, .small { font-size: 14px; line-height: 20px; }
.t-label { font-size: 12px; line-height: 16px; font-weight: 500; letter-spacing: 0.6px; text-transform: uppercase; }
.muted { color: var(--ink-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 20px; word-break: break-all; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.icon { width: 20px; height: 20px; flex: none; }
.e3-btn .icon { width: 16px; height: 16px; }

/* ---------------------------------------------------------------- layout */
.layout { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: var(--space-6) var(--space-4); display: flex; flex-direction: column; gap: var(--space-2);
  position: sticky; top: 0; height: 100vh; overflow-x: hidden; overflow-y: auto;
}
/* Logo sobre surface, com área de respiro ≥ space-4 (regra do brand book). */
.brand { display: flex; align-items: center; gap: 12px; padding: var(--space-4); margin: calc(-1 * var(--space-4)) calc(-1 * var(--space-4)) var(--space-2); }
.brand img { width: 40px; height: 40px; border-radius: 6px; display: block; }
.brand-name { font-size: 18px; line-height: 22px; font-weight: 700; color: var(--ink); }
.brand-sub { font-size: 12px; line-height: 16px; font-weight: 500; letter-spacing: 0.6px; text-transform: uppercase; color: var(--ink-muted); }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: var(--radius-md);
  color: var(--ink-muted); font-size: 14px; line-height: 20px; font-weight: 500;
}
.nav-secao { margin: var(--space-4) 12px 2px; font-size: 12px; line-height: 16px; font-weight: 500; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-muted); }
.nav a:hover { background: var(--surface-alt); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--info-bg); color: var(--brand-blue); }
.sidebar-empresa { flex: none; padding: 0 12px; margin-bottom: var(--space-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-empresa .e3-input { width: 100%; min-width: 0; box-sizing: border-box; }
.sidebar-footer { margin-top: auto; padding-top: var(--space-4); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: var(--space-2); }
.sidebar-user { font-size: 14px; line-height: 20px; }
.sidebar-user strong { display: block; font-weight: 500; }
.sidebar-footer .actions { justify-content: space-between; }
.sidebar-ambiente { padding: 0 12px; }
.sidebar-sigla { display: none; }
.btn-menu { position: absolute; top: calc(var(--space-6) + 4px); right: 8px; padding: 0 6px; gap: 0; }
.btn-menu .icon { transition: transform .2s; }

/* Menu recolhido: só ícones (desktop; no celular o menu já vira barra no topo). */
@media (min-width: 761px) {
  .layout { transition: grid-template-columns .2s; }
  .layout.menu-recolhido { grid-template-columns: 72px 1fr; }
  .menu-recolhido .sidebar { padding: var(--space-6) 12px; }
  .menu-recolhido .brand { justify-content: center; padding: var(--space-4) 0; margin: calc(-1 * var(--space-4)) 0 var(--space-2); }
  .menu-recolhido .brand > div,
  .menu-recolhido .nav-label,
  .menu-recolhido .sidebar-empresa,
  .menu-recolhido .sidebar-ambiente,
  .menu-recolhido .sidebar-user { display: none; }
  .menu-recolhido .sidebar-sigla {
    display: flex; align-items: center; justify-content: center; flex: none; align-self: center;
    width: 36px; height: 36px; border: 0; border-radius: 50%; cursor: pointer;
    background: var(--info-bg); color: var(--brand-blue); font: inherit; font-size: 13px; font-weight: 700;
  }
  .menu-recolhido .nav a { justify-content: center; padding: 10px 0; }
  .menu-recolhido .nav-secao { height: 1px; margin: var(--space-2) 8px; overflow: hidden; color: transparent; background: var(--border); }
  .menu-recolhido .sidebar-footer .actions { flex-direction: column; align-items: center; }
  .menu-recolhido .sidebar-footer .e3-btn { gap: 0; }
  .menu-recolhido .btn-menu { position: static; align-self: center; margin-top: calc(-1 * var(--space-2)); }
  .menu-recolhido .btn-menu .icon { transform: scaleX(-1); }
}
@media (prefers-reduced-motion: reduce) {
  .layout, .btn-menu .icon { transition: none; }
}
.main { padding: var(--space-8); min-width: 0; max-width: 1440px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-6); }
.page-head .back { font-size: 14px; line-height: 20px; display: inline-flex; align-items: center; gap: 4px; margin-bottom: 4px; }
.title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: var(--space-6); }
.section-gap { margin-top: var(--space-6); }

/* Painel de seção: mesmas medidas do e3-card (space-6, radius-md, border), largura livre. */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-6); min-width: 0; }
.panel > h2:first-child, .panel > .panel-head:first-child { margin-top: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); margin-bottom: var(--space-4); }
.panel-head h2 { margin: 0; }
.panel-sep { border: 0; border-top: 1px solid var(--border); margin: var(--space-6) 0; }

.grid { display: grid; gap: var(--space-6); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid > .e3-card { max-width: none; }

/* KPI sobre e3-card (eyebrow + valor); a primeira usa Card tone="brand" (uma por tela). */
.kpi-value { font-size: 32px; line-height: 40px; font-weight: 700; font-variant-numeric: tabular-nums; margin: 0 0 4px; }
.e3-card--brand .kpi-value { color: var(--on-panel); }

/* ---------------------------------------------------------------- formulários */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--space-4); }
.form-grid > .e3-field { min-width: 0; }
.e3-field > .e3-input { width: 100%; min-width: 0; }
.col-12 { grid-column: span 12; } .col-8 { grid-column: span 8; } .col-7 { grid-column: span 7; } .col-6 { grid-column: span 6; }
.col-5 { grid-column: span 5; } .col-4 { grid-column: span 4; } .col-3 { grid-column: span 3; } .col-2 { grid-column: span 2; }
.e3-field { min-width: 0; }
.e3-field > .e3-input { width: 100%; min-width: 0; }
select.e3-input { padding-right: 32px; }
textarea.e3-input { height: auto; min-height: 104px; padding: 8px 12px; resize: vertical; }
input[type="file"].e3-input { padding: 7px 12px; font-size: 14px; }
.e3-field.is-error select.e3-input, .e3-field.is-error textarea.e3-input { border-color: var(--danger); }
.e3-check { font-size: 16px; }
.e3-field--inline { justify-content: flex-end; min-height: 66px; }
.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }
.actions--end { justify-content: flex-end; }
a.e3-btn { text-decoration: none; }
.e3-btn .spinner { width: 14px; height: 14px; }

.filters { display: grid; grid-template-columns: minmax(0, 2fr) repeat(4, minmax(0, 1fr)) auto; gap: var(--space-4); align-items: end; margin-bottom: var(--space-6); }
.filters .e3-field { min-width: 0; }
.e3-field > .e3-input { width: 100%; min-width: 0; }

/* ---------------------------------------------------------------- tabelas (e3-table) */
.e3-table-wrap + .table-foot, .table-foot { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); flex-wrap: wrap; margin-top: var(--space-4); font-size: 14px; line-height: 20px; color: var(--ink-muted); }
.cell-sub { display: block; font-size: 12px; line-height: 16px; color: var(--ink-muted); margin-top: 2px; }
.cell-erro { display: block; font-size: 12px; line-height: 16px; color: var(--danger); margin-top: 4px; max-width: 280px; }
.row-actions { display: flex; gap: var(--space-2); justify-content: flex-end; flex-wrap: nowrap; }
.empty { text-align: center; padding: var(--space-8) var(--space-4); color: var(--ink-muted); font-size: 14px; line-height: 20px; }
.empty .e3-btn { margin-top: var(--space-4); }

/* Badge com ícone de andamento (a palavra carrega o significado; o ícone só reforça). */
.e3-badge { gap: 6px; white-space: nowrap; }
.e3-badge .spinner { width: 10px; height: 10px; border-width: 2px; }

/* ---------------------------------------------------------------- alertas (e3-alert) */
.e3-alert { margin-bottom: var(--space-6); }
.e3-alert .e3-alert__text + .e3-alert__text { margin-top: 4px; }
.sefaz-erro { padding: 12px 0 0; margin-top: 12px; border-top: 1px solid var(--border); font-size: 14px; line-height: 20px; }
.sefaz-erro:first-child { border-top: 0; margin-top: 4px; padding-top: 0; }
.sefaz-erro .codigo { font-family: ui-monospace, monospace; font-weight: 700; margin-right: 6px; }
.sefaz-erro .sugestao { margin-top: 4px; }
details summary { cursor: pointer; color: var(--ink-muted); font-size: 12px; line-height: 16px; margin-top: 6px; }

/* ---------------------------------------------------------------- detalhe */
.dl { display: grid; grid-template-columns: 176px minmax(0, 1fr); gap: 12px var(--space-4); margin: 0; font-size: 14px; line-height: 20px; }
.dl dt { color: var(--ink-muted); font-size: 12px; line-height: 20px; font-weight: 500; letter-spacing: 0.6px; text-transform: uppercase; }
.dl dd { margin: 0; min-width: 0; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 14px; line-height: 20px; }
.timeline li { position: relative; padding: 0 0 var(--space-4) 24px; border-left: 2px solid var(--border); margin-left: 7px; }
.timeline li::before { content: ""; position: absolute; left: -8px; top: 2px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--brand-blue); }
.timeline li.warn::before { border-color: var(--warning); background: var(--warning-bg); }
.timeline li.error::before { border-color: var(--danger); background: var(--danger); }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline .when { color: var(--ink-muted); font-size: 12px; line-height: 16px; margin-top: 2px; }
.timeline .tag { font-size: 12px; font-weight: 500; letter-spacing: .6px; text-transform: uppercase; margin-right: 4px; }
.timeline li.warn .tag { color: var(--warning); }
.timeline li.error .tag { color: var(--danger); }

/* ---------------------------------------------------------------- gráfico */
.chart svg { width: 100%; height: auto; max-height: 280px; display: block; }
.chart .bar { fill: var(--brand-blue); }
.chart .bar:hover { fill: var(--brand-blue-deep); }
.chart .axis { fill: var(--ink-muted); font-size: 12px; font-family: var(--font-roboto); }
.chart .grid-line { stroke: var(--border); }
.chart .bar-label { fill: var(--ink); font-size: 11px; font-weight: 500; font-family: var(--font-roboto); }
.status-bars { display: flex; flex-direction: column; gap: 12px; }
.status-row { display: grid; grid-template-columns: 1fr auto; gap: 6px var(--space-2); align-items: center; }
.status-row a:hover { text-decoration: none; }
.status-track { grid-column: span 2; height: 6px; background: var(--surface-alt); border-radius: 3px; overflow: hidden; }
.status-fill { height: 100%; background: var(--brand-blue); border-radius: 3px; }

/* ---------------------------------------------------------------- resumo de valores */
.summary { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); font-size: 14px; line-height: 20px; }
.summary-row { display: flex; justify-content: space-between; gap: var(--space-4); padding: 4px 0; font-variant-numeric: tabular-nums; }
.summary-row.total { border-top: 1px solid var(--border); margin-top: var(--space-2); padding-top: 12px; font-size: 18px; line-height: 26px; font-weight: 500; }

/* ---------------------------------------------------------------- modal (extensão: tokens Eye3D) */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 32, .56); display: grid; place-items: center; z-index: 50; padding: var(--space-4); }
.modal { background: var(--surface); color: var(--ink); border: 1px solid var(--border); border-radius: var(--radius-md); width: min(560px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal-wide { width: min(840px, 100%); }
.modal-head { padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); }
.modal-head h2 { margin: 0; font-size: 18px; line-height: 26px; }
.modal-body { padding: var(--space-6); }
.modal-body .e3-alert:last-child { margin-bottom: 0; }
.modal-foot { padding: var(--space-4) var(--space-6); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--space-2); }

/* ---------------------------------------------------------------- toasts (e3-alert flutuante) */
#toasts { position: fixed; right: var(--space-4); bottom: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); z-index: 100; width: min(400px, calc(100vw - 32px)); }
#toasts .e3-alert { margin: 0; overflow-wrap: anywhere; box-shadow: 0 8px 24px rgba(15, 23, 32, .16); animation: e3-slide .18s ease-out; }
@keyframes e3-slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--space-4); background: var(--surface-alt); }
.login-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-8); }
.login-card .brand { margin: 0 0 var(--space-6); padding: 0; }
.login-card .brand img { width: 56px; height: 56px; border-radius: 8px; }
.login-card form { display: flex; flex-direction: column; gap: var(--space-4); }
.login-card .e3-btn { width: 100%; }
.login-card .e3-alert { margin: 0; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: e3-spin .7s linear infinite; display: inline-block; flex: none; }
@keyframes e3-spin { to { transform: rotate(360deg); } }
.loading { padding: var(--space-8); display: flex; gap: var(--space-2); align-items: center; justify-content: center; color: var(--ink-muted); }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } #toasts .e3-alert { animation: none; } }

@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters > :first-child { grid-column: span 2; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px var(--space-4); border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { margin: 0; padding: 4px 0; }
  .brand-sub { display: none; }
  .nav { flex-direction: row; flex-wrap: wrap; width: 100%; }
  .nav a { padding: 8px 10px; }
  .nav a span.nav-label { display: none; }
  .nav-secao { display: none; }
  .sidebar-footer, .btn-menu { display: none; }
  .main { padding: var(--space-4); }
  h1, .t-h1 { font-size: 24px; line-height: 32px; }
  .grid-4, .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .filters { grid-template-columns: minmax(0, 1fr); }
  .filters > :first-child { grid-column: auto; }
  .form-grid > * { grid-column: span 12; }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .dl dd { margin-bottom: 8px; }
  .kpi-value { font-size: 24px; line-height: 32px; }
}

/* ---------------------------------------------------------------- seletor de ambiente (extensão: radio no estilo e3-check) */
.opcoes-ambiente { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-4); }
.opcao-ambiente { display: flex; gap: 12px; align-items: flex-start; padding: var(--space-4); border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); cursor: pointer; }
.opcao-ambiente:hover { background: var(--surface-alt); }
.opcao-ambiente.is-selected { border-color: var(--brand-blue); box-shadow: inset 0 0 0 1px var(--brand-blue); background: var(--info-bg); }
.opcao-ambiente input { appearance: none; -webkit-appearance: none; margin: 2px 0 0; width: 18px; height: 18px; flex: none; border: 2px solid var(--border-strong); border-radius: 50%; background: var(--surface); position: relative; cursor: pointer; }
.opcao-ambiente input:checked { border-color: var(--brand-blue); }
.opcao-ambiente input:checked::after { content: ""; position: absolute; inset: 3px; border-radius: 50%; background: var(--brand-blue); }
.opcao-ambiente input:disabled { cursor: not-allowed; }
.opcao-ambiente__corpo { display: flex; flex-direction: column; gap: 4px; }
.opcao-ambiente__titulo { font-size: 16px; line-height: 24px; font-weight: 500; }
.opcao-ambiente__texto { font-size: 14px; line-height: 20px; color: var(--ink-muted); }
.opcoes-ambiente + .e3-alert { margin: var(--space-4) 0 0; }
@media (max-width: 1180px) { .opcoes-ambiente { grid-template-columns: minmax(0, 1fr); } }

/* lista vertical de ações secundárias (painel "Ações" da nota) */
.acoes-lista { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.acoes-lista .e3-btn { justify-content: flex-start; }

/* botão com aparência de link (ex.: nome clicável em tabela) */
.btn-link { background: none; border: 0; padding: 0; color: var(--brand-blue); font: inherit; cursor: pointer; text-align: left; }
.btn-link:hover { text-decoration: underline; }
