:root {
    color-scheme: light;
    --paper: #f4f5f6;
    --surface: #ffffff;
    --surface-soft: #f8f9f9;
    --ink: #172322;
    --muted: #66706f;
    --line: #dfe3e2;
    --brand: #2f6f5e;
    --brand-deep: #1f4d42;
    --accent: #9a5b24;
    --danger: #9d2f2f;
    --focus-ring: rgba(47, 111, 94, 0.28);
    --radius-card: 14px;
    --radius-control: 10px;
    --jai-brown: #8f4f3e;
    --jai-brown-dark: #704032;
    --jai-brown-soft: #f3ebe8;
    --jai-border: #d9cfca;
    --jai-document-text: #343434;
    --jai-document-muted: #777;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Noto Sans Thai", "Leelawadee UI", Tahoma, Arial, sans-serif;
    background: var(--paper);
    color: var(--ink);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

.app-body {
    background: var(--paper);
}

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

.sidebar {
    border-right: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    padding: 16px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
}

.mobile-menu-scrim,
.sidebar-mobile-header,
.sidebar-account,
.mobile-menu-button {
    display: none;
}

.icon-button,
.mobile-menu-button {
    width: 44px;
    height: 44px;
    min-height: 44px;
    display: inline-grid;
    place-items: center;
    border-radius: 50%;
    padding: 0;
    background: transparent;
    color: var(--ink);
    border-color: transparent;
}

.icon-button svg,
.mobile-menu-button svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2.2;
}

.icon-button:hover,
.mobile-menu-button:hover {
    background: #eef4f1;
    color: var(--brand-deep);
}

.mobile-menu-button {
    display: none;
}

.brand-mark {
    display: grid;
    gap: 2px;
    color: var(--ink);
    text-decoration: none;
    padding: 8px 10px 16px;
    border-bottom: 1px solid var(--line);
}

.brand-logo {
    display: block;
    width: 88px;
    height: 88px;
    border-radius: 16px;
    object-fit: contain;
}

.brand-mark strong {
    margin-top: 6px;
    font-size: 17px;
}

.main-nav {
    display: grid;
    gap: 6px;
    margin-top: 18px;
}

.nav-link,
.nav-group summary,
.nav-child {
    display: flex;
    min-height: 44px;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    text-decoration: none;
    border-radius: var(--radius-control);
    padding: 10px 12px;
    font-weight: 650;
    transition: background-color 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.nav-link span,
.nav-group summary span,
.nav-child span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-link:hover,
.nav-group summary:hover,
.nav-child:hover,
.nav-link.active,
.nav-child.active {
    background: #e8f1ed;
    color: var(--brand-deep);
}

.nav-link.active {
    box-shadow: inset 3px 0 0 var(--brand);
}

.nav-group {
    border-radius: var(--radius-control);
}

.nav-group.active {
    background: #f2f7f4;
    box-shadow: inset 3px 0 0 var(--brand);
}

.nav-group summary {
    cursor: pointer;
    list-style: none;
}

.nav-group summary::-webkit-details-marker {
    display: none;
}

.nav-group[open] summary {
    color: var(--brand-deep);
}

.nav-icon {
    width: 19px;
    height: 19px;
    flex: 0 0 19px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}

.nav-chevron {
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    margin-left: auto;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2.2;
    transition: transform 160ms ease;
}

.nav-group[open] .nav-chevron {
    transform: rotate(180deg);
}

.nav-children {
    display: grid;
    gap: 4px;
    padding: 2px 6px 8px 14px;
}

.nav-child {
    min-height: 38px;
    border-radius: 8px;
    padding: 8px 10px;
    color: #41504d;
    font-size: 14px;
    font-weight: 650;
}

.nav-child .nav-icon {
    width: 17px;
    height: 17px;
    flex-basis: 17px;
    color: var(--muted);
}

.nav-child.active {
    background: #dfeee8;
    color: var(--brand-deep);
    box-shadow: inset 3px 0 0 var(--brand);
}

.nav-child.active .nav-icon,
.nav-child:hover .nav-icon {
    color: var(--brand-deep);
}

.workspace {
    min-width: 0;
}

.topbar {
    min-height: 68px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.86);
    padding: 12px 24px;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(18px) saturate(140%);
    -webkit-backdrop-filter: blur(18px) saturate(140%);
}

