/* TH Sarabun New for the quotation form: installed copy first, bundled copy otherwise */
@font-face { font-family: "TH Sarabun New"; font-weight: 400; font-style: normal; src: local("TH Sarabun New"), local("THSarabunNew"), url("assets/fonts/THSarabunNew.ttf") format("truetype"); }
@font-face { font-family: "TH Sarabun New"; font-weight: 700; font-style: normal; src: local("TH Sarabun New Bold"), local("THSarabunNew-Bold"), url("assets/fonts/THSarabunNew-Bold.ttf") format("truetype"); }
@font-face { font-family: "TH Sarabun New"; font-weight: 400; font-style: italic; src: local("TH Sarabun New Italic"), local("THSarabunNew-Italic"), url("assets/fonts/THSarabunNew-Italic.ttf") format("truetype"); }
@font-face { font-family: "TH Sarabun New"; font-weight: 700; font-style: italic; src: local("TH Sarabun New Bold Italic"), local("THSarabunNew-BoldItalic"), url("assets/fonts/THSarabunNew-BoldItalic.ttf") format("truetype"); }

:root {
  --bg: #eef2f6;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #667085;
  --line: #d9e0ea;
  --nav: #263746;
  --nav-2: #1f2d3a;
  --brand: #158b9b;
  --brand-dark: #0f6773;
  --accent: #f5a623;
  --good: #16875d;
  --bad: #c64646;
  --warn: #a76509;
  --shadow: 0 12px 28px rgba(31, 41, 51, 0.08);
  --pdf-margin-top: 6mm;
  --pdf-margin-right: 6mm;
  --pdf-margin-bottom: 6mm;
  --pdf-margin-left: 6mm;
  --pdf-paper-width: 198mm;
  --pdf-paper-height: 285mm;
  font-family: "Segoe UI", Tahoma, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

/* The hidden attribute always wins over component display rules */
[hidden] {
  display: none !important;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 18px 14px;
  color: #edf6f8;
  background: linear-gradient(180deg, var(--nav), var(--nav-2));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.brand-mark {
  width: 50px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: #14303a;
  background: var(--accent);
  font-weight: 900;
  letter-spacing: 0;
}

.brand strong,
.brand span,
.company-box small,
.company-box span {
  display: block;
}

.brand span,
.company-box small,
.company-box span,
.menu p {
  color: #b9cbd3;
  font-size: 12px;
}

.company-switcher {
  margin: 14px 2px 10px;
  padding: 11px 13px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: default;
}

.company-switcher strong {
  display: block;
  font-size: 14px;
  color: #fff;
  margin-bottom: 2px;
}

.company-switcher span {
  display: block;
  font-size: 11px;
  color: #b9cbd3;
}

.menu {
  display: grid;
  gap: 3px;
  margin-top: 8px;
}

/* Top-level items (หน้าแรก / ตั้งค่า / คู่มือ) */
.nav-item {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 0;
  border-radius: 8px;
  padding: 9px 11px;
  color: #e8f1f4;
  background: transparent;
  text-align: left;
  font-size: 15px;
  cursor: pointer;
}

.nav-ico {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.09);
  flex: 0 0 auto;
  font-size: 15px;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(21, 139, 155, 0.45);
}

.nav-item.active {
  font-weight: 700;
}

/* Collapsible group header */
.nav-group-head {
  width: 100%;
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 11px;
  border: 0;
  border-radius: 8px;
  padding: 9px 11px;
  color: #e8f1f4;
  background: transparent;
  text-align: left;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.nav-group-head:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-caret {
  margin-left: auto;
  opacity: 0.6;
  transition: transform 0.2s ease;
  font-size: 18px;
  line-height: 1;
}

.nav-group.open > .nav-group-head {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}

.nav-group.open > .nav-group-head .nav-caret {
  transform: rotate(90deg);
  opacity: 0.9;
}

/* Sub-items (hidden until group open) */
.nav-sub {
  display: none;
  margin: 2px 0 6px 34px;
  padding-left: 10px;
  border-left: 2px solid rgba(255, 255, 255, 0.14);
  gap: 2px;
}

.nav-group.open > .nav-sub {
  display: grid;
}

.nav-sub .nav-item {
  min-height: 36px;
  padding: 7px 11px;
  font-size: 14px;
  color: #cfe0e6;
}

.nav-sub .nav-item.active {
  color: #fff;
}

.workspace {
  min-width: 0;
  padding: 22px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
}

.page-heading p,
h1,
h2,
p {
  margin-top: 0;
}

.page-heading p {
  margin-bottom: 4px;
  color: var(--brand-dark);
  font-size: 13px;
  font-weight: 800;
}

h1 {
  margin-bottom: 0;
  font-size: 29px;
}

h2 {
  margin-bottom: 4px;
  font-size: 18px;
}

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

.search {
  width: min(420px, 36vw);
  height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
}

/* Search date range next to the top search — only on บิลซื้อ */
.search-range {
  display: none;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}

body[data-view="purchases"] .search-range {
  display: flex;
}

.search-range .dmy-date {
  width: 140px;
}

.search-range input[type="date"] {
  width: 140px;
  height: 40px;
  padding: 0 10px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.search-range > span {
  color: var(--muted);
}

/* Totals for the current search on บิลซื้อ */
.purchase-search-summary {
  margin: 14px 0 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f4fafb;
}

.pss-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
  margin-bottom: 8px;
}

.pss-figures {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px 16px;
}

.pss-figures div {
  display: grid;
  gap: 2px;
}

.pss-figures small {
  color: var(--muted);
}

.pss-figures b {
  font-size: 17px;
}

.primary-button,
.secondary-button,
.icon-button {
  min-height: 40px;
  border-radius: 7px;
  border: 1px solid transparent;
}

.primary-button {
  padding: 0 16px;
  color: white;
  background: var(--brand);
  font-weight: 800;
}

.primary-button:hover {
  background: var(--brand-dark);
}

.secondary-button {
  padding: 0 14px;
  color: var(--brand-dark);
  background: #e8f6f8;
  border-color: #c9e4e9;
  font-weight: 700;
}

.icon-button {
  width: 40px;
  background: white;
  border-color: var(--line);
}

.mobile-menu {
  display: none;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

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

@media (min-width: 1121px) {
  .summary-strip.summary-strip-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.summary-strip article,
.panel,
.module-card,
.paper {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.summary-strip article {
  padding: 16px;
}

.summary-strip span,
.summary-strip small,
.panel-header p,
.panel > p {
  color: var(--muted);
}

.summary-strip strong {
  display: block;
  margin: 7px 0;
  font-size: clamp(17px, 1.7vw, 23px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.3px;
  font-variant-numeric: tabular-nums;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(280px, 0.8fr);
  gap: 12px;
  margin-top: 12px;
}

.panel {
  padding: 17px;
  margin-top: 12px;
}

.dashboard-grid .panel {
  margin-top: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 13px;
}

.legend {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.sales-dot,
.expense-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.sales-dot {
  background: var(--brand);
}

.expense-dot {
  background: var(--accent);
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.module-card {
  min-height: 94px;
  padding: 16px;
  text-align: left;
  color: var(--ink);
}

.module-card strong,
.module-card span {
  display: block;
}

.module-card strong {
  margin-bottom: 8px;
  font-size: 18px;
}

.module-card span {
  color: var(--muted);
  line-height: 1.45;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th,
td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: #f7f9fc;
  font-size: 13px;
}

.number {
  text-align: right;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
}

.badge.paid {
  color: #126344;
  background: #e5f6ee;
}

.badge.due {
  color: var(--warn);
  background: #fff2d9;
}

.badge.draft {
  color: #4d5968;
  background: #eef1f6;
}

.badge.approved {
  color: #105f68;
  background: #e4f6f8;
}

.badge.cancelled {
  color: #6b2fa3;
  background: #f1e8fb;
}

/* Sales list: taken to the next step (quotation → invoice, invoice → receipt) = green;
   cancelled job (quotation kept as a record) = purple text */
#salesTable tr.row-done td {
  background: #e9f7ef;
}

#salesTable tr.row-done td:first-child strong {
  color: #126344;
}

#salesTable tr.row-cancelled td {
  color: #6b2fa3;
}

#salesTable tr.row-cancelled td:first-child strong {
  color: #6b2fa3;
}

.mini-button.cancel-button {
  color: #6b2fa3;
  border-color: #d9c4f0;
}

.segmented .segmented-cancelled.active {
  color: #6b2fa3;
}

.badge.bad {
  color: var(--bad);
  background: #fde8e8;
}

.alert-list {
  display: grid;
  gap: 10px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.alert-list li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfe;
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(5, minmax(190px, 1fr));
  gap: 10px;
  overflow-x: auto;
}

.pipeline-column {
  min-height: 260px;
  padding: 10px;
  border-radius: 8px;
  background: #f7f9fc;
  border: 1px solid var(--line);
}

.pipeline-column h3 {
  margin: 0 0 10px;
  font-size: 15px;
}

.doc-card {
  display: grid;
  gap: 6px;
  padding: 11px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(420px, 0.9fr) minmax(360px, 1.1fr);
  gap: 12px;
}

.sales-tabbar,
.inventory-tabbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 5px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fc;
}

.sales-tabbar button,
.inventory-tabbar button {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 0 14px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.sales-tabbar button.active,
.inventory-tabbar button.active {
  color: var(--brand-dark);
  background: white;
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.08);
}

.count-badge {
  display: inline-grid;
  min-width: 26px;
  min-height: 26px;
  place-items: center;
  margin-left: 6px;
  padding: 0 7px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: #e8f6f8;
  font-size: 13px;
  vertical-align: middle;
}

.inventory-tabbar span {
  display: inline-grid;
  min-width: 24px;
  min-height: 24px;
  place-items: center;
  margin-left: 6px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: #e8f6f8;
  font-size: 12px;
}

.sales-tab-panel {
  display: none;
}

.sales-tab-panel.active {
  display: block;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 11px;
}

.form-grid label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.form-grid input,
.form-grid select,
.inline-form input,
.inline-form select,
.line-table input {
  min-width: 0;
  height: 38px;
  padding: 0 11px;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
}

/* Date boxes: native input underneath (calendar + value), dd/mm/yyyy text drawn on top (see enhanceDateInput). */
.dmy-date {
  position: relative;
  display: block;
  min-width: 0;
}

.dmy-date > input[type="date"] {
  width: 100%;
  box-sizing: border-box;
}

.dmy-date > input[type="date"]::-webkit-datetime-edit {
  opacity: 0;
}

.dmy-date-text {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 32px;
  display: flex;
  align-items: center;
  overflow: hidden;
  white-space: nowrap;
  color: var(--ink);
  pointer-events: none;
}

.dmy-date-text.is-empty {
  color: var(--muted);
}

.form-grid textarea[name="address"] {
  min-width: 0;
  min-height: 38px;
  padding: 8px 11px;
  font: inherit;
  font-weight: 400;
  line-height: 1.4;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
  resize: vertical;
}

/* Address on the quote: Enter = new line; words between spaces never split */
/* Sales item table: item number in front of the drag handle */
.line-no-cell {
  display: flex;
  align-items: center;
  gap: 4px;
}

.line-no {
  min-width: 18px;
  text-align: right;
  font-weight: 700;
  color: var(--muted, #5b6b73);
}

/* Contacts: entity type (ภ.ง.ด.53 / 3) + VAT registration */
.contact-tax-col {
  min-width: 190px;
}

.contact-tax {
  display: grid;
  gap: 4px;
}

.contact-tax select {
  width: 100%;
  font-size: 12px;
  padding: 4px 6px;
}

#previewAddress .nobr,
#ffAddress .nobr {
  white-space: nowrap;
}

/* Customer name, address, tax ID and item descriptions in bold on the plain (no form) layout too */
#previewCustomer,
#previewAddress,
#previewTaxId,
.quote-table .description-cell span {
  font-weight: 700;
}

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

.span-3 {
  grid-column: 1 / -1;
}

.form-row-4 {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 11px;
}

.form-row-4 label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.line-editor {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fc;
}

.line-editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.line-editor-header strong,
.line-editor-header span {
  display: block;
}

.line-editor-header span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
}

.compact table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
}

.line-editor .compact {
  max-height: none;
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.line-editor .compact thead th {
  position: static;
  z-index: 5;
}

.line-table th,
.line-table td {
  padding: 6px;
}

.line-table input {
  width: 100%;
  height: 34px;
  padding: 0 8px;
  background: white;
}

.line-table th:nth-child(1),
.line-table td:nth-child(1) {
  width: 42px;
}

.line-table th:nth-child(2),
.line-table td:nth-child(2) {
  width: 8%;
}

.line-table th:nth-child(3),
.line-table td:nth-child(3) {
  width: 18%;
}

/* Description gets the most room: it often holds long equipment lists */
.line-table th:nth-child(4),
.line-table td:nth-child(4) {
  width: 27%;
}

.line-table th:nth-child(5),
.line-table td:nth-child(5),
.line-table th:nth-child(6),
.line-table td:nth-child(6),
.line-table th:nth-child(7),
.line-table td:nth-child(7) {
  width: 6%;
}

.line-table th:nth-child(8),
.line-table td:nth-child(8),
.line-table th:nth-child(9),
.line-table td:nth-child(9) {
  width: 9%;
}

.line-table th:nth-child(10),
.line-table td:nth-child(10) {
  width: 76px;
}

.product-cell,
.lookup-field {
  position: relative;
}

.product-cell {
  min-width: 0;
}

.product-picker,
.lookup-picker {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 20;
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  box-shadow: var(--shadow);
}

.lookup-picker {
  top: calc(100% - 1px);
}

/* Product list is wider than the narrow code/name cells so names aren't cut off */
.product-picker {
  right: auto;
  width: max(100%, 420px);
  max-height: 280px;
}

.product-option.active,
.lookup-option.active {
  background: #dff2f4;
  box-shadow: inset 3px 0 0 var(--brand);
}

.product-picker:empty,
.lookup-picker:empty {
  display: none;
}

.product-option,
.lookup-option {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  border: 0;
  border-bottom: 1px solid var(--line);
  padding: 8px 10px;
  background: white;
  text-align: left;
}

.lookup-option {
  grid-template-columns: 1fr auto;
}

.product-option:hover,
.lookup-option:hover,
.add-option:hover {
  background: #e8f6f8;
}

.product-option code {
  color: var(--brand-dark);
  font-weight: 800;
}

.product-option small,
.lookup-option small {
  color: var(--muted);
}

.add-option {
  color: var(--brand-dark);
  font-weight: 800;
}

/* Compact by default (one line, scrolls); drag the corner to enlarge — app.js shrinks it back on blur */
.line-table textarea.line-description {
  display: block;
  width: 100%;
  height: 34px;
  min-height: 34px;
  padding: 7px 8px;
  font: inherit;
  line-height: 1.35;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
  resize: vertical;
  overflow-y: auto;
  white-space: pre-wrap;
}

/* Description cell: the box plus a small ⤢ button that opens the large editor */
.line-desc-cell {
  position: relative;
}

.line-table .line-desc-cell textarea.line-description {
  padding-right: 30px;
}

.desc-expand {
  position: absolute;
  top: 4px;
  right: 14px;
  width: 24px;
  height: 24px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  color: var(--brand);
  background: white;
  border: 1px solid var(--line);
  border-radius: 5px;
  cursor: pointer;
}

.desc-editor-dialog {
  width: min(1100px, calc(100vw - 32px));
}

.desc-editor-body {
  padding: 8px 16px 12px;
}

.desc-editor-body textarea {
  display: block;
  width: 100%;
  height: min(62vh, 640px);
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  line-height: 1.5;
  tab-size: 8;
  white-space: pre-wrap;
  border: 1px solid var(--line);
  border-radius: 7px;
  resize: vertical;
}

/* Product/service name: one line by default, expands to full text on focus (app.js) */
.line-table textarea.line-name {
  display: block;
  width: 100%;
  height: 34px;
  min-height: 34px;
  padding: 7px 8px;
  font: inherit;
  line-height: 1.35;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 7px;
  resize: none;
  overflow: hidden;
  white-space: pre-wrap;
  word-break: break-word;
}

.line-table td {
  vertical-align: top;
}

.quote-table .description-cell span {
  white-space: pre-line;
}

/* Running totals under the sales item table */
.line-totals {
  display: grid;
  gap: 4px;
  width: min(360px, 100%);
  margin: 10px 0 0 auto;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  font-size: 14px;
}

.line-totals:empty {
  display: none;
}

.line-totals .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.line-totals .row.grand {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  font-size: 16px;
  color: var(--brand-dark);
}

/* Foreign-currency figures (prices are typed in THB, the document prints converted) */
.line-totals .row.grand + .row.fx {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--line);
}

.line-totals .row.fx {
  color: #1d4ed8;
}

.line-totals .row.fx.grand {
  border-top: 0;
  margin-top: 0;
  padding-top: 0;
}

.line-totals .row.fx.note {
  margin-top: 4px;
  font-size: 15px;
  font-weight: 700;
  color: #14532d; /* dark green: exchange rate stands out */
}

.line-totals .row.fx.note.warn {
  color: #b45309;
}

/* Heading rows in the line editor */
.line-heading-row td {
  background: #eef6f7;
}

.line-heading-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.line-heading-tag {
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  color: white;
  background: var(--brand);
  font-size: 12px;
  font-weight: 800;
}

.line-heading-cell input {
  flex: 1;
  font-weight: 800;
}

/* Heading rows in the printed document */
.quote-table .quote-heading-row td {
  height: auto;
  padding-top: 10px;
  padding-bottom: 2px;
}

.quote-table .quote-heading-row .description-cell strong {
  margin-bottom: 0;
  text-decoration: underline;
}

/* Note rows (หมายเหตุ / Remark / Note) in every printed document: the word and the text under it in navy, no number or amounts */
.quote-table .quote-note-row td,
.quote-table .quote-note-row td *,
.ff-table .ff-note-row td,
.ff-table .ff-note-row td * {
  color: #1f2f5c;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

/* No up/down spinners on number boxes anywhere in the line table */
.line-table input::-webkit-outer-spin-button,
.line-table input::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.line-table input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}

.line-table input[data-line-field="qty"],
.line-table input[data-line-field="days"],
.line-table input[data-line-field="price"] {
  text-align: right;
}

.line-table .line-total {
  font-weight: 800;
}

.small-icon-button {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.row-actions {
  display: flex;
  gap: 5px;
  align-items: center;
}

.save-catalog-button {
  color: var(--brand-dark);
  background: #e8f6f8;
  border-color: #c9e4e9;
  font-weight: 900;
}

.drag-handle {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: white;
  cursor: grab;
  font-weight: 900;
}

.line-table tr.dragging {
  opacity: 0.45;
}

.line-table tr.drag-over td {
  border-top: 2px solid var(--brand);
}

.action-stack {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

/* Documents list: compact single-line rows with horizontal scroll */
#salesTable td {
  white-space: nowrap;
  vertical-align: middle;
}

#salesTable td:nth-child(3) {
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.mini-button {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid #c9e4e9;
  border-radius: 7px;
  color: var(--brand-dark);
  background: #e8f6f8;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}

.danger-button {
  color: var(--bad);
  background: #fff5f5;
  border-color: #f4c7c7;
}

.edit-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
}

.edit-indicator span {
  color: var(--brand-dark);
  font-weight: 800;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr 1.2fr 190px 150px auto;
  gap: 10px;
  margin-bottom: 13px;
}

.document-preview {
  align-self: start;
  max-width: 980px;
}

.paper-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.paper {
  width: min(100%, 920px);
  min-height: 1280px;
  padding: 18px;
  background: #fff;
  color: #050505;
  font-family: Arial, "Segoe UI", Tahoma, sans-serif;
}

.quote-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 12px;
  align-items: start;
}

.quote-brand-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 12px;
  align-items: center;
}

