/* css/style.css */

:root {
    --sidebar-width: 260px;
    --sidebar-width-collapsed: 80px;
}

body {
    font-family: 'Kanit', sans-serif;
    background-color: #f8f9fa;
    transition: padding-left 0.3s ease;
    padding-left: var(--sidebar-width);
}

/* --- Layout & Sidebar --- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: var(--sidebar-width);
    background-color: #212529;
    color: white;
    padding: 1rem;
    transition: width 0.3s ease;
    overflow-x: hidden;
    z-index: 1050;
}

.main-header {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    right: 0;
    height: 60px;
    background-color: #ffffff;
    border-bottom: 1px solid #dee2e6;
    display: flex;
    align-items: center;
    padding: 0 1rem;
    transition: left 0.3s ease;
    z-index: 1000;
}

.content-wrapper {
    margin-top: 60px;
    padding: 1.5rem;
}

body.sidebar-collapsed {
    padding-left: var(--sidebar-width-collapsed);
}

body.sidebar-collapsed .sidebar {
    width: var(--sidebar-width-collapsed);
}

body.sidebar-collapsed .main-header {
    left: var(--sidebar-width-collapsed);
}

body.sidebar-collapsed .sidebar .nav-link span,
body.sidebar-collapsed .sidebar .sidebar-brand-text {
    display: none;
}

/* --- Sidebar Navigation --- */
.sidebar .nav-link {
    color: #adb5bd;
    display: flex;
    align-items: center;
    padding: 0.75rem 0.5rem;
    border-radius: 0.375rem;
    white-space: nowrap;
}

.sidebar .nav-link:hover {
    color: #fff;
    background-color: #343a40;
}

.sidebar .nav-link.active {
    color: #fff;
    background-color: #0d6efd;
}

.sidebar .nav-link i {
    font-size: 1.5rem;
    width: 50px;
    text-align: center;
}

/* --- Timesheet Table Styles --- */
.timesheet-container {
    overflow-x: auto;
    max-height: 75vh;
}

.timesheet-table {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
}

.timesheet-table th,
.timesheet-table td {
    border-top: 1px solid #adb5bd;
    border-left: 1px solid #adb5bd;
    padding: 0.5rem;
    white-space: nowrap;
    vertical-align: middle;
    text-align: center;
    font-size: 0.9rem;
}

.timesheet-table th:last-child,
.timesheet-table td:last-child {
    border-right: 1px solid #adb5bd;
}
.timesheet-table tbody tr:last-child td {
    border-bottom: 1px solid #adb5bd;
}


/* Thead Styles */
.timesheet-table thead th {
    background-color: #e9ecef;
    position: sticky;
    top: 0;
    z-index: 2;
}

.timesheet-table thead tr:nth-child(2) th {
    top: 39px;
}

.timesheet-table thead tr:nth-child(3) th {
    top: 77px;
}

.timesheet-table thead tr:nth-child(2) .col-date-group:nth-child(even) {
    background-color: #dde0e3; 
}

/* --- Sticky Columns Styles --- */
.sticky-col {
    position: sticky;
    background-color: #f8f9fa;
}

th.sticky-col {
    background-color: #e9ecef;
}

.sticky-col.col-seq  { left: 0px;   z-index: 4; }
.sticky-col.col-id   { left: 0px;   z-index: 5; }
.sticky-col.col-rate { left: 0px;   z-index: 6; }
.sticky-col.col-name { left: 0px;   z-index: 7; }

th.sticky-col.col-seq { z-index: 8; }
th.sticky-col.col-id  { z-index: 9; }
th.sticky-col.col-rate{ z-index: 10;}
th.sticky-col.col-name{ z-index: 11;}


/* Column Widths */
.col-seq { min-width: 20px; }
.col-id { min-width: 20px; }
.col-rate { min-width: 20px; }
.col-name { min-width: 150px; max-width: 150px; overflow: hidden; text-align: left !important; }
.col-work, .col-ot { min-width: 10px; font-size: 14px; }
.col-summary { min-width: 20px; font-weight: bold; }

/* Use Monospaced Font for numbers */
.col-id, .col-rate, .col-work, .col-ot, .col-summary, .col-date-group {
    font-family: 'Roboto Mono', monospace;
}

