@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;700&display=swap');

/**
 * Sale Order Table V4 - Main Styles
 * KBank Green Theme with responsive design
 */

/* ==================== Variables ==================== */
:root {
  /* Primary Colors (KBank Green) */
  --primary-50: #e6f3f0;
  --primary-100: #cce7e0;
  --primary-200: #99cfc1;
  --primary-300: #66b7a2;
  --primary-400: #339f83;
  --primary-500: #138871;
  --primary-600: #0f6d5b;
  --primary-700: #0d725e;
  --primary-800: #094538;
  --primary-900: #05291c;

  /* Secondary Colors (Dark Green Accent) */
  --secondary-50: #f0fdf4;
  --secondary-100: #dcfce7;
  --secondary-200: #bbf7d0;
  --secondary-300: #86efac;
  --secondary-400: #4ade80;
  --secondary-500: #34d399;
  --secondary-600: #16a34a;
  --secondary-700: #15803d;
  --secondary-800: #166534;
  --secondary-900: #14532d;

  /* Gray Scale */
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;

  /* Modern Shadows */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);

  /* Border Radius */
  --radius-sm: 0.375rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;

  /* Success/Danger Colors */
  --success-50: #f0fdf4;
  --success-100: #dcfce7;
  --success-500: #22c55e;
  --success-600: #16a34a;
  --success-700: #15803d;
  --danger-50: #fef2f2;
  --danger-100: #fee2e2;
  --danger-500: #ef4444;
  --danger-600: #dc2626;
  --danger-700: #b91c1c;
}

/* ==================== Base Styles ==================== */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

/* ==================== Container ==================== */
.so-table-v4-container {
  max-width: 95%;
  margin: 2rem auto;
  padding: 0 1rem;
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  background:
    linear-gradient(135deg, rgba(19, 136, 113, 0.03) 0%, rgba(52, 211, 153, 0.02) 100%),
    repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(19, 136, 113, 0.015) 10px, rgba(19, 136, 113, 0.015) 20px),
    linear-gradient(135deg, #e6f3f0 0%, #f9fafb 100%);
  line-height: 1.6;
  min-height: 100vh;
}

/* ==================== Header ==================== */
.so-table-header {
  margin-bottom: 2rem;
  padding: 2rem;
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  color: white;
}

.so-table-title {
  font-size: 2.25rem;
  font-weight: 700;
  color: white;
  margin-bottom: 0.5rem;
  letter-spacing: -0.025em;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.so-table-subtitle {
  font-size: 1.125rem;
  color: var(--primary-100);
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* ==================== Sticky Header (Filter + Table Head) ==================== */
.so-sticky-header {
  position: sticky;
  top: 0;
  z-index: 999;
  background: white;
  transition: box-shadow 0.2s ease;
}

.so-sticky-header.is-stuck {
  box-shadow: var(--shadow-lg);
  z-index: 999;
}

.so-header-scroll {
  overflow: hidden;
}

.so-table-head-only {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}

/* ==================== Filter Bar ==================== */
.so-filter-bar {
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 0.875rem 1rem;
  margin-bottom: 0;
  border: 1px solid var(--gray-200);
  transition: box-shadow 0.2s ease, border-radius 0.2s ease;
}

.so-sticky-header.is-stuck .so-filter-bar {
  box-shadow: none;
  border-radius: 0;
  border-left: none;
  border-right: none;
  border-top: none;
}

/* ==================== Inline Filter ==================== */
.so-filter-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: nowrap;
}

.so-filter-inline-field {
  flex: 1 1 0;
  min-width: 0;
}

.so-filter-input-sm,
.so-filter-select-sm {
  width: 100%;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 500;
  transition: all 0.15s ease;
  background-color: white;
  color: var(--gray-700);
}

.so-filter-input-sm::placeholder {
  color: var(--gray-400);
  font-size: 0.8125rem;
}

.so-filter-input-sm:hover,
.so-filter-select-sm:hover {
  border-color: var(--gray-400);
}

.so-filter-input-sm:focus,
.so-filter-select-sm:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(19, 136, 113, 0.1);
}

.so-filter-select-sm {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-position: right 0.375rem center;
  background-repeat: no-repeat;
  background-size: 1.25rem 1.25rem;
  padding-right: 1.875rem;
}

.so-filter-inline-actions {
  display: flex;
  gap: 0.375rem;
  margin-left: auto;
  flex-shrink: 0;
}

.so-btn-sm {
  padding: 0.375rem 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}

.so-btn-primary-sm {
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
  color: white;
}

.so-btn-primary-sm:hover {
  background: linear-gradient(135deg, var(--primary-700) 0%, var(--primary-800) 100%);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.so-btn-secondary-sm {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}

.so-btn-secondary-sm:hover {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.so-btn {
  padding: 0.625rem 1.5rem;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-sm);
}

.so-btn-primary {
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
  color: white;
  box-shadow: var(--shadow-md);
}

.so-btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-700) 0%, var(--primary-800) 100%);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.so-btn-secondary {
  background-color: white;
  color: var(--gray-700);
  border: 2px solid var(--gray-300);
}

.so-btn-secondary:hover {
  background-color: var(--gray-50);
  border-color: var(--gray-400);
}

/* ==================== Table Container ==================== */
.so-table-wrapper {
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  margin-bottom: 1.5rem;
  border: 1px solid var(--gray-200);
  max-width: 100%;
}

.so-table-scroll {
  overflow-x: auto;
  overflow-y: visible;
  width: 100%;
  -webkit-overflow-scrolling: touch;
}

.so-table-scroll::-webkit-scrollbar {
  height: 10px;
}

.so-table-scroll::-webkit-scrollbar-track {
  background: var(--gray-100);
}

.so-table-scroll::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, var(--primary-400) 0%, var(--primary-500) 100%);
  border-radius: 5px;
}

.so-table-scroll::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
}

/* ==================== Table ==================== */
.so-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}

.so-table thead {
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 50%, var(--primary-800) 100%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.so-table th {
  padding: 0.875rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  color: white;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  white-space: nowrap;
  position: relative;
}

.so-table th:last-child {
  border-right: none;
}

.so-table th.sortable {
  cursor: pointer;
  user-select: none;
  transition: all 0.2s ease;
}

.so-table th.sortable:hover {
  background-color: rgba(255, 255, 255, 0.15);
}

.so-table th.sortable:active {
  background-color: rgba(255, 255, 255, 0.2);
}

.so-sort-icon {
  display: inline-block;
  margin-left: 0.375rem;
  opacity: 0.6;
  transition: all 0.2s ease;
  font-size: 0.75rem;
}

.so-table th.sorted .so-sort-icon {
  opacity: 1;
  transform: scale(1.1);
}

.so-table tbody tr {
  border-bottom: 1px solid var(--gray-200);
  transition: all 0.2s ease;
}

.so-table tbody tr:hover {
  background-color: var(--primary-50);
  box-shadow: inset 0 0 0 1px var(--primary-200);
}

.so-table tbody tr.row-updated {
  animation: highlight 2s ease-in-out;
}

.so-table td {
  padding: 0.875rem 1rem;
  color: var(--gray-800);
  border-right: 1px solid var(--gray-100);
  font-weight: 500;
  line-height: 1.5;
  vertical-align: middle;
}

.so-table td:last-child {
  border-right: none;
}

/* ==================== Cell Types ==================== */
.so-cell-code {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 700;
  font-size: 1.08rem;
  color: var(--primary-600);
}

.so-cell-name {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.so-cell-status {
  display: inline-flex;
  padding: 0.375rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.8125rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary-100) 0%, var(--primary-200) 100%);
  color: var(--primary-800);
  border: 1px solid var(--primary-200);
  box-shadow: var(--shadow-sm);
  letter-spacing: 0.01em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.5);
}

/* Status Badge Variants */
.so-cell-status.status-pending {
  background: linear-gradient(135deg, var(--secondary-100) 0%, var(--secondary-200) 100%);
  color: var(--secondary-800);
  border-color: var(--secondary-300);
}

.so-cell-status.status-completed {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
  color: #065f46;
  border-color: #6ee7b7;
}

.so-cell-status.status-cancelled {
  background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
  color: #991b1b;
  border-color: #fca5a5;
}

