/* ==========================================================================
   RAJARATA FIRE SERVICE - QUOTATION & INVOICE MANAGEMENT SYSTEM
   Professional Business Interface & Print Stylesheet
   ========================================================================== */

:root {
  --primary: #D32F2F;
  --primary-hover: #B71C1C;
  --primary-light: #FFEBEE;
  --primary-dark: #9A0007;
  --primary-glow: rgba(211, 47, 47, 0.25);
  
  --secondary: #1E293B;
  --secondary-light: #334155;
  --secondary-dark: #0F172A;
  
  --accent-amber: #D97706;
  --accent-amber-light: #FEF3C7;
  --accent-green: #059669;
  --accent-green-light: #D1FAE5;
  --accent-blue: #2563EB;
  --accent-blue-light: #DBEAFE;
  
  --bg-page: #F1F5F9;
  --bg-card: #FFFFFF;
  --bg-input: #FFFFFF;
  --bg-input-focus: #FFFFFF;
  --border-color: #E2E8F0;
  --border-focus: #D32F2F;
  
  --text-main: #0F172A;
  --text-muted: #64748B;
  --text-light: #94A3B8;
  --text-on-primary: #FFFFFF;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset & Box Sizing */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* App Header */
.app-header {
  background: linear-gradient(135deg, #0F172A 0%, #1E293B 100%);
  color: #FFFFFF;
  padding: 0.75rem 1.5rem;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.2);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 2px solid var(--primary);
}

.header-inner {
  max-width: 1700px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  background: #FFFFFF;
  border-radius: 50%;
  padding: 2px;
  box-shadow: 0 0 10px rgba(211, 47, 47, 0.4);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: #FFFFFF;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.brand-badge {
  background: var(--primary);
  color: #FFFFFF;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.brand-text p {
  font-size: 0.75rem;
  color: #94A3B8;
}

/* Document Mode Selector Tabs */
.doc-mode-selector {
  display: flex;
  background: rgba(255, 255, 255, 0.08);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 255, 255, 0.12);
  gap: 4px;
}

.doc-mode-btn {
  background: transparent;
  border: none;
  color: #CBD5E1;
  padding: 0.5rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: var(--transition);
}

.doc-mode-btn:hover {
  color: #FFFFFF;
  background: rgba(255, 255, 255, 0.05);
}

.doc-mode-btn.active {
  background: var(--primary);
  color: #FFFFFF;
  box-shadow: 0 2px 8px rgba(211, 47, 47, 0.4);
}

/* Service Scope Selector (New vs Refilling vs Both) */
.service-scope-selector {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
  background: #F1F5F9;
  padding: 5px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

@media (max-width: 640px) {
  .service-scope-selector {
    grid-template-columns: 1fr;
  }
}

.scope-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 0.85rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--secondary-light);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}

.scope-btn:hover {
  background: #E2E8F0;
  color: var(--secondary-dark);
}

.scope-btn.active {
  background: #FFFFFF;
  color: var(--primary);
  border-color: #CBD5E1;
  box-shadow: var(--shadow-sm);
}

.scope-btn[data-scope="new"].active {
  color: #047857;
  border-color: #A7F3D0;
  background: #ECFDF5;
}

.scope-btn[data-scope="refill"].active {
  color: #B45309;
  border-color: #FDE68A;
  background: #FFFBEB;
}

.scope-btn[data-scope="both"].active {
  color: #D32F2F;
  border-color: #FECDD3;
  background: #FFF1F2;
}

.scope-icon {
  font-size: 1rem;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  text-decoration: none;
  line-height: 1;
}

.btn-primary {
  background: var(--primary);
  color: #FFFFFF;
  border-color: var(--primary);
}

.btn-primary:hover {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
  box-shadow: 0 4px 10px var(--primary-glow);
}

.btn-outline {
  background: rgba(255, 255, 255, 0.08);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-outline:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.4);
}

.btn-secondary {
  background: #E2E8F0;
  color: var(--text-main);
  border-color: #CBD5E1;
}

.btn-secondary:hover {
  background: #CBD5E1;
}

.btn-success {
  background: var(--accent-green);
  color: #FFFFFF;
  border-color: var(--accent-green);
}

