:root {
    color-scheme: dark;
    --bg: #0d0d0f;
    --panel: #17161a;
    --panel-2: #1e1c21;
    --border: #2a282e;
    --gold: #f0a500;
    --gold-soft: #f7c948;
    --gold-rgb: 240, 165, 0;
    --on-gold: #1a1206;
    --text: #f2f0ec;
    --muted: #9a978f;
    --sidebar-bg: #0f0e11;
    --scrollbar: #3a3730;
    --ease: cubic-bezier(.4, 0, .2, 1);
}

:root[data-theme="red"] {
    color-scheme: dark;
    --bg: #0d0d0f;
    --panel: #17161a;
    --panel-2: #1e1c21;
    --border: #2a282e;
    --gold: #e2231a;
    --gold-soft: #ff4d42;
    --gold-rgb: 226, 35, 26;
    --on-gold: #ffffff;
    --text: #f2f0ec;
    --muted: #9a978f;
    --sidebar-bg: #0f0e11;
    --scrollbar: #3a3730;
}

:root[data-theme="light"] {
    color-scheme: light;
    --bg: #faf7f2;
    --panel: #ffffff;
    --panel-2: #f5efe3;
    --border: #ece3d3;
    --gold: #ea8c00;
    --gold-soft: #b45f06;
    --gold-rgb: 234, 140, 0;
    --on-gold: #1a1206;
    --text: #241f16;
    --muted: #8a8171;
    --sidebar-bg: #ffffff;
    --scrollbar: #e3d8c4;
}

:root {
    --bs-body-color: var(--text);
    --bs-body-bg: var(--bg);
    --bs-heading-color: var(--text);
    --bs-emphasis-color: var(--text);
    --bs-card-color: var(--text);
    --bs-card-bg: var(--panel);
    --bs-secondary-color: var(--muted);
}

* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar) transparent;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 8px; }

html, body { transition: background-color .1s var(--ease), color .1s var(--ease); }

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

a { text-decoration: none; }

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

.sidebar {
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
}

.brand {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: .2px;
    margin-bottom: 18px;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeIn .12s var(--ease) both;
}

.brand .bi { color: var(--gold); }

.menu-label {
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: 1.5px;
    color: #5f5c56;
    margin: 8px 4px 10px;
}

.sidebar .nav-link {
    color: #b7b4ac;
    border-radius: 10px;
    padding: 10px 12px;
    font-weight: 600;
    font-size: .92rem;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: color .08s var(--ease), background-color .08s var(--ease), transform .08s var(--ease);
    animation: fadeInLeft .1s var(--ease) both;
}

