/* Editor de Documentos Jurídicos Web - A4 Layout & UI */
:root {
  --primary: #06315a;
  --primary-hover: #0a467a;
  --primary-light: #eff6ff;
  --secondary: #0f172a;
  --accent: #06315a;
  --success: #10b981;
  --border-color: #cbd5e1;
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --font-family: 'Aptos', 'Arial', sans-serif;
  --radius: 8px;

  /* Margens exatas do escritório */
  --margin-top: 2.35cm;
  --margin-bottom: 2.85cm;
  --margin-left: 1.5cm;
  --margin-right: 1.5cm;
}

@font-face {
  font-family: 'Aptos';
  src: url('/static/fonts/aptos/Aptos-Display.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
}
@font-face {
  font-family: 'Aptos';
  src: url('/static/fonts/aptos/Aptos-Display-Bold.ttf') format('truetype');
  font-weight: bold;
  font-style: normal;
}
@font-face {
  font-family: 'Aptos';
  src: url('/static/fonts/aptos/Aptos-Display-Italic.ttf') format('truetype');
  font-style: italic;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
.header-container {
  max-width: 1550px;
  margin: 0 auto;
  padding: 0 20px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-main);
}
.brand-badge {
  background: linear-gradient(135deg, #8b5cf6, #2563eb);
  color: white;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.15rem;
}
.brand-title {
  font-weight: 700;
  font-size: 1.15rem;
}
.brand-subtitle {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 6px;
  list-style: none;
}
.nav-link {
  padding: 7px 14px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-link:hover, .nav-link.active {
  color: var(--accent);
  background-color: #f5f3ff;
}

/* Workspace Editor Split */
.editor-workspace {
  display: flex;
  flex: 1;
  min-height: 0;
  align-items: flex-start;
}

/* Sidebar Assistente de Variáveis */
.sidebar-panel {
  width: 320px;
  flex: 0 0 320px;
  max-width: 100%;
  background: #ffffff;
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 10;
  min-width: 0;
}
.sidebar-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}
.sidebar-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}
.tag-badge {
  display: inline-block;
  max-width: calc(100% - 6px);
  overflow-wrap: anywhere;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #1e293b;
  padding: 4px 8px;
  border-radius: var(--radius);
  font-family: monospace;
  font-size: 0.78rem;
  margin: 3px;
  cursor: pointer;
  transition: all 0.15s;
}
.tag-badge:hover {
  background: #e3eef5;
  border-color: #06315a;
  color: #06315a;
  transform: translateY(-1px);
}

/* Canvas Central A4 */
.editor-main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #cbd5e1;
  min-width: 0;
  overflow-x: auto;
  position: relative;
}

/* Toolbar Fixa Superior */
.editor-toolbar {
  background: #ffffff;
  border-bottom: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.toolbar-group {
  display: flex;
  align-items: center;
  gap: 2px;
  border-right: 1px solid #e2e8f0;
  padding-right: 8px;
  margin-right: 4px;
}
.tool-btn {
  background: none;
  border: 1px solid transparent;
  padding: 6px 9px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  min-height: 40px;
  text-transform: uppercase;
}
.tool-btn:hover {
  background: #f1f5f9;
  border-color: #cbd5e1;
}
.tool-select {
  padding: 5px 8px;
  font-size: 0.85rem;
  border: 1px solid #cbd5e1;
  border-radius: 4px;
  background: white;
  font-family: inherit;
}

/* Régua A4 Superior */
.ruler-container {
  background: #e2e8f0;
  border-bottom: 1px solid #cbd5e1;
  height: 22px;
  position: sticky;
  top: 48px;
  z-index: 19;
  display: flex;
  justify-content: center;
}
.ruler-bar {
  width: 210mm;
  flex-shrink: 0;
  align-self: flex-start;
  margin-inline: auto;
  height: 100%;
  background: #f8fafc;
  border-left: 1px solid #94a3b8;
  border-right: 1px solid #94a3b8;
  position: relative;
  font-size: 9px;
  color: #64748b;
  display: flex;
  align-items: flex-end;
}
.ruler-cm {
  position: absolute;
  bottom: 2px;
  transform: translateX(-50%);
}
.ruler-margin-indicator {
  position: absolute;
  top: 0;
  bottom: 0;
  background: rgba(37, 99, 235, 0.15);
}

/* Folha de Papel A4 Real */
.a4-viewport {
  padding: 30px 20px 60px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}
.a4-sheet {
  width: 210mm;
  flex-shrink: 0;
  align-self: flex-start;
  margin-inline: auto;
  min-height: 297mm;
  background: #ffffff;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15), 0 1px 3px rgba(0, 0, 0, 0.08);
  padding: var(--margin-top) var(--margin-right) var(--margin-bottom) var(--margin-left);
  color: #000000;
  font-family: 'Aptos', sans-serif;
  font-size: 11pt;
  line-height: 1.35;
  box-sizing: border-box;
  outline: none;
  position: relative;
  transition: box-shadow 0.2s;
}
.a4-sheet:focus {
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.25), 0 2px 6px rgba(0, 0, 0, 0.1);
}

/* Tipografia e Estilo Jurídico no Canvas */
.a4-sheet p {
  margin-top: var(--document-before,0pt);
  margin-bottom: var(--document-after,6pt);
  text-align: var(--document-align,justify);
  text-indent: var(--document-indent,0cm);
}
.a4-sheet h1, .a4-sheet h2, .a4-sheet h3 {
  font-family: 'Aptos', sans-serif;
  font-weight: bold;
  margin-top: 14pt;
  margin-bottom: 8pt;
}
.a4-sheet h1 { font-size: 14pt; text-align: center; }
.a4-sheet h2 { font-size: 12pt; }
.a4-sheet table {
  width: 100%;
  border-collapse: collapse;
  margin: 12pt 0;
}
.a4-sheet table, .a4-sheet th, .a4-sheet td {
  border: 1px solid #000000;
}
.a4-sheet th, .a4-sheet td {
  padding: 6pt 8pt;
  font-size: 10pt;
}