.btn-success:hover {
  background: #047857;
}

.btn-danger {
  background: #EF4444;
  color: #FFFFFF;
  border-color: #EF4444;
}

.btn-danger:hover {
  background: #DC2626;
}

.btn-danger-outline {
  background: transparent;
  color: #EF4444;
  border-color: #FECACA;
}

.btn-danger-outline:hover {
  background: #FEE2E2;
  border-color: #EF4444;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
}

/* Main Layout Grid */
.main-wrapper {
  max-width: 1700px;
  margin: 1.25rem auto;
  padding: 0 1.25rem;
  display: grid;
  grid-template-columns: minmax(520px, 1.15fr) minmax(480px, 1fr);
  gap: 1.5rem;
  align-items: start;
}

@media (max-width: 1200px) {
  .main-wrapper {
    grid-template-columns: 1fr;
  }
}

/* Card Container */
.panel-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
  overflow: hidden;
  transition: var(--transition);
}

.panel-card:hover {
  box-shadow: var(--shadow-md);
}

.panel-card-header {
  padding: 0.9rem 1.25rem;
  background: #F8FAFC;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--secondary-dark);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel-card-title svg {
  color: var(--primary);
}

.panel-card-body {
  padding: 1.25rem;
}

/* Form Controls & Grid */
.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 1rem;
}

.form-grid-4 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 0.85rem;
}

@media (max-width: 768px) {
  .form-grid-2, .form-grid-3, .form-grid-4 {
    grid-template-columns: 1fr;
  }
}

.form-group {
  margin-bottom: 0.85rem;
}

.form-group:last-child {
  margin-bottom: 0;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--secondary-light);
  margin-bottom: 0.35rem;
}

.form-label .required {
  color: var(--primary);
}

.form-control {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text-main);
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition);
  outline: none;
}

.form-control:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-control[readonly] {
  background-color: #F8FAFC;
  color: #475569;
  cursor: default;
}

textarea.form-control {
  resize: vertical;
  min-height: 52px;
}

/* Items List & Category Cards */
.items-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.add-buttons-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.item-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1rem;
  position: relative;
  transition: var(--transition);
  border-left: 4px solid #94A3B8;
}

.item-card:hover {
  border-color: #CBD5E1;
  box-shadow: var(--shadow-sm);
}

.item-card.category-new {
  border-left-color: var(--accent-green);
}

.item-card.category-refill {
  border-left-color: var(--accent-amber);
}

.item-card.category-extra {
  border-left-color: var(--accent-blue);
}

.item-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.item-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.badge-new {
  background: var(--accent-green-light);
  color: var(--accent-green);
}

.badge-refill {
  background: var(--accent-amber-light);
  color: var(--accent-amber);
}

.badge-extra {
  background: var(--accent-blue-light);
  color: var(--accent-blue);
}

.item-card-num {
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748B;
}

.item-fields-grid {
  display: grid;
  grid-template-columns: 1.3fr 1.1fr 0.8fr 1.1fr 1.1fr auto;
  gap: 0.65rem;
  align-items: end;
  margin-bottom: 0.65rem;
}

.extra-charge-fields-grid {
  display: grid;
  grid-template-columns: 2.2fr 0.8fr 1.1fr 1.1fr auto;
  gap: 0.65rem;
  align-items: end;
  margin-bottom: 0.65rem;
}

