canvas {
    width: 100% !important;
    height: 100% !important;
}

:root {
    --apple-thai-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Sukhumvit Set", "Thonburi", "Helvetica Neue", "Noto Sans Thai", "Segoe UI", sans-serif;
    --pastel-blue: #bde7ff;
    --pastel-mint: #c8f7dc;
    --pastel-pink: #ffd6e8;
    --pastel-lavender: #ded8ff;
    --pastel-cream: #fff3c7;
    --text-ink: #172033;
    --text-soft: #6b7890;
    --card-border: rgba(255, 255, 255, 0.88);
    --cute-shadow: 0 18px 48px rgba(83, 118, 161, 0.12);
    --cute-shadow-soft: 0 10px 28px rgba(91, 123, 155, 0.10);
}

html {
    font-family: var(--apple-thai-font);
}

body {
    font-family: var(--apple-thai-font);
    background:
        radial-gradient(circle at 9% 9%, rgba(189, 231, 255, 0.76), transparent 24rem),
        radial-gradient(circle at 78% 6%, rgba(255, 214, 232, 0.72), transparent 26rem),
        radial-gradient(circle at 88% 76%, rgba(200, 247, 220, 0.60), transparent 28rem),
        linear-gradient(135deg, #fbfdff 0%, #f6fbff 38%, #fff8fc 72%, #fffdf3 100%);
    letter-spacing: -0.012em;
    font-feature-settings: "kern";
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(circle at 16% 18%, rgba(147, 197, 253, 0.18), transparent 18rem),
        radial-gradient(circle at 78% 10%, rgba(244, 114, 182, 0.14), transparent 20rem),
        radial-gradient(circle at 84% 72%, rgba(52, 211, 153, 0.14), transparent 22rem);
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: 0.24;
    background-image:
        radial-gradient(circle, rgba(37, 99, 235, 0.16) 1px, transparent 1px),
        radial-gradient(circle, rgba(236, 72, 153, 0.13) 1px, transparent 1px);
    background-position: 0 0, 18px 18px;
    background-size: 36px 36px;
}

h1,
h2,
h3 {
    color: var(--text-ink);
    letter-spacing: -0.04em;
}

main {
    background: transparent;
}

main h1,
main h2,
main h3 {
    color: var(--text-ink);
    font-weight: 900;
}

main p {
    line-height: 1.65;
}

main > div > section,
main > div > article {
    border-color: var(--card-border);
    background: rgba(255, 255, 255, 0.88);
    box-shadow: var(--cute-shadow);
    backdrop-filter: blur(18px);
}

main > div > section[class*="grid"],
main > div > section[class*="flex"] {
    background: transparent;
    border-color: transparent;
    box-shadow: none;
}

main > div > section[class*="grid"] > article {
    min-height: 132px;
    border: 1px solid rgba(255, 255, 255, 0.92);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.82)) !important;
    box-shadow: var(--cute-shadow-soft);
    backdrop-filter: blur(16px);
}

main > div > section[class*="grid"] > article:hover,
main > div > article:hover {
    transform: translateY(-1px);
}

main > div > section[class*="grid"] > article:nth-child(4n + 1) {
    border-top: 5px solid var(--pastel-blue);
}

main > div > section[class*="grid"] > article:nth-child(4n + 2) {
    border-top: 5px solid var(--pastel-pink);
}

main > div > section[class*="grid"] > article:nth-child(4n + 3) {
    border-top: 5px solid var(--pastel-mint);
}

main > div > section[class*="grid"] > article:nth-child(4n) {
    border-top: 5px solid var(--pastel-cream);
}

main > div > section[class*="grid"] > div {
    min-height: 132px;
}

input:not([type="checkbox"]):not([type="radio"]),
select,
textarea {
    border-color: rgba(191, 219, 254, 0.88) !important;
    border-radius: 1.1rem !important;
    background-color: rgba(255, 255, 255, 0.92) !important;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.95), 0 8px 20px rgba(148, 163, 184, 0.08);
    color: var(--text-ink) !important;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #8bcaff !important;
    box-shadow: 0 0 0 4px rgba(189, 231, 255, 0.72), 0 10px 22px rgba(96, 165, 250, 0.10) !important;
}

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

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

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

