/* ==========================================================================
   Planilha Web — estilos
   Tema claro/escuro via variáveis CSS. Sem dependências externas.
   ========================================================================== */

:root {
  color-scheme: light;

  /* Identidade visual extraída da logo.jpeg */
  --marca-azul-900: #071d2e;
  --marca-azul-800: #0e293e;
  --marca-azul-700: #14324a;
  --marca-azul-600: #1b364f;
  --marca-azul-500: #2b4964;
  --marca-azul-400: #375774;
  --marca-ouro: #fbbe03;
  --marca-ouro-claro: #fbdf09;
  --marca-ouro-escuro: #8a5f00;
  --marca-creme: #eaeee0;

  --fundo: #f4f1e7;
  --superficie: #fffdf6;
  --superficie-2: #f4efe1;
  --superficie-3: #eae2cf;
  --texto: #102a3f;
  --texto-suave: #576c7e;
  --texto-fraco: #5c6f80;
  --borda: #ded5c1;
  --borda-forte: #c3b79c;
  --acento: #8a5f00;
  --acento-forte: #6f4a00;
  --acento-suave: #f7e8b3;
  --acento-texto: #1c1400;
  --primaria: #0e293e;
  --primaria-forte: #071d2e;
  --primaria-texto: #fffdf6;
  --perigo: #b42318;
  --perigo-suave: #fee4e2;
  --sucesso: #067647;
  --sucesso-suave: #dcfae6;
  --aviso: #b54708;
  --aviso-suave: #fef0c7;
  --celula-bg: #fffdf6;
  --celula-zebra: #fbf8ee;
  --cabecalho: #f0ead9;
  --cabecalho-texto: #576c7e;
  --cabecalho-ativo: #f8e8b6;
  --grid-linha: #e8e1d1;
  --selecao: rgba(214, 158, 0, 0.14);
  --selecao-forte: rgba(214, 158, 0, 0.25);
  --barra-fundo: #0e293e;
  --barra-fundo-2: #071d2e;
  --barra-borda: rgba(251, 190, 3, 0.28);
  --barra-texto: #f7f4e9;
  --barra-texto-suave: #b9c8d2;
  --barra-hover: rgba(255, 255, 255, 0.09);
  --barra-ativo: rgba(251, 190, 3, 0.16);
  --sombra-1: 0 1px 2px rgba(7, 29, 46, 0.08);
  --sombra-2: 0 4px 12px rgba(7, 29, 46, 0.14);
  --sombra-3: 0 16px 40px rgba(7, 29, 46, 0.26);
  --raio: 8px;
  --raio-pequeno: 6px;
  --altura-linha: 26px;
  --fonte: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fonte-mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

[data-tema="escuro"] {
  color-scheme: dark;
  --fundo: #071d2e;
  --superficie: #0b2438;
  --superficie-2: #102f47;
  --superficie-3: #173c58;
  --texto: #eaeee0;
  --texto-suave: #a9bac7;
  --texto-fraco: #7f96a8;
  --borda: #1e4059;
  --borda-forte: #2d5875;
  --acento: #fbbe03;
  --acento-forte: #fbdf09;
  --acento-suave: #3b3008;
  --acento-texto: #1a1400;
  --primaria: #fbbe03;
  --primaria-forte: #fbdf09;
  --primaria-texto: #102a3f;
  --perigo: #ff8a80;
  --perigo-suave: #3a1d1e;
  --sucesso: #7ee2a8;
  --sucesso-suave: #12301f;
  --aviso: #ffd166;
  --aviso-suave: #35290f;
  --celula-bg: #0b2438;
  --celula-zebra: #0e293e;
  --cabecalho: #102f47;
  --cabecalho-texto: #a9bac7;
  --cabecalho-ativo: #3b3008;
  --grid-linha: #1b3d56;
  --selecao: rgba(251, 190, 3, 0.16);
  --selecao-forte: rgba(251, 190, 3, 0.28);
  --barra-fundo: #061829;
  --barra-fundo-2: #040f1a;
  --barra-borda: rgba(251, 190, 3, 0.24);
  --barra-texto: #eaeee0;
  --barra-texto-suave: #a9bac7;
  --barra-hover: rgba(255, 255, 255, 0.07);
  --barra-ativo: rgba(251, 190, 3, 0.14);
  --sombra-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --sombra-2: 0 6px 16px rgba(0, 0, 0, 0.45);
  --sombra-3: 0 20px 50px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--fonte);
  font-size: 13px;
  color: var(--texto);
  background: var(--fundo);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

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

::selection { background: var(--acento-suave); }

/* Scrollbars discretas */
* { scrollbar-width: thin; scrollbar-color: var(--borda-forte) transparent; }
*::-webkit-scrollbar { width: 12px; height: 12px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--borda-forte); border: 3px solid transparent; background-clip: content-box; border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: var(--texto-fraco); border: 3px solid transparent; background-clip: content-box; }