/* Salvamento e exportações superiores; classe preservada para impressão. */
.floating-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  background: #fff;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-color);
}


/* === PAINEL LATERAL DO AUDITOR ABNT & IA === */
.auditor-panel {
  position: fixed;
  top: 0;
  right: 0;
  transform: translateX(105%);
  visibility: hidden;
  width: min(410px,100vw);
  height: 100dvh;
  background: #ffffff;
  box-shadow: -4px 0 24px rgba(0,0,0,0.15);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  border-left: 1px solid var(--border-color);
}
.auditor-panel.open {
  transform: none;
  visibility: visible;
}
.auditor-header {
  padding: 16px 20px;
  background: #0f172a;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.auditor-body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}
.auditor-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}
.auditor-item.warning {
  border-left: 4px solid #f59e0b;
}
.auditor-item.success {
  border-left: 4px solid #10b981;
}
.auditor-item.ai-sug {
  border-left: 4px solid #8b5cf6;
  background: #faf5ff;
}

@media (max-width: 900px) { .editor-workspace { flex-direction: column; } .sidebar-panel { width: 100%; flex-basis: auto; border-right: 0; } .editor-main-area { width: 100%; } .editor-toolbar { position: relative; } }
@media (forced-colors: active) { .editor-toolbar, .sidebar-panel, .auditor-panel { background: Canvas; color: CanvasText; border-color: CanvasText; } .tool-btn { color: ButtonText; } }

/* Controles operacionais compactos; papel e impressão mantêm geometria própria. */
.pj-interface .btn {min-height:32px; height:auto; padding:5px 10px; font-size:14px; line-height:20px; font-weight:700; white-space:nowrap; width:auto;}
.pj-interface .btn-sm, .pj-interface .tool-btn {min-height:28px; padding:3px 8px; line-height:20px;}
.pj-interface .card-header, .pj-interface .floating-actions {flex-wrap:wrap;gap:6px;}
.pj-interface main {min-width:0;}
.pj-interface .data-table td:last-child {white-space:normal;}
@media(max-width:600px){.pj-interface .btn{max-width:100%;white-space:normal;} .pj-interface .editor-main-area{min-width:0;} .pj-interface .editor-canvas-wrapper{overflow:auto;max-width:100%;}}

.a4-sheet .secao-title {margin:0;}

.a4-sheet {forced-color-adjust:none;background:#fff;color:#000;}
.pj-interface h1,.pj-interface h2,.pj-interface h3,.pj-interface .tool-btn,.pj-interface button {font-weight:600;}

.documento-autocomplete {position:absolute;left:0;right:0;top:100%;z-index:40;max-height:220px;overflow:auto;background:var(--bg-card,#fff);border:1px solid var(--border-color);}
.documento-autocomplete button {display:block;width:100%;padding:7px;text-align:left;background:transparent;border:0;color:inherit;cursor:pointer;font-size:.82rem;}
.documento-autocomplete button:hover,.documento-autocomplete button[aria-selected=true] {outline:1px solid var(--primary);}

.calc-block-button{display:block;width:100%;text-align:left;margin:6px 0;padding:8px;font-weight:500}.calc-block-hint,#blocos-calculo-status{font-size:12px;line-height:1.4}.pj-bloco-calculo table{width:100%;table-layout:fixed}

#blocos-calculo-todos[hidden]{display:none!important}

.docs-content>header h1,.editor-workspace .floating-actions button,.editor-workspace .editor-toolbar button{font-weight:500!important}
.editor-toolbar .toolbar-group{max-width:100%;min-width:0;flex-wrap:wrap;row-gap:6px;box-sizing:border-box}
.editor-toolbar .tool-btn{flex-shrink:0;white-space:nowrap;max-width:100%;height:auto}
.editor-toolbar .tool-select{max-width:100%;box-sizing:border-box}
.calc-add-dialog{width:min(600px,calc(100vw - 24px));max-height:calc(100dvh - 32px);overflow:auto;border:2px solid var(--border-color);border-radius:12px;background:var(--bg-card);color:inherit;padding:16px}.calc-add-dialog h2{font-size:17px}.calc-add-dialog fieldset{border:0;padding:0;margin:12px 0;display:flex;gap:14px;flex-wrap:wrap}.calc-add-dialog label,.calc-add-dialog p{font-size:12px}.calc-add-dialog select{width:100%}.calc-add-dialog footer{display:flex;justify-content:flex-end;gap:8px;margin-top:16px}#adicionar-calculo-blocos{display:flex;flex-wrap:wrap;gap:8px}.calc-add-dialog::backdrop{background:rgb(0 0 0 / .35)}

/* Resultado fora da folha: não participa de salvar nem exportar. */
.editor-autofill-status{padding:10px 14px;margin:8px 12px;border:1px solid var(--border-color);border-radius:6px;overflow-wrap:anywhere;font-size:.85rem}
#editor-table-properties{max-height:calc(100dvh - 32px);overflow:auto}
#editor-table-properties fieldset{margin:12px 0;padding:10px;border:1px solid var(--border-color);min-width:0}
#editor-table-properties p{font-size:.8rem;margin:6px 0}