.so-cell-amount {
  font-weight: 600;
  text-align: right;
}

/* Sales Status Column */
.so-table tbody .so-col-rg_salesstatus span {
  padding: 3px 5px;
  white-space: nowrap;
  font-size: 12px;
}

/* Customer Column - Bold secondary text */
.so-table .so-col-customer .so-stacked-secondary {
  font-weight: 600;
}

/* SO/PO Column - Code size */
.so-table .so-col-so_po .so-stacked-primary .so-cell-code {
  font-size: 15px;
}

/* Stacked Secondary Code size */
.so-table .so-stacked-secondary .so-cell-code {
  font-size: 15px;
}

.so-cell-doc-badge {
  display: inline-block;
  padding: 0.375rem 0.625rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-sm);
  border: 1px solid transparent;
}

.so-doc-quotation {
  background: linear-gradient(135deg, var(--primary-100) 0%, var(--primary-200) 100%);
  color: var(--primary-800);
  border-color: var(--primary-300);
}

.so-doc-invoice {
  background: linear-gradient(135deg, var(--secondary-100) 0%, var(--secondary-200) 100%);
  color: var(--secondary-800);
  border-color: var(--secondary-300);
}

.so-doc-receipt {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
  color: #065f46;
  border-color: #6ee7b7;
}

/* ==================== Stacked Cells ==================== */
.so-stacked-cell {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 120px;
}

.so-stacked-primary {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--gray-900);
  line-height: 1.4;
}

.so-stacked-secondary {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--gray-600);
  line-height: 1.4;
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Allow delivery cell content to wrap */
.so-stacked-cell .so-stacked-secondary {
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  overflow: visible;
  text-overflow: unset;
  max-width: none;
}

/* Product cell - reduce width by 30% */
.so-product-cell {
  max-width: 170px;
  min-width: 100px;
}

.so-product-cell .so-stacked-secondary {
  max-width: 150px;
}

.so-text-small {
  font-size: 0.75rem;
}

/* ==================== SO/PO Badges ==================== */
.so-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.125rem 0.5rem;
  border-radius: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.025em;
  text-transform: uppercase;
  margin-right: 0.375rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid transparent;
}

.so-badge-so {
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
  color: white;
  border-color: var(--primary-600);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.so-badge-po {
  background: linear-gradient(135deg, var(--secondary-500) 0%, var(--secondary-600) 100%);
  color: white;
  border-color: var(--secondary-600);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.so-stacked-cell .so-cell-code {
  display: inline;
  margin-left: 0.25rem;
}

/* ==================== Amount Cells ==================== */
.so-amount-cell {
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  transition: all 0.2s ease;
  background-color: var(--gray-50);
  border: 1px solid var(--gray-200);
}

.so-amount-cell.so-amount-matched {
  background: linear-gradient(135deg, var(--success-50) 0%, var(--success-100) 100%);
  border-color: var(--success-500);
}

.so-amount-cell.so-amount-saved {
  animation: pulse-green 0.6s ease-out;
}

@keyframes pulse-green {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
  50% {
    box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.3);
  }
}

.so-amount-value {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--gray-900);
}

.so-amount-display {
  flex: 1;
}

.so-amount-edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-500);
  transition: all 0.15s ease;
  border-radius: var(--radius-sm);
}

.so-amount-edit-btn:hover {
  color: var(--primary-600);
  background-color: var(--primary-50);
}

.so-amount-edit-btn svg {
  width: 0.875rem;
  height: 0.875rem;
}

.so-amount-input {
  width: 100%;
  padding: 0.375rem 0.5rem;
  border: 2px solid var(--primary-500);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--gray-900);
  background-color: white;
  outline: none;
  box-shadow: 0 0 0 3px rgba(19, 136, 113, 0.1);
}

.so-amount-input:focus {
  border-color: var(--primary-600);
  box-shadow: 0 0 0 4px rgba(19, 136, 113, 0.15);
}

/* Trend Indicators */
.so-amount-trend {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem;
  border-radius: 50%;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.so-amount-trend-up {
  background-color: var(--success-100);
  color: var(--success-700);
}

.so-amount-trend-up svg {
  width: 0.875rem;
  height: 0.875rem;
  filter: drop-shadow(0 1px 2px rgba(21, 128, 61, 0.2));
}

.so-amount-trend-down {
  background-color: var(--danger-100);
  color: var(--danger-700);
}

.so-amount-trend-down svg {
  width: 0.875rem;
  height: 0.875rem;
  filter: drop-shadow(0 1px 2px rgba(185, 28, 28, 0.2));
}

/* Text color classes */
.so-text-green {
  color: var(--success-700) !important;
  font-weight: 700 !important;
  text-shadow: 0 1px 2px rgba(21, 128, 61, 0.1);
}

.so-text-red {
  color: var(--danger-600) !important;
  font-weight: 700 !important;
  text-shadow: 0 1px 2px rgba(220, 38, 38, 0.1);
}

/* ==================== Action Menu ==================== */
.so-action-menu {
  position: relative;
  display: inline-block;
}

.so-action-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  color: var(--gray-600);
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
}

.so-action-btn svg {
  width: 1.25rem;
  height: 1.25rem;
}

.so-action-btn:hover {
  color: var(--gray-900);
  background-color: var(--gray-100);
}

.so-action-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  min-width: 180px;
  background: white;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--gray-200);
  display: none;
  z-index: 50;
  margin-top: 0.5rem;
  animation: fadeIn 0.2s ease-out;
  overflow: hidden;
}

.so-action-dropdown.visible {
  display: block;
}

.so-action-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--gray-700);
  cursor: pointer;
  transition: all 0.15s ease;
  border: none;
  background: white;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid var(--gray-100);
}

.so-action-item:last-child {
  border-bottom: none;
}

.so-action-item svg {
  width: 1.125rem;
  height: 1.125rem;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.so-action-item:hover {
  background: linear-gradient(to right, var(--gray-50) 0%, var(--gray-100) 100%);
}

.so-action-item:hover svg {
  transform: scale(1.1);
}

.so-action-item.edit {
  color: var(--primary-700);
}

.so-action-item.edit:hover {
  background: linear-gradient(to right, var(--primary-50) 0%, var(--primary-100) 100%);
  color: var(--primary-800);
}

.so-action-item.print {
  color: var(--secondary-700);
}

.so-action-item.print:hover {
  background: linear-gradient(to right, var(--secondary-50) 0%, var(--secondary-100) 100%);
  color: var(--secondary-800);
}

.so-action-item.delete {
  color: #dc2626;
}

.so-action-item.delete:hover {
  background: linear-gradient(to right, #fef2f2 0%, #fee2e2 100%);
  color: #991b1b;
}

/* ==================== Pagination ==================== */
.so-pagination {
  background: linear-gradient(to bottom, white 0%, var(--gray-50) 100%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 1.25rem 1.75rem;
  border: 1px solid var(--gray-200);
}

.so-pagination-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.so-pagination-per-page {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.so-pagination-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--gray-700);
}

.so-pagination-select {
  padding: 0.5rem 0.75rem;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  background-color: white;
  transition: all 0.2s ease;
  cursor: pointer;
}

.so-pagination-select:hover {
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(19, 136, 113, 0.1);
}

.so-pagination-select:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 4px rgba(19, 136, 113, 0.15);
}

.so-pagination-info {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.so-pagination-text {
  font-size: 0.875rem;
  color: var(--gray-600);
}

.so-pagination-numbers {
  display: flex;
  gap: 0.25rem;
}

.so-pagination-btn {
  padding: 0.5rem 0.875rem;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-md);
  background: white;
  color: var(--gray-700);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: var(--shadow-sm);
}

.so-pagination-btn:hover:not(:disabled) {
  background: linear-gradient(to bottom, white 0%, var(--gray-50) 100%);
  border-color: var(--primary-400);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.so-pagination-btn.active {
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
  color: white;
  border-color: var(--primary-700);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.so-pagination-btn.active:hover {
  background: linear-gradient(135deg, var(--primary-700) 0%, var(--primary-800) 100%);
  transform: translateY(0);
}

.so-pagination-btn:disabled {
  background-color: var(--gray-100);
  color: var(--gray-400);
  cursor: not-allowed;
  opacity: 0.6;
  box-shadow: none;
}

/* ==================== Loading States ==================== */
.so-skeleton {
  animation: shimmer 2s infinite ease-in-out;
  background: linear-gradient(
    90deg,
    var(--gray-200) 0%,
    var(--gray-300) 25%,
    var(--gray-200) 50%,
    var(--gray-300) 75%,
    var(--gray-200) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.05);
}

.so-skeleton-row {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-200);
}

.so-skeleton-cell {
  height: 1.25rem;
}

.so-loading-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0.9) 100%);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  animation: fadeIn 0.2s ease-out;
}

