:root {
    --app-bg: #f8fafc;
    --app-ink: #111827;
    --app-muted: #64748b;
    --app-border: #e2e8f0;
    --app-sidebar: #0f172a;
}

body {
    background: var(--app-bg);
    color: var(--app-ink);
}

.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1.5rem;
}

.auth-panel {
    width: min(920px, 100%);
    display: grid;
    grid-template-columns: 1fr 420px;
    gap: 2rem;
    align-items: center;
}

.auth-panel h1 {
    font-size: clamp(2rem, 5vw, 4rem);
    font-weight: 800;
    margin: 1rem 0 .5rem;
}

.auth-card,
.card {
    border-color: var(--app-border);
    border-radius: .5rem;
    box-shadow: 0 10px 30px rgba(15, 23, 42, .04);
}

.brand-mark {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: .75rem;
    display: inline-grid;
    place-items: center;
    color: #fff;
    background: var(--app-sidebar);
    font-size: 1.35rem;
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 270px 1fr;
}

.app-sidebar {
    background: var(--app-sidebar);
    color: #fff;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 10;
}

.app-brand {
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    gap: .75rem;
}

.app-sidebar .nav-link {
    color: rgba(255, 255, 255, .72);
    border-radius: .5rem;
    display: flex;
    align-items: center;
    gap: .7rem;
}

.app-sidebar .nav-link:hover,
.app-sidebar .nav-link.active {
    background: rgba(255, 255, 255, .1);
    color: #fff;
}

.sidebar-user {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, .12);
}

.sidebar-user > div:first-child {
    min-width: 0;
}

.sidebar-user-actions {
    display: flex;
    align-items: center;
    gap: .35rem;
    flex: 0 0 auto;
}

.sidebar-user-actions .btn {
    width: 2rem;
    height: 2rem;
    display: inline-grid;
    place-items: center;
    padding: 0;
}

.sidebar-user small,
.list-row small,
.metric-card small {
    display: block;
    color: var(--app-muted);
}

.sidebar-user small {
    color: rgba(255, 255, 255, .6);
}

.app-main {
    min-width: 0;
}

.app-page-header {
    min-height: 88px;
    padding: 1rem 1.5rem;
    background: #fff;
    border-bottom: 1px solid var(--app-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.header-title-row {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: .9rem;
}

.app-page-header h1 {
    font-size: 1.55rem;
    font-weight: 750;
    margin: 0;
}

.app-page-header p {
    margin: .15rem 0 0;
    color: var(--app-muted);
}

.app-header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: .5rem;
    flex-wrap: wrap;
}

.sidebar-toggle {
    display: none;
}

.metric-card,
.list-row {
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: .5rem;
    padding: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.metric-card {
    justify-content: flex-start;
}

.metric-card strong {
    display: block;
    font-size: 1.35rem;
}

.metric-card.compact strong {
    font-size: 1.15rem;
}

.metric-icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: .5rem;
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}

.metric-dot {
    width: .8rem;
    height: .8rem;
    border-radius: 50%;
    flex: 0 0 auto;
}

.icon-btn {
    width: 2rem;
    height: 2rem;
    display: inline-grid;
    place-items: center;
    padding: 0;
}

.tag-badge {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .25rem .55rem;
    border: 1px solid var(--app-border);
    border-radius: 999px;
    font-size: .85rem;
    white-space: nowrap;
}

.tag-badge span {
    width: .55rem;
    height: .55rem;
    border-radius: 50%;
    flex: 0 0 auto;
}

.form-floating > textarea.form-control {
    min-height: 6rem;
}

.form-floating > .form-control-color {
    width: 100%;
    height: calc(3.5rem + 2px);
    padding-top: 1.625rem;
    padding-bottom: .625rem;
}

.input-group > .form-floating {
    flex: 1 1 auto;
}

.chart-bars {
    min-height: 230px;
    display: grid;
    grid-template-columns: repeat(6, minmax(48px, 1fr));
    align-items: end;
    gap: .8rem;
    overflow-x: auto;
}

.chart-bar-item {
    min-width: 54px;
    display: grid;
    justify-items: center;
    gap: .45rem;
}

.bar {
    width: 100%;
    max-width: 46px;
    border-radius: .4rem .4rem 0 0;
}

.bar.positive {
    background: #16a34a;
}

.bar.negative {
    background: #dc2626;
}

.bar-value {
    font-size: .8rem;
    color: var(--app-muted);
    white-space: nowrap;
}

.pie-layout {
    display: grid;
    grid-template-columns: 180px 1fr;
    gap: 1.25rem;
    align-items: center;
}

.pie-chart {
    width: 180px;
    aspect-ratio: 1;
    border-radius: 50%;
    border: 1px solid var(--app-border);
}

.table th {
    color: var(--app-muted);
    font-weight: 650;
    font-size: .85rem;
}

.app-context-menu {
    position: fixed;
    z-index: 1080;
    min-width: 190px;
    padding: .35rem;
    background: #fff;
    border: 1px solid var(--app-border);
    border-radius: .5rem;
    box-shadow: 0 18px 45px rgba(15, 23, 42, .18);
}

@media (max-width: 900px) {
    .auth-panel {
        grid-template-columns: 1fr;
    }

    .app-shell {
        grid-template-columns: 1fr;
    }

    .app-sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: 270px;
        max-width: calc(100vw - 3rem);
        height: 100svh;
        min-height: 100dvh;
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
        transform: translateX(-100%);
        transition: transform .2s ease;
    }

    .app-sidebar.open {
        transform: translateX(0);
    }

    body.sidebar-open::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, .42);
        z-index: 9;
    }

    .sidebar-toggle {
        display: inline-grid;
        place-items: center;
        flex: 0 0 auto;
    }

    .app-page-header {
        align-items: stretch;
        flex-direction: column;
        padding: .9rem 1rem;
    }

    .header-title-row {
        width: 100%;
        align-items: flex-start;
    }

    .header-title-row > div {
        min-width: 0;
    }

    .app-page-header h1 {
        font-size: 1.3rem;
        line-height: 1.2;
    }

    .app-page-header p {
        font-size: .9rem;
    }

    .app-header-actions,
    .app-page-header > .btn:not(.sidebar-toggle) {
        width: 100%;
        justify-content: flex-start;
    }

    .app-header-actions .btn {
        flex: 1 1 auto;
    }

    .pie-layout {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .income-table-card table,
    .income-table-card thead,
    .income-table-card tbody,
    .income-table-card tr,
    .income-table-card td {
        display: block;
    }

    .income-table-card .table-responsive {
        overflow: visible;
    }

    .income-table-card thead {
        display: none;
    }

    .income-table-card tbody {
        display: grid;
        gap: .75rem;
    }

    .income-table-card tr {
        border: 1px solid var(--app-border);
        border-radius: .5rem;
        padding: .85rem;
        background: #fff;
    }

    .income-table-card td {
        border: 0;
        padding: .25rem 0;
    }

    .income-table-card td[data-label] {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 1rem;
    }

    .income-table-card td[data-label]::before {
        content: attr(data-label);
        color: var(--app-muted);
        font-size: .8rem;
        font-weight: 650;
        flex: 0 0 7.5rem;
    }

    .income-table-card td:first-child {
        padding-bottom: .6rem;
        margin-bottom: .35rem;
        border-bottom: 1px solid var(--app-border);
    }

    .income-table-card td:first-child::before {
        display: none;
    }

    .income-table-card .income-actions-cell {
        display: flex;
        justify-content: flex-end;
        padding-top: .5rem;
    }
}