.topbar span,
.user-strip small {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.topbar strong {
    display: block;
    color: var(--ink);
    font-size: 18px;
}

.user-strip {
    display: flex;
    align-items: center;
    gap: 12px;
    text-align: right;
}

.profile-shortcut {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--ink);
    text-decoration: none;
    text-align: right;
}

.profile-shortcut:hover strong {
    color: var(--brand-deep);
}

.profile-shortcut-text strong,
.profile-shortcut-text small {
    display: block;
}

.avatar {
    display: inline-grid;
    flex: 0 0 auto;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #e8f1ed;
    color: var(--brand-deep);
    object-fit: cover;
    font-weight: 850;
    text-transform: uppercase;
}

.avatar-small {
    width: 40px;
    height: 40px;
    font-size: 13px;
}

.avatar-table {
    width: 42px;
    height: 42px;
    font-size: 13px;
}

.avatar-large {
    width: 104px;
    height: 104px;
    font-size: 30px;
}

.workspace-content {
    width: min(1120px, 100%);
    padding: 28px 24px 48px;
}

.page-header {
    margin-bottom: 22px;
}

.page-header h1 {
    font-size: clamp(28px, 4vw, 42px);
}

.metric-grid,
.quick-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin: 22px 0;
}

.metric-grid article,
.quick-actions a,
.panel-section,
.admin-band {
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(35, 43, 40, 0.05);
}

.metric-grid article {
    padding: 18px;
}

.metric-grid span,
.quick-actions span,
.admin-band span {
    display: block;
    color: var(--accent);
    font-size: 13px;
    font-weight: 800;
    margin-bottom: 8px;
}

.metric-grid strong {
    display: block;
    font-size: 34px;
    color: var(--brand-deep);
}

.metric-grid p,
.quick-actions p,
.admin-band p,
.empty-state p {
    margin: 8px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.quick-actions a {
    padding: 18px;
    color: var(--ink);
    text-decoration: none;
}

.quick-actions a:hover {
    border-color: var(--brand);
}

.quick-actions strong,
.admin-band strong,
.empty-state strong {
    display: block;
    font-size: 18px;
    color: var(--ink);
}

.admin-band {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px;
    margin-top: 22px;
}

.panel-section {
    padding: 28px;
}

.empty-state {
    width: min(560px, 100%);
}

.form-panel,
.table-panel {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-card);
    background: var(--surface);
    box-shadow: 0 8px 24px rgba(35, 43, 40, 0.05);
    padding: 20px;
    margin: 18px 0;
}

.form-panel h2,
.table-panel h2 {
    margin: 0;
    font-size: 22px;
}

.section-title {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.section-title p {
    margin: 6px 0 0;
    color: var(--muted);
    line-height: 1.6;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-top: 16px;
}

.form-grid.compact {
    align-items: end;
}

.form-grid label {
    display: grid;
    gap: 7px;
}

.form-grid label span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: #fff;
    color: var(--ink);
    font: inherit;
    padding: 11px 12px;
}

input:not([type="checkbox"]):not([type="radio"]),
select {
    min-height: 44px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand);
    outline: 3px solid var(--focus-ring);
    outline-offset: 1px;
}

textarea {
    resize: vertical;
}

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

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

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.button-link.secondary {
    background: transparent;
    color: var(--brand-deep);
    border-color: var(--line);
}

.button-link.secondary:hover {
    background: #eaf2ee;
}

.responsive-table {
    min-width: 0;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.document-list-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
}

.document-list-actions,
.filter-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.document-filter-grid {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) repeat(4, minmax(140px, 1fr)) auto;
    gap: 12px;
    align-items: end;
}

.document-filter-grid label {
    display: grid;
    gap: 7px;
}

.document-filter-grid label > span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.document-list-table small {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    line-height: 1.4;
}

.document-list-table .money-cell {
    white-space: nowrap;
}

.compact-button {
    display: inline-block;
    padding: 7px 10px;
    white-space: nowrap;
}

