/* =====================================================================
   Spends — Personal Expense & Income Tracker
   Mobile-first design system on top of Bootstrap 5.3
   =====================================================================

   Semantic colors:
     income  → green   (--c-income)
     expense → red     (--c-expense)
     balance → blue    (--c-balance)
     savings → purple  (--c-savings)
*/

:root {
    --c-income:  #22c55e;
    --c-expense: #ef4444;
    --c-balance: #3b82f6;
    --c-savings: #8b5cf6;
    --c-primary: #4f46e5;

    --c-income-soft:  rgba(34, 197, 94, .12);
    --c-expense-soft: rgba(239, 68, 68, .12);
    --c-balance-soft: rgba(59, 130, 246, .12);
    --c-savings-soft: rgba(139, 92, 246, .12);
    --c-primary-soft: rgba(79, 70, 229, .12);

    --app-bg: #f3f4f6;
    --card-bg: #ffffff;
    --card-radius: 1rem;
    --card-shadow: 0 1px 3px rgba(17, 24, 39, .06), 0 8px 24px rgba(17, 24, 39, .05);
    --card-shadow-lg: 0 4px 12px rgba(17, 24, 39, .08), 0 12px 32px rgba(17, 24, 39, .08);

    --bottom-nav-height: 64px;
    --sidebar-width: 250px;

    --bs-body-font-family: 'Poppins', system-ui, -apple-system, sans-serif;
    --bs-primary: var(--c-primary);
}

[data-bs-theme="dark"] {
    --app-bg: #0f172a;
    --card-bg: #1e293b;
    --card-shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --card-shadow-lg: 0 4px 12px rgba(0, 0, 0, .35), 0 12px 32px rgba(0, 0, 0, .3);
    --bs-body-bg: #0f172a;
}

html { -webkit-tap-highlight-color: transparent; }

body {
    font-family: 'Poppins', system-ui, -apple-system, sans-serif;
    background-color: var(--app-bg);
    min-height: 100vh;
    font-size: .925rem;
}

/* =====================================================================
   Layout: sidebar (desktop) + main + bottom nav (mobile)
   ===================================================================== */

.app-wrapper { min-height: 100vh; }

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    padding: 1.25rem 1rem;
    z-index: 1030;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .65rem;
    text-decoration: none;
    color: var(--bs-body-color);
    font-weight: 600;
    font-size: 1.15rem;
    padding: .25rem .5rem 1.25rem;
}

.brand-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--c-primary), var(--c-savings));
    color: #fff;
    font-size: 1.15rem;
}

.sidebar-nav { display: flex; flex-direction: column; gap: .25rem; }

.sidebar-link {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .7rem .9rem;
    border-radius: .75rem;
    color: var(--bs-secondary-color);
    text-decoration: none;
    font-weight: 500;
    transition: background .15s ease, color .15s ease;
}

.sidebar-link i { font-size: 1.1rem; }

.sidebar-link:hover { background: var(--c-primary-soft); color: var(--c-primary); }

.sidebar-link.active {
    background: linear-gradient(135deg, var(--c-primary), #6366f1);
    color: #fff;
    box-shadow: 0 6px 16px rgba(79, 70, 229, .35);
}

.sidebar-logout { color: var(--c-expense); }
.sidebar-logout:hover { background: var(--c-expense-soft); color: var(--c-expense); }

.app-main { min-height: 100vh; display: flex; flex-direction: column; }

@media (min-width: 992px) {
    .app-main { margin-left: var(--sidebar-width); }
}

.app-content {
    flex: 1;
    width: 100%;
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem 1rem calc(var(--bottom-nav-height) + 2rem);
}

@media (min-width: 992px) {
    .app-content { padding: 1.5rem 2rem 3rem; }
}

/* Top bar */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1rem;
    background: color-mix(in srgb, var(--app-bg) 85%, transparent);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.topbar-title { font-weight: 600; font-size: 1.1rem; }

.topbar-actions { display: flex; align-items: center; gap: .35rem; }

.topbar-user { font-weight: 500; color: var(--bs-secondary-color); font-size: .875rem; }

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--card-bg);
    color: var(--bs-body-color);
    box-shadow: var(--card-shadow);
    font-size: 1.05rem;
}

.btn-icon:hover { background: var(--c-primary-soft); color: var(--c-primary); }

