/* ==========================================================================
   Backoffice shell — light sidebar (like the client's reference), navy accents,
   B78 status sub-menu with count badges. Page overrides: design-system/loan-system/pages/
   ========================================================================== */
.app { display: grid; grid-template-columns: 264px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--surface); border-right: 1px solid var(--silver-300); display: flex; flex-direction: column; z-index: var(--z-drawer); }
.brand { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--silver-300); }
.brand .logo { height: 40px; }
.brand-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.role-box { padding: 12px 16px; border-bottom: 1px solid var(--silver-300); }
.role-box .label { font-size: 11.5px; color: var(--muted); margin-bottom: 6px; display: flex; align-items: center; gap: 6px; }
.role-box .select { min-height: 36px; font-size: 13px; }
.nav { padding: 8px; flex: 1; }
.nav-group { margin-bottom: 6px; }
.nav-title { padding: 10px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.nav a, .nav button.nav-toggle { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 0 10px; border-radius: var(--r-md); color: var(--text); font-size: 14px; font-weight: 500; text-decoration: none; border: 0; background: transparent; text-align: left; cursor: pointer; transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.nav a:hover, .nav button.nav-toggle:hover { background: var(--silver-100); text-decoration: none; }
.nav a .ic, .nav button .ic { color: var(--muted); transition: color var(--t-fast) var(--ease); }
.nav a[aria-current="page"] { background: var(--brand-100); color: var(--brand-700); font-weight: 600; }
.nav a[aria-current="page"] .ic { color: var(--brand-700); }
.nav a .badge, .nav-toggle .badge { margin-left: auto; }
.nav-toggle .chev { margin-left: auto; transition: transform var(--t-base) var(--ease); }
.nav-toggle[aria-expanded="true"] .chev { transform: rotate(180deg); }
.nav-toggle[aria-expanded="true"] { color: var(--brand-700); }
.nav-toggle[aria-expanded="true"] .ic:first-child { color: var(--brand-700); }
/* B78 status sub-menu */
.submenu { display: none; padding: 2px 0 4px 0; margin-left: 14px; border-left: 1px solid var(--silver-300); }
.submenu.is-open { display: block; }
.submenu a { min-height: 36px; padding: 0 10px 0 16px; font-size: 13.5px; font-weight: 400; border-radius: 0 var(--r-md) var(--r-md) 0; position: relative; }
.submenu a[aria-current="page"] { font-weight: 600; }
.submenu a[aria-current="page"]::before { content: ''; position: absolute; left: -1px; top: 6px; bottom: 6px; width: 2px; background: var(--brand-700); border-radius: 0 2px 2px 0; }
.submenu a .badge { min-width: 26px; height: 20px; font-size: 11.5px; }
.submenu a .q { height: 18px; font-size: 10.5px; padding: 0 5px; margin-left: 6px; }
.submenu .submenu-note { padding: 6px 10px 4px 16px; font-size: 11.5px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.submenu-divider { height: 1px; background: var(--silver-300); margin: 4px 0 4px 16px; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid var(--silver-300); font-size: 12px; color: var(--muted); }
.sidebar-foot .quota { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.sidebar-foot .quota-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sidebar-foot .progress { height: 6px; }

/* ---------- main ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: var(--z-sticky); display: flex; align-items: center; gap: 12px; height: 56px; padding: 0 20px; background: rgba(255,255,255,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--silver-300); }
.topbar .spacer { flex: 1; }
.topbar .today { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.menu-btn { display: none; }
.content { padding: 20px 24px 40px; flex: 1; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.page-head .crumbs { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-bottom: 4px; flex-wrap: wrap; }
.page-head .crumbs a { color: var(--muted); }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; max-width: 72ch; }
.meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 20px; padding: 12px 16px; margin-bottom: 16px; background: var(--surface); border: 1px solid var(--silver-300); border-radius: var(--r-lg); font-size: 13.5px; }
.meta dt { font-size: 12px; color: var(--muted); }
.meta dd { margin: 0; font-weight: 500; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.section { margin-bottom: 16px; }
.dash-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-6 { grid-column: span 6; } .span-4 { grid-column: span 4; } .span-3 { grid-column: span 3; }
@media (max-width: 1100px) { .span-8, .span-6, .span-4 { grid-column: span 12; } .span-3 { grid-column: span 6; } }
@media (max-width: 640px) { .span-3 { grid-column: span 12; } }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .kpi-grid { grid-template-columns: 1fr; } }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--silver-300); }
.filters .input, .filters .select { min-height: 36px; width: auto; }
.filters .search { position: relative; }
.filters .search .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.filters .search .input { padding-left: 32px; width: 240px; }

/* ---------- round 5: per-table search built into U.pagedTable / U.pagedList (B88) ---------- */
.table-search { position: relative; display: flex; align-items: center; gap: 6px; }
.table-search .ic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.table-search .input { padding-left: 32px; width: 220px; max-width: 100%; }
.table-search .table-search-clear[hidden] { display: none; }
.status-hero { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-radius: var(--r-lg); border: 1px solid var(--silver-300); background: var(--surface); margin-bottom: 16px; flex-wrap: wrap; }
.status-hero .badge { height: 28px; min-width: 40px; font-size: 14px; }
.status-hero .desc { color: var(--muted); font-size: 13px; flex: 1; min-width: 200px; }
.status-hero .figures { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .detail-grid { grid-template-columns: 1fr; } }
.wizard { display: grid; grid-template-columns: 1fr 360px; gap: 16px; }
@media (max-width: 1100px) { .wizard { grid-template-columns: 1fr; } }
.phone-preview { border: 1px solid var(--silver-300); border-radius: 20px; background: var(--silver-100); padding: 12px; }
.phone-preview .bubble { background: #fff; border-radius: 14px; padding: 10px 12px; font-size: 13px; margin: 8px 0; box-shadow: var(--shadow-sm); max-width: 92%; }
.phone-preview .bubble.me { background: var(--st-closed-bg); margin-left: auto; }
.phone-preview .bubble .btn { margin-top: 8px; }
.calc-box { background: var(--brand-100); color: var(--brand-900); border: 1px solid var(--brand-300); border-radius: var(--r-lg); padding: 16px; }
.calc-box .dl dt { color: var(--muted); }
.calc-box .big { font-family: var(--mono); font-size: 28px; font-weight: 600; color: var(--gold-700); }
.calc-box .divider { background: var(--brand-300); }
.perm-grid th:not(:first-child), .perm-grid td:not(:first-child) { text-align: center; width: 110px; }
.quota-card .big { font-family: var(--mono); font-size: 28px; font-weight: 600; }
.log-row { display: grid; grid-template-columns: 150px 1fr; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--silver-300); font-size: 13.5px; }
.log-row:last-child { border-bottom: 0; }
.log-row .who { display: flex; align-items: center; gap: 8px; }
.log-row .diff { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; margin-top: 6px; font-size: 12.5px; }
.log-row .diff > span:first-child, .log-row .diff > span:last-child { background: var(--silver-100); padding: 4px 8px; border-radius: var(--r-sm); }
.log-row .meta { font-size: 12px; color: var(--muted); margin-top: 4px; display: flex; gap: 12px; flex-wrap: wrap; }
@media (max-width: 640px) { .log-row { grid-template-columns: 1fr; } .log-row .diff { grid-template-columns: 1fr; } }

/* ---------- responsive shell ---------- */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(31,42,24,.45); z-index: calc(var(--z-drawer) - 1); }
@media (max-width: 1023px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 280px; max-width: 86vw; transform: translateX(-100%); transition: transform var(--t-slow) var(--ease); box-shadow: none; }
  .sidebar.is-open { transform: none; box-shadow: var(--shadow-xl); }
  .sidebar-overlay.is-open { display: block; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; }
  .content { padding: 16px 16px 40px; }
  .topbar .today { display: none; }
}
@media (max-width: 480px) {
  .page-head h1 { font-size: 19px; }
  .kpi-value { font-size: 22px; }
}
/* grid children must not expand past their track (tables scroll inside their own card) */
.dash-grid > *, .detail-grid > *, .wizard > *, .kpi-grid > *, .grid > * { min-width: 0; }

/* ---------- round 3: shared pager (§3) ---------- */
.pager { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px; border-top: 1px solid var(--silver-300); background: var(--ground); border-radius: 0 0 var(--r-lg) var(--r-lg); font-size: 12.5px; }
.pager-size { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.pager-size .select { min-height: 30px; width: auto; padding: 4px 8px; }
.pager-range { color: var(--muted); white-space: nowrap; }
.pager-btns { display: flex; align-items: center; gap: 2px; margin-left: auto; flex-wrap: wrap; }
.pager-ellipsis { padding: 0 4px; color: var(--muted); }
.select-sm { min-height: 30px; padding: 4px 8px; font-size: 12.5px; width: auto; }
.table-wrap + .pager { margin-top: -1px; }
.pager.is-fixed .pager-size { display: none; }

/* ---------- round 3: contract detail "ตอนนี้" strip (§2) ---------- */
.now-strip { padding: 14px 16px; }
.now-strip-line { font-size: 14px; }
.now-cells { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px 20px; }
.now-cell { display: flex; flex-direction: column; gap: 2px; }
.now-label { font-size: 12px; color: var(--muted); }
.now-value { font-size: 20px; font-weight: 600; color: var(--brand-900); font-variant-numeric: tabular-nums; }
.now-sub { font-size: 12px; color: var(--muted); }
.now-cell.tone-red .now-value { color: var(--st-red-text); }
.now-cell.tone-gold .now-value { color: var(--gold-700); }
.now-cell.tone-green .now-value { color: var(--brand-700); }
.now-cell.tone-purple .now-value { color: var(--st-purple-text); }
.now-cell.tone-deepred .now-value { color: var(--st-deepred-text); }
.now-progress-text { color: var(--muted); margin-top: 8px; }
.progress-row { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.progress.is-deepred > span { background: var(--st-deepred-text); }

/* ---------- round 3: report drill-down chip bar (§4) ---------- */
.chipbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); padding-bottom: 12px; }
.chipbar .pill { gap: 8px; }
.chip-x { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border: 0; background: transparent; color: inherit; font-size: 14px; line-height: 1; cursor: pointer; padding: 0; border-radius: 50%; }
.chip-x:hover { background: rgba(31,58,18,.16); }

/* ---------- round 3: slip review queue (§5) ---------- */
.queue-grid { display: grid; grid-template-columns: 2fr 3fr; gap: 12px; align-items: start; }
@media (max-width: 1100px) { .queue-grid { grid-template-columns: 1fr; } }
.queue-list { display: flex; flex-direction: column; }
.slip-row { display: flex; flex-direction: column; gap: 4px; padding: 10px 16px; border-bottom: 1px solid var(--silver-300); cursor: pointer; transition: background-color var(--t-fast) var(--ease); }
.slip-row:last-child { border-bottom: 0; }
.slip-row:hover { background: var(--silver-100); }
.slip-row.is-selected { background: var(--brand-100); box-shadow: inset 3px 0 0 var(--brand-700); }
.slip-row-line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.slip-row-line2 { padding-left: 26px; }
.slip-check { display: inline-flex; align-items: center; }
.slip-check input { width: 18px; height: 18px; accent-color: var(--brand-700); cursor: pointer; }
.bulk-bar { display: flex; flex-direction: column; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--silver-300); background: var(--gold-100); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.chip-toggle { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--silver-400); background: var(--surface); color: var(--text); font-size: 12.5px; font-weight: 500; cursor: pointer; transition: background-color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.chip-toggle:hover { background: var(--silver-100); }
.chip-toggle[aria-pressed="true"] { background: var(--brand-100); border-color: var(--brand-500); color: var(--brand-700); }

/* linked refinance contracts */
.refi-chain { margin-top: 12px; }
.refi-chain a, .refi-chain .refi-chain-cur { display: inline-flex; gap: 6px; align-items: baseline; }
.refi-chain .refi-chain-cur { color: var(--brand-900); }
.refi-chain .ic-sm { vertical-align: middle; color: var(--muted); }

/* ---------- round 5: audit log — day-grouped sentence list (§2.4) ---------- */
.audit-day { position: sticky; top: 56px; z-index: 1; padding: 6px 16px; font-size: 12.5px; color: var(--muted); background: var(--ground); }
.audit-row { border-bottom: 1px solid var(--silver-300); }
.audit-row:last-child { border-bottom: 0; }
.audit-main { display: grid; grid-template-columns: 56px 140px 1fr 56px; gap: 8px; align-items: start; width: 100%; min-height: 44px; padding: 10px 16px; font-size: 14px; color: var(--text); background: transparent; border: 0; cursor: pointer; text-align: left; transition: background-color var(--t-fast) var(--ease); }
.audit-main:hover { background: var(--ground); }
.audit-main:focus-visible { outline: none; box-shadow: inset 0 0 0 3px var(--brand-300); }
.audit-main .time { font-size: 13px; color: var(--muted); padding-top: 2px; }
.audit-main .who { padding-top: 1px; }
/* customer timeline (compact): the date matters as much as the clock, so the time cell carries both */
.audit-row-dated .audit-main { grid-template-columns: 104px 140px 1fr 56px; }
.audit-row-dated .audit-main .time { display: flex; flex-direction: column; line-height: 1.35; }
.audit-row-dated .audit-main .time .t { color: var(--silver-500); }
@media (max-width: 720px) { .audit-row-dated .audit-main { grid-template-columns: 82px 1fr 40px; } }
.audit-main .text { display: flex; flex-direction: column; gap: 2px; }
.audit-main .text a { color: var(--brand-700); }
.audit-main .result { font-size: 13px; color: var(--muted); }
.audit-main .tail { display: flex; align-items: center; gap: 6px; justify-content: flex-end; color: var(--brand-500); padding-top: 2px; }
.audit-main .tail .chev { color: var(--muted); transition: transform var(--t-fast) var(--ease); }
.audit-main[aria-expanded="true"] .chev { transform: rotate(180deg); }
.audit-detail { padding: 8px 16px 12px 212px; }
.audit-detail .audit-dl { font-size: 13px; }
.audit-detail .diff { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.audit-detail .diff > span:first-child, .audit-detail .diff > span:last-child { background: var(--silver-100); padding: 4px 8px; border-radius: var(--r-sm); }
@media (max-width: 640px) {
  .audit-main { grid-template-columns: 1fr auto; }
  .audit-main .time { grid-column: 1; }
  .audit-main .who { grid-column: 1; }
  .audit-main .text { grid-column: 1 / -1; }
  .audit-main .tail { grid-column: 2; grid-row: 1; align-self: start; }
  .audit-detail { padding-left: 16px; }
}

/* report breakdown — compact rows (one shared legend, bar only) */
.rb-legend { margin: 4px 0 10px; flex-wrap: wrap; gap: 6px 16px; }
.rb-legend .muted { margin-left: auto; }
th.rb-bar, td.rb-bar { width: 160px; }
td.rb-bar > div { margin-top: 2px; }
td.rb-pct { width: 84px; }
th.rb-go, td.rb-go { width: 28px; text-align: right; color: var(--muted); }
tr.row-link:hover td.rb-go { color: var(--brand-700); }

/* ---------- round 6: contract templates (#/template) ---------- */
.tpl-now { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--silver-300); }
.tpl-now-line { font-size: 14px; }
.tpl-now .now-cells { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.tpl-b91 { font-size: 12.5px; color: var(--muted); }

/* read mode */
.doc-layout { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 16px; align-items: start; }
.doc-rail { position: sticky; top: 72px; max-height: calc(100vh - 88px); overflow: auto; }
.doc-rail .rail-title { padding: 12px 16px 4px; font-size: 12px; font-weight: 600; color: var(--muted); }
.outline { display: flex; flex-direction: column; padding-bottom: 8px; }
.outline button { display: flex; align-items: center; gap: 6px; width: 100%; padding: 6px 14px; border: 0; border-left: 2px solid transparent; background: transparent; color: var(--text); font-size: 13px; line-height: 1.4; text-align: left; cursor: pointer; transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease); }
.outline button:hover { background: var(--ground); }
.outline button.is-current { border-left-color: var(--brand-700); background: var(--brand-100); color: var(--brand-700); font-weight: 600; }
.outline .dot-changed { width: 7px; height: 7px; border-radius: 50%; background: var(--gold-600); flex: 0 0 auto; }
.rail-fields { border-top: 1px solid var(--silver-300); }
.rail-fields summary { list-style: none; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px; font-size: 13px; font-weight: 600; cursor: pointer; }
.rail-fields summary::-webkit-details-marker { display: none; }
.rail-fields summary .chev { margin-left: auto; color: var(--muted); transition: transform var(--t-fast) var(--ease); }
.rail-fields[open] summary .chev { transform: rotate(180deg); }
.rail-fields-body { padding: 0 16px 12px; display: flex; flex-direction: column; gap: 6px; }
.doc-rail-mobile { display: none; margin-bottom: 12px; }
.doc-rail-mobile summary { list-style: none; display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 16px; font-weight: 600; cursor: pointer; }
.doc-rail-mobile summary::-webkit-details-marker { display: none; }
.doc-rail-mobile summary .chev { margin-left: auto; color: var(--muted); }

.doc { max-width: 72ch; padding: 24px 28px 40px; font-size: 15px; line-height: 1.9; color: var(--text); }
.doc p { margin: 0 0 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.doc .doc-title { font-size: 17px; font-weight: 600; text-align: center; color: var(--brand-900); margin: 0 0 20px; }
.doc .doc-h { font-size: 15px; font-weight: 600; color: var(--brand-900); margin: 24px 0 8px; scroll-margin-top: 72px; white-space: pre-wrap; }
.doc .doc-clause { margin-top: 20px; scroll-margin-top: 72px; }
.doc .doc-hn { font-weight: 600; color: var(--brand-900); }
.doc .doc-sub { padding-left: 2.2em; text-indent: -2.2em; }
.doc .doc-sign { margin-top: 28px; }
.doc .doc-sign + .doc-sign { margin-top: 12px; }
.doc p.is-changed { background: var(--gold-100); box-shadow: -4px 0 0 var(--gold-600); margin-left: -12px; padding: 4px 8px 4px 8px; border-radius: 0 var(--r-sm) var(--r-sm) 0; }
.doc-testnote { margin: 12px 16px 0; }
.doc-testnote[hidden] { display: none; } /* .note sets display:flex (author rule beats the UA [hidden] rule) */
.mf { display: inline; padding: 1px 6px; border-radius: var(--r-sm); border: 1px solid var(--brand-300); background: var(--brand-100); color: var(--brand-700); font-size: .93em; font-weight: 500; white-space: nowrap; }
.mf.is-filled { background: var(--gold-100); color: var(--gold-700); border-color: var(--gold-200); }
.mf.is-missing { background: var(--surface); color: var(--muted); border-style: dashed; }
.mf.is-unknown { background: var(--st-red-bg); color: var(--st-red-text); border-color: #E6B5B2; }

/* edit mode */
.edit-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.editor { display: block; width: 100%; font-family: var(--font); font-size: 15px; line-height: 1.8; min-height: 60vh; padding: 20px 24px; border: 0; border-top: 1px solid var(--silver-300); border-radius: 0 0 var(--r-lg) var(--r-lg); resize: none; overflow: hidden; overflow-wrap: anywhere; white-space: pre-wrap; }
.editor:focus { box-shadow: inset 0 0 0 3px rgba(107,143,62,.22); }
.field-drawer { position: sticky; top: 72px; max-height: calc(100vh - 88px); display: flex; flex-direction: column; }
.field-drawer .drawer-tools { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--silver-300); }
.field-drawer .drawer-tools .table-search .input { width: 100%; }
.field-drawer .drawer-body { flex: 1; min-height: 0; overflow: auto; padding: 4px 0; }
.field-group summary { list-style: none; display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; font-size: 13.5px; font-weight: 600; cursor: pointer; }
.field-group summary::-webkit-details-marker { display: none; }
.field-group summary .count { font-size: 12px; font-weight: 400; color: var(--muted); }
.field-group summary .chev { margin-left: auto; color: var(--muted); transition: transform var(--t-fast) var(--ease); }
.field-group[open] summary .chev { transform: rotate(180deg); }
.field-row { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 36px; padding: 0 12px 0 34px; border: 0; background: transparent; color: var(--text); font-size: 13.5px; text-align: left; cursor: pointer; transition: background-color var(--t-fast) var(--ease); }
.field-row:hover { background: var(--brand-100); }
.field-row .ic { margin-left: -22px; color: var(--brand-700); }
.field-row.is-used { color: var(--brand-700); }
.field-row .tag { margin-left: auto; height: 20px; font-size: 11.5px; }
.field-row[hidden], .field-group[hidden] { display: none; }
.drawer-body .empty[hidden] { display: none; } /* .empty sets display:flex — same [hidden]-vs-author-rule issue as .doc-testnote */
.insert-bar { display: none; }

/* ---------- round 7: Tiptap rich-text toolbar + surface — the body is HTML now (Part 1), so the
   toolbar's job is real: everything below actually survives a save. .editor stays in the DOM only
   as a hidden holder for the current HTML string — it is never shown to a user (Part 2 fallback). */
.editor[hidden] { display: none; } /* .editor sets display:block — same [hidden]-vs-author-rule issue as .doc-testnote */
[data-rich-fallback][hidden], [data-rich-loading][hidden] { display: none; } /* .note sets display:flex — same issue */
[data-rich-fallback] { flex-direction: column; align-items: flex-start; gap: 8px; }
.editor-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 8px 12px; border-top: 1px solid var(--silver-300); background: var(--ground); position: sticky; top: 72px; z-index: var(--z-sticky); }
.editor-toolbar[hidden] { display: none; }
.et-group { display: flex; align-items: center; gap: 2px; position: relative; }
.et-sep { width: 1px; align-self: stretch; margin: 4px 2px; background: var(--silver-300); flex: 0 0 auto; }
.et-btn { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; padding: 0; border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: var(--muted); cursor: pointer; transition: background-color var(--t-fast) var(--ease), color var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease); }
.et-btn:hover { background: var(--silver-100); color: var(--text); }
.et-btn[aria-pressed="true"] { background: var(--brand-100); border-color: var(--brand-300); color: var(--brand-700); }
.et-btn:disabled { opacity: .4; cursor: not-allowed; }
.et-btn-label { width: auto; padding: 0 10px; gap: 6px; }
.et-btn-label span { font-size: 13px; font-weight: 500; }
.et-btn-label .chev { color: var(--muted); }
.editor-toolbar .select { min-height: 32px; height: 32px; font-size: 13px; width: auto; padding: 0 28px 0 10px; }
/* dropdown menus (table ops, overflow "เพิ่มเติม") — one open at a time, closed on outside click */
.et-dropdown { position: absolute; top: calc(100% + 4px); left: 0; min-width: 210px; background: var(--surface); border: 1px solid var(--silver-300); border-radius: var(--r-md); box-shadow: var(--shadow-md); padding: 6px; z-index: var(--z-drawer); display: flex; flex-direction: column; gap: 2px; }
.et-dropdown[hidden] { display: none; }
.et-dd-item { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 34px; padding: 0 10px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--text); font-size: 13.5px; text-align: left; cursor: pointer; white-space: nowrap; }
.et-dd-item:hover { background: var(--brand-100); }
.et-dd-item:disabled { opacity: .4; cursor: not-allowed; background: none; }
.et-dd-item.is-danger { color: var(--st-red-text); }
.et-dd-sep { height: 1px; background: var(--silver-300); margin: 4px 2px; }
.et-dd-label { display: flex; align-items: center; gap: 6px; padding: 6px 10px 0; font-size: 12px; color: var(--muted); }
.et-swatches { display: flex; gap: 6px; padding: 4px 10px 6px; }
.sw { width: 20px; height: 20px; border-radius: 50%; border: 1px solid var(--silver-300); cursor: pointer; padding: 0; transition: transform var(--t-fast) var(--ease); }
.sw:hover { transform: scale(1.15); }
.sw-none { background: var(--surface); background-image: linear-gradient(45deg, transparent 46%, var(--st-red-text) 46%, var(--st-red-text) 54%, transparent 54%); }
/* find & replace bar — a small always-available tool, not a Tiptap extension (see task report) */
.editor-findbar { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 8px 12px; border-top: 1px solid var(--silver-300); background: var(--gold-100); }
.editor-findbar[hidden] { display: none; }
.editor-findbar .input-sm { height: 30px; font-size: 13px; padding: 0 8px; width: 170px; }
.findbar-sep { width: 1px; align-self: stretch; background: var(--gold-200, var(--silver-300)); margin: 0 4px; }
.findbar-count { min-width: 76px; }
/* character count footer — Fira Code, matches every other figure in the app */
.editor-footer { padding: 8px 24px; border-top: 1px solid var(--silver-300); text-align: right; font-size: 12px; font-family: var(--mono); color: var(--muted); }
.editor-footer[hidden] { display: none; }
.tiptap-doc { position: relative; min-height: 60vh; cursor: text; border-top: 1px solid var(--silver-300); }
/* drag handle — sits in the left gutter of the writing surface, follows the block under the cursor */
.tpl-drag { position: absolute; left: 4px; display: flex; align-items: center; justify-content: center; width: 22px; height: 26px; padding: 0; color: var(--silver-500); background: transparent; border: 0; border-radius: 6px; cursor: grab; transition: color var(--t-fast) var(--ease), background-color var(--t-fast) var(--ease); }
.tpl-drag:hover { color: var(--brand-700); background: var(--brand-100); }
.tpl-drag:active { cursor: grabbing; }
.tpl-drag:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--brand-300); }
.tiptap-doc .ProseMirror .is-dragging { opacity: .45; }
@media (max-width: 1099px) { .tpl-drag { display: none; } }
.tiptap-doc[hidden] { display: none; }
.tiptap-doc:focus-within { box-shadow: inset 0 0 0 3px rgba(107,143,62,.22); }
#tpl-fallback-doc[hidden] { display: none; }
.tiptap-doc .ProseMirror { outline: none; }
.tiptap-doc .ProseMirror p, .tiptap-doc .ProseMirror h1, .tiptap-doc .ProseMirror h2, .tiptap-doc .ProseMirror h3 { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 12px; }
.tiptap-doc .ProseMirror h1 { font-size: 17px; font-weight: 600; color: var(--brand-900); text-align: center; margin: 0 0 20px; }
.tiptap-doc .ProseMirror h2 { font-size: 15px; font-weight: 600; color: var(--brand-900); margin: 24px 0 8px; }
.tiptap-doc .ProseMirror h3 { font-size: 14px; font-weight: 600; color: var(--brand-900); margin: 18px 0 6px; }
.tiptap-doc .ProseMirror ul, .tiptap-doc .ProseMirror ol { margin: 0 0 12px; padding-left: 1.6em; }
.tiptap-doc .ProseMirror li { margin: 0 0 4px; white-space: pre-wrap; }
.tiptap-doc .ProseMirror li p { margin: 0; }
.tiptap-doc .ProseMirror p.is-editor-empty:first-child::before { content: attr(data-placeholder); float: left; height: 0; pointer-events: none; color: var(--silver-500); }
.tiptap-doc .ProseMirror .mf { cursor: default; }
.tiptap-doc .ProseMirror .mf.ProseMirror-selectednode { outline: 2px solid var(--brand-700); outline-offset: 1px; border-radius: var(--r-sm); }
.tiptap-doc .ProseMirror a, .doc a { color: var(--brand-700); text-decoration: underline; text-underline-offset: 2px; }
/* tables — read view (.doc table, the debt letter's instalment list) and the live editor share one
   look; Tiptap's own table CSS is skipped entirely (never loaded) so there is no default grey/blue
   to override — this is the only table styling that exists. */