.so-spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 4px solid var(--gray-200);
  border-top-color: var(--primary-600);
  border-right-color: var(--secondary-500);
  border-radius: 50%;
  animation: spin 0.8s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
  box-shadow: var(--shadow-lg);
}

/* ==================== Empty State ==================== */
.so-empty-state {
  padding: 4rem 2rem;
  text-align: center;
  background: linear-gradient(135deg, var(--gray-50) 0%, white 100%);
  border-radius: var(--radius-lg);
}

.so-empty-icon {
  width: 5rem;
  height: 5rem;
  margin: 0 auto 1.5rem;
  color: var(--gray-400);
  opacity: 0.7;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.05));
}

.so-empty-title {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--gray-700);
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
}

.so-empty-text {
  font-size: 1rem;
  color: var(--gray-500);
  line-height: 1.6;
  max-width: 400px;
  margin: 0 auto;
}

/* ==================== Error State ==================== */
.so-error-state {
  background: linear-gradient(135deg, #fef2f2 0%, #fee2e2 100%);
  border: 2px solid #fca5a5;
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  text-align: center;
  box-shadow: var(--shadow-md);
}

.so-error-icon {
  width: 4rem;
  height: 4rem;
  margin: 0 auto 1.25rem;
  color: #ef4444;
  filter: drop-shadow(0 2px 4px rgba(239, 68, 68, 0.2));
}

.so-error-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #991b1b;
  margin-bottom: 0.75rem;
  letter-spacing: -0.01em;
}

.so-error-text {
  font-size: 1rem;
  color: #dc2626;
  margin-bottom: 1.5rem;
  line-height: 1.6;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

.so-btn-error {
  background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
  color: white;
  padding: 0.625rem 1.5rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  box-shadow: var(--shadow-md);
  transition: all 0.2s ease;
}

.so-btn-error:hover {
  background: linear-gradient(135deg, #b91c1c 0%, #991b1b 100%);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

/* ==================== Animations ==================== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes highlight {
  0% {
    background-color: rgba(251, 146, 60, 0.2);
  }
  100% {
    background-color: transparent;
  }
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ==================== Responsive ==================== */
@media (max-width: 1024px) {
  .so-stacked-cell {
    min-width: 100px;
  }

  .so-stacked-primary {
    font-size: 0.875rem;
  }

  .so-stacked-secondary {
    font-size: 0.75rem;
    max-width: 200px;
  }

  .so-badge {
    font-size: 0.625rem;
    padding: 0.125rem 0.375rem;
  }

  .so-filter-inline-field {
    min-width: 110px;
  }

  .so-filter-input-sm,
  .so-filter-select-sm {
    font-size: 0.75rem;
  }
}

@media (max-width: 768px) {
  .so-table-v4-container {
    padding: 0 0.5rem;
    margin: 1rem auto;
  }

  .so-stacked-cell {
    min-width: 90px;
    gap: 0.25rem;
  }

  .so-stacked-primary {
    font-size: 0.8125rem;
  }

  .so-stacked-secondary {
    font-size: 0.6875rem;
    max-width: 150px;
  }

  .so-text-small {
    font-size: 0.6875rem;
  }

  .so-badge {
    font-size: 0.5625rem;
    padding: 0.0625rem 0.3125rem;
    margin-right: 0.25rem;
  }

  .so-table-header {
    padding: 1.5rem 1rem;
    margin-bottom: 1.5rem;
  }

  .so-table-title {
    font-size: 1.75rem;
  }

  .so-table-subtitle {
    font-size: 1rem;
  }

  .so-filter-bar {
    padding: 0.75rem;
  }

  .so-filter-inline {
    gap: 0.375rem;
  }

  .so-filter-inline-field {
    min-width: 100px;
    flex: 1 1 calc(50% - 0.375rem);
  }

  .so-filter-input-sm,
  .so-filter-select-sm {
    font-size: 0.75rem;
    padding: 0.3125rem 0.5rem;
  }

  .so-filter-select-sm {
    padding-right: 1.625rem;
    background-size: 1rem 1rem;
  }

  .so-filter-inline-actions {
    flex: 1 1 100%;
    margin-left: 0;
    justify-content: stretch;
  }

  .so-btn-sm {
    flex: 1;
    font-size: 0.75rem;
    padding: 0.3125rem 0.625rem;
  }

  .so-pagination {
    padding: 1rem;
  }

  .so-pagination-content {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .so-pagination-numbers {
    display: none;
  }

  .so-table th,
  .so-table td {
    padding: 0.625rem 0.5rem;
    font-size: 0.8125rem;
  }

  .so-modal {
    width: 95%;
    max-height: 95vh;
  }

  .so-modal-header,
  .so-modal-body,
  .so-modal-footer {
    padding: 1.25rem;
  }

  .so-modal-title {
    font-size: 1.25rem;
  }

  .so-action-dropdown {
    right: auto;
    left: 50%;
    transform: translateX(-50%);
  }
}

/* ==================== Modal ==================== */
.so-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(19, 136, 113, 0.2) 0%, rgba(0, 0, 0, 0.6) 100%);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s ease-out;
  padding: 1rem;
}

.so-modal-overlay.active {
  display: flex;
}

.so-modal {
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(0, 0, 0, 0.05);
  max-width: 800px;
  width: 90%;
  max-height: 90vh;
  overflow: hidden;
  animation: slideIn 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
}

.so-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.75rem 2rem;
  border-bottom: 2px solid var(--gray-200);
  background: linear-gradient(to bottom, white 0%, var(--gray-50) 100%);
  flex-shrink: 0;
}

.so-modal-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-900);
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.so-modal-close {
  background: white;
  border: 2px solid var(--gray-300);
  cursor: pointer;
  padding: 0.5rem;
  color: var(--gray-500);
  transition: all 0.2s ease;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.so-modal-close:hover {
  color: var(--gray-700);
  background-color: var(--gray-100);
  border-color: var(--gray-400);
  transform: rotate(90deg);
}

.so-modal-close svg {
  width: 1.25rem;
  height: 1.25rem;
}

.so-modal-body {
  padding: 2rem;
  overflow-y: auto;
  flex: 1;
}

.so-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.875rem;
  padding: 1.75rem 2rem;
  border-top: 2px solid var(--gray-200);
  background: linear-gradient(to top, var(--gray-50) 0%, white 100%);
  flex-shrink: 0;
}

.so-modal-btn {
  padding: 0.75rem 1.75rem;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 2px solid transparent;
  box-shadow: var(--shadow-sm);
  letter-spacing: 0.01em;
}

.so-modal-btn-primary {
  background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
  color: white;
  border-color: var(--primary-700);
  box-shadow: var(--shadow-md);
}

.so-modal-btn-primary:hover {
  background: linear-gradient(135deg, var(--primary-700) 0%, var(--primary-800) 100%);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.so-modal-btn-secondary {
  background-color: white;
  color: var(--gray-700);
  border-color: var(--gray-300);
}

.so-modal-btn-secondary:hover {
  background: linear-gradient(to bottom, white 0%, var(--gray-50) 100%);
  border-color: var(--gray-400);
  box-shadow: var(--shadow-md);
}

/* Button color override */
#so-table-root > div > div > div > button {
  color: #ffffff;
  background-color: #383838;
}

/* Division z-index */
#so-table-root > div {
  z-index: 800;
}

/* Modal primary button color */
.so-modal .so-modal-footer .so-modal-btn-primary {
  color: #ffffff;
}