.document-empty-state {
    padding: 28px 0 10px;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

.text-link {
    color: var(--brand-deep);
    font-weight: 800;
    text-decoration: none;
}

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

.status-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 5px 9px;
    background: #edf0ee;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.status-pill.active,
.status-pill.available {
    background: #e4f4ea;
    color: #1d6840;
}

.status-pill.inactive {
    background: #eeeeee;
    color: #5f6664;
}

.status-pill.reserved {
    background: #fff3dc;
    color: #8a5614;
}

.settings-layout {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(300px, 0.9fr);
    gap: 18px;
    align-items: start;
}

.settings-layout > .form-panel,
.settings-layout > .table-panel {
    margin: 0;
}

.settings-section-gap {
    margin-top: 24px;
}

.settings-rule {
    border: 1px solid #d8e7df;
    border-radius: var(--radius-control);
    background: #f3faf6;
    margin-top: 18px;
    padding: 14px;
}

.settings-rule strong,
.switch-row strong {
    display: block;
    color: var(--ink);
}

.settings-rule p {
    margin: 4px 0 0;
    color: var(--muted);
}

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

.switch-row {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 10px;
    align-items: start;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--surface-soft);
    padding: 13px;
}

.switch-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-top: 3px;
    accent-color: var(--brand);
}

.switch-row small {
    display: block;
    margin-top: 3px;
    color: var(--muted);
}

.settings-number-control {
    display: grid;
    gap: 7px;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--surface-soft);
    padding: 13px;
}

.settings-number-control span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.settings-actions {
    margin-top: 18px;
}

.document-header-preview {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: #fff;
    padding: 14px;
}

.document-header-preview img {
    width: 72px;
    height: 72px;
    object-fit: contain;
}

.document-header-preview strong {
    display: block;
    color: var(--brand-deep);
    font-size: 18px;
}

.document-header-preview p {
    margin: 4px 0 0;
    color: var(--ink);
    line-height: 1.45;
}

.settings-facts {
    display: grid;
    gap: 10px;
    margin: 14px 0 0;
}

.settings-facts div {
    border-bottom: 1px solid var(--line);
    padding-bottom: 10px;
}

.settings-facts div:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.settings-facts dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.settings-facts dd {
    margin: 3px 0 0;
    color: var(--ink);
}

.status-pill.sold {
    background: #f4e4e4;
    color: var(--danger);
}

.status-pill.used {
    background: #e4edf4;
    color: #245a85;
}

.status-pill.revoked,
.status-pill.expired {
    background: #f4e4e4;
    color: var(--danger);
}

.status-pill.pending {
    background: #fff3dc;
    color: #8a5614;
}

.status-pill.draft {
    background: #fff3dc;
    color: #8a5614;
}

.status-pill.approved {
    background: #e4f4ea;
    color: #1d6840;
}

.status-pill.rejected,
.status-pill.withdrawn {
    background: #f4e4e4;
    color: var(--danger);
}

.status-pill.issued {
    background: #e4f4ea;
    color: #1d6840;
}

.status-pill.cancelled,
.status-pill.void {
    background: #f4e4e4;
    color: var(--danger);
}

.copy-panel {
    border: 1px solid #bfe4cd;
    border-radius: 8px;
    background: #e9f7ee;
    color: #1d6840;
    padding: 16px;
    margin: 18px 0;
    overflow-wrap: anywhere;
}

.copy-panel span {
    display: block;
    font-size: 13px;
    font-weight: 800;
    margin-bottom: 8px;
}

.copy-panel strong {
    display: block;
    font-size: 16px;
}

.copy-panel p {
    margin: 8px 0 0;
}

.invite-form {
    margin-top: 24px;
}

.form-panel > .db-detail,
.invite-form + .db-detail {
    margin: 16px 0 0;
}

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

.inline-form select {
    min-width: 130px;
}

.profile-layout {
    display: grid;
    grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.5fr);
    gap: 18px;
    align-items: start;
}

.profile-layout > .form-panel {
    margin-top: 0;
}

.profile-gate-message {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border: 1px solid #efd39f;
    border-radius: var(--radius-card);
    background: #fff7e8;
    color: #805018;
    padding: 16px 18px;
    margin: 0 0 18px;
}

.profile-gate-message p {
    margin: 0;
}

.profile-avatar-block {
    display: flex;
    align-items: center;
    gap: 18px;
}

.profile-avatar-block h2,
.profile-avatar-block p {
    margin: 0 0 6px;
}