kbd {
  font-family: var(--fonte-mono);
  font-size: 10px;
  color: var(--texto-fraco);
  background: var(--superficie-2);
  border: 1px solid var(--borda);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  margin-left: auto;
  white-space: nowrap;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 320px;
  background: var(--fundo);
}

/* ==========================================================================
   Barra superior
   ========================================================================== */

.appbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: 50px;
  min-height: 50px;
  padding: 0 12px 0 14px;
  background: linear-gradient(180deg, var(--barra-fundo) 0%, var(--barra-fundo-2) 100%);
  border-bottom: 1px solid var(--barra-borda);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.22), 0 2px 10px rgba(7, 29, 46, 0.16);
  color: var(--barra-texto);
  z-index: 40;
}

.marca {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-shrink: 0;
  color: var(--marca-ouro);
  user-select: none;
}

.marca-logo {
  display: block;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 9px;
  object-fit: cover;
  background: var(--marca-azul-900);
  border: 1px solid rgba(251, 190, 3, 0.55);
  box-shadow: 0 0 0 2px rgba(251, 190, 3, 0.12), 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.marca:hover .marca-logo {
  transform: scale(1.04);
  box-shadow: 0 0 0 3px rgba(251, 190, 3, 0.18), 0 2px 8px rgba(0, 0, 0, 0.4);
}

.marca-texto {
  font-size: 14px;
  letter-spacing: -0.01em;
  color: var(--barra-texto);
  white-space: nowrap;
}

.marca-texto b { color: var(--marca-ouro); }

.doc-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  max-width: 560px;
  margin-left: 4px;
}

.doc-nome {
  min-width: 80px;
  width: 100%;
  max-width: 300px;
  height: 30px;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: var(--raio-pequeno);
  background: transparent;
  color: var(--barra-texto);
  font-weight: 600;
  font-size: 13.5px;
  text-overflow: ellipsis;
}

.doc-nome::placeholder { color: var(--barra-texto-suave); }

.doc-nome:hover { background: var(--barra-hover); }

.doc-nome:focus {
  outline: none;
  background: var(--barra-hover);
  border-color: var(--marca-ouro);
  box-shadow: 0 0 0 3px rgba(251, 190, 3, 0.18);
}

.save-state {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--barra-texto-suave);
  white-space: nowrap;
}

.save-state::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--marca-ouro);
}

.save-state.salvando::before { background: var(--aviso); animation: pulsar 0.9s ease-in-out infinite; }
.save-state.erro::before { background: var(--perigo); }