.quote-logo {
  height: 82px;
  display: grid;
  place-items: center;
  border: 2px solid #888;
  color: #111;
  font-size: calc(44px * var(--logo-scale, 1));
  font-style: italic;
  font-weight: 900;
  letter-spacing: 0;
  white-space: nowrap; /* one line; app.js sets --logo-scale so the text fits */
  overflow: hidden;
}

.quote-company h2,
.quote-company h3 {
  margin: 0;
  line-height: 1.05;
  font-size: 28px;
  font-weight: 900;
}

.quote-company h3 {
  font-size: 26px;
}

.quote-company p {
  margin: 3px 0;
  font-size: 14px;
  line-height: 1.25;
}

.quote-title-box {
  display: grid;
  gap: 7px;
}

.quote-title-box > h2,
.quote-title-box > strong {
  display: block;
  margin: 0;
  text-align: center;
}

.quote-title-box > h2 {
  padding: 13px 12px 2px;
  border: 3px solid #111;
  border-bottom: 0;
  border-radius: 10px 10px 0 0;
  font-size: 24px;
}

.quote-title-box > strong {
  padding: 0 12px 13px;
  border: 3px solid #111;
  border-top: 0;
  border-radius: 0 0 10px 10px;
  font-size: 21px;
}

.quote-copy {
  display: flex;
  justify-content: space-between;
  color: #1826b8;
  font-weight: 800;
  padding: 0 6px;
}

.quote-copy span {
  color: #111;
}

.quote-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.quote-meta div {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  border: 2px solid #111;
  border-radius: 7px;
  padding: 6px 8px;
}

.quote-meta small,
.quote-box small,
.quote-event small {
  display: block;
  color: #222;
  font-size: 10px;
  line-height: 1;
}

.quote-meta strong {
  text-align: center;
  font-size: 15px;
  line-height: 1.2;
}

/* "November 7, 2026" is longer than the old dd/mm/yyyy — keep it on one line */
#previewDate,
#previewDocNo {
  white-space: nowrap;
}

.quote-info-grid {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
  gap: 4px;
  margin-top: 7px;
}

.quote-box {
  min-height: 150px;
  border: 2px solid #111;
  border-radius: 7px;
  padding: 12px;
}

.quote-box p {
  margin: 0 0 18px;
  font-size: 15px;
}

.quote-box strong {
  display: inline-block;
  min-width: 116px;
}

.contact-box strong {
  min-width: 126px;
}

.quote-event {
  min-height: 42px;
  margin-top: 4px;
  padding: 7px 9px;
  border: 3px solid #111;
  font-size: 17px;
}

.quote-event span {
  color: #7b1a1a;
  font-weight: 800;
}

.paper-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
}

.quote-table {
  table-layout: fixed;
}

.quote-table th,
.quote-table td {
  border: 2px solid #111;
  padding: 8px 9px;
  vertical-align: top;
  white-space: normal;
  color: #050505;
}

.quote-table th {
  text-align: center;
  font-size: 14px;
  background: white;
}

.quote-table th small {
  display: block;
  font-size: 10px;
}

.quote-table th:nth-child(1),
.quote-table td:nth-child(1) {
  width: 44px;
  text-align: center;
}

.quote-table th:nth-child(3),
.quote-table td:nth-child(3) {
  width: 105px;
  text-align: center;
}

.quote-table th:nth-child(4),
.quote-table td:nth-child(4),
.quote-table th:nth-child(5),
.quote-table td:nth-child(5),
.quote-table th:nth-child(6),
.quote-table td:nth-child(6) {
  width: 110px;
  text-align: right;
}

.quote-table th:nth-child(5),
.quote-table td:nth-child(5) {
  text-align: center;
  width: 100px;
}

.quote-table td {
  height: 48px;
  font-size: 15px;
}

/* No horizontal lines between items; keep column lines and the bottom edge. */
.quote-table tbody td {
  border-top: none;
  border-bottom: none;
}

.quote-table tbody tr:last-child td {
  border-bottom: 2px solid #111;
}

