@font-face {
  font-family: "TH SarabunPSK";
  src: url("/vehicle-request/static/fonts/THSarabun.ttf") format("truetype");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "TH SarabunPSK";
  src: url("/vehicle-request/static/fonts/THSarabun Bold.ttf") format("truetype");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #f0fdf4;
  --card: #ffffff;
  --line: #cbd5e1;
  --accent: #166534;
  --accent-hover: #15803d;
  --accent-soft: #dcfce7;
  --pdf: #b91c1c;
  --pdf-hover: #991b1b;
  --err: #b91c1c;
  --text: #0f172a;
  --muted: #64748b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: linear-gradient(135deg, #f0fdf4 0%, #e2e8f0 100%);
  font-family: "Prompt", "Sarabun", system-ui, sans-serif;
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  background: linear-gradient(135deg, #166534 0%, #0f3d24 100%);
  color: #fff;
  padding: 18px 20px;
  border-bottom: 4px solid #22c55e;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.topbar-inner {
  max-width: 1460px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.badge-pill {
  display: inline-block;
  background: rgba(255, 255, 255, 0.15);
  color: #bbf7d0;
  font-size: 0.76rem;
  padding: 3px 10px;
  border-radius: 99px;
  margin-bottom: 4px;
}

.topbar h1 {
  margin: 0 0 3px;
  font-size: 1.35rem;
}

.subtitle {
  margin: 0;
  font-size: 0.86rem;
  color: #dcfce7;
  font-weight: 300;
}

.topbar-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-outline {
  color: #fff;
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.45);
  padding: 7px 12px;
  border-radius: 8px;
  font-size: 0.83rem;
  background: rgba(255, 255, 255, 0.08);
  transition: background 0.2s;
}

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

/* WORKSPACE 2-COLUMN LAYOUT */
.workspace {
  max-width: 1460px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  display: grid;
  grid-template-columns: minmax(420px, 560px) 1fr;
  gap: 22px;
  align-items: start;
}

.card {
  background: var(--card);
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.07);
}

.section-header {
  margin: 18px 0 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e2e8f0;
}

.section-header:first-of-type {
  margin-top: 0;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

h2 {
  font-size: 1.02rem;
  margin: 0;
  color: var(--accent);
}

.hint {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 2px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.full {
  grid-column: 1 / -1;
}

label {
  display: block;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--text);
}

.lbl-txt {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  line-height: 1.35;
}

label b {
  color: var(--err);
  display: inline;
}

input,
select,
textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 400;
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid #22c55e;
  border-color: var(--accent);
}

textarea {
  min-height: 68px;
  resize: vertical;
}

label.check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  background: #f8fafc;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
  cursor: pointer;
}

label.check input {
  display: inline-block;
  width: auto;
  margin-top: 0;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 18px;
}

button {
  padding: 10px 16px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.18s;
}

button:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.btn-docx {
  background: #1d4ed8;
  flex: 1;
}
.btn-docx:hover {
  background: #1e40af;
}

.btn-pdf {
  background: var(--pdf);
  flex: 1;
}
.btn-pdf:hover {
  background: var(--pdf-hover);
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #cbd5e1;
}
.btn-secondary:hover {
  background: #e2e8f0;
}

.btn-mini {
  padding: 4px 10px;
  font-size: 0.76rem;
  font-weight: 500;
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
  border-radius: 6px;
}
.btn-mini:hover {
  background: #bbf7d0;
}

.errors {
  margin-top: 14px;
  padding: 10px 13px;
  border: 1px solid var(--err);
  border-radius: 8px;
  color: var(--err);
  background: #fef2f2;
  font-size: 0.84rem;
}

.status-msg {
  margin-top: 14px;
  padding: 10px 13px;
  border: 1px solid #22c55e;
  border-radius: 8px;
  color: #166534;
  background: #f0fdf4;
  font-size: 0.84rem;
}

/* ==================== LIVE PREVIEW PANE ==================== */
.preview-pane {
  position: sticky;
  top: 16px;
  background: #334155;
  border-radius: 16px;
  padding: 14px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
}

.preview-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: #1e293b;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
  font-size: 0.85rem;
}

.preview-toolbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.live-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
  display: inline-block;
}

.page-tabs {
  display: inline-flex;
  background: #0f172a;
  padding: 3px;
  border-radius: 8px;
  gap: 3px;
}

.tab-btn {
  padding: 4px 10px;
  font-size: 0.78rem;
  font-weight: 500;
  background: transparent;
  color: #cbd5e1;
  border-radius: 6px;
}
.tab-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}
.tab-btn.active {
  background: #22c55e;
  color: #052e16;
  font-weight: 600;
}

.preview-toolbar-right {
  display: flex;
  gap: 6px;
}

.btn-toolbar-docx {
  padding: 5px 11px;
  font-size: 0.78rem;
  background: #2563eb;
  border-radius: 6px;
}
.btn-toolbar-docx:hover {
  background: #1d4ed8;
}

.btn-toolbar-pdf {
  padding: 5px 11px;
  font-size: 0.78rem;
  background: #dc2626;
  border-radius: 6px;
}
.btn-toolbar-pdf:hover {
  background: #b91c1c;
}

