/* Search Results Table Optimization */
.search-results-table {
  table-layout: fixed;
  font-size: 0.875rem;
  width: 100%;
}

.search-results-table th,
.search-results-table td {
  padding: 0.5rem 0.25rem;
  vertical-align: middle;
  overflow: visible;
  white-space: normal;
  word-wrap: break-word;
}

/* Optimized column widths for search results with responsive design */
.search-results-table th:nth-child(1), .search-results-table td:nth-child(1) { width: 18px; min-width: 18px; max-width: 18px; } /* Expand/Collapse */
.search-results-table th:nth-child(2), .search-results-table td:nth-child(2) { width: 22px; min-width: 22px; max-width: 22px; } /* Checkbox */
.search-results-table th:nth-child(3), .search-results-table td:nth-child(3) { width: 3%; min-width: 30px; white-space: nowrap; } /* # - No break for sequence numbers */
.search-results-table th:nth-child(4), .search-results-table td:nth-child(4) { width: 15%; min-width: 80px; } /* Code - Reduced to make room for Qty/Unit */
.search-results-table th:nth-child(5), .search-results-table td:nth-child(5) { width: 30%; min-width: 120px; } /* Product name - Reduced to make room for Qty/Unit */
.search-results-table th:nth-child(6), .search-results-table td:nth-child(6) { width: 7%; min-width: 60px; } /* Sold - Reduced */
.search-results-table th:nth-child(7), .search-results-table td:nth-child(7) { width: 7%; min-width: 60px; } /* Stock - Reduced */
.search-results-table th:nth-child(8), .search-results-table td:nth-child(8) { width: 8%; min-width: 60px; text-align: center; } /* Quantity - Optimized for single digits */
.search-results-table th:nth-child(9), .search-results-table td:nth-child(9) { width: 10%; min-width: 80px; text-align: center; } /* Unit - Increased min-width */
.search-results-table th:nth-child(10), .search-results-table td:nth-child(10) { width: 25px; min-width: 25px; max-width: 25px; text-align: center; } /* Comment */
.search-results-table th:nth-child(11), .search-results-table td:nth-child(11) { width: 25px; min-width: 25px; max-width: 25px; text-align: right; } /* Icon */

/* Responsive behavior for search results table */
@media (max-width: 1200px) {
  .search-results-table th:nth-child(4), .search-results-table td:nth-child(4) { width: 12%; min-width: 70px; } /* Code - Further reduced */
  .search-results-table th:nth-child(5), .search-results-table td:nth-child(5) { width: 25%; min-width: 100px; } /* Product name - Further reduced */
  .search-results-table th:nth-child(6), .search-results-table td:nth-child(6) { width: 7%; min-width: 60px; } /* Sold - Ensure full numeric visibility */
  .search-results-table th:nth-child(7), .search-results-table td:nth-child(7) { width: 7%; min-width: 60px; } /* Stock - Ensure full numeric visibility */
  .search-results-table th:nth-child(8), .search-results-table td:nth-child(8) { width: 9%; min-width: 60px; } /* Quantity - Ensure full numeric visibility */
  .search-results-table th:nth-child(9), .search-results-table td:nth-child(9) { width: 11%; min-width: 70px; } /* Unit - Maintain visibility */
}

@media (max-width: 992px) {
  .search-results-table th:nth-child(4), .search-results-table td:nth-child(4) { width: 10%; min-width: 60px; } /* Code - Minimal */
  .search-results-table th:nth-child(5), .search-results-table td:nth-child(5) { width: 20%; min-width: 80px; } /* Product name - Minimal */
  .search-results-table th:nth-child(6), .search-results-table td:nth-child(6) { width: 6%; min-width: 60px; } /* Sold - Ensure full numeric visibility */
  .search-results-table th:nth-child(7), .search-results-table td:nth-child(7) { width: 6%; min-width: 60px; } /* Stock - Ensure full numeric visibility */
  .search-results-table th:nth-child(8), .search-results-table td:nth-child(8) { width: 10%; min-width: 60px; } /* Quantity - Ensure full numeric visibility */
  .search-results-table th:nth-child(9), .search-results-table td:nth-child(9) { width: 12%; min-width: 60px; } /* Unit - Priority visibility */
}