.quote-table .quote-filler-row td {
  height: 370px;
}

.quote-table .description-cell strong {
  display: block;
  margin-bottom: 5px;
  font-size: 16px;
}

.paper-total {
  grid-column: 2;
  grid-row: 1 / span 2;
  display: grid;
  grid-template-columns: 1fr auto;
  border: 2px solid #111;
  border-bottom: 0;
  align-self: start;
}

.paper-total span,
.paper-total strong {
  min-height: 36px;
  padding: 6px 9px;
  border-bottom: 2px solid #111;
  font-size: 16px;
}

.paper-total span {
  font-weight: 900;
}

.paper-total small {
  display: block;
  font-size: 10px;
}

.paper-total strong {
  min-width: 120px;
  text-align: right;
}

.quote-summary {
  display: grid;
  grid-template-columns: 1fr 310px;
  align-items: start;
}

.quote-summary > * {
  min-width: 0;
}

.said-total {
  grid-column: 1;
  display: grid;
  grid-template-columns: 150px 1fr;
  min-height: 36px;
  border-left: 2px solid #111;
  border-bottom: 2px solid #111;
}

.said-total strong,
.said-total span {
  padding: 7px 12px;
  background: #d9d9d9;
  font-size: 15px;
  font-weight: 900;
}

/* ===== Bank Accounts ===== */
.bank-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 14px;
}

.bank-card {
  display: grid;
  gap: 8px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, #f7fbfc);
  box-shadow: var(--shadow);
}

.bank-card.cash {
  background: linear-gradient(180deg, #fff, #fff8ec);
}

.bank-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bank-kind-pill {
  font-size: 12px;
  font-weight: 800;
  color: var(--brand-dark);
  background: #e8f6f8;
  padding: 3px 10px;
  border-radius: 999px;
}

.bank-card.cash .bank-kind-pill {
  color: var(--warn);
  background: #fff2d9;
}

.bank-card input {
  height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.bank-balance-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.bank-current-balance {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--brand-dark);
  color: white;
}

.bank-current-balance strong {
  font-size: 18px;
}

/* ===== Aging Report ===== */
.aging-tabbar {
  display: flex;
  gap: 6px;
  padding: 5px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fc;
}

.aging-tabbar button {
  min-height: 40px;
  border: 0;
  border-radius: 7px;
  padding: 0 16px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.aging-tabbar button.active {
  color: var(--brand-dark);
  background: white;
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.08);
}

.aging-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.aging-summary-card {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fbfcfe;
}

.aging-summary-card span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.aging-summary-card strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.aging-summary-card.warn {
  background: #fff8ec;
  border-color: #f5d99a;
}

.aging-summary-card.danger {
  background: #fff0f0;
  border-color: #f4b9b9;
}

.aging-summary-card.total {
  background: var(--brand-dark);
  color: white;
  border-color: var(--brand-dark);
}

.aging-summary-card.total span,
.aging-summary-card.total strong {
  color: white;
}

/* ===== Statement ===== */
.statement-controls select {
  height: 40px;
  min-width: 280px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.statement-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

/* ===== Settings: panel header with action button ===== */
.settings-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.settings-panel-header > div {
  flex: 1 1 auto;
}

.settings-panel-header h3 {
  margin: 0;
}

.settings-panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

/* ===== Backup actions ===== */
.backup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.backup-actions label.secondary-button {
  display: inline-flex;
  align-items: center;
  padding: 0 16px;
  cursor: pointer;
}

.backup-status {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  min-height: 18px;
}

.backup-status.ok {
  color: #126344;
  background: #e5f6ee;
  border: 1px solid #b0e0c8;
}

.backup-status.error {
  color: var(--bad);
  background: #fff0f0;
  border: 1px solid #f4b9b9;
}

.backup-status.info {
  color: var(--brand-dark);
  background: #e8f6f8;
}

/* ===== Login Dialog ===== */
.login-dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(31, 41, 51, 0.25);
}

.login-dialog::backdrop {
  background: rgba(31, 45, 58, 0.7);
  backdrop-filter: blur(4px);
}

.login-dialog form {
  display: grid;
  gap: 14px;
  padding: 28px 28px 24px;
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.login-brand h2 {
  margin: 0;
  font-size: 20px;
  color: var(--brand-dark);
}

.login-brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.login-dialog label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.login-dialog input {
  height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 15px;
}

.login-dialog input:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}

.login-error {
  padding: 10px 14px;
  border-radius: 7px;
  color: var(--bad);
  background: #fff0f0;
  border: 1px solid #f4b9b9;
  font-size: 13px;
  font-weight: 700;
}

.login-submit {
  margin-top: 4px;
  height: 46px;
  font-size: 15px;
}

/* ===== Password show/hide (eye) ===== */
.password-field {
  position: relative;
  display: block;
}

.password-field .pw-has-toggle {
  width: 100%;
  padding-right: 46px;
}

/* Edge has its own reveal button; one eye is enough */
.password-field input::-ms-reveal,
.password-field input::-ms-clear {
  display: none;
}

.password-toggle {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.password-toggle:hover {
  color: var(--brand-dark);
  background: #f1f4f8;
}

.password-toggle:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 0;
}

/* ===== Multi-user save notice ===== */
.sync-notice {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1000;
  width: min(440px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid #f0c36d;
  border-radius: 8px;
  background: #fff8e6;
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
  font-size: 14px;
}

.sync-notice.bad {
  border-color: #f3b4b4;
  background: #fdeeee;
}

.sync-notice.bad .sync-notice-head strong {
  color: var(--bad);
}

.sync-notice.ok {
  border-color: #b9e3cd;
  background: #eef9f3;
}

.sync-notice.ok .sync-notice-head strong {
  color: var(--good);
}

.sync-notice-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sync-notice ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.sync-notice li + li {
  margin-top: 4px;
}

.sync-notice-close {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.sync-notice-close:hover {
  background: rgba(0, 0, 0, 0.06);
}

/* ===== Topbar User Menu ===== */
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 8px 4px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.user-info {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.user-info strong {
  font-size: 13px;
  color: var(--ink);
}

.user-info small {
  font-size: 11px;
  color: var(--brand-dark);
  font-weight: 700;
  text-transform: uppercase;
}

.user-menu .icon-button {
  font-size: 16px;
  width: 36px;
  height: 36px;
  min-height: 36px;
  color: var(--bad);
}

.user-menu .icon-button:hover {
  background: #fff0f0;
  border-color: #f4b9b9;
}

/* ===== Audit Log ===== */
/* ===== System log (Settings → บันทึกระบบ) ===== */
.syslog-health {
  display: grid;
  gap: 6px;
  margin-bottom: 16px;
}

.syslog-line {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
  border: 1px solid var(--line);
  background: #f7f9fc;
}

.syslog-line.ok { color: var(--good); background: #eef9f3; border-color: #cdebdc; }
.syslog-line.warn { color: var(--warn); background: #fff6e6; border-color: #f3dcb2; }
.syslog-line.bad { color: var(--bad); background: #fdeeee; border-color: #f3c7c7; font-weight: 600; }
.syslog-line.info { color: var(--muted); }

.syslog-subhead {
  margin: 4px 0 8px;
}

.syslog-backup-table td {
  white-space: nowrap;
}

.syslog-none {
  color: var(--muted);
}

.syslog-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 18px 0 4px;
}

.syslog-filter {
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.syslog-filter.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.syslog-table td:last-child {
  white-space: normal;
  word-break: break-word;
  min-width: 280px;
}

.syslog-table details summary {
  cursor: pointer;
}

.syslog-pre {
  margin: 6px 0 0;
  padding: 8px;
  max-height: 240px;
  overflow: auto;
  border-radius: 6px;
  background: #f3f5f8;
  font-size: 12px;
  white-space: pre-wrap;
}

.audit-summary,
.user-list-info {
  margin: 8px 0 12px;
  color: var(--muted);
}

.change-password-status {
  margin-left: 12px;
  font-weight: 700;
  font-size: 13px;
}

.change-password-status.ok { color: var(--good); }
.change-password-status.error { color: var(--bad); }

/* ===== Coming soon banner ===== */
.coming-soon-banner {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  padding: 16px 18px;
  margin: 8px 0 16px;
  background: linear-gradient(135deg, #fff8ec, #ffefd2);
  border-left: 5px solid var(--accent);
  border-radius: 8px;
}

.coming-soon-icon {
  font-size: 28px;
  line-height: 1;
}

.coming-soon-banner strong {
  display: block;
  margin-bottom: 4px;
  color: var(--warn);
  font-size: 15px;
}

.coming-soon-banner small {
  display: block;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.6;
}

/* ===== Help / Manual Page ===== */
.help-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.help-toc {
  position: sticky;
  top: 18px;
  display: grid;
  gap: 4px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
  max-height: calc(100vh - 36px);
  overflow-y: auto;
}

.help-toc h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.help-toc-link {
  display: block;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--ink);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}

.help-toc-link:hover {
  background: #e8f6f8;
  color: var(--brand-dark);
}

.help-content {
  display: grid;
  gap: 18px;
}

.help-section {
  padding: 24px 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  scroll-margin-top: 18px;
}

.help-section h2 {
  margin: 0 0 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--brand);
  font-size: 22px;
  color: var(--brand-dark);
}

.help-section h3 {
  margin: 16px 0 8px;
  font-size: 15px;
  color: var(--ink);
}

.help-section p,
.help-section li {
  line-height: 1.7;
  color: var(--ink);
}

.help-section ul,
.help-section ol {
  padding-left: 22px;
}

.help-section code {
  padding: 2px 7px;
  background: #f1f4f8;
  border-radius: 4px;
  font-family: Consolas, monospace;
  font-size: 13px;
  color: #c64646;
}

.help-section pre {
  padding: 12px 14px;
  background: #1f2d3a;
  border-radius: 7px;
  color: #e8f1f4;
  font-family: Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
  overflow-x: auto;
}

.help-section kbd {
  display: inline-block;
  min-width: 28px;
  padding: 2px 8px;
  border: 1px solid #c4cdda;
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #f7f9fc;
  font-family: Consolas, monospace;
  font-size: 12px;
  text-align: center;
}

.help-section a {
  color: var(--brand-dark);
  font-weight: 700;
}

.help-callout {
  margin: 12px 0;
  padding: 12px 16px;
  border-left: 4px solid var(--brand);
  border-radius: 5px;
  background: #f0f9fb;
}

.help-callout.info {
  border-color: var(--brand);
  background: #e8f6f8;
}

.help-callout.warn {
  border-color: var(--accent);
  background: #fff8ec;
}

.help-flow {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
  padding: 14px;
  background: #f7f9fc;
  border-radius: 8px;
}

.help-flow-item {
  padding: 10px 14px;
  background: white;
  border: 2px solid var(--brand);
  border-radius: 7px;
  color: var(--brand-dark);
  font-weight: 800;
  font-size: 13px;
  text-align: center;
  line-height: 1.3;
}

.help-flow-item small {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 600;
}

.help-flow > span {
  color: var(--brand);
  font-size: 20px;
  font-weight: 900;
}

.help-table {
  width: 100%;
  min-width: 0;
  margin: 10px 0;
  border-collapse: collapse;
}

.help-table th,
.help-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: normal;
}

.help-table th {
  background: #f7f9fc;
  font-weight: 800;
}

.help-footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin: 0;
}


@media (max-width: 900px) {
  .help-layout {
    grid-template-columns: 1fr;
  }
  .help-toc {
    position: static;
    max-height: none;
  }
}

.exchange-rate-note {
  grid-column: 1;
  margin-top: 4px;
  padding: 6px 12px;
  border-left: 3px solid #1826b8;
  background: #eef1ff;
  color: #1826b8;
  font-size: 13px;
  font-weight: 700;
}

.exchange-rate-note span {
  margin-left: 6px;
  color: #4a5568;
  font-weight: 400;
}

.term-box {
  grid-column: 1;
  padding: 8px 18px;
  color: #111;
  font-size: 14px;
  line-height: 1.25;
  font-weight: 800;
}

.term-box span {
  margin-left: 8px;
}

.term-box small {
  display: block;
  margin-top: 5px;
  font-size: 11px;
  font-weight: 400;
}

.remark-box {
  grid-column: 1;
  min-height: 54px;
  padding: 7px 18px;
}

.remark-box strong {
  margin-right: 10px;
}

.remark-box small {
  display: block;
  font-size: 11px;
}

.remark-box p {
  margin: 4px 0 0 64px;
}

.signature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 34px;
}

.signature-box {
  min-height: 118px;
  padding: 9px;
  border: 2px solid #111;
  border-radius: 5px;
  text-align: center;
}

.signature-box strong {
  display: block;
  font-size: 13px;
}

.signature-box span {
  display: block;
  height: 42px;
  border-bottom: 2px dotted #333;
  margin: 10px 28px 5px;
}

.signature-box p {
  margin: 5px 0;
  font-size: 13px;
}

.quote-footer-note {
  margin: 8px 0 0;
  color: #0b1b73;
  text-align: center;
  font-size: 15px;
  font-weight: 900;
}

/* The footer note prints on quotations only */
.quote-footer-note[hidden],
.ff-footer[hidden] {
  display: none !important;
}

.segmented {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fc;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  padding: 7px 10px;
  background: transparent;
  color: var(--muted);
}

.segmented .active {
  background: white;
  color: var(--brand-dark);
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.08);
}

.payment-board,
.inventory-grid,
.contacts-grid,
.report-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.inventory-list {
  display: grid;
  gap: 14px;
}

.inventory-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
}

.inventory-search {
  width: min(560px, 100%);
  flex: 1 1 320px;
}

.contacts-grid {
  display: block;
}

.inventory-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  overflow: hidden;
}

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

