/* CSS Variables for modal styling */
:root {
  --spacing-xl: 2rem;
  --spacing-lg: 1.5rem;
  --spacing-md: 1rem;
  --primary-gold: #D4AF37;
  --primary-blue: #154471;
  --border-radius-large: 8px;
  --shadow-medium: 0 4px 6px rgba(0, 0, 0, 0.1);
  --font-size-3xl: 1.875rem;
}

/* Modal components - Universal modal styling */

/* Modal overlay */
.modal-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  background-color: rgba(0, 0, 0, 0.5) !important;
  justify-content: center !important;
  align-items: flex-start !important;
  padding-top: 50px !important;
  z-index: 10000 !important;
  overflow-y: auto !important;
}

.modal-overlay.active {
  display: flex !important;
}

/* Modal container */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  justify-content: center;
  align-items: flex-start;
  padding-top: 50px;
  z-index: 10000;
  overflow-y: auto;
  box-sizing: border-box;
}

/* When shown via display:flex */
.modal[style*="display: flex"],
.modal[style*="display:flex"] {
  display: flex !important;
}

.modal .modal-content {
  background: #fff;
  border: 2px solid #D4AF37; /* fallback */
  border: 2px solid var(--primary-gold, #D4AF37);
  border-radius: 8px; /* fallback */
  border-radius: var(--border-radius-large, 8px);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* fallback */
  box-shadow: var(--shadow-medium, 0 4px 6px rgba(0, 0, 0, 0.1));
  width: 90%;
  max-width: 800px;
  min-width: 400px;
  max-height: calc(100vh - 4rem); /* fallback */
  max-height: calc(100vh - calc(var(--spacing-xl, 2rem) * 2));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  position: relative;
  margin: 0 auto 2rem auto; /* Top margin 0, auto sides, bottom margin for spacing */
  scrollbar-width: thin;
  scrollbar-color: #D4AF37 #f1f1f1; /* fallback */
  scrollbar-color: var(--primary-gold, #D4AF37) #f1f1f1;
}

/* Dedicated wide variant for editor-style modals (e.g., payout/invoice editors) */
.modal.large-modal .modal-content {
  width: 95%;
  max-width: 1200px;
  min-width: 700px;
}

.modal-large .modal-content {
  width: 95% !important;
  max-width: 1200px !important;
  min-width: 600px !important;
}

.modal-small .modal-content {
  width: 80% !important;
  max-width: 500px !important;
  min-width: 300px;
}

/* Modal content */
.modal-content {
  padding: 2rem; /* fallback */
  padding: var(--spacing-xl, 2rem);
}

.modal-compact .modal-content {
  padding: 1.5rem; /* fallback */
  padding: var(--spacing-lg, 1.5rem);
}

/* Force modal content to use full available width */
.modal-content {
  width: 100% !important;
  box-sizing: border-box !important;
}

/* Wide variant when modal-content carries large-modal (used by payout/invoice editors) */
.modal-content.large-modal {
  width: 95% !important;
  max-width: 1200px !important;
  min-width: 700px;
}

.modal-body {
  width: 100% !important;
  box-sizing: border-box !important;
}

.job-info-section,
.line-items-section,
.version-list {
  width: 100% !important;
  box-sizing: border-box !important;
}

/* Ensure all modal content elements take full width */
.modal .job-info-section p,
.modal .line-items-section div,
.modal .version-item {
  width: 100% !important;
  max-width: none !important;
}

/* Override any width constraints on modal children (except modal-content) */
.modal *:not(.modal-content) {
  max-width: none !important;
}

/* Specific overrides for job data content */
.job-data-modal .modal-body,
.version-history-modal .modal-body {
  width: 100% !important;
  padding: 0 !important;
  margin: 0 !important;
}

.job-data-modal .modal-content,
.version-history-modal .modal-content {
  padding: 1.5rem !important;
  width: 90% !important;
  max-width: 500px !important;
  min-width: 400px !important;
  box-sizing: border-box !important;
}

/* Status modal - use standard modal behavior with custom sizing */
.status-modal .modal-content {
  width: 90% !important;
  max-width: 500px !important;
  min-width: 400px !important;
}

/* Modal header */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--spacing-sm);
  padding-bottom: var(--spacing-lg);
  border-bottom: 2px solid var(--primary-gold);
}

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

.header-actions .btn {
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
}

.header-actions .modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
  margin-left: 0.5rem;
  color: #666;
}

.header-actions .modal-close-compact {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  padding: 0.15rem 0.3rem;
  margin-left: 0.5rem;
  color: #666;
  min-width: auto;
  width: auto;
}

.header-actions .modal-close:hover,
.header-actions .modal-close-compact:hover {
  color: #333;
}

/* Navigation arrow buttons - compact styling */
.header-actions #prev-proposal,
.header-actions #next-proposal {
  min-width: 24px;
  width: 24px;
  padding: 0.15rem 0.2rem;
  font-size: 1.1rem;
  line-height: 1;
}

/* Navigation arrow buttons - compact styling for invoices */
.header-actions #prev-invoice,
.header-actions #next-invoice {
  min-width: 24px;
  width: 24px;
  padding: 0.15rem 0.2rem;
  font-size: 1.1rem;
  line-height: 1;
}