@media (max-width: 768px) {
  .search-results-table {
    font-size: 0.75rem; /* Smaller font for mobile */
  }
  .search-results-table th:nth-child(4), .search-results-table td:nth-child(4) { width: 8%; min-width: 50px; } /* Code - Very minimal */
  .search-results-table th:nth-child(5), .search-results-table td:nth-child(5) { width: 18%; min-width: 60px; } /* Product name - Very minimal */
  .search-results-table th:nth-child(6), .search-results-table td:nth-child(6) { width: 7%; min-width: 60px; } /* Sold - Ensure full numeric visibility */
  .search-results-table th:nth-child(7), .search-results-table td:nth-child(7) { width: 7%; min-width: 60px; } /* Stock - Ensure full numeric visibility */
  .search-results-table th:nth-child(8), .search-results-table td:nth-child(8) { width: 11%; min-width: 60px; } /* Quantity - Ensure full numeric visibility */
  .search-results-table th:nth-child(9), .search-results-table td:nth-child(9) { width: 13%; min-width: 50px; } /* Unit - Critical visibility */
}

/* Ensure Qty and Unit columns are never hidden */
.search-results-table th:nth-child(8), .search-results-table td:nth-child(8),
.search-results-table th:nth-child(9), .search-results-table td:nth-child(9) {
  display: table-cell !important; /* Force visibility */
  visibility: visible !important;
  opacity: 1 !important;
}

/* Compact form controls */
.search-results-table .form-control-sm,
.search-results-table .form-select-sm {
  font-size: 0.75rem;
  padding: 0.125rem 0.25rem;
  height: auto;
  min-height: 1.5rem;
  width: 100%;
  box-sizing: border-box;
}

/* Optimize Qty input field for single-digit numbers - show full values */
.search-results-table th:nth-child(8) .form-control-sm,
.search-results-table td:nth-child(8) .form-control-sm {
  text-align: center;
  min-width: 50px;
  width: 100%;
  margin: 0 auto;
}

/* Ensure Qty column shows full numeric values */
.search-results-table th:nth-child(8), .search-results-table td:nth-child(8) {
  overflow: visible;
  white-space: nowrap;
  min-width: 60px;
}

/* Ensure select dropdowns are fully visible */
.search-results-table .form-select-sm {
  padding-right: 1.5rem; /* Space for dropdown arrow */
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m1 6 7 7 7-7'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.375rem center;
  background-size: 0.75rem;
}

/* Compact buttons */
.search-results-table .btn-sm {
  font-size: 0.75rem;
  padding: 0.125rem 0.25rem;
  line-height: 1.2;
}


/* Numeric columns alignment */
.search-results-table .text-end {
  text-align: right;
  font-family: monospace;
  font-size: 0.8rem;
}

/* Prevent Stock column overflow - show full numeric values */
.search-results-table th:nth-child(7), .search-results-table td:nth-child(7) {
  overflow: visible;
  white-space: nowrap;
  min-width: 60px;
}

/* Prevent Sold column overflow - show full numeric values */
.search-results-table th:nth-child(6), .search-results-table td:nth-child(6) {
  overflow: visible;
  white-space: nowrap;
  min-width: 60px;
}

/* Ensure checkboxes are always visible */
.search-results-table input[type="checkbox"] {
  width: auto !important;
  min-width: 16px;
  margin: 0;
}


/* Ensure first column stays exactly 20px */
.search-results-table th:nth-child(1),
.search-results-table td:nth-child(1) {
  width: 20px !important;
  min-width: 20px !important;
  max-width: 20px !important;
  padding: 0.5rem 0 !important;
  box-sizing: border-box;
  overflow: hidden;
}

.search-results-table td:nth-child(1) {
  background-color: transparent;
  border-right: none;
}

/* Ensure first column stays exactly 20px in all screen sizes */
@media (max-width: 768px) {
  .search-results-table th:nth-child(1),
  .search-results-table td:nth-child(1) {
    width: 20px !important;
    min-width: 20px !important;
    max-width: 20px !important;
  }
}

@media (max-width: 576px) {
  .search-results-table th:nth-child(1),
  .search-results-table td:nth-child(1) {
    width: 20px !important;
    min-width: 20px !important;
    max-width: 20px !important;
  }
}

/* AI Parsing Result Table */
.ai-parsing-table {
  table-layout: fixed;
  font-size: 0.875rem;
}

.ai-parsing-table th,
.ai-parsing-table td {
  padding: 0.5rem 0.25rem;
  vertical-align: middle;
  overflow: visible;
  white-space: normal;
  word-wrap: break-word;
}

