/* Design System Variables - Balance Sheet Theme */
:root {
    /* Modern Color Palette - Teal/Cyan Theme */
    --primary: #14B8A6;
    --primary-dark: #0D9488;
    --primary-light: #2DD4BF;
    --primary-bg: rgba(20, 184, 166, 0.1);

    --secondary: #06B6D4;
    --secondary-dark: #0891B2;
    --secondary-light: #22D3EE;

    --success: #10B981;
    --success-dark: #059669;
    --success-light: #34D399;
    --success-bg: rgba(16, 185, 129, 0.1);

    --warning: #F59E0B;
    --warning-dark: #D97706;
    --warning-light: #FCD34D;
    --warning-bg: rgba(245, 158, 11, 0.1);

    --danger: #EF4444;
    --danger-dark: #DC2626;
    --danger-light: #F87171;

    --info: #0EA5E9;
    --info-dark: #0284C7;
    --info-light: #38BDF8;

    /* Gray Scale */
    --gray-50: #F9FAFB;
    --gray-100: #F3F4F6;
    --gray-200: #E5E7EB;
    --gray-300: #D1D5DB;
    --gray-400: #9CA3AF;
    --gray-500: #6B7280;
    --gray-600: #4B5563;
    --gray-700: #374151;
    --gray-800: #1F2937;
    --gray-900: #111827;

    /* Gradients - Teal/Cyan */
    --gradient-primary: linear-gradient(135deg, #14B8A6 0%, #06B6D4 100%);
    --gradient-secondary: linear-gradient(135deg, #0EA5E9 0%, #14B8A6 100%);

    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-base: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 350ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Plus Jakarta Sans', 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, sans-serif;
    background: linear-gradient(180deg, #F0FDFA 0%, #CCFBF1 50%, #F0FDFA 100%);
    color: var(--gray-800);
    min-height: 100vh;
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background Pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: radial-gradient(circle at 20% 50%, rgba(20, 184, 166, 0.05) 0%, transparent 50%),
                      radial-gradient(circle at 80% 80%, rgba(6, 182, 212, 0.05) 0%, transparent 50%);
    pointer-events: none;
    z-index: -1;
}

/* Modern Navbar */
.navbar-modern {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow-md);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    border-bottom: 1px solid var(--gray-200);
}

.navbar-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.brand-container {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    transition: var(--transition-base);
}

.brand-logo {
    width: 48px;
    height: 48px;
    background: var(--gradient-primary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
    box-shadow: var(--shadow-md);
}

.brand-text-wrapper {
    display: flex;
    flex-direction: column;
}

.brand-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--gray-900);
    line-height: 1.2;
}

.brand-tagline {
    font-size: 12px;
    color: var(--gray-500);
    font-weight: 400;
}

/* Main Container */
.main-container {
    padding: 2rem 1rem;
    /* max-width: 1400px; */
    margin: 0 auto;
}

/* Content Section */
.content-section {
    background: white;
    border-radius: var(--radius-lg);
    padding: 2rem;
    box-shadow: var(--shadow-lg);
    margin-bottom: 2rem;
}

/* Header Section */
.page-header {
    text-align: center;
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 2px solid var(--gray-100);
}

.page-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.page-title i {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.page-subtitle {
    color: var(--gray-500);
    font-size: 14px;
}

/* Year Selector */
.year-selector-card {
    background: linear-gradient(135deg, rgba(20, 184, 166, 0.05) 0%, rgba(6, 182, 212, 0.05) 100%);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    margin-bottom: 2rem;
    border: 1px solid var(--gray-200);
}

.input-group .input-group-text {
    background: white;
    border: 1px solid var(--gray-300);
    color: var(--primary);
    font-weight: 600;
}

.input-group .form-select {
    border: 1px solid var(--gray-300);
    padding: 0.75rem 1rem;
    font-size: 14px;
    transition: var(--transition-base);
}

.input-group .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

.input-group .btn-primary {
    background: var(--gradient-primary);
    border: none;
    padding: 0.75rem 1.5rem;
    font-weight: 600;
    transition: var(--transition-base);
    box-shadow: var(--shadow-md);
}

.input-group .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-refresh-nav {
    background: linear-gradient(135deg, #10B981 0%, #059669 100%);
    border: none;
    padding: 0.625rem 1.25rem;
    font-weight: 600;
    font-size: 14px;
    transition: var(--transition-base);
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    color: white;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
}

.btn-refresh-nav:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background: linear-gradient(135deg, #059669 0%, #047857 100%);
    color: white;
}

.btn-refresh-nav i {
    font-size: 16px;
}

.btn-category-nav {
    background: linear-gradient(135deg, #3B82F6 0%, #2563EB 100%);
    border: none;
    padding: 0.625rem 1.25rem;
    font-weight: 600;
    font-size: 14px;
    transition: var(--transition-base);
    box-shadow: var(--shadow-md);
    white-space: nowrap;
    color: white;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
}

.btn-category-nav:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    background: linear-gradient(135deg, #2563EB 0%, #1D4ED8 100%);
    color: white;
}

.btn-category-nav i {
    font-size: 16px;
}

/* Loading Spinner */
#loader {
    position: fixed;
    z-index: 9999;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
}

#loader .spinner-border {
    width: 4rem;
    height: 4rem;
    border-width: 5px;
    border-color: var(--primary);
    border-right-color: transparent;
}

/* Table Styles */
.table-container {
    background: white;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    position: relative;
}

.pl-table {
    width: 100%;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--gray-300);
}

.pl-table thead {
    background: linear-gradient(180deg, #F8F9FA 0%, #E9ECEF 100%);
    border-bottom: 2px solid var(--gray-400);
}

.pl-table thead th {
    color: var(--gray-800) !important;
    font-weight: 700;
    font-size: 13px;
    padding: 1rem 0.75rem;
    text-align: center;
    border-right: 1px solid var(--gray-300);
    border-bottom: 2px solid var(--gray-400);
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 30;
    background: linear-gradient(180deg, #F8F9FA 0%, #E9ECEF 100%);
}

.pl-table thead th:last-child {
    border-right: none;
}

/* Sticky columns for Account Code and Name */
.pl-table thead th:nth-child(1),
.pl-table thead th:nth-child(2) {
    z-index: 40;
    font-weight: 700;
}

.pl-table thead th:nth-child(1) {
    left: 0;
    position: sticky;
    border-right: 2px solid var(--gray-400);
    width: 120px !important;
    min-width: 120px !important;
    max-width: 120px !important;
}

.pl-table thead th:nth-child(2) {
    left: 120px;
    position: sticky;
    border-right: 2px solid var(--gray-400);
    width: 250px !important;
    min-width: 250px !important;
    max-width: 250px !important;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
}

.pl-table tbody tr {
    transition: var(--transition-fast);
    border-bottom: 1px solid var(--gray-200);
}

.pl-table tbody tr:hover {
    background: #F0F9FF;
}

.pl-table tbody tr:nth-child(even) {
    background: #FAFBFC;
}

.pl-table tbody tr:nth-child(even):hover {
    background: #F0F9FF;
}

.pl-table tbody tr:last-child {
    border-bottom: none;
}

.pl-table tbody td {
    padding: 0.75rem 0.75rem;
    font-size: 13px;
    color: var(--gray-800);
    border-right: 1px solid var(--gray-200);
}

.pl-table tbody td:last-child {
    border-right: none;
}

/* Sticky tbody columns */
.pl-table tbody td:nth-child(1) {
    position: sticky;
    left: 0;
    background: white;
    z-index: 20;
    border-right: 2px solid var(--gray-300);
    width: 120px;
    min-width: 120px;
    max-width: 120px;
}

.pl-table tbody td:nth-child(2) {
    position: sticky;
    left: 120px;
    background: white;
    z-index: 20;
    border-right: 2px solid var(--gray-300);
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1);
    width: 250px;
    min-width: 250px;
    max-width: 250px;
}

/* Even row background for sticky columns */
.pl-table tbody tr:nth-child(even) td:nth-child(1),
.pl-table tbody tr:nth-child(even) td:nth-child(2) {
    background: #FAFBFC;
}

/* Hover effect for sticky columns */
.pl-table tbody tr:hover td:nth-child(1),
.pl-table tbody tr:hover td:nth-child(2) {
    background: #F0F9FF;
}

/* Calculation rows sticky columns - ใช้ !important เพื่อ override */
.calculation-row .calculation-label {
    position: sticky !important;
    left: 0 !important;
    z-index: 25 !important;
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%) !important;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1) !important;
    width: 370px !important;
    min-width: 370px !important;
    max-width: 370px !important;
    border-right: 2px solid var(--gray-300) !important;
}