@keyframes pulsar {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.appbar-acoes {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.appbar .btn-icone { color: var(--barra-texto-suave); }
.appbar .btn-icone:hover { background: var(--barra-hover); color: var(--barra-texto); }
.appbar .btn-icone.ativo { background: var(--barra-ativo); color: var(--marca-ouro); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 30px;
  padding: 0 13px;
  border-radius: var(--raio-pequeno);
  border: 1px solid var(--borda);
  background: var(--superficie);
  color: var(--texto);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}

.btn:hover { background: var(--superficie-2); border-color: var(--borda-forte); }
.btn:active { transform: translateY(0.5px); }

.btn-primario {
  background: var(--primaria);
  border-color: var(--primaria);
  color: var(--primaria-texto);
  box-shadow: var(--sombra-1);
  font-weight: 600;
}

.btn-primario:hover { background: var(--primaria-forte); border-color: var(--primaria-forte); }

.appbar .btn-primario {
  background: linear-gradient(180deg, var(--marca-ouro-claro) 0%, var(--marca-ouro) 100%);
  border-color: var(--marca-ouro);
  color: var(--marca-azul-900);
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.appbar .btn-primario:hover {
  background: linear-gradient(180deg, #ffe63a 0%, var(--marca-ouro-claro) 100%);
  border-color: var(--marca-ouro-claro);
}

.btn-salvar { min-width: 68px; }

.btn-secundario {
  background: var(--superficie-2);
  border-color: var(--borda);
}

.btn-perigo { color: var(--perigo); border-color: var(--perigo); background: transparent; }
.btn-perigo:hover { background: var(--perigo-suave); }

.btn-icone {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--raio-pequeno);
  background: transparent;
  color: var(--texto-suave);
  font-size: 16px;
  line-height: 1;
  transition: background 0.12s, color 0.12s;
}

.btn-icone:hover { background: var(--superficie-2); color: var(--texto); }
.btn-icone.ativo { background: var(--acento-suave); color: var(--acento); }

/* ==========================================================================
   Menu
   ========================================================================== */

.menubar {
  display: flex;
  align-items: stretch;
  height: 32px;
  min-height: 32px;
  padding: 0 8px;
  background: var(--marca-azul-900);
  border-bottom: 1px solid var(--barra-borda);
  position: relative;
  z-index: 35;
}

.menu { position: relative; display: flex; }

.menu-titulo {
  height: 100%;
  padding: 0 11px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--barra-texto-suave);
  font-size: 12.5px;
  font-weight: 500;
}

.menu-titulo:hover,
.menu.aberto .menu-titulo {
  background: var(--barra-hover);
  color: var(--barra-texto);
}

.menu.aberto .menu-titulo {
  box-shadow: inset 0 -2px 0 var(--marca-ouro);
  color: var(--marca-ouro);
}

.menu-painel {
  display: none;
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  min-width: 252px;
  padding: 5px;
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra-2);
  z-index: 1000;
}

.menu.aberto .menu-painel { display: block; }

.menu-painel button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--texto);
  font-size: 12.5px;
  text-align: left;
  white-space: nowrap;
}

.menu-painel button:hover,
.menu-painel button:focus-visible {
  background: var(--acento-suave);
  color: var(--acento-forte);
  outline: none;
}

.menu-painel kbd { background: transparent; border-color: transparent; color: var(--texto-fraco); }

.menu-sep {
  height: 1px;
  margin: 5px 8px;
  background: var(--borda);
}

.menubar-info {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding-right: 6px;
  font-size: 11.5px;
  color: var(--barra-texto-suave);
  white-space: nowrap;
  overflow: hidden;
}

.ponto-status {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--marca-ouro);
  flex-shrink: 0;
}

/* ==========================================================================
   Barra de ferramentas
   ========================================================================== */

.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 42px;
  min-height: 42px;
  padding: 0 10px;
  overflow-x: auto;
  overflow-y: hidden;
  background: var(--superficie);
  border-bottom: 1px solid var(--borda);
  z-index: 30;
}

.toolbar::-webkit-scrollbar { height: 0; }

.grupo-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
  padding: 0 6px;
  border-right: 1px solid var(--borda);
}

.grupo-toolbar:last-child { border-right: none; }

