@import url('https://fonts.googleapis.com/css2?family=Mozilla+Text:wght@200..700&display=swap');

:root {
    --bg: #e6e9ef;
    --text: #181818;
    --text-dim: #8891a5;
    --accent: #181818;
    --shadow-dark: #c3c9d6;
    --shadow-light: #ffffff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    font-family: "Mozilla Text", sans-serif;
    overflow-x: hidden;
    overflow-y: auto;
}

.navbar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 28px;
    padding: 14px 26px;
    background: var(--bg);
    box-shadow:
        9px 9px 18px var(--shadow-dark),
        -9px -9px 18px var(--shadow-light);
    text-transform: uppercase;
    position: sticky;
    top: 0;
    z-index: 100;
    width: 100%;
}

.nav-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: 14px;
    background: var(--bg);
    color: var(--text-dim);
    text-decoration: none;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.2px;
    cursor: pointer;
    user-select: none;
    box-shadow:
        6px 6px 12px var(--shadow-dark),
        -6px -6px 12px var(--shadow-light);
    transition: box-shadow 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

.nav-item svg {
    width: 17px;
    height: 17px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nav-item:hover {
    color: var(--accent);
    transform: translateY(-1px);
}

.nav-item:active {
    transform: translateY(0);
    box-shadow:
        inset 5px 5px 10px var(--shadow-dark),
        inset -5px -5px 10px var(--shadow-light);
}

.nav-item.active {
    color: var(--accent);
    box-shadow:
        inset 5px 5px 10px var(--shadow-dark),
        inset -5px -5px 10px var(--shadow-light);
}

main {
    min-height: calc(100vh - 70px);
    display: flex;
    justify-content: center;
    padding: 20px 0;
}

main h2 {
    text-transform: uppercase;
    font-family: "Mozilla Text", sans-serif;
    font-optical-sizing: auto;
    font-weight: 500;
}

.page {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
    padding: 40px 20px;
    width: 100%;
}

.panel {
    max-height: 660px;
    width: 100%;
    max-width: 580px;
    padding: 26px;
    border-radius: 22px;
    background: var(--bg);
    box-shadow:
        9px 9px 18px var(--shadow-dark),
        -9px -9px 18px var(--shadow-light);
    overflow-y: auto;
}

.input-row {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}

.field {
    flex: 1;
    min-width: 0;
    padding: 12px 16px;
    border: none;
    border-radius: 14px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    box-shadow:
        inset 4px 4px 8px var(--shadow-dark),
        inset -4px -4px 8px var(--shadow-light);
    outline: none;
    transition: box-shadow 0.18s ease;
}

.field::placeholder {
    color: var(--text-dim);
}

.field:focus {
    box-shadow:
        inset 5px 5px 10px var(--shadow-dark),
        inset -5px -5px 10px var(--shadow-light),
        0 0 0 2px rgba(91, 110, 232, 0.25);
}

.btn {
    padding: 12px 20px;
    border: none;
    border-radius: 14px;
    background: var(--bg);
    color: var(--accent);
    font-size: 14px;
    font-weight: 700;
    font-family: inherit;
    cursor: pointer;
    box-shadow:
        6px 6px 12px var(--shadow-dark),
        -6px -6px 12px var(--shadow-light);
    transition: box-shadow 0.15s ease, transform 0.15s ease;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
    box-shadow:
        inset 5px 5px 10px var(--shadow-dark),
        inset -5px -5px 10px var(--shadow-light);
}

.btn.cancel {
    color: var(--text-dim);
    display: none;
}

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

thead,
tbody {
    display: block;
    width: 100%;
}

thead tr,
tbody tr {
    display: grid;
    grid-template-columns: 1fr 110px 88px;
    align-items: center;
}

thead th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-dim);
    padding: 0 14px 10px;
    font-weight: 700;
}

thead th:last-child {
    text-align: right;
}

tbody tr {
    background: var(--bg);
    box-shadow:
        inset 3px 3px 6px var(--shadow-dark),
        inset -3px -3px 6px var(--shadow-light);
    border-radius: 14px;
}

tbody tr+tr {
    margin-top: 10px;
}

tbody td {
    padding: 14px;
    font-size: 14px;
    color: var(--text);
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
}

.row-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.icon-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 10px;
    background: var(--bg);
    cursor: pointer;
    color: var(--text-dim);
    box-shadow:
        4px 4px 8px var(--shadow-dark),
        -4px -4px 8px var(--shadow-light);
    transition: box-shadow 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
    color: var(--accent);
}

.icon-btn:active {
    box-shadow:
        inset 3px 3px 6px var(--shadow-dark),
        inset -3px -3px 6px var(--shadow-light);
}

.icon-btn svg {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.empty-state {
    text-align: center;
    padding: 24px;
    color: var(--text-dim);
    font-size: 13px;
}

.type-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.type-badge.income {
    color: #2f9e6e;
    background: rgba(47, 158, 110, 0.12);
}

.type-badge.expense {
    color: #d9534f;
    background: rgba(217, 83, 79, 0.12);
}

.field-error {
    color: #d9534f;
    font-size: 12px;
    margin: -12px 0 16px;
    display: none;
}

select.field {
    flex: 0 0 140px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238891a5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    background-size: 14px;
    padding-right: 36px;
    cursor: pointer;
}

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

.page-indicator {
    font-size: 13px;
    color: var(--text-dim);
    font-weight: 600;
    min-width: 96px;
    text-align: center;
}

.icon-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    color: var(--text-dim);
}

