body {
  font-family: 'Bai Jamjuree', sans-serif;
  background: #f3f3f3;
  margin: 0;
}

.container {
  width: 95%;
  max-width: 1200px;
  margin: auto;
  padding: 20px;
  background: #fff;
  margin-top: 20px;
  border-radius: 10px;
}

h1 {
  margin-bottom: 10px;
}

.nav-links {
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #28a745;
}

.nav-links a {
  display: inline-block;
  padding: 8px 16px;
  margin-right: 8px;
  text-decoration: none;
  color: #333;
  border-radius: 5px;
  font-size: 14px;
  font-weight: 500;
}

.nav-links a:hover {
  background: #e9ecef;
}

.nav-links a.nav-active {
  background: #28a745;
  color: #fff;
}

.row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 15px;
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 1px solid #eee;
}

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

.row label {
  display: block;
  font-weight: bold;
  margin-bottom: 6px;
  font-size: 14px;
}

.field-wrap {
  position: relative;
}

.warning {
  font-size: 12px;
  color: #d9534f;
  margin-top: 4px;
  display: none;
}

.warning.show {
  display: block;
}

.unit-convert {
  font-size: 12px;
  color: #17a2b8;
  margin-top: 3px;
  font-weight: 500;
}

input.input-warning {
  border-color: #d9534f;
  color: #d9534f;
}

.full {
  margin-bottom: 20px;
}

.full label {
  display: block;
  font-weight: bold;
  margin-bottom: 6px;
  font-size: 14px;
}

input, select, textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-sizing: border-box;
}

textarea {
  height: 80px;
}

button {
  background: #28a745;
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 5px;
  cursor: pointer;
}

button:hover {
  background: #218838;
}

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.btn-edit {
  background: #f0ad4e;
  color: #fff;
  border: none;
  padding: 12px 20px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
}

.btn-edit:hover {
  background: #ec971f;
}

/* Form readonly mode */
form.readonly-mode input:not([type="date"]),
form.readonly-mode select,
form.readonly-mode textarea {
  background: #f8f9fa;
  pointer-events: none;
}

hr {
  margin: 30px 0;
  border: none;
  border-top: 1px solid #ddd;
}

table {
  width: 100%;
  border-collapse: collapse;
}

table th, table td {
  border: 1px solid #ddd;
  padding: 10px;
}

table th {
  background: #28a745;
  color: white;
}

/* Loading overlay */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(255,255,255,0.8);
  z-index: 2000;
  justify-content: center;
  align-items: center;
}

.loading-overlay.show {
  display: flex;
}

.loading-content {
  text-align: center;
}

