/* Overlay Backdrop */
.preview-orc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: flex-end;
  z-index: 1100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.preview-orc-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.preview-orc-overlay--stacked {
  z-index: 1600;
}

/* Drawer Container */
.preview-orc-drawer {
  width: min(800px, 100vw);
  height: 100vh;
  background: #f8fafc;
  box-shadow: 
    -20px 0 25px -5 rgba(0, 0, 0, 0.1),
    -10px 0 10px -5px rgba(0, 0, 0, 0.04);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.preview-orc-overlay.open .preview-orc-drawer {
  transform: translateX(0);
}

/* Drawer Header */
.preview-orc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0;
  gap: 12px;
}

.preview-orc-header h3 {
  font-family: "Outfit", system-ui, -apple-system, sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: #0f172a;
  margin: 0;
  flex-shrink: 0;
  min-width: 0;
}

.preview-orc-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

#preview-orc-template-select {
  padding: 6px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 12px;
  outline: none;
  background: #fff;
  cursor: pointer;
  height: 32px;
}

#preview-orc-save-btn {
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  background-color: var(--cor-primaria, #00e5a0);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: opacity 0.2s;
  height: 32px;
  white-space: nowrap;
}

#preview-orc-save-btn:hover {
  opacity: 0.88;
}

.preview-orc-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #64748b;
  padding: 0;
  margin-left: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.preview-orc-close:hover {
  background: #f1f5f9;
  color: #0f172a;
}

/* Drawer Body */
.preview-orc-body {
  flex: 1;
  overflow-y: auto;
  padding: 32px 16px;
  background-color: #f1f5f9;
}

/* A4 Sheet Simulation */
.preview-paper-sheet {
  background: #ffffff;
  width: 100%;
  max-width: 680px;
  min-height: 960px;
  margin: 0 auto;
  box-shadow: 
    0 10px 15px -3px rgba(0, 0, 0, 0.05),
    0 4px 6px -4px rgba(0, 0, 0, 0.05),
    0 0 0 1px rgba(0, 0, 0, 0.02);
  padding: 40px;
  border-radius: 4px;
  position: relative;
  box-sizing: border-box;
}

/* Tipografia da folha — --cor-primaria vem da marca (JS), fallback #00e5a0 */
.preview-paper-sheet {
  color: #1a1a1a;
  font-family: 'Inter', -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 11px;
  line-height: 1.5;
}

/* Scrollable Table Container */
.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 24px;
}

/* ========================================== */
/* TEMPLATE CLASSICO (FPDF2 Replica)          */
/* ========================================== */
.tpl-classico {
  display: flex;
  flex-direction: column;
  min-height: 880px;
}

.tpl-classico .header-grid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.tpl-classico .brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 55%;
}

.tpl-classico .brand-logo {
  max-height: 40px;
  max-width: 120px;
  object-fit: contain;
}

.tpl-classico .brand-info { display: flex; flex-direction: column; }