/* 769px and larger screen sizes */
@media (min-width: 769px) {
  /* Modal header padding adjustment */
  #soEditModal .so-modal .so-modal-header {
    padding-bottom: 0px;
    padding-top: 0px;
  }

  /* Delivery Info Modal header padding */
  #soDeliveryInfoModal .so-modal-delivery-info .so-modal-header {
    padding-bottom: 0px;
    padding-top: 0px;
  }

  /* Delivery Upload Modal header padding */
  #soDeliveryUploadModal .so-modal .so-modal-header {
    padding-bottom: 0px;
    padding-top: 0px;
  }

  /* Col delivery padding */
  .so-table tbody .so-col-delivery {
    padding-right: 0px;
  }
}

/* Form Styles */
.so-form-group {
  margin-bottom: 1.25rem;
}

.so-form-label {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--gray-800);
  margin-bottom: 0.5rem;
  letter-spacing: 0.01em;
}

.so-form-input,
.so-form-select,
.so-form-textarea {
  width: 100%;
  padding: 0.75rem 0.875rem;
  border: 2px solid var(--gray-300);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: all 0.2s ease;
  background-color: white;
  box-shadow: var(--shadow-sm);
}

.so-form-input:hover,
.so-form-select:hover,
.so-form-textarea:hover {
  border-color: var(--gray-400);
}

.so-form-input:focus,
.so-form-select:focus,
.so-form-textarea:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 4px rgba(19, 136, 113, 0.15), var(--shadow-md);
  background-color: white;
}

.so-form-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.6;
  font-family: inherit;
}

.so-form-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

@media (max-width: 768px) {
  .so-form-row {
    grid-template-columns: 1fr;
  }
}

@keyframes slideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

/* Document Type Cell Styles */
.so-doctype-cell {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  min-width: 160px;
  max-width: 220px;
  width: 100%;
}

.so-doctype-list {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 135px; /* Height for ~3 items */
  overflow-y: auto;
  padding-right: 0.25rem;
  position: relative;
  -webkit-mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
  mask-image: linear-gradient(to bottom, black 70%, transparent 100%);
}

.so-doctype-list::-webkit-scrollbar {
  width: 4px;
}

.so-doctype-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 4px;
}

.so-doctype-list::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 4px;
}

.so-doctype-list::-webkit-scrollbar-thumb:hover {
  background: #94a3b8;
}

.so-doctype-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.375rem;
  background-color: #f9fafb;
  border-radius: 3px;
  font-size: 0.75rem;
  border: 1px solid #e5e7eb;
  transition: all 0.15s;
  position: relative;
}

.so-doctype-item:hover {
  background-color: #f3f4f6;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.so-doctype-item-info {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  min-width: 0;
}

.so-doctype-item-buttons {
  display: flex;
  gap: 0.125rem;
  align-items: center;
  flex-shrink: 0;
}

.so-doctype-item-actions {
  display: flex;
  gap: 0.125rem;
  transition: all 0.15s;
}

.so-doctype-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 3px;
  cursor: pointer;
  transition: all 0.15s;
  background-color: transparent;
  flex-shrink: 0;
}

.so-doctype-action-btn:hover {
  transform: scale(1.15);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.so-doctype-action-btn.edit {
  color: #2563eb;
}

.so-doctype-action-btn.edit:hover {
  background-color: #dbeafe;
}

.so-doctype-action-btn.delete {
  color: #dc2626;
}

.so-doctype-action-btn.delete:hover {
  background-color: #fee2e2;
}

.so-doctype-action-btn.print {
  color: #059669;
}

.so-doctype-action-btn.print:hover {
  background-color: #d1fae5;
}

.so-doctype-action-btn svg {
  width: 12px;
  height: 12px;
}

.so-doctype-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.125rem 0.25rem;
  border-radius: 3px;
  font-weight: 600;
  font-size: 0.625rem;
  text-align: center;
  min-width: 28px;
  height: 18px;
  line-height: 1;
  flex-shrink: 0;
}

.so-doctype-badge.badge-hs {
  background-color: #dbeafe;
  color: #1e40af;
}

.so-doctype-badge.badge-iv {
  background-color: #d1fae5;
  color: #065f46;
}

.so-doctype-badge.badge-hm {
  background-color: #fef3c7;
  color: #92400e;
}

.so-doctype-badge.badge-nn {
  background-color: #fce7f3;
  color: #9f1239;
}

.so-doctype-badge.badge-ss {
  background-color: #e0e7ff;
  color: #3730a3;
}

.so-doctype-badge.badge-se {
  background-color: #fed7aa;
  color: #9a3412;
}

.so-doctype-badge.badge-default {
  background-color: #e5e7eb;
  color: #374151;
}

.so-doctype-number {
  color: #6b7280;
  font-size: 0.6875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.so-doctype-amount {
  font-weight: 600;
  color: #111827;
  font-size: 0.6875rem;
  white-space: nowrap;
}

.so-doctype-total {
  padding: 0.25rem 0.375rem;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-radius: 4px;
  font-weight: 700;
  font-size: 0.6875rem;
  color: #1e40af;
  text-align: right;
  border: 1px solid #93c5fd;
  box-shadow: 0 1px 2px rgba(19, 136, 113, 0.05);
}

.so-doctype-add-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.25rem 0.5rem;
  background-color: #2563eb;
  color: white;
  border: none;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s;
  width: 100%;
}

.so-doctype-add-btn:hover {
  background-color: #1d4ed8;
}

.so-doctype-add-btn svg {
  width: 0.75rem;
  height: 0.75rem;
  flex-shrink: 0;
}

/* Document Type Modal Styles */
.so-doctype-modal {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100% !important;
  height: 100% !important;
  z-index: 99999 !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 !important;
  padding: 0 !important;
  background-color: rgba(0, 0, 0, 0.5) !important;
  backdrop-filter: blur(4px) !important;
  -webkit-backdrop-filter: blur(4px) !important;
}

.so-doctype-modal .so-modal-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  background: transparent !important;
  cursor: pointer !important;
  z-index: 1 !important;
}

.so-doctype-modal .so-modal-content {
  position: relative !important;
  z-index: 2 !important;
  background: white !important;
  border-radius: 12px !important;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3) !important;
  max-width: 500px !important;
  width: 90% !important;
  max-height: 90vh !important;
  display: flex !important;
  flex-direction: column !important;
  margin: 0 !important;
  overflow: hidden !important;
  transform: none !important;
  top: auto !important;
  left: auto !important;
  right: auto !important;
  bottom: auto !important;
}

.so-doctype-modal .so-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  background: #f9fafb;
}

.so-doctype-modal .so-modal-header h3 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: #111827;
}

.so-doctype-modal .so-modal-close {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
  color: #6b7280;
  transition: color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.so-doctype-modal .so-modal-close:hover {
  color: #111827;
}

.so-doctype-modal .so-modal-close svg {
  width: 1.5rem;
  height: 1.5rem;
}

.so-doctype-modal .so-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  max-height: calc(90vh - 140px);
}

.so-doctype-modal .so-modal-footer {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 1rem 1.5rem;
  border-top: 1px solid #e5e7eb;
  background: #f9fafb;
}

.so-doctype-modal .so-modal-btn {
  padding: 0.5rem 1.25rem;
  border-radius: 6px;
  font-weight: 500;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.so-doctype-modal .so-modal-btn-secondary {
  background: white;
  color: #374151;
  border: 1px solid #d1d5db;
}

.so-doctype-modal .so-modal-btn-secondary:hover {
  background: #f3f4f6;
}

.so-doctype-modal .so-modal-btn-primary {
  background: #2563eb;
  color: white;
  border: none;
}

.so-doctype-modal .so-modal-btn-primary:hover {
  background: #1d4ed8;
}

.so-doctype-options {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

.so-doctype-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  background: white;
}

.so-doctype-option:hover:not(:has(input:disabled)) {
  border-color: #2563eb;
  background-color: #f0f9ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(19, 136, 113, 0.15);
}

.so-doctype-option input[type="radio"] {
  width: 1.25rem;
  height: 1.25rem;
  cursor: pointer;
  accent-color: #2563eb;
  flex-shrink: 0;
}

.so-doctype-option input[type="radio"]:disabled {
  cursor: not-allowed;
  opacity: 0.3;
}

.so-doctype-option input[type="radio"]:checked + label {
  color: #2563eb;
  font-weight: 600;
}

.so-doctype-option label {
  flex: 1;
  cursor: pointer;
  font-size: 0.9375rem;
  font-weight: 500;
  color: #374151;
  transition: color 0.2s;
  user-select: none;
}

.so-doctype-option:has(input:disabled) {
  background-color: #fafafa;
  border-color: #e5e7eb;
  cursor: not-allowed;
  opacity: 0.5;
  position: relative;
}

.so-doctype-option:has(input:disabled)::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 10px,
    rgba(0, 0, 0, 0.03) 10px,
    rgba(0, 0, 0, 0.03) 20px
  );
  border-radius: 6px;
  pointer-events: none;
}

