@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+Thai:wght@300;400;500;600;700&family=Sarabun:ital,wght@0,300;0,400;0,500;0,600;0,700;1,400&display=swap');

:root {
  --font-primary: 'Sarabun', 'Noto Sans Thai', sans-serif;
  --cpf-green: #0b6b3a;
  --cpf-green-dark: #074f2a;
  --cpf-green-light: #e8f5ee;
  --cpf-blue: #003b71;
  --accent-amber: #d97706;
  --bg-page: #f1f5f9;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #475569;
  --border-color: #cbd5e1;
  --border-subtle: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px -2px rgba(15, 23, 42, 0.08), 0 2px 6px -1px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.12);
  --radius-md: 10px;
  --radius-lg: 14px;
}

body.font-noto {
  --font-primary: 'Noto Sans Thai', 'Sarabun', sans-serif;
}

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

body {
  font-family: var(--font-primary);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.55;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ==================== TOP NAVBAR ==================== */
.app-header {
  background: linear-gradient(135deg, #073b22 0%, #0b6b3a 60%, #0d7a43 100%);
  color: #ffffff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
}

.header-inner {
  max-width: 1480px;
  margin: 0 auto;
  padding: 0.7rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  background: #fff;
  padding: 2px;
  object-fit: contain;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}

.brand-title h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.brand-title p {
  font-size: 0.8rem;
  color: rgba(255, 255, 255, 0.85);
}

.nav-tabs {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: rgba(0, 0, 0, 0.2);
  padding: 0.3rem;
  border-radius: 10px;
}

.nav-tab {
  border: none;
  background: transparent;
  color: rgba(255, 255, 255, 0.88);
  font-family: var(--font-primary);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.18s ease;
}

.nav-tab:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.nav-tab.active {
  background: #ffffff;
  color: var(--cpf-green-dark);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.font-Select {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 7px;
  padding: 0.38rem 0.65rem;
  font-family: var(--font-primary);
  font-size: 0.82rem;
  cursor: pointer;
}

.font-Select option {
  color: var(--text-main);
  background: #fff;
}

/* ==================== MAIN CONTAINER ==================== */
.main-container {
  max-width: 1480px;
  margin: 1.25rem auto 2.5rem;
  padding: 0 1.25rem;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

/* ==================== CONVERTER WORKSPACE ==================== */
.converter-grid {
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  gap: 1.35rem;
  align-items: start;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.card-header {
  padding: 0.95rem 1.25rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--cpf-green);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
}

.card-body {
  padding: 1.2rem 1.25rem;
}

/* ==================== UPLOAD ZONE & SAMPLES ==================== */
.upload-zone {
  border: 2px dashed #94a3b8;
  border-radius: var(--radius-md);
  background: #f8fafc;
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--cpf-green);
  background: var(--cpf-green-light);
}

.upload-icon {
  font-size: 2rem;
  color: var(--cpf-green);
  margin-bottom: 0.4rem;
}

.upload-zone h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.upload-zone p {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sample-bar {
  margin-top: 1rem;
  padding-top: 0.9rem;
  border-top: 1px solid var(--border-subtle);
}

.sample-bar-label {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.sample-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.sample-chip {
  font-family: var(--font-primary);
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1e293b;
  cursor: pointer;
  transition: all 0.15s ease;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.sample-chip:hover {
  border-color: var(--cpf-green);
  background: var(--cpf-green-light);
  color: var(--cpf-green-dark);
}

.sample-chip.active {
  background: var(--cpf-green);
  color: #fff;
  border-color: var(--cpf-green);
}

/* Source Quotation Image Preview */
.source-preview-box {
  margin-top: 0.9rem;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: #f1f5f9;
  overflow: hidden;
  position: relative;
}

.source-close-btn {
  position: absolute;
  top: 10px;
  right: 14px;
  z-index: 10;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(15, 23, 42, 0.72);
  color: #ffffff;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}

.source-close-btn:hover {
  background: #dc2626;
}

.source-canvas-wrap {
  max-height: 480px;
  overflow: auto;
  text-align: center;
  padding: 0.85rem;
  background: #e2e8f0;
}

.source-canvas-wrap canvas {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.18);
}

/* ==================== EXTRACTED ITEMS TABLE ==================== */
.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.items-editor-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.items-editor-table th {
  background: #f1f5f9;
  color: #1e293b;
  font-weight: 700;
  text-align: left;
  padding: 0.6rem 0.5rem;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.items-editor-table td {
  padding: 0.45rem 0.4rem;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.items-editor-table input,
.items-editor-table textarea {
  width: 100%;
  font-family: var(--font-primary);
  font-size: 0.88rem;
  padding: 0.4rem 0.5rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: var(--text-main);
}

.items-editor-table textarea {
  resize: vertical;
  min-height: 42px;
}

.items-editor-table input:focus,
.items-editor-table textarea:focus {
  outline: none;
  border-color: var(--cpf-green);
  box-shadow: 0 0 0 2px rgba(11, 107, 58, 0.15);
}

.num-input {
  text-align: right;
}

.totals-bar {
  margin-top: 0.9rem;
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  align-items: center;
}

.total-metric {
  display: flex;
  flex-direction: column;
}

.total-metric span.lbl {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.total-metric strong.val {
  font-size: 1.05rem;
  color: var(--text-main);
}

.total-metric.grand strong.val {
  font-size: 1.2rem;
  color: var(--cpf-green);
}

/* ==================== FORM CONTROLS ==================== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.95rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-label {
  font-size: 0.86rem;
  font-weight: 600;
  color: #1e293b;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-label small {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.form-control {
  font-family: var(--font-primary);
  font-size: 0.92rem;
  padding: 0.5rem 0.7rem;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  color: var(--text-main);
  transition: border-color 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--cpf-green);
  box-shadow: 0 0 0 3px rgba(11, 107, 58, 0.12);
}

.option-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.pill-label {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.42rem 0.75rem;
  border: 1px solid #cbd5e1;
  border-radius: 7px;
  background: #fff;
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: all 0.15s ease;
}

.pill-label:hover {
  border-color: var(--cpf-green);
  background: #f8fafc;
}

.pill-label input:checked + span {
  color: var(--cpf-green-dark);
  font-weight: 700;
}

.pill-label:has(input:checked) {
  border-color: var(--cpf-green);
  background: var(--cpf-green-light);
}

/* ==================== BUTTONS ==================== */
.btn {
  font-family: var(--font-primary);
  font-size: 0.88rem;
  font-weight: 600;
  padding: 0.52rem 0.95rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all 0.15s ease;
  text-decoration: none;
}

.btn-sm {
  padding: 0.34rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 6px;
}

.btn-primary {
  background: var(--cpf-green);
  color: #fff;
}

.btn-primary:hover {
  background: var(--cpf-green-dark);
}

.btn-blue {
  background: var(--cpf-blue);
  color: #fff;
}

.btn-blue:hover {
  background: #00284d;
}

.btn-outline {
  background: #fff;
  color: #1e293b;
  border-color: #cbd5e1;
}

.btn-outline:hover {
  border-color: var(--cpf-green);
  color: var(--cpf-green-dark);
  background: #f8fafc;
}

.btn-danger {
  background: #fee2e2;
  color: #b91c1c;
  border-color: #fecaca;
}

.btn-danger:hover {
  background: #fecaca;
}

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

/* ==================== OFFICIAL CPF PR FORM PREVIEW (ตามตัวอย่าง_ใบขอซื้อ.pdf) ==================== */
.pr-preview-sticky {
  position: sticky;
  top: 76px;
}

.pr-sheet-wrapper {
  background: #cbd5e1;
  padding: 1rem;
  border-radius: 10px;
  overflow-x: auto;
}

.pr-sheet {
  width: 210mm;
  min-height: 285mm;
  margin: 0 auto;
  background: #ffffff;
  color: #000000;
  padding: 8mm 10mm;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-family: var(--font-primary);
  font-size: 12px;
  line-height: 1.35;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Top Header Section of PR Form */
.pr-top-grid {
  display: grid;
  grid-template-columns: 1fr 56mm;
  gap: 2.5mm;
  margin-bottom: 2.5mm;
}

.pr-top-left {
  border: 1.5px solid #000;
  border-radius: 10px;
  padding: 2.5mm 3.5mm;
  display: grid;
  grid-template-columns: 22mm 1fr;
  gap: 2mm;
}

.pr-logo-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding-top: 1mm;
}

.pr-logo-cell img {
  width: 19mm;
  height: auto;
  object-fit: contain;
}

.pr-fields-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.pr-fields-table td {
  padding: 1px 3px;
  vertical-align: bottom;
}

.pr-fields-table td.lbl-col {
  width: 36mm;
  text-align: right;
  padding-right: 6px;
  line-height: 1.1;
  white-space: nowrap;
}

.pr-fields-table td.lbl-col strong {
  display: block;
  font-size: 11px;
}

.pr-fields-table td.lbl-col span {
  display: block;
  font-size: 9.5px;
}

.pr-fields-table td.val-col {
  border-bottom: 1px solid #333;
  font-size: 11.5px;
  font-weight: 500;
  padding-bottom: 2px;
}

.pr-check-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  font-size: 10.5px;
}

.pr-box-item {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.pr-checkbox {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 11px;
  height: 11px;
  border: 1px solid #000;
  font-size: 9px;
  line-height: 1;
  font-weight: 700;
}

.pr-radio {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 11px;
  height: 11px;
  border: 1px solid #000;
  border-radius: 50%;
  font-size: 8px;
  line-height: 1;
}

.pr-radio.checked::after {
  content: '';
  width: 6px;
  height: 6px;
  background: #000;
  border-radius: 50%;
}

/* Top Right Box of PR Form */
.pr-top-right {
  border: 1.5px solid #000;
  border-radius: 10px;
  padding: 2.5mm 3mm;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.pr-doc-title {
  text-align: center;
  border-bottom: 1px solid #000;
  padding-bottom: 1.5mm;
  margin-bottom: 1mm;
}

.pr-doc-title h2 {
  font-size: 14px;
  font-weight: 700;
  margin: 0;
}

.pr-doc-title h3 {
  font-size: 12px;
  font-weight: 700;
  margin: 0;
}

.pr-eff-date {
  font-size: 8.5px;
  color: #444;
  text-align: center;
  border-bottom: 1px solid #555;
  padding-bottom: 1mm;
  margin-bottom: 1.5mm;
}

.pr-ref-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
}

.pr-ref-table td {
  padding: 2px 2px;
}

.pr-ref-table td.ref-lbl {
  width: 20mm;
  text-align: right;
  font-weight: 700;
  padding-right: 4px;
}

.pr-ref-table td.ref-val {
  border-bottom: 1px solid #444;
  font-size: 10.5px;
}

/* Main Product Table in PR Form */
.pr-items-table {
  width: 100%;
  border-collapse: collapse;
  border: 1.5px solid #000;
  font-size: 11px;
  flex-grow: 1;
}

.pr-items-table th {
  border: 1px solid #000;
  padding: 3px 4px;
  text-align: center;
  font-weight: 700;
  background: #fff;
  line-height: 1.15;
}

.pr-items-table td {
  border-left: 1px solid #000;
  border-right: 1px solid #000;
  padding: 4px 5px;
  vertical-align: top;
}

.pr-items-table tr.item-spacer td {
  height: 100%;
}

.pr-item-img-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  justify-content: center;
}

.pr-item-img-grid img {
  max-height: 110px;
  max-width: 160px;
  object-fit: contain;
}

/* Totals & Note Section in PR Form */
.pr-summary-table {
  width: 100%;
  border-collapse: collapse;
  border-left: 1.5px solid #000;
  border-right: 1.5px solid #000;
  border-bottom: 1.5px solid #000;
  font-size: 11px;
}

.pr-summary-table td {
  border: 1px solid #000;
  padding: 2px 5px;
}

/* Signatures Footer in PR Form */
.pr-footer {
  margin-top: 2.5mm;
  font-size: 10.5px;
}

.pr-sign-top-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4mm;
  align-items: flex-start;
  margin-bottom: 3mm;
}

.pr-copy-note {
  grid-column: 1 / 3;
  font-size: 10.5px;
  line-height: 1.5;
}

.pr-sign-bottom-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4mm;
  text-align: center;
  margin-top: 2mm;
}

.pr-sign-block {
  text-align: center;
  font-size: 10.5px;
  line-height: 1.4;
}

.pr-sign-line {
  margin-top: 18px;
  margin-bottom: 2px;
}

.pr-bottom-remark {
  margin-top: 2mm;
  font-size: 10px;
  color: #222;
}

/* ==================== SIGNATORIES EDITOR (เพิ่ม/ลดผู้เซ็นต์) ==================== */
.signatories-manager-box {
  margin-top: 0.35rem;
  border-top: 1px dashed var(--border-color);
  padding-top: 0.85rem;
}

.signatories-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
  background: #f8fafc;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
}

.signatories-toolbar-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
}

.sign-count-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: var(--cpf-green-light);
  color: var(--cpf-green-dark);
  font-size: 0.8rem;
  font-weight: 700;
}

.signatories-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.signatories-editor-grid {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.signer-item-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  align-items: start;
}

.signer-role-label-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.signer-role-input {
  font-family: var(--font-primary);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--cpf-green-dark);
  background: #f1f5f9;
  border: 1px dashed #94a3b8;
  border-radius: 5px;
  padding: 0.1rem 0.45rem;
  width: 115px;
  transition: all 0.15s ease;
}

.signer-role-input:focus {
  outline: none;
  background: #ffffff;
  border-style: solid;
  border-color: var(--cpf-green);
}

.signer-del-inline-btn {
  font-family: var(--font-primary);
  font-size: 0.75rem;
  font-weight: 600;
  color: #b91c1c;
  background: #fee2e2;
  border: 1px solid #fecaca;
  border-radius: 5px;
  padding: 0.1rem 0.45rem;
  cursor: pointer;
  transition: background 0.15s ease;
}

.signer-del-inline-btn:hover {
  background: #fecaca;
}

/* ==================== DASHBOARD ==================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: #fff;
  border-radius: var(--radius-lg);
  padding: 1.15rem 1.25rem;
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.kpi-info span.kpi-label {
  font-size: 0.84rem;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-info h3.kpi-value {
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0.2rem 0;
}

.kpi-info p.kpi-sub {
  font-size: 0.78rem;
  color: var(--cpf-green);
  font-weight: 500;
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
}

.dashboard-charts-grid {
  display: grid;
  grid-template-columns: 1.3fr 0.85fr 0.85fr;
  gap: 1.2rem;
  margin-bottom: 1.25rem;
}

.chart-container {
  position: relative;
  height: 270px;
  width: 100%;
}

.summary-tables-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.2rem;
  margin-bottom: 1.25rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

.data-table th {
  background: #f8fafc;
  color: #334155;
  font-weight: 700;
  padding: 0.6rem 0.65rem;
  border-bottom: 2px solid var(--border-subtle);
  text-align: left;
}

.data-table td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table tr:hover td {
  background: #f8fafc;
}

.badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
}

.badge-pm { background: #dcfce7; color: #166534; }
.badge-cm { background: #dbeafe; color: #1e40af; }
.badge-bm { background: #fee2e2; color: #991b1b; }
.badge-in { background: #fef3c7; color: #92400e; }
.badge-other { background: #f3e8ff; color: #6b21a8; }

.badge-plant {
  background: #e2e8f0;
  color: #1e293b;
}

/* Toast Notification */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: #0f172a;
  color: #fff;
  padding: 0.75rem 1.1rem;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-left: 4px solid var(--cpf-green);
  animation: slideIn 0.2s ease-out;
}

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

/* ==================== RESPONSIVE BREAKPOINTS ==================== */
@media (max-width: 1200px) {
  .converter-grid {
    grid-template-columns: 1fr;
  }
  .pr-preview-sticky {
    position: static;
  }
  .dashboard-charts-grid,
  .summary-tables-grid {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 768px) {
  .header-inner {
    flex-direction: column;
    align-items: stretch;
  }
  .nav-tabs {
    justify-content: center;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* ==================== OFFICIAL TOR SHEET PREVIEW (ตามตัวอย่าง_TOR) ==================== */
.tor-sheet {
  width: 210mm;
  min-height: 285mm;
  margin: 0 auto;
  background: #ffffff;
  color: #000000;
  padding: 10mm 12mm;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-family: var(--font-primary);
  font-size: 13px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.tor-header-bar {
  display: grid;
  grid-template-columns: 24mm 1fr;
  gap: 2mm;
  align-items: stretch;
  margin-bottom: 3.5mm;
}

.tor-logo-box {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tor-logo-box img {
  width: 22mm;
  height: auto;
  object-fit: contain;
}

.tor-green-banner {
  background: #12a64f;
  color: #ffffff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2.5mm 4mm;
  font-weight: 700;
   -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.tor-green-banner .tor-main-title {
  font-size: 16px;
  line-height: 1.25;
}

.tor-green-banner .tor-sub-title {
  font-size: 15px;
  line-height: 1.3;
}

.tor-section {
  margin-bottom: 3.5mm;
}

.tor-sec-title {
  background: #dcecd6;
  color: #000000;
  font-weight: 700;
  font-size: 13px;
  padding: 2px 6px;
  margin-bottom: 2mm;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.tor-sec-content {
  padding-left: 11mm;
  color: #000080;
  font-size: 12.5px;
  white-space: pre-line;
}

.tor-sec-content.employer-box {
  padding-left: 6mm;
  color: #000000;
}

.tor-images-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 3mm;
  padding-left: 6mm;
  justify-content: flex-start;
}

.tor-images-grid img {
  max-height: 150px;
  max-width: 210px;
  object-fit: contain;
  border: 1px solid #cbd5e1;
  border-radius: 3px;
}

.tor-footer-signatures {
  display: grid;
  grid-template-columns: 1fr 22mm 1fr;
  margin-top: 6mm;
}

.tor-sign-box {
  border: 1.3px solid #000000;
}

.tor-sign-header {
  background: #dcecd6;
  border-bottom: 1.3px solid #000000;
  text-align: center;
  font-weight: 700;
  font-size: 12.5px;
  padding: 2px 4px;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.tor-sign-body {
  height: 22mm;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==================== OFFICIAL BOQ SHEET PREVIEW (ตามตัวอย่าง_BOQ) ==================== */
.boq-sheet {
  width: 277mm;
  min-height: 190mm;
  margin: 0 auto;
  background: #ffffff;
  color: #000000;
  padding: 8mm 10mm;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  font-family: var(--font-primary);
  font-size: 12px;
  line-height: 1.35;
}

.boq-green-banner {
  background: #44c752;
  color: #000000;
  border-radius: 4px;
  padding: 3.5mm 6mm;
  text-align: center;
  margin-bottom: 3mm;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.boq-green-banner h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 1mm 0;
}

.boq-green-banner h3 {
  font-size: 14.5px;
  font-weight: 700;
  margin: 0;
}

.boq-plant-line {
  text-align: right;
  font-weight: 700;
  font-size: 12.5px;
  margin-bottom: 1.5mm;
}

.boq-table {
  width: 100%;
  border-collapse: collapse;
  border: 1.5px solid #000000;
  font-size: 11.5px;
}

.boq-table th,
.boq-table td {
  border: 1px solid #000000;
  padding: 3px 5px;
}

.boq-table thead th {
  font-weight: 700;
  text-align: center;
  background: #ffffff;
  vertical-align: middle;
}

.boq-table tr.boq-cat-header td {
  font-weight: 700;
  font-size: 12px;
}

.boq-table tr.boq-cat-summary td {
  background: #dcecd6;
  font-weight: 600;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.boq-table tr.boq-grand-row td {
  background: #a9d996;
  font-weight: 700;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.boq-table tr.boq-vat-row td {
  background: #d6eccb;
  font-weight: 600;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* ==================== PRINT STYLES (PR / TOR / BOQ) ==================== */
@media print {
  body {
    background: #fff !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .app-header,
  .converter-left-col,
  .tor-left-col,
  .boq-editor-card,
  .preview-toolbar,
  #dashboard-view,
  .toast-container {
    display: none !important;
  }
  .main-container,
  .converter-grid,
  .pr-preview-sticky,
  .card,
  .card-body,
  .pr-sheet-wrapper {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    box-shadow: none !important;
    background: transparent !important;
    width: 100% !important;
    max-width: none !important;
  }
  body.print-mode-pr #converter-view { display: block !important; }
  body.print-mode-pr #tor-view,
  body.print-mode-pr #boq-view { display: none !important; }

  body.print-mode-tor #tor-view { display: block !important; }
  body.print-mode-tor #converter-view,
  body.print-mode-tor #boq-view { display: none !important; }

  body.print-mode-boq #boq-view { display: block !important; }
  body.print-mode-boq #converter-view,
  body.print-mode-boq #tor-view { display: none !important; }

  .pr-sheet,
  .tor-sheet {
    width: 100% !important;
    min-height: 280mm !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 4mm 6mm !important;
  }
  .boq-sheet {
    width: 100% !important;
    min-height: auto !important;
    box-shadow: none !important;
    margin: 0 !important;
    padding: 3mm 4mm !important;
  }
}
