:root {
    --green-deep: #2d6a4f;
    --green-mid: #40916c;
    --green-light: #95d5b2;
    --green-pale: #d8f3dc;
    --green-bg: #f0f7f4;
    --earth: #d4a373;
    --earth-light: #fef3e6;
    --white: #ffffff;
    --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;
    --red: #dc2626;
    --red-light: #fef2f2;
    --amber: #d97706;
    --amber-light: #fffbeb;
    --blue: #2563eb;
    --blue-light: #eff6ff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1), 0 4px 6px rgba(0, 0, 0, 0.05);
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --font-display: "Georgia", "Times New Roman", serif;
    --font-body:
        -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
        "Ubuntu", sans-serif;
}

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

body {
    font-family: var(--font-body);
    background: var(--green-bg);
    color: var(--gray-800);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ========== LOGIN OVERLAY ========== */
.login-overlay {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #1b4332 0%, #2d6a4f 40%, #40916c 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition:
        opacity 0.4s,
        visibility 0.4s;
}
.login-overlay.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
.login-card {
    background: var(--white);
    border-radius: var(--radius-xl);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-lg);
    text-align: center;
}
.login-card .logo-icon {
    font-size: 3rem;
    margin-bottom: 0.5rem;
}
.login-card h1 {
    font-family: var(--font-display);
    color: var(--green-deep);
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
    letter-spacing: -0.5px;
}
.login-card .subtitle {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-bottom: 1.75rem;
}
.login-card .field {
    text-align: left;
    margin-bottom: 1rem;
}
.login-card .field label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--gray-700);
    margin-bottom: 0.35rem;
}
.login-card .field input {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 2px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: var(--font-body);
    transition: var(--transition);
    background: var(--gray-50);
}
.login-card .field input:focus {
    outline: none;
    border-color: var(--green-mid);
    box-shadow: 0 0 0 3px rgba(64, 145, 108, 0.15);
    background: var(--white);
}
.login-card .btn-login {
    width: 100%;
    padding: 0.85rem;
    background: var(--green-deep);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 0.5rem;
    letter-spacing: 0.3px;
}
.login-card .btn-login:hover {
    background: #1b4332;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}
.login-card .error-msg {
    color: var(--red);
    font-size: 0.85rem;
    margin-top: 0.75rem;
    display: none;
}
.login-card .error-msg.show {
    display: block;
}
.login-card .hint {
    margin-top: 1.25rem;
    font-size: 0.78rem;
    color: var(--gray-400);
    line-height: 1.5;
}
.login-card .hint strong {
    color: var(--gray-600);
}

/* ========== APP LAYOUT ========== */
.app-container {
    display: flex;
    min-height: 100vh;
    opacity: 0;
    transition: opacity 0.3s;
}
.app-container.visible {
    opacity: 1;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: linear-gradient(180deg, #1b4332 0%, #2d6a4f 100%);
    color: white;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
    transition: transform 0.3s;
    position: relative;
}
.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    text-align: center;
}
.sidebar-header .s-logo {
    font-size: 2rem;
    display: block;
}
.sidebar-header h2 {
    font-family: var(--font-display);
    font-size: 1.25rem;
    margin-top: 0.25rem;
    letter-spacing: -0.3px;
}
.sidebar-header .s-user {
    font-size: 0.78rem;
    opacity: 0.8;
    margin-top: 0.15rem;
}
.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.sidebar-nav button {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    width: 100%;
    padding: 0.75rem 1rem;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9rem;
    font-family: var(--font-body);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
    text-align: left;
    font-weight: 500;
}
.sidebar-nav button:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}
.sidebar-nav button.active {
    background: rgba(255, 255, 255, 0.16);
    color: white;
    font-weight: 600;
}
.sidebar-nav button .nav-icon {
    font-size: 1.2rem;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}
