:root {
  --ink: #1d2522;
  --muted: #68736f;
  --paper: #fffdf8;
  --surface: #ffffff;
  --wash: #f1f5f1;
  --line: #c8d2cb;
  --line-strong: #8fa298;
  --brand: #0f5b4f;
  --brand-2: #157464;
  --gold: #c8a45d;
  --red: #a7372f;
  --shadow: 0 18px 42px rgba(25, 52, 45, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(15, 91, 79, 0.08), transparent 260px),
    #e9efeb;
  font-family: Tahoma, "Noto Sans Thai", Arial, sans-serif;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button-link {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 8px 14px;
  color: var(--brand);
  background: #ffffff;
  text-decoration: none;
  cursor: pointer;
}

button.primary,
.button-link {
  border-color: var(--brand);
  color: #ffffff;
  background: var(--brand);
}

button:hover,
.button-link:hover {
  filter: brightness(0.97);
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 8px 10px;
  color: var(--ink);
  background: #ffffff;
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 252px;
  display: flex;
  flex-direction: column;
  color: #ffffff;
  background: linear-gradient(180deg, #0d4c43 0%, #07332d 100%);
  overflow-y: auto;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 16px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.1);
  font-weight: 700;
  font-size: 13px;
  overflow: hidden;
  flex-shrink: 0;
}

#sidebar-logo-img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.brand-block p {
  margin: 0;
  color: rgba(255, 255, 255, 0.55);
  font-size: 11px;
  letter-spacing: 0.3px;
}

.brand-block strong {
  display: block;
  margin-top: 2px;
  font-size: 15px;
  font-weight: 700;
  color: #fff;
}

/* ── Nav groups ────────────────────────────────────────────────────────── */
.nav-list {
  display: flex;
  flex-direction: column;
  padding: 10px 0 16px;
  flex: 1;
}

.nav-group {
  margin-bottom: 6px;
}

.nav-group-label {
  display: block;
  padding: 10px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 38px;
  padding: 0 12px 0 16px;
  border: none;
  border-left: 3px solid transparent;
  border-radius: 0;
  color: rgba(255, 255, 255, 0.7);
  background: transparent;
  text-align: left;
  font-size: 13.5px;
  font-family: inherit;
  cursor: pointer;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}

.nav-icon {
  font-size: 14px;
  min-width: 22px;
  text-align: center;
  opacity: 0.7;
  flex-shrink: 0;
}

.nav-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
  border-left-color: rgba(255, 255, 255, 0.25);
}

.nav-item:hover .nav-icon { opacity: 1; }

.nav-item.active {
  color: #fff;
  background: rgba(255, 255, 255, 0.15);
  border-left-color: #7ecfc0;
  font-weight: 600;
}

.nav-item.active .nav-icon { opacity: 1; }

.shell {
  margin-left: 252px;
  padding: 0;
  min-height: 100vh;
  background: #f4f6f5;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 60px;
  padding: 0 24px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(15, 91, 79, 0.06);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-page {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.topbar-group {
  margin: 0;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--brand);
  opacity: 0.7;
}

.topbar-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 21px;
}

h3 {
  font-size: 16px;
}

.login-panel {
  flex-shrink: 0;
}

/* ── Before login ────────────────────────────────────────────────────────── */
.login-form-area {
  display: flex;
  align-items: center;
  gap: 10px;
}

.login-fields {
  display: flex;
  gap: 8px;
}

.login-fields input {
  width: 140px;
  min-height: 40px;
  border-radius: 6px;
}

.login-btn {
  min-height: 40px;
  padding: 0 20px;
  border-radius: 6px;
  font-weight: 600;
  white-space: nowrap;
}

/* ── After login ─────────────────────────────────────────────────────────── */
.user-info-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
}

.user-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.user-display-name {
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  white-space: nowrap;
}

.logout-btn {
  min-height: 36px;
  padding: 0 14px;
  border-radius: 6px;
  border-color: #ccc;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.logout-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

.notice {
  margin: 0 24px 12px;
  padding: 11px 14px;
  border-radius: 6px;
  border: 1px solid #e1c27a;
  border-left: 4px solid var(--gold);
  background: #fff8e8;
  font-size: 13.5px;
}

.view {
  display: none;
}

.view.active {
  display: block;
  padding: 20px 24px 32px;
  animation: fadeIn 0.15s ease;
}

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

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.section-head h2 {
  font-size: 19px;
  color: var(--ink);
}

.section-head .eyebrow {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--brand);
  opacity: 0.7;
  margin-bottom: 2px;
}