.doc table, .tiptap-doc .ProseMirror table { border-collapse: collapse; table-layout: fixed; width: 100%; margin: 16px 0; font-size: .95em; }
.doc th, .doc td, .tiptap-doc .ProseMirror th, .tiptap-doc .ProseMirror td { border: 1px solid var(--silver-300); padding: 8px 10px; text-align: left; vertical-align: top; }
.doc th, .tiptap-doc .ProseMirror th { background: var(--brand-100); color: var(--brand-900); font-weight: 600; }
.doc td > *:last-child, .doc th > *:last-child, .tiptap-doc .ProseMirror td > *:last-child, .tiptap-doc .ProseMirror th > *:last-child { margin-bottom: 0; }
.tiptap-doc .ProseMirror .selectedCell { background: var(--gold-100); }
.tiptap-doc .ProseMirror .column-resize-handle { position: absolute; right: -2px; top: 0; bottom: -2px; width: 4px; background: var(--brand-500); pointer-events: none; }
.tiptap-doc .ProseMirror.resize-cursor { cursor: col-resize; }
/* page break — a visible marker while editing; @media print maps it to an actual PDF page break
   (chromedp's Page.printToPDF respects this exactly the way a browser's own print-to-PDF does). */
.doc-pagebreak { height: 26px; margin: 20px 0; border-top: 1px dashed var(--silver-500); border-bottom: 1px dashed var(--silver-500); display: flex; align-items: center; justify-content: center; }
.doc-pagebreak::after { content: 'ตัดขึ้นหน้าใหม่'; background: var(--ground); padding: 0 10px; font-size: 11px; color: var(--muted); }
.tiptap-doc .ProseMirror .doc-pagebreak.ProseMirror-selectednode { outline: 2px solid var(--brand-700); outline-offset: 2px; }
@media print {
  .doc-pagebreak { break-before: page; page-break-before: always; border: 0; height: 0; margin: 0; }
  .doc-pagebreak::after { content: none; }
}

