@charset "UTF-8";

/* --- 1. Variables & Reset --- */
:root {
    --sidebar-width: 260px;
    --sidebar-width-collapsed: 80px;
    --sidebar-bg: #1e293b;
    --sidebar-text: #f8fafc;
    --main-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-dark: #334155;
    --text-muted: #64748b;
    --primary: #3b82f6;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --border-radius: 12px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

body {
    font-family: 'Kanit', sans-serif;
    margin: 0;
    background-color: var(--main-bg);
    color: var(--text-dark);
    display: flex;
    overflow-x: hidden;
}

a {
    text-decoration: none;
    transition: 0.2s;
}

ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* --- 2. Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background-color: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 25px;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-x: hidden;
    z-index: 50;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.1);
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    border: 1px solid var(--sidebar-bg);
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background-color: rgba(255, 255, 255, 0.3);
}

/* Sidebar Header & Logo */
.sidebar-header {
    text-align: center;
    padding-bottom: 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 20px;
    display: block;
}

.sidebar-header h2 {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin: 0;
    gap: 10px;
    font-size: 1.25rem;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.sidebar-logo {
    height: 60px;
    width: auto;
    object-fit: contain;
    margin-right: 0;
}

.sidebar-nav li {
    margin-bottom: 8px;
}

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    color: #cbd5e1;
    border-radius: var(--border-radius);
    font-weight: 400;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-weight: 500;
}

.sidebar-nav a .fa-fw {
    width: 20px;
    text-align: center;
}

/* Sidebar Filters */
.sidebar-filters {
    margin-top: auto;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    opacity: 1;
    transition: opacity 0.3s;
}

.filter-group {
    margin-bottom: 15px;
}

.filter-group label {
    font-size: 0.85rem;
    color: #94a3b8;
    margin-bottom: 6px;
    display: block;
}

.filter-group input,
.filter-group select {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background-color: #334155;
    color: #ffffff;
    font-family: 'Kanit', sans-serif;
    font-size: 0.95rem;
    outline: none;
    font-weight: 400;
}

.filter-group input:focus,
.filter-group select:focus {
    background-color: #475569;
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.1);
}

.filter-group select option {
    background-color: #1e293b;
    color: #ffffff;
    padding: 10px;
}

.btn-apply-filters {
    width: 100%;
    padding: 10px;
    border-radius: 8px;
    border: none;
    background-color: var(--primary);
    color: white;
    font-weight: 500;
    cursor: pointer;
    transition: 0.2s;
}

.btn-apply-filters:hover {
    background-color: #2563eb;
}

.btn-apply-filters.btn-reset {
    background-color: rgba(255, 255, 255, 0.1);
    color: #cbd5e1;
}

.btn-apply-filters.btn-reset:hover {
    background-color: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.sidebar-footer {
    margin-top: 15px;
}

.sidebar-credit {
    display: none !important;
}

#sidebarToggle {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #cbd5e1;
    padding: 8px;
    border-radius: 8px;
    width: 100%;
    cursor: pointer;
    transition: 0.2s;
}

#sidebarToggle:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Sidebar Collapsed State */
body.sidebar-collapsed .sidebar {
    width: var(--sidebar-width-collapsed);
    padding: 25px 15px;
}

body.sidebar-collapsed .sidebar-header span,
body.sidebar-collapsed .sidebar-nav span,
body.sidebar-collapsed .sidebar-filters,
body.sidebar-collapsed .sidebar-credit {
    opacity: 0;
    visibility: hidden;
    width: 0;
    height: 0;
    padding: 0;
    margin: 0;
    overflow: hidden;
}

body.sidebar-collapsed .sidebar-header h2,
body.sidebar-collapsed .sidebar-nav a {
    justify-content: center;
}

body.sidebar-collapsed #sidebarToggle i {
    transform: rotate(180deg);
}

body.sidebar-collapsed .sidebar-header h2 {
    gap: 0;
}

body.sidebar-collapsed .sidebar-logo {
    height: 40px;
    margin-bottom: 0;
}

/* --- 3. Main Content --- */
.main-content {
    flex-grow: 1;
    margin-left: var(--sidebar-width);
    padding: 30px;
    min-height: 100vh;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

body.sidebar-collapsed .main-content {
    margin-left: var(--sidebar-width-collapsed);
}

.main-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 35px;
}

.main-header h1 {
    margin: 0;
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--text-dark);
}

