/* ============================================================
   FitManager Pro — Custom Stylesheet
   Uses Bootstrap 5 as base
   ============================================================ */

:root {
    --sidebar-w:      210px;
    --sidebar-bg:     #161d2f;
    --sidebar-hover:  #1f2942;
    --sidebar-active: #e84646;
    --accent:         #e84646;
    --accent-dark:    #c93a3a;
    --body-bg:        #f4f6fb;
    --card-shadow:    0 2px 14px rgba(0,0,0,.07);
    --radius:         10px;
}

/* ── Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
    background: var(--body-bg);
    font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
    font-size: .9375rem;
    color: #212b45;
}

a { text-decoration: none; }

/* ── Wrapper ────────────────────────────────────────────────── */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--sidebar-bg);
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    z-index: 1040;
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform .25s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    padding: .9rem 1rem .75rem;
    border-bottom: 1px solid rgba(255,255,255,.07);
    margin-bottom: .25rem;
}
.sidebar-brand .brand-icon {
    width: 30px;
    height: 30px;
    background: var(--accent);
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    color: #fff;
    flex-shrink: 0;
}
.sidebar-brand .brand-name {
    color: #fff;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: .02em;
    line-height: 1.1;
}
.sidebar-brand .brand-sub {
    color: rgba(255,255,255,.4);
    font-size: .7rem;
    display: block;
}

/* Nav sections */
.nav-section-label {
    color: rgba(255,255,255,.3);
    font-size: .6rem;
    font-weight: 600;
    letter-spacing: .09em;
    text-transform: uppercase;
    padding: .55rem 1rem .2rem;
}

.nav-link-item {
    display: flex;
    align-items: center;
    gap: .6rem;
    color: rgba(255,255,255,.62);
    padding: .4rem 1rem;
    border-radius: 0;
    font-size: .8rem;
    font-weight: 500;
    transition: background .15s, color .15s;
    position: relative;
    cursor: pointer;
}
.nav-link-item i { font-size: .95rem; flex-shrink: 0; }
.nav-link-item:hover {
    background: var(--sidebar-hover);
    color: rgba(255,255,255,.9);
}
.nav-link-item.active {
    background: rgba(232,70,70,.18);
    color: #fff;
}
.nav-link-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--accent);
    border-radius: 0 2px 2px 0;
}

/* Sidebar footer */
.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid rgba(255,255,255,.07);
    padding: 1rem 1.3rem;
}
.sidebar-user {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: .75rem;
}
.sidebar-user .avatar {
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,.12);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    color: #fff;
    flex-shrink: 0;
}
.sidebar-user .user-name {
    color: rgba(255,255,255,.85);
    font-size: .83rem;
    font-weight: 600;
}
.sidebar-user .user-role {
    color: rgba(255,255,255,.38);
    font-size: .72rem;
    display: block;
}
.btn-logout {
    display: flex;
    align-items: center;
    gap: .45rem;
    color: rgba(255,255,255,.45);
    font-size: .82rem;
    padding: .35rem .5rem;
    border-radius: 6px;
    transition: background .15s, color .15s;
}
.btn-logout:hover {
    background: rgba(255,255,255,.07);
    color: rgba(255,255,255,.8);
}

/* ── Main content ───────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Top bar */
.topbar {
    background: #fff;
    border-bottom: 1px solid #e8ecf1;
    padding: .75rem 1.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 6px rgba(0,0,0,.04);
}
.topbar-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #161d2f;
}
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.topbar-date {
    color: #8492a6;
    font-size: .8rem;
}

/* Account / settings menu (top-right) */
.account-btn {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: #f4f6fb;
    border: 1px solid #e8ecf1;
    border-radius: 40px;
    padding: .25rem .6rem .25rem .3rem;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}
