﻿@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&display=swap');
 
:root {
  /* SDDS corporate palette: blue, white, and neutral gray */
  --bg:            #f3f7fb;
  --bg-2:          #ffffff;
  --bg-3:          #e8f1f8;
  --surface:       #ffffff;
  --surface-2:     #eef5fa;
  --surface-3:     #dcebf5;
 
  /* aliases ที่ CSS ใช้อ้างถึงแต่เดิมไม่ได้ประกาศ — ทำให้ปุ่ม active/ฟิลเตอร์มองไม่เห็น */
  --accent:        #1478b9;
  /* --blue ถูกอ้างถึง 17 จุดทั้งใน styles.css และ enhancements.js แต่ไม่เคยประกาศไว้
     ค่าที่ใช้จึงเป็น invalid ทำให้พื้นปุ่มโปร่งใสจนตัวอักษรสีขาวหายไปทั้งปุ่ม */
  --blue:          #1478b9;
  --accent-light:  #dceef9;
  --accent-muted:  #e8f0fe;
  --ink-1:         #172433;
  --hover:         rgba(20,120,185,0.08);
  --shadow:        0 1px 3px rgba(15,40,70,0.10);

  --gold:          #1478b9;
  --gold-bright:   #0866a4;
  --gold-dim:      #5aa5d2;
  --gold-muted:    #dceef9;
  --gold-glow:     rgba(20,120,185,0.12);
 
  --ink:           #172433;
  --ink-2:         #536779;
  --ink-3:         #7b8d9d;
 
  --accent-teal:   #2a8a78;
  --accent-red:    #c44a3a;
  --accent-blue:   #3a6ea8;
 
  --line:          rgba(20,120,185,0.24);
  --line-subtle:   rgba(42,76,101,0.12);
 
  --shadow-card:   0 8px 24px rgba(30,83,119,0.08), 0 1px 3px rgba(30,83,119,0.08);
  --shadow-glow:   0 0 0 1px rgba(20,120,185,0.2), 0 8px 30px rgba(30,83,119,0.14);
 
  --radius:        0;
  --radius-lg:     0;
}
 
*, *::before, *::after { box-sizing: border-box; }

html {
  width: 100%;
  max-width: 100%;
  overflow-x: clip;
}
 
body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  overflow-x: clip;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Kanit', sans-serif;
  font-weight: 400;
  font-size: 14px;
  line-height: 1.6;
  letter-spacing: 0.01em;
}
 
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

.mobile-header,
.sidebar-backdrop,
.sidebar-close { display: none; }

.language-button {
  min-width: 44px;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--gold-bright);
  font-weight: 500;
}

.language-button:hover { background: var(--gold-muted); }

.login-screen {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  padding: 20px;
  overflow-x: hidden;
  overflow-y: auto;
  background: #eaf3f9;
}

.login-screen.is-hidden { display: none; }

/* Production auth gate: never expose the workspace before a verified session. */
body:not(.authenticated) .mobile-header,
body:not(.authenticated) #sidebar-backdrop,
body:not(.authenticated) #sidebar,
body:not(.authenticated) main.app-shell { display: none !important; }

.login-panel {
  position: relative;
  width: calc(100% - 8px);
  max-width: 430px;
  margin: auto;
  display: grid;
  gap: 18px;
  padding: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: #fff;
  box-shadow: var(--shadow-glow);
}

.login-language { position: absolute; top: 20px; right: 20px; }

.login-panel > img { width: 64px; height: 64px; object-fit: cover; border-radius: var(--radius); }
.login-panel h1 { margin: 3px 0 6px; color: var(--ink); font-size: 23px; font-weight: 500; }
.login-panel p { margin: 0; color: var(--ink-2); }
.login-panel label { display: grid; gap: 7px; color: var(--ink-2); }
.login-panel input, .login-panel select { width: 100%; }
 

/* ── Login card UI ────────────────────────────────── */
.login-brand { display: flex; align-items: center; gap: 14px; }
.login-brand img { width: 52px; height: 52px; object-fit: contain; border-radius: var(--radius); flex-shrink: 0; }
.inline-logo-wrap { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.inline-logo-wrap svg { display: block; border-radius: 0; }
.login-brand .inline-logo-wrap svg { width: 52px; height: 52px; }
.brand-mark .inline-logo-wrap svg { width: 100%; height: 100%; }
.mobile-brand .inline-logo-wrap svg { width: 32px; height: 32px; }
.login-brand h1 { margin: 2px 0 4px; color: var(--ink); font-size: 20px; font-weight: 600; }
.login-hint { margin: 0; font-size: 12px; color: var(--ink-3); }

.login-user-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.login-user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface-2); cursor: pointer; transition: all 0.15s; text-align: left;
}
.login-user-card:hover { background: var(--gold-muted); border-color: var(--gold); }
.login-user-card.selected { background: var(--gold-muted); border-color: var(--gold); }
.login-user-card-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--gold-muted);
  color: var(--gold-bright); font-weight: 700; font-size: 13px;
  display: grid; place-items: center; flex-shrink: 0;
}
.login-user-card-name { font-size: 12px; font-weight: 500; color: var(--ink); line-height: 1.3; }
.login-user-card-role { font-size: 11px; color: var(--ink-3); }

.login-role-row { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.login-role-badge {
  display: none; align-items: center; gap: 7px;
  padding: 6px 14px; border-radius: 0; background: var(--gold-muted);
  color: var(--gold-bright); font-size: 13px; font-weight: 600; border: 1px solid var(--gold);
}
.login-role-badge.visible { display: flex; }
.login-role-fallback { display: grid; gap: 5px; color: var(--ink-2); width: 100%; }
.login-role-fallback.hidden { display: none; }
.login-submit { width: 100%; font-size: 15px; padding: 12px; letter-spacing: 0.04em; }

/* ── Sidebar user info ─────────────────────────────── */
.sidebar-user-info {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin: 0 -4px 4px;
  border-radius: var(--radius); background: var(--bg);
  border: 1px solid var(--line);
}
.sidebar-user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--gold-muted); color: var(--gold-bright);
  font-weight: 700; font-size: 14px; display: grid; place-items: center; flex-shrink: 0;
}
.sidebar-user-info strong { display: block; font-size: 13px; color: var(--ink); line-height: 1.2; }
.sidebar-user-info span { font-size: 11px; color: var(--ink-3); }

/* ── Topbar user chip ──────────────────────────────── */
.topbar-user-chip {
  display: flex !important; align-items: center; gap: 7px;
  padding: 5px 12px !important; border-radius: 0;
  border: 1px solid var(--line) !important; background: var(--surface-2) !important;
}
.topbar-user-chip:hover { background: var(--gold-muted) !important; border-color: var(--gold) !important; }
#topbar-user-name { font-weight: 500; font-size: 13px; color: var(--ink); }
.topbar-user-role-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 0;
  background: var(--gold-muted); color: var(--gold-bright); font-weight: 600;
}

/* ── Topbar logout button ──────────────────────────── */
.topbar-logout-btn {
  display: flex !important;
  align-items: center;
  gap: 6px;
  padding: 6px 14px !important;
  border-radius: var(--radius) !important;
  border: 1px solid var(--line) !important;
  background: transparent !important;
  color: var(--ink-2) !important;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}
.topbar-logout-btn:hover {
  background: rgba(229, 68, 68, .08) !important;
  border-color: rgba(229, 68, 68, .4) !important;
  color: #e54444 !important;
}
.topbar-logout-btn svg { flex-shrink: 0; }

/* ── Metric card colors ────────────────────────────── */
.metric-blue  { border-top: 3px solid #1478b9 !important; }
.metric-blue strong { color: #1478b9; }
.metric-red   { border-top: 3px solid #c44a3a !important; }
.metric-red strong { color: #c44a3a; }
.metric-green { border-top: 3px solid #2a8a78 !important; }
.metric-green strong { color: #2a8a78; }
.metric-amber { border-top: 3px solid #b87d1a !important; }
.metric-amber strong { color: #b87d1a; }

/* ─── SIDEBAR ─────────────────────────────────────────── */
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 28px 16px;
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  z-index: 100;
  transition: transform 0.22s ease, width 0.22s ease;
  overflow: hidden;
}

/* Sidebar collapsed state */
body.sidebar-collapsed .sidebar { transform: translateX(-260px); }
body.sidebar-collapsed .app-shell { margin-left: 0; width: 100%; }

.sidebar-toggle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink-2);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}
.sidebar-toggle-btn:hover { background: var(--surface-2); color: var(--ink); }
.topbar-left { display: flex; align-items: center; gap: 12px; }
 
.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 6px;
}
 
.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 0;
  background: #1a3561;
  overflow: hidden;
}
/* CSS fallback logo — always visible, img overlays when loaded */
.brand-mark::after {
  content: 'SD';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: -0.5px;
  font-family: 'Kanit', Arial, sans-serif;
  pointer-events: none;
}
.brand-mark img {
  position: absolute;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 0;
  z-index: 1;
}
.brand-mark img[hidden], .brand-mark img.broken { display: none !important; }
 
.brand h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.03em;
}
 
.brand p {
  margin: 0;
  font-size: 10px;
  font-weight: 300;
  color: var(--gold);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
 
.nav { display: grid; flex: 1; min-height: 0; gap: 1px; overflow-y: auto; padding: 0 8px 16px; }

.nav-section-label {
  margin: 18px 4px 4px;
  color: var(--ink-3);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.nav-section-label:first-child { margin-top: 4px; }

.nav-item[hidden],
.nav-section-label[hidden],
.nav-group-toggle[hidden],
.nav-sub-item[hidden] { display: none !important; } /* บังคับซ่อนเมนูตามสิทธิ์ role */

.nav-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-2);
  text-align: left;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0.01em;
  transition: background 0.12s, color 0.12s;
  position: relative;
  cursor: pointer;
  width: 100%;
}

.nav-item:hover {
  background: var(--surface);
  color: var(--ink);
}

.nav-item.active {
  background: var(--gold-muted);
  color: var(--gold-bright);
  font-weight: 500;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0;
  background: var(--gold);
}
 
/* ─── SHELL ────────────────────────────────────────────── */
.app-shell {
  margin-left: 260px;
  width: calc(100% - 260px);
  min-width: 0;
  padding: 28px 32px;
  min-height: 100vh;
  transition: margin-left 0.22s ease, width 0.22s ease;
}
 
/* ─── TOPBAR ────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 28px;
}
 
.topbar h2 {
  margin: 4px 0 0;
  font-size: 26px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.02em;
}
 
.eyebrow {
  font-size: 10px;
  font-weight: 400;
  color: var(--gold);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
 
.brand h1, .brand p, .topbar h2, .topbar p, .panel h3 { margin: 0; }
 
.top-actions,
.modal-actions,
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
}
 
.panel-head {
  justify-content: space-between;
  margin-bottom: 18px;
}
 
/* ─── BUTTONS ────────────────────────────────────────────── */
.accent-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  padding: 0 16px;
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.04em;
  background: var(--accent);
  color: #fff;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
}
.accent-button:hover { background: var(--accent-dark, #1568a0); border-color: var(--accent-dark, #1568a0); box-shadow: 0 4px 16px rgba(27,127,196,.3); }
.accent-button.small { min-height: 32px; padding: 0 12px; font-size: 12px; }

.primary-button,
.ghost-button,
.icon-button {
  min-height: 38px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 16px;
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.04em;
  transition: all 0.15s;
}
 
.primary-button {
  background: linear-gradient(135deg, var(--gold-dim), var(--gold));
  color: #ffffff;
  border-color: var(--gold);
  font-weight: 600;
}
 
.primary-button:hover {
  background: linear-gradient(135deg, var(--gold), var(--gold-bright));
  box-shadow: 0 4px 16px rgba(20,120,185,0.24);
}
 
.primary-button.small {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
}
 
.ghost-button {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink-2);
}
 
.ghost-button:hover {
  border-color: var(--gold-dim);
  color: var(--ink);
  background: var(--surface-2);
}
 
.ghost-button.small {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
}
 
.icon-button {
  width: 38px;
  padding: 0;
  background: transparent;
  color: var(--ink-3);
  font-size: 20px;
  border-color: transparent;
}
 
.icon-button:hover { color: var(--ink); }
 
/* ─── VIEWS ────────────────────────────────────────────── */
.view { display: none; }
.view.active { display: block; }
 
/* ─── METRIC GRID ───────────────────────────────────────── */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.role-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-2);
}

.role-switcher span { font-size: 11px; }
.role-switcher select { border: 0; padding: 0 24px 0 0; background-color: transparent; color: var(--ink); }

.notification-wrap { position: relative; }

.notification-panel[hidden] { display: none !important; }

.notification-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 340px;
  max-height: 420px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(15, 40, 70, 0.14);
  z-index: 60;
}

.notification-panel-head {
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}

.notification-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.notification-item:last-child { border-bottom: 0; }
.notification-item:hover { background: rgba(21, 120, 190, 0.06); }
.notification-item-icon { flex: 0 0 auto; font-size: 16px; }
.notification-item-body { flex: 1; min-width: 0; }
.notification-item-body strong { display: block; font-size: 13px; color: var(--ink); line-height: 1.3; }
.notification-item-body small { font-size: 11px; color: var(--ink-3); }
.notification-item-count {
  flex: 0 0 auto;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #d94a4a;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
}

.notification-empty { padding: 18px 14px; margin: 0; font-size: 13px; color: var(--ink-3); text-align: center; }

.notification-button {
  position: relative;
  width: 40px;
  height: 38px;
  flex: 0 0 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.notification-button span {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 0;
  background: #d94a4a;
  color: #fff;
  font-size: 10px;
}

.user-profile-chip { display: flex; align-items: center; gap: 9px; min-height: 42px; max-width: 230px; padding: 5px 10px 5px 6px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink); text-align: left; }
.user-avatar { display: grid; place-items: center; width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%; background-color: var(--gold); background-position: center; background-size: cover; color: #fff; font-size: 12px; font-weight: 500; }
.user-avatar.large { width: 76px; height: 76px; flex-basis: 76px; font-size: 24px; }
.user-profile-copy { display: grid; min-width: 0; line-height: 1.25; }
.user-profile-copy strong { overflow: hidden; font-size: 12px; font-weight: 450; text-overflow: ellipsis; white-space: nowrap; }
.user-profile-copy small { overflow: hidden; color: var(--ink-3); font-size: 9px; font-weight: 300; text-overflow: ellipsis; white-space: nowrap; }

.system-intake-banner { background: var(--surface-2); border-color: var(--line); }

.brand-mark img { width: 100%; height: 100%; object-fit: cover; border-radius: 0; }

.timeline-kpis {
  margin-top: -6px;
}
 
.metric-card {
  display: grid;
  gap: 6px;
  padding: 20px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}

.clickable,
.clickable-row {
  cursor: pointer;
}

.clickable:hover,
.clickable-row:hover {
  outline: 1px solid var(--gold-dim);
}
 
.metric-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-dim), transparent);
  opacity: 0.5;
}
 