/* Cell Data Styles */
.text-full { color: #0a3622; font-weight: bold; }
.text-half { color: #664d03; font-weight: normal; }
.editable-cell {
    cursor: pointer;
    position: relative;
}
.editable-cell:hover {
    box-shadow: inset 0 0 0 2px #0d6efd;
}

.col-summary.bg-primary { background-color: #cfe2ff !important; }
.col-summary.bg-warning { background-color: #fff3cd !important; }
.col-summary.bg-success-subtle { background-color: #d1e7dd !important; }

/* --- Cutoff & Project Colors Page --- */
#form-message { min-height: 58px; }
.cutoff-row { cursor: pointer; }
.cutoff-row:hover, .cutoff-row.table-active { background-color: #e9ecef; }


/* --- Summary Cards on Cutoff Page (Updated) --- */
.summary-card {
    border: 1px solid #e3e6f0;
    border-radius: 0.35rem;
    color: white;
    position: relative;
    padding: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    box-shadow: 0 .15rem 1.75rem 0 rgba(58,59,69,.15)!important;
}
.summary-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 .5rem 1.75rem 0 rgba(58,59,69,.25)!important;
}
.summary-card .text-xs {
    font-size: 1.1rem;
    font-weight: 400;
    opacity: 0.9;
}
.summary-card .h5 {
    font-weight: 400;
    font-size: 1.5rem;
}
.summary-card .fw-bold {
    font-weight: 400 !important;
}
.summary-card i {
    font-size: 2.5rem;
    opacity: 0.5;
}


/* --- SweetAlert2 & Select2 Fix --- */
.swal2-container {
    z-index: 10001 !important;
}

.select2-container--open {
    z-index: 10002 !important;
}

/* ++ ADDED: Styling for upload progress bar in Swal ++ */
#swal-upload-progress .progress-bar {
    color: #fff;
    font-weight: 500;
}


/* --- Fullscreen Mode Styles --- */
body.fullscreen-mode .sidebar,
body.fullscreen-mode .main-header {
    display: none;
}

body.fullscreen-mode {
    padding-left: 0 !important;
}

body.fullscreen-mode .main-content {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    padding: 0;
    margin: 0;
    overflow: auto;
    z-index: 9999;
    background-color: #ffffff;
}

body.fullscreen-mode .content-wrapper {
    margin-top: 0;
    padding: 1rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

body.fullscreen-mode .card {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    border: none;
    border-radius: 0;
}

body.fullscreen-mode .card-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

body.fullscreen-mode .timesheet-container {
    flex-grow: 1;
    max-height: none;
}

/* ++ REVISED: Vertical Payslip Styles ++ */
.payslip-vertical {
    border: 1px solid #999;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    position: relative;
    font-size: 9pt;
    line-height: 1.4;
    background: #fff;
    page-break-inside: avoid;
    display: flex;
    flex-direction: column;
}
/* ++ ADDED: Set minimum height for short slips for consistent alignment ++ */
.print-page-short .payslip-vertical {
    min-height: 90mm; /* Approximately half the height of an A4 landscape page, minus gap */
}
.payslip-vertical-header {
    padding: 4px 6px;
    border-bottom: 1px solid #333;
    text-align: center;
}
.payslip-vertical-header .company-details {
    font-weight: bold;
    font-size: 10pt;
}
.payslip-vertical-header p {
    margin: 0;
    font-size: 7.5pt;
}
/* ++ แก้ไข: ลบเส้นคั่นและระยะห่างออก ++ */
.payslip-vertical-header .worker-details-new {
    width: 100%;
    font-size: 8.5pt;
}

.payslip-vertical-header .worker-details-new span {
    display: block;
    text-align: center;
}

.payslip-vertical-body {
    padding: 4px 6px;
    flex-grow: 1; 
}
.payslip-vertical .payslip-table {
    width: 100%;
    margin-bottom: 5px;
    border-collapse: collapse;
}
.payslip-vertical .payslip-table thead th {
    font-weight: bold;
    text-align: left;
    background-color: #f7f7f7;
    padding: 3px;
    border-bottom: 1px solid #ccc;
}
.payslip-vertical .payslip-table tbody td {
    padding: 2px 3px;
}
.payslip-vertical .deduction-subtitle {
    padding-top: 4px !important;
    border-bottom: 1px dotted #ccc;
    font-size: 8pt;
    color: #555;
}
.payslip-vertical .deduction-amount-cell {
    display: flex;
    justify-content: flex-end;
    align-items: baseline;
    white-space: nowrap;
}
.payslip-vertical .remaining-balance {
    font-size: 7.5pt;
    margin-left: 4px;
}
.payslip-vertical .withdrawal-table {
    margin-top: 5px;
}
.payslip-vertical .withdrawal-table thead th {
    background-color: #fff3cd;
    color: #664d03;
}
.payslip-vertical .withdrawal-table td:first-child {
    color: #664d03;
}
.payslip-vertical .withdrawal-table td.text-end {
    font-weight: bold;
    color: #664d03;
}
.payslip-vertical .advance-balance-table {
    margin-top: 5px;
    border-top: 1px solid #999;
}
.payslip-vertical .advance-balance-table td {
    padding-top: 4px;
    font-weight: bold;
}
.payslip-vertical .advance-balance-table td:first-child {
    color: #0d6efd;
}
.payslip-vertical .advance-balance-table td.text-end {
    color: #0d6efd;
}
.payslip-vertical .text-end {
    text-align: right;
}

.payslip-summary-footer {
    padding: 4px 6px;
    border-top: 2px solid #000;
    background-color: #e9ecef;
}

.summary-line { 
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    padding: 1px 0;
    font-size: 9.5pt;
}

.summary-line-total {
    display: flex;
    justify-content: space-between;
    font-weight: bold;
    font-size: 10.5pt;
    border-top: 1px dotted #ccc;
    margin-top: 3px;
    padding-top: 3px;
}
.summary-line-total .amount {
    color: #0d6efd;
}


/* ++ UPDATED: Print Styles for Multiple Layouts ++ */
@media print {
    body, html {
        margin: 0;
        padding: 0;
        background: #fff;
    }

    .sidebar,
    .main-header,
    .content-wrapper > .card {
        display: none !important;
    }
    
    body > .main-content, 
    body > .main-content > .content-wrapper {
        padding: 0 !important;
        margin: 0 !important;
    }

    #payslip-print-area {
        display: block !important;
    }

    .print-page {
        width: 100%;
        height: 100%;
        margin: 0;
        box-sizing: border-box;
        display: grid; 
        page-break-after: always;
    }

    /* Layout for 6 short slips per page */
    .print-page-short {
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(2, 1fr); 
        gap: 5mm; 
    }
    
    /* Layout for 3 long slips per page */
    .print-page-long {
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: 1fr;
        gap: 7mm;
    }

    /* Layout for 4 vertical slips per page */
    .print-page-4-vertical {
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: 1fr;
        gap: 4mm;
    }
    
    .print-page:last-child {
        page-break-after: avoid;
    }

    @page {
        size: A4 landscape;
        margin: 8mm; /* Adjusted margin slightly */
    }
}


/* --- Styles for Workers Page (Added Section) --- */

/* For scrollable table on workers page */
.table-container-scrollable {
    max-height: 65vh; /* Adjust height as needed */
    overflow-y: auto;
    position: relative;
}

/* For making the table header stick to the top during scroll */
.table-sticky-header thead th {
    position: sticky;
    top: -1px; /* Prevents a small gap */
    background-color: #f8f9fa; /* Match card body background */
    z-index: 10;
}

/* Styles for sortable table headers */
th[data-sort] {
    cursor: pointer;
    user-select: none; /* Prevents text selection on double click */
}

th[data-sort] i {
    font-size: 0.8em;
    margin-left: 5px;
    color: #999;
    transition: transform 0.2s ease-in-out;
}

/* This part ensures the browser uses the correct font to render the icon */
th.sort-asc i::before,
th.sort-desc i::before {
    font-family: 'bootstrap-icons'; /* This is the main fix */
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: #0d6efd; /* Highlight color for active sort */
}

th.sort-asc i::before {
    content: "\f128"; /* Bootstrap Icons: arrow-up-short */
}

th.sort-desc i::before {
    content: "\f125"; /* Bootstrap Icons: arrow-down-short */
}


/* ++ ADDED: Styles for Signature Sheet Print ++ */
.signature-sheet-container {
    border: none;
    padding: 15mm;
    font-family: 'Kanit', sans-serif;
    background: #fff;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.signature-sheet-header {
    text-align: center;
    margin-bottom: 1.5rem;
    border-bottom: 2px solid #333;
    padding-bottom: 1rem;
}

.signature-sheet-header h4 {
    margin: 0;
    font-weight: 600;
}

.signature-sheet-header p {
    margin: 5px 0 0;
    font-size: 1.1rem;
}

.signature-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 1rem;
}

.signature-table th,
.signature-table td {
    border: 1px solid #999;
    padding: 0.75rem 0.5rem;
    vertical-align: middle;
}

.signature-table thead th {
    background-color: #f2f2f2;
    font-weight: 500;
}

.signature-table .signature-cell {
    height: 40px; /* **แก้ไข** - ลดความสูงของช่องลายเซ็น */
}

.signature-table td {
    white-space: nowrap; /* **เพิ่ม** - ป้องกันการตัดคำในเซลล์ */
}

/* ++ ADDED: Print styles for A4 Portrait ++ */
.print-page-a4-portrait {
    width: 100%;
    height: 100%;
    margin: 0;
    box-sizing: border-box;
    page-break-after: always;
}

.print-page-a4-portrait:last-child {
    page-break-after: avoid;
}

/* ++ UPDATED: Add a specific @page rule for portrait mode ++ */
@media print {
    @page a4-portrait {
        size: A4 portrait;
        margin: 10mm;
    }
    
    .print-page-a4-portrait {
        page: a4-portrait;
    }

    /* ... (โค้ด @media print เดิม) ... */
}