.preview-stage {
  max-height: calc(100vh - 115px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 6px 4px 16px;
}

/* A4 PAPER SIMULATION */
.a4-sheet {
  position: relative;
  width: 100%;
  max-width: 720px;
  min-height: 960px;
  background: #ffffff;
  color: #000000;
  padding: 42px 52px 36px;
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  font-family: "TH SarabunPSK", "Sarabun", serif;
  font-size: 20px;
  line-height: 1.55;
  display: flex;
  flex-direction: column;
}

.sheet-page-badge {
  position: absolute;
  top: 10px;
  left: 14px;
  background: #f1f5f9;
  color: #475569;
  font-family: "Prompt", sans-serif;
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid #e2e8f0;
}

.doc-top-right {
  text-align: right;
  font-weight: 700;
  font-size: 21px;
  margin-bottom: 2px;
}

.doc-title {
  text-align: center;
  font-weight: 700;
  font-size: 24px;
  margin-bottom: 10px;
}

.doc-date-right {
  text-align: right;
  margin-bottom: 14px;
}

.doc-salutation {
  display: flex;
  gap: 22px;
  margin-bottom: 10px;
}

.doc-line {
  margin-bottom: 7px;
  word-break: break-word;
}

.doc-indent {
  padding-left: 52px;
}

.doc-flex-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.doc-row-single {
  display: flex;
  align-items: baseline;
  gap: 5px;
  white-space: nowrap;
  width: 100%;
}

.flex-grow {
  flex: 1 1 auto;
  min-width: 40px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Dotted underline slots matching Thai official form */
.dotted {
  display: inline-block;
  border-bottom: 1px dotted #1e293b;
  color: #0f172a;
  font-weight: 600;
  padding: 0 6px;
  text-align: center;
  min-height: 24px;
  line-height: 1.25;
  vertical-align: baseline;
}

.w-day { min-width: 46px; }
.w-month { min-width: 115px; }
.w-year { min-width: 66px; }
.w-time { min-width: 85px; }

.w-req-name { min-width: 210px; }
.w-req-pos { min-width: 215px; }
.w-plate { min-width: 230px; }
.w-purpose {
  min-width: 540px;
  text-align: left;
}
.w-dest {
  min-width: 340px;
  text-align: left;
}
.w-pass { min-width: 55px; }

.doc-sign-block {
  margin-top: 22px;
  margin-left: auto;
  width: 62%;
  text-align: center;
}

.w-sign-line { min-width: 195px; }
.sign-paren { margin-top: 4px; }
.sign-pos { margin-top: 2px; }

.doc-checkbox-row {
  display: flex;
  justify-content: center;
  gap: 90px;
  margin: 24px 0 14px;
  font-weight: 600;
}

.doc-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.box-sq {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 1.5px solid #000;
  background: #fff;
}

.approver-sign {
  margin-top: 12px;
  width: 66%;
}

.w-approver-line { min-width: 210px; }
.w-approver-name { min-width: 220px; }
.w-approver-title { min-width: 210px; }
.w-day-sm { min-width: 40px; }
.w-month-sm { min-width: 95px; }
.w-year-sm { min-width: 56px; }

.doc-driver-note {
  margin-top: 28px;
  margin-bottom: 16px;
}

.w-driver { min-width: 260px; }

.doc-footer {
  margin-top: auto;
  padding-top: 16px;
  text-align: center;
  font-weight: 700;
  font-size: 21px;
}

/* PAGE 2 SPECIFIC */
.w-p2-1 { min-width: 260px; }
.w-p2-2 { min-width: 190px; }
.w-p2-short { min-width: 100px; }
.w-p2-med { min-width: 135px; }
.w-p2-5 { min-width: 270px; }
.w-p2-full { width: 100%; }

.doc-p2-sign-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 32px;
}

.w-p2-sign { min-width: 185px; }
.w-day-xs { min-width: 34px; }
.w-month-xs { min-width: 78px; }
.w-year-xs { min-width: 48px; }

.doc-p2-center-note {
  text-align: center;
  margin-top: 36px;
  font-weight: 600;
}

.doc-p2-bottom-note {
  margin-top: 24px;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }
  .preview-pane {
    position: static;
  }
  .preview-stage {
    max-height: none;
  }
}

@media (max-width: 640px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .a4-sheet {
    padding: 24px 20px;
    font-size: 16px;
    min-height: auto;
  }
  .w-purpose, .w-dest {
    min-width: 180px;
  }
  .doc-sign-block, .approver-sign {
    width: 100%;
  }
}

/* PRINT STYLES */
@media print {
  body {
    background: #fff;
  }
  .no-print {
    display: none !important;
  }
  .workspace {
    display: block;
    padding: 0;
    margin: 0;
  }
  .preview-pane {
    background: transparent;
    padding: 0;
    box-shadow: none;
  }
  .preview-stage {
    max-height: none;
    overflow: visible;
    padding: 0;
    gap: 0;
  }
  .a4-sheet {
    box-shadow: none;
    max-width: none;
    width: 100%;
    min-height: 275mm;
    page-break-after: always;
    padding: 18mm 20mm;
  }
  .a4-sheet:last-child {
    page-break-after: auto;
  }
}