.metric-card span {
  color: var(--gold);
  font-size: 10px;
  font-weight: 400;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
 
.metric-card strong {
  font-size: 22px;
  font-weight: 600;
  color: var(--ink);
}
 
.metric-card small {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
}

/* Executive quarter dashboard */
.executive-quarter { margin-bottom: 20px; padding: 20px; border: 1px solid var(--line-subtle); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-card); }
.executive-quarter-head, .rank-label, .target-progress > div, .attention-item { display: flex; align-items: center; }
.executive-quarter-head { justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.executive-quarter-head h3 { margin: 3px 0; font-size: 19px; font-weight: 500; }
.executive-quarter-head small, .panel-head.compact small { color: var(--ink-3); font-weight: 300; }
.executive-period-label { min-width: 260px; color: var(--ink-2); font-size: 11px; }
.executive-period-label select { display: block; width: 100%; margin-top: 5px; }
.executive-kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 14px; }
.executive-kpi, .executive-chart-card { border: 1px solid var(--line-subtle); border-radius: var(--radius); background: var(--surface-2); }
.executive-kpi { display: grid; gap: 6px; min-height: 112px; padding: 16px; }
.executive-kpi span { color: var(--gold); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.executive-kpi strong { color: var(--ink); font-size: 20px; font-weight: 500; }
.executive-kpi small { color: var(--ink-3); font-size: 11px; font-weight: 300; }
.executive-kpi.negative { border-left: 3px solid #d94a4a; }
.executive-kpi.negative strong { color: #c43d3d; }
.executive-analysis-grid, .executive-breakdown-grid { display: grid; gap: 14px; margin-bottom: 14px; }
.executive-analysis-grid { grid-template-columns: 1.2fr .8fr; }
.executive-breakdown-grid { grid-template-columns: 1fr 1fr 1fr; }
.executive-chart-card { padding: 16px; }
.panel-head.compact { margin-bottom: 12px; }
.panel-head.compact h3 { margin: 0; font-size: 14px; font-weight: 450; }
.comparison-chart { display: grid; gap: 10px; }
.comparison-chart button { display: grid; grid-template-columns: 92px minmax(100px,1fr) 50px; gap: 10px; align-items: center; width: 100%; padding: 0; border: 0; background: transparent; color: var(--ink-2); text-align: left; }
.comparison-chart button > i, .rank-track, .target-progress > i { display: block; overflow: hidden; height: 9px; border-radius: 0; background: #dfeaf2; }
.comparison-chart button b, .rank-track i, .target-progress > i b { display: block; height: 100%; background: var(--gold); }
.comparison-chart button b.expense { background: #7d8d99; }
.comparison-chart button strong { text-align: right; color: var(--ink); font-weight: 450; }
.target-progress { display: grid; gap: 12px; width: 100%; padding: 4px 0 0; border: 0; background: transparent; text-align: left; }
.target-progress > span { display: flex; align-items: baseline; gap: 10px; }
.target-progress > span strong { color: var(--gold); font-size: 28px; font-weight: 500; }
.target-progress > span small { color: var(--ink-3); }
.target-progress > i { height: 14px; }
.target-progress > div { justify-content: space-between; color: var(--ink-2); font-size: 11px; }
.target-gap { display: flex; justify-content: space-between; gap: 12px; margin-top: 15px; padding-top: 12px; border-top: 1px solid var(--line); color: var(--ink-2); }
.target-gap strong { color: #c43d3d; font-weight: 500; }
.rank-list { display: grid; gap: 9px; }
.rank-row { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 5px 10px; width: 100%; padding: 0; border: 0; background: transparent; color: var(--ink); text-align: left; }
.rank-label { min-width: 0; gap: 7px; }
.rank-label strong { overflow: hidden; font-size: 12px; font-weight: 400; text-overflow: ellipsis; white-space: nowrap; }
.rank-label small { font-size: 10px; }
.rank-value { font-size: 11px; color: var(--ink-2); }
.rank-track { grid-column: 1 / -1; height: 5px; }
.attention-list { display: grid; gap: 8px; }
.attention-item { width: 100%; gap: 9px; padding: 9px; border: 1px solid var(--line-subtle); border-radius: 0; background: var(--surface); color: var(--ink); text-align: left; }
.attention-item > i { width: 7px; height: 7px; flex: 0 0 7px; border-radius: 50%; background: #d2a62d; }
.attention-item.bad > i { background: #d94a4a; }
.attention-item.good > i { background: #29a26a; }
.attention-item > span { display: grid; flex: 1; gap: 2px; }
.attention-item strong, .attention-item b { font-size: 11px; font-weight: 450; }
.attention-item small { color: var(--ink-3); font-size: 10px; font-weight: 300; }
.attention-item b { white-space: nowrap; }
.executive-sales-card { background: var(--surface); }
.executive-empty { padding: 32px; border: 1px dashed var(--line); color: var(--ink-3); text-align: center; }

/* Executive extra sections */
.executive-extra-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; margin-top: 14px; }
.exec-cash-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line-subtle); font-size: 13px; }
.exec-cash-row:last-of-type { border-bottom: none; }
.exec-cash-row.total { border-top: 1.5px solid var(--line); margin-top: 4px; padding-top: 10px; font-size: 14px; font-weight: 500; }
.exec-cash-row span { color: var(--ink-2); }
.exec-cash-note { font-size: 11px; color: var(--ink-3); margin-top: 8px; line-height: 1.5; }
.exec-recv-list { display: grid; gap: 7px; }
.exec-recv-row { display: grid; grid-template-columns: 110px 1fr 40px 90px; align-items: center; gap: 8px; font-size: 12px; }
.exec-recv-name { color: var(--ink); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exec-recv-bar-wrap { background: var(--line-subtle); border-radius: 0; height: 8px; overflow: hidden; }
.exec-recv-bar { display: block; height: 100%; background: var(--gold); border-radius: 0; }
.exec-recv-pct { color: var(--ink-3); text-align: right; }
.exec-recv-amt { color: var(--ink); text-align: right; white-space: nowrap; }
.exec-quarterly-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.exec-quarterly-table th { text-align: left; color: var(--ink-3); font-size: 11px; font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.exec-quarterly-table td { padding: 6px 8px; border-bottom: 1px solid var(--line-subtle); }
.exec-quarterly-table tr:last-child td { border-bottom: none; }
.exec-q-summary td { font-weight: 600; background: var(--surface-2); }

/* ── Attachment Widget ──────────────────────────────────────────────── */
.attach-widget { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 10px 12px; }
.attach-file-list:not(:empty) { margin-bottom: 8px; }
.attach-file-list { display: flex; flex-direction: column; gap: 5px; }
.attach-file-item { display: flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--line-subtle); border-radius: 0; padding: 5px 6px 5px 10px; font-size: 12px; }
.attach-type-badge { font-size: 10px; font-weight: 700; color: var(--ink-3); background: var(--surface-3); border-radius: 0; padding: 1px 5px; flex-shrink: 0; letter-spacing: 0.04em; }
.attach-file-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); }
.attach-remove-btn { background: none; border: none; cursor: pointer; color: var(--ink-3); font-size: 16px; line-height: 1; padding: 2px 4px; border-radius: 0; flex-shrink: 0; }
.attach-remove-btn:hover { background: #fee2e2; color: #dc2626; }
.attach-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.attach-add-btn { display: inline-flex; align-items: center; gap: 5px; padding: 6px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-1); cursor: pointer; font-size: 12px; color: var(--ink-2); }
.attach-add-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--surface-2); }
.attach-hint { font-size: 11px; color: var(--ink-3); }
.attach-photo-thumb {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
.attach-photo-thumb figure {
  margin: 0;
  overflow: hidden;
  border: 1px solid var(--line-subtle);
  border-radius: 0;
  background: var(--surface-2);
}
.attach-photo-thumb img {
  width: 100%;
  height: 92px;
  display: block;
  object-fit: cover;
}
.attach-photo-thumb figcaption {
  overflow: hidden;
  padding: 5px 6px;
  color: var(--ink-3);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Executive analytics */
.executive-filter-panel { margin-bottom: 16px; }
.executive-filter-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.executive-filter-head h3 { margin: 3px 0 0; font-size: 18px; font-weight: 500; }
.executive-filters { display: grid; grid-template-columns: .7fr 1.2fr 1fr 1.2fr; gap: 12px; }
.executive-filters label { color: var(--ink-2); font-size: 11px; font-weight: 300; }
.executive-filters select { width: 100%; margin-top: 5px; }
.analytics-metrics { margin-bottom: 16px; }
.analytics-no-data { grid-column: 1 / -1; }
.analytics-main-grid { margin-bottom: 16px; }
.analytics-table-panel, .pm-target-panel { margin-bottom: 16px; }
.monthly-chart { display: grid; gap: 13px; }
.monthly-chart-row { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 12px; align-items: center; width: 100%; padding: 0; border: 0; background: transparent; color: var(--ink); text-align: left; }
.monthly-chart-row > strong { font-size: 12px; font-weight: 400; }
.monthly-bars { display: grid; gap: 5px; }
.monthly-bars > i { position: relative; display: block; min-height: 21px; overflow: hidden; border-radius: 0; background: #e2edf4; font-style: normal; }
.monthly-bars b { position: absolute; inset: 0 auto 0 0; min-width: 2px; background: var(--gold); }
.monthly-bars b.secondary { background: #8499a8; }
.monthly-bars em { position: relative; z-index: 1; display: block; padding: 3px 7px; color: var(--ink); font-size: 10px; font-style: normal; }
.analytics-target-ring { position: relative; display: grid; place-items: center; width: 154px; height: 154px; margin: 4px auto 18px; border-radius: 50%; background: conic-gradient(var(--gold) var(--progress), #dfeaf2 0); }
.analytics-target-ring::before { content: ""; position: absolute; width: 116px; height: 116px; border-radius: 50%; background: var(--surface); }
.analytics-target-ring > div { position: relative; z-index: 1; display: grid; gap: 1px; text-align: center; }
.analytics-target-ring strong { font-size: 25px; font-weight: 500; color: var(--ink); }
.analytics-target-ring span { color: var(--ink-3); font-size: 11px; }
.analytics-target-values { display: grid; gap: 7px; }
.analytics-target-values p { display: flex; justify-content: space-between; gap: 12px; margin: 0; padding: 8px 0; border-bottom: 1px solid var(--line-subtle); }
.analytics-target-values span { color: var(--ink-2); font-size: 11px; }
.analytics-target-values strong { font-size: 12px; font-weight: 450; }
.pm-target-tools { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.compact-checkbox { min-height: 38px; margin: 0; padding: 8px 10px; border: 1px solid var(--line); border-radius: 0; background: var(--surface-2); color: var(--ink-2) !important; font-size: 11px !important; }
.pm-target-input { width: 160px; min-width: 130px; }
.pm-status-select { width: 150px; min-width: 128px; padding: 8px 10px; font-size: 12px; }
.pm-target-inactive { background: rgba(226, 237, 244, .45); color: var(--ink-3); }
.pm-target-inactive strong { color: var(--ink-2); }
.mini-progress { display: inline-block; width: 72px; height: 6px; margin-right: 7px; overflow: hidden; border-radius: 0; background: #dfeaf2; vertical-align: middle; }
.mini-progress i { display: block; height: 100%; background: var(--gold); }
.dimension-filter { min-width: 230px; color: var(--ink-2); font-size: 11px; }
.dimension-filter select { display: block; width: 100%; margin-top: 5px; }
.analytics-dimension-panel tfoot th { border-top: 2px solid var(--line); background: var(--surface-2); color: var(--ink); font-weight: 500; }
.status.employment-active { background: #e7f6ef; color: #16764b; }
.status.employment-on_leave { background: #fff4d8; color: #8a6412; }
.status.employment-suspended, .status.employment-inactive { background: #edf1f4; color: #62727e; }
.status.employment-resigned { background: #fdeaea; color: #b33a3a; }
.choice-field { min-width: 0; margin: 0; padding: 11px; border: 1px solid var(--line); border-radius: var(--radius); }
.choice-field legend { padding: 0 5px; color: var(--ink-3); font-size: 10px; font-weight: 300; letter-spacing: .04em; text-transform: uppercase; display: flex; align-items: center; }
.choice-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.view-access-field legend { text-transform: none; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.view-access-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); margin-top: 8px; }
.view-access-hint { font-size: 11px; color: var(--ink-3); margin: 4px 0 0; }
.view-access-dim { opacity: 0.5; }
.choice-option { display: flex !important; grid-template-columns: none !important; align-items: center; gap: 7px !important; min-height: 34px; padding: 6px 8px; border: 1px solid var(--line-subtle); border-radius: 0; background: var(--surface-2); color: var(--ink-2) !important; font-size: 11px !important; letter-spacing: 0 !important; text-transform: none !important; }
.choice-option input, .checkbox-label input { width: 17px !important; height: 17px !important; min-height: 17px; flex: 0 0 17px; margin: 0; accent-color: var(--gold); }
.checkbox-label { display: flex !important; grid-template-columns: none !important; align-items: center; align-self: center; gap: 8px !important; min-height: 42px; text-transform: none !important; }
.document-signature-controls { margin: 14px 0; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.document-signature-controls legend { padding: 0 6px; color: var(--blue); font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; }
.profile-photo-admin { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px; border: 1px solid var(--line-subtle); background: var(--surface-2); color: var(--ink-2); font-size: 11px; }

/* ── User Image Upload Section ──────────────────────── */
.user-image-upload-section { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.user-image-upload-block { display: flex; gap: 16px; align-items: flex-start; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.user-image-preview-wrap { flex-shrink: 0; }
.user-avatar-preview { width: 80px; height: 80px; border-radius: 50%; background: var(--gold); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 28px; font-weight: 700; background-size: cover; background-position: center; border: 2px solid var(--line); }
.signature-preview-wrap { width: 140px; height: 70px; border: 1.5px dashed var(--line); border-radius: var(--radius); background: #fff; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.user-signature-preview { max-width: 136px; max-height: 66px; object-fit: contain; display: block; }
.user-signature-placeholder { font-size: 11px; color: var(--ink-3); text-align: center; padding: 4px; }
.user-image-upload-controls { flex: 1; display: flex; flex-direction: column; gap: 8px; }
.image-upload-label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .06em; }
.image-upload-hint { font-size: 11px; font-weight: 400; color: var(--ink-3); text-transform: none; letter-spacing: 0; }
.image-upload-input { display: none; }
.image-upload-btn { display: inline-block; padding: 6px 14px; border-radius: var(--radius); border: 1px solid var(--gold); color: var(--gold); font-size: 12px; font-weight: 600; cursor: pointer; background: transparent; transition: background .15s; width: fit-content; }
.image-upload-label:has(.image-upload-input:focus) .image-upload-btn, .image-upload-btn:hover { background: rgba(180,140,60,.1); }
@media (max-width: 680px) { .user-image-upload-section { grid-template-columns: 1fr; } }
.profile-preview { display: flex; align-items: center; gap: 16px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.profile-preview > div { display: grid; gap: 4px; }
.profile-preview strong { font-size: 16px; font-weight: 500; }
.profile-preview small { color: var(--ink-3); }
.danger-button { color: #b33a3a; border-color: #efc9c9; }
button:disabled { cursor: not-allowed; opacity: .48; }
 
/* ─── CONTENT GRID ──────────────────────────────────────── */
.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(300px, 0.8fr);
  gap: 18px;
}
 
/* ─── PANEL ─────────────────────────────────────────────── */
.panel {
  padding: 20px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-card);
}
 
.panel h3 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-2);
  word-break: keep-all;
  overflow-wrap: normal;
}
 
/* ─── FORM ELEMENTS ─────────────────────────────────────── */
select, input, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--bg-3);
  color: var(--ink);
  font-family: 'Kanit', sans-serif;
  font-size: 13px;
  transition: border-color 0.15s;
}
 
select:focus, input:focus, textarea:focus {
  outline: none;
  border-color: var(--gold-dim);
  box-shadow: 0 0 0 2px rgba(20,120,185,0.12);
}
 
textarea {
  padding: 10px 12px;
  resize: vertical;
}
 
/* ─── TABLE ─────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
.dense-table {
  min-width: 1180px;
}
.dense-table th,
.dense-table td {
  white-space: nowrap;
  font-size: 12px;
}
.dense-table td:nth-child(3) {
  white-space: normal;
  min-width: 240px;
}

/* ─── SETTINGS ───────────────────────────────────────────── */
.settings-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(360px, 1fr);
  gap: 18px;
  align-items: start;
}

.settings-users-panel {
  grid-column: 1 / -1;
}

.settings-list,
.settings-table-wrap {
  margin-top: 16px;
}

.settings-table-wrap td:last-child {
  text-align: right;
  white-space: nowrap;
}

.settings-user-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.settings-actions-cell {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

#settings-user-companies {
  min-height: 42px;
}
 
table {
  width: 100%;
  border-collapse: collapse;
}
 
th, td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line-subtle);
  text-align: left;
  white-space: nowrap;
}

/* ── เอกสารที่พิมพ์ออกไปต้องตัดบรรทัดในช่องตัวเอง ─────────────
   กฎ nowrap ด้านบนตั้งไว้ให้ตารางรายการบนหน้าจอไม่ฉีกคำ
   แต่มันครอบทุก td ในระบบ รวมถึงตารางในใบเอกสารด้วย
   ข้อความไทยยาว ๆ (ไม่มีช่องว่างให้เบรก) จึงลากทะลุออกนอกช่อง
   ไปทับคอลัมน์ข้าง ๆ เวลาพิมพ์ออกมา ต้องปลดเฉพาะใบเอกสาร */
.document-page th, .document-page td,
.receipt-page th, .receipt-page td,
.sub-form-table th, .sub-form-table td,
.contractor-document-page th, .contractor-document-page td,
.expense-paper-page th, .expense-paper-page td {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* ยกเว้นช่องที่ต้องอยู่บรรทัดเดียวจริง ๆ — วันที่และตัวเลขเงิน */
.sub-form-table .sub-form-date-cell,
.sub-form-table .sub-form-base,
.sub-form-table .sub-form-vat,
.sub-form-table .sub-form-amount,
.document-page td.doc-cell-currency2 {
  white-space: nowrap;
}
 
th {
  color: var(--gold);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  background: var(--bg-3);
}
 
td { font-size: 13px; }
 
tbody tr:hover { background: var(--surface-2); }
 
/* ─── TAGS / STATUS ─────────────────────────────────────── */
.tag, .status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 0 10px;
  border-radius: 0;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
}
 
.good { color: #4ecb8a; font-weight: 600; }
.bad  { color: var(--accent-red); font-weight: 600; }
 
/* ─── QUEUE / RECORD LISTS ──────────────────────────────── */
.queue-list, .record-list {
  display: grid;
  gap: 8px;
}
 
.queue-item, .record {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius);
  background: var(--bg-3);
  transition: border-color 0.15s;
}
 
.queue-item:hover, .record:hover {
  border-color: var(--gold-dim);
}
 
.queue-item strong {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--gold-muted);
  color: var(--gold);
  font-size: 20px;
  flex-shrink: 0;
}
 
.queue-item div, .record div {
  display: grid;
  gap: 3px;
}
 
.queue-item small, .record small {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
}
 
.record > strong { white-space: nowrap; color: var(--gold-bright); }
 
.record-numbers {
  justify-items: end;
  color: var(--ink-3);
  font-size: 12px;
}
 
.record-numbers strong { color: var(--ink); }
 
.record-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}
 
/* ─── EXPORT ─────────────────────────────────────────────── */
.export-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
 
.export-card {
  display: grid;
  gap: 5px;
  min-height: 88px;
  padding: 16px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius);
  background: var(--bg-3);
  color: var(--ink);
  text-align: left;
  transition: all 0.15s;
}
 
.export-card:hover {
  border-color: var(--gold-dim);
  background: var(--surface);
  box-shadow: var(--gold-glow) 0 0 0 1px;
}
 
.export-card strong { font-size: 13px; font-weight: 500; }
 
.export-card span, .backup-actions p {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
  line-height: 1.45;
}
 
.backup-actions {
  display: grid;
  gap: 12px;
}

.accounting-grid {
  grid-template-columns: minmax(0, 1.85fr) minmax(220px, 0.38fr);
}

.accounting-guide {
  display: grid;
  gap: 9px;
  color: var(--ink-2);
  font-size: 13px;
  line-height: 1.5;
}

.accounting-guide strong {
  color: var(--gold-bright);
  font-size: 16px;
  font-weight: 600;
}

.accounting-guide p,
.accounting-guide ul {
  margin: 0;
}

.accounting-guide ul {
  padding-left: 16px;
}

.accounting-period-panel {
  display: grid;
  gap: 12px;
  margin: 14px 0 16px;
  padding: 14px;
  border: 1px solid #cfe0f7;
  border-radius: 8px;
  background: #f7fbff;
}

.accounting-period-controls {
  display: grid;
  grid-template-columns: 1.3fr 0.72fr 0.9fr 1fr;
  gap: 10px;
}

.accounting-period-controls label {
  display: grid;
  gap: 6px;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 400;
}

.accounting-period-summary {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.accounting-period-summary article {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.accounting-period-summary span {
  color: var(--ink-3);
  font-size: 11px;
}

.accounting-period-summary strong {
  color: var(--ink);
  font-size: 14px;
  white-space: nowrap;
}

.accounting-period-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.compact-head {
  align-items: flex-start;
}

.compact-head p {
  margin: 4px 0 0;
  color: var(--ink-3);
  font-size: 12px;
}

.accounting-match-panel {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.accounting-match-summary {
  display: grid;
  justify-items: end;
  gap: 2px;
  min-width: 140px;
  color: var(--ink-2);
}

.accounting-match-summary span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}

.accounting-match-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.accounting-match-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}

.accounting-match-item strong {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--ink);
}

.accounting-match-item strong span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.accounting-match-item small {
  display: block;
  margin-top: 4px;
  color: var(--ink-3);
}

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

.accounting-match-actions strong {
  color: var(--ink);
  white-space: nowrap;
}

.accounting-match-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.accounting-match-chip.matched {
  background: #e5f8ee;
  color: #147343;
}

.accounting-match-chip.pending {
  background: #eef2f7;
  color: #64748b;
}

.ghost-button.tiny {
  min-height: 28px;
  padding: 4px 10px;
  font-size: 12px;
}

.accounting-detail-match {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  align-items: center;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid #bed3f4;
  border-radius: 8px;
  background: #f4f8ff;
}

.accounting-detail-match strong {
  color: var(--accent);
}

.accounting-detail-match span {
  color: var(--ink-2);
}

.accounting-detail-match.matched {
  border-color: #b9ead0;
  background: #f0fbf5;
}

.accounting-detail-match.pending {
  border-color: var(--line);
  background: #f8fafc;
}

.accounting-filters {
  display: grid;
  grid-template-columns: 1.1fr 0.9fr 1.25fr 0.85fr 0.85fr minmax(220px, 1.35fr);
  gap: 10px;
  margin: 0 0 14px;
}

.accounting-filters label {
  display: grid;
  gap: 6px;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 400;
}

.accounting-filters .filter-search {
  min-width: 0;
}

/* QT detail — attachment banner */
.qt-detail-attach-banner {
  background: var(--surface, #f0f7ff);
  border: 1.5px solid #93c5fd;
  border-radius: 0;
  padding: 12px 16px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.qt-attach-header {
  font-size: 11px;
  font-weight: 700;
  color: #1a5fa8;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.qt-attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.qt-attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #fff;
  border: 1px solid #93c5fd;
  border-radius: 0;
  padding: 4px 12px;
  font-size: 12px;
  color: #1d4ed8;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: default;
  transition: background 0.15s;
}
.qt-attach-chip:hover { background: #dbeafe; }

.detail-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
}

/* ─── PROJECT CENTER ────────────────────────────────────── */
.project-center-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 0.35fr) repeat(2, minmax(150px, 0.35fr)) auto;
  gap: 12px;
  align-items: end;
  margin: 10px 0 18px;
}

.project-card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(260px, 1fr));
  gap: 18px;
}

.project-card {
  display: grid;
  gap: 14px;
  min-height: 250px;
  padding: 22px;
  border: 1px solid var(--line-subtle);
  border-radius: 0;
  background: #fff;
  box-shadow: 0 14px 34px rgba(11, 41, 64, 0.08);
  cursor: pointer;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.project-card:hover {
  transform: translateY(-2px);
  border-color: var(--brand);
  box-shadow: 0 18px 42px rgba(0, 114, 188, 0.14);
}

.project-card-head,
.project-card-foot,
.project-card-meta,
.project-progress div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.project-card-mark {
  display: inline-grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 0;
  background: var(--brand);
  color: #fff;
  font-size: 18px;
  font-weight: 600;
}

.project-color-1 { background: #8057e9; }
.project-color-2 { background: #ff9638; }
.project-color-3 { background: #33c47b; }
.project-color-4 { background: #13a6b8; }

.project-card h3 {
  margin: 0;
  color: var(--ink);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.25;
}

.project-card p {
  min-height: 40px;
  margin: 0;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 300;
  line-height: 1.55;
}

.project-progress {
  display: grid;
  gap: 7px;
}

.project-progress span,
.project-card-meta,
.project-card-foot,
.project-budget-strip span {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
}

.project-progress i {
  display: block;
  height: 7px;
  overflow: hidden;
  border-radius: 0;
  background: #edf2f7;
}

.project-progress b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #16a6b7, #36c486);
}

.project-budget-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px;
  border-radius: 0;
  background: #f2f8fc;
}

.project-budget-strip div {
  display: grid;
  gap: 3px;
}

.project-budget-strip strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.project-detail-hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
  padding: 16px;
  border-radius: 0;
  background: linear-gradient(135deg, #17366c, #24457f);
  color: #fff;
}

.project-detail-hero h3 {
  margin: 4px 0;
  color: #fff;
  font-size: 22px;
  font-weight: 600;
}

.project-detail-hero p,
.project-detail-hero span {
  margin: 0;
  color: rgba(255,255,255,0.78);
  font-size: 12px;
  font-weight: 300;
}

.project-detail-hero .project-card-mark {
  background: #12a8be;
}

.project-detail-summary {
  grid-template-columns: repeat(3, minmax(120px, 1fr));
}

.project-full-workspace {
  display: grid;
  gap: 18px;
}

.project-full-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  gap: 18px;
  align-items: start;
}

.project-full-main,
.project-full-side {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.project-full-side {
  position: sticky;
  top: 0;
}

.project-chart-card,
.project-calendar-card,
.project-timeline-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line-subtle);
  border-radius: 0;
  background: #fff;
  box-shadow: 0 12px 28px rgba(11, 41, 64, 0.06);
}

.project-chart-card > div:first-child,
.project-timeline-card > div:first-child,
.project-calendar-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.project-chart-card strong,
.project-calendar-head strong,
.project-timeline-card strong {
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}

.project-chart-card span,
.project-calendar-head span,
.project-timeline-card span {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
}

.project-chart-row {
  display: grid;
  grid-template-columns: 105px minmax(0, 1fr) 92px;
  gap: 10px;
  align-items: center;
}

.project-chart-row i {
  height: 10px;
  overflow: hidden;
  border-radius: 0;
  background: #edf2f7;
}

.project-chart-row b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--brand);
}

.project-chart-row strong {
  text-align: right;
  font-size: 12px;
}

.chart-cost b { background: #db4939; }
.chart-contractor b { background: #ff9638; }
.chart-billing b { background: #8057e9; }
.chart-payment b { background: #33c47b; }
.chart-outstanding b { background: #f0bd37; }

.project-calendar-weekdays,
.project-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.project-calendar-weekdays span {
  padding: 4px;
  color: var(--ink-3);
  font-size: 10px;
  text-align: center;
}

.project-calendar-grid {
  overflow: hidden;
  border: 1px solid var(--line-subtle);
  border-radius: 0;
}

.project-calendar-grid article {
  min-height: 70px;
  padding: 6px;
  border-right: 1px solid var(--line-subtle);
  border-bottom: 1px solid var(--line-subtle);
  background: #f8fafc;
}

.project-calendar-grid article.today {
  background: #fff7e1;
}

.project-calendar-grid article strong {
  display: block;
  color: var(--ink);
  font-size: 11px;
  font-weight: 500;
}

.project-calendar-date-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 5px;
}

.project-calendar-date-row button {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1px solid #b9d8ec;
  border-radius: 50%;
  background: #fff;
  color: var(--brand);
  font-size: 12px;
  cursor: pointer;
}

.project-calendar-grid article > button {
  display: block;
  width: 100%;
  overflow: hidden;
  margin-bottom: 3px;
  padding: 2px 4px;
  border: 0;
  border-radius: 0;
  background: #e5f4fb;
  color: var(--brand);
  font-size: 9px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.project-calendar-grid article > button:hover {
  filter: brightness(0.96);
}

.project-calendar-grid article > button.event-done,
.project-calendar-grid article > button.event-payment { background: #e8f8f0; color: #13804b; }
.project-calendar-grid article > button.event-delayed,
.project-calendar-grid article > button.event-credit-note { background: #fff0ee; color: #b63628; }
.project-calendar-grid article > button.event-cost,
.project-calendar-grid article > button.event-po,
.project-calendar-grid article > button.event-contractor { background: #fff5e8; color: #b75e00; }
.project-calendar-grid article > button.event-billing { background: #f1edff; color: #5f3bd0; }
.project-calendar-grid article > button.event-meeting { background: #e9f7ff; color: #0072bc; }
.project-calendar-grid article > button.event-quotation { background: #eef9f0; color: #197149; }

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

.project-doc-grid article,
.project-doc-grid button {
  display: grid;
  gap: 5px;
  padding: 12px;
  border: 1px solid var(--line-subtle);
  border-radius: 0;
  background: #f8fafc;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease;
}

.project-doc-grid button:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 24px rgba(0, 114, 188, 0.12);
}

.project-doc-grid article.done,
.project-doc-grid button.done {
  border-color: rgba(50, 196, 123, 0.45);
  background: #f0fbf6;
}

.project-doc-grid article.pending,
.project-doc-grid button.pending {
  border-color: rgba(219, 73, 57, 0.28);
  background: #fff8f7;
}

.project-doc-grid strong {
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.project-doc-grid span,
.project-doc-grid small {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
}

.project-doc-grid em {
  color: var(--brand);
  font-size: 10px;
  font-style: normal;
  font-weight: 500;
}

.project-doc-detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
  padding: 12px;
  border-radius: 0;
  background: #f2f8fc;
}

.project-doc-detail-head div {
  display: grid;
  gap: 3px;
}

.project-doc-detail-head strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
}

.project-doc-detail-head span {
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 300;
}

.project-doc-record-list {
  display: grid;
  gap: 10px;
}

.project-doc-record {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line-subtle);
  border-radius: 0;
  background: #fff;
}

.project-doc-record > div:first-child {
  display: grid;
  gap: 4px;
}

.project-doc-record strong {
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}

.project-doc-record small {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
}

.project-doc-record > b {
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
}

.project-doc-actions {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.project-detail-timeline {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.project-timeline-event {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 12px;
  padding: 11px 12px;
  border-left: 4px solid var(--brand);
  border-radius: 0;
  background: #f8fafc;
}

.project-timeline-event.event-done { border-color: #33c47b; }
.project-timeline-event.event-delayed { border-color: #db4939; }
.project-timeline-event.event-cost { border-color: #ff9638; }
.project-timeline-event.event-billing { border-color: #8057e9; }

.project-timeline-event > span {
  color: var(--brand);
  font-size: 12px;
  font-weight: 500;
}

.project-timeline-event strong {
  display: block;
  margin-bottom: 3px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
}

.project-timeline-event small {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
}

.check-row {
  display: flex !important;
  grid-template-columns: none !important;
  align-items: center;
  gap: 9px !important;
  color: var(--ink-2);
  text-transform: none !important;
}

.check-row input {
  width: auto;
}
 
.import-box {
  display: grid;
  gap: 6px;
  padding: 14px;
  border: 1px dashed var(--gold-dim);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 400;
  cursor: pointer;
  transition: background 0.15s;
}
 
.import-box:hover { background: var(--gold-muted); color: var(--ink-2); }
 
/* ─── TIMELINE ───────────────────────────────────────────── */
.timeline-list { display: grid; gap: 8px; }
 
.timeline-item {
  display: grid;
  grid-template-columns: 18px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius);
  background: var(--bg-3);
}
 
.timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold-dim);
  box-shadow: 0 0 0 3px rgba(140,112,52,0.2);
}
 
.timeline-item.done .timeline-dot {
  background: #4ecb8a;
  box-shadow: 0 0 0 3px rgba(78,203,138,0.2);
}
 
.timeline-item.delayed .timeline-dot {
  background: var(--accent-red);
  box-shadow: 0 0 0 3px rgba(196,74,58,0.2);
}
 
.timeline-item div:nth-child(2) { display: grid; gap: 3px; }
 
.timeline-item span:not(.status) {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
}

/* ─── WORK CALENDAR ─────────────────────────────────────── */
.calendar-panel { overflow: auto; }
.calendar-head { align-items: flex-start; }
.calendar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.calendar-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(220px, 0.7fr) minmax(160px, 0.45fr);
  gap: 12px;
  align-items: end;
  margin-bottom: 14px;
}

.calendar-toolbar h2 {
  margin: 0;
  color: var(--ink);
  font-size: 30px;
  font-weight: 500;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--ink-2);
  font-size: 12px;
}

.calendar-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cal-dot {
  width: 12px;
  height: 12px;
  border-radius: 0;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(126px, 1fr));
}

.calendar-weekdays {
  border-bottom: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 12px;
  text-align: center;
}

.calendar-weekdays span { padding: 10px 6px; }

.calendar-grid {
  min-width: 882px;
  border-left: 1px solid var(--line-subtle);
  border-top: 1px solid var(--line-subtle);
}

.calendar-day {
  min-height: 154px;
  padding: 9px;
  border-right: 1px solid var(--line-subtle);
  border-bottom: 1px solid var(--line-subtle);
  background: var(--bg-3);
}

.calendar-day.muted { background: rgba(255,255,255,0.025); }
.calendar-day.today { box-shadow: inset 0 0 0 2px var(--brand-blue); }

.calendar-date {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  margin-bottom: 8px;
  border-radius: 0;
  color: var(--ink);
  font-size: 18px;
  font-weight: 500;
}

.calendar-day.today .calendar-date {
  background: var(--brand-blue);
  color: #fff;
}

.calendar-events {
  display: grid;
  gap: 6px;
}

.calendar-event {
  display: grid;
  gap: 2px;
  width: 100%;
  min-height: 54px;
  padding: 7px 8px;
  border: 0;
  border-radius: 0;
  color: #fff;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
}

.calendar-event strong,
.calendar-event span,
.calendar-event em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-event strong { font-size: 12px; font-weight: 500; }
.calendar-event span { font-size: 11px; opacity: 0.86; }
.calendar-event em { font-size: 10px; font-style: normal; opacity: 0.76; }

.stage-design { background: #6e3fc5; }
.stage-production { background: #2f7d4e; }
.stage-installation { background: #1b6f96; }
.stage-billing { background: #a56b1f; }
.stage-meeting { background: #0072bc; }
.stage-default { background: #516073; }
.status-delayed { background: #c5473c; }
.status-done { background: #2f9c71; }
 
/* ─── LINE INTAKE ────────────────────────────────────────── */
.line-workspace {
  display: grid;
  grid-template-columns: minmax(420px, 0.86fr) minmax(560px, 1.14fr);
  gap: 18px;
  align-items: start;
}
 
.line-form-panel {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 60px);
  overflow: auto;
}

#line-view .form-grid.two {
  align-items: start;
}

#line-view .line-expense-type-field {
  order: 1;
}

/* ตารางรายการรายจ่าย — คุมความกว้างไม่ให้ล้นกรอบ */
.line-items-wrap { width: 100%; max-width: 100%; overflow-x: auto; }

.line-items-table {
  table-layout: fixed;
  width: 100% !important;
  max-width: 100%;
  min-width: 0 !important;
  border-collapse: collapse;
}

.line-items-table th,
.line-items-table td {
  padding: 5px 6px;
  min-width: 0;
  overflow: hidden;
  vertical-align: middle;
  box-sizing: border-box;
}

.line-items-table th { font-size: 11.5px; white-space: nowrap; }

/* ── ตารางเบิกจ่ายแนวขวาง 10 คอลัมน์ ──────────────────────────
   วันที่ · หมวดหมู่ · รายละเอียด · เอกสารแนบ · เลขที่ · ร้านค้า · ก่อน VAT · VAT · รวม · ลบ
   รวม 100% พอดีกรอบบนจอคอม ถ้าจอแคบกว่า 1100px ค่อยเลื่อนแนวนอน */
.line-items-table th:nth-child(1),
.line-items-table td:nth-child(1) { width: 9.5%; }
.line-items-table th:nth-child(2),
.line-items-table td:nth-child(2) { width: 12%; }
.line-items-table th:nth-child(3),
.line-items-table td:nth-child(3) { width: 20%; }
.line-items-table th:nth-child(4),
.line-items-table td:nth-child(4) { width: 11%; }
.line-items-table th:nth-child(5),
.line-items-table td:nth-child(5) { width: 10%; }
.line-items-table th:nth-child(6),
.line-items-table td:nth-child(6) { width: 13.5%; }
.line-items-table th:nth-child(7),
.line-items-table td:nth-child(7) { width: 8%; }
.line-items-table th:nth-child(8),
.line-items-table td:nth-child(8) { width: 7%; }
.line-items-table th:nth-child(9),
.line-items-table td:nth-child(9) { width: 8%; }
.line-items-table th:nth-child(10),
.line-items-table td:nth-child(10) { width: 32px; text-align: center; padding: 5px 3px; overflow: visible; }

.line-items-table th { font-size: 12.5px; white-space: normal; line-height: 1.3; font-weight: 600; }

/* จอแคบกว่านี้ให้เลื่อนแนวนอนแทนการบีบช่องจนกรอกไม่ได้ */
@media (max-width: 1100px) {
  .line-items-wrap { overflow-x: auto; }
  .line-items-table { min-width: 1040px !important; width: 1040px !important; table-layout: fixed; }
}

/* ปุ่มแนบไฟล์ในแถว */
.line-items-table .sri-file-btn {
  width: 100%; font-size: 11.5px; padding: 4px 4px; height: 28px;
  white-space: nowrap; overflow: hidden;
}
.line-items-table .sri-file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-items-table td.sri-file-cell { overflow: hidden; }

.line-items-table td:nth-child(4) input { text-align: right; }
.line-items-table .sri-del {
  padding: 0;
  line-height: 1;
  width: 22px;
  height: 22px;
  min-width: 0;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ฟอร์มฝั่งซ้ายไม่ให้ช่องดันกรอบ และยังเลื่อนลงไปถึงส่วนแนบรูปได้ */
#line-view .line-form-panel { min-width: 0; overflow: auto; }
#line-view .form-grid.two > label,
#line-view .form-grid.two > div { min-width: 0; }
#line-view .form-grid.two input,
#line-view .form-grid.two select,
#line-view .form-grid.two textarea { max-width: 100%; box-sizing: border-box; }

/* รูปแนบ — เรียงเป็นตารางย่อ หลายรูปไม่ล้น */
#receipt-photo-preview {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 8px;
  margin-top: 8px;
}
#receipt-photo-preview figure { margin: 0; text-align: center; }
#receipt-photo-preview img {
  width: 100%;
  height: 68px;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: #fff;
}
#receipt-photo-preview figcaption {
  font-size: 10px;
  color: var(--ink-3);
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-attachment-panel {
  padding: 14px 16px;
  border: 1px solid #d6e4fb;
  border-radius: 10px;
  background: #fff;
}

.line-attachment-panel .attach-widget {
  background: #fbfdff;
  border-color: #b7d2ff;
}

.expense-packet-preview {
  display: grid;
  gap: 18px;
  max-height: 72vh;
  overflow: auto;
  padding: 14px;
  border-radius: 12px;
  background: #1a1e26;
}

.expense-packet-preview .receipt-page {
  zoom: .62;
  box-shadow: 0 18px 48px rgba(0,0,0,.32);
}

/* ป้ายบอกใบที่/Project เหนือใบพรีวิวแต่ละใบ */
.receipt-page-tag {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin: 14px 0 6px;
  padding: 5px 12px;
  background: rgba(20,120,185,0.10);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 12px;
  color: var(--ink);
}
.receipt-page-tag strong { color: var(--accent); }
.receipt-page-tag span { color: var(--ink-3); font-size: 11.5px; }

.line-risk-banner {
  display: grid;
  gap: 6px;
  margin: 10px 0 16px;
  padding: 10px 12px;
  border: 1px solid #f5c542;
  border-radius: 8px;
  background: #fff8df;
  color: #8a5a00;
  font-size: 12px;
  font-weight: 700;
}

.line-risk-banner[hidden] {
  display: none;
}

.line-approval-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 16px;
  padding: 12px;
  border: 1px solid #cfe0fb;
  border-radius: 12px;
  background: linear-gradient(180deg, #f8fbff 0%, #ffffff 100%);
  box-shadow: inset 4px 0 0 #2f6df6;
}

.line-approval-summary div {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid #dde8f7;
  border-radius: 10px;
  background: #fff;
}

.line-approval-summary span,
.line-approval-summary small {
  display: block;
  min-width: 0;
  overflow: hidden;
  color: var(--ink-3);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.line-approval-summary span {
  margin-bottom: 4px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.line-approval-summary strong {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.line-approval-summary small {
  margin-top: 4px;
  font-size: 11px;
}

.line-approval-summary[data-tone="done"],
.line-approval-summary[data-tone="ready"] { box-shadow: inset 4px 0 0 #20a66a; }
.line-approval-summary[data-tone="waiting"],
.line-approval-summary[data-tone="checking"] { box-shadow: inset 4px 0 0 #f2a100; }
.line-approval-summary[data-tone="draft"] { box-shadow: inset 4px 0 0 #8aa0bc; }

.detail-risk {
  margin-top: 14px;
}

.expense-warning {
  display: block;
  margin-top: 4px;
  color: #c2410c;
  font-weight: 700;
}

.guarantee-record .status.warning {
  background: #fff7ed;
  color: #c2410c;
}

.guarantee-record .status.bad {
  background: #fee2e2;
  color: #b91c1c;
}
 
.line-chat-demo {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--line-subtle);
}

.advance-cat-record {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(140px, 220px) 44px;
  gap: 12px;
  align-items: center;
  min-height: 74px;
  padding: 14px 16px;
}

.advance-cat-name {
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  line-height: 1.35;
}

.advance-cat-limit-label {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  align-items: start;
  min-width: 0;
  color: var(--ink-2);
  font-size: 11px;
  font-weight: 650;
}

.advance-cat-limit-input {
  width: 100%;
  max-width: 220px;
  min-height: 40px;
  padding-inline: 12px;
  border-radius: 10px;
  text-align: left;
  font-variant-numeric: tabular-nums;
}

.advance-cat-delete {
  justify-self: end;
  width: 44px;
  min-width: 44px;
  min-height: 34px;
  padding-inline: 0 !important;
  border-radius: 999px;
}
 
.chat-bubble, .chat-card {
  width: min(100%, 430px);
  border-radius: var(--radius);
  background: var(--surface-2);
}
 
.chat-bubble {
  padding: 12px 16px;
  font-size: 13px;
  color: var(--ink-2);
}
 
.chat-card {
  display: grid;
  gap: 6px;
  padding: 16px;
  border-top: 3px solid var(--gold-dim);
}
 
.chat-card strong { font-size: 16px; font-weight: 600; }
 
.chat-card span {
  font-size: 26px;
  font-weight: 700;
  color: var(--gold-bright);
}
 
.chat-card small {
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 300;
  line-height: 1.45;
}
 
.line-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* แผงติดตามสถานะ อยู่คอลัมน์ขวาบน เหนือพรีวิวใบแทนใบเสร็จ
   (เดิมกินเต็มแถวล่างสุด เลยตกไปอยู่ y≈1100 มองไม่เห็นถ้าไม่เลื่อนจอ) */
.line-form-panel { grid-column: 1; grid-row: 1 / span 2; }
.line-list-panel { grid-column: 2; grid-row: 1; }
.receipt-preview-wrap { grid-column: 2; grid-row: 2; }
.line-list-panel #line-expense-list { max-height: 300px; overflow: auto; }

.expense-entry-switch {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0 16px;
}

.expense-entry-card {
  display: grid;
  gap: 4px;
  min-height: 76px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.expense-entry-card strong {
  color: var(--ink);
  font-size: 13px;
}

.expense-entry-card span {
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.45;
}

.expense-entry-card.active,
.expense-entry-card[aria-current="page"] {
  border-color: var(--brand);
  background: #eef6ff;
  box-shadow: inset 3px 0 0 var(--brand);
}

.expense-entry-card:not(.active):hover {
  border-color: var(--brand);
  background: var(--surface-2);
}

.line-required-evidence {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 14px 16px;
  border: 1px solid #b7d2ff;
  border-radius: 10px;
  background: #f4f8ff;
  min-width: 0;
}

.line-required-evidence legend {
  padding: 0 7px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
}

#line-required-evidence-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px;
}

#line-required-evidence-list label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #d6e4fb;
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.45;
}

#line-required-evidence-list input {
  width: auto;
  margin-top: 2px;
  flex: 0 0 auto;
}

.line-required-evidence small {
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.45;
}

.advance-metrics { margin-bottom: 20px; }
.advance-filter-row { grid-template-columns: minmax(180px, 0.35fr) minmax(260px, 1fr); margin-bottom: 16px; }
.advance-policy-panel { border-top: 3px solid var(--gold); }
.policy-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.policy-grid > div { padding: 14px; border: 1px solid var(--line); background: var(--surface-2); }
.policy-grid strong { color: var(--gold); font-size: 12px; }
.policy-grid p { margin: 7px 0 0; color: var(--ink-2); font-size: 12px; line-height: 1.55; }
.advance-evidence { display: flex; flex-wrap: wrap; gap: 14px 22px; margin: 0; padding: 14px; border: 1px solid var(--line); min-width: 0; }
.advance-evidence legend { padding: 0 6px; color: var(--ink-2); font-size: 11px; }
.advance-evidence label { display: flex; align-items: center; grid-template-columns: auto 1fr; gap: 7px; letter-spacing: 0; }
.advance-evidence input { width: auto; }
.advance-warning { color: var(--bad); }
.advance-required-evidence { display: grid; gap: 10px; margin: 0; padding: 14px; border: 1px solid var(--gold); border-radius: var(--radius); background: var(--gold-muted); min-width: 0; }
.advance-required-evidence legend { padding: 0 6px; color: var(--gold); font-size: 11px; font-weight: 700; }
.advance-required-evidence label { display: flex; align-items: flex-start; gap: 8px; color: var(--ink); font-size: 12px; line-height: 1.5; letter-spacing: 0; }
.advance-required-evidence input { width: auto; margin-top: 2px; }
.advance-required-evidence small { color: var(--ink-3); line-height: 1.45; }
#advance-required-evidence-list { display: grid; gap: 8px; }
.advance-project-lines { display: grid; gap: 10px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); min-width: 0; }
.advance-project-lines-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.advance-project-lines-head strong { display: block; color: var(--ink); font-size: 13px; }
.advance-project-lines-head small { display: block; margin-top: 3px; color: var(--ink-3); font-size: 11px; line-height: 1.45; }
#advance-project-lines { display: grid; gap: 8px; }
.advance-project-line { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 38px; gap: 8px; align-items: end; padding: 10px; border: 1px solid var(--line-subtle); border-radius: 10px; background: var(--surface); min-width: 0; }
.advance-project-line label { display: grid; gap: 5px; color: var(--ink-3); font-size: 11px; font-weight: 600; }
.advance-project-line input, .advance-project-line select { width: 100%; min-width: 0; }
.advance-line-remove { grid-column: 3; grid-row: 1 / span 2; align-self: center; justify-self: center; width: 34px; min-width: 34px; height: 38px; padding: 0; }
.advance-batch-chip { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; padding: 2px 7px; margin-left: 6px; color: var(--ink-3); font-size: 11px; font-style: normal; background: var(--surface-2); }
.advance-legacy-field { display: none; }

.incentive-metrics { margin-bottom: 20px; }
.incentive-workspace { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.55fr); gap: 18px; }
.incentive-form-panel { min-width: 0; }
.incentive-form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.incentive-form-actions { grid-column: 1 / -1; }
.incentive-preview-panel { align-self: start; position: sticky; top: 24px; }
.incentive-summary { display: grid; gap: 0; border: 1px solid var(--line); }
.incentive-summary > div { display: flex; justify-content: space-between; gap: 14px; padding: 11px 13px; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.incentive-summary > div:last-of-type { border-bottom: 0; }
.incentive-summary strong { color: var(--ink); text-align: right; }
.incentive-summary .grand-total { background: var(--gold-muted); color: var(--gold); }
.incentive-summary p { margin: 0; padding: 12px 13px; background: var(--surface-2); color: var(--ink-2); font-size: 12px; line-height: 1.5; }
.incentive-records-panel { grid-column: 1 / -1; }
.incentive-policy-panel { grid-column: 1 / -1; }
.policy-list { margin: 0; padding-left: 22px; color: var(--ink-2); line-height: 1.8; }
.compact-filter { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 11px; }
.compact-filter select { min-width: 180px; }

.contractor-metrics { margin-bottom: 20px; }
.contractor-filter-row { grid-template-columns: minmax(190px, 0.35fr) minmax(260px, 1fr); margin-bottom: 16px; }
.contractor-guide { border-top: 3px solid var(--gold); }
/* #contractor-modal now uses dialog.modal-split layout — old grid overrides removed */
#contractor-review-modal { width: min(820px, calc(100vw - 40px)); }
#contractor-review-modal form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
#contractor-review-modal .modal-head, #contractor-review-modal .modal-actions, #contractor-review-modal .full-span { grid-column: 1 / -1; }
.review-checklist { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin: 0; padding: 16px; border: 1px solid var(--line); }
.review-checklist legend { padding: 0 6px; color: var(--gold); font-size: 11px; }
.review-checklist label { display: flex; align-items: flex-start; grid-template-columns: auto 1fr; gap: 8px; letter-spacing: 0; }
.review-checklist input { width: auto; margin-top: 2px; }

.settings-edit-modal {
  width: min(1200px, calc(100vw - 40px));
  max-width: calc(100vw - 40px);
}
.settings-edit-modal form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.settings-edit-modal .modal-head, .settings-edit-modal .modal-actions, .settings-edit-modal .full-span { grid-column: 1 / -1; }

/* User modal — 4-col layout, more breathing room */
#settings-user-modal {
  width: min(1200px, calc(100vw - 40px));
  max-width: calc(100vw - 40px);
}
#settings-user-modal form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
#settings-user-modal .modal-head,
#settings-user-modal .modal-actions,
#settings-user-modal .full-span,
#settings-user-modal .user-image-upload-section,
#settings-user-modal .view-access-field { grid-column: 1 / -1; }

/* Roles fieldset — 4 cols, companies — fill row */
#settings-user-modal .roles-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#settings-user-modal .companies-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* View access — 5 cols */
.view-access-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }

/* Ensure dialog itself doesn't get clamped by browser defaults */
#settings-user-modal[open] { max-width: calc(100vw - 40px); }
#settings-company-list .record, #settings-account-list .record { min-height: 82px; }

#advance-modal { width: min(1240px, calc(100vw - 40px)); }
#advance-modal form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#advance-modal .modal-head, #advance-modal .modal-actions, #advance-modal .full-span { grid-column: 1 / -1; }
#advance-modal.modal-split[open] { grid-template-columns: minmax(500px, 58%) minmax(360px, 42%); }
#advance-modal .advance-form-body { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#advance-modal .advance-form-body .full-span { grid-column: 1 / -1; }
#advance-modal .advance-project-lines,
#advance-modal .advance-project-line,
#advance-modal .advance-required-evidence,
#advance-modal .advance-evidence { max-width: 100%; box-sizing: border-box; }
#advance-modal .advance-required-evidence label,
#advance-modal .advance-evidence label {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  min-width: 0;
  gap: 8px;
  font-weight: 600;
  line-height: 1.45;
  white-space: normal;
}
#advance-modal .advance-required-evidence label { align-items: flex-start; }
#advance-modal .advance-required-evidence input,
#advance-modal .advance-evidence input {
  flex: 0 0 16px;
  width: 16px;
  min-width: 16px;
  height: 16px;
  margin: 1px 0 0;
}
#advance-modal .advance-evidence label { flex: 1 1 190px; }
#advance-clear-modal { width: min(760px, calc(100vw - 40px)); }
#advance-clear-modal form { grid-template-columns: repeat(3, minmax(0, 1fr)); }
#advance-clear-modal .modal-head, #advance-clear-modal .modal-actions, #advance-clear-modal .full-span { grid-column: 1 / -1; }
.advance-clear-summary { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); }
.advance-clear-summary div, .advance-amount-grid div { display: grid; gap: 4px; padding: 10px; border: 1px solid var(--line-subtle); border-radius: 0; background: var(--surface); }
.advance-clear-summary span, .advance-amount-grid span { color: var(--ink-3); font-size: 10px; }
.advance-clear-summary strong, .advance-amount-grid strong { color: var(--ink); font-size: 14px; font-weight: 500; }
.advance-detail-layout { display: grid; gap: 14px; }
.advance-detail-section { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; color: var(--ink); }
.section-title span { color: var(--blue); font-size: 11px; }
.advance-amount-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.two-column-text { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.two-column-text p { margin: 6px 0 0; color: var(--ink); line-height: 1.75; white-space: normal; }
.two-column-text small { display: block; margin-top: 6px; color: var(--ink-3); line-height: 1.6; }
.approval-timeline { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.approval-timeline li { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--line-subtle); border-radius: 0; background: var(--surface-2); }
.approval-timeline i { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: #dbeaf4; color: var(--blue); font-style: normal; font-weight: 500; }
.approval-timeline li.done i { background: #dff5eb; color: #16805a; }
.approval-timeline li.current { border-color: var(--blue); background: #eef7fd; }
.approval-timeline span { display: grid; gap: 2px; }
.approval-timeline small { color: var(--ink-3); }
 
/* ─── MODAL ──────────────────────────────────────────────── */
.modal {
  width: min(460px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 0;
  background: var(--surface);
  box-shadow: 0 24px 64px rgba(0,0,0,0.7);
}
 
.modal::backdrop { background: rgba(0,0,0,0.7); }
 
.modal form {
  display: grid;
  gap: 14px;
  padding: 22px;
  max-height: min(90vh, 900px);
  overflow: auto;
}
 
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
 
.modal-head h3 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--gold);
}
 
.modal label {
  display: grid;
  gap: 6px;
  color: var(--ink-3);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
 
.modal-actions { justify-content: flex-end; }

@media (min-width: 900px) {
  /* เดิมกล่องพวกนี้ถูกตรึงไว้มุมขวาบน (inset: 24px 24px auto auto) ทำให้กล่องกรอกข้อมูล
     ไปเบียดขอบขวาและทับเนื้อหาที่กำลังดูอยู่ ย้ายมาไว้กลางจอให้อ่านและกรอกง่ายกว่า */
  dialog.modal[open]:not(.modal-split):not(.system-manual-modal):not(.document-fill-modal):not(.document-preview-modal),
  dialog.detail-modal[open]:not(.detail-modal-full) {
    position: fixed;
    inset: 0;
    margin: auto;
    max-height: calc(100dvh - 48px);
  }

  dialog.modal[open]:not(.modal-split):not(.system-manual-modal):not(.document-fill-modal):not(.document-preview-modal) form,
  dialog.detail-modal[open]:not(.detail-modal-full) .detail-dialog {
    max-height: calc(100dvh - 48px);
    overflow: auto;
  }
}

.app-action-modal {
  width: min(520px, calc(100vw - 32px));
  border-radius: 18px;
  border-color: rgba(148, 163, 184, 0.35);
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.34);
}

.app-action-modal::backdrop {
  background: rgba(15, 23, 42, 0.52);
  backdrop-filter: blur(2px);
}

.app-action-form {
  gap: 18px;
  padding: 22px;
}

.app-action-head {
  align-items: flex-start;
  gap: 16px;
}

.app-action-head h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.35;
  letter-spacing: 0;
  text-transform: none;
}

.app-action-head p {
  margin: 0;
  color: var(--ink-2);
  font-size: 14px;
  line-height: 1.65;
  white-space: pre-line;
}

.app-action-close {
  flex: 0 0 auto;
}

.app-action-input-wrap {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
}

/* กล่องยืนยันไม่มีช่องกรอก — แอตทริบิวต์ hidden ต้องมีผลจริง
   ไม่งั้นกฎ display ของ label ในฟอร์มจะทับ ทำให้ช่อง "ข้อมูล" โผล่ในกล่องยืนยัน */
.app-action-modal [hidden],
.app-action-form [hidden],
.app-action-input-wrap[hidden] { display: none !important; }

.app-action-input-wrap input {
  min-height: 44px;
}

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

.app-action-actions .danger-button {
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}

.app-action-actions .danger-button:hover {
  background: #b91c1c;
  border-color: #b91c1c;
}

@media (max-width: 560px) {
  .app-action-modal {
    width: calc(100vw - 20px);
    border-radius: 16px;
  }

  .app-action-form {
    padding: 18px;
    max-height: calc(100vh - 28px);
  }

  .app-action-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .app-action-actions button {
    width: 100%;
  }
}

#line-view .receipt-preview-wrap .receipt-page.expense-paper-page {
  width: 1120px;
  max-width: none;
}

/* Credit card import staging */
.credit-card-staging-panel {
  margin-top: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg, 16px);
  background: var(--surface, #fff);
  overflow: hidden;
}
.cc-stage-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.cc-stage-head h3 {
  margin: 0 0 4px;
  font-size: 15px;
}
.cc-stage-head p {
  margin: 0;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.5;
}
.cc-stage-head > strong {
  flex: 0 0 auto;
  color: var(--accent);
  font-size: 13px;
}
.cc-stage-table-wrap {
  overflow-x: auto;
}
.cc-stage-table {
  width: 100%;
  min-width: 980px;
  table-layout: fixed;
}
.cc-stage-table th:nth-child(1) { width: 110px; }
.cc-stage-table th:nth-child(2) { width: 130px; }
.cc-stage-table th:nth-child(4) { width: 130px; }
.cc-stage-table th:nth-child(5) { width: 270px; }
.cc-stage-table th:nth-child(6) { width: 120px; }
.cc-stage-table th:nth-child(7) { width: 150px; }
.cc-stage-table td {
  vertical-align: middle;
}
.cc-stage-table small {
  display: block;
  margin-top: 3px;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.35;
}
.cc-stage-table select {
  width: 100%;
  min-width: 0;
}
.cc-stage-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}
.cc-stage-actions .primary-button[disabled] {
  opacity: .45;
  cursor: not-allowed;
}
@media (max-width: 900px) {
  .cc-stage-head {
    flex-direction: column;
  }
  .cc-stage-head > strong {
    align-self: flex-start;
  }
}

#accounting-modal {
  width: min(1180px, calc(100vw - 48px));
  max-width: calc(100vw - 48px);
  height: min(860px, calc(100vh - 48px));
  max-height: calc(100vh - 48px);
}

#accounting-modal form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-content: start;
  max-height: none;
  height: 100%;
  padding: 24px;
}

#accounting-modal .modal-head,
#accounting-modal .modal-actions,
#accounting-modal datalist {
  grid-column: 1 / -1;
}

#accounting-modal .check-row {
  align-self: end;
  min-height: 42px;
}

#billing-modal {
  width: min(980px, calc(100vw - 40px));
}

#billing-modal form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

#billing-modal .modal-head,
#billing-modal .modal-actions,
#billing-modal .full-span {
  grid-column: 1 / -1;
}

#payment-modal,
#credit-note-modal { width: min(820px, calc(100vw - 40px)); }

#payment-modal form,
#credit-note-modal form { grid-template-columns: repeat(2, minmax(0, 1fr)); }

#payment-modal .modal-head,
#payment-modal .modal-actions,
#credit-note-modal .modal-head,
#credit-note-modal .modal-actions { grid-column: 1 / -1; }

.process-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  overflow-x: auto;
  white-space: nowrap;
}

.process-strip span { color: var(--ink); }
.process-strip b { color: var(--gold); }
.finance-wide-panel { grid-column: 1 / -1; }
.panel-subtitle { margin: 4px 0 0; color: var(--ink-2); font-size: 12px; }

/* ── Finance chain panel ─────────────────────────────── */
.finance-chain-panel { grid-column: 1 / -1; }
.finance-actions { display: flex; gap: 8px; align-items: center; }

.fin-chain-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  background: var(--surface);
  overflow: hidden;
  transition: box-shadow .15s;
}
.fin-chain-card:hover { box-shadow: 0 3px 12px rgba(0,0,0,.08); }
.fin-chain-card.fin-status-paid { border-left: 4px solid #22c55e; }
.fin-chain-card.fin-status-partial { border-left: 4px solid #f59e0b; }
.fin-chain-card.fin-status-pending { border-left: 4px solid var(--line); }

/* header row */
.fin-chain-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.fin-chain-title { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.fin-customer { font-size: 15px; font-weight: 700; }
.fin-project-name { color: var(--ink-2); font-size: 13px; }
.fin-ref-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 0;
  background: rgba(59,130,246,.1);
  color: var(--accent); font-weight: 600; white-space: nowrap;
}
.fin-chain-meta-top { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.fin-inv-id { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.fin-status-badge { font-size: 12px; padding: 3px 10px; border-radius: 0; font-weight: 600; }
.fin-badge-paid { background: #dcfce7; color: #15803d; }
.fin-badge-partial { background: #fef9c3; color: #a16207; }
.fin-badge-pending { background: #f1f5f9; color: var(--ink-2); }

/* body */
.fin-chain-body {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 0; padding: 16px;
}
@media (max-width: 680px) { .fin-chain-body { grid-template-columns: 1fr; } }

/* left: chain dots + amounts */
.fin-chain-left { display: flex; flex-direction: column; gap: 14px; padding-right: 20px; border-right: 1px solid var(--line); }
@media (max-width: 680px) { .fin-chain-left { border-right: none; border-bottom: 1px solid var(--line); padding-right: 0; padding-bottom: 14px; } }

.fin-chain-dots { display: flex; align-items: center; gap: 0; }
.fin-dot {
  display: flex; align-items: center; justify-content: center;
  padding: 0 10px; height: 28px; border-radius: 0;
  font-size: 11px; font-weight: 700;
  background: #f1f5f9; color: var(--ink-2);
  border: 2px solid var(--line);
  white-space: nowrap;
}
.fin-dot.done { background: var(--accent); color: #fff; border-color: var(--accent); }
.fin-dot.partial { background: #fef9c3; color: #a16207; border-color: #f59e0b; }
.fin-dot-line { flex: 1; height: 2px; background: var(--line); min-width: 20px; }
.fin-dot-line.active { background: var(--accent); }

.fin-amounts-grid {
  display: grid; grid-template-columns: 1fr auto;
  gap: 4px 12px; font-size: 13px; align-items: baseline;
}
.fin-amounts-grid span { color: var(--ink-2); }
.fin-outstanding-label { font-weight: 600; color: var(--ink) !important; }
.fin-amounts-grid strong { font-weight: 700; font-size: 14px; }

.fin-chain-meta-bottom { font-size: 12px; color: var(--ink-2); display: flex; flex-wrap: wrap; gap: 4px; }

/* right: sub-rows + actions */
.fin-chain-right { display: flex; flex-direction: column; gap: 10px; padding-left: 20px; }
@media (max-width: 680px) { .fin-chain-right { padding-left: 0; } }

.fin-sub-rows { display: flex; flex-direction: column; gap: 6px; }
.fin-sub-row {
  display: grid; grid-template-columns: 1fr auto auto auto auto;
  align-items: center; gap: 8px; padding: 6px 10px;
  background: #f8fafc; border-radius: var(--radius);
  font-size: 12px;
}
.fin-cn-row { background: #fff7ed; }
.fin-sub-label { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fin-sub-date { color: var(--ink-2); white-space: nowrap; }
.fin-sub-method { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fin-sub-amount { font-weight: 700; white-space: nowrap; }
.fin-no-pay { color: var(--ink-2); font-size: 13px; margin: 0; }

.fin-chain-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: auto; padding-top: 10px; }

.fin-standalone-section { margin-top: 20px; padding-top: 14px; border-top: 1px dashed var(--line); }
.fin-standalone-section h4 { font-size: 13px; color: var(--ink-2); margin: 0 0 10px; }

.ghost-button.xsmall { padding: 2px 8px !important; font-size: 11px !important; }

.detail-modal {
  width: min(720px, calc(100vw - 32px));
}

.detail-modal.detail-modal-full {
  width: calc(100vw - 32px);
  max-width: calc(100vw - 32px);
  height: calc(100vh - 32px);
  max-height: calc(100vh - 32px);
}

.detail-dialog {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.detail-modal-full .detail-dialog {
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr);
  padding: 22px;
}

.detail-body {
  display: grid;
  gap: 16px;
}

.detail-modal-full .detail-body {
  min-height: 0;
  overflow: auto;
}

.detail-body h4 {
  margin: 4px 0 0;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.detail-summary div,
.detail-item {
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.025);
}

/* ── Notification List ─────────────────────────── */
.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif-item {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 14px 16px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
  text-align: left; transition: background .15s, border-color .15s;
}
.notif-item:hover { background: var(--surface-2); border-color: var(--gold); }
.notif-icon { font-size: 20px; flex-shrink: 0; width: 28px; text-align: center; }
.notif-text { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.notif-text strong { font-size: 14px; font-weight: 600; color: var(--ink); }
.notif-text small { font-size: 12px; color: var(--ink-3); }
.notif-count { font-size: 20px; font-weight: 700; color: var(--gold); min-width: 32px; text-align: right; }
.notif-arrow { font-size: 18px; color: var(--ink-3); margin-left: 4px; }

.detail-summary div {
  display: grid;
  gap: 4px;
  padding: 12px;
}

.detail-summary span,
.detail-item span,
.empty-detail {
  color: var(--ink-3);
  font-size: 12px;
}

.detail-summary strong,
.detail-item b {
  color: var(--ink);
  font-size: 15px;
}

.detail-list {
  display: grid;
  gap: 8px;
}

.detail-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 14px;
  padding: 12px;
}

.detail-item strong {
  color: var(--ink);
}

.detail-item span {
  grid-column: 1 / 2;
}

.detail-item b {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  align-self: center;
  white-space: nowrap;
}

.empty-detail {
  margin: 0;
}
 
/* ─── DOCUMENTS ──────────────────────────────────────────── */
.document-type-center { padding: 28px 24px; border: 1px solid var(--line-subtle); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-card); }
.document-type-groups button { cursor: pointer; transition: border-color .15s, box-shadow .15s, background .15s; }
.document-type-groups button:hover { border-color: var(--gold); background: var(--gold-muted); }
.document-step-head, .document-step-title { display: flex; align-items: center; gap: 10px; }
.document-step-head { margin-bottom: 14px; }
.document-step-head > span, .document-step-title > span { display: grid; place-items: center; width: 26px; height: 26px; flex: 0 0 26px; border-radius: 50%; background: var(--gold); color: #fff; font-size: 12px; font-weight: 500; }
.document-step-head h3, .document-step-title h3 { margin: 0; font-size: 15px; font-weight: 500; }
.document-step-head p { margin: 2px 0 0; color: var(--ink-3); font-size: 11px; }
.document-type-groups { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.document-type-groups > div { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.document-type-groups > div > strong { grid-column: 1 / -1; color: var(--gold); font-size: 10px; font-weight: 400; letter-spacing: .08em; }
.document-type-groups button { display: flex; align-items: center; gap: 10px; min-height: 64px; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); color: var(--ink); text-align: left; }
.document-type-groups button.active { border-color: var(--gold); box-shadow: inset 3px 0 0 var(--gold); background: var(--gold-muted); }
.document-type-groups button.selected { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent), 0 0 0 2px rgba(27,127,196,.15); background: #dbeeff; }
.document-type-groups button.selected .doc-type-icon { color: var(--accent); }

/* ── Document type action bar ──────────────────── */
.doc-type-action-bar[hidden] { display: none; }
.doc-type-action-bar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 12px; padding: 14px 18px;
  background: #f0f7ff; border: 1.5px solid var(--accent);
  border-radius: var(--radius); animation: fadeIn .15s ease;
}
.doc-type-action-info { display: flex; align-items: center; gap: 12px; }
.doc-type-action-step {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.doc-type-action-label { font-size: 13px; color: var(--ink-2); }
.doc-type-action-info strong { font-size: 14px; color: var(--accent); }
.doc-type-action-btns { display: flex; gap: 8px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.doc-type-icon { display: flex; align-items: center; justify-content: center; flex-shrink: 0; width: 32px; height: 32px; color: var(--gold); }
.doc-type-icon.acc { color: #6b8cba; }
.doc-type-icon svg { width: 18px; height: 22px; display: block; }
.doc-type-label { display: flex; flex-direction: column; gap: 3px; font-size: 13px; font-weight: 500; }
.doc-type-label small { color: var(--ink-3); font-size: 10px; font-weight: 300; }

/* ── คู่มือการใช้งาน ─────────────────────────────────────── */
.system-manual-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  margin: 0 0 18px;
  padding: 18px 20px;
  border: 1px solid rgba(37, 99, 235, 0.16);
  border-radius: 18px;
  background: linear-gradient(135deg, #ffffff 0%, #f8fbff 58%, #eff6ff 100%);
  box-shadow: 0 16px 36px rgba(15, 23, 42, 0.06);
}
.manual-card-icon {
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  color: #2563eb;
  background: #eaf2ff;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.12);
}
.manual-card-icon svg { width: 30px; height: 30px; }
.manual-card-copy { min-width: 0; }
.manual-card-copy .eyebrow {
  margin: 0 0 5px;
  color: #2563eb;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
}
.manual-card-copy h3 {
  margin: 0 0 5px;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.25;
}
.manual-card-copy p:not(.eyebrow) {
  margin: 0;
  color: var(--ink-3);
  font-size: 12px;
  line-height: 1.6;
}
.manual-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.manual-card-actions a {
  text-decoration: none;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
@media (max-width: 900px) {
  .system-manual-card { grid-template-columns: 48px minmax(0, 1fr); }
  .manual-card-icon { width: 48px; height: 48px; }
  .manual-card-actions { grid-column: 1 / -1; justify-content: flex-start; }
}
@media (max-width: 560px) {
  .system-manual-card { grid-template-columns: 1fr; }
  .manual-card-icon { display: none; }
  .manual-card-actions { flex-direction: column; align-items: stretch; }
}

.system-manual-modal {
  width: min(1180px, calc(100vw - 32px));
  height: min(92vh, 900px);
  padding: 0;
  border: 0;
  border-radius: 20px;
  background: #f8fafc;
  color: #0f172a;
  box-shadow: 0 28px 90px rgba(15, 23, 42, 0.34);
  overflow: hidden;
  font-family: 'Kanit', Arial, sans-serif;
}
.system-manual-modal::backdrop { background: rgba(15, 23, 42, 0.48); backdrop-filter: blur(4px); }
.system-manual-shell { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.system-manual-modal[open] .system-manual-shell {
  position: relative;
  max-width: 100%;
  max-height: 100%;
}
.system-manual-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid #dbeafe;
  background: rgba(255, 255, 255, 0.96);
  flex: 0 0 auto;
}
.system-manual-topbar.manual-drag-handle { cursor: move; user-select: none; }
.system-manual-topbar .eyebrow,
.system-manual-content .eyebrow { margin: 0 0 5px; color: #2563eb; font-size: 10px; font-weight: 700; letter-spacing: .08em; }
.system-manual-topbar h2 { margin: 0; font-size: 22px; line-height: 1.25; color: #0f172a; }
.system-manual-topbar span { display: block; margin-top: 4px; color: #64748b; font-size: 12px; }
.system-manual-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
#manual-floating-button {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 900;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px 8px 10px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #ffffff;
  color: #1d4ed8;
  font: 700 12px/1 'Kanit', Arial, sans-serif;
  box-shadow: 0 14px 38px rgba(37, 99, 235, 0.22);
  cursor: pointer;
}
#manual-floating-button span {
  display: inline-grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
}
#manual-floating-button:hover { border-color: #60a5fa; background: #eff6ff; }
.system-manual-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: 0;
  flex: 1 1 auto;
}
.system-manual-toc {
  padding: 18px;
  border-right: 1px solid #e2e8f0;
  background: #ffffff;
  overflow: auto;
}
.system-manual-toc strong { display: block; margin-bottom: 12px; font-size: 13px; color: #0f172a; }
.system-manual-toc a {
  display: block;
  padding: 9px 10px;
  border-radius: 10px;
  color: #475569;
  font-size: 12px;
  text-decoration: none;
}
.system-manual-toc a:hover { background: #eff6ff; color: #1d4ed8; }
.system-manual-content {
  padding: 24px;
  overflow: auto;
  scroll-behavior: smooth;
}
.manual-section {
  max-width: 820px;
  margin: 0 auto 18px;
  padding: 22px;
  border: 1px solid #e2e8f0;
  border-radius: 18px;
  background: #ffffff;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.05);
  break-inside: avoid;
}
.manual-section-head { margin-bottom: 10px; }
.manual-section h3 { margin: 0; font-size: 21px; line-height: 1.3; color: #0f172a; }
.manual-section p {
  margin: 0 0 12px;
  color: #334155;
  font-size: 13px;
  line-height: 1.75;
}
.manual-steps { margin: 0 0 14px; padding-left: 22px; }
.manual-steps li { margin-bottom: 7px; color: #334155; font-size: 13px; line-height: 1.7; }
.manual-steps strong { color: #0f172a; }
.manual-link-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 12px 0 14px;
}
.manual-link-grid button {
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid #bfdbfe;
  border-radius: 999px;
  background: #eff6ff;
  color: #1d4ed8;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.manual-link-grid button:hover { background: #dbeafe; }
.manual-section figure { margin: 14px 0 0; }
.manual-section img {
  display: block;
  width: 100%;
  max-height: 360px;
  object-fit: contain;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #f8fafc;
}
.manual-section figcaption {
  margin-top: 7px;
  color: #64748b;
  font-size: 11px;
  text-align: center;
}
.manual-table-wrap { overflow-x: auto; margin: 12px 0; }
.manual-table-wrap table { width: 100%; border-collapse: collapse; font-size: 12px; }
.manual-table-wrap th,
.manual-table-wrap td { padding: 9px 10px; border-bottom: 1px solid #e2e8f0; text-align: left; vertical-align: top; }
.manual-table-wrap th { color: #0f172a; background: #eff6ff; font-weight: 700; }

@media (max-width: 820px) {
  .system-manual-modal { width: calc(100vw - 18px); height: calc(100vh - 18px); border-radius: 16px; }
  .system-manual-topbar { align-items: flex-start; flex-direction: column; }
  .system-manual-topbar.manual-drag-handle { cursor: default; }
  .system-manual-layout { grid-template-columns: 1fr; }
  .system-manual-toc { display: flex; gap: 4px; overflow-x: auto; border-right: 0; border-bottom: 1px solid #e2e8f0; padding: 10px 14px; }
  .system-manual-toc strong { display: none; }
  .system-manual-toc a { white-space: nowrap; }
  .system-manual-content { padding: 14px; }
  .manual-section { padding: 16px; }
  #manual-floating-button {
    right: 14px;
    bottom: 14px;
  }
  #manual-floating-button b { display: none; }
}

@media print {
  body.manual-print-mode * { visibility: hidden !important; }
  body.manual-print-mode #system-manual-modal,
  body.manual-print-mode #system-manual-modal * { visibility: visible !important; }
  body.manual-print-mode #system-manual-modal {
    position: static !important;
    inset: auto !important;
    display: block !important;
    width: auto !important;
    height: auto !important;
    max-width: none !important;
    max-height: none !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    overflow: visible !important;
  }
  body.manual-print-mode .system-manual-shell,
  body.manual-print-mode .system-manual-layout,
  body.manual-print-mode .system-manual-content {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
    padding: 0 !important;
  }
  body.manual-print-mode .system-manual-content { font-family: 'Kanit', Arial, sans-serif; }
  body.manual-print-mode .manual-section {
    max-width: none !important;
    margin: 0 0 10mm !important;
    padding: 10mm !important;
    border: 1px solid #dbeafe !important;
    box-shadow: none !important;
    break-inside: avoid;
    page-break-inside: avoid;
  }
  body.manual-print-mode .manual-section img { max-height: 115mm !important; }
}
.doc-guide { margin-top: 18px; border: 1px solid var(--line-subtle); border-radius: var(--radius); overflow: hidden; }
.doc-guide-toggle { display: flex; align-items: center; gap: 8px; padding: 11px 16px; font-size: 13px; font-weight: 500; color: var(--ink-2); cursor: pointer; list-style: none; background: var(--surface-2); user-select: none; }
.doc-guide-toggle::-webkit-details-marker { display: none; }
.doc-guide[open] .doc-guide-toggle { color: var(--gold); border-bottom: 1px solid var(--line-subtle); }
.doc-guide-body { padding: 18px 20px; background: var(--bg); }
.doc-guide-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.doc-guide-col h4 { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--ink); }
.doc-guide-col + .doc-guide-col h4 { margin-top: 0; }
.doc-guide-col ol, .doc-guide-col ul { margin: 0 0 14px; padding-left: 18px; }
.doc-guide-col li { font-size: 12.5px; color: var(--ink-2); line-height: 1.7; }
.doc-guide-col li strong { color: var(--ink); }
.doc-guide-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.doc-guide-table th { background: var(--surface-2); padding: 6px 10px; text-align: left; font-weight: 600; color: var(--ink-3); font-size: 10px; text-transform: uppercase; letter-spacing: .06em; border-bottom: 1px solid var(--line); }
.doc-guide-table td { padding: 7px 10px; border-bottom: 1px solid var(--line-subtle); color: var(--ink-2); vertical-align: middle; }
.doc-guide-table tr:last-child td { border-bottom: 0; }
@media (max-width: 700px) { .doc-guide-grid { grid-template-columns: 1fr; } }
.contractor-document-fields { margin: 0 0 16px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius); }
.contractor-document-fields legend { padding: 0 6px; color: var(--gold); font-size: 11px; }
/* ── Document Fill Modal (fullscreen dialog) ─────────────── */
.document-fill-modal {
  position: fixed;
  inset: 0;
  width: 100vw;
  max-width: 100vw;
  height: 100vh;
  max-height: 100vh;
  margin: 0;
  padding: 0;
  border: 0;
  background: var(--bg);
  overflow: hidden;
  display: none;
}
.document-fill-modal[open] { display: flex; flex-direction: column; }
.document-fill-modal::backdrop { background: rgba(0,0,0,0.6); }

/* ── Popup (non-fullscreen) mode — กด preview จาก list view ── */
.document-fill-modal.dfm-popup {
  position: fixed;
  inset: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(96vw, 1280px);
  max-width: min(96vw, 1280px);
  height: min(92vh, 900px);
  max-height: min(92vh, 900px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0,0,0,0.45);
}
.document-fill-modal.dfm-popup::backdrop { background: rgba(0,0,0,0.55); }

/* ── Multi-row WHT table ─────────────────────────────────── */
.wht-rows-table { width:100%; border-collapse:collapse; font-size:13px; margin-bottom:8px; }
.wht-rows-table th { background:var(--accent); color:#fff; padding:6px 8px; text-align:left; font-weight:600; }
.wht-rows-table td { padding:5px 6px; border-bottom:1px solid var(--line-subtle); vertical-align:middle; }
.wht-rows-table input { width:100%; border:1px solid var(--line); padding:3px 6px; font-size:12px; background:var(--bg-2); }
.wht-rows-table .wht-calc { color:var(--ink-2); font-size:12px; }
.wht-rows-table .remove-wht-row { background:none; border:none; color:var(--accent-red); cursor:pointer; font-size:16px; line-height:1; padding:0 4px; }
.wht-rows-summary { display:flex; gap:16px; font-size:13px; padding:8px 0; border-top:2px solid var(--accent); flex-wrap:wrap; }
.wht-rows-summary strong { color:var(--accent); }

/* ── DFM Topbar (full-width header) ──────────────────────── */
.dfm-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px 10px 24px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  min-height: 54px;
}
.dfm-topbar-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; overflow: hidden; }
.dfm-topbar-title h3 { margin: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dfm-subtitle { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dfm-topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.dfm-topbar-actions .ghost-button.small,
.dfm-topbar-actions .primary-button.small,
.dfm-topbar-actions .accent-button.small {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-height: 36px;
  border-radius: 8px;
  white-space: nowrap;
}
.dfm-back-btn {
  color: var(--ink-2);
  border-color: var(--line);
}
.dfm-back-btn:hover {
  color: var(--accent);
  border-color: rgba(21,120,190,0.35);
  background: rgba(21,120,190,0.08);
}
.dfm-close-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink-2);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  margin-left: 4px;
  transition: background .15s, color .15s, border-color .15s, transform .15s;
}
.dfm-close-btn:hover { background: #fff1f2; color: #e11d48; border-color: #fecdd3; transform: translateY(-1px); }
.dfm-close-btn:focus-visible {
  outline: 3px solid rgba(225, 29, 72, 0.14);
  outline-offset: 2px;
}

/* ── Document Workspace inside modal ─────────────────────── */
.document-workspace {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  align-items: stretch;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.document-controls {
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
  border-right: 1px solid var(--line);
  padding-bottom: 24px;
}

.dfm-form-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px !important;
  min-height: 44px;
}
.dfm-form-head .document-step-title h4 { margin: 0; font-size: 13px; font-weight: 500; }

/* Override .panel padding so sticky head works */
.document-fill-modal .panel { padding: 0; border: 0; background: transparent; border-radius: 0; box-shadow: none; }
.document-fill-modal .panel-head { border-radius: 0; }
.document-fill-modal .form-grid { margin: 10px 16px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.document-fill-modal .form-grid label.full,
.document-fill-modal .form-grid label.full-span { grid-column: 1 / -1; }
.document-fill-modal .document-terms-label { display: block; padding: 0 16px 14px; }
.document-fill-modal .totals-inputs { margin: 0 16px 12px; }
.document-fill-modal .document-lines-section { margin: 0 8px; }
.document-fill-modal .document-signature-controls { padding: 0 16px; }

/* Small button variant */
.primary-button.small, .ghost-button.small { min-height: 32px; padding: 0 12px; font-size: 12px; }

@media (max-width: 860px) {
  .document-workspace { grid-template-columns: 1fr; }
  .document-preview-wrap { display: none; }
}

.document-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
 
.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
 
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid .full-span { grid-column: 1 / -1; }

.document-terms-label {
  display: grid;
  gap: 6px;
  margin-bottom: 4px;
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
 
.form-grid label, .line-row label {
  display: grid;
  gap: 6px;
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}
 
.line-editor-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0 10px;
}
 
.line-editor-head h4 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}
 
.line-editor { display: grid; gap: 8px; margin-bottom: 16px; }
 
.line-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.6fr) minmax(170px, 1fr) 74px 74px 116px 112px 42px;
  gap: 8px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius);
  background: var(--bg-3);
}
 
.line-row strong {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 600;
  color: var(--gold-bright);
}
 
.line-row.is-discount { border-color: #e74c3c44; background: #fff5f5; }
.line-row.is-discount strong { color: #c0392b; }

.totals-inputs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
 
/* ─── DOCUMENT PAGE ──────────────────────────────────────── */
.doc-preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  background: #0d1017;
  border-radius: 0;
  gap: 12px;
  min-height: 44px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.doc-preview-toolbar .document-step-title { color: #fff; margin: 0; }
.doc-zoom-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.doc-zoom-controls #doc-zoom-label {
  font-size: 12px;
  color: rgba(255,255,255,0.7);
  min-width: 38px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.doc-zoom-controls .icon-button {
  width: 28px;
  height: 28px;
  font-size: 18px;
  font-weight: 300;
  color: rgba(255,255,255,0.8);
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.15);
}
.doc-zoom-controls .icon-button:hover { background: rgba(255,255,255,0.16); }
.doc-zoom-controls .ghost-button.small {
  font-size: 11px;
  padding: 4px 10px;
  min-height: 28px;
  border-color: rgba(255,255,255,0.2);
  color: rgba(255,255,255,0.7);
  background: rgba(255,255,255,0.06);
}
.doc-zoom-controls .ghost-button.small:hover { border-color: var(--gold); color: var(--gold); background: rgba(255,255,255,0.1); }

.document-preview-wrap {
  border-radius: 0;
  background: #151821;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.doc-preview-viewport {
  overflow: auto;
  flex: 1;
  padding: 24px;
  background: #1e2330;
}

.document-page {
  width: 794px;
  min-height: 1123px;
  margin: 0 auto;
  padding: 54px;
  background: #fff;
  color: #17202a;
  border: 1px solid #8896aa;
  box-shadow: 0 8px 40px rgba(0,0,0,0.7), 0 0 0 1px rgba(255,255,255,0.04);
  font-family: 'Kanit', Arial, sans-serif;
  transform-origin: top center;
  transition: transform 0.2s ease;
}
 
/* ─── SDDS DOCUMENT TEMPLATE LAYOUT ─────────────────────── */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding-bottom: 18px;
  border-bottom: 2px solid #17202a;
}
.doc-header-brand {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  flex: 1;
}
.doc-title-badge {
  text-align: right;
  min-width: 180px;
}
.doc-title-badge h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
  color: #17202a;
  letter-spacing: -0.5px;
}
.doc-original-label {
  display: inline-block;
  margin-top: 3px;
  font-size: 13px;
  font-style: italic;
  color: #4d5b68;
  letter-spacing: 1px;
}
 
.logo-box {
  display: grid;
  place-items: center;
  width: 86px;
  height: 86px;
  border: 1px solid #b8c3cf;
  border-radius: var(--radius);
  background: #f2f5f8;
  color: #64707d;
  font-weight: 700;
  font-size: 11px;
}
 
.logo-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
 
.issuer-block { flex: 1; }
.issuer-block p, .doc-note p, .doc-footer p { margin: 0; line-height: 1.55; }
.issuer-block p { color: #4d5b68; font-size: 12px; }

/* Customer 2-column info table */
.doc-customer-section {
  margin-top: 16px;
  border: 1px solid #c8d0dc;
}
.doc-customer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.doc-customer-table td {
  padding: 3px 8px;
  vertical-align: top;
  border-bottom: 1px solid #e8edf2;
}
.doc-customer-table tr:last-child td { border-bottom: 0; }
.dct-label {
  white-space: nowrap;
  color: #4d5b68;
  font-weight: 500;
  width: 110px;
}
.dct-value {
  color: #17202a;
  /* ที่อยู่/ชื่อยาว: ตัดขึ้นบรรทัดใหม่ในช่อง ไม่ดันตารางจนล้นกรอบ */
  white-space: pre-wrap;
  overflow-wrap: break-word;   /* ตัดเฉพาะเมื่อคำยาวเกินช่องจริง ๆ */
  word-break: normal;          /* ไทย: ให้ตัดตามคำ ไม่ตัดกลางคำ */
  line-break: auto;
  max-width: 0;          /* บังคับให้ตารางใช้ความกว้างที่กำหนด ไม่ขยายตามข้อความ */
  line-height: 1.45;
}
/* ที่อยู่ยาวมาก ย่อขนาดอัตโนมัติให้พอดีใบ */
#preview-client-address,
#preview-issuer-address { font-size: 8.5pt; }
#preview-client-address.dct-long,
#preview-issuer-address.dct-long { font-size: 7.5pt; line-height: 1.35; }
#preview-client-address.dct-longer,
#preview-issuer-address.dct-longer { font-size: 6.8pt; line-height: 1.3; }
.doc-customer-table { table-layout: fixed; width: 100%; }
.dct-right { border-left: 1px solid #e0e6ec; text-align: right; width: 100px; }
.dct-right-val { width: 150px; max-width: 150px; font-weight: 600; color: #17202a; word-break: normal; overflow-wrap: break-word; font-size: 8.5pt; }

/* Company TAX ID + bank account row */
.doc-tax-bank-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-top: 0;
  padding: 5px 8px;
  background: #f4f7fa;
  border: 1px solid #c8d0dc;
  border-top: 0;
  font-size: 11px;
  color: #3a4a5c;
}
.doc-tax-bank-row span { white-space: nowrap; }
.doc-note strong {
  display: block;
  margin-bottom: 8px;
  color: #17202a;
  font-size: 14px;
  font-weight: 600;
}

.contractor-document-page { font-family: 'Kanit', Arial, sans-serif; }
.contractor-doc-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.contractor-doc-brand { display: flex; gap: 10px; align-items: flex-start; max-width: 530px; }
.contractor-preview-logo { display: grid; place-items: center; width: 66px; height: 66px; flex: 0 0 66px; border: 3px solid #0878b8; color: #0878b8; font-weight: 600; }
.contractor-preview-logo img { width: 100%; height: 100%; object-fit: contain; }
.contractor-doc-brand > div:last-child { display: grid; gap: 4px; }
.contractor-doc-brand strong { font-size: 14px; font-weight: 500; }
.contractor-doc-brand small { color: #4d5b68; font-size: 9px; line-height: 1.45; }
.contractor-doc-original { display: grid; gap: 6px; min-width: 150px; text-align: right; }
.contractor-doc-original > strong { font-size: 25px; font-weight: 400; }
.contractor-doc-original > b { padding: 8px; background: #fff200; font-size: 13px; font-weight: 500; }
.contractor-doc-title { margin: 12px 0 8px; text-align: center; font-size: 22px; font-weight: 400; }
.contractor-doc-info { display: grid; gap: 5px; margin: 8px 0 18px; }
.contractor-doc-info > div { display: grid; grid-template-columns: 150px 1fr; min-height: 28px; border-bottom: 1px solid #17202a; }
.contractor-doc-info strong { font-size: 12px; font-weight: 400; }
.contractor-doc-info span { font-size: 12px; }
.contractor-doc-table { min-width: 0; border: 2px solid #17202a; }
.contractor-doc-table th, .contractor-doc-table td { border: 1px solid #17202a; background: #fff; color: #17202a; }
.contractor-doc-table th:first-child { width: 150px; }
.contractor-doc-table th:last-child, .contractor-doc-table td:last-child { width: 155px; text-align: right; }
.contractor-doc-table tbody::after { content: ""; display: table-row; height: 270px; }
.contractor-payment-box { margin-top: 0; padding: 10px 160px 10px 160px; border: 2px solid #17202a; border-top: 0; }
.contractor-payment-box > strong { display: block; text-decoration: underline; }
.contractor-payment-box p { margin: 6px 0; font-size: 11px; }
.contractor-payment-box > div { display: grid; gap: 3px; padding: 9px; background: #97d542; text-align: center; }
.contractor-doc-totals { width: 330px; margin-left: auto; border: 2px solid #17202a; border-top: 0; }
.contractor-doc-totals > div { display: grid; grid-template-columns: 1fr 130px; border-bottom: 1px solid #17202a; }
.contractor-doc-totals span, .contractor-doc-totals strong { padding: 6px 9px; text-align: right; font-size: 12px; }
.contractor-doc-totals strong { border-left: 1px solid #17202a; }
.contractor-doc-totals .grand-total { background: #f4f7f9; }
.contractor-signatures { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; margin-top: 40px; }
.contractor-signatures > div { display: grid; gap: 5px; text-align: center; }
.contractor-signatures span { height: 34px; border-bottom: 1px solid #17202a; }
.contractor-signatures strong { font-size: 11px; font-weight: 400; }
.contractor-signatures small { color: #4d5b68; }
.document-preview-modal { width: min(1160px, calc(100vw - 28px)); max-width: calc(100vw - 28px); }
.preview-only-dialog { padding: 16px; max-height: calc(100vh - 28px); overflow: auto; background: #1a1e26; }
.preview-only-dialog > .modal-head { position: sticky; top: 0; z-index: 2; margin: -16px -16px 16px; padding: 12px 16px; background: var(--surface); }
.preview-only-dialog > .modal-head small { color: var(--ink-3); }
.preview-only-body { overflow: auto; }
.preview-only-body .document-page { position: relative; margin-bottom: 18px; }

/* รายละเอียดย่อยใต้ชื่อรายการ */
.doc-desc-cell > div { min-width: 0; }
.doc-subdetail {
  font-size: 11px; color: #5a6672; line-height: 1.45;
  margin-top: 3px; white-space: pre-wrap; word-break: normal; overflow-wrap: break-word;
}
/* placeholder จางไว้ก่อน โผล่ชัดเมื่อชี้แถวหรือคลิก — กันตารางดูรก
   (จองที่ไว้เท่าเดิมตลอด แถวจึงไม่กระตุกตอนชี้) */
.doc-subdetail:empty::before {
  content: attr(data-placeholder);
  color: #c3ccd6; font-style: italic; font-size: 10.5px;
  opacity: 0; transition: opacity 0.12s;
}
#preview-lines tr:hover .doc-subdetail:empty::before,
.doc-subdetail:focus::before { opacity: 1; }
/* พรีวิว/งานพิมพ์: ถ้าไม่ได้กรอกก็ยุบหายไปเลย ไม่กินพื้นที่ */
#document-preview-modal-body .doc-subdetail:empty,
.print-measure-box .doc-subdetail:empty { display: none !important; }
.line-subdetail-label input { font-size: 12px; }

/* หน้าสุดท้าย: ดันบล็อกลายเซ็นลงไปชิดท้ายกระดาษเหมือนเอกสารจริง
   (ในกล่องวัดความสูงไม่มีที่ว่างเหลือ margin-top:auto จึงไม่กระทบการแบ่งหน้า) */
#document-preview-modal-body .document-page,
.print-measure-box .document-page { display: flex; flex-direction: column; }
#document-preview-modal-body .document-page > .doc-footer,
.print-measure-box .document-page > .doc-footer { margin-top: auto; }

/* หัวกระดาษแบบย่อสำหรับหน้าที่ 2 เป็นต้นไป */
.doc-cont-head {
  display: flex; align-items: center; gap: 10px;
  border-bottom: 2px solid #17202a;
  padding-bottom: 7px; margin-bottom: 12px;
  color: #17202a;
}
.doc-cont-head img { height: 30px; width: auto; }
.doc-cont-title { font-weight: 700; font-size: 14px; white-space: nowrap; }
.doc-cont-meta {
  margin-left: auto; text-align: right; font-size: 10.5px; color: #4a5560;
  line-height: 1.4; max-width: 62%;
}
.doc-cont-meta em { font-style: normal; color: #8a95a1; }

/* ในหน้าพรีวิว/ตอนวัดความสูง ต้องเห็นเหมือนกระดาษที่พิมพ์จริง
   ไม่มีปุ่มแก้ไข ไม่มีข้อความ "คลิกเพื่อกรอก" ไม่มีกรอบไฮไลต์ */
#document-preview-modal-body .no-print,
.print-measure-box .no-print { display: none !important; }
#document-preview-modal-body .doc-editable-empty::before,
.print-measure-box .doc-editable-empty::before { content: "" !important; }
/* ช่องลายเซ็นที่ยังไม่อนุมัติ ให้เว้นว่างจริง ๆ บนใบที่พิมพ์/พรีวิว */
#document-preview-modal-body .sig-placeholder,
.print-measure-box .sig-placeholder { visibility: hidden !important; }
#document-preview-modal-body .doc-editable,
.print-measure-box .doc-editable {
  box-shadow: none !important;
  background: transparent !important;
  cursor: default !important;
}
.document-page-number { position: absolute; right: 30px; bottom: 15px; color: #64707d; font-size: 10px; font-weight: 300; }
.print-measure-box {
  position: absolute;
  left: -10000px;
  top: 0;
  width: 794px;
  visibility: hidden;
  pointer-events: none;
  z-index: -1;
}
.print-measure-box .document-page {
  margin: 0;
  box-shadow: none;
  transform: none !important;
  zoom: 1 !important;
  /* ต้องวัดความสูง "เนื้อหาจริง" เท่านั้น ถ้าติด min-height 297mm ไว้
     ทุกหน้าจะวัดได้ 1123px > เพดาน แล้วระบบจะตัดหน้าใหม่ทุก 1 บรรทัด */
  min-height: 0 !important;
  height: auto !important;
}
.doc-note p {
  padding: 10px 12px;
  border-left: 3px solid #0072bc;
  background: #f8fafc;
  white-space: normal;
}
.doc-note.has-terms {
  background: #fffbe6;
  border: 1px solid #f0c000;
  padding: 10px 14px;
}
.doc-note.has-terms strong { color: #7c5a00; }
.doc-note.has-terms p { background: transparent; border-left-color: #f0c000; }
tr.doc-discount-line td { color: #c0392b; font-style: italic; }
tr.doc-discount-line td:last-child { font-weight: 700; }
/* Dual currency column */
.doc-table th:last-child, .doc-table td:last-child { /* override for currency2 */ }
td.doc-cell-currency2, th#preview-label-total2 {
  text-align: right;
  color: #2563a0;
  font-size: 11px;
  white-space: nowrap;
  border-left: 1px solid #dce0e8;
  background: #f5f8ff;
}
.grand-total-currency2 {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 12px;
  color: #2563a0;
  border-top: 1px dashed #c0d4f0;
}
.grand-total-currency2 strong { font-weight: 700; }
.currency-rate-warning {
  margin: 6px 0 0;
  padding: 6px 8px;
  border: 1px dashed #f0c000;
  background: #fffbe6;
  color: #7c5a00;
  font-size: 10.5px;
  line-height: 1.45;
}
.doc-title { text-align: right; }
.doc-title h1 { font-size: 26px; font-weight: 700; }
 
.doc-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 16px 0;
  padding: 10px 12px;
  border: 1px solid #d8e0e8;
  border-radius: 0;
  background: #f8fafc;
}
 
.doc-info-grid strong { display: block; margin-bottom: 5px; font-size: 12px; font-weight: 500; }

.doc-info-grid p {
  font-size: 11px;
  line-height: 1.38;
}

.settings-numbering-panel { grid-column: 1 / -1; }

/* ─── CUSTOMER MANAGEMENT ─────────────────────────────────── */
.settings-customers-panel { grid-column: 1 / -1; }

.cust-company-tabs {
  display: flex;
  gap: 0;
  padding: 14px 0 0;
  border-bottom: 2px solid var(--line);
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.cust-tab {
  padding: 8px 20px;
  border-radius: 0;
  border: 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  background: transparent;
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.cust-tab:hover { color: var(--ink); background: var(--surface-2); }
.cust-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }

.cust-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}
.cust-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cust-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.cust-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  display: block;
}
.cust-tax {
  font-size: 11px;
  color: var(--ink-3);
  display: block;
  margin-top: 1px;
}
.cust-company-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.cust-company-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 0;
  background: var(--accent-subtle, rgba(59,130,246,.12));
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
}
.cust-address {
  font-size: 12px;
  color: var(--ink-2);
  margin: 0;
  line-height: 1.5;
}
.cust-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 12px;
  color: var(--ink-2);
}
.cust-contact-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 12px;
}
.cust-contact-link:hover { text-decoration: underline; }
.cust-note {
  font-size: 12px;
  color: var(--ink-3);
  background: var(--surface-2);
  border-left: 3px solid var(--gold, #e6a817);
  padding: 6px 10px;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 0;
}
.cust-profile-note {
  margin: 0;
  padding: 7px 10px;
  border: 1px solid #bfd3ee;
  background: #f6f9ff;
  color: #2563a0;
  font-size: 11px;
  line-height: 1.45;
}
.cust-contacts-wrap { border-top: 1px solid var(--line); padding-top: 8px; }
.cust-contacts-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin: 0 0 6px;
}
.cust-contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid var(--line-subtle, var(--line));
  font-size: 12px;
}
.cust-contact-row:last-child { border-bottom: 0; }
.cust-contact-name { font-weight: 600; color: var(--ink); }
.cust-contact-title { color: var(--ink-3); }
.cust-no-contact { font-size: 12px; color: var(--ink-3); margin: 0; }
.empty-hint { font-size: 13px; color: var(--ink-3); padding: 24px; text-align: center; }

/* Customer modal contacts editor */
.cust-contacts-section {
  margin-top: 16px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
.cust-contacts-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  font-size: 13px;
}
.cust-contact-edit-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr auto;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}
.cust-contact-field {
  padding: 6px 8px;
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
}
.cust-contact-field:focus { outline: none; border-color: var(--accent); }
.danger-icon {
  color: #e54;
  border-color: transparent;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  border: 0;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
}
.danger-icon:hover { background: rgba(238,85,68,.1); }
.customer-modal { width: min(680px, 96vw); }

.numbering-input {
  width: 100%;
  min-width: 90px;
}

.numbering-sample {
  display: inline-block;
  padding: 6px 10px;
  border-radius: 0;
  background: #e6f3fb;
  color: var(--brand);
  font-size: 12px;
  font-weight: 500;
}
 
.doc-table {
  min-width: 0;
  margin-top: 8px;
  border: 1px solid #cfd8e2;
  table-layout: fixed;
}
 
.doc-table th { background: #0072bc; color: #fff; font-weight: 600; line-height: 1.25; }
/* ภาษาไทยไม่มีเว้นวรรค ถ้าใช้ word-break: break-word เบราว์เซอร์จะตัดกลางคำ
   ("รายการ" → "รายกา / ร") ต้องใช้ normal + auto phrase เพื่อให้ตัดตามคำจริง */
.doc-table th, .doc-table td {
  white-space: normal; border: 1px solid #d8e0e8;
  word-break: normal; overflow-wrap: break-word; line-break: auto; hyphens: none;
}
/* คอลัมน์สั้น ๆ (จำนวน/หน่วย) ไม่ควรตัดคำเลย */
.doc-table td:nth-child(3), .doc-table td:nth-child(4),
.doc-table th:nth-child(3), .doc-table th:nth-child(4) { word-break: keep-all; overflow-wrap: normal; }
/* A4 layout: no | description | qty | unit | unit price | total */
.doc-table th:first-child,
.doc-table td:first-child { text-align: center; width: 42px; }
.doc-table th:nth-child(2),
.doc-table td:nth-child(2) { width: auto; }
.doc-table th:nth-child(3),
.doc-table td:nth-child(3) { text-align: center; width: 70px; }
.doc-table th:nth-child(4),
.doc-table td:nth-child(4) { text-align: center; width: 76px; }
.doc-table th:nth-child(5),
.doc-table td:nth-child(5),
.doc-table th:nth-child(6),
.doc-table td:nth-child(6) { text-align: right; width: 118px; }

.doc-category-row td {
  background: #dff1fb;
  color: #0072bc;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0;
}

.doc-category-total-row td {
  background: #f3f8fc;
  color: #17202a;
  font-weight: 700;
  font-size: 12px;
  text-align: right !important;
}
.doc-category-total-row td:first-child {
  text-align: left !important;
  font-weight: 700;
  color: #0072bc;
}

.document-label-settings {
  margin: 0 0 16px;
  padding: 12px;
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius);
  background: var(--bg-3);
}

.document-label-settings summary {
  cursor: pointer;
  color: var(--gold);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.document-label-settings .form-grid {
  margin-top: 12px;
  margin-bottom: 0;
}
 
.doc-summary {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 24px;
  margin-top: 22px;
}
 
.summary-table { display: grid; gap: 8px; }
 
.summary-table div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid #d8e0e8;
}
 
.summary-table .grand-total {
  padding: 12px;
  border: 0;
  border-radius: var(--radius);
  background: #17202a;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
}
 
/* Net payable row (after WHT deduction) */
.net-payable-row {
  padding: 8px 12px !important;
  border: 0 !important;
  border-radius: var(--radius);
  background: #eff6ff;
  border: 1.5px solid #93c5fd !important;
  color: #1d4ed8 !important;
  font-size: 13px;
  font-weight: 700;
  margin-top: 4px;
}
.net-payable-row span, .net-payable-row strong { color: #1d4ed8 !important; }

.tax-toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-right: 8px;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
}

/* WHT label styling in summary */
#preview-label-wht { color: #dc2626; }
#preview-wht { color: #dc2626; }

/* Receipt payment section */
.receipt-payment-section {
  margin: 10px 0 6px;
  padding: 8px 12px;
  background: #f8fafc;
  border: 1px solid #e0e6ec;
  border-radius: 0;
  font-size: 11px;
  color: #3a4a5c;
}
.receipt-method-row { margin: 0 0 4px; }
.receipt-method-note { margin: 0; color: #6b7a8a; font-style: italic; }

/* Amount in words */
.amount-in-words {
  margin: 4px 0 0;
  padding: 6px 10px;
  background: #f4f7fa;
  border: 1px solid #e0e6ec;
  color: #3a4a5c;
  font-size: 12px;
  text-align: center;
}

/* Document footer */
.doc-footer {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 60px;
  margin-top: 50px;
  text-align: center;
}
.doc-footer-signer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}
.sig-underline {
  display: block;
  width: 100%;
  height: 1px;
  background: #17202a;
  margin: 3px 0 6px;
}
.doc-footer p { margin: 0; font-size: 12px; color: #4d5b68; }
.doc-footer strong {
  display: block;
  min-height: 18px;
  color: #17202a;
  font-size: 13px;
  font-weight: 500;
}
.doc-footer-contact {
  display: block;
  font-size: 10px;
  color: #4d5b68;
  margin-top: 4px;
}
.doc-footer-date {
  display: block;
  font-size: 11px;
  color: #4d5b68;
  margin-top: 2px;
}

/* Company footer bar */
.doc-footer-bar {
  margin-top: 24px;
  padding: 6px 0;
  border-top: 1px solid #17202a;
  text-align: center;
  font-size: 10px;
  color: #4d5b68;
}

.signature-box {
  display: grid;
  place-items: end center;
  height: 64px;
  margin-bottom: 4px;
}

.signature-box img {
  max-width: 180px;
  max-height: 58px;
  object-fit: contain;
}
 
/* ─── RECEIPT PAGE ───────────────────────────────────────── */
.receipt-preview-wrap {
  position: sticky;
  top: 20px;
  max-height: calc(100vh - 60px);
  overflow: auto;
  padding: 16px;
  border-radius: var(--radius-lg);
  background: #1a1e26;
}

#substitute-receipt-pages.side-attachment-preview {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-auto-flow: row;
  gap: 18px;
  justify-items: center;
  align-items: start;
  overflow-x: auto;
}

#substitute-receipt-pages.side-attachment-preview .expense-preview-pair {
  display: grid;
  grid-template-columns: minmax(0, max-content);
  grid-auto-flow: row;
  gap: 16px;
  align-items: start;
  justify-content: center;
  justify-items: center;
  width: 100%;
}

#substitute-receipt-pages.side-attachment-preview .expense-preview-pair > .receipt-page-tag {
  grid-column: 1 / -1;
  width: 100%;
  margin: 0;
}

#line-view #substitute-receipt-pages.side-attachment-preview .receipt-page + .receipt-page,
#line-view #substitute-receipt-pages.side-attachment-preview .expense-preview-pair + .expense-preview-pair {
  margin-top: 0;
}

#substitute-receipt-pages.side-attachment-preview .receipt-page,
#substitute-receipt-pages.attachment-only-preview .receipt-page {
  margin: 0;
}

#substitute-receipt-pages.attachment-only-preview {
  display: grid;
  gap: 18px;
  justify-content: center;
}
 
.receipt-page {
  width: 794px;
  min-height: 1123px;
  margin: 0 auto;
  padding: 54px;
  border: 1px solid #c8d0dc;
  background: #fff;
  color: #17202a;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
  font-family: 'Kanit', Arial, sans-serif;
}
 
.receipt-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 20px;
  border-bottom: 2px solid #17202a;
}
 
.receipt-header h2, .receipt-header p, .receipt-company p { margin: 0; }
.receipt-header h2 { margin-bottom: 8px; color: #17202a; font-size: 28px; font-weight: 700; }
.receipt-header p { color: #5b6673; }
.receipt-header div:last-child { display: grid; gap: 6px; color: #17202a; text-align: right; }
 
.receipt-company {
  margin: 20px 0;
  padding: 14px;
  border-radius: var(--radius);
  background: #f8fafc;
  color: #17202a;
}

.receipt-company p {
  color: #5b6673;
}
 
.receipt-info-table { min-width: 0; border: 1px solid #d8e0e8; }
.receipt-info-table th { width: 210px; background: #f1f5f9; color: #17202a; text-transform: none; font-weight: 500; }
.receipt-info-table th, .receipt-info-table td { white-space: normal; border: 1px solid #d8e0e8; }
.receipt-info-table td { color: #25313f; font-weight: 500; }
 
.receipt-photo {
  display: grid;
  place-items: center;
  min-height: 220px;
  margin-top: 20px;
  border: 1px dashed #aab6c3;
  border-radius: var(--radius);
  color: #5b6673;
  background: #f8fafc;
  font-size: 13px;
}
 
.receipt-photo img { max-width: 100%; max-height: 360px; object-fit: contain; }
.receipt-signatures { margin-top: 80px; }

.substitute-form-page {
  width: 1120px;
  min-height: 792px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 42px 44px;
  color: #222;
  font-family: 'Kanit', Arial, sans-serif;
}

.receipt-page.expense-paper-page {
  width: 1120px;
  max-width: none;
  min-height: 792px;
}

.sub-form-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 26px;
  align-items: start;
  margin-bottom: 4px;
}

.sub-form-company {
  display: grid;
  grid-template-columns: 70px 1fr;
  gap: 10px;
  align-items: start;
  font-size: 10.5px;
  line-height: 1.35;
}

.sub-form-company img {
  width: 62px;
  height: 62px;
  object-fit: contain;
}

.sub-form-company strong {
  display: block;
  font-size: 18px;
  line-height: 1.05;
}

.sub-form-company span {
  display: block;
  margin-bottom: 2px;
  font-size: 10px;
}

.sub-form-company p { margin: 0; color: #333; }

.sub-form-meta {
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.sub-form-no {
  margin-bottom: 2px;
  text-align: right;
  color: #555;
}

.sub-form-no strong {
  margin-left: 10px;
  color: #222;
  font-size: 18px;
  letter-spacing: 1px;
}

.sub-form-meta label {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #444;
}

.sub-form-meta .box {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid #777;
}

.sub-form-meta .box.checked::after {
  content: "";
  width: 18px;
  height: 9px;
  border-left: 2px solid #777;
  border-bottom: 2px solid #777;
  transform: rotate(-45deg) translate(1px, -2px);
}

.sub-form-date {
  margin-top: 2px;
  padding-top: 4px;
  border-top: 1px solid #999;
  text-align: center;
}

.sub-form-project-line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(180px, .55fr) minmax(0, 1.1fr);
  border: 2px solid #777;
  border-bottom: 0;
  font-size: 12px;
}

.sub-form-project-line > div {
  min-height: 34px;
  padding: 7px 10px;
  border-right: 1px solid #777;
}

.sub-form-project-line > div:last-child { border-right: 0; }
.sub-form-project-line strong { margin-left: 10px; font-weight: 600; }

.sub-form-table {
  width: 100%;
  flex: 1 1 auto;
  table-layout: fixed;
  border-collapse: collapse;
  color: #222;
  font-size: 9.5px;
}

.sub-form-table th,
.sub-form-table td {
  border: 2px solid #777;
  padding: 4px 5px;
  vertical-align: top;
  overflow-wrap: anywhere;
}

.sub-form-table th {
  height: 30px;
  background: #f5f5f5;
  text-align: center;
  font-weight: 600;
  line-height: 1.15;
}

.sub-form-table th small {
  display: block;
  margin-top: 2px;
  color: #444;
  font-size: 10px;
  font-weight: 500;
}

.sub-form-table tbody td { height: 24px; }
.sub-form-table .sub-form-date-cell { width: 8%; white-space: nowrap; }
.sub-form-table .sub-form-cat { width: 10%; }
.sub-form-table .sub-form-desc { width: 22%; }
.sub-form-table .sub-form-attach { width: 11%; text-align: center; }
.sub-form-table .sub-form-docno { width: 10%; }
.sub-form-table .sub-form-vendor { width: 13%; }
.sub-form-table .sub-form-base,
.sub-form-table .sub-form-vat,
.sub-form-table .sub-form-amount {
  text-align: right;
  white-space: nowrap;
}
.sub-form-table .sub-form-base { width: 8%; }
.sub-form-table .sub-form-vat { width: 7%; }
.sub-form-table .sub-form-amount { width: 11%; }

.sub-form-table tfoot td {
  height: 34px;
  font-weight: 600;
  text-align: right;
}

.sub-form-bank-line {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin: 8px 0 8px;
  color: #555;
  font-size: 12px;
}

.sub-form-bank-line span {
  border-bottom: 1px dotted #999;
  min-height: 22px;
}

.sub-form-approval-note {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin: 4px 0 8px;
  border: 1px solid #999;
  color: #222;
  font-size: 11px;
}

.sub-form-approval-note div {
  min-width: 0;
  padding: 6px 8px;
  border-right: 1px solid #999;
  border-bottom: 1px solid #999;
}

.sub-form-approval-note div:last-child { border-right: 0; }
.sub-form-approval-note div { border-bottom: 0; }

.sub-form-approval-note span {
  display: block;
  margin-bottom: 2px;
  color: #555;
  font-size: 9px;
}

.sub-form-approval-note strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 10.5px;
  line-height: 1.3;
}

.sub-form-signatures {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 24px;
  margin-top: auto;
}

.sub-form-signatures div {
  display: grid;
  place-items: center;
  min-height: 64px;
  border: 2px solid #999;
  text-align: center;
}

.sub-form-signatures span {
  min-height: 26px;
  color: #1f3f87;
  font-weight: 600;
}

.sub-form-signatures strong {
  color: #444;
  font-size: 12px;
  font-weight: 500;
}

.substitute-attachment-page {
  width: 1120px;
  min-height: 792px;
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 38px 44px;
  color: #222;
  font-family: 'Kanit', Arial, sans-serif;
}

.attachment-packet-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 18px;
  align-items: start;
  padding-bottom: 14px;
  border-bottom: 2px solid #111;
}

.attachment-packet-head h2 { margin: 0 0 4px; font-size: 24px; }
.attachment-packet-head p,
.attachment-packet-head small { margin: 0; color: #555; font-size: 12px; }
.attachment-packet-meta { text-align: right; font-size: 12px; }

.attachment-only-page .attachment-packet-head {
  border-bottom-color: #2563eb;
}

.attachment-only-page .attachment-packet-head h2 {
  color: #1d4ed8;
}

.attachment-only-page .attachment-packet-head small {
  display: block;
  max-width: 720px;
  color: #475569;
  line-height: 1.6;
}

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

.attachment-packet-grid div {
  min-height: 48px;
  padding: 9px 11px;
  border: 1px solid #cfd7e2;
}

.attachment-packet-grid span {
  display: block;
  color: #667085;
  font-size: 10.5px;
}

.attachment-packet-grid strong {
  display: block;
  margin-top: 3px;
  font-size: 13px;
}

.attachment-checklist,
.attachment-file-sheet { border: 1px solid #cfd7e2; }

.attachment-checklist h3,
.attachment-file-sheet h3 {
  margin: 0;
  padding: 9px 12px;
  border-bottom: 1px solid #cfd7e2;
  background: #f4f7fb;
  font-size: 14px;
}

.attachment-checklist ul,
.attachment-file-sheet ul {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
  padding: 12px;
  list-style: none;
}

.attachment-checklist li,
.attachment-file-sheet li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 8px;
  align-items: start;
  min-height: 26px;
  font-size: 12.5px;
}

.attachment-check-box {
  display: inline-grid;
  place-items: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid #555;
}

.attachment-check-box::after {
  content: "";
  width: 10px;
  height: 5px;
  border-left: 1.5px solid #555;
  border-bottom: 1.5px solid #555;
  transform: rotate(-45deg) translate(1px, -1px);
}

.attachment-image-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 8px;
}

.attachment-image-grid figure {
  margin: 0;
  padding: 8px;
  border: 1px dashed #b8c6d8;
  background: #fafcff;
}

.attachment-image-grid img {
  width: 100%;
  max-height: 145px;
  object-fit: contain;
  background: #fff;
}

.attachment-image-grid figcaption {
  margin-top: 5px;
  color: #555;
  font-size: 10.5px;
  text-align: center;
}

@media (min-width: 981px) {
  #line-view .receipt-page {
    zoom: 0.78;
  }
  #line-view .receipt-page.expense-paper-page {
    zoom: 0.66;
  }
  #line-view #substitute-receipt-pages.side-attachment-preview {
    justify-content: center;
  }
  #line-view #substitute-receipt-pages.side-attachment-preview .expense-preview-pair {
    grid-template-columns: minmax(0, max-content);
    gap: 16px;
  }
  #line-view #substitute-receipt-pages.side-attachment-preview .receipt-page.expense-paper-page {
    zoom: 0.56;
  }
  #line-view #substitute-receipt-pages.attachment-only-preview .receipt-page.expense-paper-page {
    zoom: 0.66;
  }
  #line-view .receipt-page + .receipt-page {
    margin-top: 18px;
  }
  #line-view #substitute-receipt-pages.side-attachment-preview .receipt-page + .receipt-page {
    margin-top: 0;
  }
}

@media (min-width: 1700px) {
  #line-view #substitute-receipt-pages.side-attachment-preview .receipt-page.expense-paper-page {
    zoom: 0.62;
  }
}
 
/* ─── PRODUCTION SECTION ─────────────────────────────────── */
.report-panel { margin-top: 18px; }
.production-grid.lower { margin-top: 18px; }
.production-metrics .metric-card:nth-child(4) strong { color: var(--gold-bright); }

/* Readability tuning */
body {
  font-weight: 350;
}

.topbar h2,
.metric-card strong,
.queue-item strong,
.record > strong,
.record-numbers strong,
.chat-card span,
.doc-title h1,
.receipt-header h2 {
  font-weight: 500;
}

.brand-mark,
.brand h1,
.nav-item.active,
.primary-button,
.panel h3,
.modal-head h3,
.detail-body h4,
.line-editor-head h4,
th,
.tag,
.status,
.export-card strong,
.detail-item strong,
.detail-summary strong,
.doc-info-grid strong,
.summary-table .grand-total,
.receipt-info-table td {
  font-weight: 400;
}

.metric-card span,
.eyebrow,
.modal label,
.form-grid label,
.line-row label,
.workflow span,
.workflow strong {
  font-weight: 300;
}

.metric-card small,
.queue-item small,
.record small,
.timeline-item span:not(.status),
.detail-summary span,
.detail-item span,
.empty-detail,
.export-card span,
.backup-actions p {
  color: var(--ink-2);
  font-weight: 300;
}

.metric-card strong {
  font-size: 21px;
}

.detail-summary strong,
.detail-item b {
  font-size: 14px;
  font-weight: 450;
}

.detail-item strong {
  font-size: 13px;
}

td,
.record,
.queue-item,
.timeline-item {
  font-weight: 350;
}

select,
input,
textarea,
button {
  font-weight: 350;
}
 
/* ─── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 980px) {
  body { padding-top: 64px; }
  body.menu-open { overflow: hidden; }
  .mobile-header {
    position: fixed;
    inset: 0 0 auto 0;
    width: 100%;
    max-width: 100vw;
    z-index: 220;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) 44px;
    align-items: center;
    height: 64px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: rgba(255,255,255,0.96);
    box-shadow: 0 4px 18px rgba(30,83,119,0.08);
  }
  .desktop-language { display: none; }
  .mobile-language { display: block !important; justify-self: end; }
  .login-screen { align-items: center; justify-content: center; padding: 16px; }
  .mobile-menu-button, .sidebar-close {
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-size: 22px;
  }
  .mobile-brand {
    display: flex;
    align-items: center;
    justify-self: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
  }
  .mobile-brand img { width: 36px; height: 36px; border-radius: 0; object-fit: cover; }
  .mobile-brand strong { overflow: hidden; text-overflow: ellipsis; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 300;
    width: min(300px, 86vw);
    height: 100dvh;
    max-height: 100dvh;
    min-height: 100vh;
    padding: 20px 16px;
    gap: 18px;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 16px 0 36px rgba(30,83,119,0.18);
  }
  body.menu-open .sidebar { transform: translateX(0); }
  .sidebar-close { display: block; position: absolute; top: 12px; right: 12px; }
  .sidebar .brand { padding-right: 48px; }
  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 260;
    border: 0;
    background: rgba(19,37,52,0.42);
  }
  body.menu-open .sidebar-backdrop { display: block; }
  .nav {
    grid-template-columns: 1fr;
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 28px;
  }
  .workflow { display: none; }
  .app-shell {
    margin-left: 0 !important;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 18px;
    overflow-x: hidden;
  }
  .app-shell > *, .view, .panel, .metric-card, .content-grid { min-width: 0; max-width: 100%; }
  .metric-grid, .content-grid { grid-template-columns: 1fr 1fr; }
  .project-card-grid { grid-template-columns: repeat(2, minmax(260px, 1fr)); }
  .project-center-filters { grid-template-columns: 1fr 1fr; }
  .project-detail-summary, .project-doc-grid { grid-template-columns: 1fr 1fr; }
  .project-full-grid { grid-template-columns: 1fr; }
  .project-full-side { position: static; }
  .accounting-grid { grid-template-columns: minmax(0, 1fr); }
  .accounting-filters { grid-template-columns: 1fr 1fr; }
  .accounting-period-controls { grid-template-columns: 1fr 1fr; }
  .accounting-period-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .accounting-match-item { grid-template-columns: minmax(0, 1fr); }
  .accounting-match-actions { justify-content: space-between; }
  #accounting-modal {
    width: calc(100vw - 28px);
    max-width: calc(100vw - 28px);
    height: calc(100vh - 28px);
    max-height: calc(100vh - 28px);
  }
  #accounting-modal form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #billing-modal form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #advance-modal form, #advance-clear-modal form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .policy-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .incentive-workspace { grid-template-columns: 1fr; }
  .incentive-preview-panel { position: static; }
  .incentive-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #contractor-modal form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings-edit-modal form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .line-workspace { grid-template-columns: 1fr; }
  .line-form-panel, .receipt-preview-wrap { position: static; max-height: none; }
  .line-form-panel, .line-list-panel, .receipt-preview-wrap { grid-column: 1; grid-row: auto; }
  .line-approval-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calendar-toolbar { grid-template-columns: 1fr 1fr; }
  .calendar-toolbar h2 { grid-column: 1 / -1; }
  .executive-kpi-grid { grid-template-columns: 1fr 1fr; }
  .executive-breakdown-grid { grid-template-columns: 1fr 1fr; }
  .executive-attention-card { grid-column: 1 / -1; }
  .executive-filters { grid-template-columns: 1fr 1fr; }
}
 
@media (max-width: 680px) {
  .sidebar { padding: 18px 14px; }
  .brand { padding: 0; }
  .nav { grid-template-columns: 1fr; }
  .topbar, .queue-item, .record, .project-record, .record-actions, .timeline-item {
    align-items: stretch;
    flex-direction: column;
  }
  .panel-head { align-items: stretch; flex-direction: column; }
  .panel-head > select, .panel-head > button { width: 100%; }
  .line-rules-box .advance-rules-content ul,
  .line-rules-table,
  .line-policy-tables { grid-template-columns: 1fr; }
  .line-approval-summary { grid-template-columns: 1fr; }
  .sub-form-approval-note { grid-template-columns: 1fr; }
  .receipt-page.expense-paper-page .sub-form-approval-note { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .sub-form-approval-note div,
  .sub-form-approval-note div:nth-child(2n),
  .sub-form-approval-note div:nth-last-child(-n+2) {
    border-right: 0;
    border-bottom: 1px solid #999;
  }
  .receipt-page.expense-paper-page .sub-form-approval-note div {
    border-right: 1px solid #999;
    border-bottom: 0;
  }
  .receipt-page.expense-paper-page .sub-form-approval-note div:last-child { border-right: 0; }
  .sub-form-approval-note div:last-child { border-bottom: 0; }
  .panel h3, .topbar h2, label, th, td { word-break: keep-all; }
  .top-actions { width: 100%; flex-wrap: wrap; }
  .user-profile-chip { order: -1; max-width: none; flex: 1 1 100%; }
  .top-actions .primary-button, .top-actions .ghost-button { flex: 1 1 125px; }
  .role-switcher { flex: 1 1 190px; justify-content: space-between; }
  .topbar h2 { font-size: 22px; }
  .metric-grid, .content-grid, .settings-grid, .form-grid, .form-grid.two, .totals-inputs, .accounting-filters {
    grid-template-columns: 1fr;
  }
  .accounting-period-controls,
  .accounting-period-summary {
    grid-template-columns: 1fr;
  }
  .accounting-period-actions {
    align-items: stretch;
    flex-direction: column;
  }
  .accounting-match-summary { justify-items: start; }
  .accounting-match-actions { align-items: stretch; flex-direction: column; }
  .accounting-detail-match { align-items: stretch; flex-direction: column; }
  .project-card-grid, .project-center-filters, .project-detail-summary, .project-doc-grid {
    grid-template-columns: 1fr;
  }
  .detail-modal.detail-modal-full {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  .detail-modal-full .detail-dialog { padding: 14px; }
  .project-detail-hero { grid-template-columns: 1fr; }
  .project-budget-strip { grid-template-columns: 1fr 1fr; }
  .project-timeline-event { grid-template-columns: 1fr; }
  .project-doc-record, .project-doc-detail-head { grid-template-columns: 1fr; }
  .project-doc-detail-head { align-items: stretch; flex-direction: column; }
  .project-doc-actions { justify-content: stretch; }
  .project-doc-actions button { flex: 1 1 120px; }
  .project-chart-row { grid-template-columns: 86px minmax(0, 1fr); }
  .project-chart-row strong { grid-column: 2; text-align: left; }
  .project-calendar-card { overflow-x: auto; }
  .project-calendar-weekdays, .project-calendar-grid { min-width: 620px; }
  .calendar-toolbar { grid-template-columns: 1fr; }
  .executive-quarter { padding: 14px; }
  .executive-quarter-head { align-items: stretch; flex-direction: column; }
  .executive-period-label { min-width: 0; }
  .executive-kpi-grid, .executive-analysis-grid, .executive-breakdown-grid { grid-template-columns: 1fr; }
  .executive-attention-card { grid-column: auto; }
  .comparison-chart button { grid-template-columns: 82px minmax(80px,1fr) 44px; }
  .executive-filter-head, .pm-target-panel .panel-head { align-items: stretch; flex-direction: column; }
  .analytics-dimension-panel .panel-head { align-items: stretch; flex-direction: column; }
  .dimension-filter { min-width: 0; }
  .executive-filters { grid-template-columns: 1fr; }
  .choice-grid { grid-template-columns: 1fr; }
  .monthly-chart-row { grid-template-columns: 68px minmax(0, 1fr); }
  .calendar-actions { justify-content: stretch; }
  .calendar-actions button { flex: 1 1 130px; }
  .calendar-weekdays, .calendar-grid { grid-template-columns: repeat(7, minmax(94px, 1fr)); }
  .calendar-grid { min-width: 658px; }
  .calendar-day { min-height: 132px; padding: 7px; }
  .calendar-event { min-height: 48px; }
  .settings-users-panel { grid-column: auto; }
  #accounting-modal {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  #accounting-modal form {
    grid-template-columns: 1fr;
    padding: 18px;
  }
  #billing-modal {
    width: 100vw;
    max-width: 100vw;
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
  }
  #billing-modal form { grid-template-columns: 1fr; }
  #payment-modal form, #credit-note-modal form { grid-template-columns: 1fr; }
  #advance-modal form, #advance-clear-modal form { grid-template-columns: 1fr; }
  .advance-project-lines-head { align-items: stretch; flex-direction: column; }
  .advance-project-lines-head .ghost-button { width: 100%; }
  .advance-project-line { grid-template-columns: 1fr; }
  .advance-line-remove { grid-column: auto; grid-row: auto; justify-self: stretch; width: 100%; }
  .expense-entry-switch { grid-template-columns: 1fr; }
  .policy-grid, .advance-filter-row { grid-template-columns: 1fr; }
  .incentive-form { grid-template-columns: 1fr; }
  #contractor-modal form, #contractor-review-modal form, .review-checklist, .contractor-filter-row { grid-template-columns: 1fr; }
  .settings-edit-modal form { grid-template-columns: 1fr; }
  .record-numbers { justify-items: start; }
  .line-row { grid-template-columns: 1fr; }
  .timeline-item { display: flex; }
  .export-grid { grid-template-columns: 1fr; }
  .line-row strong { justify-content: flex-start; }
  .document-preview-wrap { padding: 8px; }
  .document-type-groups { grid-template-columns: 1fr; }
  .document-preview-wrap > .document-step-title { width: 720px; }
  .document-page, .receipt-page { width: 720px; padding: 36px; }
  .line-actions { flex-direction: column; }
  .panel { padding: 16px; }
  .table-wrap { margin-inline: -16px; padding-inline: 16px; }
  .login-screen { align-items: center; justify-content: center; padding: 16px; }
  .login-panel { width: 100%; max-width: 430px; margin: auto; padding: 24px; }
}
 
.signature-box em, .contractor-signatures em {
  display: grid;
  place-items: center;
  min-height: 34px;
  color: #52616f;
  font-size: 10px;
  font-style: normal;
  line-height: 1.4;
}
.contractor-signatures span img { max-width: 100%; max-height: 34px; object-fit: contain; }

@media print {
  @page { size: A4 portrait; margin: 0; }
  body { background: #fff; }
  .sidebar, .topbar, .mobile-header, .sidebar-backdrop, .no-print { display: none !important; }
  /* ปุ่มลอย "คู่มือ" กับป้ายเวอร์ชันมุมจอ ไม่ได้ถูกซ่อนตอนพิมพ์ ทั้งที่ลอยอยู่ต่ำกว่าขอบกระดาษ
     จึงสร้างหน้าที่ 2 ที่มีแต่ปุ่มนั้นทุกครั้งที่พิมพ์ */
  #manual-floating-button, #build-stamp, .toast, #toast-host { display: none !important; }
  /* กันหน้าเปล่าหน้าที่ 2: ล้างความสูง/overflow ของ container และซ่อนเนื้อหาอื่นเมื่อพิมพ์จากหน้าแก้เอกสาร */
  html, body {
    height: auto !important; min-height: 0 !important;
    margin: 0 !important; padding: 0 !important; overflow: visible !important;
  }
  dialog::backdrop, #document-fill-modal::backdrop { display: none !important; background: transparent !important; }
  .document-fill-modal { border: 0 !important; padding: 0 !important; margin: 0 !important; inset: auto !important; }
  .app-shell, main, .main-area { height: auto !important; min-height: 0 !important; overflow: visible !important; }
  body:has(#document-fill-modal[open]) #documents-view { display: none !important; }
  /* ตอนพิมพ์จากหน้าเอกสาร เปลือกแอป (แถบข้าง หัวเรื่อง เนื้อหาหน้าอื่น) ยังกินความสูงอยู่ ~20mm
     ดันให้ส่วนท้ายของใบไปโผล่หน้าที่ 2 ทั้งที่เนื้อหาแค่ 232mm
     ตัวกล่องเอกสารอยู่ "ใน" app-shell จึงซ่อนทั้งก้อนไม่ได้ ต้องล้างระยะขอบและซ่อนเฉพาะพี่น้อง */
  body:has(#document-fill-modal[open]) .app-shell {
    padding: 0 !important; margin: 0 !important; gap: 0 !important;
    display: block !important; height: auto !important; min-height: 0 !important;
  }
  body:has(#document-fill-modal[open]) .app-shell > *:not(dialog) { display: none !important; }
  .document-fill-modal, .document-workspace, .document-preview-wrap {
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
  }
  /* ล้างพื้นหลังเข้ม/ขอบมน/zoom ของหน้าจอพรีวิว ไม่ให้ติดไปในงานพิมพ์ */
  .doc-preview-viewport {
    background: #fff !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    border-radius: 0 !important;
    display: block !important;
  }
  .document-page {
    zoom: 1 !important;
    transform: none !important;
    border-radius: 0 !important;
    width: 210mm !important;
    /* เดิมตั้ง 297mm เท่าความสูง A4 พอดี เศษการปัดพิกเซลเกินไป 0.1mm
       ก็ดันส่วนท้ายไปขึ้นหน้าที่ 2 ทั้งที่เนื้อหาแค่ 232mm — เผื่อไว้ 2mm */
    min-height: 295mm !important;
    height: auto !important;
    /* ขอบกระดาษเป็นมิลลิเมตร ให้ตรงกับที่พิมพ์จริง — บน 14 / ข้าง 15 / ล่าง 16 */
    padding: 14mm 15mm 16mm !important;
    box-sizing: border-box !important;
    /* ใบยาวหลายหน้าต้องตัดหน้าได้ตามปกติ — บังคับ avoid ทั้งใบทำให้เอกสารยาว
       ถูกดันไปทั้งก้อนและเกิดหน้าเปล่านำหน้า */
    page-break-inside: auto;
    break-inside: auto;
  }
  /* ข้อความบอกสถานะลายเซ็น ไม่ต้องพิมพ์ออกกระดาษ ให้เว้นว่างไว้เซ็นจริง
     แต่ยังกันความสูงของช่องไว้ เส้นลายเซ็นจะได้ไม่ขยับ */
  .sig-note { visibility: hidden !important; }
  .doc-header,
  .doc-customer-section,
  .doc-tax-bank-row,
  .doc-summary,
  .amount-in-words,
  .receipt-payment-section,
  .doc-footer,
  .doc-footer-bar,
  .contractor-doc-header,
  .contractor-doc-info,
  .contractor-payment-box,
  .contractor-doc-totals,
  .contractor-signatures {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  .doc-table,
  .contractor-doc-table {
    page-break-inside: auto;
    break-inside: auto;
  }
  .doc-table thead,
  .contractor-doc-table thead {
    display: table-header-group;
  }
  .doc-table tr,
  .doc-table td,
  .doc-table th,
  .contractor-doc-table tr,
  .contractor-doc-table td,
  .contractor-doc-table th {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  /* ห้าม override ระยะห่างตอนพิมพ์ ไม่งั้นหน้าที่พิมพ์จะสั้นกว่าที่พรีวิววัดไว้
     ทำให้แต่ละหน้าเหลือที่ว่างท้ายใบ (พรีวิวกับงานพิมพ์ต้องเหมือนกัน) */
  /* ช่องกรอกในใบ: ไม่พิมพ์ placeholder / กรอบไฮไลต์ */
  .doc-editable, .document-page .doc-editable {
    box-shadow: none !important;
    background: transparent !important;
    outline: none !important;
  }
  .doc-editable-empty:not(:focus)::before { content: "" !important; }
  .dfa-head, .dfa-row2, .dfa-bottom, .dfa-extra, .line-editor, .line-editor-head { display: none !important; }
  .app-shell { margin: 0; padding: 0; }
  .view { display: none !important; }
  #documents-view { display: block !important; }
  .document-fill-modal { position: static !important; width: auto !important; height: auto !important; max-height: none !important; display: block !important; }
  body.preview-modal-open #documents-view { display: none !important; }
  body.preview-modal-open .document-preview-modal { position: static; display: block !important; width: auto; max-width: none; border: 0; box-shadow: none; }
  body.preview-modal-open .preview-only-dialog { max-height: none; padding: 0; overflow: visible; background: #fff; }
  body.preview-modal-open .preview-only-body { overflow: visible; }
  body.preview-modal-open .preview-only-body .document-page { display: block !important; }
  body.preview-modal-open .preview-only-body .document-page { break-after: page; page-break-after: always; }
  body.preview-modal-open .preview-only-body .document-page:last-child { break-after: auto; page-break-after: auto; }
  body.preview-modal-open .document-page-number { right: 12mm; bottom: 7mm; }
  body.print-line-receipt #documents-view { display: none !important; }
  body.print-line-receipt #line-view { display: block !important; }
  .document-workspace { display: block; }
  /* ตอนพิมพ์ใบรับรอง: ซ่อนเฉพาะฟอร์มและรายการ ไม่ซ่อนทั้ง workspace
     (ใบรับรองอยู่ข้างใน workspace ถ้าซ่อนทั้งก้อนจะไม่มีอะไรพิมพ์ออกมา) */
  body.print-line-receipt .line-workspace {
    display: block !important;
    grid-template-columns: none !important;
    gap: 0 !important;
    height: auto !important;
    overflow: visible !important;
  }
  body.print-line-receipt .line-form-panel,
  body.print-line-receipt .line-list-panel { display: none !important; }
  .document-preview-wrap {
    overflow: visible;
    padding: 0;
    background: #fff;
  }
  body.print-line-receipt .receipt-preview-wrap {
    overflow: visible;
    padding: 0;
    background: #fff;
  }
  body.print-line-receipt .expense-preview-pair,
  .expense-preview-pair {
    display: contents !important;
  }
  .document-page {
    width: 210mm !important;
    min-height: 295mm !important;   /* เผื่อเศษการปัดพิกเซล ไม่ให้ล้นไปหน้าถัดไป */
    height: auto !important;
    margin: 0 !important;
    padding: 54px !important;
    border: 0 !important;
    box-shadow: none !important;
    box-sizing: border-box !important;
  }
  body.print-line-receipt .document-page { display: none !important; }
  body.print-line-receipt .receipt-page {
    width: 210mm;
    min-height: auto;   /* ถ้าสูงเต็มหน้าพอดี จะดันเกิดหน้าว่างคั่น */
    height: auto;
    margin: 0;
    padding: 14mm 16mm;
    border: 0;
    box-shadow: none;
    zoom: 1;
    box-sizing: border-box;
    overflow: hidden;
  }
  body.print-line-receipt .receipt-preview-wrap { height: auto !important; min-height: 0 !important; }
  body.print-line-receipt .receipt-page-tag { display: none !important; }
  body.print-line-receipt .receipt-page {
    break-after: page;
    page-break-after: always;
  }
  body.print-line-receipt .receipt-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }
}
 


/* ── Advance Policy tables ─────────────────────────── */
.policy-section-head { margin: 18px 0 8px; font-size: 13px; font-weight: 600; color: var(--gold-bright); }
.setup-food-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 4px; }
.setup-food-table th, .setup-food-table td { border: 1px solid var(--line); padding: 5px 8px; text-align: center; }
.setup-food-table th { background: var(--gold-muted); color: var(--gold-bright); font-weight: 600; }
.setup-food-table td:first-child { text-align: left; font-weight: 500; }
.policy-checklist { margin: 12px 0 0; padding-left: 20px; }
.policy-checklist li { font-size: 12px; color: var(--ink-2); margin-bottom: 4px; }

.enh-click-row {
  cursor: pointer;
}

.enh-click-row:hover {
  background: #eef6ff;
}

.enh-click-row:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: -2px;
  background: #eef6ff;
}

.detail-attachments-cell {
  display: grid;
  gap: 10px;
  align-content: start;
}

.detail-attachments-cell > span {
  color: var(--ink-3);
  font-size: 12px;
}

.attachment-list {
  display: grid;
  gap: 8px;
}

.attachment-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  background: #f8fbff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.attachment-chip:hover,
.attachment-chip:focus-visible {
  border-color: var(--blue);
  background: #eef6ff;
}

.attachment-chip span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.attachment-chip small {
  flex: 0 0 auto;
  color: var(--blue);
  font-size: 11px;
}

.attachment-actions,
.attachment-pack-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-preview-pack {
  display: grid;
  gap: 14px;
  font-family: 'Kanit', 'Noto Sans Thai', Tahoma, Arial, sans-serif;
}

.attachment-preview-sheet {
  padding: 18px;
  border: 1px solid var(--line);
  background: #fff;
}

.attachment-preview-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 2px solid #111827;
}

.attachment-preview-head span {
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.attachment-preview-head h4 {
  margin: 4px 0 0;
  font-size: 18px;
  color: var(--ink);
}

.attachment-preview-sheet dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 16px;
  margin: 14px 0;
}

.attachment-preview-sheet dt {
  color: var(--ink-3);
  font-size: 11px;
}

.attachment-preview-sheet dd {
  margin: 2px 0 0;
  font-weight: 600;
}

.attachment-placeholder {
  display: grid;
  place-items: center;
  min-height: 220px;
  padding: 18px;
  border: 1px dashed #9fb3cc;
  background: #f8fbff;
  text-align: center;
  color: var(--ink-3);
}

.attachment-placeholder b {
  display: block;
  margin-bottom: 6px;
  color: var(--ink);
}


/* ── Toast Notifications ─────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-radius: 0; font-size: 14px; font-weight: 500; color: #fff; min-width: 260px; max-width: 380px; box-shadow: 0 4px 20px rgba(0,0,0,0.3); pointer-events: auto; animation: toastIn 0.25s ease; }
.toast.success { background: #1a7a4a; }
.toast.error { background: #c0392b; }
.toast.warning { background: #d4870a; }
.toast.info { background: #1a5fa8; }
.toast .toast-icon { font-size: 16px; flex-shrink: 0; }
.toast .toast-msg { flex: 1; }
.toast .toast-close { margin-left: auto; background: none; border: none; color: #fff; cursor: pointer; font-size: 18px; opacity: 0.7; padding: 0 0 0 8px; line-height: 1; }
.toast.fade-out { animation: toastOut 0.25s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; transform: translateX(0); } to { opacity: 0; transform: translateX(30px); } }


/* ── Modal Split (Live Preview) ─────────────────── */
dialog.modal-split {
  max-width: 96vw;
  width: 1180px;
  padding: 0;
  overflow: hidden;
  max-height: 92vh;
}
dialog.modal-split[open] {
  display: grid;
  grid-template-columns: minmax(400px, 500px) 1fr;
  align-items: stretch;
}
dialog.modal-split > form {
  overflow-y: auto;
  padding: 0;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
}
dialog.modal-split > form .modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 16px 20px;
  flex-shrink: 0;
}
dialog.modal-split > form .modal-head h3 { margin: 0; }
.modal-preview-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 4px 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  flex-shrink: 0;
}
.modal-preview-col-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.zoom-select {
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-1);
  cursor: pointer;
  height: 26px;
}
.modal-preview-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  padding-bottom: 16px;
}
.locked-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #fff3cd;
  color: #7a5800;
  border: 1px solid #ffc107;
  border-radius: 0;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
}
/* ── Billing print overlay (injected by printBillingDoc) ── */
#billing-print-overlay {
  display: none;
}

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

  /* Billing print mode: show only the cloned document overlay */
  body.billing-print-mode { margin: 0 !important; padding: 0 !important; background: #fff !important; }
  body.billing-print-mode > *:not(#billing-print-overlay) { display: none !important; }
  body.billing-print-mode #billing-print-overlay {
    display: block !important;
    position: static !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
  }
  body.billing-print-mode #billing-print-overlay .document-page {
    zoom: 1 !important;
    transform: none !important;
    box-shadow: none !important;
    border: 0 !important;
    margin: 0 !important;
    width: 210mm !important;
    max-width: 210mm !important;
    min-height: 295mm !important;   /* เผื่อเศษการปัดพิกเซล ไม่ให้ล้นไปหน้าถัดไป */
    padding: 54px !important;
    box-sizing: border-box !important;
  }
}
dialog.modal-split > form .form-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  align-content: start;
}
dialog.modal-split > form .form-body label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 600; color: var(--ink-2); }
dialog.modal-split > form .form-body label input,
dialog.modal-split > form .form-body label select,
dialog.modal-split > form .form-body label textarea { font-size: 13px; }
dialog.modal-split > form .form-body .full { grid-column: 1 / -1; }
dialog.modal-split > form .modal-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 12px 20px;
  flex-shrink: 0;
}
.modal-preview-col {
  overflow: hidden;
  background: var(--surface-2, #f4f4f6);
  border-left: 2px solid var(--line);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.preview-col-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.mini-doc {
  background: #fff;
  border-radius: 0;
  box-shadow: 0 2px 16px rgba(0,0,0,0.13);
  padding: 20px 22px;
  font-size: 11.5px;
  color: #1a1a1a;
  line-height: 1.55;
}
.mini-doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding-bottom: 10px;
  border-bottom: 2px solid #111;
  margin-bottom: 12px;
}
.mini-doc-co { font-weight: 700; font-size: 13px; }
.mini-doc-co-meta { font-size: 9.5px; color: #666; margin-top: 2px; max-width: 200px; }
.mini-doc-ref { text-align: right; font-size: 10px; color: #555; }
.mini-doc-title { text-align: center; font-size: 14px; font-weight: 700; margin: 8px 0 2px; }
.mini-doc-subtitle { text-align: center; font-size: 10px; color: #777; margin-bottom: 12px; }
.mini-doc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 12px;
  margin-bottom: 12px;
}
.mini-doc-grid div { display: flex; gap: 4px; font-size: 11px; }
.mini-doc-grid span { color: #888; white-space: nowrap; }
.mini-doc-grid strong { color: #111; word-break: break-word; }
.mini-doc-desc {
  background: #f7f7f9;
  border-radius: 0;
  padding: 8px 10px;
  font-size: 10.5px;
  white-space: pre-wrap;
  margin-bottom: 12px;
  border-left: 3px solid var(--gold-bright, #d4a017);
  color: #333;
}
.mini-doc-totals { border-top: 1px solid #ddd; padding-top: 8px; }
.mini-doc-totals div { display: flex; justify-content: space-between; padding: 2px 0; font-size: 11.5px; }
.mini-doc-totals .grand-total { font-weight: 700; font-size: 13px; border-top: 1.5px solid #111; padding-top: 6px; margin-top: 4px; }
.mini-doc-totals .grand-net { font-weight: 700; font-size: 13px; border-top: 2px solid var(--accent); padding-top: 6px; margin-top: 4px; color: var(--accent); }
.advance-mini-doc .mini-doc-grid div { flex-direction: column; gap: 1px; }
.advance-preview-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0 12px;
}
.advance-preview-table th,
.advance-preview-table td {
  padding: 6px 7px;
  border: 1px solid #d8e0e8;
  vertical-align: top;
  font-size: 10.5px;
  line-height: 1.35;
}
.advance-preview-table th {
  background: #0f75bc;
  color: #fff;
  font-weight: 600;
}
.advance-preview-table td:last-child,
.advance-preview-table th:last-child {
  text-align: right;
  white-space: nowrap;
}
.advance-preview-evidence {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 10px 0 12px;
}
.advance-preview-evidence section {
  padding: 9px 10px;
  border: 1px solid #d8e0e8;
  background: #f8fafc;
}
.advance-preview-evidence strong {
  display: block;
  margin-bottom: 5px;
  font-size: 11px;
}
.advance-preview-evidence ul {
  margin: 0;
  padding-left: 18px;
}
.advance-preview-evidence p,
.advance-preview-evidence li {
  margin: 0;
  color: #4d5b68;
  font-size: 10.5px;
  line-height: 1.45;
}

/* Billing form calc summary */
.billing-calc-summary {
  background: #f0f9ff; border: 1px solid #bae6fd; border-radius: var(--radius);
  padding: 10px 14px; display: grid; grid-template-columns: 1fr; gap: 2px;
  font-size: 13px;
}
.calc-summary-row { display: flex; justify-content: space-between; padding: 2px 0; }
.calc-summary-row span { color: var(--ink-2); }
.calc-summary-row.highlight { border-top: 1.5px solid var(--accent); margin-top: 4px; padding-top: 6px; font-weight: 700; }
.calc-summary-row.highlight span, .calc-summary-row.highlight strong { color: var(--accent); }

/* QT → Billing next-step button */
.accent-next-button {
  background: linear-gradient(135deg, #f0fdf4, #dcfce7) !important;
  color: #15803d !important; border: 1px solid #86efac !important;
  font-weight: 600;
}
.accent-next-button:hover { background: #bbf7d0 !important; border-color: #4ade80 !important; }
.mini-doc-bank { background: #f0f7ff; border-radius: 0; padding: 8px 10px; font-size: 10.5px; margin-top: 10px; }
.mini-doc-bank strong { display: block; font-size: 11px; margin-bottom: 3px; }

/* ── Export Modal ────────────────────────────────────────────── */
#export-modal { width: min(440px, calc(100vw - 32px)); }
#export-modal form { gap: 16px; }
.export-type-badge {
  display: inline-block;
  font-size: 11px; font-weight: 600; letter-spacing: .06em;
  padding: 3px 10px; border-radius: 0;
  background: rgba(21,120,190,.12); color: var(--accent);
}
.export-date-row {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
}
.export-preview-count {
  font-size: 20px; font-weight: 700; color: var(--accent);
  text-align: center; padding: 8px 0;
  border: 1px dashed rgba(21,120,190,.3);
  border-radius: var(--radius);
  background: rgba(21,120,190,.04);
}
.preview-placeholder { color: var(--ink-3); font-size: 13px; text-align: center; margin-top: 60px; }
@media (max-width: 860px) {
  dialog.modal-split[open] { grid-template-columns: 1fr; width: min(98vw, 520px); }
  .modal-preview-col { display: none; }
}

/* ─── QT STATUS BADGES ──────────────────────────────────── */
.status-signed {
  background: rgba(50, 196, 123, 0.18);
  color: #1a7a4c;
  font-weight: 600;
}
.status-pending {
  background: rgba(219, 73, 57, 0.12);
  color: #a83228;
}
.status-additional {
  background: rgba(99, 91, 255, 0.14);
  color: #4a43c8;
}

/* ─── QT SIGNED DOCS CHIP ──────────────────────── */
/* ─── FLOWACCOUNT-STYLE DOCUMENT TABLES ─────────────── */
.fa-page-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 20px 24px 12px; background: var(--surface);
}
.fa-page-title { font-size: 20px; font-weight: 700; color: var(--ink-1); margin: 0 0 3px; }
.fa-breadcrumb { font-size: 12px; color: var(--ink-3); margin: 0; }
.fa-create-btn { min-width: 100px; }
.fa-table-container { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.fa-table-toolbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface);
}
.fa-filter-tabs { display: flex; gap: 6px; }
.fa-tab {
  background: #f1f4f8 !important; border: 1px solid #d0d9e3; border-radius: 0;
  padding: 5px 18px; font-size: 13px; font-family: inherit; cursor: pointer;
  color: #536779 !important; -webkit-text-fill-color: #536779;
  transition: all 0.15s; line-height: 1.6; overflow: visible;
  -webkit-appearance: none; appearance: none; font-weight: 500;
}
.fa-tab.active { background: var(--accent) !important; color: #fff !important; -webkit-text-fill-color: #fff; border-color: var(--accent); font-weight: 600; }
.fa-tab:hover:not(.active) { background: #e2eaf3 !important; border-color: #aab8c8; color: #2d4a6b !important; -webkit-text-fill-color: #2d4a6b; }
.fa-toolbar-right { display: flex; gap: 8px; align-items: center; }
.fa-icon-btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: 0;
  padding: 5px 10px; cursor: pointer; font-size: 14px; color: var(--ink-2);
  transition: background 0.15s;
}
.fa-icon-btn:hover { background: var(--surface-2, #f0f4ff); }
.fa-icon-btn--active { background: var(--accent-light, #dbeeff); border-color: var(--accent); color: var(--accent); }

/* Labeled toolbar button (icon + text) */
.fa-label-btn {
  display: inline-flex; align-items: center; gap: 5px;
  height: 30px; padding: 0 10px; border-radius: 0;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 12px; font-weight: 500; color: var(--ink-2);
  cursor: pointer; white-space: nowrap; transition: all 0.15s;
}
.fa-label-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.fa-label-btn:hover { background: var(--surface-2, #f0f4ff); border-color: var(--accent); color: var(--accent); }
.fa-label-btn--green { color: #217346; border-color: #217346; }
.fa-label-btn--green:hover { background: #e8f5ee; border-color: #1a5c38; color: #1a5c38; }
.fa-label-btn--active { background: var(--accent-light, #dbeeff); border-color: var(--accent); color: var(--accent); }

/* ── Filter bar ───────────────────────────────────── */
.fa-filter-bar[hidden] { display: none; } /* override display:flex when hidden */
.fa-filter-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 14px 10px; border-bottom: 1px solid var(--line);
  background: var(--surface-2, #f8fafc);
}
.fa-filter-input {
  flex: 1 1 220px; min-width: 180px; max-width: 340px;
  height: 32px; border: 1px solid var(--line); border-radius: 0;
  padding: 0 10px; font-size: 12.5px; color: var(--ink);
  background: var(--surface); outline: none;
  transition: border-color 0.15s;
}
.fa-filter-input:focus { border-color: var(--accent); }
.fa-filter-sel {
  height: 32px; border: 1px solid var(--line); border-radius: 0;
  padding: 0 8px; font-size: 12.5px; color: var(--ink);
  background: var(--surface); cursor: pointer; outline: none;
}
.fa-filter-sel:focus { border-color: var(--accent); }
.fa-filter-date-group { display: flex; align-items: center; gap: 4px; }
.fa-filter-date {
  height: 32px; border: 1px solid var(--line); border-radius: 0;
  padding: 0 6px; font-size: 12px; color: var(--ink);
  background: var(--surface); outline: none;
}
.fa-filter-date:focus { border-color: var(--accent); }
.fa-filter-date-sep { color: var(--ink-2); font-size: 12px; }

.fa-table-wrap { overflow-x: auto; }
.fa-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.fa-table thead th {
  background: #1b7fc4; color: #fff; font-size: 12.5px; font-weight: 600;
  padding: 10px 14px; text-align: left; white-space: nowrap; border: none;
}
.fa-table thead th.fa-th-num { text-align: right; }
.fa-table thead th.fa-th-check { width: 40px; padding: 10px 12px; }
.fa-row { border-bottom: 1px solid var(--line); transition: background 0.12s; cursor: pointer; }
.fa-row:last-child { border-bottom: none; }
.fa-row:hover { background: #f0f7ff; }
.fa-td-check { width: 40px; padding: 10px 12px; }
.fa-td-date { padding: 10px 14px; color: var(--ink-2); white-space: nowrap; width: 110px; }
.fa-td-docnum { padding: 10px 14px; white-space: nowrap; }
.fa-status-dot {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%;
  margin-right: 7px; vertical-align: middle; flex-shrink: 0;
}
.fa-dot-green  { background: #22c55e; }
.fa-dot-gray   { background: #94a3b8; }
.fa-dot-blue   { background: #3b82f6; }
.fa-dot-orange { background: #f59e0b; }
.fa-dot-red    { background: #ef4444; }
.fa-docnum { font-weight: 600; font-size: 13px; color: var(--ink-1); }
.fa-doc-icon-btn {
  margin-left: 6px; font-size: 12px; background: none; border: none; cursor: pointer;
  color: var(--ink-3); padding: 1px 3px; border-radius: 0; vertical-align: middle;
}
.fa-doc-icon-btn:hover { color: var(--accent); }
.fa-td-customer { padding: 8px 14px; }
.fa-customer-name { display: block; font-size: 13px; color: var(--ink-1); font-weight: 500; }
.fa-project-sub { display: block; font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.fa-td-amount { padding: 10px 14px; text-align: right; font-size: 13px; font-weight: 600; white-space: nowrap; width: 130px; }
.fa-td-status { padding: 8px 14px; white-space: nowrap; }
.fa-td-duedate { padding: 10px 14px; color: var(--ink-2); white-space: nowrap; width: 110px; }
.fa-status-badge {
  display: inline-block; padding: 3px 10px; border-radius: 0; font-size: 12px; font-weight: 500;
}
.fa-badge-green  { background: rgba(34,197,94,0.12);  color: #15803d; }
.fa-badge-gray   { background: rgba(148,163,184,0.15); color: #475569; }
.fa-badge-orange { background: rgba(245,158,11,0.12);  color: #b45309; }
.fa-badge-blue   { background: rgba(59,130,246,0.12);  color: #1d4ed8; }
.fa-badge-red    { background: rgba(239,68,68,0.12);   color: #b91c1c; }

/* ─── FA STATUS DROPDOWN (FlowAccount style) ─────────── */
.fa-status-dd {
  -webkit-appearance: none; appearance: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px 22px 4px 10px;
  font-size: 12px; font-weight: 600; font-family: inherit;
  cursor: pointer;
  max-width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpolyline points='1,1 5,5 9,1' fill='none' stroke='%23678' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 7px center;
  background-size: 9px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.fa-status-dd:hover { border-color: currentColor; }
.fa-status-dd:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(20,120,185,0.15); }
.fa-status-dd option { background: #fff; color: var(--ink); font-weight: 400; }
.fa-status-dd.fa-badge-green  { background-color: rgba(34,197,94,0.10);  color: #15803d; }
.fa-status-dd.fa-badge-gray   { background-color: rgba(148,163,184,0.13); color: #475569; }
.fa-status-dd.fa-badge-orange { background-color: rgba(245,158,11,0.10);  color: #b45309; }
.fa-status-dd.fa-badge-blue   { background-color: rgba(59,130,246,0.10);  color: #1d4ed8; }
.fa-status-dd.fa-badge-red    { background-color: rgba(239,68,68,0.10);   color: #b91c1c; }

/* ─── DFM: FlowAccount-style header (icon actions + status chip) ── */
.dfm-status-chip {
  display: inline-block;
  margin-left: 8px;
  padding: 3px 12px;
  border-radius: 4px;
  font-size: 11.5px;
  font-weight: 600;
  vertical-align: middle;
}
.dfm-status-chip[hidden] { display: none !important; }

.dfm-icon-actions {
  display: flex;
  gap: 2px;
  align-items: flex-start;
  margin-left: auto;
  margin-right: 12px;
}
.dfm-icon-actions button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 60px;
  min-height: 38px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  font-size: 10px;
  font-family: inherit;
  color: var(--ink-3);
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.12s;
}
.dfm-icon-actions button:hover {
  background: rgba(21,120,190,0.08);
  border-color: rgba(21,120,190,0.18);
  color: var(--accent);
  transform: translateY(-1px);
}
.dfm-icon-actions button:focus-visible {
  outline: 3px solid rgba(21,120,190,0.14);
  outline-offset: 2px;
}
.dfm-icon-actions .dfm-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 900px) {
  .dfm-icon-actions button span { display: none; }
  .dfm-icon-actions button { min-width: 40px; padding: 4px 6px; }
}

/* ─── DFA: FlowAccount-style document editor layout ──── */
.dfa-head {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 20px;
  margin-bottom: 14px;
}
.dfa-field { display: block; font-size: 12px; color: var(--ink-2); }
.dfa-field input, .dfa-field textarea { width: 100%; margin-top: 3px; }
.dfa-customer { display: grid; gap: 8px; align-content: start; }
.dfa-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.dfa-meta { display: grid; gap: 8px; align-content: start; justify-items: end; }
.dfa-grand { text-align: right; }
.dfa-grand span { display: block; font-size: 11.5px; color: var(--ink-3); }
.dfa-grand strong { font-size: 26px; font-weight: 600; color: var(--accent); line-height: 1.2; }
.dfa-meta-table { width: 100%; max-width: 300px; border-collapse: collapse; font-size: 12px; }
.dfa-meta-table td:first-child { color: var(--ink-3); text-align: right; padding: 3px 8px 3px 0; white-space: nowrap; }
.dfa-meta-table td:last-child { padding: 3px 0; }
.dfa-meta-table input, .dfa-meta-table select { width: 100%; font-size: 12px; padding: 4px 8px; }

.dfa-row2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
  padding: 10px 12px;
  background: rgba(21, 120, 190, 0.04);
  border: 1px solid var(--line-subtle);
  border-radius: var(--radius);
}
.dfa-row2 label { display: block; font-size: 11.5px; color: var(--ink-3); }
.dfa-row2 input, .dfa-row2 select { width: 100%; margin-top: 3px; }
.dfa-row2 label[hidden] { display: none !important; }

.dfa-extra { margin-bottom: 14px; border: 1px dashed var(--line); border-radius: var(--radius); }
.dfa-extra > summary { padding: 8px 12px; font-size: 12px; color: var(--ink-3); cursor: pointer; user-select: none; }
.dfa-extra[open] > summary { border-bottom: 1px dashed var(--line); color: var(--ink-2); }
.dfa-extra > .form-grid, .dfa-extra > fieldset, .dfa-extra > .form-grid.two { margin: 10px 12px; }

.dfa-bottom {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 20px;
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.dfa-notes label { display: block; font-size: 12px; color: var(--ink-2); }
.dfa-notes textarea { width: 100%; margin-top: 4px; }

.dfa-summary table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.dfa-summary td { padding: 4px 0; color: var(--ink-2); }
.dfa-sum-val { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); white-space: nowrap; }
.dfa-sum-neg { color: #b91c1c; }
.dfa-sum-input { color: var(--accent) !important; }
.dfa-sum-input input { width: 76px; padding: 3px 6px; font-size: 12px; margin: 0 4px; text-align: right; }
.dfa-grand-row td { border-top: 1px solid var(--line); padding-top: 8px; font-weight: 600; color: var(--ink); }
.dfa-grand-row .dfa-sum-val { font-size: 15px; color: var(--accent); }
.dfa-dual-row td {
  color: #2563a0;
  background: #f5f8ff;
}
.dfa-dual-row .dfa-sum-val { color: #2563a0; font-weight: 700; }
.dfa-currency-note {
  margin: 8px 0 0;
  padding: 7px 9px;
  border: 1px dashed #bfd3ee;
  background: #f6f9ff;
  color: #2563a0;
  font-size: 11px;
  line-height: 1.45;
}
.dfa-currency2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.dfa-currency2 label { font-size: 11.5px; color: var(--ink-3); }
.dfa-currency2 input { width: 100%; margin-top: 3px; font-size: 12px; }

/* โหมดใบเต็มจอ — แบบ FlowAccount ไม่มีฟอร์มแยก */
.document-workspace.dfm-paper-mode { grid-template-columns: 1fr; }
.document-workspace.dfm-paper-mode .document-controls { display: none !important; }
.document-workspace.dfm-paper-mode .document-preview-wrap { display: flex !important; flex-direction: column; }

/* ปุ่มควบคุมบนใบ */
.paper-line-actions { display: flex; gap: 8px; margin: 8px 0 12px; }
.paper-line-actions button {
  border: 1px dashed var(--accent);
  background: rgba(20,120,185,0.05);
  color: var(--accent);
  font-size: 12px;
  font-family: inherit;
  padding: 6px 14px;
  border-radius: 4px;
  cursor: pointer;
}
.paper-line-actions button:hover { background: rgba(20,120,185,0.12); }

.paper-cell-rel { position: relative; }
.paper-del-row {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: #c44a3a;
  font-size: 12px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s;
  padding: 2px 4px;
}
#preview-lines tr:hover .paper-del-row { opacity: 1; }

#paper-pick-customer {
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 3px;
  font-size: 10px;
  padding: 2px 6px;
  margin-left: 5px;
  cursor: pointer;
  vertical-align: middle;
}

@media print {
  .paper-line-actions, .paper-del-row, #paper-pick-customer { display: none !important; }
}

/* กรอกจริงในใบ — ช่องแก้ไขได้บนตัวเอกสาร */
.document-page .doc-editable { cursor: text; border-radius: 2px; transition: box-shadow 0.12s, background 0.12s; min-width: 40px; }
.document-page .doc-editable:hover { box-shadow: 0 0 0 1px var(--accent); background: rgba(20,120,185,0.05); }
.document-page .doc-editable:focus { outline: none; box-shadow: 0 0 0 2px var(--accent); background: #fff; }
.document-page .doc-editable-empty:not(:focus)::before { content: "คลิกเพื่อกรอก"; color: #b9c6d2; font-style: italic; }

/* หัวส่วนรายการราคา — แถบน้ำเงินแบบ FlowAccount */
.line-editor-head {
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}
.line-editor-head h4 { color: #fff !important; margin: 0; font-size: 13px; }
.line-editor-head .ghost-button { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.4); color: #fff !important; }
.line-editor-head .ghost-button:hover { background: rgba(255,255,255,0.26); }

@media (max-width: 900px) {
  .dfa-head, .dfa-bottom { grid-template-columns: 1fr; }
  .dfa-meta { justify-items: start; }
}

/* ─── FA ROW ··· MENU ────────────────────────────────── */
.fa-row-menu {
  position: fixed;
  z-index: 120;
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(15,40,70,0.16);
  padding: 4px;
  display: flex;
  flex-direction: column;
}
.fa-row-menu button {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  text-align: left;
  font-size: 13px;
  font-family: inherit;
  color: var(--ink-2);
  cursor: pointer;
}
.fa-row-menu button:hover { background: rgba(21,120,190,0.08); color: var(--ink); }
.fa-row-menu button.fa-menu-danger { color: #b91c1c; border-top: 1px solid var(--line); border-radius: 0 0 4px 4px; margin-top: 2px; }
.fa-row-menu button.fa-menu-danger:hover { background: rgba(239,68,68,0.08); }
.fa-td-actions { padding: 6px 14px; width: 200px; }
.fa-row-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.fa-menu-btn {
  background: var(--surface); border: 1px solid var(--line); border-radius: 0;
  padding: 3px 9px; cursor: pointer; font-size: 15px; line-height: 1; color: var(--ink-2);
  letter-spacing: 1px;
}
.fa-menu-btn:hover { background: var(--surface-2, #f0f4ff); }
.fa-empty-row { text-align: center; padding: 32px 16px; color: var(--ink-3); font-size: 13px; }

/* Finance view tabs bar */
.fin-doc-tabs-bar {
  display: flex; gap: 0; background: var(--surface);
  border-bottom: 2px solid var(--line); padding: 0 24px;
}
.fin-doc-tab {
  background: none; border: none; border-bottom: 3px solid transparent;
  padding: 12px 22px; font-size: 14px; font-family: inherit; cursor: pointer;
  color: var(--ink-2); margin-bottom: -2px; transition: color 0.15s, border-color 0.15s;
}
.fin-doc-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.fin-doc-tab:hover:not(.active) { color: var(--ink-1); }
.fin-tab-panel { display: none; }
.fin-tab-panel.active { display: block; }

/* QT accounting table collapsible */
.qt-accounting-details { margin-top: 16px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.qt-accounting-details .panel-head { display: flex; align-items: center; padding: 12px 20px; cursor: pointer; background: var(--surface); }
.qt-accounting-details .panel-head h3 { margin: 0; }

/* ─── FA SVG ICONS ───────────────────────────────────── */
.fa-icon-btn svg {
  width: 15px; height: 15px; display: block;
}
.fa-svg-doc {
  width: 12px; height: 13px; display: inline-block;
  vertical-align: middle; color: var(--ink-3);
}
.fa-doc-icon-btn {
  background: none; border: none; cursor: pointer;
  padding: 2px 4px; border-radius: 0; line-height: 1;
  color: var(--ink-3); margin-left: 4px;
  transition: color 0.15s, background 0.15s;
}
.fa-doc-icon-btn:hover { color: var(--accent); background: rgba(var(--accent-rgb, 59,130,246),0.08); }

/* ─── FA STATUS SELECT (FlowAccount style) ───────────── */
/* Looks like a colored label with a tiny chevron — static display */
.fa-status-sel {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px 4px 8px; border-radius: 0;
  font-size: 12.5px; font-weight: 500; line-height: 1.3;
  white-space: nowrap; cursor: default;
}
/* Override dot inside sel — no extra margin */
.fa-status-sel .fa-status-dot { margin-right: 0; flex-shrink: 0; }
/* Badge colors reused */
.fa-status-sel.fa-badge-green  { background: rgba(34,197,94,0.10);  color: #15803d; }
.fa-status-sel.fa-badge-gray   { background: rgba(148,163,184,0.13); color: #475569; }
.fa-status-sel.fa-badge-orange { background: rgba(245,158,11,0.10);  color: #b45309; }
.fa-status-sel.fa-badge-blue   { background: rgba(59,130,246,0.10);  color: #1d4ed8; }
.fa-status-sel.fa-badge-red    { background: rgba(239,68,68,0.10);   color: #b91c1c; }

/* ─── FA PAGE HEADER — finance tab-aware ─────────────── */
.fin-page-header { border-bottom: 1px solid var(--line); }

/* ─── ACCENT-NEXT BUTTON — clean text, no emoji ─────── */
.accent-next-button { font-size: 12px !important; }

/* ─── FA TABLE — tighter action column ──────────────── */
.fa-td-actions { padding: 6px 10px; }
.fa-row-actions { gap: 5px; }

/* ─── SIDEBAR SUB-NAV (FlowAccount style) ──────────────────── */
.nav-group { display: flex; flex-direction: column; }

.nav-group-toggle {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; background: none; border: none; cursor: pointer;
  padding: 10px 16px; font-size: 13px; font-weight: 500;
  color: var(--ink-2); border-radius: 0;
  transition: background .15s, color .15s;
}
.nav-group-toggle:hover { background: var(--hover); color: var(--ink-1); }
.nav-group-toggle.active-group { color: var(--accent); }

.nav-arrow {
  width: 10px; height: 10px; flex-shrink: 0;
  transition: transform .2s;
}
.nav-group-toggle.collapsed .nav-arrow { transform: rotate(-90deg); }

.nav-sub {
  display: none; flex-direction: column; gap: 1px;
  padding: 2px 0 4px 12px;
}
.nav-sub.open { display: flex; }

.nav-sub-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: none; background: none;
  font-size: 12.5px; color: var(--ink-2); border-radius: 0;
  cursor: pointer; text-align: left; width: 100%;
  transition: background .12s, color .12s;
}
.nav-sub-item:hover { background: var(--hover); color: var(--ink-1); }
.nav-sub-item--active { background: var(--accent-muted, #e8f0fe); color: var(--accent) !important; font-weight: 600; }
.nav-sub-icon { width: 14px; height: 14px; flex-shrink: 0; }

/* advance rules box */
.advance-rules-box {
  grid-column: 1 / -1;
  margin: 0 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(21, 120, 190, 0.04);
  font-size: 12.5px;
}

.advance-rules-box summary {
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-2);
  user-select: none;
}

.advance-rules-box summary:hover { color: var(--ink); }

.advance-rules-content { padding: 0 14px 12px; }

.advance-rules-content ul {
  margin: 0 0 10px;
  padding-left: 18px;
  display: grid;
  gap: 4px;
  color: var(--ink-2);
  line-height: 1.5;
}

.advance-rules-table {
  display: grid;
  gap: 6px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}

.advance-rules-table > div {
  display: grid;
  gap: 2px;
}

.advance-rules-table strong { color: var(--ink); font-size: 12px; }
.advance-rules-table span { color: var(--ink-3); font-size: 11.5px; line-height: 1.5; }

.line-rules-box {
  margin-bottom: 14px;
  border-color: #c9dcfb;
  background: #f7fbff;
  box-shadow: inset 4px 0 0 #2f6df6;
}

.line-rules-box summary {
  color: var(--ink);
  font-size: 13px;
}

.line-rules-box .advance-rules-content ul {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 18px;
}

.line-rules-table {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.line-rules-table > div {
  padding: 10px;
  border: 1px solid #d8e5f7;
  border-radius: 8px;
  background: #fff;
}

.line-policy-detail {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed #c9dcfb;
}

.line-policy-detail > strong {
  color: var(--ink);
  font-size: 12.5px;
}

.line-policy-tables {
  display: grid;
  /* แคบ = เรียงลงล่างอัตโนมัติ กันตัวเลขในตารางซ้อนทับกัน */
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 10px;
}

.line-policy-tables .setup-food-table {
  margin: 0;
  background: #fff;
  font-size: 11.5px;
}

/* ─── FLOWACCOUNT-INSPIRED UX REFRESH ─────────────────────────
   Soft SaaS dashboard skin: cleaner cards, rounded navigation,
   quieter controls, and a lighter workspace feel. */
:root {
  --bg: #f4f7fb;
  --bg-2: #ffffff;
  --bg-3: #f7faff;
  --surface: #ffffff;
  --surface-2: #f4f8fd;
  --surface-3: #eaf2fb;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --accent-muted: #eff6ff;
  --accent-dark: #1d4ed8;
  --gold: #2563eb;
  --gold-bright: #1d4ed8;
  --gold-dim: #60a5fa;
  --gold-muted: #eff6ff;
  --gold-glow: rgba(37, 99, 235, 0.12);
  --ink: #111827;
  --ink-1: #111827;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --line: rgba(148, 163, 184, 0.28);
  --line-subtle: rgba(148, 163, 184, 0.18);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-card: 0 10px 30px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-glow: 0 20px 60px rgba(37, 99, 235, 0.14), 0 8px 24px rgba(15, 23, 42, 0.08);
  /* ข้อกำหนดข้อ 8: กรอบและปุ่มเป็นทรงสี่เหลี่ยมมุมฉาก ไม่ใช้ขอบมน */
  --radius: 0;
  --radius-lg: 0;
}

body {
  background:
    radial-gradient(circle at top left, rgba(191, 219, 254, 0.55), transparent 34rem),
    linear-gradient(180deg, #f7fbff 0%, #f3f6fb 44%, #eef3f8 100%);
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 0;
}

.sidebar {
  width: 250px;
  gap: 18px;
  padding: 22px 14px;
  background: rgba(255, 255, 255, 0.92);
  border-right: 1px solid rgba(226, 232, 240, 0.9);
  box-shadow: 10px 0 30px rgba(15, 23, 42, 0.035);
  backdrop-filter: blur(12px);
}

body.sidebar-collapsed .sidebar { transform: translateX(-250px); }

.app-shell {
  margin-left: 250px;
  width: calc(100% - 250px);
  padding: 22px 30px 34px;
}

.brand {
  gap: 12px;
  padding: 6px 8px 12px;
  border-bottom: 1px solid var(--line-subtle);
}

.brand-mark,
.login-brand img,
.mobile-brand img {
  border-radius: 0 !important;
  background: transparent;
  box-shadow: none;
  object-fit: contain;
}

.brand h1 {
  font-size: 15px;
  letter-spacing: 0;
}

.brand p {
  color: var(--ink-3);
  font-size: 10px;
  letter-spacing: 0.06em;
}

.sidebar-user-info {
  margin: 0;
  padding: 12px;
  border-radius: 16px;
  background: linear-gradient(135deg, #eff6ff 0%, #f8fbff 100%);
  border-color: rgba(191, 219, 254, 0.85);
}

.sidebar-user-avatar,
.login-user-card-avatar,
.user-avatar,
.user-avatar-preview {
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  color: #fff;
}

.nav {
  gap: 4px;
  padding: 0 4px 18px;
}

.nav-section-label {
  margin: 18px 10px 6px;
  color: #94a3b8;
  font-size: 10px;
  letter-spacing: 0.08em;
}

.nav-item,
.nav-group-toggle,
.nav-sub-item {
  border-radius: 12px;
  color: #64748b;
}

.nav-item {
  min-height: 40px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
}

.nav-item span,
.nav-group-toggle span {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.nav-item span::before,
.nav-group-toggle span::before {
  content: "";
  width: 18px;
  height: 18px;
  flex: 0 0 18px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(96, 165, 250, 0.36);
  border-radius: 7px;
  background: linear-gradient(180deg, #ffffff 0%, #eff6ff 100%);
  color: #2563eb;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
  opacity: 1;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

.nav-item[data-view="dashboard"] span::before { content: "D"; }
.nav-item[data-view="executive"] span::before { content: "A"; }
.nav-group-toggle span::before { content: "S"; }
.nav-item[data-view="project"] span::before { content: "P"; }
.nav-item[data-view="production"] span::before { content: "W"; }
.nav-item[data-view="calendar"] span::before { content: "C"; }
.nav-item[data-view="line"] span::before { content: "E"; }
.nav-item[data-view="advance"] span::before { content: "A"; }
.nav-item[data-view="contractor"] span::before { content: "B"; }
.nav-item[data-view="accounting"] span::before { content: "L"; }
.nav-item[data-view="incentive"] span::before { content: "%"; }
.nav-item[data-view="documents"] span::before { content: "F"; }
.nav-item[data-open-guide="true"] span::before { content: "?"; }
.nav-item[data-view="reports"] span::before { content: "R"; }
.nav-item[data-view="settings"] span::before { content: "⚙"; }

.nav-item:hover,
.nav-group-toggle:hover,
.nav-sub-item:hover {
  background: #f1f5f9;
  color: var(--ink);
}

.nav-item.active,
.nav-group-toggle.active-group,
.nav-sub-item--active {
  background: #eaf2ff;
  color: #1d4ed8 !important;
  font-weight: 600;
  box-shadow: inset 0 0 0 1px rgba(37, 99, 235, 0.08);
}

.nav-item.active::before { display: none; }

.nav-item.active span::before,
.nav-group-toggle.active-group span::before {
  border-color: #2563eb;
  background: linear-gradient(135deg, #2563eb, #38bdf8);
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.22);
}

.nav-sub {
  gap: 3px;
  padding: 4px 0 6px 22px;
}

.nav-sub-item {
  padding: 8px 10px;
  font-size: 12px;
}

.topbar {
  position: relative;
  z-index: 220;
  min-height: 64px;
  margin: 0 0 22px;
  padding: 10px 12px 10px 16px;
  border: 1px solid rgba(226, 232, 240, 0.85);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.045);
  backdrop-filter: blur(14px);
}

.topbar-left {
  min-width: 240px;
}

.topbar h2 {
  margin-top: 2px;
  font-size: 22px;
  font-weight: 650;
  letter-spacing: 0;
}

.eyebrow {
  color: #64748b;
  font-size: 10px;
  letter-spacing: 0.08em;
}

.sidebar-toggle-btn,
.notification-button,
.language-button,
.user-profile-chip,
.topbar-logout-btn,
.role-switcher {
  border-radius: 12px !important;
  border-color: rgba(226, 232, 240, 0.9) !important;
  background: #fff !important;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.sidebar-toggle-btn,
.notification-button,
.language-button,
.icon-button,
.fa-doc-icon-btn,
.fa-menu-btn {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 12px !important;
}

.sidebar-toggle-btn,
.notification-button,
.language-button,
.icon-button {
  min-width: 40px;
  min-height: 40px;
}

.sidebar-toggle-btn,
.notification-button,
.icon-button,
.fa-doc-icon-btn,
.fa-menu-btn {
  color: #475569;
}

.sidebar-toggle-btn:hover,
.notification-button:hover,
.language-button:hover,
.icon-button:hover,
.fa-doc-icon-btn:hover,
.fa-menu-btn:hover {
  transform: translateY(-1px);
  background: #eff6ff !important;
  border-color: #bfdbfe !important;
  color: #1d4ed8 !important;
}

.sidebar-toggle-btn:focus-visible,
.notification-button:focus-visible,
.language-button:focus-visible,
.user-profile-chip:focus-visible,
.topbar-logout-btn:focus-visible,
.role-switcher:focus-within,
.icon-button:focus-visible,
.fa-doc-icon-btn:focus-visible,
.fa-menu-btn:focus-visible {
  outline: 3px solid rgba(37, 99, 235, 0.16);
  outline-offset: 2px;
}

.top-actions {
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  min-width: 0;
  position: relative;
  z-index: 260;
}

.role-switcher {
  flex: 0 1 170px;
  min-height: 40px;
  padding: 4px 10px;
}

.company-switcher {
  flex-basis: 150px;
}

.role-switcher select {
  min-width: 0;
  max-width: 136px;
  text-overflow: ellipsis;
}

.user-profile-chip {
  flex: 0 1 210px;
}

.topbar-logout-btn {
  flex: 0 0 auto;
  min-height: 40px;
  padding-inline: 12px !important;
}

.role-switcher span {
  color: var(--ink-3);
  font-size: 10px;
}

.notification-wrap {
  position: relative;
  z-index: 500;
}

.notification-button {
  width: 42px;
  height: 42px;
  flex-basis: 42px;
  line-height: 1;
}

.topbar-bell-icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.notification-button span {
  top: -7px;
  right: -7px;
  min-width: 19px;
  height: 19px;
  border: 2px solid #fff;
  border-radius: 999px;
  background: #ef4444;
  font-size: 10px;
  font-weight: 700;
}

.notification-panel {
  top: calc(100% + 12px);
  right: 0;
  width: min(360px, calc(100vw - 32px));
  max-height: 360px;
  overflow: hidden auto;
  border: 1px solid rgba(226, 232, 240, 0.98);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.18);
  z-index: 1200;
}

.notification-panel::before {
  content: "";
  position: absolute;
  top: -7px;
  right: 18px;
  width: 14px;
  height: 14px;
  border-left: 1px solid rgba(226, 232, 240, 0.98);
  border-top: 1px solid rgba(226, 232, 240, 0.98);
  background: #fff;
  transform: rotate(45deg);
}

.notification-panel-head {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 14px 16px 10px;
  background: #fff;
  border-bottom: 1px solid rgba(226, 232, 240, 0.82);
  font-size: 13px;
}

.notification-item {
  gap: 12px;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid rgba(226, 232, 240, 0.78);
}

.notification-item:hover {
  background: #f8fbff;
}

.notification-item-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  background: #eff6ff;
  color: #2563eb;
  position: relative;
  overflow: hidden;
  font-size: 0;
}

.notification-item-icon::before,
.notification-item-icon::after {
  content: "";
  position: absolute;
  box-sizing: border-box;
}

.notification-item-icon::before {
  width: 15px;
  height: 17px;
  border: 1.8px solid currentColor;
  border-radius: 3px;
}

.notification-item-icon::after {
  width: 7px;
  height: 1.8px;
  background: currentColor;
  box-shadow: 0 4px 0 currentColor;
  transform: translateY(2px);
}

.notification-item[data-notif-view="advance"] .notification-item-icon,
.notification-item[data-notif-view="contractor"] .notification-item-icon {
  background: #eef6ff;
  color: #1d4ed8;
}

.notification-item[data-notif-view="advance"] .notification-item-icon::before,
.notification-item[data-notif-view="contractor"] .notification-item-icon::before {
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.notification-item[data-notif-view="advance"] .notification-item-icon::after,
.notification-item[data-notif-view="contractor"] .notification-item-icon::after {
  width: 8px;
  height: 5px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  background: transparent;
  box-shadow: none;
  transform: rotate(-45deg) translate(-1px, -1px);
}

.notification-item[data-notif-view="finance"] .notification-item-icon {
  background: #fff7ed;
  color: #c2410c;
}

.notification-item[data-notif-view="finance"] .notification-item-icon::before {
  width: 0;
  height: 0;
  border-right: 8px solid transparent;
  border-bottom: 15px solid currentColor;
  border-left: 8px solid transparent;
  border-top: 0;
  border-radius: 0;
}

.notification-item[data-notif-view="finance"] .notification-item-icon::after {
  width: 2px;
  height: 7px;
  background: #fff;
  box-shadow: 0 9px 0 #fff;
  transform: translateY(1px);
}

.notification-item[data-notif-view="accounting"] .notification-item-icon {
  background: #f1f5f9;
  color: #475569;
}
}

.notification-item-body strong {
  color: #0f172a;
  font-size: 12.5px;
  font-weight: 650;
}

.notification-item-body small {
  display: block;
  margin-top: 2px;
  color: #94a3b8;
  font-size: 11px;
  line-height: 1.35;
}

.notification-item-count {
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: #ef4444;
  font-size: 10px;
}

.fa-status-dd {
  min-width: 138px;
  max-width: 190px;
  min-height: 34px;
  padding: 0 34px 0 12px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0;
  box-shadow: none;
}

.fa-status-dd option {
  color: #0f172a;
  font-weight: 500;
}

.fa-row-menu {
  min-width: 226px;
  padding: 6px;
  border-radius: 12px;
}

.fa-row-menu button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 8px;
  color: #334155;
  font-weight: 500;
  letter-spacing: 0;
}

.fa-row-menu button + button {
  margin-top: 2px;
}

.fa-menu-ico {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  border-radius: 6px;
  background: #eff6ff;
  color: #2563eb;
  font-size: 10px;
  font-weight: 700;
}

.fa-row-menu button:hover .fa-menu-ico {
  background: #dbeafe;
}

.fa-row-menu button.fa-menu-danger {
  margin-top: 6px;
  padding-top: 9px;
  border-top: 1px solid rgba(226, 232, 240, 0.95);
  border-radius: 8px;
}

.fa-row-menu button.fa-menu-danger .fa-menu-ico {
  background: #fee2e2;
  color: #b91c1c;
}

.doc-customer-picker {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
  align-items: center;
}

.doc-customer-picker input {
  min-width: 0;
}

.doc-customer-picker .ghost-button.small {
  min-height: 38px;
  padding: 0 12px;
  white-space: nowrap;
}

#client-contact-select {
  margin-bottom: 6px;
}

.fa-row-menu button span:not(.fa-menu-ico) {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.fa-row-menu button strong {
  overflow: hidden;
  color: inherit;
  font-size: 12.5px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fa-row-menu button small {
  overflow: hidden;
  color: #94a3b8;
  font-size: 11px;
  font-weight: 400;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fa-row-menu button > * {
  pointer-events: none;
}

@media (max-width: 720px) {
  .doc-customer-picker {
    grid-template-columns: 1fr;
  }

  .doc-customer-picker .ghost-button.small {
    width: 100%;
  }
}

/* FlowAccount-like document form: dense accounting input surface */
.document-fill-modal .document-controls {
  background: #f4f8fc;
}

.document-fill-modal .dfa-head,
.document-fill-modal .dfa-row2,
.document-fill-modal .dfa-extra,
.document-fill-modal .document-lines-section,
.document-fill-modal .document-terms-label,
.document-fill-modal .totals-inputs {
  margin-left: 12px;
  margin-right: 12px;
}

.document-fill-modal .dfa-customer,
.document-fill-modal .dfa-meta {
  position: relative;
  padding: 32px 12px 12px;
  border: 1px solid #d7e2ef;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
}

.document-fill-modal .dfa-customer::before,
.document-fill-modal .dfa-meta::before {
  position: absolute;
  top: 10px;
  left: 12px;
  color: #1e9bd7;
  font-size: 13px;
  font-weight: 650;
}

.document-fill-modal .dfa-customer::before { content: "ข้อมูลลูกค้า"; }
.document-fill-modal .dfa-meta::before { content: "ข้อมูลเอกสาร"; }

.document-fill-modal .dfa-field,
.document-fill-modal .dfa-row2 label,
.document-fill-modal .form-grid label,
.document-fill-modal .line-row label,
.document-fill-modal .document-terms-label {
  color: #52677d;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.document-fill-modal input,
.document-fill-modal select,
.document-fill-modal textarea {
  min-height: 34px;
  border-color: #cbd8e6;
  border-radius: 5px;
  background: #fff;
  font-size: 12.5px;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.035);
}

.document-fill-modal textarea {
  min-height: 62px;
}

.document-fill-modal input:focus,
.document-fill-modal select:focus,
.document-fill-modal textarea:focus {
  border-color: #1e9bd7;
  box-shadow: 0 0 0 2px rgba(30, 155, 215, 0.14);
}

.document-fill-modal .dfa-meta {
  justify-items: stretch;
}

.document-fill-modal .dfa-grand {
  padding: 0 0 8px;
  text-align: right;
  border-bottom: 1px solid #e2e8f0;
}

.document-fill-modal .dfa-grand span {
  color: #64748b;
}

.document-fill-modal .dfa-grand strong {
  color: #148dcc;
  font-size: 24px;
  font-weight: 650;
}

.document-fill-modal .dfa-meta-table {
  max-width: none;
  min-width: 0;
  border-collapse: separate;
  border-spacing: 0 4px;
}

.document-fill-modal .dfa-meta-table td:first-child {
  width: 92px;
  color: #7790aa;
  font-size: 11px;
}

.document-fill-modal .dfa-row2 {
  padding: 10px 12px;
  border: 1px solid #cfe0ee;
  border-radius: 8px;
  background: #eaf5fb;
}

.document-fill-modal .dfa-extra {
  overflow: hidden;
  border-color: #d7e2ef;
  border-style: solid;
  border-radius: 8px;
  background: #fff;
}

.document-fill-modal .dfa-extra > summary {
  color: #1e74b7;
  background: #f8fbff;
}

.document-fill-modal .line-editor-head {
  margin: 12px 0 0;
  border-radius: 8px 8px 0 0;
  background: #2563eb;
}

.document-fill-modal .line-editor {
  gap: 0;
  overflow: hidden;
  border: 1px solid #d7e2ef;
  border-top: 0;
  border-radius: 0 0 8px 8px;
  background: #fff;
}

.document-fill-modal .line-row {
  grid-template-columns: minmax(116px, .72fr) minmax(210px, 1.55fr) 74px 74px 112px 106px 34px;
  gap: 8px;
  padding: 10px 12px;
  border: 0;
  border-bottom: 1px solid #e2e8f0;
  border-radius: 0;
  background: #fff;
}

.document-fill-modal .line-row:last-child {
  border-bottom: 0;
}

.document-fill-modal .line-row strong {
  min-height: 34px;
  color: #1d4ed8;
  font-size: 12.5px;
}

.document-fill-modal .remove-line {
  width: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 6px !important;
  color: #64748b;
}

.document-fill-modal .totals-inputs {
  padding: 12px;
  border: 1px solid #d7e2ef;
  border-radius: 8px;
  background: #fff;
}

.document-fill-modal .document-terms-label {
  padding: 0;
}

.metric-grid {
  gap: 16px;
}

.metric-card,
.panel,
.executive-kpi,
.executive-chart-card,
.project-card,
.project-chart-card,
.project-calendar-card,
.project-timeline-card,
.export-card,
.profile-preview,
.advance-rules-box {
  border-color: rgba(226, 232, 240, 0.9);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-card);
}

.metric-card {
  min-height: 126px;
  padding: 18px 18px 16px;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.metric-card:hover,
.project-card:hover,
.export-card:hover {
  transform: translateY(-2px);
  border-color: rgba(147, 197, 253, 0.95);
  box-shadow: 0 16px 38px rgba(15, 23, 42, 0.08);
}

.metric-card::before {
  inset: 16px 16px auto auto;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--accent-muted);
  opacity: 1;
}

.metric-card::after {
  content: "";
  position: absolute;
  top: 29px;
  right: 29px;
  width: 16px;
  height: 16px;
  border-radius: 5px;
  background: var(--gold);
  opacity: .78;
}

.metric-card span {
  color: #64748b;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}

.metric-card strong {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0;
}

.metric-card small {
  color: #94a3b8;
  font-size: 12px;
  font-weight: 400;
}

.metric-blue::before { background: #dbeafe; }
.metric-red::before { background: #fee2e2; }
.metric-green::before { background: #dcfce7; }
.metric-amber::before { background: #fef3c7; }
.metric-blue::after { background: #2563eb; }
.metric-red::after { background: #ef4444; }
.metric-green::after { background: #22c55e; }
.metric-amber::after { background: #f59e0b; }

.panel {
  padding: 18px;
}

.panel-head {
  gap: 12px;
  padding: 0;
  margin-bottom: 14px;
}

.panel h3,
.panel-head.compact h3 {
  color: #0f172a;
  font-size: 14px;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
}

.panel-subtitle,
.panel-head.compact small {
  color: #94a3b8;
}

select,
input,
textarea {
  min-height: 40px;
  border-color: rgba(203, 213, 225, 0.9);
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.025);
}

select:focus,
input:focus,
textarea:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.10);
}

.primary-button,
.ghost-button,
.accent-button,
.icon-button,
.fa-menu-btn,
.fin-doc-tab,
.tag,
.status,
.fa-status-sel {
  border-radius: 12px;
}

.primary-button,
.accent-button {
  background: #2563eb;
  border-color: #2563eb;
  color: #fff;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.16);
}

.primary-button:hover,
.accent-button:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.ghost-button {
  background: #fff;
  border-color: rgba(203, 213, 225, 0.95);
  color: #475569;
}

.ghost-button:hover,
.icon-button:hover {
  background: #f8fafc;
  border-color: #bfdbfe;
  color: #1d4ed8;
}

.table-wrap,
.settings-table-wrap {
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: 16px;
  background: #fff;
}

table {
  border-collapse: separate;
  border-spacing: 0;
}

th {
  background: #f8fafc;
  color: #64748b;
  font-size: 11px;
  letter-spacing: 0.02em;
}

td {
  color: #334155;
}

tbody tr:hover {
  background: #f8fbff;
}

.login-screen {
  background:
    radial-gradient(circle at 24% 16%, rgba(147, 197, 253, 0.58), transparent 25rem),
    linear-gradient(135deg, #eaf6ff 0%, #f8fbff 52%, #eef5ff 100%);
}

.login-panel {
  max-width: 470px;
  border-color: rgba(226, 232, 240, 0.9);
  border-radius: 24px;
  box-shadow: 0 28px 90px rgba(15, 23, 42, 0.13);
}

.login-user-card {
  border-color: rgba(226, 232, 240, 0.9);
  border-radius: 16px;
  background: #f8fafc;
}

.login-user-card:hover,
.login-user-card.selected {
  background: #eff6ff;
  border-color: #93c5fd;
}

.notification-panel,
.fa-row-menu {
  border-color: rgba(226, 232, 240, 0.95);
  border-radius: 16px;
  box-shadow: 0 22px 55px rgba(15, 23, 42, 0.12);
}

@media (max-width: 900px) {
  .app-shell {
    margin-left: 0;
    width: 100%;
    padding: 82px 14px 24px;
  }

  .topbar {
    border-radius: 16px;
    align-items: flex-start;
  }

  .metric-card,
  .panel {
    border-radius: 16px;
  }

  .advance-cat-record {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .advance-cat-limit-input {
    max-width: none;
  }

  .advance-cat-delete {
    justify-self: start;
  }
}

/* Quotation list UX pass: dense FlowAccount-like table with stable action columns. */
#quotation-view .fa-page-header {
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid rgba(226, 232, 240, 0.85);
}

#quotation-view .fa-create-btn {
  min-height: 38px;
  border-radius: 12px;
}

#quotation-view .fa-table-toolbar {
  gap: 12px;
  padding: 10px 16px;
}

#quotation-view .fa-filter-tabs {
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

#quotation-view .fa-tab {
  min-height: 34px;
  padding-inline: 16px;
  white-space: nowrap;
}

#quotation-view .fa-toolbar-right {
  flex: 0 0 auto;
}

#quotation-view .fa-table {
  table-layout: fixed;
  min-width: 1160px;
}

#quotation-view .fa-table th:nth-child(1) { width: 42px; }
#quotation-view .fa-table th:nth-child(2) { width: 110px; }
#quotation-view .fa-table th:nth-child(3) { width: 265px; }
#quotation-view .fa-table th:nth-child(5) { width: 150px; }
#quotation-view .fa-table th:nth-child(6) { width: 218px; }
#quotation-view .fa-table th:nth-child(7) { width: 244px; }

#quotation-view .fa-table thead th {
  height: 44px;
  vertical-align: middle;
}

#quotation-view .fa-row {
  cursor: default;
}

#quotation-view .fa-row td {
  height: 70px;
  vertical-align: middle;
}

#quotation-view .fa-td-docnum,
#quotation-view .fa-td-customer {
  min-width: 0;
}

#quotation-view .fa-docnum,
#quotation-view .fa-customer-name,
#quotation-view .fa-project-sub {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

#quotation-view .fa-docnum {
  display: inline-block;
  max-width: 190px;
  vertical-align: middle;
}

#quotation-view .fa-customer-name,
#quotation-view .fa-project-sub {
  display: block;
  white-space: nowrap;
}

#quotation-view .fa-td-amount {
  color: #0f172a;
  font-variant-numeric: tabular-nums;
}

#quotation-view .fa-td-status {
  padding-inline: 10px;
}

#quotation-view .fa-status-dd {
  width: 100%;
  max-width: 190px;
}

#quotation-view .fa-td-actions {
  width: 244px;
  padding: 8px 12px;
}

#quotation-view .fa-row-actions {
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 6px;
}

#quotation-view .fa-row-actions .small,
#quotation-view .fa-row-actions .accent-next-button {
  min-height: 34px;
  padding-inline: 12px;
  border-radius: 12px;
  font-size: 12px !important;
  letter-spacing: 0;
  white-space: nowrap;
}

#quotation-view .fa-row-actions .accent-next-button {
  border: 1px solid #86efac !important;
  background: #f0fdf4 !important;
  color: #15803d !important;
  box-shadow: none !important;
}

#quotation-view .fa-row-actions .accent-next-button:hover {
  background: #dcfce7 !important;
  border-color: #4ade80 !important;
}

#quotation-view .fa-menu-btn {
  display: inline-grid;
  flex: 0 0 38px;
  place-items: center;
  width: 38px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 12px;
  font-size: 0;
  letter-spacing: 0;
}

#quotation-view .fa-menu-btn::before {
  content: "...";
  font-size: 15px;
  line-height: 1;
  color: currentColor;
}

@media (max-width: 1500px) {
  #quotation-view .fa-table { min-width: 1080px; }
  #quotation-view .fa-table th:nth-child(3) { width: 230px; }
  #quotation-view .fa-table th:nth-child(6) { width: 200px; }
  #quotation-view .fa-table th:nth-child(7) { width: 190px; }
  #quotation-view .fa-td-actions { width: 190px; }
  #quotation-view .fa-row-actions .accent-next-button { display: none; }
}

@media (max-width: 980px) {
  #quotation-view .fa-page-header,
  #quotation-view .fa-table-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  #quotation-view .fa-toolbar-right {
    justify-content: flex-end;
  }
}

@media (max-width: 1360px) {
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
  }

  .topbar-left {
    min-width: 0;
  }

  .topbar-left .eyebrow,
  .topbar p,
  .dfm-subtitle,
  .topbar-user-chip small,
  .user-profile-chip small {
    display: none !important;
  }

  #global-search-wrap {
    display: none !important;
  }

  .topbar-controls,
  .topbar-actions {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: thin;
  }
}

@media (max-width: 1180px) {
  #quotation-view .fa-table,
  #finance-view .fa-table {
    min-width: 900px;
  }

  #quotation-view .fa-td-date,
  #finance-view .fa-td-date,
  #quotation-view .fa-table th:nth-child(2),
  #finance-view .fa-table th:nth-child(2),
  #quotation-view .fa-table td:nth-child(2),
  #finance-view .fa-table td:nth-child(2) {
    display: none;
  }

  #quotation-view .fa-td-actions,
  #finance-view .fa-td-actions,
  #quotation-view .fa-table th:nth-last-child(1),
  #finance-view .fa-table th:nth-last-child(1) {
    width: 136px;
  }

  #quotation-view .fa-row-actions .ghost-button.small:not(.fa-menu-btn),
  #finance-view .fa-row-actions .ghost-button.small:not(.fa-menu-btn) {
    display: none;
  }

  #advance-modal.modal-split[open] {
    grid-template-columns: minmax(0, 1fr);
    width: min(980px, calc(100vw - 24px));
  }

  #advance-modal .modal-preview-col {
    max-height: 56vh;
  }
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    padding: 10px;
  }

  .topbar-left { min-width: 0; }
  .topbar-left .sidebar-toggle-btn,
  .topbar-left .eyebrow,
  .top-actions .user-profile-chip,
  .top-actions .role-switcher,
  .top-actions .notification-wrap,
  #font-scale-picker { display: none !important; }
  .top-actions { width: auto; min-width: 0; flex-wrap: nowrap; overflow: visible; }
  .topbar-logout-btn { width: 40px; min-width: 40px; padding: 0 !important; font-size: 0; }
  .topbar-logout-btn svg { width: 18px; height: 18px; }

  .topbar h2 {
    font-size: 19px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-controls,
  .topbar-actions,
  .dfm-topbar-actions,
  .dfm-icon-actions {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
  }

  .qt-project-choice-wrap {
    grid-template-columns: 1fr;
  }

  #advance-modal .advance-project-line {
    grid-template-columns: 1fr;
  }

  #advance-modal .advance-line-remove {
    justify-self: stretch;
    width: 100%;
  }

  #advance-modal .advance-preview-evidence,
  .advance-preview-evidence {
    grid-template-columns: 1fr;
  }
}

@media (min-width: 1180px) {
  .topbar {
    align-items: center;
  }

  .top-actions {
    flex-wrap: nowrap;
    justify-content: flex-end;
    min-width: 0;
  }

  .topbar-user-chip {
    flex: 0 1 210px;
    min-width: 170px;
  }

  .role-switcher {
    flex: 0 1 170px;
    min-width: 150px;
  }

  .company-switcher {
    flex-basis: 150px;
  }

  .topbar-logout-btn {
    flex: 0 0 auto;
    min-width: 126px;
    white-space: nowrap;
  }
}

/* Sales document UX pass: denser FlowAccount-like document lists. */
#quotation-view,
#finance-view {
  --doc-row-height: 58px;
  --doc-blue: #1684c7;
  --doc-border: #dbe6f1;
}

#quotation-view .fa-page-header,
#finance-view .fa-page-header {
  min-height: 86px;
  align-items: center;
  padding: 18px 24px;
  border: 1px solid rgba(226, 232, 240, 0.86);
  border-bottom: 0;
  border-radius: 0;
  box-shadow: none;
}

#quotation-view .fa-page-title,
#finance-view .fa-page-title {
  font-size: 20px;
  line-height: 1.2;
}

#quotation-view .fa-breadcrumb,
#finance-view .fa-breadcrumb {
  margin-top: 6px;
  color: #8aa0bd;
}

#quotation-view .fa-create-btn,
#finance-view .fa-create-btn {
  min-height: 38px;
  padding-inline: 18px;
  border-radius: 12px;
  box-shadow: 0 12px 24px rgba(37, 99, 235, 0.16);
  white-space: nowrap;
}

#quotation-view .fa-table-container,
#finance-view .fa-table-container {
  border: 1px solid var(--doc-border);
  border-radius: 0;
  box-shadow: none;
}

#quotation-view .fa-table-toolbar,
#finance-view .fa-table-toolbar {
  min-height: 54px;
  gap: 12px;
  padding: 10px 16px;
  border-color: var(--doc-border);
}

#quotation-view .fa-filter-tabs,
#finance-view .fa-filter-tabs {
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: thin;
}

#quotation-view .fa-tab,
#finance-view .fa-tab,
#finance-view .fin-doc-tab {
  min-height: 34px;
  padding: 6px 18px;
  border-radius: 0;
  white-space: nowrap;
}

#finance-view .fin-doc-tabs-bar {
  min-height: 42px;
  padding: 0 24px;
  border: 1px solid var(--doc-border);
  border-top: 0;
  background: #fff;
}

#quotation-view .fa-toolbar-right,
#finance-view .fa-toolbar-right {
  flex: 0 0 auto;
  margin-left: auto;
}

#quotation-view .fa-label-btn,
#finance-view .fa-label-btn,
#quotation-view .fa-icon-btn,
#finance-view .fa-icon-btn {
  height: 32px;
  min-width: 40px;
  border-radius: 0;
}

#quotation-view .fa-table,
#finance-view .fa-table {
  table-layout: fixed;
  min-width: 1120px;
  border-collapse: separate;
  border-spacing: 0;
}

#quotation-view .fa-table thead th,
#finance-view .fa-table thead th {
  height: 44px;
  padding: 8px 14px;
  background: var(--doc-blue);
  color: #fff;
  font-size: 12px;
  line-height: 1.2;
  vertical-align: middle;
}

#quotation-view .fa-row td,
#finance-view .fa-row td {
  height: var(--doc-row-height);
  padding-top: 9px;
  padding-bottom: 9px;
  vertical-align: middle;
}

#quotation-view .fa-td-date,
#finance-view .fa-td-date {
  width: 108px;
  color: #334155;
}

#quotation-view .fa-td-docnum,
#finance-view .fa-td-docnum {
  width: 250px;
}

#quotation-view .fa-td-customer,
#finance-view .fa-td-customer {
  min-width: 0;
}

#quotation-view .fa-docnum,
#finance-view .fa-docnum,
#quotation-view .fa-customer-name,
#finance-view .fa-customer-name,
#quotation-view .fa-project-sub,
#finance-view .fa-project-sub {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#quotation-view .fa-docnum,
#finance-view .fa-docnum {
  display: inline-block;
  max-width: 180px;
  vertical-align: middle;
}

#quotation-view .fa-td-amount,
#finance-view .fa-td-amount {
  width: 128px;
  color: #0f172a;
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

#quotation-view .fa-td-status,
#finance-view .fa-td-status {
  width: 180px;
  padding-inline: 10px;
}

#quotation-view .fa-status-dd,
#finance-view .fa-status-dd,
#finance-view .fa-status-sel {
  width: 100%;
  max-width: 170px;
  min-height: 34px;
  border-radius: 10px;
  font-size: 12px;
}

#quotation-view .fa-td-actions,
#finance-view .fa-td-actions {
  width: 210px;
  padding: 7px 12px;
}

#quotation-view .fa-row-actions,
#finance-view .fa-row-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 6px;
}

#quotation-view .fa-row-actions .small,
#finance-view .fa-row-actions .small,
#quotation-view .fa-row-actions .accent-next-button,
#finance-view .fa-row-actions .accent-next-button {
  min-height: 32px;
  padding-inline: 12px;
  border-radius: 10px;
  font-size: 12px !important;
  line-height: 1;
  white-space: nowrap;
}

#quotation-view .fa-row-actions .accent-next-button,
#finance-view .fa-row-actions .accent-next-button {
  border: 1px solid #86efac !important;
  background: #f0fdf4 !important;
  color: #15803d !important;
  box-shadow: none !important;
}

#quotation-view .fa-menu-btn,
#finance-view .fa-menu-btn {
  display: inline-grid;
  flex: 0 0 36px;
  place-items: center;
  width: 36px;
  height: 32px;
  min-height: 32px;
  padding: 0;
  border-radius: 10px;
  font-size: 0;
  letter-spacing: 0;
}

#quotation-view .fa-menu-btn::before,
#finance-view .fa-menu-btn::before {
  content: "...";
  font-size: 14px;
  line-height: 1;
  color: currentColor;
}

.qt-project-choice-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 0.55fr);
  gap: 10px 12px;
  padding: 12px;
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  background: #eff6ff;
}
.qt-project-choice-wrap label {
  min-width: 0;
  color: #315270;
  font-size: 11px;
  font-weight: 700;
}
.qt-project-choice-wrap select {
  width: 100%;
  min-width: 0;
  margin-top: 5px;
  background: #fff;
}
.qt-project-choice-wrap small {
  grid-column: 1 / -1;
  color: #64748b;
  line-height: 1.55;
}

.topbar,
.panel-head,
.fa-table-toolbar,
.dfm-topbar,
.dfm-topbar-title,
.topbar-left,
.topbar-actions,
.topbar-controls {
  min-width: 0;
}

.topbar h2,
.panel-head h3,
.dfm-topbar-title h3,
.fa-table thead th {
  overflow-wrap: anywhere;
  word-break: normal;
}

#quotation-view .fa-table thead th,
#finance-view .fa-table thead th {
  white-space: normal;
  text-wrap: balance;
}

#quotation-view .fa-table-wrap,
#finance-view .fa-table-wrap,
.line-items-wrap,
.cc-stage-table-wrap {
  overflow-x: auto;
  overscroll-behavior-inline: contain;
}

#advance-modal.modal-split[open] {
  align-items: stretch;
  overflow: hidden;
}

#advance-modal.modal-split[open] > form,
#advance-modal .modal-preview-col {
  min-width: 0;
  max-width: 100%;
}

#advance-modal .modal-preview-col {
  overflow: auto;
}

#advance-modal .advance-form-body,
#advance-modal .advance-project-lines,
#advance-modal .advance-required-evidence,
#advance-modal .attach-widget {
  min-width: 0;
}

#advance-modal .modal-head h3,
#advance-modal label,
#advance-modal legend,
#advance-modal .advance-project-line label,
.record strong,
.record span,
.record small {
  overflow-wrap: anywhere;
}

#advance-modal .advance-form-body input,
#advance-modal .advance-form-body select,
#advance-modal .advance-form-body textarea {
  min-width: 0;
}

#advance-modal .advance-project-line {
  grid-template-columns: minmax(170px, 1.1fr) minmax(130px, .8fr) minmax(120px, .65fr) minmax(180px, 1fr) 38px;
}

#advance-modal .advance-line-remove {
  grid-column: auto;
  grid-row: auto;
}

#finance-view .fa-table th:nth-child(1),
#quotation-view .fa-table th:nth-child(1) { width: 42px; }
#finance-view .fa-table th:nth-child(2),
#quotation-view .fa-table th:nth-child(2) { width: 108px; }
#finance-view .fa-table th:nth-child(3),
#quotation-view .fa-table th:nth-child(3) { width: 250px; }
#finance-view .fa-table th:nth-last-child(3),
#quotation-view .fa-table th:nth-last-child(3) { width: 128px; }
#finance-view .fa-table th:nth-last-child(2),
#quotation-view .fa-table th:nth-last-child(2) { width: 180px; }
#finance-view .fa-table th:nth-last-child(1),
#quotation-view .fa-table th:nth-last-child(1) { width: 210px; }

.nav {
  scrollbar-width: thin;
  scrollbar-color: #94a3b8 transparent;
}

.nav::-webkit-scrollbar {
  width: 8px;
}

.nav::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: #94a3b8;
}

@media (max-width: 1500px) {
  #quotation-view .fa-table,
  #finance-view .fa-table {
    min-width: 1040px;
  }

  #quotation-view .fa-td-actions,
  #finance-view .fa-td-actions,
  #quotation-view .fa-table th:nth-last-child(1),
  #finance-view .fa-table th:nth-last-child(1) {
    width: 172px;
  }

  #quotation-view .fa-row-actions .accent-next-button,
  #finance-view .fa-row-actions .accent-next-button {
    display: none;
  }
}