.main-header h1 small {
    display: block;
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-top: 5px;
}

.header-office-title {
    text-align: right;
}

#viewOperatorsLink {
    font-size: 0.85rem;
    color: var(--primary);
    font-weight: 500;
    padding: 6px 12px;
    background: rgba(59, 130, 246, 0.1);
    border-radius: 20px;
    display: inline-block;
    margin-top: 8px;
}

#viewOperatorsLink:hover {
    background: rgba(59, 130, 246, 0.2);
}

/* KPI Cards */
.kpi-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    margin-bottom: 35px;
}

.kpi-card {
    background: var(--card-bg);
    padding: 24px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.5);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    transition: transform 0.2s;
}

.kpi-card:hover {
    transform: translateY(-2px);
}

.kpi-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.kpi-card-header h3 {
    margin: 0;
    font-size: 0.95rem;
    color: var(--text-muted);
    font-weight: 500;
}

.kpi-card-header .icon {
    padding: 10px;
    border-radius: 10px;
    background: #f8fafc;
    color: var(--text-dark);
}

.kpi-card-body .value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-dark);
    margin: 0;
    line-height: 1.2;
}

.kpi-card-footer {
    margin-top: 15px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.positive {
    color: var(--success) !important;
    font-weight: 600;
}

.negative {
    color: var(--danger) !important;
    font-weight: 600;
}

/* Charts & Tables */
.data-container {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 24px;
}

.data-card {
    background: var(--card-bg);
    border-radius: var(--border-radius);
    padding: 24px;
    box-shadow: var(--shadow-md);
    border: 1px solid rgba(255, 255, 255, 0.5);
    margin-bottom: 24px;
}

.data-card h2 {
    margin: 0 0 20px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-dark);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chart-column-left {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.data-card.data-table {
    grid-column: 2;
}

.data-card.full-width {
    grid-column: 1 / -1;
}

/* Table Styles */
.responsive-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.responsive-table th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid #f1f5f9;
    background: #fff;
    white-space: nowrap;
}

.responsive-table td {
    padding: 14px 16px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text-dark);
    vertical-align: middle;
}

.product-row {
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.product-row:hover {
    background-color: #e2e8f0 !important;
}

.product-row.active {
    background-color: #cbd5e1 !important;
    border-left: 4px solid var(--primary);
}

/* Link Style in Table */
.product-name-link {
    color: var(--text-dark);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
    position: relative;
    z-index: 2;
    cursor: pointer;
    border-bottom: 1px dashed transparent;
}

.product-name-link:hover {
    color: var(--primary);
    text-decoration: none;
    border-bottom-color: var(--primary);
}

.product-icon {
    font-size: 1rem;
    width: 16px;
    text-align: center;
    display: inline-block;
    margin-right: 8px;
}

.responsive-table th:nth-child(n+2),
.responsive-table td:nth-child(n+2) {
    text-align: right;
}

.responsive-table tfoot td {
    font-weight: 700;
    background-color: #f8fafc;
    border-top: 2px solid #e2e8f0;
}

.responsive-table td.positive,
.modal-table td.positive {
    color: var(--success) !important;
}

.responsive-table td.negative,
.modal-table td.negative {
    color: var(--danger) !important;
}

/* View More Button */
.btn-view-more {
    font-size: 0.7rem;
    background: transparent;
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    cursor: pointer;
    transition: all 0.2s ease;
    float: right;
    margin-left: 10px;
}

.btn-view-more:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: var(--text-dark);
}

/* Table Filters */
.table-filter-container {
    margin-bottom: 20px;
}

.table-filter-group {
    position: relative;
    width: 100%;
    max-width: 300px;
}

.table-filter-group .fa-search {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
}

.table-filter-group select {
    width: 100%;
    padding: 10px 10px 10px 36px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: var(--text-dark);
    font-family: 'Kanit', sans-serif;
}

.sortable {
    cursor: pointer;
    position: relative;
    user-select: none;
}

.sortable::after {
    content: ' \25B2\25BC';
    color: #ccc;
    font-size: 0.8em;
    position: absolute;
    right: 10px;
    opacity: 0.7;
}

.sortable[data-sort-state="asc"]::after {
    content: ' \25B2';
    color: #333;
    opacity: 1;
}

.sortable[data-sort-state="desc"]::after {
    content: ' \25BC';
    color: #333;
    opacity: 1;
}

.sortable:hover {
    background-color: #f5f5f5;
}

