:root {
    --ss-primary: #5b3df5;
    --ss-primary-dark: #4a2fd6;
    --ss-accent: #16c79a;
    --ss-danger: #e7536d;
    --ss-bg: #f5f5fb;
    --ss-card: #ffffff;
    --ss-text: #1d1d2e;
    --ss-muted: #6c6f88;
    --ss-border: #ebebf3;
    --ss-shadow: 0 6px 24px rgba(31, 23, 67, .08);
    --ss-radius: 18px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background: var(--ss-bg);
    color: var(--ss-text);
    -webkit-tap-highlight-color: transparent;
    padding-bottom: env(safe-area-inset-bottom);
}

.bg-app { background: var(--ss-bg); }
a { color: var(--ss-primary); }
a:hover { color: var(--ss-primary-dark); }

.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.app-main { flex: 1; padding-bottom: 80px; }

/* Top bar */
.app-topbar {
    background: linear-gradient(135deg, var(--ss-primary), #7c5cff);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 1020;
}
.app-topbar .brand, .app-topbar .brand:hover { color: #fff; font-weight: 700; }
.brand-logo {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: 12px;
    background: rgba(255,255,255,.18);
    font-size: 1.1rem;
}

/* Avatar */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #ffd6e8, #c9b6ff);
    color: #fff;
    font-weight: 700;
    border-radius: 50%;
    width: 40px; height: 40px;
    background: var(--ss-primary);
    overflow: hidden;
}
.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}
.avatar-sm { width: 32px; height: 32px; font-size: .9rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.3rem; }

/* Cards */
.card {
    border: 1px solid var(--ss-border);
    border-radius: var(--ss-radius);
    background: var(--ss-card);
    box-shadow: var(--ss-shadow);
}
.card-flat {
    border: 1px solid var(--ss-border);
    border-radius: var(--ss-radius);
    background: var(--ss-card);
    box-shadow: none;
}
.section-title {
    font-size: .8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--ss-muted);
    margin: 1.25rem 0 .5rem;
}

/* Buttons */
.btn-primary {
    background: var(--ss-primary);
    border-color: var(--ss-primary);
}
.btn-primary:hover, .btn-primary:focus {
    background: var(--ss-primary-dark);
    border-color: var(--ss-primary-dark);
}
.btn-outline-primary {
    color: var(--ss-primary);
    border-color: var(--ss-primary);
}
.btn-outline-primary:hover { background: var(--ss-primary); border-color: var(--ss-primary); }
.btn { border-radius: 12px; font-weight: 600; }
.btn-lg { padding: .8rem 1.2rem; }

/* Forms */
.form-control, .form-select {
    border-radius: 12px;
    border-color: var(--ss-border);
    padding: 5px 3px;
}
.form-control:focus, .form-select:focus {
    border-color: var(--ss-primary);
    box-shadow: 0 0 0 .2rem rgba(91, 61, 245, .15);
}
.form-label { font-weight: 600; font-size: .9rem; color: var(--ss-text); }

/* Group cards */
.group-card {
    display: flex;
    align-items: center;
    gap: .9rem;
    padding: 1rem;
    border-radius: var(--ss-radius);
    background: var(--ss-card);
    border: 1px solid var(--ss-border);
    text-decoration: none;
    color: inherit;
    transition: transform .2s ease, box-shadow .2s ease;
}
.group-card:hover { transform: translateY(-2px); box-shadow: var(--ss-shadow); color: inherit; }
.group-cover {
    width: 56px; height: 56px;
    border-radius: 14px;
    background: linear-gradient(135deg, #7c5cff, #16c79a);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 1.2rem;
    background-size: cover; background-position: center;
}
.group-card .meta { font-size: .85rem; color: var(--ss-muted); }
.balance-pos { color: var(--ss-accent); font-weight: 700; }
.balance-neg { color: var(--ss-danger); font-weight: 700; }
.balance-zero { color: var(--ss-muted); font-weight: 600; }

/* Member chips */
.member-chip {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    background: var(--ss-bg);
    border: 1px solid var(--ss-border);
    border-radius: 999px;
    padding: .25rem .7rem;
    font-size: .85rem;
    font-weight: 500;
}

/* Bottom bar */
.app-bottombar {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    background: #fff;
    border-top: 1px solid var(--ss-border);
    padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom));
    z-index: 1020;
    box-shadow: 0 -4px 12px rgba(0,0,0,.05);
}
.bottom-link, .bottom-link-form button {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: var(--ss-muted);
    font-size: .72rem;
    background: none;
    border: 0;
    padding: .35rem .5rem;
    gap: 2px;
}
.bottom-link i { font-size: 1.2rem; }
.bottom-link.active { color: var(--ss-primary); }
.bottom-link-fab {
    background: var(--ss-primary);
    color: #fff !important;
    width: 48px; height: 48px;
    border-radius: 50%;
    justify-content: center;
    box-shadow: 0 6px 16px rgba(91, 61, 245, .35);
}
.bottom-link-fab i { font-size: 1.4rem; }
.bottom-link-form { margin: 0; }