.net-profit-row .calculation-label {
    position: sticky !important;
    left: 0 !important;
    z-index: 25 !important;
    background: linear-gradient(135deg, #D1FAE5 0%, #A7F3D0 100%) !important;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1) !important;
    width: 370px !important;
    min-width: 370px !important;
    max-width: 370px !important;
    border-right: 2px solid var(--gray-300) !important;
}

.pl-table .account-code {
    width: 120px !important;
    min-width: 120px !important;
    max-width: 120px !important;
    font-weight: 600;
    color: var(--primary);
}

.pl-table .account-name {
    width: 250px !important;
    min-width: 250px !important;
    max-width: 250px !important;
    font-weight: 500;
}

.pl-table .month-col {
    text-align: right;
    width: 130px !important;
    min-width: 130px !important;
    max-width: 130px !important;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    padding: 0.75rem 0.5rem !important;
    white-space: nowrap;
    overflow: visible;
}

.pl-table .total-col {
    text-align: right;
    width: 150px !important;
    min-width: 150px !important;
    max-width: 150px !important;
    font-weight: 700;
    background: #FFF9E6;
    color: var(--gray-900);
    font-family: 'Courier New', monospace;
    border-left: 2px solid var(--gray-300);
    padding: 0.75rem 0.5rem !important;
    white-space: nowrap;
    overflow: visible;
}

.pl-table tbody tr:nth-child(even) .total-col {
    background: #FFF4CC;
}

.pl-table tbody tr:hover .total-col {
    background: #FFECB3;
}

.text-right {
    text-align: right;
}

/* Responsive Table */
.table-responsive {
    border-radius: var(--radius-lg);
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 280px);
    -webkit-overflow-scrolling: touch;
    position: relative;
}

