/* 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;
}

/* Common template variables & text styles */
.preview-paper-sheet {
  --cor-primaria: #00e5a0;
  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;
}

.tpl-classico .header-top-bar {
  height: 3px;
  background-color: var(--cor-primaria);
  margin-bottom: 20px;
}

.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);
  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: 1px solid var(--cor-primaria);
  margin: 10px 0 16px 0;
  opacity: 0.7;
}

/* Client & Terms Box */
.tpl-classico .client-terms-box {
  background-color: #f9f9f9;
  border-left: 4px solid var(--cor-primaria);
  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;
}

/* Items Table */
.tpl-classico .items-table {
  width: 100%;
  border-collapse: collapse;
}

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

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

.tpl-classico .items-table th.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 .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;
}

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

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

.tpl-classico .summary-table td {
  padding: 6px 0;
  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.total-row td {
  border-top: 1px solid #e5e7eb;
  padding-top: 10px;
  font-size: 13px;
  font-weight: 700;
}

.tpl-classico .summary-table tr.total-row td.val {
  color: var(--cor-primaria);
  font-size: 14px;
}

/* Notes & Conditions */
.tpl-classico .footer-sections {
  border-top: 1px solid #f1f5f9;
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 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 .tpl-footer-bottom {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  font-size: 8px;
  color: #9ca3af;
}

/* ========================================== */
/* TEMPLATE MODERNO (Jinja2 HTML Replica)     */
/* ========================================== */
.tpl-moderno {
  display: flex;
  flex-direction: column;
}

.tpl-moderno .header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 30px;
  padding-bottom: 16px;
  border-bottom: 1px solid #eee;
}

.tpl-moderno .brand {
  flex: 1;
}

.tpl-moderno .logo-img {
  max-height: 48px;
  margin-bottom: 10px;
  border-radius: 6px;
}

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

.tpl-moderno .empresa-info {
  font-size: 9.5px;
  color: #666;
}

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

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

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

.tpl-moderno .document-meta {
  font-size: 9.5px;
  color: #666;
}

/* Info Grid */
.tpl-moderno .info-grid {
  display: flex;
  gap: 30px;
  margin-bottom: 30px;
}

.tpl-moderno .info-block {
  flex: 1;
}

.tpl-moderno .info-label {
  font-size: 8.5px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #999;
  font-weight: 700;
  margin-bottom: 8px;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 4px;
}

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

.tpl-moderno .cliente-detail {
  font-size: 9.5px;
  color: #444;
}

.tpl-moderno .badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 8.5px;
  font-weight: 700;
  text-transform: uppercase;
}

.tpl-moderno .badge-success {
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
}

.tpl-moderno .badge-other {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #e5e7eb;
}

/* Table */
.tpl-moderno .items-table {
  width: 100%;
  border-collapse: collapse;
}

.tpl-moderno .items-table th {
  padding: 10px 8px;
  text-align: left;
  font-size: 8.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #666;
  background: #fcfcfc;
  border-bottom: 2px solid #eee;
}

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

.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: 8.5px;
  color: #777;
}

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

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

/* Totals */
.tpl-moderno .summary-container {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 30px;
}

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

.tpl-moderno .summary-table td {
  padding: 6px 0;
  font-size: 9.5px;
}

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

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

.tpl-moderno .summary-table .total-row td {
  padding-top: 12px;
  border-top: 1px solid #eee;
  font-size: 14px;
  font-weight: 800;
  color: var(--cor-primaria);
}

/* Notes & Conditions */
.tpl-moderno .footer-blocks {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.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: 9px;
  color: #444;
  white-space: pre-wrap;
}

.tpl-moderno .footer-bottom {
  margin-top: 40px;
  padding-top: 16px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  font-size: 8px;
  color: #bbb;
}

/* ========================================== */
/* RESPONSIVE MEDIA QUERIES (MOBILE LAYOUTS)  */
/* ========================================== */
/* Dark mode — drawer chrome only, A4 paper stays white */
[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) {
  /* Scale down spacing & sizes of body */
  .preview-orc-body {
    padding: 16px 8px;
  }
  
  .preview-paper-sheet {
    padding: 20px 16px;
    min-height: auto;
    border-radius: 4px;
  }

  /* Force table container to scroll horizontally on mobile */
  .table-container {
    margin-bottom: 16px;
  }

  .tpl-classico .items-table,
  .tpl-moderno .items-table {
    min-width: 580px; /* Ensure table elements are readable and don't squeeze */
  }

  /* --- CLASSIC MOBILE OVERRIDES --- */
  .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-classico .tpl-footer-bottom {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }

  /* --- MODERN MOBILE OVERRIDES --- */
  .tpl-moderno .header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }

  .tpl-moderno .document-info {
    text-align: left;
    border-top: 1px solid #eee;
    padding-top: 12px;
  }

  .tpl-moderno .info-grid {
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
  }

  .tpl-moderno .summary-container {
    justify-content: flex-start;
  }

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

  .tpl-moderno .footer-bottom {
    flex-direction: column;
    gap: 10px;
    text-align: center;
  }
}