.tax-drilldown {
    font-weight: 500;
    color: var(--color-blue);
    cursor: pointer;
    text-decoration: none;
    transition: text-decoration 0.2s;
}

.tax-drilldown:hover {
    text-decoration: underline;
}

#resetOperatorChart {
    font-size: 0.8rem;
    margin-left: 10px;
    cursor: pointer;
    padding: 2px 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
    background: #eee;
    display: none;
}

#resetOperatorChart:hover {
    background: #ddd;
}

.chart-title-span {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 1.1rem;
    margin-left: 8px;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.chart-header h2 {
    margin: 0;
}

.chart-header select {
    padding: 6px 10px;
    font-family: 'Kanit', sans-serif;
    font-size: 0.9rem;
    border-radius: 6px;
    border: 1px solid #ccc;
}

#barChartWrapper {
    overflow-y: hidden;
    overflow-x: hidden;
    padding-top: 15px;
    width: 100%;
    box-sizing: border-box;
}

/* Footer */
.main-footer {
    margin-top: 40px;
    padding-top: 20px;
    border-top: 1px solid #e2e8f0;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding-bottom: 10px;
}

.main-footer span {
    display: inline-block;
    margin: 0 5px;
}

/* --- 4. Modal & Login --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal-overlay.hidden {
    display: none !important;
}

.modal-content {
    background: #fff;
    padding: 30px;
    border-radius: 16px;
    width: 90%;
    max-width: 800px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    color: var(--text-dark);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    position: relative;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 2rem;
    font-weight: bold;
    color: #aaa;
    cursor: pointer;
    transition: transform 0.2s;
    line-height: 1;
    z-index: 2001;
}

.modal-close:hover {
    color: #333;
    transform: scale(1.1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 20px;
    padding-right: 30px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--sidebar-bg);
}

.modal-body {
    overflow-y: auto;
    flex-grow: 1;
    margin-top: 5px;
    padding-right: 5px;
}

.modal-body::-webkit-scrollbar {
    width: 6px;
}

.modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.modal-body::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background-color: rgba(0, 0, 0, 0.2);
}

.modal-table {
    width: 100%;
    border-collapse: collapse;
}

.modal-table th,
.modal-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #ddd;
}

.modal-table th:first-child,
.modal-table td:first-child {
    text-align: left;
}

.modal-table th:nth-child(n+2),
.modal-table td:nth-child(n+2) {
    text-align: right;
}

.modal-table th {
    background-color: #f9f9f9;
    text-align: left;
}

.modal-table td:nth-child(2) {
    font-weight: 500;
}

.modal-table tfoot.total-row td {
    font-weight: bold;
    background-color: #f9f9f9;
}

.modal-table .fa-arrow-up,
.modal-table .fa-arrow-down {
    margin-left: 5px;
}

/* Login Card */
.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    padding: 40px;
    border-radius: 16px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.login-card .login-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    margin-bottom: 25px;
    text-align: center;
}

.login-logo {
    height: 80px;
    width: auto;
    margin-bottom: 15px;
    object-fit: contain;
}

.login-card .form-group {
    margin-bottom: 15px;
}

.login-card .password-group {
    margin-bottom: 10px;
}

.login-card input {
    width: 100%;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-sizing: border-box;
}

.login-card .password-group input {
    padding-right: 12px;
}

.login-card button.btn-login {
    width: 100%;
    padding: 12px;
    background: var(--sidebar-bg);
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.3s;
}

.login-card button.btn-login:hover {
    background-color: #2c5683;
}

/* Toggle Password Button */
.login-card .toggle-password {
    display: block;
    width: 100%;
    text-align: right;
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    font-size: 1.1rem;
    padding: 5px 0;
    margin-bottom: 10px;
    outline: none;
}

.login-card .toggle-password:hover {
    color: #333;
}

.login-card .error-message {
    background-color: #ffebee;
    color: var(--danger);
    border: 1px solid var(--danger);
    padding: 10px 15px;
    border-radius: 6px;
    text-align: center;
    font-size: 0.9rem;
    margin-bottom: 20px;
}

/* Loading Overlay */
#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(2px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    transition: opacity 0.3s ease;
}

#loadingOverlay.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

.loading-icon {
    width: 80px;
    height: 80px;
    object-fit: contain;
    animation: spin 1.5s linear infinite;
}

