/* ═══════════════════════════════════════
   TBS — Criar Documento (Editor)
   Estilos exclusivos da página de criação
   de orçamentos, contratos e recibos
═══════════════════════════════════════ */

/* ─── LAYOUT DO EDITOR ─── */
.orc-layout {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 24px;
  align-items: start;
  min-width: 0;
}
.orc-layout > * { min-width: 0; }

/* ─── SEÇÕES DO FORMULÁRIO ─── */
.form-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  margin-bottom: 16px;
}
.form-section-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 700;
  color: var(--white);
  display: flex;
  align-items: center;
  gap: 8px;
}
.form-section-body { padding: 20px; }

/* ─── GRID E INPUTS DO FORMULÁRIO ─── */
.form-grid   { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group  { display: flex; flex-direction: column; gap: 6px; }
.form-label  {
  font-size: 11px;
  font-weight: 700;
  color: var(--text2);
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.form-input {
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13px;
  color: var(--text);
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 500;
  transition: border-color 0.18s;
  width: 100%;
}
.form-input:focus         { outline: none; border-color: rgba(90,24,154,0.5); }
.form-input::placeholder  { color: var(--text3); }

/* ─── TABELA DE ITENS ─── */
.orc-items-table { width: 100%; table-layout: auto; }
.orc-items-table th {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.orc-items-table td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 12.5px;
  white-space: nowrap;
}
.orc-items-table td:first-child,
.orc-items-table th:first-child { white-space: normal; min-width: 0; width: auto; }
.orc-items-table tr:last-child td { border-bottom: none; }

.add-item-row {
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.add-item-row:hover { background: rgba(90,24,154,0.05); }

/* ─── ITEM CARD (painel de itens estilo card) ─── */
.item-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  display: flex; flex-direction: column; gap: 5px;
}
.item-card-row { display: flex; gap: 5px; align-items: center; }
.item-card input {
  background: var(--surface3);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 5px 7px;
  font-size: 12px;
  color: var(--text);
  font-family: 'Plus Jakarta Sans', sans-serif;
  outline: none;
  transition: border-color .15s;
}
.item-card input:focus { border-color: rgba(109,40,217,0.5); }
.item-card .ic-desc  { flex: 1; }
.item-card .ic-num   { width: 48px; text-align: center; }
.item-card .ic-del   {
  width: 24px; height: 24px; border-radius: 6px;
  background: transparent; border: none;
  color: var(--text3); font-size: 13px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; flex-shrink: 0;
}
.item-card .ic-del:hover  { background: rgba(244,63,94,0.15); color: var(--red); }
.item-card .ic-total {
  font-size: 13px; font-weight: 800; color: var(--green);
  text-align: right; min-width: 70px; flex-shrink: 0;
}

/* ─── PAINEL LATERAL (resumo / total) ─── */
.summary-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  position: sticky;
  top: calc(var(--topbar-h) + 28px);
  min-width: 0;
  max-width: 100%;
}
.summary-panel-header {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 700;
  color: var(--white);
}
.summary-panel-body { padding: 16px 20px; }
.line-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.line-item:last-child { border-bottom: none; }
.line-label { font-size: 13px; color: var(--text2); font-weight: 500; }
.line-value { font-size: 13px; color: var(--white); font-weight: 600; }
.total-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(90,24,154,0.1);
  border: 1px solid rgba(90,24,154,0.2);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 16px 0;
}
.total-label  { font-size: 13px; font-weight: 700; color: var(--text2); }
.total-value  {
  font-family: 'Epilogue', sans-serif;
  font-size: 26px;
  font-weight: 900;
  color: var(--green);
  letter-spacing: -0.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── BOTÕES DE IA (painel) ─── */
.ai-actions    { display: flex; gap: 8px; margin-bottom: 16px; }
.ai-action-btn {
  flex: 1;
  background: rgba(90,24,154,0.12);
  border: 1px solid rgba(90,24,154,0.25);
  border-radius: 12px;
  padding: 11px 10px;
  text-align: center;
  cursor: pointer;
  transition: all 0.18s;
  font-family: 'Plus Jakarta Sans', sans-serif;
}
.ai-action-btn:hover              { background: rgba(90,24,154,0.2); }
.ai-action-btn div:first-child    { font-size: 20px; margin-bottom: 4px; }
.ai-action-btn div:last-child     { font-size: 11px; font-weight: 600; color: var(--purple); }

/* ─── ABAS DO EDITOR (tipos: Orçamento, Contrato, Recibo) ─── */
.editor-tab-btn {
  background: transparent; border: none; color: var(--text2);
  padding: 6px 14px; border-radius: 8px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: 'Plus Jakarta Sans', sans-serif; transition: all .18s;
}
.editor-tab-btn.active { background: var(--surface3); color: var(--white); }

.doc-tipo-btn {
  background: var(--surface2); border: 1px solid var(--border2); color: var(--text2);
  padding: 7px 16px; border-radius: 10px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: 'Plus Jakarta Sans', sans-serif; transition: all .18s;
}
.doc-tipo-btn.active           { background: rgba(109,40,217,0.18); border-color: rgba(109,40,217,0.4); color: var(--accent-light); }
.doc-tipo-btn:hover:not(.active) { background: var(--surface3); color: var(--white); }

/* ─── RICH TEXT EDITOR ─── */
.rt-group   { display: flex; gap: 2px; }
.rt-btn {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text2);
  width: 30px; height: 28px; border-radius: 6px; font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; transition: all .15s;
  font-family: 'Plus Jakarta Sans', sans-serif;
}
.rt-btn:hover              { background: var(--surface3); color: var(--white); border-color: var(--border2); }
.rt-btn-danger:hover       { color: var(--red); border-color: rgba(244,63,94,0.4); }
.rt-select {
  background: var(--surface2); border: 1px solid var(--border); color: var(--text2);
  height: 28px; border-radius: 6px; font-size: 11.5px; padding: 0 6px; cursor: pointer;
  font-family: 'Plus Jakarta Sans', sans-serif;
}
.rt-color {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid var(--border);
  padding: 2px; cursor: pointer; background: var(--surface2);
}
.rt-sep { width: 1px; background: var(--border2); margin: 0 2px; align-self: stretch; }