/* Bottom navigation (mobile) */
.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1030;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--card-bg);
    box-shadow: 0 -2px 16px rgba(17, 24, 39, .08);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    text-decoration: none;
    color: var(--bs-secondary-color);
    font-size: .65rem;
    font-weight: 500;
}

.bottom-nav-item i { font-size: 1.25rem; }

.bottom-nav-item.active { color: var(--c-primary); }

.bottom-nav-add {
    display: flex;
    align-items: center;
    justify-content: center;
    align-self: center;
    width: 54px;
    height: 54px;
    margin-top: -26px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--c-primary), var(--c-savings));
    color: #fff;
    font-size: 1.5rem;
    text-decoration: none;
    box-shadow: 0 8px 20px rgba(79, 70, 229, .45);
    transition: transform .15s ease;
}

.bottom-nav-add:active { transform: scale(.92); }
.bottom-nav-add:hover { color: #fff; }

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

.card {
    border: none;
    border-radius: var(--card-radius);
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 1.5rem 0 .75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.section-title .link-more {
    font-size: .8rem;
    font-weight: 500;
    text-decoration: none;
}

/* Stat / summary cards */
.stat-card {
    border-radius: var(--card-radius);
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    padding: 1rem;
    height: 100%;
    display: flex;
    align-items: center;
    gap: .85rem;
}

.stat-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    font-size: 1.2rem;
}

/* The text block must be allowed to shrink inside the flex row,
   or long amounts push past the card edge. */
.stat-card > div { flex: 1 1 auto; min-width: 0; }

.stat-label {
    font-size: .72rem;
    font-weight: 500;
    color: var(--bs-secondary-color);
    text-transform: uppercase;
    letter-spacing: .03em;
    margin-bottom: .1rem;
}

.stat-value { font-size: 1.15rem; font-weight: 600; line-height: 1.2; }

.stat-income  .stat-icon { background: var(--c-income-soft);  color: var(--c-income); }
.stat-expense .stat-icon { background: var(--c-expense-soft); color: var(--c-expense); }
.stat-balance .stat-icon { background: var(--c-balance-soft); color: var(--c-balance); }
.stat-savings .stat-icon { background: var(--c-savings-soft); color: var(--c-savings); }

.stat-income  .stat-value { color: var(--c-income); }
.stat-expense .stat-value { color: var(--c-expense); }
.stat-savings .stat-value { color: var(--c-savings); }

/* Tighter stat cards on phones so values never clip in col-6 grids */
@media (max-width: 575.98px) {
    .stat-card { padding: .8rem .75rem; gap: .6rem; }
    .stat-icon { width: 38px; height: 38px; border-radius: 12px; font-size: 1.05rem; }
    .stat-label { font-size: .62rem; letter-spacing: .02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .stat-value { font-size: 1rem; }
    .balance-hero .hero-value { font-size: 1.75rem; }
}

/* Hero balance card */
.balance-hero {
    border-radius: 1.25rem;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 55%, #a855f7 100%);
    color: #fff;
    padding: 1.5rem 1.35rem;
    box-shadow: 0 12px 32px rgba(99, 102, 241, .35);
}

.balance-hero .hero-label { font-size: .8rem; opacity: .85; font-weight: 500; }
.balance-hero .hero-value { font-size: 2rem; font-weight: 700; letter-spacing: -.02em; }
.balance-hero .hero-sub { font-size: .78rem; opacity: .9; }

/* =====================================================================
   Transaction cards
   ===================================================================== */

.tx-card {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .9rem 1rem;
    border-radius: var(--card-radius);
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    margin-bottom: .65rem;
    transition: transform .12s ease, box-shadow .12s ease;
}

.tx-card:active { transform: scale(.985); }

.tx-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    font-size: 1.15rem;
    color: #fff;
}

.tx-info { flex: 1; min-width: 0; }

.tx-title {
    font-weight: 600;
    font-size: .9rem;
    display: flex;
    align-items: center;
    gap: .45rem;
}

.tx-meta {
    font-size: .74rem;
    color: var(--bs-secondary-color);
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .2rem .55rem;
    margin-top: .1rem;
}

.tx-desc {
    font-size: .76rem;
    color: var(--bs-secondary-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: .1rem;
}

.tx-right { text-align: right; flex-shrink: 0; }

.tx-amount { font-weight: 700; font-size: .95rem; white-space: nowrap; }
.tx-amount.income  { color: var(--c-income); }
.tx-amount.expense { color: var(--c-expense); }

.tx-actions { display: flex; gap: .35rem; justify-content: flex-end; margin-top: .35rem; }

.tx-actions .btn {
    --bs-btn-padding-y: .22rem;
    --bs-btn-padding-x: .5rem;
    --bs-btn-font-size: .72rem;
    border-radius: .55rem;
}

.badge-type {
    font-size: .62rem;
    font-weight: 600;
    padding: .22em .6em;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.badge-type.income  { background: var(--c-income-soft);  color: var(--c-income); }
.badge-type.expense { background: var(--c-expense-soft); color: var(--c-expense); }

/* Category management cards */
.cat-card {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .9rem 1rem;
    border-radius: var(--card-radius);
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    margin-bottom: .65rem;
}

.cat-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    font-size: 1.15rem;
    color: #fff;
}

/* =====================================================================
   Filters
   ===================================================================== */

.chip-scroll {
    display: flex;
    flex-wrap: nowrap;
    gap: .5rem;
    overflow-x: auto;
    padding: .25rem 2px .5rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
}

.chip-scroll::-webkit-scrollbar { display: none; }

.chip-scroll > * { scroll-snap-align: start; }

/* Compact pill-shaped selects in a side-scrolling row */
.filter-scroll {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: .5rem;
    overflow-x: auto;
    padding: .25rem 2px .5rem;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}

.filter-scroll::-webkit-scrollbar { display: none; }

.select-pill {
    flex: 0 0 auto;
    width: auto;
    min-height: 42px;
    border: none;
    border-radius: 999px;
    background-color: var(--card-bg);
    background-position: right .85rem center;
    background-size: 14px 10px;
    box-shadow: var(--card-shadow);
    color: var(--bs-body-color);
    font-size: .82rem;
    font-weight: 500;
    padding: .5rem 2.4rem .5rem 1.1rem;
    cursor: pointer;
    transition: box-shadow .15s ease;
}

.select-pill:focus { box-shadow: 0 0 0 .2rem var(--c-primary-soft); }

/* Pill select with a non-default value gets the primary accent */
.select-pill.has-value {
    background-color: var(--c-primary);
    color: #fff;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    box-shadow: 0 6px 16px rgba(79, 70, 229, .35);
}

/* Filter rows bleed to the screen edge on mobile so the side-scroll
   feels natural (matches the 1rem content/card padding). */
@media (max-width: 991.98px) {
    .chip-scroll,
    .filter-scroll {
        margin-left: -1rem;
        margin-right: -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
    }
}

/* Pill search bar */
.search-bar .input-group-text {
    border: none;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    border-radius: 999px 0 0 999px;
    padding-left: 1rem;
    color: var(--bs-secondary-color);
}

.search-bar .form-control {
    border: none;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    border-radius: 0 999px 999px 0;
    min-height: 46px;
}

.search-bar .form-control:focus { box-shadow: var(--card-shadow); }

.chip {
    flex-shrink: 0;
    padding: .45rem 1rem;
    border-radius: 999px;
    border: none;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    color: var(--bs-body-color);
    font-size: .8rem;
    font-weight: 500;
    white-space: nowrap;
    transition: background .15s ease, color .15s ease;
}

.chip.active {
    background: var(--c-primary);
    color: #fff;
    box-shadow: 0 6px 16px rgba(79, 70, 229, .35);
}

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

.form-control, .form-select {
    border-radius: .75rem;
    border-color: var(--bs-border-color);
}

.form-floating > .form-control,
.form-floating > .form-select { min-height: 56px; }

.form-control:focus, .form-select:focus {
    border-color: var(--c-primary);
    box-shadow: 0 0 0 .2rem var(--c-primary-soft);
}

.btn-primary {
    --bs-btn-bg: var(--c-primary);
    --bs-btn-border-color: var(--c-primary);
    --bs-btn-hover-bg: #4338ca;
    --bs-btn-hover-border-color: #4338ca;
    --bs-btn-active-bg: #4338ca;
    --bs-btn-active-border-color: #4338ca;
}

.btn { border-radius: .75rem; }
.btn-lg { padding-top: .8rem; padding-bottom: .8rem; font-weight: 600; }

/* Income / Expense segmented toggle */
.type-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
    padding: .35rem;
    border-radius: 1rem;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
}

.type-toggle input { position: absolute; opacity: 0; pointer-events: none; }

.type-toggle label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .75rem;
    border-radius: .75rem;
    font-weight: 600;
    font-size: .9rem;
    color: var(--bs-secondary-color);
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.type-toggle input:checked + label.toggle-income  { background: var(--c-income);  color: #fff; box-shadow: 0 6px 14px rgba(34, 197, 94, .4); }
.type-toggle input:checked + label.toggle-expense { background: var(--c-expense); color: #fff; box-shadow: 0 6px 14px rgba(239, 68, 68, .4); }

/* Big amount input */
.amount-input {
    font-size: 1.6rem;
    font-weight: 700;
    text-align: center;
}

/* Icon & color pickers (categories) */
.icon-picker, .color-picker {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.icon-picker .pick, .color-picker .pick {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 2px solid transparent;
    background: var(--app-bg);
    color: var(--bs-body-color);
    font-size: 1.05rem;
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease;
}

.icon-picker .pick.active, .color-picker .pick.active {
    border-color: var(--c-primary);
    transform: scale(1.08);
}

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

.chart-card { padding: 1rem 1rem 1.25rem; }

.chart-card .chart-title { font-size: .9rem; font-weight: 600; margin-bottom: .75rem; }

.chart-container { position: relative; height: 240px; }

@media (min-width: 992px) {
    .chart-container { height: 280px; }
}

/* =====================================================================
   Misc
   ===================================================================== */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--bs-secondary-color);
}

/* Only the big illustration icon — never icons inside CTA buttons */
/*.empty-state > i { font-size: 2.5rem; opacity: .4; }*/

.empty-state .btn { font-weight: 600; padding-top: .65rem; padding-bottom: .65rem; }
.empty-state .btn i { font-size: 1em; opacity: 1; vertical-align: -.05em; }

.empty-state p { margin: .75rem 0 0; font-size: .875rem; }

.toast-container { bottom: calc(var(--bottom-nav-height) + .5rem); left: 50%; transform: translateX(-50%); }

@media (min-width: 992px) {
    .toast-container { bottom: 1rem; left: auto; right: 1rem; transform: none; }
}

.confirm-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--c-expense-soft);
    color: var(--c-expense);
    font-size: 1.5rem;
}