.loading-text {
    margin-top: 15px;
    font-size: 1.1rem;
    color: #555;
    font-weight: 500;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Mobile Menu Button (hidden on desktop) */
#mobileMenuBtn {
    display: none;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-dark);
    cursor: pointer;
    margin-right: 15px;
    padding: 5px;
    line-height: 1;
}

/* Sidebar overlay backdrop (mobile) */
#sidebarOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 49;
}

#sidebarOverlay.active {
    display: block;
}

/* Responsive */
@media (max-width: 1200px) {
    .data-container {
        grid-template-columns: 1fr;
    }

    .chart-column-left,
    .data-table {
        grid-column: 1 / -1;
    }
}

@media (max-width: 900px) {
    .table-filter-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {

    /* body: column layout บน mobile ให้ main-content เต็ม width */
    body {
        flex-direction: column;
    }

    /* KPI: 2 columns on mobile */
    .kpi-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin-bottom: 20px;
    }

    .kpi-card {
        padding: 16px;
    }

    .kpi-card-body .value {
        font-size: 1.4rem;
    }

    .kpi-card-header h3 {
        font-size: 0.8rem;
    }

    /* Sidebar: hide off-screen, open as overlay */
    .sidebar {
        width: var(--sidebar-width) !important;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding: 20px;
        z-index: 50;
        box-shadow: none;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.3);
    }

    /* Reset collapsed state on mobile */
    .sidebar-header span,
    .sidebar-nav span,
    .sidebar-filters,
    .sidebar-credit {
        opacity: 1 !important;
        visibility: visible !important;
        width: auto !important;
        height: auto !important;
        padding-top: 0;
        margin: 0;
    }

    .sidebar-filters {
        padding-top: 20px;
        margin-top: 20px;
        border-top: 1px solid rgba(255, 255, 255, 0.1);
    }

    .sidebar-header h2,
    .sidebar-nav a {
        justify-content: flex-start;
    }

    /* Main content: no margin (sidebar is overlay) */
    .main-content {
        margin-left: 0 !important;
        padding: 15px;
        width: 100%;
        box-sizing: border-box;
        min-width: 0;
    }

    /* data-container เต็มความกว้างบน mobile */
    .data-container {
        width: 100%;
        box-sizing: border-box;
    }

    /* data-card ทุกอันขยายเต็มกว้าง */
    .data-card {
        width: 100%;
        box-sizing: border-box;
    }


    /* Header */
    .main-header {
        flex-wrap: wrap;
        gap: 8px;
        margin-bottom: 20px;
    }

    .header-office-title {
        display: none;
    }

    #mobileMenuBtn {
        display: inline-flex !important;
        /* override inline style in index.php */
        align-items: center;
    }

    /* sidebar-footer บน mobile: แสดงปุ่มปิด (close) */
    .sidebar-footer {
        margin-top: 10px;
        padding: 10px 0;
    }

    #sidebarToggle {
        width: 100%;
        padding: 12px;
        font-size: 1rem;
        background: rgba(255, 255, 255, 0.1);
        color: #fff;
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 8px;
    }

    /* Chart & table */
    .chart-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .slide-item img {
        height: 200px;
    }

    /* ตาราง: scroll แนวนอนได้ ไม่ล้นหน้าจอ */
    .data-card {
        padding: 16px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .responsive-table {
        min-width: 500px;
        /* ให้ scroll แทนที่จะบีบ */
    }

    .responsive-table th,
    .responsive-table td {
        padding: 10px 8px;
        font-size: 0.85rem;
    }

    .table-filter-group {
        max-width: 100%;
    }

    /* กราฟ: ไม่ล้นกว้างกว่า container */
    canvas {
        max-width: 100% !important;
    }

    #barChartWrapper {
        overflow-x: hidden;
        width: 100%;
    }

    #barChartWrapper canvas {
        width: 100% !important;
        /* JS จัดการ height แล้ว ไม่ต้องตั้ง min-width */
    }

    /* กราฟ pie: จำกัดความสูงบน mobile */
    .data-card canvas#pieChartProducts,
    .data-card canvas#operatorPieChart {
        max-height: 280px !important;
    }
}

@media (max-width: 480px) {

    /* Extra small: 1 column KPI */
    .kpi-container {
        grid-template-columns: 1fr;
    }

    .kpi-card-body .value {
        font-size: 1.3rem;
    }

    .main-header h1 {
        font-size: 1.3rem;
    }
}