.btn-tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 30px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--raio-pequeno);
  background: transparent;
  color: var(--texto-suave);
  font-size: 14px;
  transition: background 0.12s, color 0.12s;
}

.btn-tool:hover { background: var(--superficie-2); color: var(--texto); }
.btn-tool.ativo { background: var(--acento-suave); color: var(--acento); border-color: var(--acento-suave); }

.btn-texto {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  width: 30px;
}

.btn-cor {
  position: relative;
  flex-direction: column;
  gap: 1px;
  padding-top: 1px;
  color: var(--texto);
  font-size: 13px;
}

.cor-letra { line-height: 1; font-weight: 600; }

.cor-barra {
  display: block;
  width: 16px;
  height: 3px;
  border-radius: 1px;
  background: var(--texto);
}

.fx-simbolo {
  font-family: Georgia, serif;
  font-style: italic;
  font-weight: 700;
  font-size: 15px;
  color: var(--texto-suave);
}

.select-tool {
  height: 30px;
  padding: 0 6px;
  border: 1px solid transparent;
  border-radius: var(--raio-pequeno);
  background: transparent;
  color: var(--texto);
  font-size: 12px;
  cursor: pointer;
}

.select-tool:hover { background: var(--superficie-2); border-color: var(--borda); }
.select-fonte { width: 126px; }
.select-tamanho { width: 62px; }
.select-formato { width: 130px; }

/* ==========================================================================
   Barra de fórmulas
   ========================================================================== */

.formulabar {
  display: flex;
  align-items: center;
  height: 36px;
  min-height: 36px;
  padding: 0 8px;
  gap: 6px;
  background: var(--superficie);
  border-bottom: 1px solid var(--borda);
  z-index: 25;
}

.name-box {
  width: 100px;
  height: 26px;
  padding: 0 8px;
  border: 1px solid var(--borda);
  border-radius: 5px;
  background: var(--superficie);
  font-family: var(--fonte-mono);
  font-size: 11.5px;
  text-align: center;
  color: var(--texto);
}

.name-box:focus {
  outline: none;
  border-color: var(--acento);
  box-shadow: 0 0 0 2px var(--acento-suave);
}

.btn-fx {
  display: grid;
  place-items: center;
  width: 28px;
  height: 26px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: var(--texto-suave);
  font-family: Georgia, serif;
  font-style: italic;
  font-weight: 700;
  font-size: 14px;
}

.btn-fx:hover { background: var(--superficie-2); color: var(--texto); }

.formula-campo { flex: 1; min-width: 0; }

.formula-input {
  width: 100%;
  height: 26px;
  padding: 0 9px;
  border: 1px solid var(--borda);
  border-radius: 5px;
  background: var(--superficie);
  font-family: var(--fonte-mono);
  font-size: 12px;
  color: var(--texto);
}

.formula-input:focus {
  outline: none;
  border-color: var(--acento);
  box-shadow: 0 0 0 2px var(--acento-suave);
}

.formula-input.alterado { border-color: var(--acento); background: var(--acento-suave); }

.formula-botoes { display: none; gap: 2px; }
.formula-botoes.visivel { display: flex; }

.btn-formula {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--borda);
  border-radius: 5px;
  background: var(--superficie);
  color: var(--sucesso);
  font-size: 13px;
}

.btn-formula:hover { background: var(--superficie-2); }
.btn-formula:last-child { color: var(--perigo); }

/* ==========================================================================
   Área de trabalho / grade
   ========================================================================== */

.workspace {
  position: relative;
  flex: 1;
  min-height: 0;
  background: var(--superficie);
}

.grid-scroll {
  position: absolute;
  inset: 0;
  overflow: auto;
  background: var(--celula-bg);
  outline: none;
}

.grid-wrap {
  position: relative;
  display: inline-block;
  min-width: 100%;
  vertical-align: top;
}

.grid {
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 13px;
  background: var(--celula-bg);
  user-select: none;
}