.filters {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.filters input {
  width: 92px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric,
.panel,
.paper-form,
.print-sheet {
  border: 1px solid var(--line);
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(15, 91, 79, 0.07);
}

.metric {
  padding: 18px 20px;
  border-top: none;
  border-left: 4px solid var(--brand);
  transition: box-shadow 0.15s;
}

.metric:hover {
  box-shadow: 0 4px 12px rgba(15, 91, 79, 0.12);
}

.metric span,
.metric small {
  display: block;
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 10px 0 3px;
  color: var(--ink);
  font-size: 30px;
  font-weight: 700;
}

.metric small {
  font-size: 11.5px;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.7fr);
  gap: 16px;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: #f9fbf9;
}

.panel-head h3 { font-size: 14px; }

.panel-head span {
  color: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.panel .table-wrap,
.paper-form + .table-wrap {
  border-width: 0;
  border-radius: 0;
}

.compact {
  max-height: 420px;
  overflow-y: auto;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  border-right: none;
  border-left: none;
  border-top: none;
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  background: #f7faf8;
  font-weight: 600;
  font-size: 11.5px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  border-bottom: 2px solid var(--line);
}

td {
  background: #ffffff;
  font-size: 13.5px;
  color: var(--ink);
}

tr:hover td {
  background: #f6faf8;
}

tr:nth-child(even) td {
  background: #fafcfa;
}

tr:nth-child(even):hover td {
  background: #f2f8f5;
}

.row-inactive td {
  opacity: 0.5;
}

.num {
  text-align: right;
}

.paper-form {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
  padding: 20px;
  border-radius: 8px;
}

.paper-form {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
  padding: 18px;
}

.inline-form {
  grid-template-columns: repeat(6, minmax(120px, 1fr)) auto;
  align-items: end;
}

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

.request-form {
  max-width: 1180px;
  margin-inline: auto;
}

.company-line {
  display: grid;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--brand);
  text-align: center;
}

.company-line strong {
  font-size: 18px;
}

.company-line span {
  color: var(--muted);
  font-size: 12px;
}

.form-title {
  display: grid;
  gap: 4px;
  text-align: center;
}

.form-title h3 {
  font-size: 18px;
}

.form-title p {
  margin: 0;
  color: var(--muted);
}

.document-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.form-table-wrap {
  border: 1px solid var(--line-strong);
  overflow: visible; /* allow dropdown to overflow table */
}

.form-table input,
.form-table select {
  border-color: transparent;
  background: transparent;
}

/* Search input inside form-table: show border on focus */
.form-table .line-mat-search {
  border-color: transparent;
  background: transparent;
}

.form-table .line-mat-search:focus {
  border-color: var(--brand);
  background: #fff;
}

.form-table input:focus,
.form-table select:focus {
  outline: 1px solid var(--brand);
  background: #ffffff;
}

.line-actions,
.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.form-note {
  margin: 0;
  color: var(--red);
  font-size: 12px;
}

.signature-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line-strong);
}

.signature-strip > div {
  display: grid;
  gap: 8px;
  min-height: 112px;
  padding: 12px;
  border-right: 1px solid var(--line);
  text-align: center;
}

.signature-strip > div:last-child {
  border-right: 0;
}

.signature-strip span,
.signature-strip small {
  color: var(--muted);
  font-size: 12px;
}

.signature-strip strong {
  display: grid;
  place-items: center;
  min-height: 34px;
  border-bottom: 1px solid var(--ink);
  color: var(--brand);
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 9px;
  border-radius: 999px;
  color: var(--brand);
  background: #edf8f5;
  font-size: 12px;
  font-weight: 700;
}