/* Text and spacing safety pass: keep Thai/English labels readable across panels. */
.panel,
.metric-card,
.record,
.notification-panel,
.modal,
.table-wrap {
  overflow-wrap: anywhere;
}

.panel-head {
  align-items: flex-start;
  gap: 14px;
}

.panel-head > div {
  min-width: 0;
}

.panel-head h3,
.panel h3,
.panel h4 {
  max-width: 100%;
  line-height: 1.35;
  letter-spacing: 0;
  text-wrap: pretty;
}

.panel-subtitle,
.panel p,
.record small,
.notification-item-body small,
.backup-actions p,
.export-card span {
  max-width: 100%;
  line-height: 1.55;
  letter-spacing: 0;
  overflow-wrap: anywhere;
  word-break: normal;
}

.panel-subtitle {
  margin-top: 6px;
  color: #8aa0bd;
}

.panel-head .primary-button,
.panel-head .ghost-button {
  flex: 0 0 auto;
  white-space: nowrap;
}

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

.backup-actions .primary-button,
.backup-actions .ghost-button {
  min-height: 38px;
  white-space: nowrap;
}

.backup-actions p,
.backup-actions small,
.sync-status,
.status-note {
  flex: 1 1 240px;
  min-width: 180px;
}

.settings-grid .panel {
  min-width: 0;
}

