@charset "UTF-8";

/* --- 1. Variables & Reset --- */
:root {
    --header-height: 70px;
    --tab-height: 50px;

    /* Pure Minimalist Palette (Bento Box) */
    --primary-main: #0f172a;
    /* Jet/Slate for primary actions */
    --primary-hover: #334155;
    --bg-main: #f8fafc;
    /* Off-white background */
    --bg-card: #ffffff;
    /* Pure white cards */
    --border-color: #e2e8f0;
    /* Thin subtle border */

    /* Text */
    --text-main: #0f172a;
    /* High contrast dark slate */
    --text-muted: #64748b;
    /* Muted secondary text */

    /* Semantic */
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;

    /* Geometry */
    --border-radius-lg: 16px;
    /* Bento box curves */
    --border-radius-md: 10px;
    --border-radius-sm: 6px;

    /* Shadows */
    --shadow-subtle: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Kanit', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a {
    text-decoration: none;
    transition: 0.2s;
}

ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* --- 2. Top Navigation (Replaces Sidebar) --- */
.top-header {
    width: 100%;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 30px;
    height: var(--header-height);
    box-sizing: border-box;
    position: sticky;
    top: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-logo {
    height: 40px;
}

.header-titles h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: var(--primary-main);
}

.header-titles small {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 30px;
}

.header-nav {
    display: flex;
    gap: 20px;
}

.header-nav a {
    color: var(--text-muted);
    font-weight: 500;
    font-size: 0.95rem;
    padding: 8px 12px;
    border-radius: 6px;
    transition: all 0.2s;
}

.header-nav a:hover,
.header-nav a.active {
    color: var(--primary-main);
    background: #f1f5f9;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 20px;
    border-left: 1px solid var(--border-color);
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-info strong {
    font-size: 0.9rem;
    color: var(--text-main);
}

.user-info span {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.btn-logout {
    color: var(--danger);
    font-size: 1.1rem;
    padding: 8px;
    border-radius: 6px;
    transition: 0.2s;
}

.btn-logout:hover {
    background: #fef2f2;
}

/* --- Dashboard Controls & Month Tabs --- */
.dashboard-controls {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px 30px 0;
    width: 100%;
    box-sizing: border-box;
}

.year-group {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--bg-card);
    padding: 8px 16px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-subtle);
}

.year-group label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
}

.year-input {
    width: 80px;
    border: none;
    background: #f1f5f9;
    padding: 6px 10px;
    border-radius: 4px;
    font-family: inherit;
    font-weight: 600;
    color: var(--text-main);
    text-align: center;
    outline: none;
}

.year-input:focus {
    box-shadow: 0 0 0 2px var(--border-color);
}

.month-tabs {
    display: flex;
    flex-wrap: nowrap;
    overflow-x: auto;
    background: var(--bg-card);
    padding: 6px;
    border-radius: var(--border-radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-subtle);
    gap: 4px;
    align-items: center;
    /* Hide scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.month-tabs::-webkit-scrollbar {
    display: none;
}

/* Hide actual checkbox */
.month-checkbox,
.compare-month-checkbox {
    display: none;
}

/* Style label as pill button */
.month-label {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    font-family: 'Kanit', sans-serif;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    user-select: none;
}

.month-label:hover {
    background: #f1f5f9;
    color: var(--text-main);
}

/* Checked state styling */
.month-checkbox:checked+.month-label,
.compare-month-checkbox:checked+.month-label {
    background: var(--primary-main);
    color: white;
    box-shadow: 0 2px 4px rgba(15, 23, 42, 0.2);
}

/* Optional: distinct color for Select All/Clear buttons */
.btn-tab-action {
    padding: 8px 16px;
    background: #f1f5f9;
    border: none;
    border-radius: 6px;
    color: var(--text-main);
    font-family: 'Kanit', sans-serif;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-tab-action:hover {
    background: #e2e8f0;
}

.month-divider {
    width: 1px;
    height: 24px;
    background-color: var(--border-color);
    margin: 0 4px;
}

/* --- 3. Main Content Flex Wrapper --- */
.main-content {
    flex: 1;
    padding: 24px 30px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.dashboard-header-text {
    margin-bottom: 24px;
}

.dashboard-header-text h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text-main);
    font-weight: 600;
}

/* KPI Cards */
.kpi-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.kpi-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.kpi-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.kpi-card-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-muted);
    font-weight: 500;
}