.so-doctype-option:has(input:disabled) label {
  cursor: not-allowed;
  color: #9ca3af;
}

.so-doctype-locked-notice {
  padding: 0.75rem 1rem;
  background-color: #fef3c7;
  border-left: 4px solid #f59e0b;
  border-radius: 6px;
  color: #92400e;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 1rem;
}

/* Responsive adjustments for doctype cell */

/* Tablet */
@media (max-width: 1024px) {
  .so-doctype-cell {
    min-width: 140px;
    max-width: 200px;
  }

  .so-doctype-list {
    max-height: 120px;
  }

  .so-doctype-item {
    gap: 0.2rem;
    padding: 0.2rem 0.3rem;
  }

  .so-doctype-number,
  .so-doctype-amount {
    font-size: 0.65rem;
  }

  .so-doctype-badge {
    font-size: 0.6rem;
    min-width: 26px;
    height: 16px;
    padding: 0.125rem 0.2rem;
  }

  .so-doctype-action-btn {
    width: 18px;
    height: 18px;
  }

  .so-doctype-action-btn svg {
    width: 11px;
    height: 11px;
  }

  .so-doctype-add-btn {
    font-size: 0.7rem;
    padding: 0.2rem 0.4rem;
    gap: 0.2rem;
  }

  .so-doctype-add-btn svg {
    width: 0.7rem;
    height: 0.7rem;
  }

  .so-doctype-total {
    font-size: 0.65rem;
    padding: 0.2rem 0.3rem;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .so-doctype-cell {
    min-width: 130px;
    max-width: 180px;
  }

  .so-doctype-list {
    max-height: 100px;
    gap: 0.2rem;
  }

  .so-doctype-item {
    grid-template-columns: 28px 1fr auto;
    gap: 0.15rem;
    padding: 0.2rem 0.25rem;
  }

  .so-doctype-item-info {
    gap: 0.1rem;
  }

  .so-doctype-number,
  .so-doctype-amount {
    font-size: 0.625rem;
  }

  .so-doctype-badge {
    font-size: 0.55rem;
    min-width: 24px;
    height: 15px;
    padding: 0.1rem 0.15rem;
  }

  .so-doctype-action-btn {
    width: 16px;
    height: 16px;
  }

  .so-doctype-action-btn svg {
    width: 10px;
    height: 10px;
  }

  .so-doctype-item-buttons {
    gap: 0.1rem;
  }

  .so-doctype-item-actions {
    gap: 0.1rem;
  }

  .so-doctype-add-btn {
    font-size: 0.65rem;
    padding: 0.2rem 0.35rem;
    gap: 0.15rem;
  }

  .so-doctype-add-btn svg {
    width: 0.65rem;
    height: 0.65rem;
  }

  .so-doctype-total {
    font-size: 0.625rem;
    padding: 0.2rem 0.25rem;
  }
}

/* ========================================
   Delivery Document Upload Styles
   ======================================== */

/* Upload button in delivery cell */
.so-btn-upload-delivery {
  padding: 6px 12px;
  font-size: 0.75rem;
  background: #0073aa;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  white-space: nowrap;
}

.so-btn-upload-delivery:hover {
  background: #005177;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 115, 170, 0.2);
}

.so-btn-upload-delivery:active {
  transform: translateY(0);
}

/* Delivery date button */
.so-btn-delivery-date {
  padding: 6px 12px;
  font-size: 0.75rem;
  background: #28a745;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  white-space: nowrap;
}

.so-btn-delivery-date:hover {
  background: #218838;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(40, 167, 69, 0.2);
}

.so-btn-delivery-date:active {
  transform: translateY(0);
}

/* Close sales status button (permanent) */
.so-btn-close-status {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  font-size: 0.7rem;
  background: #dc3545;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  white-space: nowrap;
}

.so-btn-close-status:hover {
  background: #b02a37;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(220, 53, 69, 0.2);
}

.so-btn-close-status:active {
  transform: translateY(0);
}

/* Closed-by / closed-at info shown under the status badge */
.so-closed-info {
  display: block;
  margin-top: 6px;
  font-size: 0.7rem;
  color: #6b7280;
  line-height: 1.3;
  white-space: nowrap;
}

/* Reopen sales status button (administrators only) */
.so-btn-reopen-status {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 10px;
  font-size: 0.7rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 600;
  white-space: nowrap;
}

.so-btn-reopen-status:hover {
  background: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(37, 99, 235, 0.2);
}

.so-btn-reopen-status:active {
  transform: translateY(0);
}

/* ========================================
   Closed row lock — hide every in-row edit affordance.
   The backend enforces this too; this is the UX layer.
   (Administrators reopen via the status cell, which is NOT hidden.)
   ======================================== */
tr.row-closed .so-amount-edit-btn,
tr.row-closed .so-doctype-add-btn,
tr.row-closed .so-doctype-item-actions,
tr.row-closed .so-dlv-actions,
tr.row-closed .so-ship-edit,
tr.row-closed .so-action-item.edit,
tr.row-closed .so-action-item.delete {
  display: none !important;
}

/* ========================================
   Delivery Cell Redesign
   ======================================== */

.so-delivery-cell {
  min-width: 250px;
  max-width: 250px;
}

.so-delivery-status {
  display: inline-block;
  padding: 5px 14px;
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  border: 1px solid #90caf9;
  border-radius: 6px;
  color: #1565c0;
  font-weight: 600;
  font-size: 0.8rem;
}

.so-delivery-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* Delivery cell secondary section spacing */
.so-delivery-cell .so-stacked-secondary {
  margin-top: 12px;
}

/* Delivery info container - Flexible grid layout */
.so-delivery-info-container {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 0;
  padding-top: 0;
}

/* Compact inline mode for delivery info items */
.so-delivery-info-item.so-delivery-compact {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 6px;
  padding: 8px 10px;
  background: #f8f9fa;
  border-left: 3px solid #0073aa;
  border-radius: 5px;
  transition: all 0.2s ease;
  font-size: 0.75rem;
  min-height: 36px;
}

.so-delivery-info-item.so-delivery-compact:hover {
  background: #e8f4f8;
  border-left-color: #005177;
  box-shadow: 0 2px 6px rgba(0, 115, 170, 0.08);
}

/* Compact mode icon */
.so-delivery-info-item.so-delivery-compact .so-delivery-icon {
  font-size: 1rem;
  line-height: 1.5;
  flex-shrink: 0;
  margin-top: 1px;
}

/* Compact mode label - inline with value */
.so-delivery-info-item.so-delivery-compact .so-delivery-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: #555;
  white-space: nowrap;
  margin-right: 5px;
  flex-shrink: 0;
  line-height: 1.5;
}

/* Compact mode value - allow wrapping */
.so-delivery-info-item.so-delivery-compact .so-delivery-value {
  font-size: 0.78rem;
  color: #222;
  font-weight: 500;
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  flex: 1;
  line-height: 1.5;
}

/* Full width items - กำหนดส่ง และ วิธีรับ */
.so-delivery-fdate,
.so-delivery-method {
  grid-column: 1 / -1;
}

/* Delivery info item */
.elementor .elementor-element .elementor-widget-shortcode .elementor-shortcode #so-table-root div .so-table-scroll .so-table tbody tr .so-col-delivery .so-delivery-cell .so-stacked-secondary .so-delivery-info-container .so-delivery-info-item {
  width: 247px !important;
}

/* Delivery info item */
.so-table tr .so-delivery-info-item {
  max-width: 239px !important;
}

/* Document count in compact mode */
.so-delivery-info-item.so-delivery-compact .so-delivery-docs-count {
  color: #0073aa;
  font-weight: 600;
  cursor: help;
  position: relative;
}

/* Documents tooltip container */
.so-delivery-docs-item {
  position: relative;
}