.grid th,
.grid td {
  height: var(--altura-linha);
  padding: 0 6px;
  border-right: 1px solid var(--grid-linha);
  border-bottom: 1px solid var(--grid-linha);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  line-height: 1.25;
}

.grid thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 27px;
  background: var(--cabecalho);
  color: var(--cabecalho-texto);
  font-weight: 500;
  font-size: 11px;
  text-align: center;
  user-select: none;
}

.grid th.canto,
.grid th.linha-cabecalho {
  position: sticky;
  left: 0;
  width: 46px;
  min-width: 46px;
  max-width: 46px;
  padding: 0;
  background: var(--cabecalho);
  color: var(--texto-fraco);
  font-weight: 500;
  font-size: 10.5px;
  text-align: center;
  z-index: 2;
  user-select: none;
  cursor: pointer;
}

.grid thead th.canto {
  top: 0;
  z-index: 4;
  cursor: default;
}

.grid th.coluna-cabecalho { cursor: pointer; padding: 0 4px; }
.grid th.coluna-cabecalho:hover { background: var(--cabecalho-ativo); color: var(--acento); }
.grid th.linha-cabecalho:hover { background: var(--cabecalho-ativo); color: var(--acento); }

.grid th.hl { background: var(--cabecalho-ativo); color: var(--acento); font-weight: 700; }

.grid td.celula {
  background: var(--celula-bg);
  color: var(--texto);
  cursor: cell;
  overflow: hidden;
}

.grid td.celula.num { text-align: right; }
.grid td.celula.erro { color: var(--perigo); text-align: center; font-weight: 600; }
.grid td.celula.logico { text-align: center; color: var(--texto-suave); }

.grid td.celula.sel { background: var(--selecao); }
.grid td.celula.sel.ativa { background: var(--selecao-forte); }

.grid td.celula.preenchida { position: relative; }

.grid td.celula.preenchida::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-top: 4px solid var(--texto-fraco);
  opacity: 0.55;
}

.grid td.celula.cortando { opacity: 0.5; }

.grid td.celula em {
  font-style: normal;
  color: var(--texto-fraco);
}

/* Célula ativa e alça de preenchimento */
.sel-overlay {
  position: absolute;
  display: none;
  border: 2px solid var(--acento);
  background: transparent;
  pointer-events: none;
  z-index: 5;
  box-sizing: border-box;
}

.fill-handle {
  position: absolute;
  right: -4px;
  bottom: -4px;
  width: 7px;
  height: 7px;
  border: 1px solid #fff;
  background: var(--acento);
  border-radius: 1px;
  pointer-events: auto;
  cursor: crosshair;
  z-index: 6;
}

.fill-preview {
  position: absolute;
  display: none;
  border: 1px dashed var(--acento);
  background: var(--selecao);
  pointer-events: none;
  z-index: 4;
}

.fill-preview[hidden] { display: none; }

/* Editor flutuante */
.cell-editor {
  position: absolute;
  display: block;
  z-index: 12;
  min-width: 80px;
  height: 26px;
  min-height: 26px;
  padding: 3px 5px;
  border: 2px solid var(--acento);
  border-radius: 1px;
  background: var(--superficie);
  color: var(--texto);
  font-family: var(--fonte);
  font-size: 13px;
  line-height: 1.25;
  resize: none;
  overflow: hidden;
  white-space: pre;
  box-shadow: var(--sombra-2);
  outline: none;
}

.cell-editor[hidden] { display: none; }

/* ==========================================================================
   Barra de abas / status
   ========================================================================== */

.sheetbar {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  min-height: 36px;
  padding: 0 8px;
  background: var(--superficie);
  border-top: 1px solid var(--borda);
  z-index: 20;
}

.sheet-nav { display: flex; gap: 1px; }

.sheet-nav .btn-icone { width: 24px; height: 26px; font-size: 17px; }

