/* ==========================================================================
   BudgetFlow — design system
   ========================================================================== */

:root {
    --brand-50: #eefdf4;
    --brand-100: #d6f8e3;
    --brand-200: #b0efcc;
    --brand-300: #7ce1ae;
    --brand-400: #46cb89;
    --brand-500: #1fb16c;
    --brand-600: #149057;
    --brand-700: #127347;
    --brand-800: #125b3b;
    --brand-900: #104b32;
    --brand-950: #06291b;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --shadow-card: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px -4px rgba(15, 23, 42, .08);
    --shadow-float: 0 12px 32px -8px rgba(2, 6, 23, .18);
    --shadow-modal: 0 24px 64px -12px rgba(2, 6, 23, .4);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-top: env(safe-area-inset-top, 0px);
}

html {
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    scroll-behavior: smooth;
}

body {
    background-color: #f1f5f9;
}

/* Keep anything (long notes, wide numbers) from pushing a horizontal scrollbar,
   without breaking position:sticky (hence overflow-x: clip on supporting browsers). */
html, body {
    max-width: 100%;
    overflow-x: hidden;
}
@supports (overflow: clip) {
    html, body {
        overflow-x: clip;
    }
}

::selection {
    background: var(--brand-500);
    color: #fff;
}

button, a {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

*::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
*::-webkit-scrollbar-track {
    background: transparent;
}
*::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 8px;
    border: 2px solid transparent;
    background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
    background-clip: content-box;
}

/* ==========================================================================
   Motion
   ========================================================================== */

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    /* End at `none` (not translateY(0)): a retained transform would turn this
       element into the containing block for fixed-position modals inside it. */
    to   { opacity: 1; transform: none; }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes modalPop {
    from { opacity: 0; transform: scale(.95) translateY(10px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes spin360 {
    to { transform: rotate(360deg); }
}

.fade-in-up {
    animation: fadeInUp .35s cubic-bezier(.16, 1, .3, 1) both;
}
.fade-in {
    animation: fadeIn .25s ease-out both;
}
.modal-pop {
    animation: modalPop .24s cubic-bezier(.16, 1, .3, 1) both;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 1rem;
    box-shadow: var(--shadow-card);
    transition: box-shadow .2s ease, transform .2s ease, border-color .2s ease;
}
.card-hover:hover {
    box-shadow: var(--shadow-float);
    transform: translateY(-2px);
    border-color: #d1d9e6;
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--line);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

/* ==========================================================================
   Forms
   ========================================================================== */

input, select, textarea {
    -webkit-appearance: none;
    appearance: none;
}
input[type="date"], input[type="month"] {
    -webkit-appearance: none;
    appearance: auto;
}

/* ==========================================================================
   Tables
   ========================================================================== */

.data-table th {
    text-transform: uppercase;
    font-size: .7rem;
    letter-spacing: .06em;
    font-weight: 700;
    color: #94a3b8;
}
.data-table tbody tr {
    transition: background-color .15s ease;
}
.data-table tbody tr:hover {
    background-color: #f8fafc;
}

.tnum {
    font-variant-numeric: tabular-nums;
}

.stack-value {
    display: block;
    min-width: 0;
}

/* Responsive stacked tables (mobile) */
@media (max-width: 639px) {
    .stack-table thead {
        display: none;
    }
    .stack-table,
    .stack-table tbody,
    .stack-table tr,
    .stack-table td {
        display: block;
        width: 100%;
    }
    .stack-table tbody > tr + tr {
        border-top: 0 !important;
    }
    .stack-table tr {
        padding: .7rem 1rem;
        border-bottom: 1px solid #f1f5f9;
        background: #fff;
    }
    .stack-table tr:last-child {
        border-bottom: 0;
    }
    .stack-table td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        min-width: 0;
        padding: .28rem 0;
        text-align: right !important;
        overflow: hidden;
    }
    .stack-value {
        flex: 1 1 auto;
        text-align: right;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .stack-table td[data-empty] {
        justify-content: center;
        text-align: center !important;
        color: #94a3b8;
    }
    .stack-table td::before {
        content: attr(data-label);
        flex-shrink: 0;
        font-size: .66rem;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: .06em;
        color: #94a3b8;
    }
    .stack-table td[data-label=""]::before,
    .stack-table td[data-hide-label]::before {
        content: none;
    }
    .stack-table td[data-label=""] {
        justify-content: flex-end;
    }
    .stack-table td:first-child {
        font-size: .95rem;
        font-weight: 700;
        color: var(--ink);
        padding-bottom: .4rem;
    }
}

/* ==========================================================================
   Charts
   ========================================================================== */

.chart-box {
    position: relative;
    height: 240px;
}
.chart-box-sm {
    position: relative;
    height: 200px;
}
@media (min-width: 1024px) {
    .chart-box {
        height: 320px;
    }
    .chart-box-sm {
        height: 260px;
    }
}

/* ==========================================================================
   Modals
   ========================================================================== */

body.modal-open {
    overflow: hidden;
}

.modal-panel {
    max-height: calc(100vh - 2rem);
    max-height: calc(100dvh - 2rem);
}

/* ==========================================================================
   Toasts
   ========================================================================== */

#toast-root {
    position: fixed;
    bottom: max(1rem, calc(var(--safe-bottom) + 1rem));
    left: 50%;
    transform: translateX(-50%);
    z-index: 300;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .5rem;
    width: calc(100% - 2rem);
    max-width: 400px;
    pointer-events: none;
}
.toast {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .7rem 1.1rem;
    border-radius: .9rem;
    font-size: .875rem;
    font-weight: 600;
    color: #fff;
    box-shadow: var(--shadow-modal);
    animation: fadeInUp .25s cubic-bezier(.16, 1, .3, 1) both;
    pointer-events: auto;
}
@media (min-width: 640px) {
    #toast-root {
        top: 1rem;
        right: 1rem;
        bottom: auto;
        left: auto;
        transform: none;
        align-items: stretch;
        width: auto;
    }
}

/* ==========================================================================
   Bottom navigation (mobile)
   ========================================================================== */

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    display: flex;
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -8px 24px -12px rgba(2, 6, 23, .12);
    padding-bottom: var(--safe-bottom);
}
@media (min-width: 1024px) {
    .bottom-nav {
        display: none;
    }
}
.bottom-nav a {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: .5rem 0 .45rem;
    font-size: .62rem;
    font-weight: 600;
    color: #94a3b8;
    transition: color .15s ease, background-color .15s ease;
}
.bottom-nav a:hover {
    color: #334155;
}
.bottom-nav a.active {
    color: var(--brand-600);
}
.bottom-nav a span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.bottom-nav a svg {
    flex-shrink: 0;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn-loading {
    opacity: .75;
    pointer-events: none;
}
.btn-loading::after {
    content: "";
    display: inline-block;
    width: .9em;
    height: .9em;
    margin-left: .5em;
    vertical-align: middle;
    border: 2px solid rgba(255, 255, 255, .35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin360 .6s linear infinite;
}