.tpl-classico .empresa-nome {
  font-size: 16px;
  font-weight: 700;
  color: var(--cor-primaria, #00e5a0);
  line-height: 1.2;
  margin-bottom: 4px;
}

.tpl-classico .empresa-info { font-size: 9px; color: #737373; }

.tpl-classico .document-block { text-align: right; max-width: 40%; }

.tpl-classico .doc-title-label {
  font-size: 8px;
  font-weight: 700;
  color: #b3b3b3;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.tpl-classico .doc-number {
  font-size: 15px;
  font-weight: 700;
  color: #141414;
  margin-bottom: 6px;
}

.tpl-classico .doc-dates { font-size: 9px; color: #525252; }

.tpl-classico .header-divider {
  border: 0;
  border-top: 3px solid var(--cor-primaria, #00e5a0);
  margin: 10px 0 16px 0;
}

.tpl-classico .client-terms-box {
  background-color: #f9f9f9;
  border-left: 4px solid var(--cor-primaria, #00e5a0);
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.tpl-classico .client-col { flex: 1; }

.tpl-classico .box-section-label {
  font-size: 8px;
  font-weight: 700;
  color: #a3a3a3;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.tpl-classico .cliente-nome {
  font-size: 13px;
  font-weight: 700;
  color: #141414;
  margin-bottom: 4px;
}

.tpl-classico .cliente-detalhes {
  font-size: 9px;
  color: #525252;
  line-height: 1.4;
}

.tpl-classico .terms-col { text-align: right; min-width: 150px; }

.tpl-classico .terms-item {
  font-size: 9px;
  color: #525252;
  margin-bottom: 4px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.tpl-classico .terms-item-label { color: #525252; }
.tpl-classico .terms-item-value { font-weight: 700; color: #141414; }

.tpl-classico .items-table { width: 100%; border-collapse: collapse; }

.tpl-classico .items-table th {
  background-color: var(--cor-primaria, #00e5a0);
  color: var(--cor-sobre, #ffffff);
  font-weight: 700;
  font-size: 9px;
  text-transform: uppercase;
  padding: 8px 10px;
  text-align: left;
}

.tpl-classico .items-table th.align-center,
.tpl-classico .items-table td.align-center { text-align: center; }
.tpl-classico .items-table th.align-right,
.tpl-classico .items-table td.align-right { text-align: right; }

.tpl-classico .items-table tr.tpl-classico-item-row:nth-child(even) { background-color: #f8f9fa; }
.tpl-classico .items-table tr.tpl-classico-item-row:nth-child(odd) { background-color: #ffffff; }

.tpl-classico .items-table td {
  padding: 8px 10px;
  font-size: 10px;
  color: #1f2937;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: top;
}

.tpl-classico .items-table td.item-total { font-weight: 700; }

.tpl-classico .item-cell-desc {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.tpl-classico .item-thumbnail {
  width: 48px;
  height: 48px;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
  object-fit: cover;
  flex-shrink: 0;
  background-color: #f8fafc;
}

.tpl-classico .item-title { font-weight: 600; }
.tpl-classico .item-obs { font-size: 8px; color: #6b7280; margin-top: 2px; }

.tpl-classico .summary-wrapper {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 24px;
}

.tpl-classico .summary-table { width: 220px; border-collapse: collapse; }

.tpl-classico .summary-table td { padding: 6px 8px; font-size: 10px; }
.tpl-classico .summary-table td.label { color: #4b5563; }
.tpl-classico .summary-table td.val { text-align: right; font-weight: 600; color: #111827; }

.tpl-classico .summary-table tr.subtotal-row td { background: #f5f5f5; }
.tpl-classico .summary-table tr.discount-row td { background: #fff5f5; color: #c83c3c; }
.tpl-classico .summary-table tr.discount-row td.val { color: #c83c3c; }

.tpl-classico .summary-table tr.summary-total td {
  padding: 10px 8px;
  font-size: 12px;
  font-weight: 800;
  background: var(--cor-primaria, #00e5a0);
  color: var(--cor-sobre, #ffffff);
  border-top: none;
}

.tpl-classico .summary-table tr.summary-total td.label {
  color: var(--cor-sobre, #ffffff);
}

.tpl-classico .summary-table tr.summary-total td.val {
  color: var(--cor-sobre, #ffffff);
  font-size: 13px;
}

.tpl-classico .footer-sections {
  border-top: 1px solid #f1f5f9;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.tpl-classico .section-block-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: #9ca3af;
  margin-bottom: 6px;
  letter-spacing: 0.05em;
}

.tpl-classico .section-block-content {
  font-size: 9.5px;
  color: #374151;
  white-space: pre-wrap;
}

.tpl-classico .aceite-box {
  background: #f0fff5;
  border-left: 4px solid #009632;
  padding: 10px 14px;
  margin-bottom: 16px;
}

.tpl-classico .aceite-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: #007828;
  margin-bottom: 4px;
}

.tpl-classico .aceite-body { font-size: 10px; color: #141414; }

.tpl-page-footer {
  margin-top: auto;
  padding-top: 28px;
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
  min-height: 36px;
}

.tpl-page-footer--classic {
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid #dcdcdc;
  padding-top: 10px;
}

.tpl-page-footer-meta {
  font-size: 7px;
  color: #bebebe;
  line-height: 1.3;
}

.tpl-page-footer-brand {
  font-size: 7px;
  font-weight: 400;
  color: #c8c8c8;
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

/* ========================================== */
/* TEMPLATE MODERNO (paridade WeasyPrint PDF) */
/* ========================================== */
.tpl-moderno {
  display: flex;
  flex-direction: column;
  min-height: 880px;
}

.tpl-moderno .layout-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.tpl-moderno .layout-table td {
  vertical-align: top;
  padding: 0;
}

.tpl-moderno .header {
  margin-bottom: 20px;
  padding-bottom: 14px;
  border-bottom: 3px solid var(--cor-primaria, #00e5a0);
}

.tpl-moderno .logo-img {
  max-height: 50px;
  margin-bottom: 6px;
  display: block;
}

.tpl-moderno .empresa-nome {
  font-size: 18px;
  font-weight: 700;
  color: var(--cor-primaria, #00e5a0);
  margin-bottom: 4px;
}

.tpl-moderno .empresa-info {
  font-size: 10px;
  color: #666;
  line-height: 1.45;
}

.tpl-moderno .document-info {
  text-align: right;
}

.tpl-moderno .document-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #999;
  font-weight: 600;
  margin-bottom: 2px;
}

.tpl-moderno .document-number {
  font-size: 22px;
  font-weight: 800;
  color: #000;
  margin-bottom: 6px;
}

.tpl-moderno .document-meta {
  font-size: 10px;
  color: #666;
  line-height: 1.45;
}

.tpl-moderno .info-box {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
  background: #f9f9f9;
}

.tpl-moderno .info-box td {
  padding: 12px 14px;
  vertical-align: top;
}

.tpl-moderno .info-box .accent {
  width: 4px;
  padding: 0;
  background: var(--cor-primaria, #00e5a0);
}

.tpl-moderno .info-label {
  font-size: 8px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #b4b4b4;
  font-weight: 700;
  margin-bottom: 6px;
}

.tpl-moderno .info-label.right {
  text-align: right;
}

.tpl-moderno .cliente-nome {
  font-size: 13px;
  font-weight: 700;
  color: #141414;
  margin-bottom: 4px;
}

.tpl-moderno .cliente-detail {
  font-size: 9px;
  color: #646464;
  line-height: 1.5;
}

.tpl-moderno .condicoes-row {
  font-size: 9px;
  color: #646464;
  text-align: right;
  margin-top: 4px;
}

.tpl-moderno .condicoes-row strong {
  color: #141414;
  font-weight: 700;
}

.tpl-moderno .items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

.tpl-moderno .items-table th {
  padding: 9px 10px;
  text-align: left;
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cor-sobre, #ffffff);
  background: var(--cor-primaria, #00e5a0);
  border-bottom: none;
}

.tpl-moderno .items-table td {
  padding: 10px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: top;
  font-size: 10px;
}

.tpl-moderno .items-table .text-right {
  text-align: right;
}

.tpl-moderno .items-table .text-center {
  text-align: center;
}

.tpl-moderno .item-desc {
  font-weight: 600;
  color: #000;
  margin-bottom: 2px;
}

.tpl-moderno .item-sub {
  font-size: 9px;
  color: #777;
}

.tpl-moderno .item-thumb {
  float: left;
  width: 72px;
  height: 72px;
  margin-right: 10px;
  border-radius: 4px;
  overflow: hidden;
  background-color: #f5f5f5;
  border: 1px solid #eee;
}

.tpl-moderno .item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.tpl-moderno .summary-wrap {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 28px;
}

.tpl-moderno .summary-wrap > tbody > tr > td {
  padding: 0;
  vertical-align: top;
}

.tpl-moderno .summary-table {
  width: 240px;
  border-collapse: collapse;
  margin-left: auto;
}

.tpl-moderno .summary-table td {
  padding: 7px 8px;
  font-size: 11px;
}

.tpl-moderno .summary-table .label {
  color: #666;
}

.tpl-moderno .summary-table .value {
  text-align: right;
  font-weight: 600;
}

.tpl-moderno .summary-table .discount .value {
  color: #dc2626;
}

.tpl-moderno .summary-table .summary-total td {
  padding: 10px 8px;
  font-size: 13px;
  font-weight: 800;
  background: var(--cor-primaria, #00e5a0);
  color: var(--cor-sobre, #ffffff);
  border-top: none;
}

.tpl-moderno .summary-table .summary-total td.label,
.tpl-moderno .summary-table .summary-total td.value {
  color: var(--cor-sobre, #ffffff);
}

.tpl-moderno .footer-blocks {
  margin-top: 8px;
}

.tpl-moderno .block {
  margin-bottom: 18px;
}

.tpl-moderno .block-title {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  color: #999;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.tpl-moderno .block-content {
  font-size: 10px;
  color: #444;
  white-space: pre-wrap;
}

/* ========================================== */
/* RESPONSIVE MEDIA QUERIES (MOBILE LAYOUTS)  */
/* ========================================== */
[data-theme="dark"] .preview-orc-drawer { background: var(--surface); box-shadow: -20px 0 25px -5px rgba(0,0,0,0.4), -10px 0 10px -5px rgba(0,0,0,0.2); }
[data-theme="dark"] .preview-orc-header { background: var(--surface2); border-color: var(--border); }
[data-theme="dark"] .preview-orc-header h3 { color: var(--text); }
[data-theme="dark"] .preview-orc-close { color: var(--muted); }
[data-theme="dark"] .preview-orc-close:hover { background: rgba(255,255,255,0.06); color: var(--text); }
[data-theme="dark"] .preview-orc-body { background-color: var(--bg); }

@media (max-width: 768px) {
  .preview-orc-body {
    padding: 16px 8px;
  }

  .preview-paper-sheet {
    padding: 20px 16px;
    min-height: auto;
    border-radius: 4px;
  }

  .table-container {
    margin-bottom: 16px;
  }

  .tpl-classico .items-table,
  .tpl-moderno .items-table {
    min-width: 580px;
  }

  .tpl-classico .header-grid {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }

  .tpl-classico .brand-block {
    max-width: 100%;
    flex-direction: row;
    gap: 12px;
  }

  .tpl-classico .document-block {
    text-align: left;
    max-width: 100%;
    border-top: 1px solid #f1f5f9;
    padding-top: 12px;
  }

  .tpl-classico .client-terms-box {
    flex-direction: column;
    gap: 16px;
    padding: 12px;
  }

  .tpl-classico .terms-col {
    text-align: left;
    min-width: 100%;
    border-top: 1px dotted #e5e7eb;
    padding-top: 12px;
  }

  .tpl-classico .terms-item {
    justify-content: flex-start;
  }

  .tpl-classico .summary-wrapper {
    justify-content: flex-start;
  }

  .tpl-classico .summary-table {
    width: 100%;
  }

  .tpl-page-footer--classic {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .tpl-moderno {
    min-height: auto;
  }

  .tpl-moderno .document-info {
    text-align: left;
  }

  .tpl-moderno .layout-table.header td {
    display: block;
    width: 100% !important;
  }

  .tpl-moderno .layout-table.header td + td {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #eee;
  }

  .tpl-moderno .info-box td.accent {
    display: none;
  }

  .tpl-moderno .info-box td {
    display: block;
    width: 100% !important;
  }

  .tpl-moderno .info-label.right,
  .tpl-moderno .condicoes-row {
    text-align: left;
  }

  .tpl-moderno .summary-table {
    width: 100%;
    margin-left: 0;
  }
}