/* AI parsing table - column classes */
.ai-parsing-table .col-num { width: 5%; min-width: 30px; }
.ai-parsing-table .col-product-name { width: 35%; }
.ai-parsing-table .col-qty { width: 10%; min-width: 80px; }
.ai-parsing-table .col-unit { width: 8%; }
.ai-parsing-table .col-attributes-icon { width: 5%; min-width: 40px; }
.ai-parsing-table .col-qty-corrected { width: 10%; min-width: 80px; }
.ai-parsing-table .col-unit-corrected { width: 8%; }
.ai-parsing-table .col-changes { width: 5%; min-width: 40px; }
.ai-parsing-table .col-actions { width: 12%; min-width: 100px; }
.ai-parsing-table .col-info-icon { width: 5%; min-width: 30px; }

/* Numeric columns alignment for AI table */
.ai-parsing-table .text-end {
  text-align: right;
  font-family: monospace;
  font-size: 0.8rem;
}

/* Icon columns centered */
.ai-parsing-table th:nth-child(3),
.ai-parsing-table td:nth-child(3),
.ai-parsing-table th:nth-child(6),
.ai-parsing-table td:nth-child(6),
.ai-parsing-table th:nth-child(7),
.ai-parsing-table td:nth-child(7) {
  text-align: center;
}

/* Icon styling */
.ai-parsing-table .fa {
  font-size: 0.875rem;
  cursor: help;
}

/* Action buttons styling */
.ai-parsing-table .btn-sm {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

.ai-parsing-table .btn-sm i {
  font-size: 0.75rem;
}

/* Optimize main email list table rendering */
.email-registry-table {
  table-layout: fixed;
  width: 100%;
  min-width: 1200px; /* Ensure minimum width to prevent column compression */
}

.email-registry-table th,
.email-registry-table td {
  overflow: visible;
  white-space: normal;
  word-wrap: break-word;
}

/* Email Registry List Table - specific column widths */
.email-registry-table th:nth-child(1),
.email-registry-table td:nth-child(1) { width: 3%; } /* Checkbox */
.email-registry-table th:nth-child(2),
.email-registry-table td:nth-child(2) { width: 10%; } /* Received */
.email-registry-table th:nth-child(3),
.email-registry-table td:nth-child(3) { width: 15%; } /* From */
.email-registry-table th:nth-child(4),
.email-registry-table td:nth-child(4) { width: 12%; } /* Customer */
.email-registry-table th:nth-child(5),
.email-registry-table td:nth-child(5) { width: 20%; } /* Subject */
.email-registry-table th:nth-child(6),
.email-registry-table td:nth-child(6) { width: 10%; } /* Mailbox */
.email-registry-table th:nth-child(7),
.email-registry-table td:nth-child(7) { width: 8%; } /* Category */
.email-registry-table th:nth-child(8),
.email-registry-table td:nth-child(8) { width: 8%; } /* Language */
.email-registry-table th:nth-child(9),
.email-registry-table td:nth-child(9) { width: 8%; } /* Status */
.email-registry-table th:nth-child(10),
.email-registry-table td:nth-child(10) { width: 3%; } /* Attachment icon */
.email-registry-table th:nth-child(11),
.email-registry-table td:nth-child(11) { width: 8%; } /* Actions */

/* Container for email registry table to handle overflow */
.email-registry-container {
  overflow-x: auto;
  width: 100%;
}

/* Table headers with ellipsis */
.email-registry-table th,
.search-results-table th,
.ai-parsing-table th {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Allow text truncation with tooltips */
.text-truncate {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Optimize form controls */
.form-select-sm {
  font-size: 0.875rem;
  padding: 0.25rem 0.5rem;
}

/* Loading states */
.opacity-50 {
  opacity: 0.5;
  pointer-events: none;
}

/* Sortable column indicators */
.sortable {
  cursor: pointer;
  user-select: none;
}

.sortable:hover {
  background-color: rgba(0, 0, 0, 0.05);
}

/* Responsive table improvements */
@media (max-width: 768px) {
  .table-responsive {
    font-size: 0.875rem;
  }

  .table th:nth-child(5), .table td:nth-child(5) { display: none; } /* Hide To column on mobile */
  .table th:nth-child(7), .table td:nth-child(7) { display: none; } /* Hide Language column on mobile */
}

/* Root and variables */
:root {
  --primary-color: #0066cc;
  --primary-hover: #005bb5;
  --bg-color: #f5f7fa;
  --white: #ffffff;
  --border-color: #dde2e6;
  --text-color: #333333;
  --label-color: #555555;
  --input-bg: #ffffff;
}

/* Extra small button size */
.btn-xs {
  padding: 0.125rem 0.25rem;
  font-size: 0.75rem;
  line-height: 1.2;
  border-radius: 0.2rem;
}

/* Close icon (×) for modals */
.modal-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
}

/* Base styles */
body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-color);
}