.so-docs-tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 12px;
  min-width: 280px;
  max-width: 400px;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
  pointer-events: none;
}

.so-delivery-docs-item:hover .so-docs-tooltip {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateX(-50%) translateY(-4px);
}

/* Tooltip arrow */
.so-docs-tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: white;
}

.so-docs-tooltip::before {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 7px solid transparent;
  border-top-color: #e0e0e0;
  margin-top: 1px;
  z-index: -1;
}

/* Tooltip item */
.so-doc-tooltip-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px;
  margin-bottom: 6px;
  background: #f8f9fa;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.so-doc-tooltip-item:last-child {
  margin-bottom: 0;
}

.so-doc-tooltip-item:hover {
  background: #e8f4f8;
  box-shadow: 0 2px 4px rgba(0, 115, 170, 0.1);
}

/* Tooltip link */
.so-doc-tooltip-link {
  color: #0073aa;
  text-decoration: none;
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: color 0.2s ease;
}

.so-doc-tooltip-link:hover {
  color: #005177;
  text-decoration: underline;
}

/* Tooltip date */
.so-doc-tooltip-date {
  font-size: 0.7rem;
  color: #666;
  white-space: nowrap;
  margin-left: 8px;
  padding: 2px 6px;
  background: white;
  border-radius: 4px;
}

/* Fallback for non-compact mode (if needed) */
.so-delivery-info-item:not(.so-delivery-compact) {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px;
  background: #f8f9fa;
  border-left: 3px solid #0073aa;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.so-delivery-info-item:not(.so-delivery-compact):hover {
  background: #e8f4f8;
  border-left-color: #005177;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.so-delivery-icon {
  font-size: 1.1rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.so-delivery-info-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.so-delivery-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.so-delivery-value {
  font-size: 0.85rem;
  color: #333;
  font-weight: 500;
  word-wrap: break-word;
  overflow-wrap: break-word;
  line-height: 1.4;
}

/* Delivery documents section */
.so-delivery-docs-section {
  margin-top: 12px;
  border-top: 2px solid #e0e0e0;
  padding-top: 10px;
}

.so-delivery-docs-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  padding: 6px 8px;
  background: linear-gradient(135deg, #fff3e0 0%, #ffe0b2 100%);
  border-radius: 6px;
  border: 1px solid #ffb74d;
}

.so-delivery-docs-header .so-delivery-icon {
  font-size: 1rem;
}

.so-delivery-docs-header .so-delivery-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: #e65100;
  text-transform: uppercase;
}

.so-delivery-docs {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #e0e0e0;
}

.so-delivery-docs strong {
  display: block;
  margin-bottom: 4px;
  color: #333;
  font-size: 0.8rem;
}

/* Document item in cell */
.so-doc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 8px;
  margin-bottom: 4px;
  background: #f5f5f5;
  border-radius: 4px;
  transition: background 0.2s;
}

.so-doc-item:hover {
  background: #e8f4f8;
}

.so-doc-link {
  color: #0073aa;
  text-decoration: none;
  font-size: 0.75rem;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.so-doc-link:hover {
  text-decoration: underline;
  color: #005177;
}

.so-doc-date {
  color: #666;
  font-size: 0.7rem;
  margin-left: 8px;
  white-space: nowrap;
}

/* ========================================
   Delivery Documents Table (Compact)
   ======================================== */

/* Table wrapper with fade effect */
.so-delivery-docs-table-wrapper {
  position: relative;
  max-width: 180px;
  margin-top: 7px;
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 5px;
  overflow: hidden;
}

/* Scrollable container for table */
.so-delivery-docs-table-wrapper::before {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 18px;
  background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.95));
  pointer-events: none;
  z-index: 1;
}

/* Table styles */
.so-delivery-docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.675rem;
  max-height: 126px; /* 3.5 rows x 36px = 126px */
  display: block;
  overflow-y: auto;
  overflow-x: hidden;
}

.so-delivery-docs-table::-webkit-scrollbar {
  width: 3.6px;
}

.so-delivery-docs-table::-webkit-scrollbar-track {
  background: #f1f1f1;
}

.so-delivery-docs-table::-webkit-scrollbar-thumb {
  background: #888;
  border-radius: 1.8px;
}

.so-delivery-docs-table::-webkit-scrollbar-thumb:hover {
  background: #555;
}

/* Table body */
.so-delivery-docs-table tbody {
  display: table;
  width: 100%;
}

/* Table rows */
.so-doc-table-row {
  height: 36px;
  border-bottom: 1px solid #f0f0f0;
  transition: background-color 0.2s;
}

.so-doc-table-row:last-child {
  border-bottom: none;
}

.so-doc-table-row:hover {
  background-color: #f8f9fa;
}

/* Table cells */
.so-doc-table-name,
.so-doc-table-size {
  padding: 7px 9px;
  vertical-align: middle;
}