.inventory-section-head h3 {
  margin: 0;
  font-size: 17px;
}

.inventory-section-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.inventory-table-wrap {
  overflow-x: auto;
}

.inventory-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
}

/* Short code and price (fits tens of thousands), wide name / description, note for sourcing & tier pricing. */
.inventory-table .inv-col-sku { width: 9%; }
.inventory-table .inv-col-name { width: 30%; }
.inventory-table .inv-col-desc { width: 30%; }
.inventory-table .inv-col-price { width: 10%; }
.inventory-table .inv-col-note { width: 21%; }
.inventory-table .inv-col-del { width: 52px; }

.editable-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
}

.inventory-table th,
.inventory-table td,
.editable-table th,
.editable-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.inventory-table th,
.editable-table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.inventory-table input,
.inventory-table select {
  width: 100%;
  min-height: 36px;
  border: 1px solid #d4dde9;
  border-radius: 6px;
  padding: 7px 8px;
  background: white;
}

/* Name / description: one line by default, drag the corner down to read more. */
.inventory-table textarea.inv-grow {
  display: block;
  width: 100%;
  height: 36px;
  min-height: 36px;
  border: 1px solid #d4dde9;
  border-radius: 6px;
  padding: 7px 8px;
  background: white;
  font: inherit;
  line-height: 20px;
  resize: vertical;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.inventory-table textarea.inv-grow:focus {
  overflow: auto;
}

.inventory-table textarea.inv-grow.expanded {
  white-space: pre-wrap;
  overflow: auto;
}

.table-wrap td input,
.table-wrap td select {
  width: 100%;
  min-height: 34px;
  border: 1px solid #d4dde9;
  border-radius: 6px;
  padding: 7px 8px;
  background: white;
}

/* Customers / vendors table */
.contacts-table td {
  vertical-align: top;
}

.contacts-table .contact-address-col {
  min-width: 220px;
}

.contacts-table .contact-name-col {
  min-width: 220px;
}

.contacts-table .contact-info-col {
  min-width: 230px;
}

.table-wrap td textarea.autogrow {
  display: block;
  width: 100%;
  min-height: 34px;
  border: 1px solid #d4dde9;
  border-radius: 6px;
  padding: 7px 8px;
  background: white;
  font: inherit;
  line-height: 1.4;
  resize: vertical;
  overflow: hidden;
}

.contact-info {
  display: grid;
  gap: 4px;
}

.inventory-table .number {
  text-align: right;
}

.low-stock-row {
  background: #fff7ed;
}

.inventory-card,
.contact-card,
.payment-card,
.account-row,
.journal-row {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.inventory-card strong,
.contact-card strong,
.payment-card strong {
  display: block;
  margin-bottom: 5px;
}

.settings-shell {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  margin-top: 16px;
  align-items: start;
}

.settings-menu {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fc;
  position: sticky;
  top: 14px;
}

.settings-tab {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
  text-align: left;
  padding: 0 12px;
  cursor: pointer;
}

.settings-tab.active,
.settings-tab:hover {
  border-color: #bde4eb;
  background: #eaf8fb;
  color: var(--brand-dark);
}

.settings-content {
  min-width: 0;
}

.settings-panel {
  display: none;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.settings-panel.active {
  display: block;
}

.settings-panel h3 {
  margin: 0 0 4px;
}

.settings-panel > p {
  margin: 0 0 14px;
  color: var(--muted);
}

.settings-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.settings-form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}

.settings-form-grid input,
.settings-form-grid textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 12px;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  background: white;
}

.settings-form-grid textarea {
  resize: vertical;
}

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

.settings-status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.settings-status-grid div {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fc;
}

.settings-status-grid small,
.settings-status-grid strong {
  display: block;
}

.settings-status-grid small {
  color: var(--muted);
  margin-bottom: 5px;
}

.app-settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
  margin-bottom: 20px;
}

.app-settings-section {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f9fc;
}

.app-settings-section h3 {
  margin: 0 0 4px;
  font-size: 15px;
}

.app-settings-section > p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.radio-group {
  display: grid;
  gap: 8px;
}

.radio-label {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  cursor: pointer;
  transition: border-color 0.15s;
}

.radio-label:has(input:checked) {
  border-color: var(--brand);
  background: #edf8fa;
}

.radio-label input[type="radio"] {
  margin-top: 3px;
  flex: 0 0 auto;
  accent-color: var(--brand);
}

.radio-content {
  display: grid;
  gap: 2px;
}

.radio-content strong {
  font-size: 14px;
  color: var(--ink);
}

.radio-content small {
  color: var(--muted);
  font-size: 12px;
}

.print-settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.print-settings-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 800;
}

.print-settings-grid input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
}

.print-settings-preview {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 18px;
  align-items: center;
  margin-top: 18px;
}

.print-page-preview {
  position: relative;
  width: 170px;
  aspect-ratio: 210 / 297;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: white;
  box-shadow: var(--shadow);
}

.print-margin-box {
  width: 100%;
  height: 100%;
  display: block;
  border: 1px dashed var(--brand);
  color: var(--brand-dark);
  background: #f7fbfc;
  font-weight: 900;
  overflow: hidden;
}

.margin-label {
  position: absolute;
  z-index: 2;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 10px;
  line-height: 1;
}

.margin-label-top {
  top: 5px;
  left: 50%;
  transform: translateX(-50%);
}

.margin-label-right {
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
}

.margin-label-bottom {
  bottom: 5px;
  left: 50%;
  transform: translateX(-50%);
}

.margin-label-left {
  top: 50%;
  left: 5px;
  transform: translateY(-50%);
}

.print-content-preview {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr 1fr 26px;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(21, 139, 155, 0.2);
  background: white;
}

.print-content-preview strong {
  color: var(--ink);
  font-size: 12px;
}

.print-content-preview span,
.print-content-preview em {
  display: block;
  border: 1px solid #d4dde9;
  background: #eef7f9;
}

.stock-line {
  height: 8px;
  margin: 11px 0;
  border-radius: 999px;
  background: #e5ebf3;
  overflow: hidden;
}

.stock-line span {
  display: block;
  height: 100%;
  background: var(--brand);
}

.low .stock-line span {
  background: var(--bad);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--brand-dark);
  background: #e8f6f8;
  font-weight: 800;
  font-size: 13px;
}

.report-number {
  margin: 12px 0 8px;
  font-size: 32px;
  font-weight: 900;
}