/* Highlight row on drag over in importable fields */
tr.drag-over {
  background-color: #e9ecef;
}
.container {
  position: relative;
  max-width: none !important;
  margin: 50px auto;
  background-color: var(--white);
  padding: 30px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
/* Login form specific width */
.login-container {
	max-width: 400px !important;
}
h1 {
  margin-top: 0;
  font-size: 28px;
  font-weight: 600;
  text-align: center;
  color: var(--text-color);
}

/* Form styles */
.form-group {
  display: flex;
  flex-direction: column;
  margin-bottom: 20px;
}
.form-group label {
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--label-color);
}
/* Align all Bootstrap form controls to small button height */
.form-control,
.form-control-sm,
.form-select,
.form-select-sm {
  padding: .25rem .5rem;
  line-height: 1.5;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background-color: var(--input-bg);
  font-size: .875rem;
  transition: border-color 0.2s;
}
/* Reserve space for select arrow */
.form-select,
.form-select-sm {
  padding-right: 2rem;
}
input:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary-color);
}
.form-actions {
  display: flex;
  justify-content: center;
}
.submit-btn {
  background-color: var(--primary-color);
  color: var(--white);
  border: none;
  border-radius: 4px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
}
.submit-btn:hover {
  background-color: var(--primary-hover);
}

/* Results table */
#results {
  margin-top: 30px;
}

/* Full-page loader overlay */
.loader-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  /* overlay above modals */
  z-index: 20000 !important;
}
#results table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}
#results th,
#results td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}
#results th {
  background-color: var(--white);
  position: sticky;
  top: 0;
  z-index: 1;
  font-weight: 600;
}
#results tbody tr:hover {
  background-color: #fafafa;
  cursor: pointer;
}
#results input[type='number'] {
  width: 70px;
  padding: 6px;
}
#results input[type='checkbox'] {
  transform: scale(1.2);
  margin-right: 8px;
}

/* Dashboard grid layout */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}
.dashboard-cell {
  position: relative;
}

/* ensure dropdown menus on dashboard are visible above the grid */
.dashboard-cell .dropdown {
  z-index: 10;
}

/* Action button */
.action-btn {
  display: inline-block;
  background-color: var(--primary-color);
  color: var(--white);
  border: none;
  border-radius: 4px;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
  margin-top: 20px;
}
/* Filters row */
.filters {
  display: flex;
  gap: 1em;
  margin-bottom: 1em;
  align-items: center;
}
/* List grid rows */
.list {
  display: grid;
  grid-template-rows: auto;
  gap: 0.5em;
}
.list .row {
  display: grid;
  grid-template-columns: 50px 150px 1fr 200px 150px 200px;
  gap: 1em;
  padding: 0.5em;
  background: var(--white);
  border-radius: 4px;
  align-items: center;
}
.list .header {
  font-weight: 600;
  background: none;
  border-bottom: 2px solid var(--border-color);
}
/* Modal */
/* Modal overlay and container styles (generic modal) */
.modal:not(.fade) {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex !important;
  justify-content: center;
  align-items: center;
  z-index: 2000;
}
.modal:not(.fade).hidden {
  display: none !important;
}
.modal-content {
  background: var(--white);
  padding: 2em;
  border-radius: 8px;
  min-width: 500px;
  max-width: 99%;
  position: relative;
}
/* Allow scrolling when content exceeds viewport height */
.modal-body {
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}

/* Preserve line breaks in email body */
.email-body {
  white-space: pre-wrap;
  word-wrap: break-word;
  margin-bottom: 1em;
}
/* Sticky footer for Create Document button in email details */
/* Footer slot in GenericModal: always sticky at bottom */
.modal-footer {
  position: sticky;
  bottom: 0;
  background-color: var(--white);
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border-color);
  z-index: 10;
}
.action-btn:hover {
  background-color: var(--primary-hover);
}
/* Sortable table headers indicators */
th.sortable {
  cursor: pointer;
}
th.sortable::after {
  content: '\2195';
  font-size: .75rem;
  margin-left: .25rem;
  opacity: .5;
}
th.sortable[aria-sort="asc"]::after {
  content: '\2191';
}
th.sortable[aria-sort="desc"]::after {
  content: '\2193';
}
/* Toast notifications container */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  /* ensure toasts always overlay modals */
  z-index: 20000 !important;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}