@media (max-width: 1099px) {
  .doc-layout, .edit-layout { grid-template-columns: 1fr; }
  .doc-rail { display: none; }
  .doc-rail-mobile { display: block; }
  .field-drawer { display: none; }
  .insert-bar { display: block; position: sticky; bottom: 12px; padding: 8px 12px 12px; background: var(--surface); border-radius: 0 0 var(--r-lg) var(--r-lg); }
}
@media (max-width: 640px) {
  .doc { padding: 16px; }
  .doc .doc-sub { padding-left: 1.4em; text-indent: -1.4em; }
  .doc p.is-changed { margin-left: -8px; }
  .editor { padding: 16px; }
  .et-btn-label span { display: none; } /* icon-only on phones — labels reflow into too many rows otherwise */
  .editor-findbar .input-sm { width: 120px; }
}

/* ---------- ตรวจรูปยืนยันตัวตนก่อนอนุมัติ ---------- */
.idcheck .idphoto-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 720px) { .idcheck .idphoto-grid { grid-template-columns: 1fr; } }
.idphoto { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.idphoto-box { aspect-ratio: 4 / 3; border-radius: var(--r-md); border: 1px solid var(--silver-300);
  background: var(--silver-100); color: var(--silver-500); display: flex; align-items: center; justify-content: center; }
.idphoto figcaption { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; font-size: 13px; }


/* ---------- group C: สาขา (ตัวเลือกสาขาที่แถบด้านบน) + หน้าสาขา / ร้านค้าพันธมิตร ---------- */
.branch-switch { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); min-width: 0; }
.branch-switch .select { width: auto; max-width: 240px; min-height: 32px; padding-right: 30px; background-position: right 8px center; color: var(--text); text-overflow: ellipsis; }
.branch-chip { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; max-width: 240px; min-width: 0; padding: 0 10px; border-radius: 999px; border: 1px solid var(--silver-300); background: var(--silver-100); color: var(--text); font-size: 12.5px; white-space: nowrap; }
.branch-chip .ic { flex: 0 0 auto; color: var(--muted); }
.topbar-me { min-width: 0; flex: 0 0 auto; }
@media (max-width: 1023px) { .topbar { gap: 8px; } }
@media (max-width: 480px) {
  .topbar-me-text { display: none; }            /* avatar alone — the name/role is in the sidebar role box */
  .branch-switch > .ic { display: none; }
  .branch-switch .select { max-width: 170px; }
  .branch-chip { max-width: 170px; }
}
.branch-cell-addr { max-width: 260px; }
.acct-line { display: flex; flex-direction: column; gap: 2px; }