.so-doc-table-name {
  width: 126px;
  max-width: 126px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.so-doc-table-size {
  width: 45px;
  text-align: right;
  color: #666;
  font-size: 0.63rem;
  white-space: nowrap;
}

/* File link in table */
.so-doc-table-link {
  color: #0073aa;
  text-decoration: none;
  font-weight: 500;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.so-doc-table-link:hover {
  color: #005177;
  text-decoration: underline;
}

/* Icon for download */
.so-doc-table-link::before {
  content: '📄 ';
  margin-right: 3.6px;
}

/* Fade effect on 4th+ rows */
.so-doc-table-row:nth-child(4) {
  opacity: 0.5;
}

.so-doc-table-row:nth-child(n+5) {
  opacity: 1;
}

/* Responsive */
@media (max-width: 768px) {
  .so-delivery-docs-table-wrapper {
    max-width: 100%;
  }

  .so-doc-table-name {
    width: auto;
    max-width: none;
  }

  /* Compact delivery info - single column on mobile */
  .so-delivery-info-container {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  /* All items full width on mobile */
  .so-delivery-fdate,
  .so-delivery-method,
  .so-delivery-address,
  .so-delivery-docs-item {
    grid-column: 1 / -1;
  }

  .so-delivery-info-item.so-delivery-compact {
    padding: 5px 6px;
    gap: 3px;
  }

  .so-delivery-info-item.so-delivery-compact .so-delivery-icon {
    font-size: 0.9rem;
  }

  .so-delivery-info-item.so-delivery-compact .so-delivery-label {
    font-size: 0.65rem;
  }

  .so-delivery-info-item.so-delivery-compact .so-delivery-value {
    font-size: 0.7rem;
  }

  /* Product cell on mobile */
  .so-product-cell {
    max-width: 140px;
    min-width: 90px;
  }

  .so-product-cell .so-stacked-secondary {
    max-width: 130px;
  }

  /* Delivery cell on mobile */
  .so-delivery-cell {
    min-width: 280px;
    max-width: 100%;
  }

  /* Tooltip on mobile */
  .so-docs-tooltip {
    min-width: 240px;
    max-width: 90vw;
    left: auto;
    right: 0;
    transform: translateX(0) translateY(-8px);
  }

  .so-delivery-docs-item:hover .so-docs-tooltip {
    transform: translateX(0) translateY(-4px);
  }

  .so-docs-tooltip::after,
  .so-docs-tooltip::before {
    left: auto;
    right: 20px;
    transform: translateX(0);
  }
}

/* Upload modal styles */
.so-upload-section {
  margin-bottom: 24px;
  padding: 20px;
  background: linear-gradient(to bottom, #f9f9f9, #ffffff);
  border-radius: 8px;
  border: 1px solid #e0e0e0;
}

.so-file-label {
  display: block;
  padding: 24px;
  text-align: center;
  border: 2px dashed #ccc;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.3s ease;
  background: white;
}

.so-file-label:hover {
  border-color: #0073aa;
  background: #f0f7ff;
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 115, 170, 0.1);
}

.so-file-label span {
  font-size: 0.95rem;
  color: #666;
  font-weight: 500;
}

.so-file-preview {
  margin: 16px 0;
  padding: 12px;
  background: white;
  border-radius: 6px;
  border: 1px solid #e0e0e0;
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.so-file-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 8px;
}

.so-file-info strong {
  color: #333;
  font-size: 0.9rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 70%;
}

.so-file-info span {
  color: #0073aa;
  font-size: 0.85rem;
  font-weight: 600;
  background: #e8f4f8;
  padding: 4px 8px;
  border-radius: 4px;
}

/* Primary button */
.so-btn-primary {
  width: 100%;
  padding: 14px;
  background: linear-gradient(to bottom, #0073aa, #005177);
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 4px rgba(0, 115, 170, 0.2);
}

.so-btn-primary:hover:not(:disabled) {
  background: linear-gradient(to bottom, #005177, #003d5c);
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 115, 170, 0.3);
}

.so-btn-primary:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(0, 115, 170, 0.2);
}

.so-btn-primary:disabled {
  background: #ccc;
  cursor: not-allowed;
  box-shadow: none;
}

/* Upload progress */
.so-upload-progress {
  margin-top: 16px;
  text-align: center;
}

.so-progress-bar {
  width: 100%;
  height: 8px;
  background: #e0e0e0;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.so-progress-fill {
  height: 100%;
  background: linear-gradient(to right, #0073aa, #00a0d2);
  transition: width 0.3s ease;
  animation: progressShine 1.5s infinite;
}

@keyframes progressShine {
  0% {
    background-position: -100% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.so-progress-text {
  font-size: 0.875rem;
  color: #666;
  margin: 0;
}

/* Documents list in modal */
.so-docs-list {
  margin-top: 24px;
  padding-top: 24px;
  border-top: 2px solid #e0e0e0;
}

.so-docs-list h4 {
  margin: 0 0 16px 0;
  font-size: 1rem;
  color: #333;
  font-weight: 600;
}

.so-docs-list .so-doc-item {
  padding: 12px 16px;
  margin-bottom: 8px;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
}

.so-docs-list .so-doc-item:hover {
  background: #f0f7ff;
  border-color: #0073aa;
}

.so-docs-list .so-doc-link {
  font-size: 0.9rem;
}

.so-docs-list .so-doc-date {
  font-size: 0.8rem;
}

.so-no-docs {
  text-align: center;
  color: #999;
  font-style: italic;
  padding: 20px;
  margin: 0;
}

.so-error-text {
  text-align: center;
  color: #d63301;
  padding: 20px;
  margin: 0;
}

/* Migration Notice Styles */
.so-migration-notice {
  background: linear-gradient(135deg, #fff9e6 0%, #fff4d6 100%);
  border: 2px solid #f0ad4e;
  border-left: 5px solid #f0ad4e;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 20px;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  box-shadow: 0 2px 4px rgba(240, 173, 78, 0.15);
}

.so-migration-icon {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.so-migration-content {
  flex: 1;
  min-width: 0;
}

.so-migration-title {
  margin: 0 0 8px 0;
  color: #8b5a00;
  font-size: 15px;
}

.so-migration-desc {
  margin: 0 0 10px 0;
  color: #6b4800;
  font-size: 14px;
  line-height: 1.5;
}

.so-migration-url {
  font-size: 12px;
  font-family: 'Courier New', monospace;
  color: #6b4800;
  background: rgba(255, 255, 255, 0.7);
  padding: 8px 12px;
  border-radius: 4px;
  margin-top: 8px;
  word-break: break-all;
  border: 1px solid rgba(240, 173, 78, 0.3);
  max-height: 60px;
  overflow-y: auto;
}

.so-migration-btn {
  background: #138871;
  color: white;
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  flex-shrink: 0;
  transition: all 0.2s ease;
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  box-shadow: 0 2px 4px rgba(19, 136, 113, 0.2);
}

.so-migration-btn:hover {
  background: #0d725e;
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(19, 136, 113, 0.3);
}

.so-migration-btn:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* Document Edit Mode Styles */
.so-doc-display {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.so-doc-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.so-doc-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.so-doc-edit-btn,
.so-doc-delete-btn {
  padding: 6px 8px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.so-doc-edit-btn {
  color: #138871;
}

.so-doc-edit-btn:hover {
  background: #138871;
  color: white;
  border-color: #138871;
}

.so-doc-delete-btn {
  color: #dc3545;
}

.so-doc-delete-btn:hover {
  background: #dc3545;
  color: white;
  border-color: #dc3545;
}

/* Edit Form Styles */
.so-doc-edit-form {
  padding: 12px 0;
}

.so-doc-edit-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
}

.so-doc-edit-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.so-doc-edit-group label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #333;
}

.so-doc-edit-name,
.so-doc-edit-date,
.so-doc-edit-link {
  padding: 8px 12px;
  border: 2px solid #e0e0e0;
  border-radius: 4px;
  font-size: 0.875rem;
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
  transition: border-color 0.2s ease;
}

.so-doc-edit-name:focus,
.so-doc-edit-date:focus,
.so-doc-edit-link:focus {
  outline: none;
  border-color: #138871;
  box-shadow: 0 0 0 3px rgba(19, 136, 113, 0.1);
}

.so-doc-edit-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.so-doc-update-btn,
.so-doc-cancel-btn {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, sans-serif;
}

.so-doc-update-btn {
  background: #138871;
  color: white;
}

.so-doc-update-btn:hover {
  background: #0d725e;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(19, 136, 113, 0.3);
}

.so-doc-cancel-btn {
  background: #6c757d;
  color: white;
}

.so-doc-cancel-btn:hover {
  background: #5a6268;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(108, 117, 125, 0.3);
}

/* Responsive styles for upload */
@media (max-width: 768px) {
  .so-btn-upload-delivery {
    display: block;
    margin: 4px 0 0 0;
    width: 100%;
    padding: 6px 10px;
    font-size: 0.7rem;
  }

  .so-delivery-docs {
    margin-top: 8px;
  }

  .so-doc-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .so-doc-date {
    margin-left: 0;
  }

  .so-upload-section {
    padding: 16px;
  }

  .so-file-label {
    padding: 16px;
  }

  .so-file-label span {
    font-size: 0.85rem;
  }

  .so-file-info {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .so-file-info strong {
    max-width: 100%;
  }
}

/* ========================================
   Delivery Info Modal Styles
   ======================================== */

.so-modal-delivery-info {
  max-width: 600px;
  width: 90%;
}

.so-form-group {
  margin-bottom: 20px;
}

.so-form-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
  color: #333;
  font-size: 0.9rem;
}

.so-form-input,
.so-form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
  transition: all 0.2s ease;
  box-sizing: border-box;
}

.so-form-input:focus,
.so-form-textarea:focus {
  outline: none;
  border-color: #0073aa;
  box-shadow: 0 0 0 3px rgba(0, 115, 170, 0.1);
}

.so-form-textarea {
  resize: vertical;
  min-height: 100px;
  line-height: 1.5;
}

/* Radio button group */
.so-radio-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Radio group - Grid layout for delivery info form */
#soDeliveryInfoForm .so-form-group .so-radio-group {
  display: grid;
}

/* Radio group - Custom grid template */
#soDeliveryInfoModal .so-modal-delivery-info .so-modal-body #soDeliveryInfoForm .so-form-group .so-radio-group {
  grid-template-columns: auto 1fr !important;
}

.so-radio-label {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: #fff;
}

.so-radio-label:hover {
  border-color: #0073aa;
  background: #f8f9fa;
}

.so-radio-input {
  width: 18px;
  height: 18px;
  margin-right: 10px;
  cursor: pointer;
  accent-color: #0073aa;
}

.so-radio-input:checked + .so-radio-text {
  font-weight: 600;
  color: #0073aa;
}

.so-radio-label:has(.so-radio-input:checked) {
  border-color: #0073aa;
  background: #e8f4f8;
}

.so-radio-text {
  flex: 1;
  color: #333;
  font-size: 0.9rem;
  user-select: none;
}

/* Form actions */
.so-form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid #e0e0e0;
}

.so-btn {
  padding: 10px 20px;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: 100px;
}

.so-btn-secondary {
  background: #f0f0f0;
  color: #333;
}

.so-btn-secondary:hover {
  background: #e0e0e0;
}

/* Delivery Info Modal - Custom Styles */
#soDeliveryInfoModal .so-modal-delivery-info .so-modal-header {
  transform: translateX(0px) translateY(0px);
}

/* Save delivery info button */
#soSaveDeliveryInfo {
  color: #ffffff;
  text-align: center;
  justify-content: center;
}

/* Secondary button in delivery form */
#soDeliveryInfoForm .so-form-actions .so-btn-secondary {
  justify-content: center;
}

/* Responsive */
@media (max-width: 768px) {
  .so-modal-delivery-info {
    width: 95%;
    max-width: none;
  }

  .so-form-actions {
    flex-direction: column-reverse;
  }

  .so-btn {
    width: 100%;
  }

  .so-btn-delivery-date,
  .so-btn-upload-delivery {
    display: block;
    margin: 4px 0 0 0;
    width: 100%;
    padding: 6px 10px;
    font-size: 0.7rem;
  }

  .so-delivery-cell {
    min-width: auto;
  }

  .so-delivery-actions {
    flex-direction: column;
    width: 100%;
  }

  .so-delivery-actions button {
    width: 100%;
  }

  .so-delivery-info-item {
    padding: 6px;
  }

  .so-delivery-icon {
    font-size: 1rem;
  }

  .so-delivery-label {
    font-size: 0.65rem;
  }

  .so-delivery-value {
    font-size: 0.8rem;
  }
}

/* ========================================
   Notification Styles
   ======================================== */

.so-notification {
  position: fixed;
  top: 20px;
  right: 20px;
  min-width: 300px;
  max-width: 500px;
  padding: 16px 20px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 10000;
  opacity: 0;
  transform: translateX(400px);
  transition: all 0.3s ease;
  font-size: 0.9rem;
}

.so-notification.show {
  opacity: 1;
  transform: translateX(0);
}

.so-notification-content {
  display: flex;
  align-items: center;
  gap: 10px;
}

.so-notification-success {
  border-left: 4px solid #28a745;
  color: #155724;
  background: #d4edda;
}

.so-notification-error {
  border-left: 4px solid #dc3545;
  color: #721c24;
  background: #f8d7da;
}

.so-notification-info {
  border-left: 4px solid #0073aa;
  color: #004085;
  background: #d1ecf1;
}

/* ========================================
   Settings Modal Styles
   ======================================== */

/* Settings button */
.so-btn-icon-sm {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: white;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.so-btn-icon-sm:hover {
  background: #f5f5f5;
  border-color: #999;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.so-btn-icon-sm:active {
  transform: translateY(0);
}

/* Settings modal overlay */
.so-settings-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s ease;
}

.so-settings-modal-overlay.so-modal-visible {
  opacity: 1;
  visibility: visible;
}

/* Settings modal */
.so-settings-modal {
  background: white;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.so-modal-visible .so-settings-modal {
  transform: scale(1);
}

/* Modal header */
.so-settings-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid #e0e0e0;
  background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

.so-settings-modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #333;
  display: flex;
  align-items: center;
  gap: 8px;
}

.so-settings-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  line-height: 1;
  color: #666;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.so-settings-close:hover {
  background: rgba(0, 0, 0, 0.1);
  color: #333;
}