.kpi-card-header .icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    background: #f1f5f9;
    color: var(--primary-main);
}

.kpi-card-body .value {
    font-size: 1.8rem;
    font-weight: 600;
    color: var(--text-main);
    margin: 0;
    line-height: 1.2;
    font-feature-settings: "tnum";
}

.kpi-card-footer {
    margin-top: 15px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.positive {
    color: #10b981 !important;
    font-weight: 600;
}

.negative {
    color: #ef4444 !important;
    font-weight: 600;
}

/* Data Sections */
.data-container {
    display: grid;
    grid-template-columns: 1fr 2fr;
    /* 1/3 Pie, 2/3 Table */
    gap: 20px;
    margin-bottom: 20px;
}

.data-card {
    background: var(--bg-card);
    border-radius: var(--border-radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-subtle);
    border: 1px solid var(--border-color);
}

.data-card h2 {
    margin: 0 0 20px 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.chart-column-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.data-card.data-table {
    display: flex;
    flex-direction: column;
}

.data-card.full-width {
    grid-column: 1 / -1;
    margin-bottom: 30px;
}

/* Table Minimalist Bento Box Theme */
.responsive-table {
    width: 100%;
    border-collapse: collapse;
    /* Shift to collapse for cleaner lines */
    font-size: 0.95rem;
}

.responsive-table th {
    text-align: left;
    padding: 12px 16px;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.5px;
}

.responsive-table td {
    padding: 14px 16px;
    background: transparent;
    color: var(--text-main);
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.product-row {
    cursor: pointer;
}

.product-row:hover td {
    background: #f1f5f9;
}

.product-row.active td {
    background: #e2e8f0;
}

.product-name-link {
    color: var(--text-main);
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: transparent;
    transition: text-decoration-color 0.2s;
}

.product-name-link:hover {
    color: var(--primary-glow);
    text-decoration-color: var(--primary-glow);
    text-shadow: var(--shadow-glow);
}

.product-icon {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 3px;
    margin-right: 12px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.responsive-table th:nth-child(n+2),
.responsive-table td:nth-child(n+2) {
    text-align: right;
    font-feature-settings: "tnum";
}

.responsive-table tfoot td {
    font-weight: 700;
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
    padding: 14px 16px;
    border-top: 2px solid var(--border-color);
}

.responsive-table td.positive {
    color: var(--success) !important;
    font-weight: 600;
}

.responsive-table td.negative {
    color: var(--danger) !important;
    font-weight: 600;
}

/* Buttons & Inputs */
.btn-view-more {
    font-size: 0.85rem;
    background: #f1f5f9;
    color: var(--primary-main);
    padding: 6px 16px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Kanit', sans-serif;
    font-weight: 500;
}

.btn-view-more:hover {
    background: var(--primary-main);
    color: white;
    border-color: var(--primary-main);
}

.table-filter-group {
    position: relative;
    width: 100%;
    max-width: 320px;
}

.table-filter-group select {
    width: 100%;
    padding: 8px 12px 8px 36px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: #f1f5f9;
    color: var(--text-main);
    font-family: 'Kanit', sans-serif;
    font-size: 0.95rem;
    transition: all 0.2s;
    outline: none;
}

.table-filter-group select option {
    background: var(--bg-card);
    color: var(--text-main);
}

.table-filter-group select:focus {
    border-color: var(--primary-main);
    background: var(--bg-card);
}

.chart-controls .btn-zoom {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--text-muted);
    transition: all 0.2s;
    cursor: pointer;
    box-shadow: var(--shadow-subtle);
}

.chart-controls .btn-zoom:hover {
    background: #f1f5f9;
    color: var(--primary-main);
    border-color: var(--border-color);
}

/* Overlays */
#barChartWrapper {
    max-height: 400px;
    overflow-y: hidden;
    overflow-x: hidden;
    padding-top: 15px;
}

#loadingOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.85);
    /* Light Overlay */
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    transition: opacity 0.3s;
}

#loadingOverlay.hidden {
    opacity: 0;
    pointer-events: none;
    z-index: -1;
}