.settings-list .record {
  min-width: 0;
}

.settings-list .record > div {
  min-width: 0;
}

.settings-list strong,
.settings-list span,
.settings-list small {
  max-width: 100%;
}

button,
.primary-button,
.ghost-button,
.fa-label-btn,
.fa-tab,
.fin-doc-tab {
  letter-spacing: 0;
  text-wrap: nowrap;
}

#sb-panel .enh-actions {
  align-items: center;
  flex-wrap: wrap;
}

.sb-auto-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid #dbe6f5;
  border-radius: 12px;
  background: #f8fbff;
  color: #334155;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.sb-auto-toggle input[type="checkbox"] {
  appearance: none;
  display: grid;
  place-content: center;
  flex: 0 0 18px;
  width: 18px;
  height: 18px;
  margin: 0;
  border: 1px solid #bfdbfe;
  border-radius: 5px;
  background: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .6);
  cursor: pointer;
}

.sb-auto-toggle input[type="checkbox"]::before {
  content: "";
  width: 10px;
  height: 10px;
  transform: scale(0);
  transform-origin: center;
  transition: transform .12s ease;
  background: #ffffff;
  clip-path: polygon(14% 45%, 0 62%, 38% 100%, 100% 16%, 82% 0, 36% 63%);
}

.sb-auto-toggle input[type="checkbox"]:checked {
  border-color: #2563eb;
  background: #2563eb;
}