.modal-content { border: none; border-radius: 1.25rem; box-shadow: var(--card-shadow-lg); }

/* Let a flex item shrink so .text-truncate children can ellipsize */
.min-w-0 { min-width: 0; }

/* Subtle entry animation for cards & lists */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fade-in-up { animation: fadeInUp .25s ease both; }

@media (prefers-reduced-motion: reduce) {
    .fade-in-up { animation: none; }
}

/* Loading skeleton shimmer */
.skeleton {
    border-radius: var(--card-radius);
    background: linear-gradient(90deg, var(--card-bg) 25%, var(--app-bg) 50%, var(--card-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.2s infinite;
    height: 68px;
    margin-bottom: .65rem;
}

@keyframes shimmer {
    from { background-position: 200% 0; }
    to   { background-position: -200% 0; }
}

/* =====================================================================
   Login page
   ===================================================================== */

.login-page {
    background: linear-gradient(160deg, #4f46e5 0%, #7c3aed 50%, #0ea5e9 130%);
    min-height: 100vh;
}

.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.25rem;
}

.login-card { width: 100%; max-width: 400px; border-radius: 1.5rem; box-shadow: var(--card-shadow-lg); }

.login-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 20px;
    background: linear-gradient(135deg, var(--c-primary), var(--c-savings));
    color: #fff;
    font-size: 1.75rem;
    box-shadow: 0 10px 24px rgba(79, 70, 229, .4);
}

/* =====================================================================
   Print (used by report export)
   ===================================================================== */

@media print {
    .app-sidebar, .app-topbar, .bottom-nav, .no-print { display: none !important; }
    .app-main { margin: 0 !important; }
    body { background: #fff; }
    .card, .tx-card { box-shadow: none; border: 1px solid #ddd; }
}
