/* assets/css/editor.css */
/* Estilos do Editor Markdown e Modal */

#editorOverlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(7, 16, 31, 0.85);
    backdrop-filter: blur(8px);
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: editorFadeIn 0.2s ease;
}

#editorOverlay.open {
    display: flex;
}

@keyframes editorFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

#editorOverlay .modal {
    background: #fff;
    border-radius: 16px;
    width: 100%;
    max-width: 900px;
    height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: editorSlideUp 0.3s ease;
}

@keyframes editorSlideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

#editorOverlay .modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f8fafd;
    flex-shrink: 0;
}

#editorOverlay .modal-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    color: #07101F;
}

#editorClose {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #64748B;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#editorClose:hover {
    background: #f1f5f9;
    color: #07101F;
}

.editor-toolbar {
    padding: 10px 16px;
    background: #f8fafd;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    flex-shrink: 0;
}

.editor-toolbar .btn-sm {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    color: #334155;
    transition: all 0.2s;
    font-family: inherit;
}

.editor-toolbar .btn-sm:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    transform: translateY(-1px);
}

.editor-toolbar .btn-sm:active {
    transform: translateY(0);
}

.editor-toolbar .btn-sm.btn-primary {
    background: linear-gradient(135deg, #3B82F6, #1D4ED8);
    color: #fff;
    border: none;
    margin-left: auto;
}

.editor-toolbar .btn-sm.btn-primary:hover {
    background: linear-gradient(135deg, #2563EB, #1E40AF);
}

.editor-toolbar .btn-sm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

#editorTextarea {
    flex: 1;
    width: 100%;
    padding: 20px;
    border: none;
    resize: none;
    font-family: 'Courier New', 'Consolas', monospace;
    font-size: 14px;
    line-height: 1.7;
    color: #07101F;
    background: #fff;
    outline: none;
    tab-size: 2;
}

#editorTextarea::placeholder {
    color: #94a3b8;
}

#previewPane {
    width: 50%;
    padding: 20px;
    overflow-y: auto;
    background: #f8fafd;
    display: none;
    border-left: 1px solid #e5e7eb;
}

#previewPane.active {
    display: block;
}

#previewContent {
    background: #fff;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    min-height: 100%;
    font-size: 14px;
    line-height: 1.7;
    color: #07101F;
}

#previewContent h1 {
    font-size: 22px;
    font-weight: 900;
    margin: 16px 0 8px;
    color: #07101F;
    border-bottom: 3px solid #3B82F6;
    padding-bottom: 6px;
}

#previewContent h2 {
    font-size: 18px;
    font-weight: 800;
    margin: 14px 0 7px;
    color: #0f172a;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 4px;
}

#previewContent h3 {
    font-size: 16px;
    font-weight: 700;
    margin: 12px 0 6px;
    color: #0f172a;
}

#previewContent p {
    margin: 8px 0;
}

#previewContent strong {
    font-weight: 700;
    color: #1e293b;
}

#previewContent em {
    font-style: italic;
}

#previewContent code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'Courier New', monospace;
}

#previewContent ul, #previewContent ol {
    margin: 8px 0;
    padding-left: 24px;
}

#previewContent li {
    margin: 4px 0;
}

#previewContent table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    font-size: 13px;
}

#previewContent th, #previewContent td {
    border: 1px solid #e2e8f0;
    padding: 8px 12px;
    text-align: left;
}

#previewContent th {
    background: #f8fafd;
    font-weight: 700;
}

#editorStats {
    padding: 8px 20px;
    background: #f8fafd;
    border-top: 1px solid #e5e7eb;
    font-size: 12px;
    color: #64748B;
    font-weight: 600;
    flex-shrink: 0;
}

@media (max-width: 768px) {
    #editorOverlay {
        padding: 0;
    }
    
    #editorOverlay .modal {
        height: 100vh;
        max-width: 100%;
        border-radius: 0;
    }
    
    #previewPane {
        width: 100%;
        border-left: none;
        border-top: 1px solid #e5e7eb;
    }
    
    .editor-toolbar {
        padding: 8px;
        gap: 4px;
    }
    
    .editor-toolbar .btn-sm {
        padding: 5px 8px;
        font-size: 11px;
    }
}
/* ================================================================
   EDITOR MELHORADO — Preview A4 fiel + Tabs de formato
   (adicionado à versão existente — não substitui)
   ================================================================ */

/* Shell do editor */
.ed-shell {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 1100px;
  height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  animation: editorSlideUp 0.25s ease;
}

/* Header */
.ed-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid #e5e7eb;
  background: #f8fafd;
  flex-shrink: 0;
}

.ed-title {
  margin: 0;
  font-size: 16px;
  font-weight: 800;
  color: #07101F;
  white-space: nowrap;
}

