/* ==========================================================================
   XESTUS BIZCRAFT - INVOICE & QUOTATION MODULE STYLES
   Split screen builder, dynamic line items, multi-template live preview.
   Ultra-responsive across mobile, tablet, and desktop screens.
   ========================================================================== */

.studio-layout {
  display: grid;
  grid-template-columns: minmax(440px, 1fr) minmax(500px, 1fr);
  gap: var(--space-xl);
  align-items: start;
}

@media (max-width: 1180px) {
  .studio-layout {
    grid-template-columns: 1fr;
  }
}

/* Left Editor Column */
.editor-pane {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
  min-width: 0;
}

.editor-section {
  background: var(--bg-surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}

@media (max-width: 600px) {
  .editor-section {
    padding: var(--space-md);
  }
}

.editor-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--border-subtle);
  flex-wrap: wrap;
  gap: 8px;
}

.editor-section-header h3 {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Line Items Table in Editor */
.line-items-editor-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: var(--space-md);
  min-width: 600px;
}

.line-items-editor-table th {
  text-align: left;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border-subtle);
}

.line-items-editor-table td {
  padding: 6px 4px;
  vertical-align: top;
}

.line-item-row {
  transition: background var(--transition-fast);
}

.line-item-row:hover {
  background: var(--bg-surface-hover);
}

.line-item-row .form-input,
.line-item-row .form-select {
  padding: 8px 10px;
  font-size: 0.88rem;
}

/* Right Preview Column */
.preview-pane {
  position: sticky;
  top: 96px;
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  min-width: 0;
}

@media (max-width: 1180px) {
  .preview-pane {
    position: static;
  }
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
  gap: 10px;
}

.preview-toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* --------------------------------------------------------------------------
   DOCUMENT PAPER PREVIEW (A4 Ratio Standard)
   -------------------------------------------------------------------------- */
.paper-scroll-wrapper {
  max-height: calc(100vh - 170px);
  overflow-y: auto;
  overflow-x: auto;
  padding: 12px;
  background: var(--bg-canvas);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  display: flex;
  justify-content: center;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 1180px) {
  .paper-scroll-wrapper {
    max-height: none;
    padding: 8px 0;
  }
}

.document-paper {
  width: 100%;
  max-width: 820px;
  min-height: 1080px;
  background-color: var(--paper-bg);
  color: var(--paper-text);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  border-radius: 4px;
  padding: 44px 48px;
  font-family: var(--font-sans);
  position: relative;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

@media (max-width: 768px) {
  .document-paper {
    padding: 24px 20px;
    min-height: auto;
    font-size: 0.88rem;
  }
}

/* Paper Header */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 28px;
  border-bottom: 2px solid #f1f5f9;
  padding-bottom: 20px;
  flex-wrap: wrap;
}

.doc-logo-title {
  display: flex;
  align-items: center;
  gap: 16px;
}

.doc-brand-logo {
  max-width: 120px;
  max-height: 60px;
  object-fit: contain;
}

.doc-company-title {
  font-size: 1.45rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
}

.doc-company-sub {
  font-size: 0.82rem;
  color: #475569;
  margin-top: 4px;
  line-height: 1.4;
}

.doc-meta-box {
  text-align: right;
  margin-left: auto;
}

@media (max-width: 600px) {
  .doc-meta-box {
    text-align: left;
    margin-left: 0;
    width: 100%;
  }
  .doc-meta-table {
    margin-left: 0 !important;
  }
  .doc-meta-table td.lbl {
    text-align: left !important;
  }
}

.doc-type-badge {
  display: inline-block;
  font-size: 1.3rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #4f46e5;
  margin-bottom: 6px;
}

.doc-meta-table {
  font-size: 0.85rem;
  margin-left: auto;
  color: #334155;
}

.doc-meta-table td {
  padding: 3px 6px;
}

.doc-meta-table td.lbl {
  font-weight: 600;
  color: #64748b;
  text-align: right;
}

.doc-meta-table td.val {
  font-family: var(--font-mono);
  font-weight: 600;
  color: #0f172a;
  text-align: right;
}

/* Bill To / Ship To Grid */
.doc-parties-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-bottom: 24px;
  background: #f8fafc;
  padding: 16px 20px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}

@media (max-width: 600px) {
  .doc-parties-grid {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 12px 14px;
  }
}

.party-block h4 {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #64748b;
  margin-bottom: 8px;
}

.party-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.party-details {
  font-size: 0.84rem;
  color: #475569;
  line-height: 1.45;
}

/* Line Items Display Table */
.doc-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 24px;
}

.doc-items-table th {
  background: #f1f5f9;
  color: #334155;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  border-top: 1px solid #cbd5e1;
  border-bottom: 2px solid #cbd5e1;
  text-align: left;
}