.balance-sheet,
.account-list,
.journal-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.account-row,
.journal-row,
.balance-line {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.balance-line.total {
  border-top: 1px solid var(--border, #e2e8f0);
  padding-top: 8px;
  font-weight: 800;
}

.balance-line.equity strong {
  color: var(--primary, #0f9b8e);
}

.report-hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted, #64748b);
  line-height: 1.5;
}

.dashboard-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 14px;
}

tr.total-row td {
  border-top: 2px solid var(--border, #e2e8f0);
  background: var(--subtle, #f8fafc);
  font-weight: 800;
}

.tax-strip article strong {
  font-size: 24px;
}

.balance-line.sub {
  font-size: 13px;
  color: var(--muted, #64748b);
  padding-left: 14px;
}

.pl-section-head {
  margin-top: 10px;
  font-weight: 800;
  color: var(--text, #1f2d3a);
}

.pl-section-head:first-child {
  margin-top: 0;
}

.smemove-strip {
  margin-bottom: 18px;
}

.sm-card {
  background: linear-gradient(135deg, #0ea5a0, #0f766e) !important;
  color: #fff !important;
}

.sm-card span,
.sm-card small {
  color: rgba(255, 255, 255, 0.85) !important;
}

.sm-card strong {
  color: #fff !important;
}

.source-badge {
  align-self: flex-start;
  padding: 4px 12px;
  border-radius: 999px;
  background: #e6fffa;
  color: #0f766e;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  margin: 10px 0 14px;
}

.list-toolbar input[type="search"] {
  flex: 1;
  min-width: 220px;
  padding: 9px 14px;
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  font-size: 14px;
}

.list-filter-chips {
  display: inline-flex;
  gap: 6px;
}

.chip-filter {
  padding: 7px 16px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--card, #fff);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted, #64748b);
  cursor: pointer;
}

.chip-filter.active {
  background: var(--primary, #0f9b8e);
  border-color: var(--primary, #0f9b8e);
  color: #fff;
}

.list-pager {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
}

.pager-info {
  font-size: 13px;
  color: var(--muted, #64748b);
}

.pager-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.pager-page {
  font-size: 13px;
  font-weight: 700;
}

.pager-btn {
  padding: 7px 14px;
  border: 1px solid var(--border, #e2e8f0);
  background: var(--card, #fff);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text, #1f2d3a);
}

.pager-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.pager-btn:not(:disabled):hover {
  border-color: var(--primary, #0f9b8e);
  color: var(--primary, #0f9b8e);
}

.etax-badge {
  display: inline-block;
  margin: 4px 0;
  padding: 2px 10px;
  border-radius: 999px;
  background: linear-gradient(135deg, #0ea5a0, #0f766e);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.3px;
}

.etax-toggle {
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

/* ฟอร์มสร้างเอกสารขาย: 4 คอลัมน์ ช่องกรอกเตี้ยลง */
#salesForm {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px 10px;
}

#salesForm label {
  gap: 2px;
  font-size: 12px;
}

#salesForm > label input:not([type="checkbox"]),
#salesForm > label select {
  height: 32px;
  padding: 0 9px;
}

#salesForm [hidden],
.paper [hidden],
.edit-indicator[hidden] {
  display: none !important;
}

#salesForm .etax-toggle {
  display: flex;
  align-self: end;
  min-height: 32px;
}

@media (max-width: 1120px) {
  #salesForm {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  #salesForm {
    grid-template-columns: 1fr;
  }
}

.etax-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--primary, #0f9b8e);
}

.etax-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 0 6px;
  border-radius: 6px;
  background: #e6fffa;
  color: #0f766e;
  font-size: 10px;
  font-weight: 800;
  vertical-align: middle;
}

.period-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card, #fff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  padding: 6px 12px;
  box-shadow: var(--shadow, 0 1px 2px rgba(16, 24, 40, 0.06));
}

.period-filter label {
  font-size: 13px;
  color: var(--muted, #64748b);
  font-weight: 600;
}

.period-filter select {
  border: 0;
  background: transparent;
  font-size: 14px;
  font-weight: 700;
  color: var(--text, #1f2d3a);
  cursor: pointer;
  padding: 2px 4px;
}

.period-filter select:focus {
  outline: none;
}

dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(31, 45, 58, 0.44);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 17px;
  border-bottom: 1px solid var(--line);
}

.modal-header h2 {
  margin: 0;
}

/* Event Detail column in the sales document list: one line, full text on hover */
.event-detail-cell {
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Reference column in the sales document list: collapsed by default,
   drag the header's right edge to widen, double-click to toggle */
#salesDocList {
  --ref-col-w: 34px;
}

#salesDocList .ref-col {
  position: relative;
  padding-left: 6px;
  padding-right: 6px;
}

#salesDocList .ref-clip {
  width: var(--ref-col-w);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#salesDocList .col-resizer {
  position: absolute;
  top: 0;
  right: -3px;
  width: 8px;
  height: 100%;
  cursor: col-resize;
  z-index: 2;
}

#salesDocList .col-resizer::after {
  content: "";
  position: absolute;
  top: 25%;
  bottom: 25%;
  left: 3px;
  width: 2px;
  border-radius: 1px;
  background: currentColor;
  opacity: 0.25;
}

#salesDocList .col-resizer:hover::after,
#salesDocList.col-resizing .col-resizer::after {
  opacity: 0.7;
}

#salesDocList.col-resizing,
#salesDocList.col-resizing * {
  cursor: col-resize !important;
  user-select: none;
}

.contact-code-col {
  width: 110px;
}

.vendor-lookup {
  min-width: 0;
}

.vendor-lookup input {
  width: 100%;
}

.lookup-option code {
  color: var(--brand-dark);
  font-weight: 800;
}

/* ===== Work order (ใบสั่งงาน) dialog ===== */
.work-order-dialog {
  width: min(900px, calc(100vw - 32px));
}

.wo-history {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 17px 0;
}

.wo-history label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.wo-history select {
  min-width: 240px;
}

.wo-sheet {
  margin: 12px 17px;
  padding: 18px 22px;
  background: #fff;
  color: #111;
  border: 1px solid #d5d9e0;
  border-radius: 6px;
  font-family: "TH Sarabun New", "THSarabunNew", Tahoma, sans-serif;
  font-size: 19px;
}

.wo-sheet input,
.wo-sheet textarea {
  font: inherit;
  font-weight: 700;
  color: #000;
  background: #fff;
  border: 0;
  border-bottom: 1px dotted #9aa3af;
  border-radius: 0;
  padding: 1px 4px;
  margin: 0;
  min-width: 0;
  width: 100%;
  box-shadow: none;
  height: auto;
}

.wo-sheet input:focus,
.wo-sheet textarea:focus {
  outline: none;
  border-bottom: 1px solid #2563eb;
  background: #eef4ff;
}

.wo-head {
  display: flex;
  align-items: flex-start;
}

.wo-logo {
  position: relative;
  overflow: hidden;
  width: 210px;
  height: 78px;
}

.wo-logo img {
  position: absolute;
  width: 1003px; /* 1700px form scaled so the 356px-wide logo is 210px */
  left: -57px;
  top: 0;
  max-width: none;
}

.wo-phone {
  font-weight: 700;
  font-size: 16px;
}

@font-face {
  font-family: "WO Wansika";
  src: local("JS Wansika Italic"), local("JS Wansika"), url("assets/fonts/JSWansika-Italic.ttf");
}

.wo-title {
  flex: 1;
  text-align: center;
  font-family: "WO Wansika", "TH Sarabun New", serif;
  font-size: 50pt;
  font-weight: 400;
  line-height: 1;
  padding: 6px 100px 0 0;
}

.wo-sheet label {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin: 0;
  font-style: italic;
  font-weight: 400;
  white-space: nowrap;
}

.wo-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 16px;
  margin: 4px 0 10px auto;
  width: min(460px, 100%);
}

.wo-meta-wide {
  grid-column: 1 / 3;
}

.wo-fields {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.wo-fields label > :first-child {
  flex: 1;
}

.wo-row {
  display: grid;
  gap: 4px 16px;
}

.wo-row-place { grid-template-columns: 1fr 240px; }
.wo-row-when { grid-template-columns: 240px 220px; }

.wo-sheet input.wo-red {
  color: #8b0000;
}

.wo-list-title {
  font-size: 22px;
  font-style: italic;
  margin: 14px 0 4px;
}

.wo-items {
  width: 100%;
  border-collapse: collapse;
}

.wo-items th {
  text-align: left;
  font-size: 16px;
  border-top: 1px solid #000;
  border-bottom: 1px solid #000;
  padding: 2px 4px;
  background: none;
  color: #111;
}

.wo-items td {
  border-bottom: 1px solid #000;
  padding: 2px 4px;
}

.wo-items td input {
  border-bottom: 0;
}

.wo-items td .wo-detail {
  display: block;
  width: 100%;
  margin-top: 2px;
  padding: 2px 4px 2px 16px;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  color: #444;
  resize: vertical;
  field-sizing: content;
}

.wo-items .wo-no {
  width: 48px;
  text-align: center;
}

.wo-items .wo-qty {
  width: 150px;
}

.wo-items .wo-act {
  width: 84px;
  white-space: nowrap;
  text-align: right;
}

.wo-row-btn {
  border: 1px solid #d5d9e0;
  background: #fff;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  padding: 0;
  margin-left: 2px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.wo-row-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.wo-empty {
  text-align: center;
  color: #6b7280;
  padding: 12px !important;
}

.wo-add-row {
  margin-top: 8px;
}

.wo-docs {
  display: grid;
  grid-template-columns: 80px 1fr 1fr;
  gap: 2px 12px;
  margin-top: 12px;
  font-style: italic;
}

.wo-docs > span {
  grid-row: 1 / 3;
  text-align: right;
}

.wo-docs input {
  width: auto;
}

.wo-remark {
  margin-top: 8px !important;
  align-items: flex-start !important;
}

.wo-remark textarea {
  border: 1px solid #c4cad3;
  resize: vertical;
}

@media (max-width: 640px) {
  .wo-title { padding-right: 0; font-size: 40px; }
  .wo-head { flex-direction: column; }
  .wo-meta, .wo-row { grid-template-columns: 1fr; }
  .wo-meta-wide { grid-column: auto; }
}

/* ===== Envelope printing dialog ===== */
.envelope-dialog {
  width: min(980px, calc(100vw - 32px));
}

.envelope-body {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 16px;
  padding: 16px 17px;
}

@media (max-width: 760px) {
  .envelope-body {
    grid-template-columns: 1fr;
  }
}

.envelope-controls {
  display: grid;
  align-content: start;
  gap: 10px;
}

.envelope-controls label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.envelope-controls input:not([type="radio"]):not([type="checkbox"]),
.envelope-controls select,
.envelope-controls textarea {
  min-height: 34px;
  padding: 6px 9px;
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.envelope-controls textarea {
  resize: vertical;
}

.envelope-size-actions {
  display: flex;
  gap: 8px;
}

.envelope-size-actions .danger-text {
  color: var(--bad);
}

.envelope-add-size {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.envelope-add-size label:first-child,
.envelope-add-size button {
  grid-column: 1 / -1;
}

.envelope-add-size[hidden],
.envelope-size-actions [hidden] {
  display: none !important;
}

.envelope-address-choice {
  display: grid;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: 0;
}

.envelope-address-choice legend {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.envelope-address-choice label,
.envelope-check {
  display: flex !important;
  align-items: center;
  gap: 6px;
  color: var(--ink) !important;
  font-weight: 400 !important;
}

.envelope-preview-wrap {
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
  padding: 14px;
  border-radius: 8px;
  background: #eef1f5;
}

.envelope-preview {
  position: relative;
  overflow: hidden;
}

.envelope-preview .env {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  box-shadow: 0 2px 10px rgba(31, 41, 51, 0.18);
}

.envelope-preview-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

/* Envelope sheet styles live in app.js (ENVELOPE_SHEET_CSS) so print and preview match. */

/* ===== 50 ทวิ (withholding tax certificate) ===== */
.wht-dialog {
  width: min(1100px, calc(100vw - 32px));
}

.wht-dialog .envelope-body {
  max-height: calc(100vh - 170px);
  overflow: auto;
}

.wht-preview .wht-page {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: top left;
  box-shadow: 0 2px 10px rgba(31, 41, 51, 0.18);
}

.wht-no-row {
  display: flex;
  gap: 6px;
}

.wht-no-row input {
  flex: 1;
  min-width: 0;
}

.wht-choice-inline {
  grid-template-columns: 1fr;
}

.wht-signature {
  gap: 6px !important;
}

.wht-signature-slot {
  display: grid;
  place-items: center;
  min-height: 64px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-size: 12px;
}

.wht-signature-slot img {
  max-width: 90%;
  max-height: 60px;
}

.wht-signature-slot [hidden],
.wht-signature [hidden] {
  display: none !important;
}

.wht-upload {
  cursor: pointer;
  display: inline-flex !important;
  align-items: center;
  color: var(--ink) !important;
}

.wht-cell {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
}

.wht-cert-button {
  min-height: 26px;
  padding: 2px 8px;
  font-size: 12px;
  white-space: nowrap;
}

/* ===== Invoice-from-quotation dialog ===== */
.invoice-dialog-sub {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.invoice-dialog-body {
  display: grid;
  gap: 12px;
  padding: 16px 17px;
}

.invoice-dialog-summary {
  display: grid;
  gap: 4px;
  font-size: 14px;
}

.invoice-dialog-summary .row,
.invoice-dialog-result .row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.invoice-dialog-summary .existing {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.invoice-dialog-warning {
  padding: 10px 12px;
  border-radius: 7px;
  color: #8a5a00;
  background: #fff6e0;
  font-size: 13px;
  font-weight: 700;
}

.invoice-mode-group {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.invoice-mode-group legend {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.invoice-mode {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}

.invoice-mode:has(input[type="radio"]:checked) {
  border-color: var(--brand);
  background: #eef8f9;
}

.invoice-mode > span:first-of-type {
  display: grid;
  flex: 1;
  gap: 2px;
}

.invoice-mode small {
  color: var(--muted);
  font-size: 12px;
}

.invoice-percent {
  display: flex;
  align-items: center;
  gap: 4px;
  font-weight: 800;
}

.invoice-percent input {
  width: 64px;
  height: 32px;
  padding: 0 6px;
  text-align: right;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.invoice-desc-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.invoice-desc-field textarea {
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 7px;
  resize: vertical;
}

.invoice-desc-field .link-button {
  justify-self: end;
  padding: 0;
  border: 0;
  color: var(--brand-dark);
  background: none;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.invoice-dialog-result {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f7f9fc;
  font-size: 14px;
}

.invoice-dialog-result .row.total {
  font-weight: 800;
}

.invoice-dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 17px 17px;
  border-top: 1px solid var(--line);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
  padding: 17px;
}

.quick-action {
  min-height: 78px;
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  text-align: left;
  padding: 13px;
}

.quick-action span {
  color: var(--muted);
}

/* ===== Top bar: never break buttons / user name onto two lines ===== */
.topbar-actions {
  flex: 1 1 auto;
  justify-content: flex-end;
  min-width: 0;
}

.topbar-actions .search {
  flex: 0 1 420px;
  width: auto;
  min-width: 160px;
}

.topbar-actions > button,
.user-info strong,
.user-info small {
  white-space: nowrap;
}

.page-heading {
  min-width: 0;
  flex: 0 1 auto;
}

.page-heading h1 {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== Notebook / laptop screens (about 1121–1500px wide) ===== */
@media (max-width: 1500px) {
  .app-shell {
    grid-template-columns: 236px minmax(0, 1fr);
  }

  .sidebar {
    padding: 14px 10px;
  }

  .brand {
    padding: 4px 6px 14px;
  }

  .nav-item,
  .nav-group-head {
    min-height: 36px;
    padding: 7px 9px;
    gap: 9px;
    font-size: 14px;
  }

  .nav-ico {
    width: 24px;
    height: 24px;
    font-size: 13px;
  }

  .nav-sub {
    margin-left: 28px;
  }

  .nav-sub .nav-item {
    min-height: 32px;
    padding: 6px 9px;
    font-size: 13px;
  }

  .workspace {
    padding: 16px 18px;
  }

  .topbar {
    gap: 12px;
    margin-bottom: 12px;
  }

  h1 {
    font-size: 23px;
  }

  h2 {
    font-size: 16px;
  }

  .topbar-actions {
    gap: 8px;
  }

  .primary-button,
  .secondary-button,
  .icon-button {
    min-height: 36px;
  }

  .topbar-actions .search {
    height: 36px;
  }

  .primary-button,
  .secondary-button {
    padding: 0 12px;
  }

  .user-menu {
    padding: 3px 6px 3px 10px;
  }

  .user-menu .icon-button {
    width: 32px;
    height: 32px;
    min-height: 32px;
  }

  .panel {
    padding: 14px;
  }

  th,
  td {
    padding: 8px 8px;
    font-size: 14px;
  }

  th {
    font-size: 12px;
  }

  .event-detail-cell {
    max-width: 240px;
  }
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 10;
    width: 286px;
    transform: translateX(-102%);
    transition: transform 180ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-grid;
    place-items: center;
  }

  .summary-strip,
  .module-grid,
  .dashboard-grid,
  .work-grid,
  .payment-board,
  .inventory-grid,
  .contacts-grid,
  .print-settings-grid,
  .app-settings-grid,
  .settings-shell,
  .settings-status-grid,
  .form-row-4,
  .report-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .settings-menu {
    position: static;
  }
}

@media (max-width: 760px) {
  .workspace {
    padding: 15px;
  }

  .topbar,
  .topbar-actions,
  .inventory-tools {
    align-items: stretch;
    flex-direction: column;
  }

  .search {
    width: 100%;
  }

  .summary-strip,
  .module-grid,
  .dashboard-grid,
  .work-grid,
  .payment-board,
  .inventory-grid,
  .contacts-grid,
  .print-settings-grid,
  .print-settings-preview,
  .app-settings-grid,
  .settings-shell,
  .settings-form-grid,
  .settings-status-grid,
  .form-row-4,
  .report-grid,
  .form-grid,
  .inline-form,
  .paper-grid {
    grid-template-columns: 1fr;
  }

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

  .settings-form-grid .span-2 {
    grid-column: auto;
  }

  .paper-header {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    size: A4;
    margin: var(--pdf-margin-top) var(--pdf-margin-right) var(--pdf-margin-bottom) var(--pdf-margin-left);
  }

  html,
  body {
    width: 210mm;
    min-height: 297mm;
  }

  body.printing-document {
    background: white;
  }

  body.printing-document * {
    visibility: hidden;
    box-shadow: none !important;
  }

  body.printing-document .paper,
  body.printing-document .paper * {
    visibility: visible;
  }

  body.printing-document .view,
  body.printing-document .sales-tab-panel {
    display: none !important;
  }

  body.printing-document .app-shell,
  body.printing-document .workspace,
  body.printing-document main,
  body.printing-document #salesView,
  body.printing-document [data-sales-tab-panel="company"],
  body.printing-document .document-preview {
    margin: 0 !important;
    padding: 0 !important;
    width: auto !important;
    max-width: none !important;
    min-height: 0 !important;
    display: block !important;
  }

  body.printing-document .paper {
    position: relative;
    top: 0;
    left: auto;
    margin: 0 auto !important;
    width: var(--pdf-paper-width, 198mm);
    min-height: var(--pdf-paper-height, 285mm);
    border: 0;
    border-radius: 0;
    padding: 0;
    font-size: 11px;
    overflow: visible;
  }

  body.printing-document .paper-actions,
  body.printing-document .sidebar,
  body.printing-document .topbar,
  body.printing-document .sales-tabbar {
    display: none !important;
  }

  body.printing-document .quote-top {
    grid-template-columns: minmax(0, 1fr) 76mm;
    gap: 2mm;
  }

  body.printing-document .quote-brand-row {
    grid-template-columns: 42mm 1fr;
    gap: 2mm;
  }

  body.printing-document .quote-logo {
    height: 18mm;
    font-size: calc(26px * var(--logo-scale, 1));
    border-width: 1px;
  }

  body.printing-document .quote-company h2,
  body.printing-document .quote-company h3 {
    font-size: 19px;
    line-height: 1;
  }

  body.printing-document .quote-company p {
    margin: 1px 0;
    font-size: 10px;
    line-height: 1.15;
  }

  body.printing-document .quote-title-box {
    gap: 1mm;
  }

  body.printing-document .quote-title-box > h2 {
    padding: 3mm 2mm 0;
    border-width: 1.5px;
    font-size: 18px;
  }

  body.printing-document .quote-title-box > strong {
    padding: 0 2mm 3mm;
    border-width: 1.5px;
    font-size: 15px;
  }

  body.printing-document .quote-copy {
    padding: 0 2mm;
    font-size: 10px;
  }

  body.printing-document .quote-meta div {
    min-height: 11mm;
    padding: 1.5mm 2mm;
    border-width: 1.5px;
  }

  body.printing-document .quote-meta strong {
    font-size: 11px;
  }

  body.printing-document .quote-info-grid {
    margin-top: 1mm;
    gap: 1mm;
  }

  body.printing-document .quote-box {
    min-height: 35mm;
    padding: 2mm;
    border-width: 1.5px;
  }

  body.printing-document .quote-box p {
    margin-bottom: 4mm;
    font-size: 11px;
  }

  body.printing-document .quote-box strong,
  body.printing-document .contact-box strong {
    min-width: 28mm;
  }

  body.printing-document .quote-event {
    min-height: 10mm;
    margin-top: 1mm;
    padding: 1.5mm 2mm;
    border-width: 1.5px;
    font-size: 12px;
  }

  body.printing-document .quote-table th,
  body.printing-document .quote-table td {
    padding: 1.5mm 2mm;
    border-width: 1.5px;
  }

  body.printing-document .quote-table th {
    font-size: 10px;
  }

  body.printing-document .quote-table th small,
  body.printing-document .quote-meta small,
  body.printing-document .quote-box small,
  body.printing-document .quote-event small,
  body.printing-document .paper-total small,
  body.printing-document .term-box small,
  body.printing-document .remark-box small {
    font-size: 7px;
  }

  body.printing-document .quote-table td {
    height: 9mm;
    font-size: 10px;
  }

  body.printing-document .quote-table .quote-heading-row td {
    height: auto;
    padding-top: 2.5mm;
    padding-bottom: 0.5mm;
  }

  body.printing-document .quote-table .quote-filler-row td {
    height: var(--quote-filler-print-height, 82mm);
  }

  body.printing-document .quote-table tbody tr:last-child td {
    border-bottom-width: 1.5px;
  }

  body.printing-document .quote-table .description-cell strong {
    margin-bottom: 1mm;
    font-size: 11px;
  }

  body.printing-document .quote-summary {
    grid-template-columns: 1fr 48mm;
  }

  body.printing-document .exchange-rate-note {
    margin-top: 1mm;
    padding: 1mm 3mm;
    font-size: 9px;
    border-left-width: 2px;
  }

  body.printing-document .exchange-rate-note span {
    font-size: 8px;
  }

  body.printing-document .said-total {
    min-height: 8mm;
    grid-template-columns: 32mm 1fr;
    border-width: 1.5px;
  }

  body.printing-document .said-total strong,
  body.printing-document .said-total span {
    padding: 1.5mm 2mm;
    font-size: 10px;
  }

  body.printing-document .paper-total {
    border-width: 1.5px;
  }

  body.printing-document .paper-total span,
  body.printing-document .paper-total strong {
    min-height: 8mm;
    padding: 1mm 2mm;
    border-width: 1.5px;
    font-size: 11px;
  }

  body.printing-document .paper-total strong {
    min-width: 25mm;
  }

  body.printing-document .remark-box {
    min-height: 10mm;
    padding: 1.5mm 4mm;
  }

  body.printing-document .term-box {
    padding: 1.5mm 4mm;
    font-size: 10px;
    line-height: 1.15;
  }

  body.printing-document .signature-grid {
    gap: 1.5mm;
    margin-top: 6mm;
    break-inside: avoid;
  }

  body.printing-document .signature-box {
    min-height: 28mm;
    padding: 2mm;
    border-width: 1.5px;
  }

  body.printing-document .signature-box strong,
  body.printing-document .signature-box p {
    font-size: 9px;
  }

  body.printing-document .signature-box span {
    height: 10mm;
    margin: 2mm 8mm 1mm;
    border-bottom-width: 1.5px;
  }

  body.printing-document .quote-footer-note {
    margin-top: 1.5mm;
    font-size: 10px;
  }
  /* Quotation on the company form: @page margin is 0 (set in printDocument).
     The form's printed content (x 34.6-576.5 pt, y 0.7-790 pt of the 612x792 sheet) is scaled
     to fill A4 inside ~5 mm margins: 0.3636 mm/pt, so the sheet is 222.5 mm wide and its own
     white side margins fall outside the page (clipped). */
  body.printing-document .paper.form-mode {
    width: 210mm !important;
    /* exactly N pages (fitFormSheet sets --form-pages), a hair short so rounding never adds a blank page */
    height: calc(var(--form-pages, 1) * 297mm - 1mm);
    min-height: 0;
    padding: 0 !important;
    overflow: clip; /* cut the sheet's white side margins; clip (not hidden) keeps page breaks working */
    display: flow-root !important; /* keep the sheet's top margin inside (clip alone lets it collapse out) */
  }

  /* Each page: 4.75 mm + 287.9 mm sheet = 292.7 mm, under A4 so it never spills onto a blank page */
  body.printing-document .paper.form-mode .form-sheet {
    width: 222.5mm;
    margin-left: -6.08mm;
  }

  body.printing-document .paper.form-mode > .form-sheet {
    margin-top: 4.75mm;
  }

  body.printing-document .form-sheet-page {
    break-before: page;
    margin-top: 0;
    padding-top: 4.75mm;
  }
}

/* ===== Quotation printed on the company form ===== */
.paper.form-mode {
  padding: 0;
  min-height: 0;
}

.paper.form-mode > :not(.form-sheet):not(.form-sheet-page) {
  display: none !important;
}

/* Page 2, 3, ... of a quotation whose items do not fit on one form page */
.form-sheet-page {
  margin-top: 16px;
}

.paper:not(.form-mode) .form-sheet-page {
  display: none;
}

.ff-page {
  font-size: calc(11 * var(--u));
  text-align: right;
}

.ff-page[hidden] {
  display: none;
}

/* Receipt copy name (Original / Customer Copy / Accounting Copy) under the title box */
.ff-copy {
  font-size: calc(12 * var(--u));
  text-align: center;
  color: #1a3fb8;
}

.ff-copy[hidden] {
  display: none;
}

.receipt-copy-picker {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  font-size: 14px;
}

.receipt-copy-picker[hidden] {
  display: none;
}

.receipt-copy-picker label {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
}

/* Every page but the last: no totals (they are on the last page).
   Extra specificity beats the print rule that makes everything inside .paper visible. */
.ff-not-last .ff-total,
body.printing-document .paper .ff-not-last .ff-total {
  visibility: hidden;
}

.ff-see-next {
  font-size: calc(13 * var(--u));
  font-style: italic;
  font-weight: 700;
  line-height: calc(14 * var(--u));
  text-align: right;
  padding-right: calc(3 * var(--u)); /* same right padding as the amounts above */
}

.ff-see-next[hidden] {
  display: none;
}

/* Receipts: small WHT note under the Grand Total box */
.ff-wht {
  font-size: calc(7.5 * var(--u));
  line-height: 1.25;
  text-align: right;
  white-space: pre;
}

.ff.ff-wht {
  color: #1c2e5e; /* navy (กรมท่า) */
}

.ff-wht[hidden] {
  display: none;
}

.ff-note .ff-continued {
  text-align: right;
  font-style: italic;
}

.form-sheet {
  position: relative;
  width: 100%;
  aspect-ratio: 612 / 792;
  container-type: inline-size;
  overflow: hidden;
  background: #fff;
  color: #000;
  /* Filled-in text: TH Sarabun New (Thai + English in one font). Its glyphs are small for their
     point size, so the sizes below are ~1.35x what Tahoma/Times would use. */
  font-family: "TH Sarabun New", "THSarabunNew", Tahoma, "Leelawadee UI", sans-serif;
}

/* Bigger filled-in fields, sized to their boxes on the form (sizes in form points) */
#ffCustomer { font-size: calc(14 * var(--u) * var(--fit, 1)); }
#ffAddress { font-size: calc(13.5 * var(--u) * var(--fit, 1)); line-height: 1.1; }
#ffTaxId { font-size: calc(13 * var(--u) * var(--fit, 1)); line-height: 1; }
#ffContact { font-size: calc(13.5 * var(--u) * var(--fit, 1)); line-height: 1.1; }
#ffEvent { font-size: calc(15 * var(--u) * var(--fit, 1)); }
#ffSaidTotal { font-size: calc(13.5 * var(--u) * var(--fit, 1)); }
#ffSalesDate,
#ffAuthorizeDate { font-size: calc(13 * var(--u) * var(--fit, 1)); line-height: 1; text-overflow: clip; }

/* Thai stacked marks (e.g. ชั้น: ั + ้) rise above the line box and were clipped by the field's top
   edge. Give the text fields headroom: start the box higher and pad it by the same amount, so the
   text stays where it was but the marks above it are no longer cut off. */
#ffCustomer,
#ffAddress,
#ffTaxId,
#ffContact,
#ffEvent,
#ffSaidTotal,
#ffBank,
.form-sheet .ff-sales {
  top: calc((var(--y) - 4) * var(--u));
  height: calc((var(--h) + 4) * var(--u));
  padding-top: calc(4 * var(--u));
}

/* Lines of the address / contact: a little more line spacing so upper marks never touch the line above */
#ffAddress,
#ffContact { line-height: 1.22; }

/* All positions/sizes are PDF points of the 612 x 792 form, scaled to the sheet width. */
.form-sheet > * {
  --u: calc(100cqw / 612);
}

.form-sheet-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.ff,
.ff-lines,
.ff-img {
  position: absolute;
  left: calc(var(--x) * var(--u));
  top: calc(var(--y) * var(--u));
  width: calc(var(--w) * var(--u));
  height: calc(var(--h) * var(--u));
  overflow: hidden;
}

.ff {
  font-size: calc(11 * var(--u));
  line-height: 1.1;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.ff-strong {
  font-weight: 700;
}

/* Signatures + stamp: transparent PNGs, ink blended over the form's lines like a real pen/stamp */
.ff-img {
  object-fit: contain;
  mix-blend-mode: multiply;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.ff-img[hidden] {
  display: none;
}

#ffStamp {
  z-index: 1;
}

.print-signatures-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 12px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.print-signatures-toggle[hidden] {
  display: none;
}

.signature-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 10px;
}

.signature-slot {
  display: grid;
  gap: 8px;
  justify-items: start;
  width: 200px;
}

.signature-thumb {
  width: 200px;
  height: 90px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line, #d4dde9);
  border-radius: 8px;
  background: #fff;
}

.signature-thumb img {
  max-width: 180px;
  max-height: 80px;
  object-fit: contain;
}

.signature-slot [hidden] {
  display: none;
}

.ff-docno {
  font-size: calc(15 * var(--u) * var(--fit, 1));
  line-height: 1;
  text-overflow: clip;
}

#ffDate {
  font-size: calc(13 * var(--u) * var(--fit, 1));
  line-height: 1;
  text-overflow: clip;
  text-align: center;
}

.ff-footer {
  font-size: calc(11.5 * var(--u));
  line-height: 1;
  font-style: italic;
  font-weight: 700;
  text-align: center;
}

.ff-wrap {
  white-space: pre-line;
}

/* Invoice bank details (dark red, like the quotation's payment terms) */
.ff-bank {
  font-size: calc(11.5 * var(--u) * var(--fit, 1));
  line-height: 1.12;
  font-weight: 600;
  color: #6b0f12;
}

/* Invoice: credit term + due date, first line of the bank box */
.ff-bank .ff-due {
  color: #111;
  font-weight: 700;
  margin-bottom: calc(2 * var(--u));
}

.ff-bank[hidden] {
  display: none !important;
}

/* Receipt Remark + payment details (under Said Total) */
.ff-pay {
  white-space: normal;
  font-size: calc(11.2 * var(--u));
  line-height: 1.05;
  color: #000;
}

.ff-pay[hidden] {
  display: none !important;
}

.ff-pay .pay-remark {
  display: flex;
  gap: calc(4 * var(--u));
  margin-bottom: calc(2.5 * var(--u));
}

.ff-pay .pay-remark strong {
  font-size: calc(14 * var(--u));
  white-space: nowrap;
  line-height: 1;
}

.ff-pay .pay-remark span {
  font-size: calc(9.8 * var(--u));
  line-height: 1.02;
}

.ff-pay .pay-row {
  display: flex;
  align-items: baseline;
  gap: calc(3 * var(--u));
  padding-left: calc(48 * var(--u));
  height: calc(11.4 * var(--u));
  white-space: nowrap;
}

.ff-pay .pay-methods {
  gap: calc(22 * var(--u));
}

.ff-pay .pay-box b {
  font-size: 0.9em;
}

/* Dotted line with the filled-in value written on it (blue, like a pen) */
.ff-pay .pay-fill {
  display: inline-block;
  position: relative;
  height: 1em; /* keeps the dotted line visible when the field is left empty */
  color: #1a3fb8;
  font-size: 1.1em;
  text-align: center;
  overflow: hidden;
  line-height: 1;
}

/* The dots sit just under the letters (not at the bottom of the line box) */
.ff-pay .pay-fill::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--pay-dots-bottom, 0.14em);
  border-bottom: calc(0.9 * var(--u)) dotted #000;
}

.ff-pay .w-bank { width: calc(82 * var(--u)); }
.ff-pay .w-branch { width: calc(82 * var(--u)); }
.ff-pay .w-cheque { width: calc(70 * var(--u)); }
.ff-pay .w-date { width: calc(82 * var(--u)); }
.ff-pay .w-amount { width: calc(82 * var(--u)); }

.receipt-payment-dialog {
  width: min(460px, calc(100vw - 32px));
}

.receipt-payment-body {
  display: grid;
  gap: 10px;
  padding: 8px 16px 12px;
}

.receipt-payment-body label {
  display: grid;
  gap: 4px;
}

.receipt-payment-method {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}

.receipt-payment-method label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.receipt-payment-calc {
  flex-basis: 100%;
  margin: 2px 0 0;
  font-size: 0.85em;
  color: #555;
}

.ff-middle {
  display: flex;
  align-items: center;
}

/* Right-aligned amounts: plain block (not flex) so an overflow is measurable and fitFormSheet can shrink it. */
.ff-num {
  display: block;
  text-align: right;
  text-overflow: clip;
  line-height: calc(var(--h) * var(--u));
  font-size: calc(13.5 * var(--u) * var(--fit, 1));
  padding: 0 calc(3 * var(--u)) 0 calc(1.5 * var(--u));
}

.ff-lines {
  display: flex;
  flex-direction: column;
  /* first row (item or heading) starts 3 mm lower: 3 mm / 0.3636 mm per form point = 8.25 pt */
  padding-top: calc(8.25 * var(--u));
}

.ff-table {
  width: 100%;
  min-width: 0; /* the app-wide table rule sets 720px, which would break the column alignment */
  table-layout: fixed;
  border-collapse: collapse;
  font-size: calc(13.5 * var(--u) * var(--ff-scale, 1)); /* TH Sarabun New runs small: 13.5pt ~ 10pt Times */
  line-height: 1;
}

.ff-table col {
  width: calc(var(--w) * var(--u));
}

.ff-table td {
  font-size: inherit; /* the table's form-scaled size, not the app's fixed "th, td { 14px }" on screens <= 1500px */
  padding: calc(1.5 * var(--u) * var(--ff-scale, 1)) calc(3 * var(--u));
  border: 0; /* no row lines: the form's own column lines are enough */
  white-space: normal;
  vertical-align: top;
  overflow-wrap: anywhere;
}

/* Item rows: regular weight (name, qty, price, days, amount); only section headings stay bold */
.ff-table td.ff-v {
  font-weight: 400;
}

/* Item name + description in bold, for easier reading */
.ff-table td strong,
.ff-table td span {
  font-weight: 700;
}

.ff-table .ff-heading td strong {
  font-weight: 700;
}

.ff-table td.ff-v {
  white-space: nowrap; /* fitFormSheet shrinks a value that is wider than its column */
  padding-left: calc(2 * var(--u));
  padding-right: calc(2 * var(--u));
}

.ff-sales {
  font-family: "Times New Roman", Times, serif;
  font-style: italic;
  font-weight: 700;
  font-size: calc(9 * var(--u) * var(--fit, 1));
  line-height: 1.25;
  color: #0b1d5c;
}

.ff-table td span {
  display: block;
  white-space: pre-line;
  font-size: 0.87em; /* item description: smaller than the item name, upright (the indent sets it apart) */
  padding-left: calc(13.75 * var(--u)); /* indent 0.5 cm (print scale 0.3636 mm per form point) */
  color: #222;
}

.ff-table .ff-c {
  text-align: center;
}

.ff-table .ff-r {
  text-align: right;
}

.ff-table .ff-heading td {
  padding-top: calc(3.5 * var(--u) * var(--ff-scale, 1));
  text-decoration: underline;
}

/* Event Detail and section headings: dark red, close to black */
#ffEvent,
.ff-table .ff-heading td {
  color: #6b0000;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.ff-note {
  margin-top: auto;
  margin-left: calc(22.8 * var(--u));
  width: calc(314.5 * var(--u));
  padding: 0 calc(3 * var(--u)) calc(2 * var(--u));
  font-size: calc(9.5 * var(--u) * var(--ff-scale, 1));
  line-height: 1.1;
}

.ff-note p {
  margin: 0;
}

.form-overflow-warning {
  margin: 0 auto 0 0;
  padding: 6px 10px;
  border-radius: 8px;
  background: #fff4e5;
  color: #8a4b00;
  font-size: 13px;
}

/* Settings: form template */
.form-template-settings {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line, #e5e7eb);
}

.form-template-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-top: 10px;
  flex-wrap: wrap;
}

.form-template-row > div {
  display: grid;
  gap: 8px;
  justify-items: start;
  flex: 1 1 240px;
}

.form-template-thumb {
  width: 150px;
  aspect-ratio: 612 / 792;
  object-fit: fill;
  border: 1px solid var(--line, #e5e7eb);
  background: #fff;
}

.form-template-upload {
  cursor: pointer;
}

.form-template-hint {
  font-size: 12px;
  color: var(--muted, #6b7280);
}

/* ===== Expense receipts (photo / scan / file, category, project) ===== */
.expense-dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
}

.expense-dialog form {
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 32px);
}

.expense-body {
  overflow-y: auto;
  padding: 14px 17px;
  display: grid;
  gap: 14px;
}

.expense-files {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 2px dashed #c9d7e3;
  border-radius: 10px;
  background: #f7fafc;
}

.expense-files.dragging {
  border-color: var(--brand);
  background: #e8f6f8;
}

.expense-file-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.expense-file {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.expense-file > a {
  display: block;
  width: 100%;
  height: 100%;
}

.expense-file img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.expense-file-pdf {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 4px;
  height: 100%;
  font-size: 30px;
  color: var(--ink);
  text-align: center;
}

.expense-file-pdf small {
  font-size: 11px;
  padding: 0 4px;
  word-break: break-all;
}

.expense-file-remove {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: rgba(31, 41, 51, 0.72);
  color: #fff;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

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

.expense-file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  flex: 1 1 180px;
  min-height: 46px;
  font-size: 15px;
}

.expense-file-status {
  color: var(--brand-dark);
  font-weight: 700;
  font-size: 13px;
}

.expense-file-status:empty {
  display: none;
}

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

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

.expense-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.expense-grid input,
.expense-grid select,
.expense-new-note input {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
  min-width: 0;
}

.expense-link-button {
  justify-self: start;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--brand-dark);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.expense-new-note {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  border-radius: 8px;
  background: #fff8e6;
}

.expense-new-note input {
  flex: 1 1 180px;
}

/* under ผู้ขาย / ร้านค้า: "✓ in the list" or "new shop + add to vendors" */
.expense-vendor-status {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  margin-top: -6px;
  color: var(--muted);
  font-size: 13px;
}

.expense-vendor-known {
  color: #17714a;
}

.expense-vendor-known code {
  font-weight: 800;
}

.expense-new-vendor {
  background: #eef8f9;
}

.expense-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 17px;
  border-top: 1px solid var(--line);
  background: #fff;
}

.expense-error {
  flex: 1 1 auto;
  color: var(--bad);
  font-size: 13px;
  font-weight: 700;
}

.purchase-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.pm-chip {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  max-width: 100%;
  padding: 1px 8px;
  border-radius: 999px;
  background: #eef1f6;
  color: #4d5968;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-decoration: none;
}

.pm-project {
  background: #e4f6f8;
  color: #105f68;
}

.pm-note {
  background: #fff2d9;
  color: var(--warn);
}

.pm-file {
  background: #e5f6ee;
  color: #126344;
}

.pm-file:hover {
  text-decoration: underline;
}

.purchase-row-actions {
  white-space: nowrap;
}

.purchase-row-actions .small-icon-button + .small-icon-button {
  margin-left: 4px;
}

#projectNoteTable .note-matched td {
  color: var(--muted);
}

#projectNoteTable .note-actions {
  white-space: nowrap;
}

.expense-categories-input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font: inherit;
  line-height: 1.6;
}

/* Phones: the receipt dialog fills the screen, big buttons first */
@media (max-width: 640px) {
  .expense-dialog {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
  }

  .expense-dialog form {
    height: 100%;
    max-height: 100dvh;
  }

  .expense-body {
    flex: 1 1 auto;
  }

  .expense-grid {
    grid-template-columns: 1fr;
  }

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

  .expense-drop-hint {
    display: none;
  }
}

.expense-check {
  display: flex !important;
  align-items: flex-start;
  gap: 8px;
  color: var(--ink) !important;
  font-weight: 600 !important;
  cursor: pointer;
}

.expense-check input {
  width: 18px;
  min-height: 18px !important;
  height: 18px;
  margin-top: 2px;
  flex: 0 0 auto;
}

/* Phones: the top bar stacks into a column — the search box's 420px flex basis must not become its height */
@media (max-width: 760px) {
  .topbar-actions .search {
    flex: 0 0 auto;
    height: 40px;
  }
}

/* ซื้อ → ใบเสร็จค่าใช้จ่าย */
.expense-capture-button {
  min-height: 46px;
  font-size: 15px;
  white-space: nowrap;
}

.expense-list-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.expense-list-tools input,
.expense-list-tools select {
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font: inherit;
}

.expense-list-tools input {
  flex: 1 1 260px;
  min-width: 0;
}

.expense-list-tools select {
  flex: 0 1 220px;
}

.expense-list-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
}

.expense-list-summary:empty {
  display: none;
}

.expense-thumb {
  position: relative;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border: 1px solid var(--line);
  border-radius: 7px;
  overflow: hidden;
  background: #f7f9fc;
  font-size: 24px;
  text-decoration: none;
  color: var(--muted);
}

.expense-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.expense-thumb b {
  position: absolute;
  right: 2px;
  bottom: 2px;
  padding: 0 4px;
  border-radius: 4px;
  background: rgba(31, 41, 51, 0.75);
  color: #fff;
  font-size: 11px;
}

.expense-thumb-none {
  font-size: 14px;
}

@media (max-width: 640px) {
  #expenseReceiptsView .panel-header {
    flex-direction: column;
    align-items: stretch;
  }

  .expense-capture-button {
    width: 100%;
    min-height: 54px;
    font-size: 17px;
  }
}

/* ===== Home page: my shortcuts (app-style tiles, each user picks their own) ===== */
.home-launcher {
  margin-top: 0;
  margin-bottom: 12px;
}

.home-launcher-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
}

.home-launcher-head h2 {
  margin: 0;
  font-size: 18px;
}

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

.home-launcher-actions .secondary-button {
  min-height: 36px;
  font-size: 14px;
}

#appIconOpen.attention {
  color: #fff;
  background: var(--brand);
  border-color: var(--brand);
}

.home-shortcuts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
}

