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

html, body {
    font-family: 'Inter', 'Noto Sans Thai', sans-serif;
    background: #f9fafb;
    color: #1f2937;
}

.container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: #1a1a2e;
    color: white;
    padding: 24px 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 32px;
    padding: 0 8px;
    background: linear-gradient(135deg, #3b82f6 0%, #06b6d4 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
}

.nav-item {
    padding: 12px 16px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    font-weight: 500;
    border: 2px solid transparent;
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-group-label {
    padding: 8px 16px;
    font-size: 11px;
    font-weight: 700;
    color: rgba(255,255,255,0.5);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 12px;
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.nav-group-label:hover {
    color: rgba(255,255,255,0.8);
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow: hidden;
    transition: max-height 0.3s ease;
    max-height: 500px;
}

.nav-group.collapsed {
    max-height: 0;
}

.nav-group .nav-item {
    padding: 8px 16px 8px 28px;
    font-size: 13px;
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.nav-item.active {
    background: #3b82f6;
    border-color: #60a5fa;
}

.nav-item span {
    font-size: 18px;
}

/* Main content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.header {
    background: white;
    border-bottom: 1px solid #e5e7eb;
    padding: 16px 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    font-size: 24px;
    font-weight: 700;
    color: #1f2937;
}

.content {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
}

/* Sections */
.section {
    display: none;
}

.section.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

/* Dashboard */
.cash-input-section {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 28px;
    border-radius: 12px;
    margin-bottom: 32px;
}

.cash-input-label {
    font-size: 14px;
    font-weight: 600;
    opacity: 0.9;
    margin-bottom: 12px;
}

.cash-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
}

.cash-input {
    flex: 1;
    font-size: 32px;
    font-weight: 700;
    padding: 16px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.95);
    color: #1f2937;
    font-family: 'Inter', monospace;
}

.cash-input:focus {
    outline: none;
    background: white;
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.3);
}

.cash-save-btn {
    padding: 12px 20px;
    background: white;
    color: #667eea;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.cash-save-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* KPI Cards */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.kpi-card {
    background: white;
    border-radius: 12px;
    padding: 20px;
    border: 1px solid #e5e7eb;
    transition: all 0.3s ease;
}

.kpi-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
    border-color: #d1d5db;
}

.kpi-label {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 28px;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 4px;
}

.kpi-trend {
    font-size: 12px;
    color: #6b7280;
}

/* Charts */
.charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 32px;
}

.chart-card {
    background: white;
    border-radius: 12px;
    padding: 24px;
    border: 1px solid #e5e7eb;
}

.chart-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    color: #1f2937;
}

.chart-container {
    position: relative;
    height: 300px;
}

/* Buttons */
.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: #3b82f6;
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
    background: white;
    color: #3b82f6;
    border: 2px solid #3b82f6;
}

.btn-secondary:hover {
    background: #f0f9ff;
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:hover {
    background: #059669;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Payment Plan */
.payment-list {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.payment-item {
    display: grid;
    grid-template-columns: 36px 80px 130px 140px 1fr 110px 90px 120px 80px;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid #e5e7eb;
    border-radius: 0;
    align-items: center;
    transition: all 0.2s ease;
    font-size: 13px;
    background: white;
    border-bottom: none;
}

.payment-item:last-child {
    border-bottom: 1px solid #e5e7eb;
}

.payment-item:first-child {
    border-radius: 10px 10px 0 0;
}

.payment-item:last-child {
    border-radius: 0 0 10px 10px;
}

.payment-item:only-child {
    border-radius: 10px;
    border-bottom: 1px solid #e5e7eb;
}

.payment-item.selected {
    background: #eff6ff;
    border-color: #93c5fd;
}

.payment-item.payable {
    border-left: 3px solid #10b981;
}

.payment-item.unpayable {
    border-left: 3px solid #ef4444;
}

.payment-item:hover {
    background: #f9fafb;
    border-color: #d1d5db;
}

.plan-header-row {
    display: grid;
    grid-template-columns: 36px 80px 130px 140px 1fr 110px 90px 120px 80px;
    gap: 12px;
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 700;
    color: #9ca3af;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #e5e7eb;
    background: #f9fafb;
    border-radius: 10px 10px 0 0;
}

.sortable-header {
    cursor: pointer;
    user-select: none;
    transition: color 0.2s;
}

.sortable-header:hover {
    color: #3b82f6;
}

.plan-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin-bottom: 16px;
    padding: 12px 0;
}

.plan-filter-label {
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    margin-right: 4px;
}

.plan-filter-divider {
    width: 1px;
    height: 24px;
    background: #e5e7eb;
    margin: 0 8px;
}

.vendor-filter-select {
    padding: 6px 12px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    background: white;
    cursor: pointer;
    max-width: 200px;
}

.vendor-filter-select:focus {
    outline: none;
    border-color: #3b82f6;
}

/* Priority badges */
.priority-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.priority-badge.clickable {
    cursor: pointer;
    transition: all 0.2s ease;
}

.priority-badge.clickable:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.priority-critical {
    background: #fecaca;
    color: #991b1b;
}

.priority-high {
    background: #fed7aa;
    color: #9a3412;
}

.priority-medium {
    background: #bfdbfe;
    color: #1e40af;
}

.priority-low {
    background: #f3f4f6;
    color: #6b7280;
}

/* Priority dropdown */
.priority-dropdown {
    position: fixed;
    z-index: 9999;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    min-width: 180px;
    overflow: hidden;
}

.priority-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s ease;
    font-size: 13px;
}

.priority-dropdown-item:hover {
    background: #f3f4f6;
}

.priority-dropdown-item.current {
    background: #eff6ff;
}

/* Batch bar */
.plan-batch-bar {
    position: sticky;
    bottom: 0;
    background: #1e293b;
    color: white;
    padding: 12px 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 12px;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.1);
    z-index: 10;
}