.sidebar .nav-link .bi { font-size: 1rem; width: 18px; text-align: center; color: #7a776f; transition: color .12s var(--ease); }

.sidebar .nav-link:hover { color: var(--text); background: #1c1a1d; transform: translateX(2px); }
.sidebar .nav-link:hover .bi { color: var(--gold-soft); }

.sidebar .nav-link.active {
    color: var(--on-gold);
    background: linear-gradient(135deg, var(--gold-soft), var(--gold));
    box-shadow: 0 6px 18px rgba(var(--gold-rgb), .25);
}

.sidebar .nav-link.active .bi { color: var(--on-gold); }

.sidebar .nav-link:nth-child(1) { animation-delay: .005s; }
.sidebar .nav-link:nth-child(2) { animation-delay: .01s; }
.sidebar .nav-link:nth-child(3) { animation-delay: .015s; }
.sidebar .nav-link:nth-child(4) { animation-delay: .02s; }
.sidebar .nav-link:nth-child(5) { animation-delay: .025s; }
.sidebar .nav-link:nth-child(6) { animation-delay: .03s; }
.sidebar .nav-link:nth-child(7) { animation-delay: .035s; }
.sidebar .nav-link:nth-child(8) { animation-delay: .04s; }
.sidebar .nav-link:nth-child(9) { animation-delay: .045s; }
.sidebar .nav-link:nth-child(10) { animation-delay: .05s; }
.sidebar .nav-link:nth-child(11) { animation-delay: .055s; }
.sidebar .nav-link:nth-child(12) { animation-delay: .06s; }
.sidebar .nav-link:nth-child(13) { animation-delay: .065s; }

.sidebar-cta {
    margin-top: auto;
    background: linear-gradient(160deg, rgba(var(--gold-rgb), .12), rgba(0,0,0,.15));
    border: 1px solid rgba(var(--gold-rgb), .25);
    border-radius: 14px;
    padding: 16px;
    font-size: .95rem;
    line-height: 1.3;
    color: var(--gold-soft);
    animation: fadeInUp .12s var(--ease) both;
    animation-delay: .07s;
}

.sidebar-footer { margin-top: 14px; }

.user-chip { display: flex; align-items: center; gap: 10px; }

.avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: linear-gradient(135deg, var(--gold-soft), var(--gold));
    color: var(--on-gold); font-weight: 800; display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.text-muted-soft { color: var(--muted) !important; }

.content { padding: 28px 32px; }

.topbar {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 26px;
}

.topbar h1 { font-size: 1.7rem; font-weight: 800; margin: 0; letter-spacing: -.3px; }

.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.search-box-wrap { position: relative; flex: 1 1 auto; min-width: 220px; }

.search-box {
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: 8px 14px; display: flex; align-items: center; gap: 8px; color: var(--muted);
    width: 100%;
}
.search-box input { background: transparent; border: 0; outline: none; color: var(--text); width: 100%; }
.search-box input::placeholder { color: var(--muted); }

.search-dropdown {
    display: none; position: absolute; top: calc(100% + 6px); left: 0; right: 0;
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 16px 32px rgba(0,0,0,.35); z-index: 500; max-height: 360px; overflow-y: auto;
    padding: 6px 0;
}
.search-dropdown.show { display: block; }
.search-dropdown-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 14px; color: var(--text);
    transition: background-color .08s var(--ease);
}
.search-dropdown-item:hover { background: var(--panel-2); }
.search-dropdown-avatar {
    width: 30px; height: 30px; border-radius: 50%; background: var(--panel-2); flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .72rem; color: var(--gold-soft);
}
.search-dropdown-more {
    display: block; text-align: center; padding: 8px 14px; font-size: .82rem; font-weight: 600;
    color: var(--gold-soft); border-top: 1px solid var(--border); margin-top: 4px;
}
.search-dropdown-empty { padding: 16px; text-align: center; color: var(--muted); font-size: .85rem; }
.min-w-0 { min-width: 0; }

.icon-btn {
    width: 40px; height: 40px; border-radius: 10px; background: var(--panel); border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center; position: relative; color: var(--text);
    transition: background-color .1s var(--ease);
    padding: 0; cursor: pointer; font-size: 1rem; flex-shrink: 0;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }

.notif-wrap { position: relative; }
.notif-panel {
    display: none; position: fixed; width: 300px; max-width: calc(100vw - 24px); max-height: 360px;
    overflow-y: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 16px 32px rgba(0,0,0,.35); z-index: 99999; padding: 10px 0;
}
.notif-panel.show { display: block; }
.notif-panel-head { padding: 6px 16px 10px; font-weight: 700; font-size: .88rem; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.notif-section-label { padding: 8px 16px 4px; font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.notif-item { display: flex; align-items: flex-start; gap: 10px; padding: 7px 16px; font-size: .86rem; }
.notif-item i { margin-top: 2px; }
.notif-sub { display: block; font-size: .74rem; color: var(--muted); }
.notif-empty { padding: 16px; text-align: center; color: var(--muted); font-size: .85rem; }

.theme-wrap { position: relative; }
#themePanel { width: 220px; }
.theme-option {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 16px;
    background: transparent; border: 0; color: var(--text); font-size: .88rem; font-weight: 600;
    transition: background-color .08s var(--ease);
}
.theme-option:hover { background: var(--panel-2); }
.theme-swatch { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; border: 1px solid rgba(255,255,255,.25); }
.theme-check { visibility: hidden; color: var(--gold-soft); }
.theme-option.active .theme-check { visibility: visible; }

.hamburger {
    display: none;
    width: 40px; height: 40px; border-radius: 10px; background: var(--panel); border: 1px solid var(--border);
    align-items: center; justify-content: center; color: var(--text); font-size: 1.2rem; cursor: pointer; padding: 0;
    flex-shrink: 0;
}

.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 999;
}
.sidebar-backdrop.show { display: block; }

.date-chip {
    background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
    padding: 8px 14px; font-size: .88rem; color: var(--text); display: flex; align-items: center; gap: 8px;
}

.stat-card, .table-card, .chart-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    transition: transform .1s var(--ease), box-shadow .1s var(--ease), border-color .1s var(--ease);
    animation: fadeInUp .12s var(--ease) both;
}

.stat-card:hover, .chart-card:hover {
    transform: translateY(-3px);
    border-color: rgba(var(--gold-rgb), .35);
    box-shadow: 0 16px 32px rgba(0, 0, 0, .35);
}

.row.g-3.mb-4 > div:nth-child(1) .stat-card { animation-delay: .01s; }
.row.g-3.mb-4 > div:nth-child(2) .stat-card { animation-delay: .02s; }
.row.g-3.mb-4 > div:nth-child(3) .stat-card { animation-delay: .03s; }
.row.g-3.mb-4 > div:nth-child(4) .stat-card { animation-delay: .04s; }

.stat-card .card-body { padding: 20px; }

.stat-icon {
    width: 40px; height: 40px; border-radius: 10px; background: rgba(var(--gold-rgb),.12);
    color: var(--gold); display: flex; align-items: center; justify-content: center; font-size: 1.1rem; margin-bottom: 10px;
}

.stat-card .value { font-size: 1.7rem; font-weight: 800; color: var(--text); }
.stat-card .label { color: var(--muted); font-size: .85rem; }
.stat-card .delta { font-size: .8rem; font-weight: 600; }
.delta.up { color: #4ade80; }
.delta.down { color: #f87171; }

.table-card { padding: 20px; }
.chart-card { padding: 20px; }

.table-card h2, .chart-card h2 { font-size: 1.02rem; font-weight: 700; color: var(--text); }

.table { color: var(--text); --bs-table-color: var(--text); }
.table > :not(caption) > * > * { background: transparent; color: var(--text); border-bottom-color: var(--border); }
.table thead th { color: var(--muted); font-weight: 600; font-size: .82rem; text-transform: uppercase; letter-spacing: .4px; border-bottom-color: var(--border); }
.table-hover tbody tr { transition: background-color .08s var(--ease); }
.table-hover tbody tr:hover > * { background-color: var(--panel-2); }

.badge.text-bg-success { background-color: rgba(74, 222, 128, .15) !important; color: #4ade80 !important; }
.badge.text-bg-danger { background-color: rgba(248, 113, 113, .15) !important; color: #f87171 !important; }
.badge.text-bg-warning { background-color: rgba(var(--gold-rgb),.15) !important; color: var(--gold-soft) !important; }
.badge.text-bg-secondary { background-color: rgba(154, 151, 143, .15) !important; color: var(--muted) !important; }
.badge.text-bg-primary { background-color: rgba(var(--gold-rgb),.18) !important; color: var(--gold-soft) !important; }
.badge.text-bg-info { background-color: rgba(103, 190, 255, .15) !important; color: #67beff !important; }

.activity-item { display: flex; align-items: center; justify-content: between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.activity-item:last-child { border-bottom: 0; }
.activity-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2); display:flex; align-items:center; justify-content:center; font-weight:700; font-size:.8rem; color: var(--gold-soft); flex-shrink:0; }

.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; display: inline-block; margin-right: 5px; animation: pulseDot 1.8s ease-in-out infinite; }

.class-item { border-left: 3px solid var(--gold); background: var(--panel-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; display:flex; justify-content: space-between; align-items:center; }

.required::after { content: " *"; color: #f87171; }

.form-control, .form-select {
    background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
    transition: border-color .08s var(--ease), box-shadow .08s var(--ease);
}
.form-control:focus, .form-select:focus {
    background: var(--panel-2); color: var(--text);
    border-color: var(--gold); box-shadow: 0 0 0 .2rem rgba(var(--gold-rgb),.15);
}
.form-control::placeholder { color: var(--muted); }
.form-label { color: var(--text); font-weight: 600; font-size: .88rem; }

.btn { transition: background-color .08s var(--ease), border-color .08s var(--ease), color .08s var(--ease), transform .06s var(--ease), box-shadow .08s var(--ease); }
.btn:active { transform: scale(.97); }

.btn-primary { background-color: var(--gold); border-color: var(--gold); color: var(--on-gold); font-weight: 700; }
.btn-primary:hover { background-color: var(--gold-soft); border-color: var(--gold-soft); color: var(--on-gold); box-shadow: 0 6px 16px rgba(var(--gold-rgb),.3); }

.btn-outline-primary { color: var(--gold-soft); border-color: var(--gold); }
.btn-outline-primary:hover { background-color: var(--gold); border-color: var(--gold); color: var(--on-gold); }

.btn-outline-secondary, .btn-outline-danger, .btn-light { color: var(--text); border-color: var(--border); background: var(--panel-2); }
.btn-outline-secondary:hover, .btn-light:hover { background: var(--panel); color: var(--text); }
.btn-outline-danger:hover { background: #f87171; border-color: #f87171; }

.text-primary { color: var(--gold-soft) !important; }

.btn-wa { background-color: #25d366; border-color: #25d366; color: #fff; }
.btn-wa:hover { background-color: #1ea952; border-color: #1ea952; color: #fff; box-shadow: 0 6px 16px rgba(37, 211, 102, .3); }

.alert { animation: fadeInUp .1s var(--ease) both; }
.alert-success { background: rgba(74,222,128,.12); color:#4ade80; border-color: rgba(74,222,128,.3); }
.alert-danger { background: rgba(248,113,113,.12); color:#f87171; border-color: rgba(248,113,113,.3); }
.alert-warning { background: rgba(var(--gold-rgb),.12); color:var(--gold-soft); border-color: rgba(var(--gold-rgb),.3); }

:root[data-theme="light"] .menu-label { color: #a89c86; }
:root[data-theme="light"] .sidebar .nav-link { color: #6b6459; }
:root[data-theme="light"] .sidebar .nav-link .bi { color: #a89c86; }
:root[data-theme="light"] .sidebar .nav-link:hover { background: #f5efe3; color: var(--text); }
:root[data-theme="light"] .sidebar .nav-link.active { color: #fff; }
:root[data-theme="light"] .sidebar-cta { color: var(--gold-soft); }
:root[data-theme="light"] .sidebar-footer .btn-outline-light { color: var(--text); border-color: var(--border); }
:root[data-theme="light"] .sidebar-footer .btn-outline-light:hover { background: var(--panel-2); color: var(--text); }
:root[data-theme="light"] .stat-card:hover, :root[data-theme="light"] .chart-card:hover { box-shadow: 0 16px 32px rgba(var(--gold-rgb), .12); }
:root[data-theme="light"] .table-hover tbody tr:hover > * { background-color: var(--panel-2); }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fadeInLeft { from { opacity: 0; transform: translateX(-6px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeInDown { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulseDot { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

.member-card {
    background: linear-gradient(135deg, #1c1410, #2b1c14);
    border: 1px solid #3a2c1a;
    border-radius: 18px;
    padding: 24px;
    color: #fff;
    max-width: 420px;
    margin: 0 auto;
    animation: fadeIn .15s var(--ease) both;
}
:root[data-theme="light"] .member-card {
    background: linear-gradient(135deg, #201705, #3a2a08);
    border-color: #4a3610;
}
.member-card-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.member-card-brand { color: var(--gold-soft); font-weight: 700; font-size: .85rem; margin-bottom: 10px; }
.member-card-name { font-size: 1.3rem; font-weight: 800; }
.member-card-sub { color: #cbbfae; font-size: .85rem; }
.member-card-qr { background: #fff; border-radius: 12px; padding: 16px; display: flex; align-items: center; justify-content: center; }
.member-card-footer { display: flex; justify-content: space-between; margin-top: 16px; font-size: .78rem; color: #cbbfae; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .001s !important; animation-delay: 0s !important; transition-duration: .001s !important; }
}

@media (max-width: 1100px) {
    .app-shell { grid-template-columns: 1fr; }
    .hamburger { display: flex; }
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        width: 260px;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform .15s var(--ease);
    }
    .sidebar.open { transform: translateX(0); }
    .content { padding: 16px; }
    .topbar { flex-direction: column; align-items: stretch; gap: 12px; }
    .topbar-top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
}

@media (max-width: 560px) {
    .search-box-wrap { display: none; }
    .content { padding: 14px; }
    .stat-card .value { font-size: 1.4rem; }
}

@media print {
    .sidebar, .no-print, .btn, form { display: none !important; }
    .app-shell { display: block; }
    .content { padding: 0; }
    body { background: #fff; color: #000; }
    * { animation: none !important; }
}

body.print-receipt .content > *:not(.receipt-print-area) { display: none !important; }
body.print-receipt .topbar { display: none !important; }

.receipt-wrap { max-width: 340px; margin: 0 auto; }
.receipt {
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    padding: 22px 20px; font-family: 'Courier New', Courier, monospace; color: var(--text);
}
.receipt-header { text-align: center; margin-bottom: 12px; }
.receipt-header .receipt-brand { font-weight: 800; font-size: 1rem; letter-spacing: .3px; }
.receipt-header .receipt-sub { font-size: .72rem; color: var(--muted); margin-top: 2px; }
.receipt-divider { border: none; border-top: 1px dashed var(--border); margin: 10px 0; }
.receipt-row { display: flex; justify-content: space-between; gap: 10px; font-size: .82rem; margin-bottom: 4px; }
.receipt-item-name { display: block; }
.receipt-item-meta { color: var(--muted); font-size: .76rem; }
.receipt-total-row { display: flex; justify-content: space-between; font-weight: 800; font-size: .98rem; margin-top: 6px; }
.receipt-footer { text-align: center; font-size: .74rem; color: var(--muted); margin-top: 14px; }

@media print {
    body.print-receipt .receipt-wrap { max-width: 100%; }
    body.print-receipt .receipt { border: none; padding: 0; color: #000; }
    body.print-receipt .receipt-divider { border-top-color: #000; }
    body.print-receipt .receipt-header .receipt-sub,
    body.print-receipt .receipt-item-meta,
    body.print-receipt .receipt-footer { color: #333; }
    body.print-receipt { background: #fff; }
    @page { margin: 6mm; }
}

.weight-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 8px; max-width: 420px; }
.weight-gallery-thumb {
    aspect-ratio: 1; border-radius: 8px; overflow: hidden; border: 1px solid var(--border);
    cursor: pointer; background: var(--panel-2); transition: transform .08s var(--ease), border-color .08s var(--ease);
}
.weight-gallery-thumb:hover { transform: scale(1.04); border-color: var(--gold); }
.weight-gallery-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }

.lightbox-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,.82); z-index: 2000;
    align-items: center; justify-content: center; padding: 24px; animation: fadeIn .1s var(--ease) both;
}
.lightbox-overlay.show { display: flex; }
.lightbox-overlay img { max-width: 92vw; max-height: 88vh; border-radius: 10px; box-shadow: 0 20px 50px rgba(0,0,0,.5); }
.lightbox-close {
    position: absolute; top: 20px; right: 24px; width: 42px; height: 42px; border-radius: 50%;
    background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.25); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 1.3rem; cursor: pointer;
}
.lightbox-close:hover { background: rgba(255,255,255,.2); }