.sb-auto-toggle input[type="checkbox"]:checked::before {
  transform: scale(1);
}

.enh-document-ops-table th,
.enh-document-ops-table td {
  vertical-align: top;
}

#enh-document-ops-panel {
  overflow: visible;
}

.enh-flow-list {
  display: grid;
  gap: 10px;
}

.enh-flow-card {
  display: grid;
  grid-template-columns: minmax(300px, 1.1fr) minmax(360px, 1fr) auto;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line-subtle);
  background: #fff;
}

.enh-flow-main {
  display: grid;
  grid-template-columns: 190px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-width: 0;
}

.enh-flow-qt,
.enh-flow-step {
  border: 1px solid var(--line);
  background: #f8fbff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.enh-flow-qt {
  display: grid;
  gap: 2px;
  min-height: 72px;
  padding: 10px 12px;
}

.enh-flow-qt span,
.enh-flow-step b {
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.enh-flow-qt strong,
.enh-flow-info strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.enh-flow-qt small,
.enh-flow-info span,
.enh-flow-step span {
  color: var(--ink-3);
  font-size: 11px;
}

.enh-flow-info {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.enh-flow-info .fa-badge-gray,
.enh-flow-info .fa-badge-blue,
.enh-flow-info .fa-badge-red {
  width: fit-content;
}

.enh-flow-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(100px, 1fr));
  gap: 8px;
  align-items: stretch;
}