.profile-avatar-block p {
    color: var(--muted);
}

.avatar-form {
    display: grid;
    gap: 10px;
    margin-top: 22px;
}

.avatar-form label,
.status-action-form label {
    display: grid;
    gap: 7px;
}

.avatar-form label span,
.status-action-form label span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.profile-delete-avatar-form {
    margin-top: 12px;
}

.danger-text {
    color: var(--danger);
}

.document-name-preview {
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--surface-soft);
    padding: 14px;
}

.document-name-preview span,
.document-name-preview strong {
    display: block;
}

.document-name-preview span {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 4px;
}

.document-name-preview strong {
    color: var(--brand-deep);
    font-size: 18px;
}

.confirmation-field {
    display: flex !important;
    grid-template-columns: auto 1fr;
    align-items: flex-start;
}

.confirmation-field input {
    width: auto;
    margin-top: 4px;
}

.user-cell {
    display: flex;
    align-items: center;
    min-width: 190px;
    gap: 10px;
}

.user-cell strong,
.user-cell small {
    display: block;
}

.user-cell small {
    color: var(--muted);
    margin-top: 2px;
}

.user-detail-hero {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) minmax(360px, 1.1fr);
    gap: 24px;
    align-items: center;
}

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

.user-facts div {
    border: 1px solid var(--line);
    border-radius: var(--radius-control);
    background: var(--surface-soft);
    padding: 12px;
}

.user-facts dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.user-facts dd {
    margin: 4px 0 0;
    font-weight: 750;
}

.admin-user-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.admin-user-grid > .form-panel {
    margin: 0;
}

.admin-user-grid > .form-panel:first-child {
    grid-column: 1 / -1;
}

.account-status-panel > p {
    color: var(--muted);
}

.status-action-form {
    display: grid;
    gap: 12px;
}

.document-form {
    display: grid;
    gap: 0;
    min-width: 0;
}

.document-form [hidden] {
    display: none !important;
}

.form-hint {
    margin: 0.75rem 0 0;
    color: var(--muted-text, #64748b);
    font-size: 0.9rem;
}

.amount-summary-table th {
    text-align: left;
}

.amount-summary-table td {
    text-align: right;
}

.items-table input {
    min-width: 140px;
}

.sticky-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 253, 249, 0.96);
    padding: 14px;
    margin-top: 18px;
    box-shadow: 0 -10px 28px rgba(35, 43, 40, 0.08);
}

.sticky-actions > * {
    flex: 0 1 auto;
}

.quotation-form .sticky-actions button[name="document_action"][value="issue"] {
    display: none;
}

.sticky-actions .secondary-button {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--brand-deep);
}

.document-page {
    position: relative;
    width: min(210mm, 100%);
    min-height: 297mm;
    overflow: hidden;
    margin: 0 auto;
    padding: 12mm 14mm 10mm;
    border: 1px solid var(--jai-border);
    border-radius: 4px;
    background: #fff;
    box-shadow: 0 18px 45px rgba(38, 29, 25, 0.12);
    color: var(--jai-document-text);
    font-family: "Sarabun", "Noto Sans Thai", Tahoma, sans-serif;
    font-size: 13px;
    line-height: 1.45;
}

.document-brand-watermark,
.document-status-watermark {
    position: absolute;
    inset: 45% auto auto 50%;
    z-index: 0;
    transform: translate(-50%, -50%) rotate(-18deg);
    pointer-events: none;
}

.document-brand-watermark {
    width: 72%;
    opacity: 0.055;
}

.document-brand-watermark img {
    display: block;
    width: 100%;
    height: auto;
}

.document-status-watermark {
    inset: 53% auto auto 50%;
    color: rgba(157, 47, 47, 0.13);
    font-size: clamp(100px, 18vw, 175px);
    font-weight: 900;
    letter-spacing: 0.08em;
    white-space: nowrap;
}

.document-page.is-cancelled .document-brand-watermark {
    opacity: 0.035;
}

.document-content {
    position: relative;
    z-index: 1;
}

.a4-document-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 76mm;
    gap: 8mm;
    align-items: start;
    padding-bottom: 5mm;
    border-bottom: 1.5px solid var(--jai-brown);
}