.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.btn-logout {
    width: 100%;
    padding: 0.65rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--font-body);
    transition: var(--transition);
    font-weight: 500;
}
.btn-logout:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 1.5rem 2rem 2rem;
    overflow-y: auto;
    max-height: 100vh;
}
.page {
    display: none;
    animation: fadeSlideIn 0.35s ease;
}
.page.active {
    display: block;
}
@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}
.page-header {
    margin-bottom: 1.5rem;
}
.page-header h2 {
    font-family: var(--font-display);
    font-size: 1.6rem;
    color: var(--green-deep);
    letter-spacing: -0.4px;
}
.page-header p {
    color: var(--gray-500);
    font-size: 0.9rem;
}

/* ========== CARDS ========== */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem 1.4rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--green-mid);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}
.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}
.stat-card.income {
    border-left-color: var(--green-mid);
}
.stat-card.expense {
    border-left-color: #e07b5a;
}
.stat-card.balance {
    border-left-color: var(--blue);
}
.stat-card.warning {
    border-left-color: var(--amber);
}
.stat-card .card-icon {
    font-size: 1.6rem;
    margin-bottom: 0.4rem;
}
.stat-card .card-label {
    font-size: 0.78rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.stat-card .card-value {
    font-size: 1.7rem;
    font-weight: 700;
    color: var(--gray-900);
    font-family: var(--font-display);
}
.stat-card .card-sub {
    font-size: 0.8rem;
    color: var(--gray-400);
    margin-top: 0.15rem;
}
.budget-bar-wrap {
    background: var(--gray-200);
    border-radius: 20px;
    height: 10px;
    margin-top: 0.6rem;
    overflow: hidden;
}
.budget-bar-fill {
    height: 100%;
    border-radius: 20px;
    transition: width 0.5s ease;
    background: var(--green-mid);
}
.budget-bar-fill.high {
    background: #e07b5a;
}
.budget-bar-fill.medium {
    background: var(--amber);
}

/* ========== TABLE ========== */
.table-container {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.table-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    align-items: center;
}
.table-toolbar select,
.table-toolbar input {
    padding: 0.5rem 0.75rem;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: var(--font-body);
    background: var(--gray-50);
    transition: var(--transition);
    min-width: 120px;
}
.table-toolbar select:focus,
.table-toolbar input:focus {
    outline: none;
    border-color: var(--green-mid);
    box-shadow: 0 0 0 2px rgba(64, 145, 108, 0.1);
}
.table-toolbar .spacer {
    flex: 1;
}
.btn {
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    font-family: var(--font-body);
    letter-spacing: 0.2px;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.btn-primary {
    background: var(--green-deep);
    color: white;
}
.btn-primary:hover {
    background: #1b4332;
    box-shadow: var(--shadow);
}
.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.78rem;
    border-radius: 6px;
}
.btn-ghost {
    background: transparent;
    color: var(--gray-600);
    border: 1px solid var(--gray-300);
}
.btn-ghost:hover {
    background: var(--gray-100);
}
.btn-danger {
    background: var(--red);
    color: white;
}
.btn-danger:hover {
    background: #b91c1c;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
table th {
    background: var(--gray-50);
    padding: 0.7rem 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--gray-600);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    border-bottom: 2px solid var(--gray-200);
}
table th:hover {
    color: var(--green-deep);
}
table th .sort-arrow {
    font-size: 0.65rem;
    margin-left: 3px;
    opacity: 0.4;
}
table th .sort-arrow.active {
    opacity: 1;
}
table td {
    padding: 0.65rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    white-space: nowrap;
}
table tbody tr {
    transition: var(--transition);
}
table tbody tr:hover {
    background: var(--green-pale);
}
.badge {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 20px;
    font-size: 0.73rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}
.badge-income {
    background: #d8f3dc;
    color: #1b4332;
}
.badge-expense {
    background: #fde8e4;
    color: #9b3d2a;
}
.actions-cell {
    display: flex;
    gap: 0.35rem;
}
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--gray-400);
}
.empty-state .empty-icon {
    font-size: 3rem;
    margin-bottom: 0.75rem;
}

