* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --color-primary: #2EB67D;
    --color-primary-dark: #248f5f;
    --color-primary-light: #3CB371;
    --color-primary-bg: #E6F7F1;
    --color-white: #FFFFFF;
    --color-gray-50: #FAFAFA;
    --color-gray-100: #F8F9FA;
    --color-gray-200: #E9ECEF;
    --color-gray-300: #DEE2E6;
    --color-gray-400: #CED4DA;
    --color-gray-500: #ADB5BD;
    --color-gray-600: #6C757D;
    --color-gray-700: #495057;
    --color-gray-800: #343A40;
    --color-gray-900: #212529;
    --color-danger: #DC3545;
    --color-success: #28A745;
    --color-warning: #FFC107;
    --color-info: #17A2B8;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 20px rgba(0,0,0,0.1);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

body {
    font-family: 'Noto Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--color-gray-50);
    color: var(--color-gray-800);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ==================== SCREEN MANAGEMENT ==================== */
.screen {
    display: none;
}

.screen.active {
    display: block;
}

/* ==================== LOGIN SCREEN ==================== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-light) 100%);
    padding: 1rem;
}

.login-card {
    background: var(--color-white);
    padding: 3rem 2.5rem;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-card .logo {
    font-size: 5rem;
    margin-bottom: 1rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.login-card h1 {
    font-size: 1.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--color-gray-900);
}

.login-card .subtitle {
    color: var(--color-gray-600);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.login-footer {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-gray-200);
    color: var(--color-gray-500);
}

/* ==================== FORM ELEMENTS ==================== */
.form-group {
    margin-bottom: 1.25rem;
    text-align: left;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--color-gray-700);
    font-size: 0.9rem;
}

input, select, textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--color-gray-300);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.3s;
    background: var(--color-white);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-bg);
}

input:disabled, select:disabled, textarea:disabled {
    background: var(--color-gray-100);
    cursor: not-allowed;
}

textarea {
    resize: vertical;
    min-height: 80px;
}

/* ==================== BUTTONS ==================== */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: var(--color-white);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(46, 182, 125, 0.3);
}

.btn-secondary {
    background: var(--color-gray-300);
    color: var(--color-gray-800);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-gray-400);
}

.btn-danger {
    background: var(--color-danger);
    color: var(--color-white);
}

.btn-danger:hover:not(:disabled) {
    background: #c82333;
}

.btn-success {
    background: var(--color-success);
    color: var(--color-white);
}

.btn-success:hover:not(:disabled) {
    background: #218838;
}

.btn-warning {
    background: var(--color-warning);
    color: var(--color-gray-900);
}

.btn-warning:hover:not(:disabled) {
    background: #e0a800;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
}

.btn-outline:hover:not(:disabled) {
    background: var(--color-primary);
    color: var(--color-white);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
}

.btn-lg {
    padding: 1rem 2rem;
    font-size: 1.125rem;
}

/* ==================== MAIN LAYOUT ==================== */
#main-screen {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 280px;
    background: var(--color-white);
    box-shadow: var(--shadow-md);
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 2rem 1.5rem;
    text-align: center;
    border-bottom: 1px solid var(--color-gray-200);
}

.sidebar-header .logo {
    font-size: 3.5rem;
    margin-bottom: 0.5rem;
}

.sidebar-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-gray-900);
}

.nav-menu {
    list-style: none;
    padding: 1rem 0;
    flex: 1;
}

.nav-menu li a {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    color: var(--color-gray-600);
    text-decoration: none;
    transition: all 0.3s;
    font-weight: 500;
}

.nav-menu li a .icon {
    font-size: 1.5rem;
}

.nav-menu li a:hover {
    background: var(--color-primary-bg);
    color: var(--color-primary);
}

.nav-menu li a.active {
    background: var(--color-primary-bg);
    color: var(--color-primary);
    border-right: 4px solid var(--color-primary);
}

.sidebar-footer {
    padding: 1.5rem;
    border-top: 1px solid var(--color-gray-200);
    background: var(--color-gray-50);
}

.user-info {
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--color-gray-600);
    text-align: center;
}

.main-content {
    margin-left: 280px;
    flex: 1;
    padding: 2rem;
    padding-bottom: 100px;
    max-width: 1600px;
}

.bottom-nav {
    display: none;
}

/* ==================== CARDS ==================== */
.card {
    background: var(--color-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid var(--color-gray-100);
}

.card-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--color-gray-900);
}

.card-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-gray-800);
}