.loading-content p {
  margin-top: 15px;
  font-size: 16px;
  color: #333;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #ddd;
  border-top: 4px solid #28a745;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

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

/* History cards */
.history-card {
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 15px;
  margin-bottom: 15px;
  background: #fafafa;
}

.history-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.history-card .card-header h3 {
  margin: 0;
  font-size: 16px;
}

.history-card .card-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.history-card .card-item {
  font-size: 13px;
}

.history-card .card-item .item-label {
  color: #666;
  font-size: 11px;
}

.history-card .card-item .item-value {
  font-weight: 500;
}

.history-card .card-item .item-value.deviated {
  color: #d9534f;
  font-weight: 600;
}

.history-card .card-item .item-reason {
  font-size: 11px;
  color: #d9534f;
  cursor: pointer;
  text-decoration: underline;
}

.btn-view-reason {
  background: #f0ad4e;
  color: #fff;
  border: none;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

.btn-view-reason:hover {
  background: #ec971f;
}

.btn-info {
  background: #17a2b8;
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

.btn-info:hover {
  background: #138496;
}

/* Autocomplete */
.autocomplete-wrap {
  position: relative;
}

.autocomplete-list {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ccc;
  border-top: none;
  border-radius: 0 0 5px 5px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
}

.autocomplete-list.show {
  display: block;
}

.autocomplete-list .ac-item {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 14px;
}

.autocomplete-list .ac-item:hover {
  background: #e9ecef;
}

/* History buttons */
.history-btn {
  background: #f8f9fa;
  border: 1px solid #ddd;
  padding: 8px 15px;
  border-radius: 5px;
  cursor: pointer;
  margin-right: 8px;
  margin-bottom: 8px;
  font-family: 'Bai Jamjuree', sans-serif;
  font-size: 14px;
}

.history-btn:hover {
  background: #e9ecef;
}

.history-btn.active {
  background: #28a745;
  color: #fff;
  border-color: #28a745;
}

.view-reason-link {
  color: #f0ad4e;
  cursor: pointer;
  font-size: 11px;
  margin-left: 5px;
}

.view-reason-link:hover {
  text-decoration: underline;
}

/* Reason popup */
.reason-popup {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.4);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.reason-popup.show {
  display: flex;
}

.reason-popup-content {
  background: #fff;
  border-radius: 10px;
  padding: 25px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}

.reason-popup-content h3 {
  margin-top: 0;
}

.reason-popup-content .reason-list-item {
  padding: 10px 0;
  border-bottom: 1px solid #eee;
}

.reason-popup-content .reason-list-item:last-child {
  border-bottom: none;
}

.reason-popup-content .btn-close-popup {
  background: #28a745;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
  margin-top: 15px;
}

/* Modal Styles */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9999;
  justify-content: center;
  align-items: center;
}

.modal-overlay.show {
  display: flex;
}

.modal-content {
  background: #fff;
  border-radius: 10px;
  padding: 30px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 5px 30px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
  margin-top: 0;
  margin-bottom: 10px;
  font-size: 20px;
  color: #d9534f;
}

.modal-content p {
  color: #666;
  margin-bottom: 20px;
}

.reason-item {
  margin-bottom: 15px;
  padding: 12px;
  background: #fff8f8;
  border: 1px solid #f5c6cb;
  border-radius: 6px;
}

.reason-item label {
  display: block;
  font-weight: bold;
  margin-bottom: 4px;
  font-size: 14px;
  color: #333;
}

.reason-item .deviation-info {
  font-size: 12px;
  color: #d9534f;
  margin-bottom: 8px;
}

.reason-item textarea {
  width: 100%;
  height: 50px;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
  font-family: 'Bai Jamjuree', sans-serif;
  resize: vertical;
}

.reason-item textarea.reason-error {
  border-color: #d9534f;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

.btn-cancel {
  background: #6c757d;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
}

.btn-cancel:hover {
  background: #5a6268;
}

.btn-confirm {
  background: #28a745;
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 5px;
  cursor: pointer;
}

.btn-confirm:hover {
  background: #218838;
}

/* Success Modal */
.modal-success {
  text-align: center;
}

.modal-success h2 {
  color: #28a745;
}

.success-icon {
  font-size: 48px;
  margin-bottom: 10px;
}

.modal-actions.center {
  justify-content: center;
}

/* Loading Modal */
.modal-loading {
  text-align: center;
}

.modal-loading h2 {
  color: #333;
  margin-top: 15px;
}

.modal-loading p {
  color: #666;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #e0e0e0;
  border-top: 5px solid #28a745;
  border-radius: 50%;
  margin: 0 auto;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Input with detail button */
.input-with-btn {
  display: flex;
  gap: 5px;
  align-items: center;
}

.input-with-btn input {
  flex: 1;
}

.btn-detail {
  background: #17a2b8;
  color: #fff;
  border: none;
  padding: 8px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
  white-space: nowrap;
}

.btn-detail:hover {
  background: #138496;
}

/* Detail Modal */
.detail-fields {
  margin: 15px 0;
}

.detail-item {
  margin-bottom: 15px;
  padding: 12px;
  background: #f8f9fa;
  border: 1px solid #dee2e6;
  border-radius: 6px;
}

.detail-item label {
  display: block;
  font-weight: bold;
  margin-bottom: 6px;
  font-size: 14px;
}

.detail-item input {
  width: 100%;
  padding: 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  box-sizing: border-box;
}

.detail-remaining {
  font-size: 12px;
  color: #6c757d;
  margin-top: 4px;
  font-style: italic;
}