.account-btn:hover, .account-btn[aria-expanded="true"] {
    background: #eef1f8;
    border-color: #d8deea;
}
.account-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .95rem;
    flex-shrink: 0;
}
.account-meta { flex-direction: column; line-height: 1.05; text-align: left; }
.account-name { font-size: .8rem; font-weight: 600; color: #161d2f; }
.account-role { font-size: .68rem; color: #8492a6; }
.account-caret { font-size: .7rem; color: #8492a6; }
.dropdown-item.active {
    background: rgba(232,70,70,.12);
    color: var(--accent);
}

/* Page content */
.page-body {
    padding: 1.75rem;
    flex: 1;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
}
.card-header {
    background: transparent;
    border-bottom: 1px solid #eef0f4;
    padding: 1rem 1.25rem .75rem;
    font-weight: 600;
    font-size: .92rem;
}

/* Stat cards */
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
    padding: 1.4rem 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    transition: transform .18s, box-shadow .18s;
}
.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(0,0,0,.1);
}
.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}
.stat-icon.blue   { background: #e8f0fe; color: #1a73e8; }
.stat-icon.green  { background: #e6f4ea; color: #1e8e3e; }
.stat-icon.red    { background: #fce8e6; color: #d93025; }
.stat-icon.orange { background: #fef0e5; color: #e67700; }
.stat-icon.purple { background: #f0e6ff; color: #7b2ff7; }
.stat-icon.teal   { background: #e0f5f5; color: #007b83; }

.stat-body {}
.stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1;
    color: #161d2f;
}
.stat-label {
    font-size: .78rem;
    color: #8492a6;
    font-weight: 500;
    margin-top: .2rem;
}

/* ── Tables ─────────────────────────────────────────────────── */
.table { font-size: .875rem; }
.table thead th {
    background: #f8f9fc;
    color: #6b7280;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    border-bottom: 2px solid #e8ecf1;
    padding: .65rem .85rem;
}
.table tbody td { padding: .7rem .85rem; vertical-align: middle; }
.table-hover tbody tr:hover { background: #f8f9fc; }

/* ── Buttons ────────────────────────────────────────────────── */
.btn-primary {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
}
.btn-primary:hover {
    background: var(--accent-dark) !important;
    border-color: var(--accent-dark) !important;
}

/* ── Form ───────────────────────────────────────────────────── */
.form-control:focus, .form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 .2rem rgba(232,70,70,.18);
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge { font-weight: 600; font-size: .75rem; }

/* ── Credit balance ─────────────────────────────────────────── */
.credit-positive { color: #1e8e3e; font-weight: 700; }
.credit-negative { color: #d93025; font-weight: 700; }
.credit-zero     { color: #8492a6; font-weight: 600; }

/* ── Login page ─────────────────────────────────────────────── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #161d2f 0%, #1f2942 60%, #e84646 100%);
}
.login-card {
    width: 100%;
    max-width: 400px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    padding: 2.5rem 2rem;
}
.login-logo {
    width: 52px;
    height: 52px;
    background: var(--accent);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: #fff;
    margin: 0 auto 1.25rem;
}
.login-card h1 {
    font-size: 1.4rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: .2rem;
}
.login-card p.sub {
    text-align: center;
    color: #8492a6;
    font-size: .85rem;
    margin-bottom: 1.75rem;
}

/* ── Responsive ─────────────────────────────────────────────── */

/* Never let a wide table or element push the whole page sideways. */
html, body { max-width: 100%; overflow-x: clip; -webkit-text-size-adjust: 100%; }
.main-content { min-width: 0; }               /* allow flex child to shrink */
.table-responsive { -webkit-overflow-scrolling: touch; }

@media (max-width: 768px) {
    /* Off-canvas sidebar + dim backdrop */
    .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.45); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .sidebar.open ~ .sidebar-backdrop,
    .sidebar-backdrop.show { display: block; }

    /* Tighten desktop-sized padding so content isn't cramped */
    .topbar { padding: .6rem .9rem; }
    .topbar-title { font-size: 1rem; }
    .topbar-date { display: none; }
    .page-body { padding: .9rem; }

    .page-header { margin-bottom: 1rem; }
    .page-header h2 { font-size: 1.05rem; }

    .card-header { padding: .8rem 1rem .6rem; }
    .card-body { padding: 1rem; }

    /* Compact stat cards so a couple fit per row comfortably */
    .stat-card { padding: 1rem; gap: .75rem; }
    .stat-icon { width: 42px; height: 42px; font-size: 1.1rem; border-radius: 10px; }
    .stat-value { font-size: 1.4rem; }

    /* Filter forms: stack each control full-width instead of squashing them */
    form.js-auto-filter.row > [class*="col"] { flex: 1 1 100%; max-width: 100%; }
    form.js-auto-filter .form-select,
    form.js-auto-filter .form-control { width: 100%; }

    /* Roomier tap targets, tighter table cells */
    .table thead th, .table tbody td { padding: .55rem .6rem; }
    .btn-sm { padding: .3rem .55rem; }

    /* Action-button clusters wrap neatly instead of overflowing */
    td.text-end .d-inline-flex,
    .page-header .d-flex { flex-wrap: wrap; }

    .login-card { padding: 1.75rem 1.25rem; margin: 1rem; }
}

/* Dim backdrop behind the open mobile sidebar */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1035;
}

/* ── Misc helpers ───────────────────────────────────────────── */
.text-accent { color: var(--accent) !important; }
.bg-accent   { background: var(--accent) !important; }
.rounded-pill-sm { border-radius: 20px; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: .5rem;
}
.page-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin: 0;
    color: #161d2f;
}

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #8492a6;
}
.empty-state i { font-size: 2.5rem; margin-bottom: .75rem; display: block; }

/* Ledger change colors */
.change-pos { color: #1e8e3e; }
.change-neg { color: #d93025; }

/* ============================================================
   Dark theme — toggled via <html class="theme-dark">
   (sidebar is already dark, so it stays as-is)
   ============================================================ */
.theme-dark { background: #0f1522; }
.theme-dark {
    --body-bg:     #0f1522;
    --card-shadow: 0 2px 14px rgba(0,0,0,.45);
}
.theme-dark body { background: var(--body-bg); color: #e4e8f1; }

/* Topbar */
.theme-dark .topbar {
    background: #161d2f;
    border-bottom-color: #243049;
    box-shadow: 0 1px 6px rgba(0,0,0,.3);
}
.theme-dark .topbar-title { color: #f2f4f9; }
.theme-dark .topbar-date  { color: #8b98ac; }

/* Account button + dropdown */
.theme-dark .account-btn { background: #1f2942; border-color: #2c3a59; }
.theme-dark .account-btn:hover,
.theme-dark .account-btn[aria-expanded="true"] { background: #26324f; border-color: #38486c; }
.theme-dark .account-name { color: #f2f4f9; }
.theme-dark .dropdown-menu { background: #1a2235; border: 1px solid #2c3a59; }
.theme-dark .dropdown-item { color: #d7dce8; }
.theme-dark .dropdown-item:hover,
.theme-dark .dropdown-item:focus { background: #26324f; color: #fff; }
.theme-dark .dropdown-header  { color: #8b98ac; }
.theme-dark .dropdown-divider { border-color: #2c3a59; }

/* Cards / surfaces */
.theme-dark .card,
.theme-dark .stat-card { background: #1a2235; color: #e4e8f1; }
.theme-dark .card-header { border-bottom-color: #2a3550; color: #e4e8f1; }
.theme-dark .card-footer.bg-white { background: #1a2235 !important; border-top-color: #2a3550; }
.theme-dark .stat-value { color: #f2f4f9; }

/* Tables — must override Bootstrap's --bs-table-* vars (default bg is white) */
.theme-dark .table {
    --bs-table-bg: #1a2235;
    --bs-table-color: #d7dce8;
    --bs-table-hover-bg: #212c44;
    --bs-table-hover-color: #ffffff;
    --bs-table-striped-bg: #1e2840;
    --bs-table-striped-color: #d7dce8;
    --bs-table-border-color: #232e46;
    color: #d7dce8;
}
.theme-dark .table thead th { background: #131a29; color: #8b98ac; border-bottom-color: #2a3550; }
.theme-dark .table tbody td,
.theme-dark .table tbody th { border-color: #232e46; }
.theme-dark .table .text-dark,
.theme-dark a.text-dark { color: #e4e8f1 !important; }

/* Forms */
.theme-dark .form-control,
.theme-dark .form-select { background: #131a29; border-color: #2c3a59; color: #e4e8f1; }
.theme-dark .form-control::placeholder { color: #6b7890; }
.theme-dark .form-control:focus,
.theme-dark .form-select:focus { background: #131a29; color: #e4e8f1; }
.theme-dark .input-group-text { background: #1f2942; border-color: #2c3a59; color: #8b98ac; }

/* Pagination */
.theme-dark .pagination .page-link { background: #1a2235; border-color: #2c3a59; color: #d7dce8; }
.theme-dark .pagination .page-item.active .page-link { background: var(--accent); border-color: var(--accent); color: #fff; }
.theme-dark .pagination .page-item.disabled .page-link { background: #161d2f; color: #5b6680; }

/* Card-header tabs (member add/edit) */
.theme-dark .nav-tabs { border-bottom-color: #2c3a59; }
.theme-dark .nav-tabs .nav-link { color: #8b98ac; }
.theme-dark .nav-tabs .nav-link:hover { border-color: #2c3a59 #2c3a59 transparent; color: #e4e8f1; }
.theme-dark .nav-tabs .nav-link.active {
    background: #1a2235;
    color: var(--accent);
    border-color: #2c3a59 #2c3a59 #1a2235;
}

/* Tom Select (searchable dropdowns) in dark mode */
.theme-dark .ts-control,
.theme-dark .ts-dropdown {
    background: #131a29;
    border-color: #2c3a59;
    color: #e4e8f1;
}
.theme-dark .ts-control input,
.theme-dark .ts-control .item { color: #e4e8f1; }
.theme-dark .ts-dropdown .option { color: #d7dce8; }
.theme-dark .ts-dropdown .active { background: #26324f; color: #fff; }
.theme-dark .ts-dropdown .optgroup-header { background: #131a29; color: #8b98ac; }
.theme-dark .ts-control .item { background: #26324f; }

/* Misc */
.theme-dark .text-muted { color: #8b98ac !important; }
.theme-dark .page-header h2 { color: #f2f4f9; }
.theme-dark .badge.bg-light { background: #2a3550 !important; color: #d7dce8 !important; }
.theme-dark .empty-state { color: #8b98ac; }
.theme-dark .table tfoot.table-light,
.theme-dark .table .table-light { --bs-table-bg: #131a29; --bs-table-color: #d7dce8; }