/* ========== MODAL ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition:
        opacity 0.25s,
        visibility 0.25s;
}
.modal-overlay.open {
    opacity: 1;
    visibility: visible;
}
.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}
@keyframes modalIn {
    from {
        transform: scale(0.94);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}
.modal h3 {
    font-family: var(--font-display);
    color: var(--green-deep);
    margin-bottom: 1.25rem;
    font-size: 1.25rem;
}
.modal .form-group {
    margin-bottom: 1rem;
}
.modal .form-group label {
    display: block;
    font-weight: 600;
    font-size: 0.82rem;
    color: var(--gray-600);
    margin-bottom: 0.3rem;
}
.modal .form-group input,
.modal .form-group select,
.modal .form-group textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font-body);
    transition: var(--transition);
    background: var(--gray-50);
}
.modal .form-group input:focus,
.modal .form-group select:focus,
.modal .form-group textarea:focus {
    outline: none;
    border-color: var(--green-mid);
    box-shadow: 0 0 0 3px rgba(64, 145, 108, 0.1);
    background: var(--white);
}
.modal .form-group textarea {
    resize: vertical;
    min-height: 60px;
}
.type-toggle {
    display: flex;
    gap: 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 2px solid var(--gray-200);
}
.type-toggle button {
    flex: 1;
    padding: 0.6rem;
    border: none;
    background: var(--white);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
    font-family: var(--font-body);
    transition: var(--transition);
    color: var(--gray-500);
}
.type-toggle button.selected-income {
    background: var(--green-mid);
    color: white;
}
.type-toggle button.selected-expense {
    background: #e07b5a;
    color: white;
}
.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ========== REPORTS ========== */
.charts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}
.chart-card {
    background: var(--white);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}
.chart-card h4 {
    font-family: var(--font-display);
    color: var(--green-deep);
    margin-bottom: 0.75rem;
    font-size: 1rem;
}
.chart-card canvas {
    max-height: 280px;
}
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: var(--white);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.comparison-table th,
.comparison-table td {
    padding: 0.6rem 1rem;
    text-align: right;
    border-bottom: 1px solid var(--gray-100);
}
.comparison-table th:first-child,
.comparison-table td:first-child {
    text-align: left;
    font-weight: 600;
}
.comparison-table th {
    background: var(--gray-50);
    color: var(--gray-600);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
}
.diff-positive {
    color: var(--green-mid);
    font-weight: 600;
}
.diff-negative {
    color: var(--red);
    font-weight: 600;
}

/* ========== TOAST ========== */
.toast-container {
    position: fixed;
    top: 1.25rem;
    right: 1.25rem;
    z-index: 600;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    background: var(--gray-900);
    color: white;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation:
        toastIn 0.35s ease,
        toastOut 0.3s ease 2.5s forwards;
    pointer-events: auto;
    max-width: 380px;
}
.toast.success {
    border-left: 4px solid var(--green-mid);
}
.toast.error {
    border-left: 4px solid var(--red);
}
@keyframes toastIn {
    from {
        transform: translateX(120%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}
@keyframes toastOut {
    from {
        opacity: 1;
    }
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* ========== MOBILE ========== */
.hamburger {
    display: none;
    background: none;
    border: none;
    font-size: 1.6rem;
    cursor: pointer;
    color: var(--green-deep);
    padding: 0.4rem;
    line-height: 1;
}
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        width: 260px;
        z-index: 200;
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 150;
    }
    .sidebar-backdrop.show {
        display: block;
    }
    .hamburger {
        display: inline-block;
    }
    .main-content {
        padding: 1rem;
    }
    .charts-grid {
        grid-template-columns: 1fr;
    }
    .cards-grid {
        grid-template-columns: 1fr 1fr;
        gap: 0.6rem;
    }
    .stat-card .card-value {
        font-size: 1.3rem;
    }
    table {
        font-size: 0.75rem;
    }
    table th,
    table td {
        padding: 0.45rem 0.5rem;
    }
    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .table-toolbar select,
    .table-toolbar input {
        min-width: auto;
    }
    .modal {
        margin: 0.75rem;
        max-width: none;
        border-radius: var(--radius);
    }
}
@media (max-width: 420px) {
    .cards-grid {
        grid-template-columns: 1fr;
    }
    .stat-card {
        padding: 1rem;
    }
    .stat-card .card-value {
        font-size: 1.2rem;
    }
}