.home-shortcut {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}

.home-shortcut:hover,
.home-shortcut:focus-visible {
  background: #f1f7f8;
  border-color: var(--line);
}

.home-shortcut-icon {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border-radius: 16px;
  font-size: 32px;
  line-height: 1;
  background: linear-gradient(135deg, #e6f5f7, #cde8ec);
  box-shadow: inset 0 0 0 1px rgba(15, 103, 115, 0.12);
}

.home-shortcut-label {
  font-size: 14px;
  line-height: 1.3;
  text-align: center;
}

.home-shortcut-empty {
  margin: 0;
  color: var(--muted);
}

/* Shortcut editor (phones: full screen, like the receipt dialog) */
@media (min-width: 641px) {
  .home-shortcut-dialog {
    width: min(560px, calc(100vw - 32px));
  }
}

.shortcut-pick-title {
  margin: 0 0 8px;
  font-size: 15px;
}

.shortcut-pick-title small {
  color: var(--muted);
  font-weight: 400;
}

.shortcut-pick-list {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.shortcut-pick {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.shortcut-pick-icon {
  width: 32px;
  font-size: 22px;
  text-align: center;
}

.shortcut-pick-label {
  flex: 1 1 auto;
  min-width: 0;
}

.shortcut-pick-buttons {
  display: flex;
  gap: 4px;
}

.shortcut-pick-buttons .icon-button {
  width: 36px;
  min-height: 36px;
}

.shortcut-pick-buttons .secondary-button {
  min-height: 36px;
}

.shortcut-pick-empty {
  padding: 6px 2px;
  color: var(--muted);
}

.shortcut-reset {
  margin-right: auto;
}

/* Install as an app + my app icon */
@media (min-width: 641px) {
  .app-icon-dialog {
    width: min(640px, calc(100vw - 32px));
  }
}

.app-install-box {
  padding: 12px 14px;
  border: 1px solid #cfe5e9;
  border-radius: 10px;
  background: #f1f7f8;
}

.app-install-status {
  margin: 0 0 8px;
  font-weight: 700;
}

.app-install-steps {
  margin: 0;
  padding-left: 22px;
  line-height: 1.7;
}

.app-install-steps:empty {
  display: none;
}

.app-icon-maker h3 {
  margin: 0 0 4px;
}

.app-icon-note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 14px;
}

.app-icon-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.app-icon-preview {
  flex: 0 0 auto;
  width: 120px;
  height: 120px;
  border-radius: 26px;
  background: #e5e7eb;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.22);
}

.app-icon-options {
  display: grid;
  flex: 1 1 auto;
  gap: 8px;
  min-width: 0;
}

.app-icon-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.app-icon-symbols {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
}

.app-icon-choice {
  display: grid;
  place-items: center;
  height: 44px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 24px;
  cursor: pointer;
}

.app-icon-choice img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
}

.app-icon-choice.selected,
.app-icon-color.selected {
  outline: 3px solid var(--brand);
  outline-offset: 1px;
}

.app-icon-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.app-icon-inline input {
  flex: 1 1 160px;
  min-width: 0;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 15px;
}

.app-icon-file {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
}

.app-icon-colors {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.app-icon-colors.disabled {
  opacity: 0.45;
}

.app-icon-color {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 50%;
  cursor: pointer;
}

.expense-error.ok {
  color: var(--good);
}

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

  .home-launcher-actions {
    width: 100%;
  }

  .home-launcher-actions .secondary-button {
    flex: 1 1 0;
    padding: 0 8px;
  }

  .home-shortcuts {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 2px;
  }

  .home-shortcut {
    padding: 8px 2px;
  }

  .home-shortcut-icon {
    width: 54px;
    height: 54px;
    border-radius: 14px;
    font-size: 28px;
  }

  .home-shortcut-label {
    font-size: 12.5px;
  }

  .app-icon-row {
    flex-direction: column;
    align-items: center;
  }

  .app-icon-options {
    width: 100%;
  }
}

/* Home-page chart: its size comes from here. drawCashflow() sets canvas.width = shown width × devicePixelRatio, so
   without a CSS width the canvas grew ×2–3 on every redraw on phones and pushed the page wider than the screen. */
#cashflowChart {
  display: block;
  width: 100%;
  height: 230px;
}