/* Scrollable tab nav with shadow indicators */
.nav-tabs-scroll {
    position: relative;
}
.nav-tabs-scroll > .nav-tabs {
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.nav-tabs-scroll > .nav-tabs::-webkit-scrollbar { display: none; }
.nav-tabs-scroll > .nav-tabs .nav-item { flex: 0 0 auto; }
.nav-tabs-scroll > .nav-tabs .nav-link { white-space: nowrap; }
.nav-tabs-scroll::before,
.nav-tabs-scroll::after {
    content: "";
    position: absolute;
    top: 0; bottom: 0;
    width: 24px;
    pointer-events: none;
    opacity: 0;
    transition: opacity .15s ease;
    z-index: 2;
}
.nav-tabs-scroll::before {
    left: 0;
    background: linear-gradient(to right, rgba(31, 23, 67, .18), rgba(31, 23, 67, 0));
}
.nav-tabs-scroll::after {
    right: 0;
    background: linear-gradient(to left, rgba(31, 23, 67, .18), rgba(31, 23, 67, 0));
}
.nav-tabs-scroll.has-overflow-start::before { opacity: 1; }
.nav-tabs-scroll.has-overflow-end::after { opacity: 1; }
.has-overflow-end {
    margin-right: -12px;
}
.has-overflow-start {
    margin-left: -12px;
}

/* Split form */
.split-row {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .7rem .8rem;
    border-bottom: 1px solid var(--ss-border);
}
.split-row:last-child { border-bottom: 0; }
.split-row .form-control { max-width: 130px; }
.split-row .name { flex: 1; font-weight: 500; }
.split-summary {
    position: sticky;
    bottom: 20px;
    background: #fff;
    border-top: 1px solid var(--ss-border);
    padding: .8rem 1rem;
    border-radius: var(--ss-radius);
    box-shadow: 0 -12px 28px rgba(31, 23, 67, .18), 0 -2px 6px rgba(31, 23, 67, .08);
    margin-top: 2rem;
}
.split-remaining-ok { color: var(--ss-accent); }
.split-remaining-bad { color: var(--ss-danger); }

/* Split type tabs */
.split-tabs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: .4rem;
    margin-bottom: 1rem;
}
.split-tab {
    border: 1px solid var(--ss-border);
    border-radius: 12px;
    background: #fff;
    text-align: center;
    padding: .55rem .25rem;
    font-size: .8rem;
    font-weight: 600;
    color: var(--ss-muted);
    cursor: pointer;
    transition: all .15s ease;
}
.split-tab i { display: block; font-size: 1.1rem; margin-bottom: 2px; }
.split-tab.active {
    background: var(--ss-primary);
    color: #fff;
    border-color: var(--ss-primary);
}