/* Toast common style */
.toast {
  min-width: 200px;
  margin-top: 10px;
  padding: 12px 20px;
  border-radius: 4px;
  color: #000;
  opacity: 0.95;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  font-size: 14px;
  /* ensure visibility above bootstrap defaults */
  display: block !important;
}
.toast.success { background-color: #D4EDDA; color: #155724; }
.toast.error   { background-color: #F8D7DA; color: #721C24; }
.toast.warning { background-color: #FFF3CD; color: #856404; }
.toast.info    { background-color: #D1ECF1; color: #0C5460; }

/* MSSQL connection status */
#connection-status {
  margin-bottom: 1em;
  font-weight: bold;
}
#connection-status.success { color: #155724; }
#connection-status.error   { color: #721C24; }
/* Logout button (in top-right of container) */
.logout-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  color: var(--primary-color);
  font-size: 14px;
  cursor: pointer;
  transition: color 0.2s;
}
.logout-btn:hover {
  color: var(--primary-hover);
}
/* Header navigation */
nav {
  background-color: var(--primary-color);
  padding: 0.5em;
}
nav .header-menu {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
}
nav .header-menu li {
  margin-right: 1em;
}
nav .header-menu li a {
  color: var(--white);
  text-decoration: none;
  font-weight: 500;
}
nav .header-menu li a:hover {
  text-decoration: underline;
}
nav .header-menu li.active a {
  text-decoration: underline;
}
/* Slide toggle containers */
.slidable {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}
.slidable.open {
  max-height: 1000px;
}

/* Comment field styling */
.comment-field {
  position: relative;
  width: 100%;
}

.comment-preview {
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background-color: #f8f9fa;
  cursor: pointer;
  font-size: 0.875rem;
  color: #6c757d;
  min-height: 32px;
  display: flex;
  align-items: center;
  transition: background-color 0.2s ease;
}

.comment-preview:hover {
  background-color: #e9ecef;
  border-color: #adb5bd;
}

.comment-preview:not(:empty) {
  color: #495057;
  background-color: #ffffff;
}

.comment-textarea {
  resize: vertical;
  min-height: 60px;
  font-size: 0.875rem;
}

/* Document items table layout */
.document-items-table {
  table-layout: fixed;
  width: 100%;
}

.document-items-table th.col-number,
.document-items-table td:first-child {
  width: 40px;
  text-align: center;
}

.document-items-table th.col-code,
.document-items-table td:nth-child(2) {
  width: 120px;
}

.document-items-table th.col-name,
.document-items-table td:nth-child(3) {
  width: 200px;
}

.document-items-table th.col-quantity,
.document-items-table td:nth-child(4) {
  width: 100px;
}

.document-items-table th.col-unit,
.document-items-table td:nth-child(5) {
  width: 80px;
}

.document-items-table th.col-price,
.document-items-table td:nth-child(6) {
  width: 100px;
}

.document-items-table th.col-discount,
.document-items-table td:nth-child(7) {
  width: 100px;
}

.document-items-table th.col-comment,
.document-items-table td:nth-child(8) {
  width: 200px;
}

.document-items-table th.col-actions,
.document-items-table td:last-child {
  width: 50px;
  text-align: center;
}

/* Ensure inputs fit within their columns */
.document-items-table input,
.document-items-table select {
  width: 100%;
  min-width: 0;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 1200px) {
  .document-items-table th.col-name,
  .document-items-table td:nth-child(3) {
    width: 150px;
  }

  .document-items-table th.col-comment,
  .document-items-table td:nth-child(8) {
    width: 150px;
  }
}

@media (max-width: 992px) {
  .document-items-table th.col-code,
  .document-items-table td:nth-child(2) {
    width: 100px;
  }

  .document-items-table th.col-name,
  .document-items-table td:nth-child(3) {
    width: 120px;
  }

  .document-items-table th.col-comment,
  .document-items-table td:nth-child(8) {
    width: 120px;
  }
}