.doc-items-table th.num,
.doc-items-table td.num {
  text-align: right;
  font-family: var(--font-mono);
}

.doc-items-table td {
  padding: 11px 12px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.88rem;
  color: #1e293b;
  vertical-align: top;
}

.doc-item-desc {
  font-weight: 600;
  color: #0f172a;
}

/* Calculation & Summary Section */
.doc-summary-section {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 28px;
  margin-bottom: 28px;
  align-items: start;
}

@media (max-width: 768px) {
  .doc-summary-section {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

.doc-payment-info {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 16px;
  font-size: 0.84rem;
}

.doc-payment-title {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #475569;
  margin-bottom: 8px;
}

.doc-bank-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  font-size: 0.82rem;
  color: #334155;
}

.doc-bank-grid .lbl {
  color: #64748b;
  font-weight: 600;
}

.doc-bank-grid .val {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* Integrated UPI QR in Invoice */
.doc-upi-qr-card {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed #cbd5e1;
  display: flex;
  align-items: center;
  gap: 12px;
}

.doc-upi-canvas {
  width: 78px;
  height: 78px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  padding: 3px;
  flex-shrink: 0;
}

.doc-upi-text {
  font-size: 0.78rem;
  color: #475569;
}
.doc-upi-text strong {
  color: #0f172a;
  font-size: 0.82rem;
  display: block;
  margin-bottom: 2px;
}

/* Totals Table */
.doc-totals-table {
  width: 100%;
  font-size: 0.88rem;
  border-collapse: collapse;
}

.doc-totals-table td {
  padding: 6px 8px;
  color: #475569;
}

.doc-totals-table td.num {
  text-align: right;
  font-family: var(--font-mono);
  font-weight: 600;
  color: #1e293b;
}

.doc-totals-table tr.total-row td {
  border-top: 2px solid #0f172a;
  border-bottom: 2px solid #0f172a;
  padding: 10px 8px;
  font-size: 1.15rem;
  font-weight: 800;
  color: #0f172a;
}

.doc-amount-words {
  font-size: 0.82rem;
  font-weight: 600;
  color: #475569;
  margin-top: 10px;
  padding: 8px 12px;
  background: #f1f5f9;
  border-radius: 6px;
  line-height: 1.4;
}
.doc-amount-words strong {
  color: #0f172a;
  text-transform: uppercase;
  font-size: 0.72rem;
  display: block;
  margin-bottom: 2px;
}

/* Footer & Signatures */
.doc-footer-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  padding-top: 20px;
  border-top: 1px solid #e2e8f0;
  margin-top: auto;
  flex-wrap: wrap;
}

.doc-terms {
  max-width: 420px;
  font-size: 0.76rem;
  color: #64748b;
  line-height: 1.45;
}

.doc-terms-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  color: #475569;
  margin-bottom: 4px;
}

.doc-signature-block {
  text-align: center;
  min-width: 180px;
  margin-left: auto;
}

@media (max-width: 600px) {
  .doc-signature-block {
    margin-left: 0;
    width: 100%;
    margin-top: 16px;
  }
}

.doc-signature-img {
  max-height: 52px;
  max-width: 160px;
  margin-bottom: 4px;
  object-fit: contain;
}

.doc-signature-line {
  border-top: 1px solid #0f172a;
  padding-top: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #0f172a;
}

.doc-signature-title {
  font-size: 0.72rem;
  color: #64748b;
}

/* --------------------------------------------------------------------------
   TEMPLATE THEME VARIANTS
   -------------------------------------------------------------------------- */
.template-apex-modern .doc-type-badge { color: #4f46e5; }
.template-apex-modern .doc-items-table th { background: #f8fafc; border-bottom: 2px solid #4f46e5; color: #1e293b; }

.template-executive-slate .doc-header { border-bottom: 3px solid #0f172a; }
.template-executive-slate .doc-type-badge { color: #0f172a; }
.template-executive-slate .doc-items-table th { background: #0f172a; color: #ffffff; border: none; }
.template-executive-slate .party-block h4 { color: #0f172a; }

.template-emerald-luxe .doc-type-badge { color: #059669; }
.template-emerald-luxe .doc-header { border-bottom: 2px solid #10b981; }
.template-emerald-luxe .doc-items-table th { background: #ecfdf5; color: #065f46; border-bottom: 2px solid #10b981; }
.template-emerald-luxe .doc-totals-table tr.total-row td { border-color: #059669; color: #065f46; }

.template-cyber-minimal { font-family: var(--font-mono); }
.template-cyber-minimal .doc-type-badge { color: #2563eb; font-weight: 900; }
.template-cyber-minimal .doc-parties-grid { border: 1px solid #0f172a; background: #ffffff; border-radius: 0; }
.template-cyber-minimal .doc-items-table th { background: #ffffff; border-top: 2px solid #0f172a; border-bottom: 2px solid #0f172a; }