.table-responsive::-webkit-scrollbar {
    height: 8px;
    width: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: var(--gray-100);
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: var(--primary);
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: var(--primary-dark);
}

/* Corner scrollbar style */
.table-responsive::-webkit-scrollbar-corner {
    background: var(--gray-100);
}

/* Empty State */
.text-muted {
    color: var(--gray-500);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.content-section {
    animation: fadeIn 0.5s ease-out;
}

/* Category Modal Styles */
.category-list {
    max-height: 500px;
    overflow-y: auto;
}

.category-item {
    padding: 1rem;
    border-bottom: 1px solid var(--gray-200);
    cursor: move;
    transition: var(--transition-fast);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-item:hover {
    background: var(--gray-50);
}

.category-item.active {
    background: var(--primary-bg);
    border-left: 4px solid var(--primary);
}

.category-item .drag-handle {
    color: var(--gray-400);
    margin-right: 0.5rem;
    cursor: grab;
}

.category-item .drag-handle:active {
    cursor: grabbing;
}

.account-selector {
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
    background: var(--gray-50);
}

.account-checkbox-item {
    padding: 0.5rem;
    border-bottom: 1px solid var(--gray-200);
}

.account-checkbox-item:last-child {
    border-bottom: none;
}

.account-checkbox-item label {
    display: flex;
    align-items: center;
    cursor: pointer;
    margin-bottom: 0;
}

.account-checkbox-item input[type="checkbox"] {
    margin-right: 0.75rem;
    cursor: pointer;
}

/* Category Header in Table */
.category-header-row {
    background: linear-gradient(135deg, #CCFBF1 0%, #99F6E4 100%);
    color: var(--primary-dark) !important;
    font-weight: 700;
    font-size: 15px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.category-header-row td {
    padding: 1rem 0.875rem !important;
    border-bottom: 3px solid var(--primary) !important;
    color: var(--primary-dark) !important;
    font-weight: 700 !important;
}

.category-header-row i {
    font-size: 16px;
    margin-right: 0.5rem;
    color: var(--primary) !important;
}

/* Category Total Row */
.category-total-row {
    background: linear-gradient(135deg, #E0E7FF 0%, #C7D2FE 100%);
    font-weight: 700;
    font-size: 14px;
    border-top: 2px solid var(--primary);
}

.category-total-row td {
    padding: 0.875rem !important;
    color: var(--primary-dark) !important;
    font-weight: 700 !important;
    border-bottom: 2px solid var(--primary) !important;
}

.category-total-row .month-col,
.category-total-row .total-col {
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

/* Reversal Settings Styles */
.reversal-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--gray-200);
    gap: 1rem;
}

.reversal-item:last-child {
    border-bottom: none;
}

.reversal-account-info {
    flex: 1;
    font-size: 14px;
}

.reversal-options {
    flex: 0 0 auto;
    min-width: 180px;
}

.reversal-options select {
    font-size: 13px;
}

/* Compact Mode Styles */
.category-name-col {
    cursor: pointer;
    user-select: none;
    transition: var(--transition-fast);
}

.category-name-col:hover {
    background: rgba(255, 255, 255, 0.1);
}

.category-toggle-icon {
    transition: transform 0.3s ease;
    margin-right: 0.5rem;
    font-size: 14px;
}

.category-detail-row {
    transition: opacity 0.3s ease;
}

/* Category Header Row - Sticky columns for merged cell */
.category-header-row .category-name-col {
    position: sticky !important;
    left: 0 !important;
    z-index: 25 !important;
    width: 370px !important;
    min-width: 370px !important;
    max-width: 370px !important;
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.1) !important;
    background: linear-gradient(135deg, #CCFBF1 0%, #99F6E4 100%) !important;
    border-right: 2px solid var(--gray-300) !important;
}

/* Category Header Row - คอลัมน์เดือน */
.category-header-row td.month-col {
    width: 130px !important;
    min-width: 130px !important;
    max-width: 130px !important;
    padding: 0.75rem 0.5rem !important;
    box-shadow: none !important;
    border-left: 1px solid var(--gray-200) !important;
}

/* Category Header Row - คอลัมน์รวมทั้งปี */
.category-header-row td.total-col {
    width: 150px !important;
    min-width: 150px !important;
    max-width: 150px !important;
    box-shadow: none !important;
    border-left: 2px solid var(--gray-300) !important;
}

/* Calculation Row Styles */
.calculation-row {
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    font-weight: 700;
    font-size: 14px;
    border-top: 2px solid var(--warning);
}

.calculation-row td {
    padding: 0.875rem !important;
    color: var(--gray-900) !important;
    font-weight: 700 !important;
    border-bottom: 2px solid var(--warning) !important;
    box-shadow: none !important;
    border-left: none !important;
}

.calculation-row td:last-child {
    border-left: 2px solid var(--gray-300) !important;
}

.calculation-row .month-col,
.calculation-row .total-col {
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.calculation-row i {
    color: var(--warning-dark) !important;
}

/* Net Profit Row Styles */
.net-profit-row {
    background: linear-gradient(135deg, #D1FAE5 0%, #A7F3D0 100%);
    font-weight: 800;
    font-size: 15px;
    border-top: 3px solid var(--success);
    border-bottom: 3px solid var(--success);
}

.net-profit-row td {
    padding: 1rem !important;
    color: var(--success-dark) !important;
    font-weight: 800 !important;
    box-shadow: none !important;
    border-left: none !important;
}

.net-profit-row td:last-child {
    border-left: 2px solid var(--gray-300) !important;
}

.net-profit-row .month-col,
.net-profit-row .total-col {
    font-family: 'Courier New', monospace;
    font-size: 14px;
    font-weight: 800 !important;
}

.net-profit-row i {
    color: var(--success-dark) !important;
    font-size: 18px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-container {
        padding: 1rem 0.5rem;
    }

    .content-section {
        padding: 1rem;
        border-radius: var(--radius-md);
    }

    .page-title {
        font-size: 22px;
    }

    .pl-table thead th,
    .pl-table tbody td {
        padding: 0.625rem 0.5rem;
        font-size: 12px;
    }

    .pl-table .month-col,
    .pl-table .total-col {
        min-width: 75px;
    }
}