#rich-editor:focus { outline: none; }
#rich-editor h1, #rich-editor h2, #rich-editor h3 { font-family: 'Epilogue', sans-serif; }
#rich-editor table                                 { border-collapse: collapse; width: 100%; table-layout: auto; }
#rich-editor td, #rich-editor th                   { white-space: normal; overflow-wrap: break-word; min-width: 60px; }
#rich-editor td:first-child, #rich-editor th:first-child { min-width: 120px; }
#rich-editor td, #rich-editor th                   { border: 1px solid rgba(255,255,255,0.1); padding: 6px 10px; }
#rich-editor                                       { overflow-x: hidden; }
#rich-editor > div > table,
#rich-editor > div > div > table                   { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
#rich-editor > div                                 { overflow-x: auto; }

/* ─── INPUTS LEGADOS (tabela antiga) ─── */
.item-input {
  background: transparent; border: none; outline: none; color: var(--text);
  font-family: 'Plus Jakarta Sans', sans-serif; font-size: 13px; width: 100%;
  padding: 4px 0; min-width: 0;
}
.item-input:focus                  { border-bottom: 1px solid rgba(109,40,217,0.4); }
.item-input.item-num               { text-align: center; width: 100%; padding: 4px 2px; font-size: 12px; }
.item-del                          { color: var(--text3); cursor: pointer; font-size: 14px; padding: 4px; transition: color .15s; }
.item-del:hover                    { color: var(--red); }

/* ─── DOCUMENTO RENDERIZADO (preview) ─── */
#doc-live { color: #1a1a2e; }

/* ─── MODAL DE SELEÇÃO DE MODELOS ─── */
.msm-filtro {
  background: var(--surface2); border: 1px solid var(--border2);
  color: var(--text2); border-radius: 20px; padding: 4px 11px;
  font-size: 11px; font-weight: 600; cursor: pointer;
  font-family: 'Plus Jakarta Sans', sans-serif; transition: all .15s;
  white-space: nowrap;
}
.msm-filtro.active         { background: var(--accent); color: white; border-color: var(--accent); }
.msm-filtro:hover:not(.active) { color: var(--white); border-color: var(--border2); }