.icon-btn:disabled:hover {
    color: var(--text-dim);
}

.icon-btn:disabled:active {
    box-shadow:
        4px 4px 8px var(--shadow-dark),
        -4px -4px 8px var(--shadow-light);
}

.toast {
    position: fixed;
    bottom: 28px;
    left: 28px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 20px;
    border-radius: 14px;
    background: var(--bg);
    box-shadow:
        8px 8px 16px var(--shadow-dark),
        -8px -8px 16px var(--shadow-light);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    border-left: 4px solid transparent;
    opacity: 0;
    transform: translateY(16px);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    z-index: 1000;
    max-width: 320px;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast.success {
    border-left-color: #2f9e6e;
}

.toast.error {
    border-left-color: #d9534f;
}

.toast-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

.toast.success .toast-icon {
    stroke: #2f9e6e;
}

.toast.error .toast-icon {
    stroke: #d9534f;
}

.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn:disabled:hover {
    transform: none;
}

.field:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.loading-row {
    display: block !important;
    background: transparent !important;
    box-shadow: none !important;
}

.loading-row td {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 24px 14px;
    color: var(--text-dim);
    font-size: 13px;
    white-space: nowrap;
}

.loading-spinner {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--shadow-dark);
    border-top-color: var(--accent);
    animation: spin 0.7s linear infinite;
}

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

.txn-table thead tr,
.txn-table tbody tr {
    grid-template-columns: 130px 1fr 100px 100px 88px;
}

.txn-table tbody td:nth-child(3) {
    overflow: visible;
    text-overflow: clip;
}

.amount {
    font-weight: 700;
    text-align: right;
    display: block;
}

.amount.income {
    color: #2f9e6e;
}

.amount.expense {
    color: #d9534f;
}

.txn-desc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 20px;
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 18px;
    border-radius: 16px;
    background: var(--bg);
    box-shadow:
        inset 4px 4px 8px var(--shadow-dark),
        inset -4px -4px 8px var(--shadow-light);
}

.stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-dim);
    font-weight: 700;
}

.stat-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
}

.stat-card.income .stat-value {
    color: #2f9e6e;
}

.stat-card.expense .stat-value {
    color: #d9534f;
}

.stat-card.balance .stat-value {
    color: var(--accent);
}

.report-table thead tr,
.report-table tbody tr {
    grid-template-columns: 1fr 100px 110px;
}

.report {
    max-height: 700px;
    width: 100%;
    max-width: 540px;
    padding: 26px;
    border-radius: 22px;
    background: var(--bg);
    box-shadow:
        9px 9px 18px var(--shadow-dark),
        -9px -9px 18px var(--shadow-light);
    overflow-y: auto;
}

.range-filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}

.range-btn {
    color: var(--text-dim);
}

.range-btn.active {
    color: var(--accent);
    box-shadow:
        inset 5px 5px 10px var(--shadow-dark),
        inset -5px -5px 10px var(--shadow-light);
}

.login-main {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-panel {
    width: 100%;
    max-width: 360px;
}

.login-panel h2 {
    text-align: center;
    margin-bottom: 20px;
}

.login-panel .input-row {
    margin-bottom: 14px;
}

/* Mobile Responsive Optimizations */

@media (max-width: 640px) {
    .navbar {
        gap: 12px;
        padding: 10px 14px;
        overflow-x: auto;
        justify-content: flex-start;
        -webkit-overflow-scrolling: touch;
    }

    .nav-item {
        padding: 8px 14px;
        font-size: 13px;
        flex-shrink: 0;
    }

    .page {
        padding: 20px 12px;
        gap: 20px;
    }

    .panel,
    .report {
        padding: 16px;
        border-radius: 16px;
        max-height: none;
    }

    .input-row {
        flex-direction: column;
        gap: 12px;
    }

    select.field {
        flex: 1 1 auto;
        width: 100%;
    }

    .btn {
        width: 100%;
    }

    /* Standard Table Mobile Layout */
    thead tr,
    tbody tr {
        grid-template-columns: 1fr 80px 76px;
    }

    tbody td {
        padding: 10px 8px;
        font-size: 13px;
    }

    /* Transaction Table Mobile Layout */
    .txn-table thead tr,
    .txn-table tbody tr {
        grid-template-columns: 90px 1fr 70px 75px 40px;
    }

    /* Report Table Mobile Layout */
    .report-table thead tr,
    .report-table tbody tr {
        grid-template-columns: 1fr 75px 85px;
    }

    .toast {
        left: 16px;
        right: 16px;
        bottom: 16px;
        max-width: calc(100vw - 32px);
    }
}

@media (max-width: 560px) {
    .stat-cards {
        grid-template-columns: 1fr;
    }

    .range-filters {
        justify-content: center;
    }

    .range-filters .btn {
        flex: 1 1 calc(50% - 10px);
    }
}