table thead tr {
    background: linear-gradient(90deg, #eff9ff, #fff2f8, #f2fff8) !important;
    color: #55708c !important;
}

.approval-table {
    min-width: 980px;
}

.approval-col-no { width: 12%; }
.approval-col-type { width: 9%; }
.approval-col-user { width: 12%; }
.approval-col-dept { width: 9%; }
.approval-col-items { width: 34%; }
.approval-col-date { width: 10%; }
.approval-col-actions { width: 14%; }

.approval-table th,
.approval-table td {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.approval-items-cell {
    line-height: 1.45;
}

tbody tr:hover {
    background-color: rgba(239, 249, 255, 0.82) !important;
}

a[class*="bg-blue-600"],
button[class*="bg-blue-600"] {
    background: linear-gradient(135deg, #74c0fc, #8b9cff) !important;
    box-shadow: 0 14px 28px rgba(116, 192, 252, 0.24) !important;
}

a[class*="bg-blue-600"]:hover,
button[class*="bg-blue-600"]:hover {
    background: linear-gradient(135deg, #60a5fa, #7c8df5) !important;
}

a[class*="bg-green-600"],
button[class*="bg-green-600"] {
    background: linear-gradient(135deg, #7be6ad, #4fd1c5) !important;
    color: #ffffff !important;
}

a[class*="bg-red-600"],
button[class*="bg-red-600"] {
    background: linear-gradient(135deg, #ff9ab3, #fb7185) !important;
}

a[class*="rounded"],
button[class*="rounded"] {
    transition: transform 180ms ease, box-shadow 180ms ease, background 180ms ease, border-color 180ms ease;
}

a[class*="rounded"]:hover,
button[class*="rounded"]:hover {
    transform: translateY(-1px);
}

.rounded-2xl,
.rounded-3xl {
    overflow: hidden;
}

.pastel-section-label {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 999px;
    background: linear-gradient(135deg, rgba(239, 249, 255, 0.96), rgba(255, 242, 248, 0.96));
    padding: 0.42rem 0.82rem;
    color: #4f7df3;
    font-size: 0.75rem;
    font-weight: 900;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    box-shadow: inset 0 0 0 1px rgba(191, 219, 254, 0.62), 0 8px 18px rgba(148, 163, 184, 0.10);
}

.pastel-section-label::before {
    content: "";
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 999px;
    background: linear-gradient(135deg, #74c0fc, #f9a8d4);
    box-shadow: 0 0 0 4px rgba(191, 219, 254, 0.35);
}

.document-barcode {
    display: block;
    width: 100%;
    height: 46px;
}

.withdrawal-slip {
    color: #111827;
}

.withdrawal-slip .slip-top-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.65fr 1.15fr;
    gap: 1rem;
    align-items: start;
}

.withdrawal-slip .slip-title-block {
    text-align: center;
}

.withdrawal-slip .slip-title-block h2 {
    margin: 0.2rem 0 0;
    font-size: 2rem;
    font-weight: 900;
    letter-spacing: -0.04em;
}

.withdrawal-slip .slip-title-block p {
    margin-top: 0.25rem;
    font-size: 0.82rem;
    font-weight: 800;
    color: #475569;
}

.withdrawal-slip .slip-logo {
    display: none !important;
    width: 42px !important;
    height: 42px !important;
    max-width: 42px !important;
    max-height: 42px !important;
    object-fit: contain;
    margin: 0 auto;
}

.withdrawal-slip .slip-field,
.withdrawal-slip .slip-date-row {
    display: grid;
    grid-template-columns: 96px 1fr;
    align-items: end;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    font-size: 0.92rem;
}

.slip-field strong,
.slip-date-row strong {
    display: block;
    min-height: 1.55rem;
    border-bottom: 1px solid #475569;
    padding: 0 0.4rem 0.1rem;
    font-size: 1rem;
    font-weight: 800;
}

.slip-form-code {
    margin-bottom: 0.35rem;
    text-align: right;
    font-weight: 900;
    color: #0f172a;
}

.slip-barcode-box {
    margin-top: 0.35rem;
}

.slip-barcode-text {
    margin-top: 0.1rem;
    text-align: center;
    font-size: 0.82rem;
    letter-spacing: 0.2em;
    white-space: nowrap;
    color: #111827;
}

.slip-bom-note {
    margin-top: 0.75rem;
    border: 1px solid #cbd5e1;
    padding: 0.45rem 0.65rem;
    font-size: 0.82rem;
}

.withdrawal-form-table {
    border-collapse: collapse;
    table-layout: fixed;
}

.withdrawal-form-table th,
.withdrawal-form-table td {
    border: 1.5px solid #1f2937;
    padding: 0.42rem 0.5rem;
    vertical-align: middle;
    line-height: 1.25;
    word-break: break-word;
}

.withdrawal-form-table th {
    background: #f8fafc;
    text-align: center;
    font-weight: 900;
}

.slip-non-stock {
    display: block;
    font-size: 0.65rem;
    font-weight: 800;
    color: #2563eb;
}

.withdrawal-signature-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2rem;
    margin: 3rem auto 0;
    max-width: 760px;
    text-align: center;
}

.withdrawal-signature {
    min-height: 4.2rem;
}

.signature-name {
    min-height: 1.35rem;
    font-size: 0.82rem;
    font-weight: 700;
}

.signature-line {
    margin: 0.2rem auto 0.35rem;
    width: 78%;
    border-top: 1.5px solid #111827;
}

.withdrawal-signature strong {
    font-weight: 800;
}

.withdrawal-effective-date {
    margin-top: 2.2rem;
    text-align: right;
    font-weight: 800;
    color: #1f2937;
}

* {
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

@media (max-width: 640px) {
    html,
    body {
        max-width: 100%;
        overflow-x: hidden;
    }

    body {
        background:
            radial-gradient(circle at 6% 4%, rgba(189, 231, 255, 0.62), transparent 16rem),
            radial-gradient(circle at 92% 8%, rgba(255, 214, 232, 0.55), transparent 16rem),
            linear-gradient(145deg, #fbfdff 0%, #f7fbff 48%, #fff8fc 100%);
    }

    #appSidebar {
        width: min(86vw, 250px);
    }

    #sidebarOverlay {
        backdrop-filter: blur(2px);
    }

    header > div {
        min-height: 4.4rem !important;
        gap: 0.7rem !important;
        padding: 0.75rem !important;
    }

    header .flex.items-center.gap-4 {
        min-width: 0;
        gap: 0.75rem !important;
    }

    header h2 {
        max-width: 48vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 1.06rem !important;
        line-height: 1.2;
    }

    header .text-sm {
        font-size: 0.75rem;
    }

    header .rounded-2xl {
        border-radius: 1rem !important;
    }

    main > div {
        padding: 0.9rem 0.75rem 1.35rem !important;
    }

    main > div > section,
    main > div > article {
        border-radius: 1.35rem !important;
        padding: 1rem !important;
    }

    main > div > section[class*="grid"] > article,
    main > div > section[class*="grid"] > div {
        min-height: auto;
    }

    h1,
    main h1 {
        font-size: 1.65rem !important;
        line-height: 1.15 !important;
    }

    h2,
    main h2 {
        font-size: 1.28rem !important;
        line-height: 1.2 !important;
    }

    .pastel-section-label {
        max-width: 100%;
        white-space: normal;
        letter-spacing: 0.1em;
    }

    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea {
        min-height: 3rem;
        font-size: 1rem !important;
    }

    .overflow-x-auto {
        overflow-x: visible !important;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) {
        width: 100% !important;
        min-width: 0 !important;
        border-collapse: separate !important;
        border-spacing: 0 !important;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) thead {
        display: none !important;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) tbody {
        display: grid;
        gap: 0.75rem;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) tbody tr {
        display: block;
        overflow: hidden;
        border: 1px solid rgba(226, 232, 240, 0.92);
        border-radius: 1.15rem;
        background: rgba(255, 255, 255, 0.95);
        box-shadow: var(--cute-shadow-soft);
        padding: 0.45rem 0.7rem;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) tbody tr:hover {
        background: rgba(255, 255, 255, 0.98) !important;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) tbody td {
        display: grid;
        grid-template-columns: minmax(6.8rem, 42%) minmax(0, 1fr);
        gap: 0.75rem;
        align-items: start;
        border: 0 !important;
        border-bottom: 1px solid rgba(226, 232, 240, 0.78) !important;
        padding: 0.6rem 0.05rem !important;
        text-align: left !important;
        white-space: normal !important;
        word-break: break-word;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) tbody td:last-child {
        border-bottom: 0 !important;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) tbody td::before {
        content: attr(data-label);
        color: #64748b;
        font-size: 0.72rem;
        font-weight: 900;
        line-height: 1.35;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) tbody td[colspan] {
        display: block;
        text-align: center !important;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) tbody td[colspan]::before {
        display: none;
    }

    table:not(.print-only-table):not(.print-items-table):not(.withdrawal-form-table) tbody td .flex {
        flex-wrap: wrap;
    }

    .approval-table {
        min-width: 0;
    }

    .withdrawal-slip .slip-top-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .withdrawal-slip .slip-title-block {
        order: -1;
    }

    .withdrawal-signature-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.25rem;
    }

    .document-barcode {
        height: 38px;
    }
}

@media print {
    @page {
        size: A4 portrait;
        margin: 10mm;
    }

    body {
        background: #ffffff !important;
        color: #111827 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body::before,
    aside,
    header,
    .print-hidden,
    #sidebarOverlay {
        display: none !important;
    }

    main {
        margin: 0 !important;
        width: 100% !important;
    }

    main > div {
        padding: 0 !important;
    }

    .print-page {
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: #ffffff !important;
        padding: 0 !important;
    }

    .print-card {
        border: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        background: #ffffff !important;
        padding: 4mm !important;
        width: 190mm !important;
        max-width: 190mm !important;
        margin: 0 auto !important;
    }

    table thead tr {
        background: #f1f5f9 !important;
    }

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

    .print-only-table th,
    .print-only-table td {
        border: 1px solid #cbd5e1 !important;
        padding: 5px 7px !important;
        vertical-align: top !important;
        word-break: break-word !important;
        font-size: 11px !important;
    }

    .print-document-no {
        white-space: nowrap !important;
        font-size: 15px !important;
        letter-spacing: -0.02em !important;
    }

    .document-barcode {
        width: 100% !important;
        height: 13mm !important;
        max-height: 13mm !important;
    }

    .print-items-table thead {
        display: table-header-group !important;
    }

    .print-items-table tfoot {
        display: table-row-group !important;
    }

    .print-items-table tr {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .slip-top-grid {
        grid-template-columns: 1.2fr 0.65fr 1.15fr !important;
        gap: 6mm !important;
        align-items: start !important;
    }

    .slip-title-block h2 {
        font-size: 26px !important;
        line-height: 1.05 !important;
    }

    .slip-title-block p,
    .slip-logo {
        display: none !important;
    }

    .slip-field,
    .slip-date-row {
        grid-template-columns: 19mm 1fr !important;
        gap: 3mm !important;
        margin-bottom: 1mm !important;
        font-size: 12px !important;
    }

    .slip-field strong,
    .slip-date-row strong {
        min-height: 5mm !important;
        padding: 0 1.5mm 0.5mm !important;
        font-size: 12px !important;
        line-height: 1.2 !important;
    }

    .slip-form-code {
        margin: 0 0 1mm !important;
        font-size: 12px !important;
    }

    .slip-barcode-box {
        margin-top: 1mm !important;
    }

    .slip-barcode-box .document-barcode {
        height: 16mm !important;
        max-height: 16mm !important;
    }

    .slip-barcode-text {
        font-size: 9px !important;
        letter-spacing: 0.2em !important;
        white-space: nowrap !important;
        line-height: 1 !important;
    }

    .slip-bom-note {
        margin-top: 3mm !important;
        padding: 1.5mm 2mm !important;
        font-size: 10px !important;
        border-color: #1f2937 !important;
    }

    .withdrawal-form-table {
        width: 100% !important;
        min-width: 0 !important;
        border-collapse: collapse !important;
        table-layout: fixed !important;
        font-size: 11px !important;
    }

    .withdrawal-form-table th,
    .withdrawal-form-table td {
        border: 1.3px solid #111827 !important;
        padding: 3px 5px !important;
        font-size: 11px !important;
        line-height: 1.18 !important;
    }

    .withdrawal-form-table th {
        background: #ffffff !important;
        color: #111827 !important;
        font-size: 11px !important;
    }

    .slip-non-stock {
        font-size: 8px !important;
        line-height: 1 !important;
    }

    .withdrawal-signature-grid {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 12mm !important;
        margin-top: 14mm !important;
        max-width: 150mm !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .withdrawal-signature {
        min-height: 16mm !important;
    }

    .signature-name {
        min-height: 5mm !important;
        font-size: 10px !important;
    }

    .signature-line {
        width: 100% !important;
        margin: 1mm auto 1.5mm !important;
        border-top: 1px solid #111827 !important;
    }

    .withdrawal-signature strong {
        font-size: 11px !important;
    }

    .withdrawal-effective-date {
        margin-top: 9mm !important;
        padding-right: 14mm !important;
        font-size: 11px !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .print-signature-grid {
        display: grid !important;
        grid-template-columns: repeat(4, 1fr) !important;
        gap: 8px !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .print-signature-box {
        min-height: 22mm !important;
        border: 1px solid #cbd5e1 !important;
        border-radius: 0 !important;
        padding: 8px !important;
    }
}