.document-identity {
    display: grid;
    grid-template-columns: 18mm minmax(0, 1fr);
    gap: 4mm;
    align-items: start;
}

.document-symbol {
    width: 18mm;
    height: 18mm;
    overflow: hidden;
    border-radius: 3mm;
}

.document-symbol img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.document-identity h2 {
    margin: 0 0 2mm;
    color: var(--jai-brown-dark);
    font-size: 20px;
    line-height: 1.25;
}

.document-identity p {
    margin: 1mm 0;
    color: var(--jai-document-muted);
    font-size: 11px;
    line-height: 1.35;
}

.document-title-card {
    overflow: hidden;
    border: 1px solid var(--jai-brown);
    border-radius: 6px;
}

.document-title {
    padding: 3mm 2mm;
    background: var(--jai-brown);
    color: #fff;
    text-align: center;
    font-size: 20px;
    font-weight: 800;
    line-height: 1.25;
}

.document-copy-badge {
    padding: 1.5mm 2mm;
    background: var(--jai-brown-soft);
    color: var(--jai-brown-dark);
    text-align: center;
    font-weight: 800;
}

.document-meta-list {
    display: grid;
    gap: 1.2mm;
    margin: 0;
    padding: 2.5mm 3mm;
}

.document-meta-list div,
.payment-card dl div {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 3mm;
}

.document-meta-list dt,
.payment-card dt {
    color: var(--jai-document-muted);
}

.document-meta-list dd,
.payment-card dd {
    margin: 0;
    text-align: right;
    overflow-wrap: anywhere;
}

.document-section {
    margin-top: 4mm;
}

.a4-section-title {
    margin: 0 0 2mm;
    padding-bottom: 1.2mm;
    border-bottom: 1.5px solid var(--jai-brown);
    color: var(--jai-brown);
    font-size: 15px;
    line-height: 1.3;
}

.a4-info-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-top: 1px solid var(--jai-border);
    border-left: 1px solid var(--jai-border);
}

.a4-info-grid > div {
    min-height: 13mm;
    padding: 2mm 2.5mm;
    border-right: 1px solid var(--jai-border);
    border-bottom: 1px solid var(--jai-border);
}

.a4-info-grid > div.wide {
    grid-column: span 2;
}

.a4-info-grid span,
.cancellation-reference span {
    display: block;
    margin-bottom: 1mm;
    color: var(--jai-document-muted);
    font-size: 10px;
}

.a4-info-grid strong,
.cancellation-reference strong {
    font-size: 12px;
    line-height: 1.35;
}

.a4-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.a4-table th,
.a4-table td {
    padding: 2mm 2.2mm;
    border: 1px solid var(--jai-border);
    vertical-align: top;
}

.a4-table th {
    background: var(--jai-brown-soft);
    color: var(--jai-brown-dark);
    font-weight: 800;
}

.detail-table .sequence-column {
    width: 13mm;
}

.detail-table .quantity-column {
    width: 18mm;
}

.detail-table .money-column {
    width: 30mm;
    text-align: right;
}

.a4-table .center {
    text-align: center;
}

.a4-table .money-cell {
    text-align: right;
    white-space: nowrap;
}

.key-value-table th {
    width: 43mm;
}

.cancellation-reference {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 2mm;
    margin-bottom: 2mm;
}

.cancellation-reference > div {
    padding: 2mm;
    border: 1px solid var(--jai-border);
    background: #fff;
}

.document-financial-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 78mm;
    gap: 4mm;
    align-items: stretch;
    margin-top: 4mm;
}

.payment-card,
.total-card {
    border: 1px solid var(--jai-border);
    background: rgba(255, 255, 255, 0.92);
}

.payment-card {
    padding: 3mm;
}

.payment-card h3 {
    margin: 0 0 2mm;
    color: var(--jai-brown);
    font-size: 14px;
}

.payment-card dl {
    display: grid;
    gap: 1.2mm;
    margin: 0;
    font-size: 11px;
}

.total-card {
    margin: 0;
    width: auto;
}

.total-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 3mm;
    padding: 2.2mm 3mm;
    border-bottom: 1px solid var(--jai-border);
}

.total-row:last-child {
    border-bottom: 0;
}

.total-row strong {
    text-align: right;
    white-space: nowrap;
}