.msm-card {
  border: 2px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: all .15s;
  background: var(--surface2);
  position: relative;
  padding: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.msm-card:hover    { border-color: rgba(109,40,217,0.5); background: var(--surface3); }
.msm-card.selected { border-color: var(--accent); background: rgba(109,40,217,0.1); box-shadow: 0 0 0 2px rgba(109,40,217,0.2); }
.msm-card.selected::after {
  content: '✓'; position: absolute; top: 8px; right: 8px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: white;
  font-size: 11px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.msm-thumb {
  background: white; border-radius: 6px;
  height: 100px; overflow: hidden;
  pointer-events: none;
  font-family: 'Plus Jakarta Sans', Arial, sans-serif;
  transform: scale(0.7); transform-origin: top left;
  width: calc(100% / 0.7);
  margin-bottom: calc(-100px * 0.3);
}
.msm-preview { display: none; }
.msm-footer  { display: none; }

.tipo-pill {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px; border-radius: 9px;
  background: transparent; border: 1px solid transparent;
  color: var(--text2); font-size: 12.5px; font-weight: 600;
  cursor: pointer; font-family: 'Plus Jakarta Sans', sans-serif;
  transition: all .15s; text-align: left;
}
.tipo-pill:hover { background: var(--surface2); color: var(--white); }
.tipo-pill.active {
  background: rgba(109,40,217,0.18);
  border-color: rgba(109,40,217,0.4);
  color: var(--accent-light);
}
.tipo-pill span { font-size: 15px; }

.cor-paleta {
  cursor: pointer; border-radius: 8px;
  border: 2px solid transparent;
  padding: 2px; transition: all .15s;
}
.cor-paleta.active, .cor-paleta:hover { border-color: var(--white); transform: scale(1.1); }

/* ─── MODELOS SALVOS ─── */
.modelo-item {
  padding: 8px 10px; border-radius: 9px; font-size: 12px; font-weight: 600;
  color: var(--text2); cursor: pointer; transition: all .15s; border: 1px solid transparent;
}
.modelo-item:hover { background: var(--surface2); color: var(--white); border-color: var(--border); }

.modelo-salvo {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px;
  background: var(--surface2); border: 1px solid var(--border);
  cursor: pointer; transition: all .15s; position: relative;
}
.modelo-salvo:hover        { border-color: rgba(109,40,217,0.35); background: rgba(109,40,217,0.06); }
.modelo-salvo-info         { flex: 1; min-width: 0; }
.modelo-salvo-nome         { font-size: 12.5px; font-weight: 600; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.modelo-salvo-meta         { font-size: 10.5px; color: var(--text3); margin-top: 2px; }
.modelo-salvo-del          { color: var(--text3); font-size: 13px; padding: 2px 4px; border-radius: 5px; flex-shrink: 0; transition: all .15s; }
.modelo-salvo-del:hover    { color: var(--red); background: rgba(244,63,94,0.1); }

/* ─── CARD DE MODELOS (galeria) ─── */
.modelo-card {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--border); cursor: pointer; transition: all .15s;
  background: var(--surface2);
}
.modelo-card:hover     { border-color: rgba(109,40,217,0.4); background: rgba(109,40,217,0.07); transform: translateX(2px); }
.modelo-card-icon      { font-size: 20px; flex-shrink: 0; width: 32px; text-align: center; }
.modelo-card-info      { flex: 1; min-width: 0; }
.modelo-card-nome      { font-size: 12.5px; font-weight: 600; color: var(--white); }
.modelo-card-meta      { font-size: 10.5px; color: var(--text3); margin-top: 1px; }
.modelo-card-arr       { font-size: 14px; color: var(--text3); flex-shrink: 0; }

/* ─── EMOJI PICKER (catálogo de ícones) ─── */
.ep-opt {
  font-size: 20px; cursor: pointer; padding: 4px; border-radius: 6px;
  transition: background .12s; display: inline-block;
}
.ep-opt:hover          { background: var(--surface2); }
#emoji-picker-grid     { display: none; }
#emoji-picker-grid.open { display: flex; }

/* ─── CHIP EXTRAS ─── */
.chip-extra {
  display: flex; align-items: center; gap: 5px;
  background: var(--surface2); border: 1px solid var(--border2);
  border-radius: 20px; padding: 5px 10px;
  font-size: 11px; font-weight: 600; color: var(--text2);
  cursor: pointer; transition: all .15s;
  font-family: 'Plus Jakarta Sans', sans-serif; white-space: nowrap;
}
.chip-extra.selected {
  background: rgba(109,40,217,0.15);
  border-color: rgba(109,40,217,0.5);
  color: var(--accent-light);
}

/* ─── RESPONSIVO EDITOR ─── */
@media (max-width: 1100px) {
  #editor-3col { grid-template-columns: 220px 1fr 260px !important; }
}
@media (max-width: 900px) {
  #editor-3col { grid-template-columns: 1fr !important; }
}
@media (max-width: 768px) {
  #editor-3col { grid-template-columns: 1fr !important; }
}

/* Modal de modelos: responsivo */
@media (max-width: 700px) {
  #msm-body { grid-template-columns: 1fr !important; overflow-y: auto; }
  #msm-preview-col {
    display: none !important;
    border-top: 1px solid var(--border);
    padding: 14px !important;
    max-height: 52vh;
  }
  #msm-preview-col.msm-visible { display: flex !important; }
  .msm-thumb { height: 80px !important; }
}
@media (max-width: 480px) {
  #modal-selecionar-modelo > div {
    border-radius: 16px !important;
    margin: 0 6px !important;
    max-height: 96vh !important;
  }
}

/* ── Tema Claro ── */
[data-tema="light"] .form-section-header,
[data-tema="light"] .summary-panel-header,
[data-tema="light"] .line-value,
[data-tema="light"] .modelo-salvo-nome,
[data-tema="light"] .modelo-card-nome { color: var(--text) !important; }
[data-tema="light"] .doc-tipo-btn:hover:not(.active),
[data-tema="light"] .rt-btn:hover,
[data-tema="light"] .tipo-pill:hover,
[data-tema="light"] .modelo-item:hover,
[data-tema="light"] .modelo-salvo:hover,
[data-tema="light"] .modelo-card:hover { color: var(--text) !important; }