/* Expense row */
.expense-row {
    display: flex;
    align-items: center;
    gap: .85rem;
    padding: .9rem 1rem;
    border-bottom: 1px solid var(--ss-border);
    background: #fff;
    text-decoration: none;
    color: inherit;
}
.expense-row:last-child { border-bottom: 0; }
.expense-row:hover { background: #fafaff; color: inherit; }
.expense-icon {
    width: 42px; height: 42px;
    background: rgba(91, 61, 245, .1);
    color: var(--ss-primary);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.expense-row .desc { font-weight: 600; }
.expense-row .meta { font-size: .8rem; color: var(--ss-muted); }
.expense-row .amount { font-weight: 700; }

/* Auth pages */
.auth-shell {
    min-height: 100vh;
    background: linear-gradient(135deg, #5b3df5, #16c79a);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.auth-card {
    width: 100%;
    max-width: 420px;
    background: #fff;
    border-radius: 22px;
    padding: 1.75rem 1.5rem;
    box-shadow: 0 24px 60px rgba(31, 23, 67, .25);
}
.auth-card h1 { font-weight: 800; }

/* Welcome page */
.hero {
    min-height: 100vh;
    background: radial-gradient(circle at top left, #7c5cff, transparent 50%),
                radial-gradient(circle at bottom right, #16c79a, transparent 50%),
                #1d1d2e;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    text-align: center;
}
.hero h1 { font-weight: 800; font-size: clamp(2rem, 6vw, 3.5rem); }
.hero p.lead { color: rgba(255,255,255,.85); max-width: 600px; margin: 1rem auto; }
.hero .feature {
    background: rgba(255,255,255,.08);
    backdrop-filter: blur(8px);
    border: 1px solid rgba(255,255,255,.18);
    border-radius: var(--ss-radius);
    padding: 1.2rem;
    color: #fff;
    height: 100%;
}
.hero .feature i { font-size: 1.6rem; color: #ffe066; }

/* Helpers */
.text-muted-2 { color: var(--ss-muted); }
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--ss-muted);
}
.empty-state i.bi-collection { font-size: 3rem; color: var(--ss-primary); opacity: .4; }

.list-card { background: #fff; border-radius: var(--ss-radius); border: 1px solid var(--ss-border); overflow: hidden; }

/* Animations */
@keyframes pop { from { transform: scale(.96); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.pop-in { animation: pop .25s ease both; }

.text-truncate {
    max-width: 150px;
}

/* Alerts */
.alert {
    --alert-bg: #fff;
    --alert-fg: var(--ss-text);
    --alert-accent: var(--ss-primary);
    position: relative;
    border: 1px solid var(--ss-border);
    border-left: 4px solid var(--alert-accent);
    border-radius: 14px;
    background: var(--alert-bg);
    color: var(--alert-fg);
    box-shadow: var(--ss-shadow);
    padding: .85rem 2.5rem .85rem 1rem;
    display: flex;
    align-items: flex-start;
    gap: .65rem;
    font-size: .92rem;
}
.alert::before {
    font-family: 'bootstrap-icons';
    font-size: 1.1rem;
    line-height: 1.3;
    color: var(--alert-accent);
    flex-shrink: 0;
}
.alert > ul { margin: 0; padding-left: 1.1rem; }
.alert > ul:only-child { padding-left: 1.1rem; }
.alert .btn-close {
    position: absolute;
    top: .75rem;
    right: .75rem;
    padding: .35rem;
    font-size: .75rem;
    opacity: .55;
}
.alert .btn-close:hover { opacity: 1; }

.alert-success {
    --alert-bg: #e9faf3;
    --alert-fg: #0d6f53;
    --alert-accent: var(--ss-accent);
}
.alert-success::before { content: "\f26b"; } /* check-circle */

.alert-danger {
    --alert-bg: #fdecef;
    --alert-fg: #a3243a;
    --alert-accent: var(--ss-danger);
}
.alert-danger::before { content: "\f33a"; } /* exclamation-triangle */

.alert-warning {
    --alert-bg: #fff7e6;
    --alert-fg: #8a5a00;
    --alert-accent: #f0b429;
}
.alert-warning::before { content: "\f33b"; } /* exclamation-circle */

.alert-info,
.alert-primary {
    --alert-bg: #eee9ff;
    --alert-fg: #3a2bb5;
    --alert-accent: var(--ss-primary);
}
.alert-info::before,
.alert-primary::before { content: "\f431"; } /* info-circle */

.alert-secondary {
    --alert-bg: #f1f1f7;
    --alert-fg: var(--ss-text);
    --alert-accent: var(--ss-muted);
}
.alert-secondary::before { content: "\f47f"; } /* lock-fill */

.alert-light {
    --alert-bg: #fafaff;
    --alert-fg: var(--ss-muted);
    --alert-accent: var(--ss-border);
    box-shadow: none;
}
.alert-light::before { content: "\f431"; } /* info-circle */

.alert.alert-no-icon { padding-left: 1rem; }
.alert.alert-no-icon::before { content: none; display: none; }


/* ============ PWA install banner ============ */
.pwa-install-banner {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: 12px;
    z-index: 1080;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: #ffffff;
    color: #1f2937;
    border-radius: 14px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18), 0 2px 6px rgba(15, 23, 42, 0.08);
    border: 1px solid rgba(91, 61, 245, 0.15);
    animation: pwa-banner-in 240ms ease-out;
}

@media (min-width: 576px) {
    .pwa-install-banner {
        left: auto;
        right: 16px;
        bottom: 16px;
        max-width: 420px;
    }
}

/* Lift above the mobile bottom nav when authenticated. */
@media (max-width: 767.98px) {
    body:has(.app-bottombar) .pwa-install-banner {
        bottom: 84px;
    }
    .split-summary {
        bottom: 75px;
    }
}

.pwa-install-banner__icon img {
    display: block;
    width: 40px;
    height: 40px;
    border-radius: 10px;
}

.pwa-install-banner__text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.pwa-install-banner__text strong {
    font-size: 0.95rem;
    font-weight: 700;
}

.pwa-install-banner__text span {
    font-size: 0.8rem;
    color: #4b5563;
}

.pwa-install-banner__actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

@keyframes pwa-banner-in {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