.enh-flow-step {
  display: grid;
  gap: 4px;
  min-height: 58px;
  padding: 9px 10px;
}

.enh-flow-step.is-done {
  border-color: rgba(37, 99, 235, 0.28);
  background: #eef6ff;
}

.enh-flow-step.is-empty {
  border-style: dashed;
  background: #f8fafc;
  cursor: default;
}

.enh-flow-step.is-empty b,
.enh-flow-step.is-empty span {
  color: #94a3b8;
}

.enh-flow-qt:hover,
.enh-flow-step.is-done:hover {
  border-color: var(--blue);
  background: #eaf3ff;
}

.enh-flow-qt:focus-visible,
.enh-flow-step:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 2px;
}

.enh-doc-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  min-width: 240px;
}

.enh-doc-actions .ghost-button,
.enh-doc-actions .primary-button {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

@media (max-width: 1280px) {
  .enh-flow-card {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .enh-doc-actions {
    justify-content: flex-start;
    min-width: 0;
  }
}

@media (max-width: 680px) {
  .enh-flow-card {
    padding: 10px;
  }

  .enh-flow-main,
  .enh-flow-steps {
    grid-template-columns: 1fr;
  }

  .enh-flow-qt,
  .enh-flow-step {
    min-height: 0;
  }

  .enh-doc-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .enh-doc-actions button {
    width: 100%;
  }
}

.enh-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(3px);
}

.enh-legal-modal {
  position: relative;
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  border: 1px solid #dbe6f5;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 22px 70px rgba(15, 23, 42, 0.22);
  padding: 22px;
}

.enh-legal-modal h3 {
  margin: 0 36px 8px 0;
  color: #0f172a;
  font-size: 20px;
  line-height: 1.35;
}

.enh-modal-x {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 34px;
  height: 34px;
  border: 1px solid #dbe6f5;
  border-radius: 999px;
  background: #ffffff;
  color: #64748b;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.enh-modal-x:hover {
  background: #f8fafc;
  color: #0f172a;
}

.enh-legal-reason-label {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 16px;
  color: #334155;
  font-size: 13px;
  font-weight: 700;
}

.enh-legal-reason-label textarea {
  width: 100%;
  min-height: 116px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 12px 14px;
  resize: vertical;
  color: #0f172a;
  font: inherit;
  font-weight: 500;
  outline: none;
}

.enh-legal-reason-label textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}