.loading-icon {
    width: 70px;
    height: 70px;
    animation: spin-ping 1.5s cubic-bezier(0, 0.2, 0.8, 1) infinite;
    border-radius: 50%;
    border: 4px solid #e2e8f0;
    border-top-color: var(--primary-main);
    border-right-color: var(--primary-main);
}

@keyframes spin-ping {
    0% {
        transform: rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: rotate(360deg);
        opacity: 0.5;
    }
}

.main-footer {
    margin-top: 50px;
    padding: 25px 0;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    text-align: center;
    color: #94a3b8;
    font-size: 0.9rem;
}

/* Modals */
.modal-overlay {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--bg-card);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
}

.modal-header h2 {
    color: var(--text-main);
    font-weight: 600;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    color: var(--text-main);
}

.login-card button.btn-login {
    background: var(--primary-main);
    border: 1px solid var(--primary-main);
    box-shadow: none;
    color: white;
    transition: 0.3s;
}

.login-card button.btn-login:hover {
    background: var(--primary-hover);
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.kpi-card {
    animation: fadeInUp 0.6s ease-out forwards;
    opacity: 0;
}

.kpi-card:nth-child(1) {
    animation-delay: 0.1s;
}

.kpi-card:nth-child(2) {
    animation-delay: 0.2s;
}

.kpi-card:nth-child(3) {
    animation-delay: 0.3s;
}

.kpi-card:nth-child(4) {
    animation-delay: 0.4s;
}

.data-card {
    animation: fadeInUp 0.6s ease-out 0.5s forwards;
    opacity: 0;
}

@media (max-width: 1200px) {
    .data-container {
        grid-template-columns: 1fr;
    }

    .chart-column-left,
    .data-table {
        grid-column: 1 / -1;
    }

    .chart-column-left {
        flex-direction: row;
    }

    .chart-column-left .data-card {
        width: 50%;
    }
}

@media (max-width: 900px) {
    .kpi-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 14px;
    }

    .chart-column-left {
        flex-direction: column;
    }

    .chart-column-left .data-card {
        width: 100%;
    }
}

@media (max-width: 768px) {

    /* Header mobile */
    .top-header {
        padding: 0 16px;
        height: auto;
        min-height: var(--header-height);
        flex-wrap: wrap;
        gap: 8px;
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .header-titles small {
        display: none;
    }

    .header-titles h1 {
        font-size: 1rem;
    }

    .header-logo {
        height: 32px;
    }

    .header-right {
        gap: 10px;
        width: 100%;
        justify-content: space-between;
    }

    .header-nav {
        gap: 4px;
        flex-wrap: wrap;
    }

    .header-nav a {
        font-size: 0.8rem;
        padding: 6px 8px;
    }

    .header-user .user-info {
        display: none;
    }

    /* Dashboard controls mobile */
    .dashboard-controls {
        padding: 12px 16px 0;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .primary-filter-row,
    .compare-filter-row {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px;
    }

    .year-group {
        margin-right: 0 !important;
    }

    .month-tabs {
        overflow-x: auto;
    }

    .month-label {
        padding: 6px 10px;
        font-size: 0.82rem;
    }

    .btn-tab-action {
        padding: 6px 10px;
        font-size: 0.82rem;
    }

    /* KPI: stay 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.82rem;
    }

    .kpi-card-header .icon {
        width: 32px;
        height: 32px;
        font-size: 1rem;
    }

    /* Main content */
    .main-content {
        padding: 16px;
    }

    .dashboard-header-text h2 {
        font-size: 1.2rem;
    }

    /* Table: 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.82rem;
    }

    .table-filter-group {
        max-width: 100%;
    }

    /* กราฟ: ไม่ล้นกว้างกว่า container */
    canvas {
        max-width: 100% !important;
    }

    #barChartWrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    #barChartWrapper canvas {
        min-width: 500px;
        /* ให้กราฟ bar scroll แนวนอนได้ถ้าจำเป็น */
    }

    /* กราฟ pie: จำกัดความสูงบน mobile */
    .data-card canvas#pieChartProducts {
        max-height: 280px !important;
    }
}

@media (max-width: 480px) {

    /* Extra-small: single column KPI */
    .kpi-container {
        grid-template-columns: 1fr;
    }

    .kpi-card-body .value {
        font-size: 1.3rem;
    }

    .top-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .header-left {
        width: 100%;
    }

    .header-right {
        width: 100%;
    }
}