/* ── Role badges ─────────────────────────────────────────────────────────── */
.role-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}
.rb-requester { color: #555; background: #eee; }
.rb-manager   { color: #1a5fa8; background: #deeaf8; }
.rb-approver  { color: #7a4500; background: #fde8c8; }
.rb-warehouse { color: #5a1fa0; background: #ede0f8; }
.rb-admin     { color: var(--brand); background: #edf8f5; }

/* ── User form ───────────────────────────────────────────────────────────── */
.user-form {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}
.uf-title {
  grid-column: 1 / -1;
  font-weight: 700;
  font-size: 14px;
  color: var(--brand);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}

/* ── Profile page ────────────────────────────────────────────────────────── */
.profile-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}

.profile-card { padding: 0; }

.profile-inner-form {
  padding: 16px;
  display: grid;
  gap: 12px;
}

.profile-info {
  padding: 16px;
  display: grid;
  gap: 10px;
}

.profile-info-row {
  display: flex;
  gap: 8px;
  font-size: 13px;
}
.profile-info-row span:first-child {
  color: var(--muted);
  min-width: 80px;
}

.sig-preview-box {
  min-height: 80px;
  border: 1px dashed var(--line-strong);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;   /* ขาวล้วน — จำเป็นสำหรับ mix-blend-mode:multiply */
  overflow: hidden;
}

.sig-preview-box img {
  max-height: 80px;
  max-width: 100%;
  object-fit: contain;
  mix-blend-mode: multiply;  /* ลบพื้นหลังมืด — รองรับข้อมูลเก่าในDB ด้วย */
}

.sig-upload-label {
  cursor: pointer;
  justify-content: center;
  text-align: center;
}

@media (max-width: 1080px) {
  .profile-grid { grid-template-columns: 1fr; }
  .user-form    { grid-template-columns: repeat(2, 1fr); }
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.row-actions button {
  min-height: 30px;
  padding: 4px 8px;
  font-size: 12px;
}

.print-sheet {
  max-width: 1040px;
  margin: 0 auto;
  padding: 28px;
}

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 16px;
  margin: 18px 0;
}

.checkbox-grid span::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 8px;
  border: 1px solid var(--line-strong);
  vertical-align: -1px;
}

.checkbox-grid .checked::before {
  background:
    linear-gradient(45deg, transparent 42%, var(--brand) 43%, var(--brand) 58%, transparent 59%),
    linear-gradient(-45deg, transparent 42%, var(--brand) 43%, var(--brand) 58%, transparent 59%);
}

.print-table th,
.print-table td {
  border-color: var(--line-strong);
}

.approval-title {
  margin: 18px 0 10px;
  text-align: center;
}

.print-signatures {
  box-shadow: none;
}

@media (max-width: 1080px) {
  .sidebar {
    position: static;
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
  }

  .shell {
    margin-left: 0;
  }

  .nav-list {
    flex-direction: row;
    flex-wrap: wrap;
    padding: 6px;
  }

  .nav-group { margin-bottom: 0; }
  .nav-group-label { display: none; }
  .nav-item { border-left: none; border-bottom: 3px solid transparent; }
  .nav-item.active { border-bottom-color: #7ecfc0; border-left: none; }

  .topbar { height: auto; min-height: 56px; padding: 10px 16px; }
  .section-head { flex-direction: column; align-items: flex-start; }

  .login-fields { flex-direction: column; gap: 6px; }
  .login-fields input { width: 100%; }
  .login-form-area { flex-wrap: wrap; }
  .user-info-area { flex-wrap: wrap; }

  .content-grid,
  .metric-grid,
  .document-grid,
  .signature-strip {
    grid-template-columns: 1fr;
  }

  .inline-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .shell {
    padding: 12px;
  }

  .nav-list,
  .inline-form,
  .checkbox-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 20px;
  }
}

/* ── Stock Balance Report ────────────────────────────────────────────────── */
.sr-filter-label {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  color: var(--muted);
}

.sr-summary-bar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 10px 16px;
  background: #edf8f5;
  border-radius: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  flex-wrap: wrap;
}

.sr-physical-col { background: #f0f8f5; }
.sr-diff-col     { background: #fff8f0; }
.sr-diff-pos     { color: #1a5fa8; font-weight: 600; }
.sr-diff-neg     { color: var(--red); font-weight: 600; }

.sr-physical-input {
  width: 80px;
  min-height: 28px;
  border: 1.5px solid var(--brand);
  border-radius: 4px;
  text-align: right;
  padding: 2px 6px;
  font-size: 12.5px;
}

.sr-cat-row td {
  background: #f2f8f5 !important;
  font-weight: 700;
  font-size: 12px;
  color: var(--brand);
  padding: 6px 10px;
}

/* Print styles */
.sr-print-header { display: none; }
.sr-print-title  { font-size: 16px; font-weight: 700; display: block; }
.sr-print-meta   { display: flex; gap: 24px; font-size: 12px; margin-top: 4px; }

.sr-signatures {
  display: flex;
  justify-content: space-around;
  margin-top: 32px;
  padding-top: 12px;
}

.sr-signatures > div { text-align: center; }
.sr-sig-line {
  width: 180px;
  border-bottom: 1px solid #333;
  margin-bottom: 6px;
  height: 40px;
}
.sr-signatures small { font-size: 11px; color: var(--muted); }

/* ── Signature image in print form ──────────────────────────────────────── */
.ps-sig-img {
  max-height: 52px;
  max-width: 130px;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  margin: 0 auto 2px;
  /* ลบพื้นหลังสีทึบ — ขาว = โปร่งใส เหลือแค่เส้นลายเซ็น */
  mix-blend-mode: multiply;
}

.ps-sig-name {
  display: block;
  font-size: 10.5px;
  text-align: center;
  color: var(--ink);
}

/* ── Stock History Panel ─────────────────────────────────────────────────── */
#stock-history-panel {
  margin-top: 20px;
  border: 1.5px solid var(--brand);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
  animation: fadeIn 0.2s ease;
}

.sh-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  background: #f7fcfb;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.sh-header h3 { margin: 0; font-size: 15px; }

.sh-summary {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.sh-metric {
  text-align: center;
  padding: 6px 14px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--line);
  min-width: 80px;
}

.sh-metric span { display: block; font-size: 10.5px; color: var(--muted); margin-bottom: 3px; }
.sh-metric strong { font-size: 18px; color: var(--brand); }
.sh-in strong   { color: #1a5fa8; }
.sh-out strong  { color: var(--red); }
.sh-adj strong  { color: var(--gold); }

.sh-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.sh-table { min-width: unset !important; width: 100%; font-size: 12.5px; }
.sh-table th, .sh-table td { padding: 7px 10px; }
.sh-balance-col { background: #f2f8f5; font-weight: 700; color: var(--brand); }
.sh-type-in   { color: #1a5fa8; font-weight: 600; }
.sh-type-out  { color: var(--red); font-weight: 600; }
.sh-type-adj  { color: #7a4500; font-weight: 600; }
.sh-neg       { color: var(--red); }

/* ── Stock info box (Adjust mode) ───────────────────────────────────────── */
.stock-info-box {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  margin-bottom: 12px;
  background: #edf8f5;
  border: 1px solid var(--brand);
  border-radius: 6px;
  font-size: 13.5px;
}

.stock-info-badge {
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
}

.adjust-guide {
  margin-top: 12px;
  padding: 12px 16px;
  background: #fff8e8;
  border: 1px solid var(--gold);
  border-radius: 6px;
  font-size: 12.5px;
}

.adjust-guide ul {
  margin: 6px 0 0;
  padding-left: 18px;
}

.adjust-guide li { margin-bottom: 4px; }

/* ── Import Zone ────────────────────────────────────────────────────────── */
.import-zone {
  margin-top: 24px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.import-zone-title {
  margin: 0 0 14px;
  font-size: 15px;
  color: var(--brand);
}

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

.import-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fafcfa;
}

.import-card-header {
  font-weight: 700;
  font-size: 14px;
  color: var(--ink);
  margin-bottom: 6px;
}

.import-card p {
  margin: 0 0 12px;
  font-size: 12.5px;
  color: var(--muted);
}

.import-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.import-upload-btn { cursor: pointer; }

.import-preview-header {
  font-size: 13px;
  margin-bottom: 8px;
  padding: 6px 10px;
  background: #edf8f5;
  border-radius: 4px;
}

@media (max-width:900px) { .import-grid { grid-template-columns: 1fr; } }

/* ── Danger Zone ────────────────────────────────────────────────────────── */
.danger-zone {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 24px;
  padding: 16px 20px;
  border: 1.5px solid #e0a09b;
  border-radius: 8px;
  background: #fff8f7;
  flex-wrap: wrap;
}

.danger-zone-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.danger-icon {
  font-size: 22px;
  color: var(--red);
  line-height: 1;
  flex-shrink: 0;
}

.danger-zone-header strong {
  display: block;
  color: var(--red);
  font-size: 14px;
  margin-bottom: 4px;
}

.danger-zone-header p {
  margin: 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

.btn-danger {
  min-height: 38px;
  padding: 0 16px;
  border-radius: 6px;
  border: 1.5px solid var(--red);
  color: var(--red);
  background: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 25, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 28px 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}

.modal-title {
  margin: 0 0 12px;
  color: var(--red);
  font-size: 17px;
}

.modal-box p { margin: 0 0 10px; font-size: 13.5px; }
.modal-box ul { margin: 0 0 14px; padding-left: 20px; }
.modal-box li { font-size: 13px; color: var(--ink); margin-bottom: 4px; }

.modal-warn {
  font-weight: 600;
  color: var(--red) !important;
}

.modal-box input {
  margin-bottom: 16px;
  border: 2px solid var(--line);
  border-radius: 6px;
}

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

/* ── Doc tabs & filters ──────────────────────────────────────────────────── */
.doc-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--line);
  margin-bottom: 14px;
}

.doc-tab {
  padding: 9px 20px;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  margin-bottom: -2px;
  transition: color 0.12s, border-color 0.12s;
}

.doc-tab:hover { color: var(--brand); }
.doc-tab.active { color: var(--brand); border-bottom-color: var(--brand); }

.doc-type-filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.doc-type-btn {
  min-height: 30px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  background: #fff;
  font-size: 12.5px;
  cursor: pointer;
  transition: all 0.12s;
}

.doc-type-btn.active,
.doc-type-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: #edf8f5;
}

/* ── Doc type badges ─────────────────────────────────────────────────────── */
.dt-request  { color: #555;    background: #eee;    padding: 2px 8px; border-radius: 4px; font-size: 11px; }
.dt-purchase { color: #7a4500; background: #fde8c8; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.dt-new_item { color: #5a1fa0; background: #ede0f8; padding: 2px 8px; border-radius: 4px; font-size: 11px; }

/* ── PO status: submitted ────────────────────────────────────────────────── */
.sb-submitted { color: #1a5fa8; background: #deeaf8; }
.sb-approved  { color: var(--brand); background: #edf8f5; }
.sb-sent      { color: #0d4c43; background: #c6eae2; font-weight: 700; }

/* ── Stock badge in requisition lines ───────────────────────────────────── */
.line-stock-badge {
  display: inline-block;
  margin-top: 3px;
  font-size: 10.5px;
  padding: 1px 7px;
  border-radius: 999px;
  font-weight: 600;
  cursor: default;
}

/* ── File attachment chips ───────────────────────────────────────────────── */
.line-attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #edf8f5;
  border: 1px solid var(--brand);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  color: var(--brand);
  max-width: 160px;
}

.attach-del-btn {
  border: none;
  background: none;
  color: var(--red);
  cursor: pointer;
  padding: 0;
  min-height: unset;
  font-size: 11px;
  line-height: 1;
}

.line-attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1.5px solid var(--brand);
  border-radius: 4px;
  color: var(--brand);
  background: #fff;
  cursor: pointer;
  font-size: 14px;
  flex-shrink: 0;
  transition: background 0.12s;
}

.line-attach-btn:hover { background: #edf8f5; }

/* existing attachments in document view */
.att-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  font-size: 12px;
  color: var(--brand);
  text-decoration: none;
  background: #fff;
}

.att-link:hover { background: #edf8f5; }

/* ── Searchable Material Combobox ────────────────────────────────────────── */
.mat-search-cell { position: relative; min-width: 200px; }

.mat-search-wrap {
  position: relative;
  width: 100%;
}

.line-mat-search {
  width: 100%;
  min-height: 30px;
  padding: 4px 8px;
  border: 1.5px solid var(--line);
  border-radius: 4px;
  font-size: 12.5px;
  background: #fff;
  transition: border-color 0.12s;
}

.line-mat-search:focus {
  outline: none;
  border-color: var(--brand);
  background: #fff;
}

.mat-dropdown {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  min-width: 320px;
  background: #fff;
  border: 1.5px solid var(--brand);
  border-radius: 0 0 6px 6px;
  max-height: 220px;
  overflow-y: auto;
  z-index: 9999;
  box-shadow: 0 6px 20px rgba(15, 91, 79, 0.18);
}

.mat-dd-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 12px;
  cursor: pointer;
  font-size: 12.5px;
  border-bottom: 1px solid #f0f4f2;
  transition: background 0.08s;
}

.mat-dd-item:hover,
.mat-dd-item:focus {
  background: #edf8f5;
}

.mat-dd-item:last-child { border-bottom: none; }

.mat-dd-code {
  flex-shrink: 0;
  font-weight: 700;
  color: var(--brand);
  font-size: 11.5px;
  min-width: 58px;
}

.mat-dd-name {
  flex: 1;
  color: var(--ink);
}

.mat-dd-unit {
  flex-shrink: 0;
  color: var(--muted);
  font-size: 11px;
}

.mat-dd-custom .mat-dd-code { color: var(--muted); }
.mat-dd-custom .mat-dd-name { color: var(--muted); font-style: italic; }

.mat-dropdown mark {
  background: #fff3a0;
  border-radius: 2px;
  padding: 0 1px;
  font-style: normal;
}

/* ── Requisition picker ──────────────────────────────────────────────────── */
.po-req-picker {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #f0f8f5;
  border: 1px dashed var(--brand);
  border-radius: 6px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.po-req-picker-label {
  font-weight: 600;
  font-size: 12.5px;
  color: var(--brand);
  white-space: nowrap;
}

.po-req-picker select {
  flex: 1;
  min-width: 220px;
  min-height: 36px;
}

.po-req-picker-hint {
  font-size: 11.5px;
  color: var(--muted);
}

/* ── PO Signature boxes ──────────────────────────────────────────────────── */
.po-sig-box {
  min-width: 200px;
  text-align: center;
  font-size: 11.5px;
}

.po-sig-space {
  min-height: 52px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  padding-bottom: 4px;
}

.po-sig-underline {
  border-bottom: 1px solid #333;
  margin-bottom: 4px;
}

.po-sig-label {
  font-weight: 600;
  font-size: 12px;
  margin-bottom: 3px;
}

.po-sig-date-line {
  color: var(--muted);
  font-size: 11px;
}

/* ── PO form grid ───────────────────────────────────────────────────────── */
.po-form-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  align-items: end;
}

.po-form-title {
  grid-column: 1 / -1;
  font-weight: 700;
  font-size: 14px;
  color: var(--brand);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.po-line-table th,
.po-line-table td {
  padding: 5px 7px;
  vertical-align: middle;
}

.po-line-table input,
.po-line-table select {
  min-height: 32px;
  border-color: transparent;
  background: transparent;
  padding: 4px 6px;
}

.po-line-table input:focus,
.po-line-table select:focus {
  outline: 1px solid var(--brand);
  background: #fff;
}

.po-summary {
  text-align: right;
  font-size: 13px;
  line-height: 1.8;
}

.po-summary .grand { font-weight: 700; font-size: 15px; color: var(--brand); }

/* ── PO status badges ────────────────────────────────────────────────────── */
.sb-draft          { color: #555; background: #eee; }
.sb-confirmed      { color: #1a5fa8; background: #deeaf8; }
.sb-partial        { color: #7a4500; background: #fde8c8; }
.sb-received       { color: var(--brand); background: #edf8f5; }
.sb-cancelled      { color: #68736f; background: #f0f2f0; }

/* ── PO Print Sheet ──────────────────────────────────────────────────────── */
.po-hdr-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--ink);
}

.po-number-label { font-weight: 700; font-size: 13px; }
.po-number-val   { font-size: 16px; font-weight: 700; margin: 0 8px; }
.po-ref-note     { font-size: 11px; color: var(--red); }
.po-doc-title    { font-size: 15px; font-weight: 700; }

.po-dates-row {
  display: flex;
  gap: 32px;
  margin-bottom: 8px;
  font-size: 12px;
}

.po-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 16px;
  margin-bottom: 8px;
  font-size: 11.5px;
  line-height: 1.7;
}

.po-buyer, .po-supplier {
  border: 1px solid #ccc;
  padding: 8px 10px;
}

.po-credit { float: right; }

.po-items-table {
  width: 100%;
  min-width: unset;
  border-collapse: collapse;
  margin-bottom: 8px;
  font-size: 11px;
}

.po-items-table th,
.po-items-table td {
  border: 1px solid #999;
  padding: 4px 6px;
  vertical-align: middle;
}

.po-items-table th {
  background: #f0f0f0;
  color: #111;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
  border-bottom: 1px solid #999;
}

.po-items-table td { background: #fff; }

.po-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
  font-size: 11.5px;
}

.po-footer-left { flex: 1; display: flex; flex-direction: column; gap: 8px; }

.po-delivery { line-height: 1.8; }
.po-delivery strong { font-size: 12px; }

.po-payment {
  border: 1px solid #ccc;
  padding: 8px 10px;
  line-height: 1.7;
}
.po-payment strong { font-size: 12px; }

.po-payment-options {
  display: flex;
  gap: 18px;
  margin: 4px 0;
}
.po-pay-opt { display: inline-flex; align-items: center; gap: 5px; }
.po-pay-radio {
  display: inline-block;
  width: 11px;
  height: 11px;
  border: 1.5px solid #333;
  border-radius: 50%;
}
.po-pay-opt.selected .po-pay-radio { background: #333; }
.po-pay-opt.selected { font-weight: 700; }

.po-payment-bank {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 4px;
}

.po-totals { min-width: 280px; }
.po-total-row {
  display: flex;
  justify-content: space-between;
  padding: 2px 0;
  border-bottom: 1px solid #eee;
}
.po-total-grand { font-weight: 700; font-size: 13px; border-top: 2px solid #333; }

.po-note {
  font-size: 11px;
  color: var(--red);
  font-weight: 600;
  margin-bottom: 14px;
  line-height: 1.6;
}

.po-sigs {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  font-size: 11.5px;
  text-align: center;
}

.po-sigs > div { min-width: 220px; }
.po-sig-line { letter-spacing: 1px; margin-bottom: 4px; }

/* ── Print Sheet (ps-*) ──────────────────────────────────────────────────── */
.ps-toolbar {
  max-width: 794px;
  margin: 0 auto 12px;
}

.print-sheet {
  max-width: 794px;    /* A4 width at 96dpi */
  margin: 0 auto;
  padding: 20px 24px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 12px;
  font-family: Tahoma, "Noto Sans Thai", Arial, sans-serif;
  color: #111;
}

/* Header */
.ps-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 10px;
}

.ps-logo-box {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 72px;
}

.ps-logo-img {
  max-width: 72px;
  max-height: 72px;
  width: auto;
  height: auto;
  object-fit: contain;
}

.ps-logo-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.ps-logo-mark {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 2px solid var(--brand);
  border-radius: 4px;
  color: var(--brand);
  font-weight: 700;
  font-size: 14px;
}

.ps-logo-sub {
  font-size: 8px;
  color: var(--brand);
  font-weight: 700;
  letter-spacing: 0.5px;
}

.ps-logo-upload-btn {
  cursor: pointer;
}

.ps-company-info {
  flex: 1;
  display: grid;
  gap: 2px;
  text-align: center;
}

.ps-company-info strong {
  font-size: 15px;
}

.ps-company-info span {
  font-size: 11px;
  color: #333;
}

/* Title box */
.ps-title-box {
  display: grid;
  gap: 2px;
  padding: 7px 12px;
  margin-bottom: 6px;
  border: 2px solid var(--brand);
  background: #e6f4f1;
  text-align: center;
}

.ps-title-box strong {
  font-size: 14px;
}

.ps-title-box span {
  font-size: 12px;
}

/* Checkbox area */
/* เก็บ class เดิมไว้สำหรับ backward compat */
.ps-cb-area { border: 1px solid #888; margin-bottom: 0; }
.ps-cb-row  { display: flex; align-items: stretch; border-bottom: 1px solid #ccc; }
.ps-cb-row:last-child { border-bottom: none; }
.ps-cb-group { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 14px; padding: 5px 10px; flex: 1; }
.ps-cb-divider { flex: 0 0 auto; min-width: 200px; border-left: 1px solid #ccc; }
.ps-cb-indent { padding-left: 28px; }

/* ── section header สำหรับ 2 group ── */
.ps-cb-section-hdr {
  background: #e6f4f1;
  padding: 4px 10px;
  font-weight: 700;
  font-size: 11px;
  color: var(--brand);
  border-bottom: 1px solid #aaa;
  border-top: 1px solid #aaa;
}

.ps-cb-full {
  padding: 5px 12px;
  line-height: 2;
}

/* ── ใหม่: table layout ตรงกับต้นฉบับ ── */
.ps-cb-table {
  width: 100%;
  min-width: unset !important;
  border-collapse: collapse;
  border: 1px solid #888;
  margin-bottom: 0;
}

.ps-cb-table tr { border-bottom: 1px solid #ccc; }
.ps-cb-table tr:last-child { border-bottom: none; }

.ps-cb-left {
  padding: 5px 10px;
  vertical-align: middle;
  font-size: 11px;
  white-space: nowrap;
}

.ps-cb-right {
  padding: 5px 10px;
  vertical-align: middle;
  font-size: 11px;
  border-left: 1px solid #ccc;
  width: 210px;
  white-space: nowrap;
}

/* ไม่ให้ print CSS ขัดกับ table */
@media print {
  .ps-cb-table { min-width: unset !important; }
  .ps-cb-table th, .ps-cb-table td {
    border: none;
    background: transparent;
    text-transform: none;
    letter-spacing: 0;
    font-weight: normal;
    font-size: 11px;
    color: #111;
    padding: 4px 8px;
  }
}

.ps-cb-label {
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  margin-right: 6px;
}

/* Checkbox item */
.ps-cb {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  white-space: nowrap;
  cursor: default;
}

.ps-cb::before {
  content: "□";
  font-size: 13px;
  line-height: 1;
  color: #444;
}

.ps-cb.checked::before {
  content: "☑";
  color: var(--brand);
  font-size: 13px;
}

/* Document type row */
.ps-type-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 5px 10px;
  border: 1px solid #888;
  border-top: none;
  margin-bottom: 6px;
}

.ps-type-row strong {
  font-size: 12px;
  white-space: nowrap;
}

/* Items table */
.ps-table-wrap {
  overflow: visible;
  margin-bottom: 4px;
}

.ps-items-table {
  width: 100%;
  min-width: unset;
  border-collapse: collapse;
  font-size: 11.5px;
}

.ps-items-table th,
.ps-items-table td {
  border: 1px solid #888;
  padding: 4px 6px;
  vertical-align: middle;
  background: #fff;
}

.ps-items-table th {
  background: #fff;
  color: #111;
  font-weight: 700;
  text-align: center;
  font-size: 11.5px;
}

.ps-items-table td {
  height: 26px;
}

.ps-col-no    { width: 5%;  text-align: center; }
.ps-col-code  { width: 12%; }
.ps-col-qty   { width: 9%;  text-align: center; }
.ps-col-unit  { width: 12%; text-align: center; }
.ps-col-remark{ width: 20%; }

/* หมายเหตุ */
.ps-remark-area {
  margin: 4px 0 6px;
}

.ps-remark-title {
  margin: 0 0 1px;
  font-weight: 700;
  font-size: 12px;
  text-decoration: underline;
}

.ps-remark-body {
  margin: 0;
  padding-left: 16px;
  font-size: 11px;
  color: #c0392b;
}

/* หมายเหตุจากขั้นตอนตรวจสอบ/อนุมัติ/จ่ายของ */
.ps-workflow-remarks {
  margin: 2px 0 0;
  padding-left: 16px;
  font-size: 11px;
  color: #1a1a1a;
}
.ps-workflow-remarks div { margin: 1px 0; }
.ps-workflow-remarks:empty { display: none; }

/* Approval title */
.ps-approval-title {
  margin: 4px 0 4px;
  font-weight: 700;
  font-size: 12px;
  text-decoration: underline;
}

/* ── Stock Balance Report print ──────────────────────────────────────────── */
@media print {
  body.print-stock-report .sidebar,
  body.print-stock-report .topbar,
  body.print-stock-report .notice,
  body.print-stock-report .no-print { display: none !important; }

  body.print-stock-report .view { display: none !important; }

  body.print-stock-report #stock-report {
    display: block !important;
    padding: 0 !important;
  }

  body.print-stock-report .sr-print-header { display: block !important; }

  body.print-stock-report .shell {
    margin: 0 !important; padding: 0 !important; background: #fff !important;
  }

  body.print-stock-report #sr-table { font-size: 9.5px; min-width: unset !important; }
  body.print-stock-report #sr-table th,
  body.print-stock-report #sr-table td { padding: 3px 5px; }

  /* ช่องนับจริงและหมายเหตุ — แสดงเส้นสำหรับกรอกมือ */
  body.print-stock-report .sr-physical-input,
  body.print-stock-report .sr-note-input {
    border: none;
    border-bottom: 1px solid #888;
    background: transparent;
    width: 100%;
  }

  body.print-stock-report .sr-diff-cell,
  body.print-stock-report .sr-diff-col { background: transparent; }

  body.print-stock-report .sr-signatures { display: flex !important; }

  body.print-stock-report * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* ── Stock Card print — body.print-stock-card ───────────────────────────── */
@media print {
  body.print-stock-card .sidebar,
  body.print-stock-card .topbar,
  body.print-stock-card .notice { display: none !important; }

  body.print-stock-card .view { display: none !important; }

  body.print-stock-card #materials {
    display: block !important;
    padding: 0 !important;
    animation: none !important;
  }

  body.print-stock-card #materials > *:not(#stock-history-panel) {
    display: none !important;
  }

  body.print-stock-card #stock-history-panel {
    display: block !important;
    border: none !important;
    animation: none !important;
  }

  body.print-stock-card .sh-controls { display: none !important; }

  body.print-stock-card .shell {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  body.print-stock-card .sh-table {
    font-size: 10.5px;
    min-width: unset !important;
  }

  body.print-stock-card .sh-table th,
  body.print-stock-card .sh-table td { padding: 4px 7px; }

  body.print-stock-card * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* Signature table */
.ps-sig-table {
  width: 100%;
  min-width: unset;
  border-collapse: collapse;
  font-size: 11.5px;
}

.ps-sig-table td {
  border: 1px solid #888;
  text-align: center;
  background: #fff;
  width: 25%;
}

.ps-sig-nums-row td {
  border: none;
  padding: 2px 4px 0;
}

.ps-sig-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
}

.ps-sig-roles-row td {
  padding: 5px 6px;
  font-weight: 700;
  font-size: 11.5px;
  border-bottom: none;
}

.ps-sig-body-row td {
  height: 64px;
  padding: 6px;
  vertical-align: middle;
  font-size: 12px;
  border-top: none;
}

.ps-sig-date-row td {
  padding: 5px 8px;
  font-size: 11px;
  text-align: left;
}

/* ── Notice variants ─────────────────────────────────────────────────────── */
.notice-success {
  border-color: #6abda8;
  border-left-color: var(--brand);
  background: #edf8f5;
}

.notice-error {
  border-color: #e0a09b;
  border-left-color: var(--red);
  background: #fdf2f1;
}

.notice-info {
  border-color: #e1c27a;
  border-left-color: var(--gold);
  background: #fff8e8;
}

/* ── Status badges ───────────────────────────────────────────────────────── */
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.sb-draft      { color: #5c6b65; background: #e8eeec; }
.sb-submitted  { color: #1a5fa8; background: #deeaf8; }
.sb-checked    { color: #8a6100; background: #fdf0cc; }
.sb-approved   { color: var(--brand); background: #edf8f5; }
.sb-issued     { color: #0d4c43; background: #c6eae2; }
.sb-rejected   { color: #a7372f; background: #fdecea; }
.sb-cancelled  { color: #68736f; background: #f0f2f0; }

/* ── Table utilities ─────────────────────────────────────────────────────── */
.td-empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.text-muted { color: var(--muted); }
.text-red   { color: var(--red);   }

.date-hint {
  display: block;
  margin-top: 3px;
  font-size: 11px;
  color: var(--brand);
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* ── Requisition line last cell ──────────────────────────────────────────── */
.td-line-last {
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  padding: 0 6px;
}

.td-line-last input {
  flex: 1;
  min-width: 0;
  border-color: transparent;
  background: transparent;
  min-height: 32px;
}

.btn-del-line {
  flex-shrink: 0;
  min-height: 26px;
  padding: 2px 7px;
  border-color: #dca9a5;
  color: var(--red);
  background: #fff0ef;
  font-size: 11px;
}

.btn-del-line:hover {
  background: #fdecea;
}

/* ── Doc link ────────────────────────────────────────────────────────────── */
.doc-link {
  color: var(--brand-2);
  font-weight: 600;
  text-decoration: none;
}

.doc-link:hover { text-decoration: underline; }

@media print {
  @page {
    size: 210mm 297mm;   /* explicit portrait: กว้าง < สูง = portrait เสมอ */
    margin: 10mm;
  }

  /* บังคับ html/body ให้ไม่เกิน 210mm — ป้องกัน browser auto-rotate */
  html {
    width: 210mm !important;
    max-width: 210mm !important;
    overflow-x: hidden !important;
  }

  body {
    width: 210mm !important;
    max-width: 210mm !important;
    overflow-x: hidden !important;
    background: #fff;
  }

  /* ── บังคับทุก container ให้ fit portrait ── */
  .shell,
  .view.active,
  .print-sheet,
  #po-sheet {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
  }

  /* ── table: ห้ามเกินหน้า ── */
  table {
    min-width: unset !important;
    width: 100% !important;
    max-width: 100% !important;
    table-layout: auto !important;
  }

  /* ── ซ่อน elements ที่ไม่ต้องพิมพ์ ── */
  .sidebar,
  .topbar,
  .notice,
  .ps-toolbar,
  .no-print,
  .po-req-picker,
  .doc-tabs,
  .doc-type-filters,
  .section-head,
  .row-actions,
  .form-actions,
  .line-actions,
  #grn-panel,
  #po-form,
  #po-table-wrap,
  #supplier-form,
  .btn-add-po-line,
  .btn-reload-po {
    display: none !important;
  }

  /* ── ซ่อน views ทั้งหมด ── */
  .view {
    display: none !important;
    padding: 0 !important;
  }

  /* ── แสดงเฉพาะ view ที่ active อยู่ตอนนี้ ── */
  .view.active {
    display: block !important;
    padding: 0 !important;
    animation: none !important;
  }

  .shell {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }

  /* ── Stock History Print ── handled by body.print-stock-card below ── */

  /* ── OC Requisition print sheet ── */
  .print-sheet {
    max-width: 100%;
    border: none;
    box-shadow: none;
    padding: 0;
  }

  /* ── PO print sheet ── */
  #po-sheet {
    max-width: 100%;
    border: none;
    box-shadow: none;
    padding: 0;
    font-size: 10px;       /* ลดจาก 11px เพื่อให้ fit A4 */
  }

  /* ลด spacing ทุกส่วนในหน้า PO */
  .po-hdr-row       { margin-bottom: 3px; padding-bottom: 4px; }
  .po-dates-row     { margin-bottom: 5px; }
  .po-parties       { margin-bottom: 5px; font-size: 10px; }
  .po-buyer,
  .po-supplier      { padding: 5px 8px; }
  .po-items-table   { margin-bottom: 5px; font-size: 10px; }
  .po-items-table th,
  .po-items-table td { padding: 3px 5px; }
  .po-items-table td { height: 20px; }
  .po-footer        { margin-bottom: 5px; font-size: 10px; }
  .po-payment       { padding: 5px 8px; }
  .po-note          { margin-bottom: 8px; font-size: 9.5px; line-height: 1.4; }
  .po-sigs          { margin-top: 10px; }
  .po-sig-box       { min-width: 160px; }
  .po-sig-space     { min-height: 40px; font-size: 11px; }
  .po-total-grand   { font-size: 12px; }
  .po-number-val    { font-size: 14px; }

  /* ไม่ตัด section ข้ามหน้า */
  .po-footer  { page-break-inside: avoid; }
  .po-totals  { page-break-inside: avoid; }
  .po-sigs    { page-break-inside: avoid; }
  .po-note    { page-break-inside: avoid; }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}