.ed-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: #64748b;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  transition: background 0.15s;
}
.ed-close:hover { background: #f1f5f9; color: #07101F; }

/* Tabs principais (Preview / Editar) */
.ed-fmt-tabs {
  display: flex;
  gap: 4px;
  background: #e9ecef;
  border-radius: 10px;
  padding: 3px;
}
.ed-tab {
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: #64748b;
  font-family: inherit;
  transition: all 0.15s;
}
.ed-tab.active {
  background: #fff;
  color: #07101F;
  box-shadow: 0 1px 4px rgba(0,0,0,0.12);
}
.ed-tab:hover:not(.active) { color: #334155; }

/* Sub-toolbars */
.ed-subtoolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #f8fafd;
  border-bottom: 1px solid #e5e7eb;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.ed-fmt-label {
  font-size: 12px;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ed-fmt-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Botões de formato (PDF / Word / Excel) */
.ed-fmtbtn {
  padding: 5px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: #475569;
  font-family: inherit;
  transition: all 0.15s;
}
.ed-fmtbtn:hover { border-color: #94a3b8; background: #f8fafc; }
.ed-fmtbtn.active {
  background: #07101F;
  color: #fff;
  border-color: #07101F;
}

/* Botões de acção */
.ed-action-btn {
  padding: 6px 13px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  color: #334155;
  font-family: inherit;
  transition: all 0.2s;
  white-space: nowrap;
}
.ed-action-btn:hover { background: #f1f5f9; border-color: #cbd5e1; transform: translateY(-1px); }
.ed-action-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none !important; }

.ed-action-btn.primary {
  background: linear-gradient(135deg,#3B82F6,#1D4ED8);
  color: #fff; border: none;
}
.ed-action-btn.primary:hover { background: linear-gradient(135deg,#2563EB,#1E40AF); }

.ed-action-btn.wa {
  background: #22c55e;
  color: #fff; border: none;
}
.ed-action-btn.wa:hover { background: #16a34a; }

.ed-action-btn.ai {
  background: linear-gradient(135deg,#8B5CF6,#6D28D9);
  color: #fff; border: none;
}
.ed-action-btn.ai:hover { background: linear-gradient(135deg,#7C3AED,#5B21B6); }
.ed-action-btn.save {
  background: linear-gradient(135deg,#10b981,#059669);
  color: #fff; border-color: transparent; font-weight: 700;
}
.ed-action-btn.save:hover { background: linear-gradient(135deg,#059669,#047857); }

/* Stats */
.ed-stats {
  margin-left: auto;
  font-size: 11px;
  color: #94a3b8;
  font-weight: 600;
}

/* BODY */
.ed-body {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Preview A4 */
.ed-preview-wrap {
  flex: 1;
  overflow: auto;
  background: #d1d5db;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px;
}

.ed-a4-bg {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.ed-a4-label {
  font-size: 11px;
  color: #6b7280;
  background: #fff;
  padding: 3px 12px;
  border-radius: 20px;
  font-weight: 600;
}

.ed-a4-frame {
  width: 210mm;
  min-height: 297mm;
  border: none;
  background: #fff;
  box-shadow: 0 4px 24px rgba(0,0,0,0.18);
  display: block;
}

/* Edit textarea */
.ed-edit-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ed-textarea {
  flex: 1;
  padding: 20px 24px;
  border: none;
  resize: none;
  font-family: 'Courier New', Consolas, monospace;
  font-size: 14px;
  line-height: 1.7;
  color: #07101F;
  background: #fff;
  outline: none;
  tab-size: 2;
}
.ed-textarea::placeholder { color: #94a3b8; }

/* Responsive */
@media (max-width: 900px) {
  .ed-shell { max-width: 100%; height: 100dvh; border-radius: 0; }
  #editorOverlay { padding: 0; }

  .ed-preview-wrap { padding: 12px 8px; }
  .ed-a4-bg { width: 100%; align-items: center; }

  /* Scale A4 to fit mobile viewport */
  .ed-a4-frame {
    width: 210mm;
    min-height: 297mm;
    transform-origin: top center;
    transform: scale(var(--a4-scale, 0.42));
    margin-bottom: calc((297mm * var(--a4-scale, 0.42)) - 297mm);
  }

  .ed-fmt-group { flex-wrap: wrap; }
  .ed-title { display: none; }
  .ed-action-btn { padding: 5px 9px; font-size: 11px; }
  .ed-fmtbtn { padding: 5px 9px; font-size: 11px; }
  .ed-tab { padding: 5px 10px; font-size: 12px; }
  .ed-textarea { font-size: 16px; padding: 16px; } /* prevent iOS zoom */
}

@media (max-width: 480px) {
  .ed-subtoolbar { gap: 5px; padding: 6px 10px; }
  .ed-action-btn.wa,
  .ed-action-btn.ai { display: none; }
  .ed-action-btn.save { padding: 5px 12px; font-size: 12px; } /* always visible */
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── WORD TOOLBAR ─────────────────────────────────────────────── */
.ed-word-toolbar {
  flex-direction: column;
  gap: 4px;
  padding: 6px 10px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
}
.ed-word-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.ed-word-row2 { border-top: 1px solid #e2e8f0; padding-top: 5px; }
.ed-word-group {
  display: flex;
  align-items: center;
  gap: 2px;
  border-right: 1px solid #e2e8f0;
  padding-right: 6px;
  margin-right: 2px;
}
.ed-word-group:last-child { border-right: none; }

.ed-wbtn {
  padding: 3px 7px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  font-family: inherit;
  color: #374151;
  transition: background .12s, border-color .12s;
  white-space: nowrap;
  min-height: 26px;
}
.ed-wbtn:hover { background: #e2e8f0; border-color: #cbd5e1; }
.ed-wbtn.active { background: #dbeafe; border-color: #3b82f6; color: #1d4ed8; }

.ed-sel {
  padding: 3px 6px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
  font-size: 12px;
  color: #374151;
  cursor: pointer;
  height: 26px;
}
.ed-sel-sm { width: 52px; }

.ed-color-lbl {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 13px;
  font-weight: bold;
  cursor: pointer;
  padding: 2px 5px;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  background: #fff;
  height: 26px;
}
.ed-color-lbl input[type=color] {
  width: 20px; height: 16px;
  border: none; padding: 0; cursor: pointer;
  background: none;
}
.ed-color-bg { color: #6b7280; }

/* ── WORD PAGE (editor WYSIWYG) ───────────────────────────────── */
.ed-word-page-wrap {
  flex: 1;
  overflow-y: auto;
  background: #e8ecf0;
  padding: 20px;
  display: flex;
  justify-content: center;
}
.ed-word-page {
  width: 210mm;
  min-height: 297mm;
  padding: 25mm 22mm 20mm 25mm;
  background: #fff;
  box-shadow: 0 2px 16px rgba(0,0,0,.15);
  font-family: 'Calibri', Arial, sans-serif;
  font-size: 12pt;
  line-height: 1.5;
  color: #000;
  outline: none;
  cursor: text;
}
.ed-word-page:focus { box-shadow: 0 2px 20px rgba(59,130,246,.25); }
.ed-word-page h1 { font-size:18pt; font-weight:bold; text-align:center; margin-bottom:14pt; color:#1F3864; }
.ed-word-page h2 { font-size:14pt; font-weight:bold; margin:14pt 0 7pt; color:#2E74B5; border-bottom:1px solid #ddd; padding-bottom:3pt; }
.ed-word-page h3 { font-size:12pt; font-weight:bold; margin:10pt 0 5pt; }
.ed-word-page h4 { font-size:11pt; font-weight:bold; margin:8pt 0 4pt; }
.ed-word-page p  { margin-bottom:8pt; text-align:justify; }
.ed-word-page ul,
.ed-word-page ol { margin:6pt 0 6pt 18pt; }
.ed-word-page li { margin-bottom:3pt; }
.ed-word-page table { width:100%; border-collapse:collapse; margin:10pt 0; }
.ed-word-page td,
.ed-word-page th  { border:1px solid #aaa; padding:5pt 7pt; }
.ed-word-page th  { background:#f0f0f0; font-weight:bold; }
.ed-word-page hr  { border:none; border-top:1px solid #ccc; margin:12pt 0; }
/* Cursor de tabela editável */
.ed-word-page td[contenteditable=true]:focus { outline:2px solid #3b82f6; }

/* ── EDIT WRAP ────────────────────────────────────────────────── */
.ed-edit-wrap {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── MOBILE WORD EDITOR ───────────────────────────────────────── */
@media (max-width: 900px) {
  .ed-word-toolbar { padding: 4px 8px; gap: 3px; }
  .ed-word-row { gap: 4px; }
  .ed-word-group { gap: 1px; padding-right: 4px; }
  .ed-wbtn { padding: 3px 5px; font-size: 11px; }
  .ed-sel  { font-size: 11px; padding: 2px 4px; }
  .ed-word-page-wrap { padding: 10px; }
  .ed-word-page {
    width: 100%;
    min-height: auto;
    padding: 16px;
    font-size: 11pt;
  }
  /* Esconder alguns botões menos usados em mobile */
  #edBtnTable, #edBtnHr, #edBtnLink { display: none; }
}