.tabs {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 100%;
  padding-top: 4px;
  max-width: 55%;
  overflow-x: auto;
  overflow-y: hidden;
}

.tabs::-webkit-scrollbar { height: 0; }

.aba {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 28px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--texto-suave);
  font-size: 12px;
  white-space: nowrap;
  max-width: 180px;
}

.aba:hover { background: var(--superficie-2); color: var(--texto); }

.aba.ativa {
  background: var(--superficie);
  border-color: var(--borda);
  color: var(--acento);
  font-weight: 600;
  box-shadow: 0 -2px 0 var(--marca-ouro) inset;
}

.aba .aba-nome {
  overflow: hidden;
  text-overflow: ellipsis;
}

.aba .aba-cor {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.55;
  flex-shrink: 0;
}

.btn-add-aba {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--texto-suave);
  font-size: 17px;
}

.btn-add-aba:hover { background: var(--superficie-2); color: var(--texto); }

.sheetbar-espaco { flex: 1; }

.stats {
  max-width: 52%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 3px 8px;
  border-radius: 5px;
  background: var(--superficie-2);
  color: var(--texto-suave);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.stats b { color: var(--texto); font-weight: 600; }

/* ==========================================================================
   Barra de localizar/substituir
   ========================================================================== */

.findbar {
  position: absolute;
  top: 8px;
  right: 22px;
  z-index: 22;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(560px, calc(100% - 60px));
  padding: 8px;
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra-2);
}

.findbar[hidden] { display: none; }

.findbar-campos {
  display: flex;
  align-items: center;
  gap: 4px;
}

.findbar-campos input[type="text"] {
  flex: 1;
  min-width: 0;
  height: 28px;
  padding: 0 8px;
  border: 1px solid var(--borda);
  border-radius: 5px;
  background: var(--superficie);
  font-size: 12px;
}

.findbar-campos input[type="text"]:focus {
  outline: none;
  border-color: var(--acento);
  box-shadow: 0 0 0 2px var(--acento-suave);
}

.find-opcao {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  padding: 0 4px;
  color: var(--texto-suave);
  font-size: 11px;
  user-select: none;
}

.find-info {
  flex-shrink: 0;
  min-width: 54px;
  padding: 0 4px;
  color: var(--texto-fraco);
  font-size: 11px;
  text-align: right;
}

.findbar .btn { height: 28px; padding: 0 9px; font-size: 11.5px; }

/* ==========================================================================
   Menus de contexto, popover de cor
   ========================================================================== */

.context-menu {
  position: fixed;
  z-index: 1200;
  min-width: 224px;
  padding: 5px;
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra-3);
}

.context-menu[hidden] { display: none; }

.context-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--texto);
  font-size: 12.5px;
  text-align: left;
  white-space: nowrap;
}

.context-menu button:hover { background: var(--acento-suave); color: var(--acento-forte); }
.context-menu button.perigo { color: var(--perigo); }
.context-menu button.perigo:hover { background: var(--perigo-suave); }
.context-menu kbd { background: transparent; border-color: transparent; }

.color-popover {
  position: fixed;
  z-index: 1300;
  width: 248px;
  padding: 10px;
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: var(--raio);
  box-shadow: var(--sombra-3);
}

.color-popover[hidden] { display: none; }

.color-topo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  font-size: 12px;
}

.color-topo .btn-icone { width: 24px; height: 24px; font-size: 13px; }

.color-swatches {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}

.swatch {
  width: 100%;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.16);
  border-radius: 4px;
  background: transparent;
}

.swatch:hover { transform: scale(1.12); outline: 2px solid var(--acento); outline-offset: 1px; }
.swatch.sem-cor {
  background-image: linear-gradient(45deg, transparent 44%, var(--perigo) 44%, var(--perigo) 56%, transparent 56%);
  background-color: var(--superficie);
}

.color-personalizada {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--borda);
  font-size: 11px;
  color: var(--texto-suave);
}