@media (max-width: 900px) {
  .item-fields-grid, .extra-charge-fields-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Service Toggles Chips for Refilling */
.refill-services-wrapper {
  background: #FFFBEB;
  border: 1px dashed #FCD34D;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.refill-services-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #B45309;
}

.service-toggles {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.service-toggle-label {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: #78350F;
  cursor: pointer;
  user-select: none;
}

.service-toggle-label input[type="checkbox"] {
  accent-color: var(--accent-amber);
  cursor: pointer;
}

/* Description Input Row */
.desc-field-group {
  position: relative;
}

.desc-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.btn-link-action {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.72rem;
  cursor: pointer;
  text-decoration: underline;
  padding: 0;
}

.btn-link-action:hover {
  color: var(--primary-hover);
}

/* Empty State */
.empty-items-state {
  text-align: center;
  padding: 2.5rem 1rem;
  background: #F8FAFC;
  border: 2px dashed #CBD5E1;
  border-radius: var(--radius-md);
  color: #64748B;
}

.empty-items-state svg {
  margin-bottom: 0.5rem;
  color: #94A3B8;
}

/* Financial Summary Card */
.summary-card {
  background: #F8FAFC;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 1.25rem;
}

.summary-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  font-size: 0.875rem;
  color: var(--text-muted);
  border-bottom: 1px dashed #E2E8F0;
}

.summary-row:last-child {
  border-bottom: none;
}

.summary-row.highlight {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  border-top: 2px solid var(--primary);
  border-bottom: none;
  padding-top: 0.75rem;
  margin-top: 0.5rem;
}

.summary-value {
  font-weight: 600;
  color: var(--text-main);
  font-variant-numeric: tabular-nums;
}

.summary-row.highlight .summary-value {
  color: var(--primary);
  font-size: 1.25rem;
}

/* Words representation */
.total-in-words-box {
  background: #FFF1F2;
  border: 1px solid #FFE4E6;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.78rem;
  color: #9F1239;
  margin-top: 0.75rem;
  font-style: italic;
}

/* Right Panel: Live Document Preview */
.preview-column {
  position: sticky;
  top: 75px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  padding: 0.65rem 1rem;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  border: 1px solid var(--border-color);
  border-bottom: none;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.preview-zoom-controls {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.zoom-btn {
  background: #F1F5F9;
  border: 1px solid #CBD5E1;
  padding: 2px 7px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
}

.zoom-btn:hover {
  background: #E2E8F0;
}

.preview-viewport {
  background: #475569;
  padding: 1.5rem 1rem;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
  border: 1px solid var(--border-color);
  max-height: calc(100vh - 140px);
  overflow-y: auto;
  display: flex;
  justify-content: center;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* A4 Sheet Preview Format */
.a4-document {
  width: 210mm;
  min-height: 297mm;
  background: #FFFFFF;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  padding: 0.2in; /* 0.2 inch margin every side */
  color: #1E293B;
  font-size: 10pt;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transform-origin: top center;
  position: relative;
  box-sizing: border-box;
}

/* Document Top Letterhead */
.doc-header-banner {
  width: 100%;
  margin-bottom: 4mm;
}

.doc-header-banner img {
  width: 100%;
  height: auto;
  display: block;
}

/* Fallback / Custom Header */
.doc-header-custom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 3mm;
  margin-bottom: 3mm;
}

.doc-header-custom-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.doc-header-custom-logo {
  width: 55px;
  height: 55px;
  object-fit: contain;
}

.doc-header-custom-text h2 {
  font-size: 14pt;
  font-weight: 800;
  color: var(--primary);
  line-height: 1.2;
}

.doc-header-custom-text p {
  font-size: 8pt;
  color: #475569;
}

.doc-header-custom-right {
  text-align: right;
  font-size: 7.5pt;
  color: #334155;
  line-height: 1.25;
}

/* Document Meta & Client Details */
.doc-meta-section {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 4mm;
  font-size: 9pt;
}

.doc-client-details {
  max-width: 58%;
}

.doc-client-details .client-name {
  font-size: 10.5pt;
  font-weight: 700;
  color: #0F172A;
  margin-bottom: 3px;
}

.doc-client-details .client-line {
  color: #334155;
  line-height: 1.35;
}

.doc-numbering-box {
  text-align: right;
  font-size: 9pt;
}

.doc-numbering-box .doc-no-badge {
  font-size: 10.5pt;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 3px;
}

.doc-numbering-box .doc-date-line {
  color: #475569;
  line-height: 1.35;
}

/* Document Subject / Salutation */
.doc-subject-section {
  margin-bottom: 3.5mm;
}

.doc-salutation {
  font-size: 9.5pt;
  font-weight: 600;
  margin-bottom: 2mm;
}

.doc-title-underline {
  font-size: 10.5pt;
  font-weight: 800;
  text-decoration: underline;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #0F172A;
  margin-bottom: 2mm;
}

.doc-intro-text {
  font-size: 9pt;
  color: #334155;
  text-align: justify;
  line-height: 1.4;
}

/* Document Items Table */
.doc-table-wrapper {
  margin-bottom: 3.5mm;
  flex-grow: 1;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 8.5pt;
}

.doc-table th, .doc-table td {
  border: 1px solid #1E293B;
  padding: 4px 6px;
  vertical-align: middle;
}

.doc-table th {
  background-color: #F1F5F9;
  font-weight: 700;
  text-align: center;
  font-size: 8pt;
  letter-spacing: 0.2px;
  text-transform: uppercase;
  color: #0F172A;
}

.doc-table th.col-item-no { width: 7%; }
.doc-table th.col-desc { width: 57%; text-align: left; }
.doc-table th.col-qty { width: 8%; }
.doc-table th.col-price { width: 14%; text-align: right; }
.doc-table th.col-total { width: 14%; text-align: right; }

.doc-table td.text-center { text-align: center; }
.doc-table td.text-right { text-align: right; }
.doc-table td.text-left { text-align: left; }

.doc-table .table-category-heading td {
  background-color: #E2E8F0;
  font-weight: 700;
  font-size: 8pt;
  letter-spacing: 0.3px;
  text-align: left;
  padding: 3px 6px;
  color: #0F172A;
}

.doc-table .item-desc-cell {
  line-height: 1.35;
  color: #0F172A;
}

.doc-table .total-row td {
  font-weight: 700;
  background-color: #F8FAFC;
}

.doc-table .grand-total-row td {
  font-size: 10pt;
  font-weight: 800;
  background-color: #F1F5F9;
  border-top: 2px solid #0F172A;
}

/* Terms & Conditions Section */
.doc-terms-section {
  font-size: 8.5pt;
  margin-bottom: 3mm;
  line-height: 1.35;
}

.doc-terms-title {
  font-weight: 700;
  text-decoration: underline;
  margin-bottom: 2px;
  color: #0F172A;
}

.doc-terms-list {
  list-style: none;
}

.doc-terms-list li {
  margin-bottom: 2.5px;
  color: #1E293B;
}

.doc-terms-list strong {
  font-weight: 700;
}

.doc-closing-text {
  margin-top: 2.5mm;
  font-size: 8.5pt;
  line-height: 1.35;
}

/* Signature & Seal Block */
.doc-sign-section {
  display: flex;
  justify-content: flex-start;
  align-items: flex-end;
  margin-top: 4mm;
  margin-bottom: 3mm;
  font-size: 8.5pt;
}

.doc-sign-box {
  position: relative;
  width: auto;
  min-width: 220px;
}

.doc-signature-img {
  max-height: 44px;
  width: auto;
  display: block;
  margin-bottom: -8px;
}

.doc-sign-dots {
  letter-spacing: 2px;
  margin-bottom: 2px;
}

.doc-sign-name {
  font-weight: 700;
  color: #0F172A;
}

.doc-sign-title {
  color: #475569;
}

.doc-sign-company {
  font-size: 7.5pt;
  color: #475569;
  margin-bottom: 2px;
}

.doc-seal-img {
  display: block;
  margin-top: 2px;
  max-height: 48px;
  max-width: 175px;
  object-fit: contain;
  opacity: 0.95;
  mix-blend-mode: multiply;
  pointer-events: none;
}

/* Bottom Letterhead Wave Banner */
.doc-footer-banner {
  width: 100%;
  margin-top: auto;
}

.doc-footer-banner img {
  width: 100%;
  height: auto;
  display: block;
}

/* Notifications Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--secondary-dark);
  color: #FFFFFF;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.85rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-left: 4px solid var(--primary);
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   LOAD & EDIT PREVIOUS DOCUMENT MODAL & HISTORY STYLES
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(5px);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-dialog {
  background: #FFFFFF;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.45);
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #CBD5E1;
  animation: modalPop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 1.1rem 1.4rem;
  background: #F8FAFC;
  border-bottom: 1px solid #E2E8F0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-icon-badge {
  font-size: 1.5rem;
  background: #EFF6FF;
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  border: 1px solid #BFDBFE;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: #0F172A;
  margin: 0;
}

.modal-subtitle {
  font-size: 0.78rem;
  color: #64748B;
  margin: 0;
}

.modal-close-btn {
  background: none;
  border: none;
  font-size: 1.35rem;
  color: #64748B;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
  line-height: 1;
}

.modal-close-btn:hover {
  background: #E2E8F0;
  color: #0F172A;
}

.modal-nav-tabs {
  display: flex;
  border-bottom: 1px solid #E2E8F0;
  background: #F1F5F9;
  padding: 0 1rem;
  gap: 0.5rem;
}

.modal-tab-btn {
  padding: 0.75rem 1.1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748B;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
}

.modal-tab-btn:hover {
  color: #0F172A;
}

.modal-tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: #FFFFFF;
}

.modal-body {
  padding: 1.35rem;
  overflow-y: auto;
  max-height: calc(90vh - 150px);
}

.modal-tab-pane {
  display: none;
}

.modal-tab-pane.active {
  display: block;
}

/* Dropzone */
.dropzone-area {
  border: 2px dashed #93C5FD;
  background: #F8FAFC;
  border-radius: var(--radius-md);
  padding: 2.2rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.dropzone-area:hover, .dropzone-area.dragover {
  border-color: var(--primary);
  background: #EFF6FF;
}

.dropzone-icon {
  font-size: 2.6rem;
  margin-bottom: 0.5rem;
}

.dropzone-area h4 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #0F172A;
  margin-bottom: 0.25rem;
}

.dropzone-area p {
  font-size: 0.83rem;
  color: #64748B;
  margin-bottom: 0.65rem;
}

/* Summary Card for parsed PDF */
.pdf-summary-card {
  background: #F0FDF4;
  border: 1px solid #86EFAC;
  border-radius: var(--radius-md);
  padding: 1.1rem 1.25rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.pdf-summary-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.85rem;
  border-bottom: 1px solid #DCFCE7;
  padding-bottom: 0.5rem;
}

.pdf-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  font-size: 0.82rem;
  margin-bottom: 1rem;
}

.pdf-summary-field label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #166534;
  text-transform: uppercase;
  display: block;
  margin-bottom: 2px;
}

.pdf-summary-field span {
  color: #0F172A;
  font-weight: 600;
}

/* History List Table / Cards */
.history-list-wrapper {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: 380px;
  overflow-y: auto;
}

.history-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: var(--radius-md);
  padding: 0.75rem 1rem;
  transition: all 0.15s ease;
}