.enh-modal-note {
  margin: 10px 0 0;
  color: #64748b;
  font-size: 12px;
  line-height: 1.6;
}

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

@media (max-width: 720px) {
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .panel-head .primary-button,
  .panel-head .ghost-button,
  .backup-actions .primary-button,
  .backup-actions .ghost-button {
    width: 100%;
  }

  .enh-modal-backdrop {
    align-items: end;
    padding: 8px;
  }

  .enh-legal-modal {
    width: 100%;
    max-height: calc(100vh - 16px);
    border-radius: 16px 16px 12px 12px;
    padding: 18px;
  }

  .enh-modal-actions {
    flex-direction: column-reverse;
  }

  .enh-modal-actions .primary-button,
  .enh-modal-actions .ghost-button {
    width: 100%;
    min-height: 42px;
  }

  .enh-doc-actions {
    justify-content: flex-start;
    min-width: 0;
  }

  .enh-doc-actions .ghost-button,
  .enh-doc-actions .primary-button {
    min-height: 34px;
  }
}

/* ═══ กันกรอบล้น (ตรวจพบจากการทดสอบที่จอ 1280-1500px) ═══ */

/* หน้าเบิกค่าใช้จ่าย: ตารางวงเงิน SET UP ล้นถึง 211px */
.line-policy-tables { min-width: 0; }
.line-policy-tables > * { min-width: 0; max-width: 100%; }
.line-policy-tables .setup-food-table,
.policy-grid .setup-food-table,
.setup-food-table {
  table-layout: fixed;
  width: 100%;
  min-width: 0;
}
.setup-food-table th,
.setup-food-table td {
  word-break: normal;
  overflow-wrap: break-word;
  padding: 5px 6px;
}