.color-personalizada input[type="color"] {
  width: 34px;
  height: 28px;
  padding: 1px;
  border: 1px solid var(--borda);
  border-radius: 5px;
  background: var(--superficie);
  cursor: pointer;
}

.color-personalizada .btn { height: 28px; padding: 0 9px; font-size: 11px; margin-left: auto; }

.color-limpar {
  width: 100%;
  margin-top: 8px;
  padding: 7px;
  border: 1px dashed var(--borda);
  border-radius: 5px;
  background: transparent;
  color: var(--texto-suave);
  font-size: 11.5px;
}

.color-limpar:hover { background: var(--superficie-2); color: var(--texto); }

/* ==========================================================================
   Modais
   ========================================================================== */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(11, 18, 32, 0.48);
  backdrop-filter: blur(2px);
}

.modal-root[hidden] { display: none; }

.modal {
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(82vh, 760px);
  background: var(--superficie);
  border: 1px solid var(--borda);
  border-radius: 12px;
  box-shadow: var(--sombra-3);
  animation: surgir 0.14s ease-out;
}

.modal.modal-largo { width: min(860px, 100%); }
.modal.modal-estreito { width: min(420px, 100%); }

@keyframes surgir {
  from { opacity: 0; transform: translateY(6px) scale(0.99); }
  to { opacity: 1; transform: none; }
}

.modal-cabecalho {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 18px 12px;
  border-bottom: 1px solid var(--borda);
}

.modal-cabecalho h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-cabecalho .btn-icone { margin-left: auto; }

.modal-corpo {
  padding: 16px 18px;
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.55;
}

.modal-rodape {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--borda);
  background: var(--superficie-2);
  border-radius: 0 0 12px 12px;
}

.modal-rodape .esquerda { margin-right: auto; }

.campo {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 12px;
}

.campo > label { font-size: 11.5px; font-weight: 600; color: var(--texto-suave); }

.campo input[type="text"],
.campo input[type="number"],
.campo select,
.campo textarea {
  width: 100%;
  min-height: 32px;
  padding: 6px 9px;
  border: 1px solid var(--borda);
  border-radius: 6px;
  background: var(--superficie);
  font-size: 12.5px;
}

.campo textarea { resize: vertical; font-family: var(--fonte-mono); line-height: 1.5; }

.campo input:focus, .campo select:focus, .campo textarea:focus {
  outline: none;
  border-color: var(--acento);
  box-shadow: 0 0 0 2px var(--acento-suave);
}

.campo .dica { font-size: 11px; color: var(--texto-fraco); }

.modal-corpo p { margin: 0 0 10px; }
.modal-corpo h3 { margin: 16px 0 7px; font-size: 12.5px; }
.modal-corpo ul { margin: 0 0 10px; padding-left: 18px; }
.modal-corpo code {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--superficie-2);
  font-family: var(--fonte-mono);
  font-size: 11.5px;
}

.lista-funcoes {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
  border: 1px solid var(--borda);
  border-radius: 7px;
  overflow: hidden;
}

.linha-funcao {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--borda);
  font-size: 11.5px;
}

.linha-funcao:last-child { border-bottom: none; }
.linha-funcao:nth-child(even) { background: var(--celula-zebra); }
.linha-funcao code { min-width: 120px; font-weight: 600; color: var(--acento); background: transparent; }
.linha-funcao span { color: var(--texto-fraco); }
.linha-funcao .btn { margin-left: auto; height: 24px; padding: 0 7px; font-size: 10.5px; }

.tabela-atalhos {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.tabela-atalhos th,
.tabela-atalhos td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--borda);
  text-align: left;
}

.tabela-atalhos th { color: var(--texto-suave); font-size: 11px; font-weight: 600; }
.tabela-atalhos td:last-child { text-align: right; white-space: nowrap; }

.opcoes-modal { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0; }
.opcoes-modal label { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--texto-suave); }