.modal-title {
  color: var(--primary-blue);
  font-size: var(--font-size-3xl);
  font-weight: bold;
  margin: 0;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.modal-compact .modal-title {
  font-size: var(--font-size-2xl);
}

/* Modal body */
.modal-body {
  flex-grow: 1;
  overflow-y: auto;
  margin-bottom: var(--spacing-xs);
}

/* Modal footer - General styles */
.modal-footer {
  display: flex;
  gap: var(--spacing-md);
  justify-content: flex-end;
  padding-top: var(--spacing-lg);
  border-top: 1px solid #eee;
  flex-wrap: wrap;
  flex-shrink: 0;
}

/* Modal sections */
.modal-section {
  margin-bottom: var(--spacing-sm);
}

.modal-section:last-child {
  margin-bottom: 0;
}

.modal-section-title {
  color: var(--primary-blue);
  font-size: var(--font-size-2xl);
  font-weight: bold;
  margin: 0 0 var(--spacing-lg) 0;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.modal-compact .modal-section-title {
  font-size: var(--font-size-xl);
  margin-bottom: var(--spacing-md);
}

/* Prevent body scroll when modal is open */
body.modal-open {
  overflow: hidden;
  padding-right: 0;
}

/* Table styling within modals */
.modal table:not(.cfp-proposals-table) {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  border: 2px solid var(--primary-gold);
  border-radius: var(--border-radius);
  overflow: hidden;
  background: var(--background-overlay);
  box-shadow: var(--shadow-light);
  margin: var(--spacing-lg) 0;
}

.modal table:not(.cfp-proposals-table) th {
  background: linear-gradient(45deg, var(--primary-blue), var(--primary-blue-light));
  color: white;
  font-weight: bold;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
  padding: var(--spacing-md) var(--spacing-sm);
  font-size: var(--font-size-sm);
  text-align: left;
}

.modal table:not(.cfp-proposals-table) td {
  padding: var(--spacing-sm);
  border-bottom: 1px solid rgba(225, 177, 23, 0.3);
  border-right: 1px solid rgba(225, 177, 23, 0.3);
  font-size: var(--font-size-sm);
}

.modal table:not(.cfp-proposals-table) td:last-child {
  border-right: none;
}

.modal table:not(.cfp-proposals-table) tbody tr:last-child td {
  border-bottom: none;
}

.modal table:not(.cfp-proposals-table) tbody tr:nth-child(even) {
  background: linear-gradient(135deg, rgba(225, 177, 23, 0.08), rgba(225, 177, 23, 0.04));
}

.modal table:not(.cfp-proposals-table) tbody tr:hover {
  background: linear-gradient(135deg, rgba(21, 68, 113, 0.1), rgba(21, 68, 113, 0.05));
}

/* Compact table styling for mobile */
.modal-compact table th,
.modal-compact table td {
  padding: calc(var(--spacing-sm) * 0.75) var(--spacing-xs);
  font-size: var(--font-size-xs);
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
  .modal-overlay {
    padding: var(--spacing-lg) var(--spacing-md);
  }
  
  .modal {
    width: 95%;
    min-width: unset;
    margin: 1rem auto;
  }
  
  .modal-large {
    width: 95%;
    min-width: unset;
  }
  
  .modal-small {
    width: 90%;
    min-width: unset;
  }
  
  .modal-content {
    padding: var(--spacing-lg);
  }
  
  .modal-compact .modal-content {
    padding: var(--spacing-md);
  }
  
  .modal-title {
    font-size: var(--font-size-2xl);
  }
  
  .modal-compact .modal-title {
    font-size: var(--font-size-xl);
  }
  
  .modal-section-title {
    font-size: var(--font-size-xl);
  }
  
  .modal-compact .modal-section-title {
    font-size: var(--font-size-lg);
  }
  
  .modal-footer {
    flex-direction: column;
    gap: var(--spacing-sm);
  }
  
  .modal-footer > * {
    flex: 1;
  }
}

@media (max-width: 480px) {
  .modal-overlay {
    padding: var(--spacing-md) var(--spacing-sm);
  }
  
  .modal {
    width: 98%;
    margin: 0.5rem auto;
  }
  
  .modal-content {
    padding: 1rem;
  }
  
  .modal-compact .modal-content {
    padding: var(--spacing-sm);
  }
  
  .modal-header {
    margin-bottom: var(--spacing-lg);
    padding-bottom: var(--spacing-sm);
  }
  
  .modal-title {
    font-size: var(--font-size-xl);
  }
  
  .modal-section-title {
    font-size: var(--font-size-lg);
  }
}

/* Additional debug and visibility rules */
.modal-overlay.active .modal {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

.modal-overlay.active .modal-content {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Ensure modals are properly hidden by default and visible when active */
.modal-overlay {
  display: none;
}

.modal-overlay.active {
  display: flex !important;
}

/* Modal positioning and visibility when active */
.modal-overlay.active .modal {
  position: relative !important;
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
}

/* Emergency fallback for modal content */
.modal-content {
  min-height: 100px !important;
  background: white !important;
  color: black !important;
}

/* Job data modal specific styles */
.job-data-modal .modal-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.job-info-section,
.line-items-section {
  margin-bottom: 0.5rem;
}

.job-info-section h4,
.line-items-section h4 {
  color: var(--primary-blue, #154471);
  border-bottom: 2px solid var(--primary-gold, #D4AF37);
  padding-bottom: 0.5rem;
  margin-bottom: var(--spacing-xs);
}

.line-item {
  display: flex;
  justify-content: space-between;
  padding: 0.5rem 0;
  border-bottom: 1px solid #f0f0f0;
}

.items-subtotal,
.grand-total {
  font-weight: bold;
  padding: var(--spacing-xs) 0;
  margin-top: var(--spacing-xs);
}

.grand-total {
  border-top: 2px solid var(--primary-gold, #D4AF37);
  font-size: 1.2em;
  color: #000000 !important; /* Black for better visibility */
  background-color: #f8f9fa;
  padding: var(--spacing-sm);
  margin-top: var(--spacing-xs);
  border-radius: 4px;
  text-align: center;
}

/* Version history modal styles */
.version-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border: 1px solid #eee;
  border-radius: 4px;
  margin-bottom: var(--spacing-xs);
  background: #f9f9f9;
}

.version-info {
  flex-grow: 1;
}

.version-total {
  font-weight: bold;
  margin: 0 1rem;
}

.version-actions {
  display: flex;
  gap: 0.5rem;
}

/* Status badges */
.status-badge {
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: bold;
  text-transform: uppercase;
  white-space: nowrap;
  display: inline-block;
}

.status-draft { background: #ffc107; color: #000; }
.status-sent { background: #007bff; color: #fff; }
.status-overdue { background: #dc3545; color: #fff; }
.status-paid { background: #28a745; color: #fff; }
.status-accepted { background: #28a745; color: #fff; }
.status-rejected { background: #dc3545; color: #fff; }

/* Form elements in modals should use full width */
.modal .form-group,
.modal .form-field,
.modal .form-row {
  width: 100% !important;
  max-width: none !important;
}

.modal input,
.modal select,
.modal textarea {
  width: 100% !important;
  max-width: none !important;
  box-sizing: border-box !important;
}

/* Exception for payout editor form inputs to allow flex layout sizing */
.modal .payout-details-section .form-group input,
.modal .payout-details-section .form-group select,
.modal .payout-details-section .form-group textarea {
  width: auto !important;
  max-width: 100% !important;
}

/* Payout editor form groups should not be forced full-width */
#edit-payout-modal .payout-details-section .form-group {
  width: auto !important;
  max-width: none !important;
  display: block !important;
}

.modal .modal-controls {
  width: 100% !important;
  max-width: none !important;
}

/* Version history specific width fixes */
.version-item {
  width: 100% !important;
  display: flex !important;
  justify-content: space-between !important;
  align-items: center !important;
  box-sizing: border-box !important;
}

.version-info {
  flex-grow: 1 !important;
  min-width: 0 !important;
}

.version-actions {
  flex-shrink: 0 !important;
  display: flex !important;
  gap: 0.5rem !important;
}

/* Line Items Editor Modal Styles */
.line-items-editor-modal .modal-content {
  width: 95% !important;
  max-width: 1200px !important;
  min-width: 600px !important;
  max-height: calc(100vh - 4rem) !important; /* Leave room for top padding */
  display: flex;
  flex-direction: column;
  overflow: hidden; /* Prevent overflow on modal content */
  margin: 0; /* Remove auto margin since we're top-aligning */
}

.line-items-editor-modal .modal-header {
  flex-shrink: 0;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  position: sticky;
  top: 0;
  background: white;
  z-index: 10;
  padding-bottom: 0.5rem;
}

/* Only apply flexbox to the modal body, not the entire modal content */
.line-items-editor-modal .modal-body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
  min-height: 0; /* Important for flex child to shrink */
  gap: 0.3rem;
}

/* Proposal info section - optimized width usage */
.proposal-info-section {
  flex-shrink: 0;
  margin-bottom: 0 !important;
  padding: 4px 12px 2px !important;
  background: #f8f9fa;
  max-width: 100% !important;
}

/* Invoice info section - optimized width usage */
.invoice-info-section {
  flex-shrink: 0;
  margin-bottom: 0 !important;
  padding: 4px 12px 2px !important;
  background: #f8f9fa;
  max-width: 100% !important;
}

/* Proposal info section header row */
.proposal-info-header {
  display: flex !important;
  justify-content: space-between !important;
  align-items: baseline !important;
  margin-bottom: 3px !important;
}

/* Invoice info section header row */
.invoice-info-header {
  display: flex !important;
  justify-content: space-between !important;
  align-items: baseline !important;
  margin-bottom: 3px !important;
}

.proposal-info-section h4 {
  margin: 0 !important;
  padding: 0 !important;
  flex: 0 0 auto !important;
}

.invoice-info-section h4 {
  margin: 0 !important;
  padding: 0 !important;
  flex: 0 0 auto !important;
}

/* Notes label positioned next to proposal info header */
.notes-header-inline {
  margin: 0 !important;
  padding: 0 !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  color: var(--primary-blue) !important;
  line-height: 1.4 !important;
  flex: 0 0 auto !important;
}

/* New proposal info layout - two columns with notes in top right */
.proposal-info-layout {
  display: flex;
  gap: 16px;
  margin-bottom: 4px;
  padding: 0 !important;
  align-items: flex-start;
}

/* New invoice info layout - two columns with notes in top right */
.invoice-info-layout {
  display: flex;
  gap: 16px;
  margin-bottom: 4px;
  padding: 0 !important;
  align-items: flex-start;
}

/* Left column for all form fields */
.proposal-left-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Left column for all form fields */
.invoice-left-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Right column for notes in top right */
.proposal-right-column {
  flex: 0 0 250px;
  max-width: 250px;
}

/* Right column for notes in top right */
.invoice-right-column {
  flex: 0 0 250px;
  max-width: 250px;
}

/* Notes in corner styling */
.notes-in-corner {
  margin-top: 0;
}

.notes-in-corner .form-group {
  margin-bottom: 0 !important;
  height: auto !important;
  display: flex !important;
  flex-direction: column !important;
}

.notes-in-corner .notes-textarea {
  min-height: 48px !important;
  max-height: 65px !important;
  resize: vertical !important;
  font-size: 11px !important;
  padding: 5px 8px !important;
  width: 100% !important;
  border: 1px solid #ddd !important;
  border-radius: 4px !important;
}

/* Horizontal label-input layout for proposal left column - FORCE HORIZONTAL LAYOUT */
/* Override base form-group styles that set flex-direction: column */
.line-items-editor-modal .modal-body .proposal-info-section .proposal-left-column .form-group {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 6px !important;
  margin-bottom: 2px !important;
  width: auto !important;
}

/* Horizontal label-input layout for invoice left column - FORCE HORIZONTAL LAYOUT */
/* Override base form-group styles that set flex-direction: column */
.line-items-editor-modal .modal-body .invoice-info-section .invoice-left-column .form-group {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 6px !important;
  margin-bottom: 2px !important;
  width: auto !important;
}

.line-items-editor-modal .modal-body .proposal-info-section .proposal-left-column .form-group label {
  flex: 0 0 auto !important;
  font-size: 11px !important;
  margin-bottom: 0 !important;
  margin-right: 0 !important;
  font-weight: 600 !important;
  color: var(--primary-blue) !important;
  white-space: nowrap !important;
  line-height: 26px !important;
  width: auto !important;
  position: static !important;
  display: inline-block !important;
}

.line-items-editor-modal .modal-body .invoice-info-section .invoice-left-column .form-group label {
  flex: 0 0 auto !important;
  font-size: 11px !important;
  margin-bottom: 0 !important;
  margin-right: 0 !important;
  font-weight: 600 !important;
  color: var(--primary-blue) !important;
  white-space: nowrap !important;
  line-height: 26px !important;
  width: auto !important;
  position: static !important;
  display: inline-block !important;
}

.line-items-editor-modal .modal-body .proposal-info-section .proposal-left-column .form-group input,
.line-items-editor-modal .modal-body .proposal-info-section .proposal-left-column .form-group select {
  flex: 0 0 auto !important;
  padding: 3px 6px !important;
  font-size: 11px !important;
  height: 26px !important;
  line-height: 1.2 !important;
  box-sizing: border-box !important;
  margin-left: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

.line-items-editor-modal .modal-body .invoice-info-section .invoice-left-column .form-group input,
.line-items-editor-modal .modal-body .invoice-info-section .invoice-left-column .form-group select {
  flex: 0 0 auto !important;
  padding: 3px 6px !important;
  font-size: 11px !important;
  height: 26px !important;
  line-height: 1.2 !important;
  box-sizing: border-box !important;
  margin-left: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Form row adjustments for horizontal layout - FORCE HORIZONTAL LAYOUT */
.line-items-editor-modal .modal-body .proposal-info-section .proposal-left-column .form-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 10px !important;
  margin-bottom: 2px !important;
  flex-wrap: nowrap !important;
  width: auto !important;
}

/* Form row adjustments for horizontal layout - FORCE HORIZONTAL LAYOUT */
.line-items-editor-modal .modal-body .invoice-info-section .invoice-left-column .form-row {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 10px !important;
  margin-bottom: 2px !important;
  flex-wrap: nowrap !important;
  width: auto !important;
}

.line-items-editor-modal .modal-body .proposal-info-section .proposal-left-column .form-row .form-group {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 6px !important;
  margin-bottom: 0 !important;
  flex: 0 0 auto !important;
  width: auto !important;
}

.line-items-editor-modal .modal-body .invoice-info-section .invoice-left-column .form-row .form-group {
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 6px !important;
  margin-bottom: 0 !important;
  flex: 0 0 auto !important;
  width: auto !important;
}

.line-items-editor-modal .modal-body .proposal-info-section .proposal-left-column .form-row .form-group label {
  flex: 0 0 auto !important;
  font-size: 11px !important;
  line-height: 26px !important;
  font-weight: 600 !important;
  color: var(--primary-blue) !important;
  white-space: nowrap !important;
  width: auto !important;
  margin-bottom: 0 !important;
  margin-right: 0 !important;
  position: static !important;
  display: inline-block !important;
}

.line-items-editor-modal .modal-body .invoice-info-section .invoice-left-column .form-row .form-group label {
  flex: 0 0 auto !important;
  font-size: 11px !important;
  line-height: 26px !important;
  font-weight: 600 !important;
  color: var(--primary-blue) !important;
  white-space: nowrap !important;
  width: auto !important;
  margin-bottom: 0 !important;
  margin-right: 0 !important;
  position: static !important;
  display: inline-block !important;
}

.line-items-editor-modal .modal-body .proposal-info-section .proposal-left-column .form-row .form-group input,
.line-items-editor-modal .modal-body .proposal-info-section .proposal-left-column .form-row .form-group select {
  flex: 0 0 auto !important;
  padding: 3px 6px !important;
  font-size: 11px !important;
  height: 26px !important;
  line-height: 1.2 !important;
  box-sizing: border-box !important;
  margin-left: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

.line-items-editor-modal .modal-body .invoice-info-section .invoice-left-column .form-row .form-group input,
.line-items-editor-modal .modal-body .invoice-info-section .invoice-left-column .form-row .form-group select {
  flex: 0 0 auto !important;
  padding: 3px 6px !important;
  font-size: 11px !important;
  height: 26px !important;
  line-height: 1.2 !important;
  box-sizing: border-box !important;
  margin-left: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
}

/* Specific widths for different input types */
.line-items-editor-modal input[type="text"]:not([id*="state"]):not([id*="zip"]):not([id*="town"]) {
  width: 160px !important;
}

.line-items-editor-modal input[id*="town"] {
  width: 100px !important;
}

.line-items-editor-modal input[id*="state"] {
  width: 70px !important;
}

.line-items-editor-modal input[id*="zip"] {
  width: 70px !important;
}

.line-items-editor-modal input[type="number"] {
  width: 80px !important;
}

.line-items-editor-modal input[type="date"] {
  width: 120px !important;
}

.line-items-editor-modal select {
  width: 140px !important;
}

/* Special styling for the unified job address row with 5 fields */
.line-items-editor-modal .proposal-basic-info .form-row.job-address-row {
  gap: 6px !important; /* Tighter gap for 5 fields */
  flex-wrap: nowrap !important;
}

/* Special styling for the unified job address row with 5 fields */
.line-items-editor-modal .invoice-basic-info .form-row.job-address-row {
  gap: 6px !important; /* Tighter gap for 5 fields */
  flex-wrap: nowrap !important;
}

.line-items-editor-modal .proposal-basic-info .form-row.job-address-row .form-group {
  gap: 3px !important; /* Tighter gap between label and input */
  flex: 0 0 auto !important;
}

.line-items-editor-modal .invoice-basic-info .form-row.job-address-row .form-group {
  gap: 3px !important; /* Tighter gap between label and input */
  flex: 0 0 auto !important;
}

/* Specific widths for the Job Site + Street row */
.line-items-editor-modal .form-row.job-address-row select {
  width: 140px !important; /* Job site dropdown */
}

.line-items-editor-modal .form-row.job-address-row input[id*="street"] {
  width: 200px !important; /* Street address - can be longer now */
}

/* Specific widths for the compact address fields in flexible row */
.line-items-editor-modal .address-fields input[id*="town"] {
  width: 80px !important; /* City - compact */
}

.line-items-editor-modal .address-fields input[id*="state"] {
  width: 120px !important; /* State - widened to accommodate full state names */
}

.line-items-editor-modal .address-fields input[id*="zip"] {
  width: 60px !important; /* ZIP - compact */
}

/* Compact notes section - remove label since it's in header */
.line-items-editor-modal .proposal-notes .form-group {
  margin-bottom: 0 !important;
  height: 100%;
  display: flex !important;
  flex-direction: column !important;
}

/* Responsive design for proposal layout */
@media (max-width: 768px) {
  .proposal-info-layout {
    flex-direction: column;
    gap: 10px;
  }
  
  .invoice-info-layout {
    flex-direction: column;
    gap: 10px;
  }
  
  .proposal-basic-info,
  .proposal-notes {
    flex: 1 1 auto;
  }
  
  .invoice-basic-info,
  .invoice-notes {
    flex: 1 1 auto;
  }
  
  .line-items-editor-modal .proposal-notes .form-group .notes-textarea {
    min-height: 60px !important;
  }
  
  .line-items-editor-modal .invoice-notes .form-group .notes-textarea {
    min-height: 60px !important;
  }
}

/* Line items section with scrollable table */
.line-items-section {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0; /* Important for flex child to shrink */
  margin-bottom: 0 !important; /* Remove margin, using gap instead */
}

.line-items-section h4 {
  flex-shrink: 0;
  margin-bottom: 0.2rem;
  margin-top: 0;
  padding-top: 0;
  font-size: 0.9rem;
  border-top: none;
}

.line-items-editor {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Scrollable container for the line items table */
.line-items-table-container {
  flex: 0 1 auto; /* Don't grow, but can shrink */
  overflow-y: auto;
  border: 1px solid #dee2e6;
  border-radius: 4px;
  margin: 0; /* Remove any margins */
  padding: 0; /* Remove any padding */
  max-height: 60vh; /* Limit maximum height for scrolling */
}

/* Handle empty state - when no line items are present */
.line-items-table-container.empty-state {
  border: none;
  padding: 0;
  margin: 0;
  height: 0;
  overflow: hidden;
  flex: 0 0 0; /* Don't take any space when empty */
}

/* Hide table when empty */
.line-items-table.empty-table {
  display: none;
}

.editor-actions {
  flex-shrink: 0;
  margin-top: 0.2rem;
}

.line-items-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 !important; /* Force margin to 0 with !important */
  border: none; /* Remove border since container has it */
  table-layout: fixed; /* Consistent column widths */
}

/* Ensure no spacing in table elements */
.line-items-table tbody,
.line-items-table thead {
  margin: 0 !important;
  padding: 0 !important;
}

.line-items-table tbody tr:last-child {
  margin-bottom: 0 !important;
}

.line-items-table tbody tr:last-child td {
  margin-bottom: 0 !important;
  padding-bottom: 0.25rem !important; /* Small padding for last row */
}

/* Ensure no margins on table inside the container */
.line-items-table-container .line-items-table {
  margin: 0 !important;
  padding: 0 !important;
}

/* Override any bootstrap or other framework table margins */
.line-items-editor-modal .line-items-table,
.line-items-editor .line-items-table,
table.line-items-table {
  margin: 0 !important;
  margin-top: 0 !important;
  margin-bottom: 0 !important;
  margin-left: 0 !important;
  margin-right: 0 !important;
}

/* Payment preview section - fixed at bottom */
.payment-preview-section {
  flex-shrink: 0;
  background: #f8f9fa;
  padding: 0.5rem;
  border-radius: 4px;
  border: 1px solid #e9ecef;
  margin-bottom: 0 !important; /* Remove margin, using gap instead */
}

.payment-preview-section h4 {
  margin-top: 0;
  margin-bottom: 0.25rem;
  color: var(--primary-blue);
  font-size: 0.9rem;
  border-bottom: none !important;
}

/* Modal footer styles are now removed since buttons moved to header */

/* Sticky table header */
.line-items-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.line-items-table th,
.line-items-table td {
  padding: 0.5rem 0.75rem;
  border-right: 1px solid #dee2e6;
  border-bottom: 1px solid #dee2e6;
  vertical-align: middle; /* Center content vertically */
}

.line-items-table th {
  background: var(--primary-blue, #154471);
  color: white;
  font-weight: bold;
  text-align: center;
  padding: 0.25rem 0.375rem; /* Further reduced padding */
  font-size: 0.75rem; /* Even smaller font for header */
  line-height: 1.1; /* Tighter line height */
  border-top: none; /* Remove top border for flush appearance */
  height: 2rem; /* Fixed height to ensure consistency */
}

.line-items-table td {
  background: white;
}

/* Specific styling for action column (contains Remove button) */
.line-items-table td:last-child {
  text-align: center;
  vertical-align: middle;
  padding: 0.375rem;
}

/* Remove right border from last column and ensure proper alignment */
.line-items-table th:last-child,
.line-items-table td:last-child {
  border-right: none;
}

/* Style buttons in line items table */
.line-items-table .btn {
  margin: 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  line-height: 1;
  text-align: center;
}

.line-items-table .form-control {
  width: 100%;
  border: 1px solid #ced4da;
  border-radius: 4px;
  padding: 0.375rem 0.75rem;
  font-size: 0.875rem;
}

.line-items-table textarea.form-control {
  resize: vertical;
  min-height: 2.5rem;
}

.line-items-table input[type="number"] {
  text-align: right;
  /* Remove spinner arrows — value changes via keyboard only */
  -moz-appearance: textfield;
}

.line-items-table input[type="number"]::-webkit-outer-spin-button,
.line-items-table input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.editor-actions {
  display: flex;
  justify-content: flex-start;
  flex-shrink: 0 !important;
  margin-top: var(--spacing-sm);
}

.line-items-editor .modal-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--spacing-md);
  flex-shrink: 0;
  padding: var(--spacing-lg) 0 0 0;
  border-top: 1px solid #eee;
  margin-top: var(--spacing-md);
}

.line-items-editor .modal-footer .btn {
  flex: 0 0 auto;
}

/* Line item reorder controls */
.reorder-controls {
  text-align: center !important;
  white-space: nowrap !important;
  padding: 8px !important;
}

.reorder-controls .btn {
  margin: 0 2px !important;
  padding: 4px 8px !important;
  min-width: 30px !important;
  height: 30px !important;
  border: 1px solid #dee2e6 !important;
  background-color: #f8f9fa !important;
  color: #495057 !important;
  transition: all 0.2s ease !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
}

.reorder-controls .btn:hover:not(:disabled) {
  background-color: #e9ecef !important;
  border-color: #adb5bd !important;
  color: #212529 !important;
}

.reorder-controls .btn:disabled {
  opacity: 0.4 !important;
  cursor: not-allowed !important;
  background-color: #f8f9fa !important;
  border-color: #dee2e6 !important;
}

.reorder-controls .btn {
  font-size: 16px !important;
  font-weight: bold !important;
  line-height: 1 !important;
}

/* Make sure the line items table has proper spacing */
#line-items-editor-body td {
  vertical-align: middle !important;
}

#line-items-editor-body .item-description {
  min-height: 38px !important;
  resize: none !important;
  overflow: hidden !important;
  transition: height 0.1s ease !important;
  box-sizing: border-box !important;
}

#line-items-editor-body .item-cost {
  width: 100% !important;
}

#line-items-editor-body .item-type {
  width: 100% !important;
}

/* Responsive adjustments for line items table */
@media (max-width: 768px) {
  .reorder-controls .btn {
    min-width: 28px !important;
    height: 28px !important;
    padding: 2px 6px !important;
  }
  
  .reorder-controls .btn i {
    font-size: 10px !important;
  }
  
  .line-items-table {
    font-size: 0.8rem;
  }
  
  .line-items-table th,
  .line-items-table td {
    padding: 0.5rem;
  }
  
  .line-items-table .form-control {
    font-size: 0.8rem;
    padding: 0.25rem 0.5rem;
  }
}

/* Payment terms section in modals */
.payment-terms-section {
  margin-top: 1rem;
  padding: 1rem;
  background-color: #f8f9fa;
  border-radius: 4px;
  border-left: 4px solid var(--primary-gold, #D4AF37);
}

.payment-terms-section h5 {
  color: var(--primary-blue, #154471);
  margin-bottom: 0.5rem;
  font-weight: bold;
}

.payment-terms-section p {
  margin: 0.25rem 0;
  color: #495057;
}

.payment-terms-section p:last-child {
  font-weight: bold;
  color: #000000;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid #dee2e6;
}

/* Upfront payment section in line items editor */
.upfront-payment-section {
  margin-top: 2rem;
  padding: 1.5rem;
  background-color: #f8f9fa;
  border-radius: 6px;
  border-left: 4px solid var(--primary-gold, #D4AF37);
}

.upfront-payment-section h5 {
  color: var(--primary-blue, #154471);
  margin-bottom: 1rem;
  font-weight: bold;
  font-size: 1.1em;
}

.payment-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.payment-fields .form-group {
  margin-bottom: 0;
}

.payment-fields label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #495057;
}

.payment-fields .form-control {
  width: 100%;
  padding: 0.5rem;
  border: 1px solid #ced4da;
  border-radius: 4px;
  font-size: 0.9rem;
}

.payment-fields .form-control:focus {
  border-color: var(--primary-gold, #D4AF37);
  box-shadow: 0 0 0 0.2rem rgba(212, 175, 55, 0.25);
  outline: 0;
}

.help-text {
  margin-top: 0.75rem;
  margin-bottom: 0;
  font-size: 0.85rem;
  color: #6c757d;
  font-style: italic;
}

/* Responsive design for payment fields */
@media (max-width: 768px) {
  .payment-fields {
    grid-template-columns: 1fr;
  }
}

/* Payment preview section */
.payment-preview {
  margin-top: 1rem;
  padding: 0.75rem;
  background-color: #e9ecef;
  border-radius: 4px;
  border-left: 3px solid var(--primary-blue, #154471);
  font-size: 0.9rem;
  line-height: 1.4;
}

.payment-preview:empty {
  display: none;
}

/* Status modal specific styling fixes */
#status-modal .modal-header {
  margin-bottom: var(--spacing-sm);
  padding-bottom: var(--spacing-xs);
}

#status-modal .modal-title {
  font-size: var(--font-size-xl);
  margin: 0;
}

#status-modal .form-group {
  margin-bottom: var(--spacing-sm);
}

#status-modal .form-group:last-of-type {
  margin-bottom: var(--spacing-sm);
}

#status-modal .form-actions {
  display: flex;
  gap: var(--spacing-md);
  justify-content: flex-end;
  margin-top: var(--spacing-sm);
}

/* Create from Proposal Modal */
.cfp-modal {
  align-items: center;
  justify-content: center;
}

.cfp-modal-content {
  width: min(1300px, 95vw) !important;
  max-width: min(1300px, 95vw) !important;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  padding: 0 !important; /* header and body handle their own spacing */
}

#create-from-proposal-modal .modal-header {
  padding: 0.6rem 1rem;
}

#create-from-proposal-modal #close-create-from-proposal {
  font-size: 1.1rem;
  padding: 0.1rem 0.4rem;
  line-height: 1;
}

.cfp-modal-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  padding: var(--spacing-md);
}

.cfp-modal-body form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* Top row: Name, Date, IDs on one line */
.cfp-fields-row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-shrink: 0;
  margin-bottom: 10px;
}

.cfp-fields-row .form-group {
  margin-bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cfp-fields-row .form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--primary-blue);
  white-space: nowrap;
  margin: 0;
}

.cfp-fields-row .form-group input {
  height: 30px;
  padding: 3px 8px;
  font-size: 13px;
}

.cfp-fields-row .form-group:first-child {
  flex: 2;
}

.cfp-fields-row .form-group:nth-child(2) {
  flex: 0 0 140px;
}

.cfp-ids-group {
  flex: 1 !important;
}

/* Proposals browse table wrapper */
.cfp-table-wrapper {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin-bottom: 10px;
}

.cfp-table-status {
  padding: 1rem;
  color: #666;
  font-size: 0.9rem;
  text-align: center;
}

.cfp-proposals-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.cfp-proposals-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
}

.cfp-proposals-table th {
  background: var(--primary-blue, #154471);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 5px 8px;
  text-align: left;
  white-space: nowrap;
}

.cfp-proposals-table td {
  font-size: 0.82rem;
  padding: 5px 8px;
  border-bottom: 1px solid #e9ecef;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Column widths */
.cfp-proposals-table th:nth-child(1),
.cfp-proposals-table td:nth-child(1) { width: 5%; min-width: 62px; text-align: center; }   /* ID */
.cfp-proposals-table th:nth-child(2),
.cfp-proposals-table td:nth-child(2) { width: 20%; }                       /* Name */
.cfp-proposals-table th:nth-child(3),
.cfp-proposals-table td:nth-child(3) { width: 18%; }                       /* Client */
.cfp-proposals-table th:nth-child(4),
.cfp-proposals-table td:nth-child(4) { width: auto; white-space: normal; } /* Job Site */
.cfp-proposals-table th:nth-child(5),
.cfp-proposals-table td:nth-child(5) { width: 10%; }                       /* Date */
.cfp-proposals-table th:nth-child(6),
.cfp-proposals-table td:nth-child(6) { width: 9%; }                        /* Status */
.cfp-proposals-table th:nth-child(7),
.cfp-proposals-table td:nth-child(7) { width: 7%; min-width: 75px; text-align: right; } /* Total */

.cfp-row:hover {
  background: rgba(212, 175, 55, 0.08);
}

.cfp-row-selected {
  background: rgba(21, 68, 113, 0.12) !important;
  outline: 2px solid var(--primary-blue, #154471);
  outline-offset: -2px;
}

.cfp-row-selected:hover {
  background: rgba(21, 68, 113, 0.18) !important;
}

#create-from-proposal-modal .form-actions {
  display: flex;
  gap: var(--spacing-md);
  justify-content: flex-end;
  flex-shrink: 0;
  padding-top: 6px;
  border-top: 1px solid #e5e5e5;
}

/* Create Proposal Modal */
#create-proposal-modal .form-actions {
  display: flex;
  gap: var(--spacing-md);
  justify-content: flex-end;
  margin-top: var(--spacing-sm);
  padding-top: var(--spacing-sm);
  border-top: 1px solid #e5e5e5;
}

#create-proposal-modal .form-row:last-of-type {
  margin-bottom: var(--spacing-sm);
}

/* Improved modal header layout with navigation */
.line-items-editor-modal .modal-header {
  flex-shrink: 0;
  margin-bottom: 0.5rem;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.modal-title-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
}

.modal-title-section .modal-title {
  margin: 0;
  font-size: 1.25rem;
}

.proposal-navigation,
.invoice-navigation {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.proposal-navigation .btn,
.invoice-navigation .btn {
  min-width: 36px;
  width: 36px;
  font-size: 1rem;
  padding: 0.15rem 0.3rem;
  font-weight: bold;
}

/* Client Profile button sits in the nav row but should auto-size like a normal button */
.proposal-navigation #client-profile-btn,
.invoice-navigation #client-profile-btn {
  width: auto;
  min-width: auto;
  padding: 0.25rem 0.75rem;
  font-size: 0.875rem;
  font-weight: bold;
  margin-left: 0.4rem;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Client info display row */
.line-items-editor-modal .form-row.client-info-row {
  margin-top: 0.2rem;
  margin-bottom: 0;
  padding: 0;
  align-items: center;
}

.client-info-display {
  font-size: 11px;
  color: #444;
  display: flex;
  align-items: center;
  gap: 0;
  flex-wrap: wrap;
}

.client-info-display strong {
  color: var(--primary-blue);
  margin-right: 0.4em;
  white-space: nowrap;
}

/* Spacer between client name and address */
.client-info-sep {
  display: inline-block;
  width: 2em;
}

/* Payment status row styling */
.line-items-editor-modal .form-row.payment-status-row {
  margin-top: 0.3rem;
  margin-bottom: 0.2rem;
  border-top: 1px solid #e0e0e0;
  padding-top: 0.3rem;
}

.line-items-editor-modal .form-row.payment-status-row .paid-checkbox-wrapper {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  height: 26px;
  cursor: pointer;
}

.line-items-editor-modal .form-row.payment-status-row .paid-checkbox-wrapper:hover label {
  color: #218838;
}

.line-items-editor-modal .form-row.payment-status-row .paid-checkbox-wrapper input[type="checkbox"] {
  transform: scale(0.9);
  accent-color: #28a745;
  margin: 0;
}

.line-items-editor-modal .form-row.payment-status-row .paid-checkbox-wrapper label {
  font-weight: 600;
  color: #28a745;
  margin: 0;
  font-size: 11px;
  cursor: pointer;
}

.line-items-editor-modal .form-row.payment-status-row input[type="date"]:disabled {
  background-color: #f8f9fa;
  color: #6c757d;
}

/* Payment Summary Two-Column Layout */
.payment-summary-section {
  margin-top: 0.4rem;
  border-top: 1px solid #e0e0e0;
  padding-top: 0.4rem;
  flex-shrink: 0;
}

.payment-summary-section h4 {
  margin: 0 0 0.25rem 0;
  color: var(--primary-blue, #154471);
  font-size: 0.85rem;
  font-weight: 600;
}

.payment-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0;
}

.payment-column {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.payment-column h5 {
  margin: 0 0 0.25rem 0;
  color: var(--primary-blue, #154471);
  font-size: 0.8rem;
  font-weight: 600;
  border-bottom: 1px solid #ddd;
  padding-bottom: 0.15rem;
}

.payment-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.1rem 0;
  font-size: 0.78rem;
}

.payment-line.total {
  border-top: 1px solid #ccc;
  margin-top: 0.15rem;
  padding-top: 0.2rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.payment-line.balance {
  border-top: 1px solid var(--primary-blue, #154471);
  margin-top: 0.15rem;
  padding-top: 0.2rem;
  font-size: 0.8rem;
  font-weight: 600;
}

.payment-line.additions .amount {
  color: #28a745;
  font-weight: 600;
}

.payment-line.credits .amount {
  color: #dc3545;
  font-weight: 600;
}

.payment-line .amount {
  font-weight: 500;
  font-family: 'Courier New', monospace;
}

/* Payment input styling - inline labels and inputs */
.payment-column div:has(input.payment-input) {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.2rem;
}

.payment-column div:has(input.payment-input) label {
  font-weight: 500;
  color: #495057;
  font-size: 0.75rem;
  white-space: nowrap;
  margin: 0;
  flex: 1;
}

.payment-input {
  flex: 0 0 auto !important;
  padding: 2px 6px !important;
  font-size: 11px !important;
  height: 22px !important;
  line-height: 1.2 !important;
  box-sizing: border-box !important;
  margin: 0 !important;
  width: 100px !important;
  border: 1px solid #ced4da;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  background-color: #fff;
  text-align: right;
  transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.payment-input:focus {
  outline: none;
  border-color: #21447a;
  box-shadow: 0 0 0 0.2rem rgba(33, 68, 122, 0.25);
}

/* Responsive design for payment summary */
@media (max-width: 768px) {
  .payment-summary-grid {
    grid-template-columns: 1fr;
    gap: 0.5rem;
  }

  .payment-column {
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 0.4rem;
  }

  .payment-column:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }
}
