:root {
  --pea-purple: #742A8C;
  --pea-dark-purple: #561D69;
  --pea-light-purple: #F3EAF7;
  --pea-gold: #F5A623;
  --bg-color: #F7F8FA;
  --card-bg: #FFFFFF;
  --text-main: #2D3748;
  --text-muted: #718096;
  --border-color: #E2E8F0;
  --primary: #742A8C;
  --primary-hover: #5D2070;
  --danger: #E53E3E;
  --success: #38A169;
  --docx-blue: #185ABD;
  --pdf-red: #C5221F;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Sarabun', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-main);
  line-height: 1.5;
  font-size: 15px;
}

/* Navbar */
.navbar {
  background: linear-gradient(135deg, var(--pea-purple), var(--pea-dark-purple));
  color: white;
  padding: 12px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 16px;
}

.pea-logo {
  background-color: white;
  color: var(--pea-purple);
  font-weight: 900;
  font-size: 20px;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  letter-spacing: 1px;
  box-shadow: var(--shadow-sm);
}

.brand-text h1 {
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.2px;
}

.brand-text p {
  font-size: 12px;
  opacity: 0.85;
}

.nav-actions {
  display: flex;
  gap: 12px;
}

/* Container */
.container {
  max-width: 1280px;
  margin: 24px auto;
  padding: 0 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Cards */
.card {
  background-color: var(--card-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  overflow: hidden;
}

.card-header {
  padding: 16px 22px;
  background: linear-gradient(180deg, #FAF8FD 0%, #F5F0F8 100%);
  border-bottom: 2px solid #EDE4F3;
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-header h2 {
  font-size: 19px;
  font-weight: 700;
  color: var(--pea-purple);
  letter-spacing: 0.2px;
}

.card-header i {
  font-size: 20px;
}

.card-header.space-between {
  justify-content: space-between;
}

.flex-align {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-body {
  padding: 22px;
}

.text-purple {
  color: var(--pea-purple);
}

/* Form Elements */
.form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

.span-2 {
  grid-column: span 2;
}

.span-4 {
  grid-column: span 4;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

input[type="text"], input[type="number"], input[type="date"], select {
  padding: 9px 12px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus, input[type="number"]:focus, input[type="date"]:focus, select:focus {
  border-color: var(--pea-purple);
  box-shadow: 0 0 0 3px rgba(116, 42, 140, 0.15);
}

/* Mandatory Highlight Field (Default Red Border) */
.input-required {
  border: 2px solid #E53E3E !important;
  background-color: #FFFBFB;
  color: #9B1C1C;
  font-weight: 500;
}

.input-required:focus {
  border-color: #E53E3E !important;
  box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.25) !important;
}

.label-required {
  color: #C53030 !important;
  font-weight: 700 !important;
}

.label-required::after {
  content: " * (จำเป็น)";
  color: #E53E3E;
  font-size: 11px;
  font-weight: 600;
  margin-left: 4px;
}

.input-error-glow {
  animation: shake 0.3s ease-in-out;
  border-color: #E53E3E !important;
  box-shadow: 0 0 0 4px rgba(229, 62, 62, 0.35) !important;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* Charges Config Card */
.charges-config-card {
  border-left: 4px solid var(--pea-purple);
}

.charge-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  gap: 16px;
}

.charge-info {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1.2;
}

.charge-num {
  background-color: var(--pea-light-purple);
  color: var(--pea-purple);
  font-weight: 700;
  font-size: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.charge-info h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-main);
}

.charge-info p {
  font-size: 12px;
}

.hour-selector-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.hour-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
}

.hour-btn-group {
  display: flex;
  gap: 6px;
}

.btn-hour {
  background-color: #EDF2F7;
  border: 1px solid var(--border-color);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-main);
  transition: all 0.2s;
}

.btn-hour:hover {
  background-color: var(--pea-light-purple);
  color: var(--pea-purple);
  border-color: var(--pea-purple);
}

.btn-hour.active {
  background-color: var(--pea-purple);
  color: white;
  border-color: var(--pea-purple);
  box-shadow: 0 2px 5px rgba(116, 42, 140, 0.3);
}

.charge-amount {
  min-width: 140px;
  text-align: right;
}

.amount-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--pea-purple);
}

.unit-val {
  font-size: 14px;
  color: var(--text-muted);
  margin-left: 4px;
}

.charge-divider {
  height: 1px;
  background-color: var(--border-color);
  margin: 14px 0;
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  border: 1px solid rgba(116, 42, 140, 0.2);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.data-table th {
  background-color: var(--pea-purple);
  padding: 12px 14px;
  font-size: 13px;
  font-weight: 600;
  color: #FFFFFF;
  border-bottom: 2px solid var(--pea-dark-purple);
}

.data-table td {
  padding: 10px 14px;
  font-size: 14px;
  border-bottom: 1px solid #F0E6F4;
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background-color: #FAF5FC;
}

.empty-state {
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 38px;
  margin-bottom: 10px;
  opacity: 0.5;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.btn-primary {
  background-color: var(--pea-purple);
  color: white;
}

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

.btn-secondary {
  background-color: var(--pea-light-purple);
  color: var(--pea-purple);
  border: 1px solid rgba(116, 42, 140, 0.2);
}

.btn-secondary:hover {
  background-color: #EBDAF2;
}

.btn-outline {
  background-color: transparent;
  border-color: rgba(255, 255, 255, 0.5);
  color: white;
}

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

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}

.btn-icon:hover {
  color: var(--danger);
  background-color: #FFF5F5;
}

.btn-group {
  display: flex;
  gap: 8px;
}

.badge {
  background-color: var(--pea-light-purple);
  color: var(--pea-purple);
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 20px;
  font-weight: 600;
}

.badge-lg {
  padding: 5px 12px;
  font-size: 13px;
}

/* 2 Column Layout */
.grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* Summary Card */
.summary-card {
  background: linear-gradient(180deg, #FFFFFF 0%, #FAF8FC 100%);
}

.summary-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  font-size: 15px;
}

.sum-value {
  font-weight: 600;
  color: var(--text-main);
}

.summary-divider {
  height: 1px;
  background-color: var(--border-color);
  margin: 10px 0;
}

.total-line {
  font-size: 18px;
  font-weight: 700;
}

.sum-grand {
  color: var(--pea-purple);
  font-size: 22px;
  font-weight: 700;
}

.baht-text-box {
  margin-top: 14px;
  padding: 12px 14px;
  background-color: var(--pea-light-purple);
  border: 1px dashed rgba(116, 42, 140, 0.35);
  border-radius: var(--radius-sm);
  color: var(--pea-purple);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.export-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
}

.btn-docx {
  background-color: var(--docx-blue);
  color: white;
  justify-content: center;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
}

.btn-docx:hover {
  background-color: #12458f;
  box-shadow: 0 4px 10px rgba(24, 90, 189, 0.3);
}

.btn-pdf {
  background-color: var(--pdf-red);
  color: white;
  justify-content: center;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
}

.btn-pdf:hover {
  background-color: #a01a18;
  box-shadow: 0 4px 10px rgba(197, 34, 31, 0.3);
}

/* Modals */
.modal-backdrop {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-backdrop.active {
  display: flex;
}

.modal {
  background-color: white;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 900px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease-out;
}

.modal-lg {
  max-width: 1050px;
}

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

.modal-header {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 17px;
  font-weight: 600;
  color: var(--pea-purple);
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-close {
  background: transparent;
  border: none;
  font-size: 24px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
}

.btn-close:hover {
  color: var(--danger);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.search-box {
  position: relative;
  margin-bottom: 12px;
}

.search-box i {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-box input {
  width: 100%;
  padding: 12px 14px 12px 42px;
  font-size: 15px;
  border-radius: var(--radius-md);
}

.search-stats {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-align: right;
}

.modal-table-wrap {
  max-height: 480px;
  overflow-y: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

/* Custom Checkbox */
.checkbox-container {
  display: inline-flex;
  align-items: center;
  position: relative;
  cursor: pointer;
  font-size: 14px;
  user-select: none;
  gap: 8px;
}

.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}

.checkmark {
  height: 18px;
  width: 18px;
  background-color: #EEE;
  border-radius: 4px;
  display: inline-block;
  position: relative;
  transition: background-color 0.2s;
}

.checkbox-container:hover input ~ .checkmark {
  background-color: #DDD;
}

.checkbox-container input:checked ~ .checkmark {
  background-color: var(--pea-purple);
}

.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}

.checkbox-container input:checked ~ .checkmark:after {
  display: block;
  left: 6px;
  top: 2px;
  width: 4px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Price selection tags */
.price-pill {
  cursor: pointer;
  padding: 3px 6px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  display: inline-block;
  background-color: #EDF2F7;
  color: var(--text-muted);
  transition: all 0.15s;
}

/* Inline Search Dropdown */
.inline-search-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: white;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  max-height: 380px;
  overflow-y: auto;
  z-index: 500;
}

.inline-drop-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.15s;
}

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

.inline-drop-row:hover {
  background-color: var(--pea-light-purple);
}

.inline-code {
  display: inline-block;
  color: var(--pea-purple);
  margin-right: 8px;
}

.inline-desc {
  font-size: 14px;
  color: var(--text-main);
  margin-right: 8px;
}

.inline-unit {
  font-size: 12px;
  color: var(--text-muted);
}

.inline-price {
  font-size: 13px;
  color: var(--text-main);
}

/* Price Edition Selector (รูปที่ 2) */
.price-edition-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.price-edition-label {
  font-size: 13.5px;
  font-weight: 600;
  color: #1E3A8A;
}

.select-price-edition {
  appearance: none;
  -webkit-appearance: none;
  background-color: #EFF6FF;
  border: 1.5px solid #BFDBFE;
  color: #1D4ED8;
  font-size: 13.5px;
  font-weight: 600;
  padding: 6px 34px 6px 14px;
  border-radius: 9999px; /* Pill shape like image */
  cursor: pointer;
  outline: none;
  transition: all 0.2s ease;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%232563EB'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2.5' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 14px;
}

.select-price-edition:hover {
  background-color: #DBEAFE;
  border-color: #93C5FD;
}

.select-price-edition:focus {
  border-color: #3B82F6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