/* ==========================================================================
   Toasts
   ========================================================================== */

.toasts {
  position: fixed;
  right: 16px;
  bottom: 52px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  max-width: 360px;
  padding: 10px 13px;
  border: 1px solid var(--borda);
  border-left: 3px solid var(--acento);
  border-radius: 7px;
  background: var(--superficie);
  box-shadow: var(--sombra-2);
  color: var(--texto);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: auto;
  animation: toast-entrar 0.18s ease-out;
}

.toast.saindo { animation: toast-sair 0.16s ease-in forwards; }
.toast.sucesso { border-left-color: var(--sucesso); }
.toast.erro { border-left-color: var(--perigo); }
.toast.aviso { border-left-color: var(--aviso); }
.toast .toast-icone { flex-shrink: 0; font-size: 13px; line-height: 1.4; }

@keyframes toast-entrar { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-sair { to { opacity: 0; transform: translateX(12px); } }

/* ==========================================================================
   Diversos
   ========================================================================== */

.aviso-noscript {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 30px;
  background: var(--superficie);
  color: var(--texto);
  font-size: 15px;
  text-align: center;
}

.print-area { display: none; }

.link {
  color: var(--acento);
  text-decoration: none;
  cursor: pointer;
}

.link:hover { text-decoration: underline; }

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--acento-suave);
  color: var(--acento-forte);
  font-size: 10px;
  font-weight: 600;
}

.sobre-marca {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--barra-borda);
  border-radius: 10px;
  background: linear-gradient(135deg, var(--marca-azul-800) 0%, var(--marca-azul-700) 100%);
  color: var(--marca-creme);
}

.sobre-marca img {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid rgba(251, 190, 3, 0.55);
  box-shadow: 0 0 0 2px rgba(251, 190, 3, 0.12);
}

.sobre-marca strong {
  display: block;
  font-size: 15px;
  color: var(--marca-ouro);
}

.sobre-marca span {
  display: block;
  margin-top: 2px;
  font-size: 11.5px;
  color: var(--barra-texto-suave);
}

/* ==========================================================================
   Responsividade
   ========================================================================== */

@media (max-width: 860px) {
  .marca-texto { display: none; }
  .doc-info { max-width: none; }
  .menubar-info { display: none; }
  .tabs { max-width: 45%; }
  .stats { max-width: 45%; }
  .select-fonte { width: 100px; }
}

@media (max-width: 620px) {
  .appbar { gap: 8px; padding: 0 8px; }
  .save-state { display: none; }
  .doc-nome { max-width: 100%; }
  .btn-salvar { min-width: 0; padding: 0 10px; }
  .menubar { overflow-x: auto; }
  .menu-titulo { padding: 0 8px; font-size: 12px; }
  .stats { display: none; }
  .findbar { right: 8px; width: calc(100% - 16px); }
  .findbar-campos { flex-wrap: wrap; }
  .tabs { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ==========================================================================
   Impressão
   ========================================================================== */

@media print {
  @page { margin: 12mm; }

  body { overflow: visible; background: #fff; color: #000; }

  body > *:not(.print-area) { display: none !important; }

  .print-area {
    display: block !important;
    font-family: Arial, sans-serif;
    color: #000;
  }

  .print-area h1 { margin: 0 0 2px; font-size: 18pt; }
  .print-area .print-meta { margin: 0 0 10px; color: #555; font-size: 9pt; }
  .print-area table { border-collapse: collapse; width: 100%; font-size: 9pt; }
  .print-area th, .print-area td {
    border: 1px solid #999;
    padding: 3px 5px;
    text-align: left;
    vertical-align: top;
  }
  .print-area th { background: #eee; font-weight: 700; }
  .print-area .pnum { text-align: right; }
  .print-area .print-rodape { margin-top: 10px; font-size: 8pt; color: #777; }
  .print-area tr { break-inside: avoid; }
}