/* ===== Document scanner for receipt photos (dark, full screen, like a scanner app) ===== */
.expense-file-rescan {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(31, 41, 51, 0.72);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}

.scan-dialog {
  width: min(900px, calc(100vw - 32px));
  max-width: none;
  height: min(860px, calc(100dvh - 32px));
  max-height: none;
  padding: 0;
  background: #111418;
  color: #f2f4f7;
}

.scan-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.scan-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
}

.scan-head strong {
  display: block;
  font-size: 17px;
}

.scan-head small {
  color: #aab4c0;
}

.scan-count {
  color: #aab4c0;
  font-size: 14px;
  white-space: nowrap;
}

.scan-stage {
  position: relative;
  display: grid;
  flex: 1 1 auto;
  min-height: 0;
  place-items: center;
  overflow: hidden;
  touch-action: none;
}

.scan-stage canvas#scanCanvas {
  display: block;
}

.scan-overlay {
  position: absolute;
  overflow: visible;
  touch-action: none;
}

.scan-overlay polygon {
  fill: rgba(34, 211, 238, 0.14);
  stroke: #22d3ee;
}

.scan-overlay circle {
  fill: rgba(17, 20, 24, 0.35);
  stroke: #22d3ee;
  cursor: grab;
}

.scan-overlay circle.active {
  fill: rgba(34, 211, 238, 0.45);
}