/* การ์ดเลือกประเภทการเบิก: ข้อความยาวดันออกนอกปุ่ม */
.expense-entry-card { min-width: 0; overflow: hidden; }
.expense-entry-card > * {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: normal;
}

/* หน้าบัญชี: แถวปุ่มไม่ตัดบรรทัด ทำให้ปุ่มหลักหลุดกรอบ 142px */
#accounting-view .panel-head > div,
#accounting-view .panel-head {
  flex-wrap: wrap;
  min-width: 0;
  gap: 8px;
}
#accounting-view .panel-head button { flex: 0 0 auto; }

/* หน้าเอกสาร: การ์ด flow ข้อความยาวดันออกนอกปุ่ม */
.enh-flow-qt, [class*="enh-flow-"] { min-width: 0; overflow: hidden; }
.enh-flow-qt > *, [class*="enh-flow-"] > * {
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  white-space: normal;
}

/* จอ 1200-1400px: คอลัมน์ขั้นต่ำของหน้าเบิกกว้างเกินพื้นที่จริง */
@media (max-width: 1400px) {
  .line-workspace { grid-template-columns: minmax(0, 0.86fr) minmax(0, 1.14fr); }
  .line-workspace > * { min-width: 0; }
}

/* ═══ แท็กเวลา/เวอร์ชัน มุมล่างขวา ═══ */
#build-stamp {
  position: fixed;
  right: 12px;
  bottom: 10px;
  z-index: 300;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(15, 40, 70, 0.10);
  font-size: 11px;
  line-height: 1.35;
  color: var(--ink-3);
  cursor: default;
  user-select: none;
  transition: opacity 0.15s;
  opacity: 0.72;
}
#build-stamp:hover { opacity: 1; }
#build-stamp .bs-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #22c55e;
  flex: 0 0 auto;
}
#build-stamp strong { color: var(--ink-2); font-weight: 600; }
@media (max-width: 820px) { #build-stamp { font-size: 10px; padding: 4px 9px; right: 8px; bottom: 8px; } }
@media print { #build-stamp { display: none !important; } }


/* ตารางวงเงิน: ตัวเลขต้องอ่านออกแม้ช่องแคบ */
.setup-food-table { font-size: 11px; }
.setup-food-table th, .setup-food-table td { line-height: 1.35; white-space: normal; }
.setup-food-table th:first-child, .setup-food-table td:first-child { width: 46%; }

/* ═══ การตัดคำภาษาไทยในตัวเอกสาร ═══
   กฎกันข้อความล้นกรอบ (.modal / .panel { overflow-wrap: anywhere }) ถูกสืบทอด
   เข้าไปในใบเอกสารด้วย ทำให้เบราว์เซอร์ตัดกลางคำไทย เช่น "รายการ" → "รายกา / ร"
   ในกระดาษเอกสารจึงต้องรีเซ็ตให้ตัดตามคำจริง */
.document-page,
.document-page *,
#document-preview-modal-body .document-page *,
#doc-print-overlay .document-page * {
  overflow-wrap: break-word;
  word-break: normal;
  line-break: auto;
  hyphens: none;
}
/* คอลัมน์แคบ (จำนวน / หน่วย) ห้ามตัดคำเด็ดขาด */
.document-page .doc-table td:nth-child(3),
.document-page .doc-table td:nth-child(4),
.document-page .doc-table th:nth-child(3),
.document-page .doc-table th:nth-child(4) {
  word-break: keep-all;
  overflow-wrap: normal;
}

/* คอลัมน์สถานะ: สถานะที่ระบบคำนวณเอง (อ่านอย่างเดียว) + สถานะเอกสารที่กรอกได้ */
/* td ห้ามเป็น flex เพราะทำให้ตารางคำนวณความสูงแถวผิด → ใช้ block ซ้อนกันแทน */
.fa-td-status { vertical-align: middle; }
.fa-td-status .fa-status-auto { display: inline-flex; margin-bottom: 4px; }
.fa-td-status .fa-status-dd { display: block; }
.fa-status-auto { cursor: help; opacity: 0.95; }
.fa-status-auto::after { content: " · อัตโนมัติ"; font-size: 10px; opacity: 0.7; font-weight: 400; }
.fa-status-dd { max-width: 100%; }

/* รายละเอียดย่อยในแถวรายการ: วางเป็นบรรทัดที่สอง เยื้องใต้ช่อง "รายละเอียด"
   ไม่แทรกเป็นคอลัมน์ที่ 3 เพราะจะดันหัวคอลัมน์อื่นเบียดจนตัวอักษรลอยไม่ตรงช่อง */
.line-row .line-subdetail-label {
  grid-column: 2 / -1;
  margin-top: 2px;
}
.line-row .line-subdetail-label > input { font-size: 12px; }
@media (max-width: 900px) {
  .line-row .line-subdetail-label { grid-column: 1 / -1; }
}

/* สถานะโปรเจกต์บนการ์ด: เลือกเปลี่ยนได้ ไม่ใช่ป้ายอ่านอย่างเดียว */
.project-status-dd {
  font-size: 11.5px; font-weight: 600; padding: 3px 8px;
  border: 1px solid var(--line); border-radius: 0;
  background: var(--surface); color: var(--ink-2);
  font-family: inherit; cursor: pointer; max-width: 130px;
}
.project-status-dd:hover { border-color: var(--accent); color: var(--accent); }

/* ข้อกำหนดข้อ 3: Remark / Payment Term วางต่อจากรายการสินค้า ก่อนสรุปยอดเงิน
   (เดิมอยู่คอลัมน์ซ้ายคู่กับยอดรวม ลูกค้าอ่านเงื่อนไขไม่ทันก่อนเห็นราคาสุทธิ) */
.doc-note-block { margin: 10px 0 2px; }
.doc-note-block p { padding: 7px 10px; margin: 4px 0 0; }
.doc-summary.doc-summary-right {
  grid-template-columns: 1fr 300px;
  margin-top: 6px;
}
.doc-summary.doc-summary-right > .summary-table { grid-column: 2; }

/* ช่องเลือกชื่อโปรเจกต์ ซ่อนเมื่อหมวดไม่ใช่ PROJECT */
#line-project-wrap[hidden] { display: none !important; }

/* ═══ ช่องกรอกในฟอร์ม: แยกให้เห็นชัดว่าอันไหนเลือกได้ อันไหนระบบคิดให้ ═══ */

/* dropdown ต้องดูออกว่าเป็น dropdown ไม่ใช่ช่องพิมพ์ */
select:not([multiple]):not([size]) {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath fill='%23475569' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 11px;
  padding-right: 30px !important;
  cursor: pointer;
}
select:not([multiple]):not([size]):hover { background-color: rgba(21,120,190,0.04); }

/* ช่องที่ระบบคำนวณให้ / แก้ไขไม่ได้ → เทา ชัดเจนว่ากรอกไม่ได้ */
input[readonly], textarea[readonly], input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-2, #eef2f7) !important;
  color: var(--ink-3) !important;
  cursor: not-allowed;
  border-style: dashed;
}
label.is-computed > span, label.is-computed { color: var(--ink-3); }
label.is-computed::after {
  content: " (ระบบคำนวณให้)";
  font-size: 10px; color: var(--ink-3); font-weight: 400;
}
label.is-computed input { font-weight: 600; }

/* placeholder ให้จางกว่าข้อความจริง จะได้ไม่เข้าใจผิดว่ากรอกไว้แล้ว */
input::placeholder, textarea::placeholder { color: #b6c2ce; font-style: italic; }

/* ── แผงติดตามสถานะคำขอเบิก ── */
.line-list-panel .panel-head { display: flex; align-items: center; justify-content: space-between; }
.line-list-count { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.line-status-tabs {
  display: flex; gap: 0; flex-wrap: wrap;
  border-bottom: 2px solid var(--line); padding: 0 16px;
}
.line-status-tab {
  background: none; border: none; border-bottom: 3px solid transparent;
  padding: 9px 16px; font-size: 12.5px; font-family: inherit; cursor: pointer;
  color: var(--ink-2); margin-bottom: -2px; transition: color .15s, border-color .15s;
}
.line-status-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.line-status-tab:hover:not(.active) { color: var(--ink-1); }

/* ── ตารางรายการย่อย (ย้ายขึ้นมาอยู่ต่อจากช่องกรอกหลัก) ── */
.sub-items-block { margin: 4px 0 12px; }
.sub-items-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.sub-items-head strong { font-size: 13px; }
#sub-receipt-items-table th:nth-child(1) { width: auto; }
#sub-receipt-items-table th:nth-child(2), #sub-receipt-items-table td:nth-child(2) { width: 110px; }
#sub-receipt-items-table th:nth-child(3), #sub-receipt-items-table td:nth-child(3) { width: 28%; }
#sub-receipt-items-table th:nth-child(4), #sub-receipt-items-table td:nth-child(4) { width: 34px; }
#sub-receipt-items-table input { width: 100%; font-size: 12px; }
.line-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.line-actions #submit-line-expense { margin-left: auto; }

/* ── ป็อปอัพยืนยันหลังบันทึก/ส่งคำขอเบิก ── */
#line-saved-modal { width: min(430px, calc(100vw - 32px)); }
#line-saved-modal .line-saved-body { display: flex; flex-direction: column; }
#line-saved-modal .modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); }
#line-saved-modal .line-saved-content { padding: 18px; font-size: 13.5px; line-height: 1.6; }
#line-saved-modal .line-saved-hint { color: var(--ink-3); font-size: 12px; margin-top: 10px; }
#line-saved-modal .modal-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface);
}
.line-actions #draft-line-expense { margin-left: auto; }
.line-actions #submit-line-expense { margin-left: 0; }

/* ═══ ไทม์ไลน์เอกสารในโปรเจกต์ (แนวนอน) ═══ */
.proj-timeline {
  display: flex; align-items: flex-start; gap: 0;
  list-style: none; margin: 10px 0 22px; padding: 4px 0 2px;
  overflow-x: auto; overflow-y: hidden;
}
.pt-step {
  position: relative; flex: 1 1 0; min-width: 150px;
  padding: 0 8px; text-align: center;
}
.pt-step::before {
  content: ""; position: absolute; top: 15px; left: -50%; width: 100%;
  height: 2px; background: var(--line); z-index: 0;
}
.pt-step:first-child::before { display: none; }
.pt-step.pt-done::before, .pt-step.pt-active::before { background: var(--accent); }
.pt-dot {
  position: relative; z-index: 1;
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--surface);
  color: var(--ink-3); font-size: 13px; font-weight: 600; font-family: inherit;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
  transition: transform .12s, box-shadow .12s;
}
.pt-dot:hover { transform: scale(1.08); box-shadow: 0 0 0 4px rgba(21,120,190,0.12); }
.pt-done .pt-dot { background: var(--accent); border-color: var(--accent); color: #fff; }
.pt-active .pt-dot { border-color: var(--accent); color: var(--accent); box-shadow: 0 0 0 4px rgba(21,120,190,0.14); }
.pt-skip .pt-dot { border-style: dashed; }
.pt-body { margin-top: 8px; display: flex; flex-direction: column; gap: 2px; align-items: center; }
.pt-body strong { font-size: 12.5px; color: var(--ink-1); line-height: 1.3; }
.pt-body span { font-size: 11.5px; color: var(--ink-3); }
.pt-body small { font-size: 12px; font-weight: 600; color: var(--accent); }
.pt-todo .pt-body strong, .pt-skip .pt-body strong { color: var(--ink-3); }
.pt-links { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; justify-content: center; }
.pt-link {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  font-family: inherit; font-size: 11px; padding: 3px 9px; border-radius: 0; cursor: pointer;
}
.pt-link:hover { border-color: var(--accent); color: var(--accent); }
.pt-link-ghost { border-style: dashed; }
@media (max-width: 900px) {
  .proj-timeline { flex-direction: column; align-items: stretch; gap: 14px; }
  .pt-step { min-width: 0; display: flex; gap: 10px; text-align: left; padding: 0; }
  .pt-step::before { top: -10px; left: 15px; width: 2px; height: 14px; }
  .pt-body { margin-top: 0; align-items: flex-start; }
  .pt-links { justify-content: flex-start; }
}

/* ── วางบิลผู้รับเหมา: หน้าจอใหญ่เหมือนหน้าเอกสารจริง ── */
#contractor-modal {
  width: min(97vw, 1560px); max-width: min(97vw, 1560px);
  height: min(94vh, 1000px); max-height: min(94vh, 1000px);
}
#contractor-modal > form { height: 100%; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
#contractor-modal .form-body { grid-template-columns: 1fr 1fr; }

/* เอกสารแนบรายใบ */
#cb-evidence-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 10px; }
.cb-evi-row {
  border: 1px solid var(--line-subtle); border-radius: var(--radius);
  padding: 9px 11px; background: var(--surface);
}
.cb-evi-row.cb-evi-missing { border-color: #e5a13a; background: rgba(245,158,11,0.06); }
.cb-evi-row.cb-evi-off { opacity: 0.55; }
.cb-evi-row.cb-evi-off .attach-widget { display: none; }
.cb-evi-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.cb-evi-head label { display: flex; align-items: center; gap: 7px; margin: 0; cursor: pointer; font-weight: 500; }
.cb-evi-flag { margin-left: auto; font-size: 11px; font-weight: 600; }
.cb-evi-flag.is-missing { color: #b45309; }
.cb-evi-flag.is-ok { color: #15803d; }
.cb-evi-row .attach-widget { margin-top: 7px; }
.cb-evidence-note { display: block; margin-top: 8px; font-size: 11.5px; color: var(--ink-3); }
.wht-rows-table input[inputmode="decimal"] { text-align: right; }

/* กัน label ในฟอร์ม (flex column) มาทำให้ checkbox ลอยอยู่คนละบรรทัดกับข้อความ */
#cb-evidence-list .cb-evi-head label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  width: auto;
}
#cb-evidence-list .cb-evi-head label input[type="checkbox"] {
  width: 16px; height: 16px; min-width: 16px; flex: 0 0 16px; margin: 0;
}
#cb-evidence-list .cb-evi-head label span { flex: 1; }
/* กล่องอัปโหลดรวมกลายเป็นตัวสรุปอย่างเดียว */
#contractor-attach-widget.attach-mirror .attach-actions,
#contractor-attach-widget.attach-mirror .attach-remove-btn { display: none; }

/* ── หน้ารายละเอียดเอกสารในโปรเจกต์: ไม่ให้กล่องยืดเต็มจอจนโล่ง ── */
.detail-modal-full .detail-body { align-content: start; }
.project-doc-detail-head {
  align-items: center;
  padding: 12px 16px;
  min-height: 0;
}
.project-doc-detail-head > div { min-width: 0; }
.project-doc-record-list { align-content: start; }
.project-doc-record {
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  padding: 12px 14px;
  gap: 14px;
}
.project-doc-record .project-doc-actions {
  display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end;
}
.project-doc-record .status { justify-self: start; }
@media (max-width: 900px) {
  .project-doc-record { grid-template-columns: 1fr; }
  .project-doc-record .project-doc-actions { justify-content: flex-start; }
}

/* หน้าต่างพรีวิวใบ: แสดงกระดาษขนาดจริง ไม่ให้ค่า zoom จากหน้าแก้ไขติดมาย่อจนอ่านไม่ออก */
.preview-only-body { padding: 20px 0 28px; display: grid; justify-items: center; }
.preview-only-body .document-page {
  zoom: 1 !important;
  transform: none !important;
  width: 794px !important;
  max-width: 100%;
  box-shadow: 0 8px 34px rgba(0,0,0,0.35);
}

/* บรรทัดข้อมูลหัก ณ ที่จ่าย — ไม่ใช่ยอดหักจากรายได้ แต่บอกว่าเงินเข้าบัญชีจริงเท่าไหร่ */
.summary-table .wht-memo-row { color: #b45309; font-size: 12px; }
.summary-table .wht-memo-row strong { font-weight: 600; }
#preview-net-transfer-row { border-top: 1px dashed var(--line); padding-top: 6px; }

/* ยอดผูกพันจาก PO ที่ยังไม่วางบิล */
.project-budget-strip { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.project-budget-strip strong.warn { color: #b45309; }
@media (max-width: 900px) { .project-budget-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ── แถวเบิกแนวนอน: เห็นข้อมูลครบในแถวเดียวตามมติประชุม ──
   10 คอลัมน์: วันที่ · หมวดหมู่ · รายละเอียด · เอกสารแนบ · เลขที่ · ร้านค้า · ก่อน VAT · VAT · รวม · ลบ */
#sub-receipt-items-table { table-layout: fixed; width: 100%; }
#sub-receipt-items-table th:nth-child(1),  #sub-receipt-items-table td:nth-child(1)  { width: 9.5%; }
#sub-receipt-items-table th:nth-child(2),  #sub-receipt-items-table td:nth-child(2)  { width: 12%; }
#sub-receipt-items-table th:nth-child(3),  #sub-receipt-items-table td:nth-child(3)  { width: auto; }
#sub-receipt-items-table th:nth-child(4),  #sub-receipt-items-table td:nth-child(4)  { width: 11%; }
#sub-receipt-items-table th:nth-child(5),  #sub-receipt-items-table td:nth-child(5)  { width: 10%; }
#sub-receipt-items-table th:nth-child(6),  #sub-receipt-items-table td:nth-child(6)  { width: 13%; }
#sub-receipt-items-table th:nth-child(7),  #sub-receipt-items-table td:nth-child(7)  { width: 8.5%; }
#sub-receipt-items-table th:nth-child(8),  #sub-receipt-items-table td:nth-child(8)  { width: 7%; }
#sub-receipt-items-table th:nth-child(9),  #sub-receipt-items-table td:nth-child(9)  { width: 8.5%; }
#sub-receipt-items-table th:nth-child(10), #sub-receipt-items-table td:nth-child(10) { width: 34px; text-align: center; }

/* ตัวอักษรใหญ่ขึ้นให้อ่านง่ายและกดง่ายบน iPad */
#sub-receipt-items-table th { font-size: 12.5px; font-weight: 600; line-height: 1.3; white-space: normal; }
#sub-receipt-items-table input,
#sub-receipt-items-table select { font-size: 13px; padding: 5px 7px; height: 34px; }
#sub-receipt-items-table .sri-file { display: none !important; }
#sub-receipt-items-table .sri-file-btn { font-size: 11.5px; height: 28px; padding: 3px 5px; width: 100%; }
#sub-receipt-items-table .sri-file-name { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* จอแคบกว่า 1100px ให้เลื่อนแนวนอนแทนการบีบช่องจนกรอกไม่ได้ */
@media (max-width: 1100px) {
  .sub-items-block .line-items-wrap { overflow-x: auto; }
  #sub-receipt-items-table { min-width: 1060px; }
}

.sub-items-block .line-items-wrap { overflow-x: auto; }


/* ── หน้าเบิกจ่ายแบบแนวขวาง (Landscape) ──────────────────────
   ฝ่ายจัดซื้อและ PM ใช้บนจอคอมและ iPad จึงขยายพื้นที่เนื้อหาให้กว้างเต็มจอ
   และวางฟอร์มไว้บน ตารางรายการไว้ล่าง เพื่อให้ตารางได้ความกว้างเต็ม */
#line-view { max-width: none; width: 100%; }
#line-view .line-items-wrap { width: 100%; }

@media (min-width: 1200px) {
  #line-view .form-grid.two { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #line-view .form-grid.two .full-span { grid-column: 1 / -1; }
}

/* iPad แนวนอน — ช่องสูงขึ้นให้นิ้วกดง่าย */
@media (min-width: 1024px) and (max-width: 1366px) {
  #line-view .form-grid.two { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #sub-receipt-items-table input,
  #sub-receipt-items-table select { height: 38px; font-size: 13.5px; }
}

/* ── Responsive polish after customer UAT ─────────────────────
   Keep dense desktop screens usable, then collapse preview/form areas
   before inputs start squeezing into each other. */
@media (max-width: 1440px) {
  .app-main { padding-inline: clamp(14px, 1.4vw, 22px); }
  .line-workspace {
    grid-template-columns: minmax(430px, 0.95fr) minmax(480px, 1.05fr);
    gap: 14px;
  }
  dialog.modal-split[open],
  #advance-modal.modal-split[open],
  #contractor-modal > form {
    grid-template-columns: minmax(460px, 0.98fr) minmax(420px, 1.02fr);
  }
  .document-page,
  .receipt-page,
  .mini-doc {
    max-width: 100%;
  }
}

@media (max-width: 1180px) {
  .line-workspace,
  .document-workspace,
  .project-full-grid,
  .accounting-grid {
    grid-template-columns: 1fr !important;
  }
  .line-form-panel,
  .receipt-preview-wrap,
  .incentive-preview-panel {
    position: static;
    max-height: none;
  }
  .document-preview-wrap,
  .receipt-preview-wrap {
    min-height: 520px;
  }
  dialog.modal-split[open],
  #advance-modal.modal-split[open],
  #contractor-modal[open] > form {
    grid-template-columns: 1fr;
    width: min(98vw, 760px);
  }
  .modal-preview-col {
    display: none;
  }
  #advance-modal .advance-form-body,
  #advance-modal form,
  #advance-clear-modal form,
  dialog.modal-split > form .form-body {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  /* Mobile already has its own fixed application header.  Keep the desktop
     toolbar to a single compact row instead of stacking every desktop control
     underneath it. */
  .app-shell { padding: 78px 12px 24px; }
  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    min-height: 52px;
    margin-bottom: 14px;
    padding: 8px 10px;
  }
  .topbar-left { min-width: 0; }
  .topbar-left .sidebar-toggle-btn,
  .topbar-left .eyebrow,
  .top-actions .user-profile-chip,
  .top-actions .role-switcher,
  .top-actions .notification-wrap { display: none !important; }
  .topbar h2 { font-size: 18px; line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .top-actions { width: auto; min-width: 0; flex-wrap: nowrap; overflow: visible; }
  .topbar-logout-btn { width: 40px; min-width: 40px; padding: 0 !important; font-size: 0; }
  .topbar-logout-btn svg { width: 18px; height: 18px; }

  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 60;
    width: min(86vw, 300px);
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  .topbar,
  .panel-head,
  .modal-head,
  .dfm-topbar {
    gap: 10px;
    flex-wrap: wrap;
  }
  .topbar-controls,
  .doc-actions,
  .dfm-icon-actions,
  .modal-actions {
    width: 100%;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 2px;
  }
  .metric-grid,
  .content-grid,
  .detail-summary,
  .project-budget-strip,
  .accounting-period-controls,
  .accounting-filters {
    grid-template-columns: 1fr !important;
  }
  #line-view .form-grid.two,
  #advance-modal .advance-form-body,
  #advance-modal form,
  #advance-clear-modal form,
  dialog.modal-split > form .form-body,
  .modal form {
    grid-template-columns: 1fr !important;
  }
  .advance-project-line {
    grid-template-columns: 1fr;
  }
  .advance-line-remove {
    grid-column: auto;
    grid-row: auto;
    justify-self: end;
  }
  dialog,
  .modal,
  .document-fill-modal,
  dialog.modal-split {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
  }
  .document-preview-wrap,
  .receipt-preview-wrap {
    min-height: 420px;
    padding: 10px;
    overflow: auto;
  }
  .table-wrap,
  .line-items-wrap,
  .fa-table-wrap {
    margin-inline: -12px;
    padding-inline: 12px;
  }
  button,
  .primary-button,
  .ghost-button {
    min-height: 40px;
  }
}


/* ── ปุ่มในแถวใบเสนอราคา: ไม่ให้ล้นหรือซ้อนกัน ────────────── */
#quotation-view .fa-row-actions {
  display: flex; flex-wrap: nowrap; gap: 6px;
  justify-content: flex-end; align-items: center;
  white-space: nowrap;
}
#quotation-view .fa-row-actions > button { flex: 0 0 auto; }
#quotation-view .fa-td-actions { width: 1%; white-space: nowrap; }
@media (max-width: 1400px) {
  #quotation-view .fa-row-actions { flex-wrap: wrap; justify-content: flex-end; row-gap: 4px; }
}


/* ── แถวใบเสนอราคา: ป้ายสถานะกับปุ่มต้องไม่ทับกัน ────────────── */
#quotation-view .fa-td-status { min-width: 150px; white-space: nowrap; }
#quotation-view .fa-td-status select,
#quotation-view .fa-td-status .fa-status-select { max-width: 100%; }
#quotation-view .fa-row-actions { gap: 5px; padding-left: 8px; }
#quotation-view .fa-row-actions button { white-space: nowrap; }
#quotation-view .fa-row-actions button[disabled] { pointer-events: none; }
@media (max-width: 1500px) {
  #quotation-view .fa-td-status { min-width: 120px; }
  #quotation-view .fa-row-actions .small { font-size: 11.5px; padding: 3px 8px; }
}


/* ── ข้อความแทนลายเซ็น ── */
/* บนหน้าจอแสดงให้เห็นว่าสถานะเป็นอย่างไร แต่เวลาพิมพ์จะถูกซ่อนไว้
   เพื่อให้เส้นลายเซ็นว่างพอสำหรับเซ็นจริงด้วยปากกา */
.sig-note { color: var(--ink-3); font-size: 11px; font-style: italic; }
@media print {
  .sig-note { visibility: hidden !important; }
  .signature-box { height: 64px !important; }
}


/* ── ขอบกระดาษตอนพิมพ์ ─────────────────────────────────
   ต้องจำเพาะพอที่จะชนะกฎ .document-page เดิม (padding 54px)
   ใช้หน่วยมิลลิเมตรเพื่อให้ขอบบนกระดาษจริงตรงตามที่ตั้ง */
@media print {
  .document-page,
  .doc-preview-viewport .document-page,
  #document-preview-modal-body .document-page,
  .document-preview-wrap .document-page,
  .preview-only-body .document-page {
    padding: 14mm 15mm 16mm !important;
  }
  /* กล่องวัดความสูงไม่ใช่หน้าพิมพ์จริง ไม่ต้องมีขอบ */
  .print-measure-box { display: none !important; }
  .document-page-number { right: 15mm !important; bottom: 7mm !important; }
}


/* ── ปุ่มพิมพ์/ดาวน์โหลดในหน้าเอกสาร ─────────────────────────
   ปุ่มพวกนี้ตั้ง display เป็น flex ไว้ แอตทริบิวต์ hidden จึงไม่มีผล
   ต้องบังคับซ่อนตรงนี้ ไม่งั้นใบที่ยังไม่อนุมัติจะยังเห็นปุ่มและกดได้ */
#dfm-act-print[hidden],
#dfm-act-download[hidden],
#dfm-act-share[hidden],
.dfm-actions [hidden],
[data-doc-print][hidden],
[data-doc-download][hidden] { display: none !important; }

#doc-send-note { max-width: 340px; }


/* ── ไฟล์ PDF ที่ export ออกไป ──────────────────────────────
   ปัญหาที่เจอจากไฟล์จริง SDDS-QT-2026-0005.pdf
   1) ข้อความ "คลิกเพื่อกรอก" ติดไปบนกระดาษ ในช่องเลขผู้เสียภาษี/วันที่
   2) สระและวรรณยุกต์ไทยหลุดตำแหน่งเมื่อฟอนต์ Kanit โหลดจาก Google ไม่ทัน
      หรือเครื่องออฟไลน์ จึงต้องมีฟอนต์ไทยในเครื่องรองไว้ทุกชั้น
   3) แถว "รวมหมวด" ถูกดันข้ามไปหน้าถัดไป แยกจากรายการในหมวดเดียวกัน */
@media print {
  /* 1) ช่องว่างต้องว่างจริง ไม่มีคำใบ้ ไม่มีกรอบ */
  .doc-editable-empty::before,
  .document-page .doc-editable-empty:not(:focus)::before { content: "" !important; }
  .document-page .doc-editable,
  .document-page .doc-editable:hover,
  .document-page .doc-editable:focus {
    box-shadow: none !important;
    background: transparent !important;
    outline: none !important;
  }

  /* 2) ลำดับฟอนต์สำรอง — Sarabun/Leelawadee/Tahoma มีในเครื่อง Windows
        ทั้งหมดวางสระบน-ล่างถูกต้อง ต่างจากฟอนต์ละตินที่ทิ้งวรรณยุกต์ */
  .document-page,
  .document-page *,
  .contractor-document-page,
  .contractor-document-page * {
    font-family: 'Kanit', 'Noto Sans Thai', 'Sarabun', 'TH SarabunPSK',
                 'Leelawadee UI', 'Tahoma', sans-serif !important;
  }

  /* 3) แถวรวมหมวดต้องอยู่หน้าเดียวกับหมวดของมัน และห้ามฉีกกลางแถว */
  .document-page tr,
  .doc-category-total-row { break-inside: avoid !important; page-break-inside: avoid !important; }
  .doc-category-total-row { break-before: avoid !important; page-break-before: avoid !important; }
  .document-page thead { display: table-header-group; }
  .document-page tfoot { display: table-footer-group; }

  /* หัวตารางห้ามตัดคำ ไทยไม่มีช่องว่างระหว่างคำ เบราว์เซอร์จึงหั่น
     "ลำดับ" เป็น "ลำ / ดับ" ได้ ซึ่งอ่านแล้วเหมือนพิมพ์ผิด */
  .document-page thead th { white-space: nowrap !important; }
}


/* ── ฟอร์มเบิกและบันทึกค่าใช้จ่าย — จัดแถวให้ตรงกัน ──────────────
   ปัญหาเดิมสองข้อ
   1) ป้ายชื่อยาวไม่เท่ากัน ("หมวดค่าใช้จ่าย / COST CENTER" ตัดสองบรรทัด
      แต่ "วันที่ / DATE" บรรทัดเดียว) พอช่องกรอกวางต่อจากป้ายทันที
      ช่องในแถวเดียวกันจึงอยู่คนละระดับ ดูเป็นฟันปลา
   2) หมายเหตุ "(ระบบคำนวณให้)" ใต้ช่อง VAT เป็นสมาชิกของ grid
      จึงดันความสูงเฉพาะแถวนั้น ระยะห่างระหว่างแถวเลยไม่เท่ากัน

   วิธีแก้: ให้ทุกป้าย+ช่องกรอกดันไปชิดล่างของช่องตาราง
   ช่องกรอกทั้งแถวจึงอยู่ระดับเดียวกันเสมอ ไม่ว่าป้ายจะกี่บรรทัด
   และย้ายหมายเหตุออกจากการไหลของ layout */
#line-view .form-grid.two {
  align-items: stretch;
  row-gap: 22px;
  column-gap: 14px;
}

#line-view .form-grid.two > label {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 6px;
  min-width: 0;
  font-size: 10.5px;
  letter-spacing: 0.06em;
  line-height: 1.45;
}

#line-view .form-grid.two > label > input,
#line-view .form-grid.two > label > select {
  height: 42px;
  box-sizing: border-box;
}

#line-view .form-grid.two > label.is-computed::after {
  position: absolute;
  left: 2px;
  top: 100%;
  margin-top: 3px;
  white-space: nowrap;
  line-height: 1;
}

/* ป้ายที่ยาวเกินสองบรรทัดให้ตัด … แทนที่จะดันแถวสูงขึ้นเรื่อย ๆ */
#line-view .form-grid.two > label > span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ช่องคำอธิบายและบล็อกเต็มความกว้าง ไม่ต้องดันชิดล่าง */
#line-view .form-grid.two > label.full-span { justify-content: flex-start; }
/* Real authentication */
#login-user-cards[hidden], #login-role-row[hidden] { display: none !important; }
.login-auth-message { min-height: 20px; margin: 0; font-size: 12px; color: var(--ink-3); }
.login-auth-message[data-type="error"] { color: #b91c1c; }
.login-auth-message[data-type="success"] { color: #15803d; }
.login-first-admin { margin-top: 8px; border-top: 1px solid var(--line); padding-top: 10px; font-size: 12px; }
.login-first-admin summary { cursor: pointer; color: var(--ink-3); }
.login-first-admin[open] { display: grid; gap: 8px; }
.auth-password-modal { max-width: 440px; }
.auth-password-error { color: #b91c1c; min-height: 18px; margin: 0; font-size: 12px; }
.auth-admin-panel { grid-column: 1 / -1; }
.auth-admin-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.auth-status { display: inline-flex; padding: 3px 7px; border-radius: 4px; font-size: 11px; font-weight: 700; }
.auth-status-ready { color: #166534; background: #dcfce7; }
.auth-status-missing { color: #92400e; background: #fef3c7; }
.auth-status-disabled { color: #991b1b; background: #fee2e2; }