/* Stats Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--color-white);
    padding: 1.75rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--color-gray-300);
    transition: all 0.3s;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-card h3 {
    font-size: 0.875rem;
    color: var(--color-gray-600);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.stat-card .value {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--color-gray-900);
    margin-bottom: 0.5rem;
}

.stat-card .sub-value {
    font-size: 0.875rem;
    color: var(--color-gray-600);
}

.stat-card.income {
    border-left-color: var(--color-success);
}

.stat-card.income .value {
    color: var(--color-success);
}

.stat-card.expense {
    border-left-color: var(--color-danger);
}

.stat-card.expense .value {
    color: var(--color-danger);
}

.stat-card.profit {
    border-left-color: var(--color-primary);
}

.stat-card.profit .value {
    color: var(--color-primary);
}

/* ==================== TABLES ==================== */
.table-container {
    overflow-x: auto;
    margin: 1rem 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.95rem;
}

thead {
    background: var(--color-gray-100);
}

th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--color-gray-700);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid var(--color-gray-300);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--color-gray-200);
}

td .flex {
    display: flex;
}

tbody tr {
    transition: background 0.2s;
}

tbody tr:hover {
    background: var(--color-gray-50);
}

.text-right {
    text-align: right;
}

.text-center {
    text-align: center;
}

/* ==================== BADGES ==================== */
.badge {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.badge-success {
    background: #D4EDDA;
    color: #155724;
}

.badge-danger {
    background: #F8D7DA;
    color: #721C24;
}

.badge-warning {
    background: #FFF3CD;
    color: #856404;
}

.badge-info {
    background: #D1ECF1;
    color: #0C5460;
}

/* ==================== FORM LAYOUTS ==================== */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--color-gray-200);
}

/* ==================== LOADING & TOAST ==================== */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay.hidden {
    display: none;
}

.spinner {
    border: 4px solid var(--color-gray-300);
    border-top: 4px solid var(--color-primary);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-overlay p {
    color: var(--color-white);
    margin-top: 1rem;
    font-weight: 500;
}

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
}

.toast {
    background: var(--color-white);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    margin-bottom: 0.5rem;
    min-width: 300px;
    animation: slideIn 0.3s ease;
    border-left: 4px solid var(--color-primary);
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast.success {
    border-left-color: var(--color-success);
}

.toast.error {
    border-left-color: var(--color-danger);
}

.toast.warning {
    border-left-color: var(--color-warning);
}

/* ==================== ERROR MESSAGE ==================== */
.error-message {
    color: var(--color-danger);
    margin-top: 1rem;
    font-size: 0.875rem;
    padding: 0.75rem;
    background: #F8D7DA;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--color-danger);
    display: none;
}

.error-message:not(:empty) {
    display: block;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-gray-500);
}

.empty-state .icon {
    font-size: 4rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* ==================== UTILITIES ==================== */
.hidden { display: none !important; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
.flex { display: flex; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.items-center { align-items: center; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-bottom: 80px;
    }

    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--color-white);
        box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
        z-index: 100;
        padding: 0.5rem 0;
    }

    .bottom-nav a {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0.5rem;
        color: var(--color-gray-600);
        text-decoration: none;
        font-size: 0.75rem;
        transition: all 0.3s;
    }

    .bottom-nav a .icon {
        font-size: 1.5rem;
        margin-bottom: 0.25rem;
    }

    .bottom-nav a.active {
        color: var(--color-primary);
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .btn {
        width: 100%;
    }

    table {
        font-size: 0.875rem;
    }

    th, td {
        padding: 0.75rem 0.5rem;
    }

    td .flex {
        flex-direction: column;
    }

    .btn-sm {
        width: 100%;
        margin-bottom: 0.25rem;
    }

    .card {
        padding: 1rem;
    }

    .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .toast-container {
        left: 10px;
        right: 10px;
    }

    .toast {
        min-width: auto;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 2rem 1.5rem;
    }

    .stat-card .value {
        font-size: 1.75rem;
    }

    h1 {
        font-size: 1.5rem;
    }

    h2 {
        font-size: 1.25rem;
    }
}

/* ==================== ADDITIONAL UTILITIES ==================== */
.btn-warning {
    background: var(--color-warning);
    color: var(--color-gray-900);
}

.btn-warning:hover:not(:disabled) {
    background: #e0a800;
}

.badge-warning {
    background: #FFF3CD;
    color: #856404;
}

/* ==================== TABLE ACTIONS ==================== */
.btn-sm {
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
}

td .flex {
    display: flex;
}

/* ==================== FILTER SECTION ==================== */
.card h3 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-gray-800);
}

/* ==================== RESPONSIVE UPDATES ==================== */
@media (max-width: 768px) {
    td .flex {
        flex-direction: column;
    }
    
    .btn-sm {
        width: 100%;
        margin-bottom: 0.25rem;
    }
}

/* ==================== PRINT STYLES ==================== */
@media print {
    body * {
        visibility: hidden;
    }
    
    #report-content, #report-content * {
        visibility: visible;
    }
    
    #report-content {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        box-shadow: none !important;
    }
    
    .btn, button, .card:not(#report-content) {
        display: none !important;
    }
    
    .sidebar, .bottom-nav {
        display: none !important;
    }
    
    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
}