.scan-result {
  display: block;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 24px);
  background: #fff;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}

.scan-loupe {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 132px;
  height: 132px;
  border: 3px solid #22d3ee;
  border-radius: 50%;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  pointer-events: none;
}

.scan-loupe.right {
  right: 10px;
  left: auto;
}

.scan-busy {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(17, 20, 24, 0.6);
  font-size: 16px;
  font-weight: 700;
}

.scan-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 10px 12px 4px;
}

.scan-chip {
  min-height: 38px;
  padding: 0 14px;
  border: 1px solid #3a4452;
  border-radius: 999px;
  background: #1d232b;
  color: #f2f4f7;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}

.scan-chip.selected {
  border-color: #22d3ee;
  background: #0e3a44;
  color: #fff;
}

.scan-foot {
  display: flex;
  gap: 8px;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom));
}

.scan-button {
  flex: 1 1 0;
  min-height: 46px;
  border: 1px solid #3a4452;
  border-radius: 10px;
  background: #1d232b;
  color: #f2f4f7;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.scan-button.primary {
  flex: 1.4 1 0;
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.scan-dialog::backdrop {
  background: rgba(0, 0, 0, 0.8);
}

@media (max-width: 640px) {
  .scan-dialog {
    width: 100vw;
    height: 100dvh;
    margin: 0;
    border-radius: 0;
  }
}