.history-card:hover {
  background: #FFFFFF;
  border-color: #CBD5E1;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.history-info {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.history-title-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.history-client {
  font-weight: 700;
  font-size: 0.92rem;
  color: #0F172A;
}

.history-meta {
  font-size: 0.75rem;
  color: #64748B;
}

.history-total {
  font-weight: 700;
  color: var(--primary);
  font-size: 0.95rem;
  margin-right: 0.75rem;
}

.history-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.backup-box {
  background: #F8FAFC;
  border: 1px solid #E2E8F0;
  border-radius: var(--radius-md);
  padding: 1.25rem;
}

.backup-box h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
  color: #0F172A;
}

.backup-box p {
  font-size: 0.8rem;
  color: #64748B;
  margin-bottom: 0.75rem;
}

/* ==========================================================================
   PRINT STYLESHEET (@media print)
   Standard A4 Portrait - Hide all app chrome and render document pixel-perfect
   ========================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 0.2in;
  }

  html, body {
    background: #FFFFFF !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    min-height: 100% !important;
    font-size: 10pt !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Hide everything except printable document */
  .app-header,
  .panel-card,
  .preview-toolbar,
  .toast-container,
  .no-print {
    display: none !important;
  }

  .main-wrapper {
    display: block !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .preview-column {
    position: static !important;
    width: 100% !important;
  }

  .preview-viewport {
    background: transparent !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .a4-document {
    width: 100% !important;
    min-height: auto !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    transform: none !important;
    page-break-after: avoid;
  }

  .doc-table {
    page-break-inside: auto;
  }

  .doc-table tr {
    page-break-inside: avoid;
    page-break-after: auto;
  }

  .doc-sign-section {
    page-break-inside: avoid;
  }
}