.batch-count {
    font-weight: 600;
    font-size: 14px;
}

.batch-amount {
    font-size: 14px;
    color: #93c5fd;
    font-weight: 600;
}

.btn-deselect {
    padding: 6px 14px;
    background: rgba(255,255,255,0.15);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    transition: background 0.2s;
}

.btn-deselect:hover {
    background: rgba(255,255,255,0.25);
}

.btn-batch {
    padding: 8px 16px;
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    margin-left: auto;
    transition: background 0.2s;
}

.btn-batch:hover {
    background: #2563eb;
}

/* Pagination */
.plan-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px 0;
    flex-wrap: wrap;
}

.page-btn {
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    background: white;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.page-btn.active {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.page-info {
    font-size: 12px;
    color: #9ca3af;
    padding: 0 8px;
}

.plan-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
    accent-color: #3b82f6;
}

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.status-overdue {
    background: #fecaca;
    color: #991b1b;
}

.status-pending {
    background: #fef08a;
    color: #92400e;
}

.status-paid {
    background: #d1fae5;
    color: #065f46;
}

.status-draft {
    background: #f3f4f6;
    color: #374151;
}

.balance-indicator {
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    background: #f0f9ff;
    color: #0369a1;
}

.balance-indicator.shortfall {
    background: #fef2f2;
    color: #dc2626;
}

.amount-column {
    text-align: right;
    font-weight: 600;
    font-family: 'Inter', monospace;
}

/* Expenses Table */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 16px;
    border: 2px solid #e5e7eb;
    background: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
    transition: all 0.3s ease;
}

.filter-btn.active {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

.filter-btn:hover {
    border-color: #3b82f6;
}

.search-bar {
    flex: 1;
    min-width: 250px;
    padding: 8px 16px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.3s ease;
}

.search-bar:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.table-wrapper {
    background: white;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: #f9fafb;
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 12px;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #e5e7eb;
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid #f3f4f6;
    font-size: 14px;
}

tr:hover {
    background: #f9fafb;
}

.row-number {
    color: #9ca3af;
    font-weight: 600;
}

/* Vendors Table */
.vendors-table {
    background: white;
    border-radius: 12px;
    border: 1px solid #e5e7eb;
    overflow: hidden;
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: white;
    border-radius: 12px;
    padding: 32px;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.2);
}

.modal-header {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 24px;
    color: #1f2937;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
    color: #374151;
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    font-family: 'Inter', 'Noto Sans Thai', sans-serif;
    transition: all 0.3s ease;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 28px;
}

.form-actions .btn {
    flex: 1;
}

.form-info {
    background: #f0f9ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 16px;
    font-size: 13px;
    color: #0369a1;
}

/* Toast notifications */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 14px 20px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    font-size: 14px;
    z-index: 2000;
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    background: #10b981;
}

.toast.error {
    background: #ef4444;
}

.toast.info {
    background: #3b82f6;
}

/* Loading spinner */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 300px;
    color: #6b7280;
    font-weight: 500;
}

.loading-state span {
    margin-right: 12px;
}

/* Responsive */
@media (max-width: 1200px) {
    .charts-row {
        grid-template-columns: 1fr;
    }

    .payment-item {
        grid-template-columns: 80px 130px 1fr 100px 80px;
        gap: 12px;
    }
}

@media (max-width: 768px) {
    .sidebar {
        width: 200px;
        padding: 16px 12px;
    }

    .content {
        padding: 16px;
    }

    .cash-input {
        font-size: 24px;
    }

    .header-title {
        font-size: 18px;
    }
}

/* Login Screen */
.login-screen {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    z-index: 9999;
}
.login-screen.hidden { display: none; }
.login-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-header {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 4px;
}
.login-subtitle {
    color: #6b7280;
    font-size: 14px;
    margin-bottom: 32px;
}