.total-row.highlight {
    background: var(--jai-brown);
    color: #fff;
}

.amount-in-words {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 4mm;
    margin: 3mm 0 0;
    padding: 2mm 3mm;
    border: 1px solid var(--jai-border);
    background: var(--jai-brown-soft);
}

.amount-in-words span {
    color: var(--jai-brown-dark);
}

.note-section p {
    margin: 1.5mm 0;
}

.writing-lines {
    margin: 1.5mm 0 0;
    padding-left: 6mm;
    color: var(--jai-document-muted);
    line-height: 1.7;
}

.document-disclaimer {
    margin: 3mm 0 0;
    padding: 2mm 3mm;
    border-left: 3px solid var(--jai-brown-soft);
    color: var(--jai-document-muted);
    font-size: 10px;
}

.a4-signature-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8mm;
    margin-top: 5mm;
}

.a4-signature-grid.three-columns {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4mm;
}

.signature-box {
    min-height: 28mm;
    display: grid;
    align-content: end;
    gap: 2mm;
    padding: 3mm;
    border: 1px solid var(--jai-border);
    border-radius: 5px;
    text-align: center;
}

.signature-box span {
    margin-bottom: 5mm;
    color: var(--jai-brown-dark);
    font-weight: 800;
}

.signature-box small {
    color: var(--jai-document-muted);
}

.document-footer {
    display: flex;
    justify-content: space-between;
    gap: 4mm;
    margin-top: 4mm;
    padding-top: 2mm;
    border-top: 1px solid var(--jai-border);
    color: var(--jai-document-muted);
    font-size: 9px;
}

.avoid-break {
    break-inside: avoid;
    page-break-inside: avoid;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.status-panel {
    width: min(760px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: clamp(24px, 5vw, 44px);
    box-shadow: 0 18px 48px rgba(35, 43, 40, 0.08);
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--brand);
    font-size: 14px;
    font-weight: 700;
}

h1 {
    margin: 0;
    font-size: clamp(32px, 6vw, 48px);
    line-height: 1.1;
}

.lead {
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 17px;
    line-height: 1.7;
}

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

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

.status-grid span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 6px;
}

.status-grid strong {
    display: block;
    color: var(--brand-deep);
    font-size: 16px;
}

.db-detail {
    margin: -8px 0 22px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.6;
}

.demo-form {
    margin: 0 0 24px;
}

.demo-form button {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    background: #eef5f1;
    color: var(--brand-deep);
    font: inherit;
    font-weight: 700;
}

.notice {
    margin: 20px 0 0;
    border-radius: 8px;
    padding: 12px 14px;
    font-weight: 700;
}

.notice.success {
    background: #e9f7ee;
    color: #1d6840;
    border: 1px solid #bfe4cd;
}

.notice.error {
    background: #fff0f0;
    color: #9d2f2f;
    border: 1px solid #f1c2c2;
}

.notice.warning {
    background: #fff7e8;
    color: #805018;
    border: 1px solid #efd39f;
}

.login-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 28px 0 18px;
}

.login-card {
    display: grid;
    gap: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    background: #fbfaf7;
}

.login-card span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.login-card strong {
    color: var(--brand-deep);
    font-size: 18px;
}

.auth-panel {
    max-width: 680px;
}

.line-login-action {
    display: grid;
    gap: 10px;
    margin: 28px 0 18px;
    text-align: center;
}

.line-login-action p,
.mock-login-panel > p {
    margin: 0;
    color: var(--muted);
}

.line-login-button {
    border-color: #06c755;
    background: #06c755;
    color: #fff;
    font-weight: 800;
}

.line-login-button:hover {
    border-color: #05a847;
    background: #05a847;
}