/* Modal body */
.so-settings-modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: calc(90vh - 160px);
}

.so-settings-section {
  margin-bottom: 24px;
}

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

.so-settings-section h4 {
  margin: 0 0 16px 0;
  font-size: 1rem;
  font-weight: 600;
  color: #333;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e0e0e0;
}

/* Checkboxes */
.so-settings-checkboxes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.so-settings-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  background: #f9f9f9;
}

.so-settings-checkbox:hover {
  background: #f0f7ff;
  border-color: #0073aa;
}

.so-settings-checkbox.disabled {
  opacity: 0.6;
  cursor: not-allowed;
  background: #f5f5f5;
}

.so-settings-checkbox.disabled:hover {
  background: #f5f5f5;
  border-color: #e0e0e0;
}

.so-settings-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  flex-shrink: 0;
}

.so-settings-checkbox.disabled input[type="checkbox"] {
  cursor: not-allowed;
}

.so-settings-checkbox span {
  font-size: 0.875rem;
  font-weight: 500;
  color: #333;
  flex: 1;
}

.so-settings-note {
  font-size: 0.75rem;
  color: #999;
  font-weight: 400;
  font-style: italic;
}

/* Modal footer */
.so-settings-modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-top: 1px solid #e0e0e0;
  background: #f8f9fa;
}

.so-settings-actions {
  display: flex;
  gap: 10px;
}

/* Button styles */
.so-btn-primary {
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  background: linear-gradient(135deg, #0073aa 0%, #005177 100%);
  color: white;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 115, 170, 0.2);
}

.so-btn-primary:hover {
  background: linear-gradient(135deg, #005177 0%, #003d5c 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 115, 170, 0.3);
}

.so-btn-primary:active {
  transform: translateY(0);
}

.so-btn-secondary {
  padding: 10px 20px;
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid #ccc;
  border-radius: 6px;
  background: white;
  color: #333;
  cursor: pointer;
  transition: all 0.2s ease;
}

.so-btn-secondary:hover {
  background: #f5f5f5;
  border-color: #999;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.so-btn-secondary:active {
  transform: translateY(0);
}

/* Filter visibility animation */
.so-filter-visible {
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 1025px and larger screen sizes */
@media (min-width: 1025px) {
  /* Customer column - larger font */
  .so-table .so-col-customer .so-stacked-secondary {
    font-size: 15px;
  }

  /* Product column - smaller primary */
  .so-table .so-col-product .so-stacked-primary {
    font-size: 13px;
  }
}

/* Responsive */
@media (max-width: 768px) {
  .so-settings-modal {
    width: 95%;
    max-height: 95vh;
  }

  .so-settings-modal-header {
    padding: 16px;
  }

  .so-settings-modal-body {
    padding: 16px;
  }

  .so-settings-checkboxes {
    grid-template-columns: 1fr;
  }

  .so-settings-modal-footer {
    flex-direction: column;
    gap: 12px;
    padding: 16px;
  }

  .so-settings-actions {
    width: 100%;
    flex-direction: column;
  }

  .so-btn-primary,
  .so-btn-secondary {
    width: 100%;
  }
}

/* ========================================
   Image Lightbox
   ======================================== */
.so-lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: soLightboxIn 200ms ease-out;
  cursor: pointer;
}

@keyframes soLightboxIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.so-lightbox-container {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  cursor: default;
}

.so-lightbox-close {
  position: absolute;
  top: -40px;
  right: -10px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: white;
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 200ms ease;
  z-index: 1;
}

.so-lightbox-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

.so-lightbox-content {
  display: flex;
  align-items: center;
  justify-content: center;
}

.so-lightbox-image {
  max-width: 90vw;
  max-height: 85vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.so-lightbox-title {
  text-align: center;
  color: rgba(255, 255, 255, 0.8);
  font-size: 13px;
  margin-top: 12px;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   Document Chips (SO/PO column)
   ======================================== */
.so-doc-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.so-doc-chip-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  background: #f0f7ff;
  border: 1px solid #c2d9f0;
  border-radius: 4px;
  color: #1a5a96;
  font-size: 0.72rem;
  font-weight: 500;
  text-decoration: none;
  max-width: 160px;
  transition: all 150ms ease;
  cursor: pointer;
  line-height: 1.3;
}

.so-doc-chip-link:hover {
  background: #dbeafe;
  border-color: #93b8e0;
  color: #0d4a80;
  box-shadow: 0 1px 3px rgba(26, 90, 150, 0.15);
}

.so-doc-chip-link i {
  font-size: 11px;
  flex-shrink: 0;
}

.so-doc-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* File type icon colors */
.so-doc-chip-link .fa-file-image,
.so-doc-tooltip-link .fa-file-image,
.so-doc-link .fa-file-image {
  color: #2e7d32;
}

.so-doc-chip-link .fa-file-pdf,
.so-doc-tooltip-link .fa-file-pdf,
.so-doc-link .fa-file-pdf {
  color: #c62828;
}

.so-doc-chip-link .fa-file-word,
.so-doc-tooltip-link .fa-file-word,
.so-doc-link .fa-file-word {
  color: #1565c0;
}

.so-doc-chip-link .fa-file-excel,
.so-doc-tooltip-link .fa-file-excel,
.so-doc-link .fa-file-excel {
  color: #2e7d32;
}

.so-doc-chip-link .fa-file,
.so-doc-tooltip-link .fa-file,
.so-doc-link .fa-file {
  color: #546e7a;
}