.mock-login-panel {
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.mock-login-panel summary {
    color: var(--brand-deep);
    font-weight: 800;
    cursor: pointer;
}

button,
.button-link {
    border: 1px solid var(--brand-deep);
    border-radius: var(--radius-control);
    min-height: 44px;
    padding: 10px 14px;
    background: var(--brand);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    text-align: center;
    transition: background-color 160ms ease, border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.button-ghost {
    background: transparent;
    color: var(--brand-deep);
    border-color: var(--line);
    padding: 9px 12px;
}

.button-ghost:hover {
    background: #eaf2ee;
    color: var(--brand-deep);
}

button:hover,
.button-link:hover {
    background: var(--brand-deep);
}

button:active,
.button-link:active {
    transform: translateY(1px);
}

button:focus-visible,
.button-link:focus-visible,
a:focus-visible,
summary:focus-visible {
    outline: 3px solid var(--focus-ring);
    outline-offset: 2px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.52;
}

button.danger,
.button-link.danger {
    border-color: var(--danger);
    background: var(--danger);
}

button.danger:hover,
.button-link.danger:hover {
    background: #762222;
}

.calculated-value {
    display: grid;
    align-content: center;
    gap: 7px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    padding: 11px 12px;
}

.calculated-value span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.reference-panel {
    margin-bottom: 18px;
}

.attachment-panel {
    margin: 20px 0;
}

.attachment-grid {
    display: grid;
    grid-template-columns: minmax(180px, 300px) 1fr;
    gap: 20px;
    align-items: start;
    margin-bottom: 20px;
}

.attachment-preview {
    display: block;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    overflow: hidden;
}

.attachment-preview img {
    display: block;
    width: 100%;
    max-height: 360px;
    object-fit: contain;
}

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

.attachment-details span {
    color: var(--muted);
}

.attachment-upload-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: end;
    border-top: 1px solid var(--line);
    padding-top: 18px;
}

.attachment-upload-form label {
    display: grid;
    gap: 7px;
}

.attachment-upload-form label span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.signature-grid.three-columns {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
}

.next-steps {
    margin: 0;
    padding-left: 22px;
    color: var(--ink);
    line-height: 1.8;
}

@media screen and (max-width: 640px) {
    .status-grid {
        grid-template-columns: 1fr;
    }

    .login-grid {
        grid-template-columns: 1fr;
    }

}

@media screen and (max-width: 860px) {
    .app-layout {
        grid-template-columns: 1fr;
        width: 100%;
        min-width: 0;
        overflow-x: clip;
    }

    .sidebar {
        position: fixed;
        inset: auto 0 0 0;
        z-index: 40;
        width: 100%;
        min-width: 0;
        height: auto;
        max-height: min(82vh, 720px);
        overflow-y: auto;
        border-right: 0;
        border-bottom: 0;
        border-top: 1px solid rgba(223, 227, 226, 0.9);
        border-radius: 20px 20px 0 0;
        padding: 10px 12px max(16px, env(safe-area-inset-bottom));
        box-shadow: 0 -22px 55px rgba(23, 35, 34, 0.22);
        transform: translateY(calc(100% + 24px));
        transition: transform 220ms ease;
        overscroll-behavior: contain;
    }

    .mobile-menu-open {
        overflow: hidden;
    }

    .mobile-menu-open .sidebar {
        transform: translateY(0);
    }

    .mobile-menu-scrim {
        position: fixed;
        inset: 0;
        z-index: 35;
        display: block;
        width: 100%;
        height: 100%;
        min-height: 0;
        padding: 0;
        border: 0;
        border-radius: 0;
        background: rgba(10, 20, 18, 0.22);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }

    .mobile-menu-open .mobile-menu-scrim {
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-mobile-header {
        display: flex;
        min-height: 50px;
        align-items: center;
        justify-content: space-between;
        padding: 2px 2px 8px 10px;
    }

    .sidebar-mobile-header span {
        color: var(--ink);
        font-size: 17px;
        font-weight: 850;
    }

    .brand-mark {
        display: flex;
        min-height: 52px;
        align-items: center;
        gap: 10px;
        padding: 6px 8px 10px;
    }

    .brand-logo {
        width: 48px;
        height: 48px;
        flex: 0 0 48px;
        border-radius: 10px;
    }

    .brand-mark strong {
        margin: 0;
    }

    .main-nav {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
        min-width: 0;
        gap: 8px;
        overflow: visible;
        padding-bottom: 10px;
    }

    .nav-group {
        grid-column: 1 / -1;
    }

    .nav-link,
    .nav-group summary,
    .nav-child {
        white-space: normal;
    }

    .nav-children {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding: 4px 6px 8px;
    }

    .topbar,
    .user-strip,
    .admin-band {
        align-items: flex-start;
        flex-direction: column;
        text-align: left;
    }

    .profile-shortcut {
        text-align: left;
    }

    .topbar {
        min-height: 62px;
        display: grid;
        grid-template-columns: 44px minmax(0, 1fr) auto;
        align-items: center;
        gap: 10px;
        padding: max(8px, env(safe-area-inset-top)) 12px 8px;
    }

    .mobile-menu-button {
        display: inline-grid;
    }

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

    .topbar-title span,
    .topbar-title strong {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar-title strong {
        font-size: 17px;
    }

    .user-strip {
        flex-direction: row;
        align-items: center;
        gap: 0;
        text-align: left;
    }

    .topbar .profile-shortcut {
        width: 44px;
        height: 44px;
        justify-content: center;
        border-radius: 50%;
    }

    .topbar .profile-shortcut-text,
    .topbar .user-strip form {
        display: none;
    }

    .topbar .avatar-small {
        width: 38px;
        height: 38px;
    }

    .sidebar-account {
        display: grid;
        gap: 12px;
        border-top: 1px solid var(--line);
        padding: 14px 4px 0;
        margin-top: 6px;
    }

    .sidebar-account .profile-shortcut {
        min-height: 56px;
        border-radius: var(--radius-control);
        padding: 8px;
        text-align: left;
    }

    .sidebar-account .profile-shortcut:hover {
        background: #eef4f1;
    }

    .sidebar-account .button-ghost {
        width: 100%;
    }

    .workspace-content {
        padding: 22px 16px calc(34px + env(safe-area-inset-bottom));
    }

    .document-list-header,
    .document-list-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .document-filter-grid {
        grid-template-columns: 1fr;
    }

    .metric-grid,
    .quick-actions {
        grid-template-columns: 1fr;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .span-2,
    .span-3 {
        grid-column: 1;
    }

    .form-actions,
    .inline-form {
        align-items: stretch;
        flex-direction: column;
    }

    .sticky-actions {
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .sticky-actions > * {
        width: 100%;
    }

    .document-list-actions > * {
        width: 100%;
    }

    .signature-grid,
    .signature-grid.three-columns {
        grid-template-columns: 1fr;
    }

    .attachment-grid,
    .attachment-upload-form {
        grid-template-columns: 1fr;
    }

    .profile-layout,
    .user-detail-hero,
    .admin-user-grid,
    .settings-layout {
        grid-template-columns: 1fr;
    }

    .settings-switch-grid {
        grid-template-columns: 1fr;
    }

    .admin-user-grid > .form-panel:first-child {
        grid-column: 1;
    }

    .profile-gate-message,
    .profile-avatar-block {
        align-items: flex-start;
        flex-direction: column;
    }

    .user-facts {
        grid-template-columns: 1fr;
    }

}

@media screen and (max-width: 640px) {
    .main-nav,
    .nav-children {
        grid-template-columns: 1fr;
    }

    .document-results .responsive-table {
        overflow-x: visible;
    }

    .document-list-table,
    .document-list-table thead,
    .document-list-table tbody,
    .document-list-table tr,
    .document-list-table td {
        display: block;
        width: 100%;
    }

    .document-list-table thead {
        display: none;
    }

    .document-list-table tr {
        border: 1px solid var(--line);
        border-radius: var(--radius-control);
        background: var(--surface);
        padding: 12px;
        margin-bottom: 10px;
    }

    .document-list-table td {
        border-bottom: 0;
        padding: 7px 0;
    }

    .document-list-table td::before {
        display: block;
        margin-bottom: 2px;
        color: var(--muted);
        font-size: 12px;
        font-weight: 800;
    }

    .document-list-table td:nth-child(1)::before {
        content: "เลขที่ / วันที่";
    }

    .document-list-table td:nth-child(2)::before {
        content: "ประเภท";
    }

    .document-list-table td:nth-child(3)::before {
        content: "ลูกค้า / แปลง";
    }

    .document-list-table td:nth-child(4)::before {
        content: "โครงการ";
    }

    .document-list-table td:nth-child(5)::before {
        content: "ยอดเงิน";
    }

    .document-list-table td:nth-child(6)::before {
        content: "สถานะ";
    }

    .document-list-table .money-cell {
        white-space: normal;
    }

    .document-list-table .compact-button {
        width: 100%;
        margin-top: 4px;
    }
}
