/* ===== RESET & BASE ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary:    #6C63FF;
    --primary-dark: #5A52D5;
    --secondary:  #FF6584;
    --gold:       #FFD700;
    --gold-dark:  #FFA500;
    --success:    #2ED573;
    --danger:     #FF4757;
    --warning:    #FFA502;
    --dark:       #1E1E2E;
    --card-bg:    #2A2A3E;
    --card-border:#3A3A5C;
    --text:       #E0E0FF;
    --text-muted: #9090B0;
    --sidebar-w:  260px;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--dark);
    color: var(--text);
    min-height: 100vh;
}

/* ===== LOGIN ===== */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1E1E2E 0%, #2D2D4E 100%);
}

.login-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .coin-icon {
    font-size: 64px;
    display: block;
    margin-bottom: 12px;
    animation: spin 4s linear infinite;
}

@keyframes spin {
    0%   { transform: rotateY(0deg); }
    50%  { transform: rotateY(180deg); }
    100% { transform: rotateY(360deg); }
}

.login-logo h1 {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--gold), var(--gold-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-logo p { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 8px; font-size: 14px; font-weight: 600; color: var(--text-muted); }
.form-control {
    width: 100%;
    padding: 14px 16px;
    background: var(--dark);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    color: var(--text);
    font-size: 15px;
    transition: border-color .2s, box-shadow .2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(108,99,255,.2);
}
.form-control option { background: var(--dark); }

/* ===== BUTTONS ===== */
.btn {
    padding: 14px 24px;
    border: none;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: all .2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.btn-primary  { background: linear-gradient(135deg,var(--primary),var(--primary-dark)); color:#fff; }
.btn-success  { background: linear-gradient(135deg,#2ED573,#17a34a); color:#fff; }
.btn-danger   { background: linear-gradient(135deg,var(--danger),#c0392b); color:#fff; }
.btn-warning  { background: linear-gradient(135deg,var(--warning),#e67e22); color:#fff; }
.btn-gold     { background: linear-gradient(135deg,var(--gold),var(--gold-dark)); color:#1a1a2e; }
.btn-full     { width: 100%; justify-content: center; }
.btn:hover    { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.3); }
.btn:active   { transform: translateY(0); }

/* ===== LAYOUT ===== */
.app-layout { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
    width: var(--sidebar-w);
    background: var(--card-bg);
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    top: 0; left: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-header {
    padding: 28px 24px;
    border-bottom: 1px solid var(--card-border);
    text-align: center;
}

.sidebar-logo {
    font-size: 36px;
    display: block;
    margin-bottom: 8px;
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--gold), var(--gold-dark));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sidebar-user {
    padding: 20px 24px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-avatar-sm {
    width: 44px; height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg,var(--primary),var(--secondary));
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
}

.sidebar-user-info h4 { font-size: 14px; font-weight: 700; }
.sidebar-user-info span { font-size: 12px; color: var(--text-muted); }

.sidebar-nav { padding: 16px 0; flex: 1; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 24px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: all .2s;
    border-left: 3px solid transparent;
}

.nav-item:hover, .nav-item.active {
    background: rgba(108,99,255,.1);
    color: var(--text);
    border-left-color: var(--primary);
}

.nav-item.active { color: var(--primary); }
.nav-icon { font-size: 20px; width: 24px; text-align: center; }

.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--card-border);
}

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    padding: 32px;
    max-width: calc(100vw - var(--sidebar-w));
}

/* ===== TOPBAR ===== */
.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.topbar h1 { font-size: 28px; font-weight: 800; }
.topbar p  { color: var(--text-muted); margin-top: 4px; font-size: 14px; }

/* ===== CARDS ===== */
.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 28px;
}

.card-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ===== STAT CARDS ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 24px;
    position: relative;
    overflow: hidden;
    transition: transform .2s;
}

.stat-card:hover { transform: translateY(-3px); }

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 4px;
}

.stat-card.gold::before   { background: linear-gradient(90deg,var(--gold),var(--gold-dark)); }
.stat-card.purple::before { background: linear-gradient(90deg,var(--primary),var(--secondary)); }
.stat-card.green::before  { background: linear-gradient(90deg,var(--success),#17a34a); }
.stat-card.red::before    { background: linear-gradient(90deg,var(--danger),#c0392b); }

.stat-icon  { font-size: 32px; margin-bottom: 12px; }
.stat-value { font-size: 32px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 13px; color: var(--text-muted); margin-top: 6px; }

.stat-card.gold   .stat-value { color: var(--gold); }
.stat-card.purple .stat-value { color: var(--primary); }
.stat-card.green  .stat-value { color: var(--success); }
.stat-card.red    .stat-value { color: var(--danger); }

/* ===== BALANCE HERO ===== */
.balance-hero {
    background: linear-gradient(135deg,#2D1B69 0%,#1a1a3e 100%);
    border: 1px solid rgba(108,99,255,.3);
    border-radius: 24px;
    padding: 40px;
    text-align: center;
    margin-bottom: 28px;
    position: relative;
    overflow: hidden;
}

.balance-hero::before {
    content: 'ðŸª™';
    position: absolute;
    font-size: 180px;
    opacity: .05;
    right: -20px; top: -20px;
}

.balance-hero .label   { font-size: 14px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 2px; }
.balance-hero .amount  { font-size: 72px; font-weight: 900; color: var(--gold); line-height: 1; margin: 12px 0; }
.balance-hero .coin    { font-size: 18px; color: var(--text-muted); }
.balance-hero .change  { display: inline-block; margin-top: 12px; padding: 6px 16px; border-radius: 20px; font-size: 13px; font-weight: 700; }
.balance-hero .change.up   { background: rgba(46,213,115,.15); color: var(--success); }
.balance-hero .change.down { background: rgba(255,71,87,.15); color: var(--danger); }

/* ===== GRID ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* ===== TRANSACTION LIST ===== */
.tx-list { display: flex; flex-direction: column; gap: 12px; }

.tx-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--dark);
    border-radius: 14px;
    transition: background .2s;
}

.tx-item:hover { background: rgba(108,99,255,.08); }

.tx-icon {
    width: 44px; height: 44px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.tx-icon.credit   { background: rgba(46,213,115,.15); }
.tx-icon.debit    { background: rgba(255,71,87,.15); }
.tx-icon.transfer { background: rgba(108,99,255,.15); }

.tx-info { flex: 1; }
.tx-desc { font-size: 14px; font-weight: 600; }
.tx-date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.tx-amount { font-size: 16px; font-weight: 800; }
.tx-amount.positive { color: var(--success); }
.tx-amount.negative { color: var(--danger); }

/* ===== BOOK LIST ===== */
.book-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--dark);
    border-radius: 12px;
    margin-bottom: 10px;
}

.book-cover {
    width: 40px; height: 48px;
    background: linear-gradient(135deg,var(--primary),var(--secondary));
    border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.book-info h4 { font-size: 13px; font-weight: 700; }
.book-info p  { font-size: 12px; color: var(--text-muted); }
.book-coins   { margin-left: auto; font-weight: 800; color: var(--gold); font-size: 14px; }

/* ===== CHILDREN GRID (admin) ===== */
.children-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
}

.child-card {
    background: var(--dark);
    border-radius: 18px;
    padding: 24px;
    text-align: center;
    border: 1px solid var(--card-border);
    transition: transform .2s, border-color .2s;
}

.child-card:hover { transform: translateY(-3px); border-color: var(--primary); }

.child-avatar {
    width: 70px; height: 70px;
    border-radius: 50%;
    background: linear-gradient(135deg,var(--primary),var(--secondary));
    display: flex; align-items: center; justify-content: center;
    font-size: 36px;
    margin: 0 auto 16px;
}

.child-name    { font-size: 16px; font-weight: 700; }
.child-balance { font-size: 28px; font-weight: 900; color: var(--gold); margin: 8px 0; }
.child-username { font-size: 12px; color: var(--text-muted); }

/* ===== RANKING ===== */
.rank-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--dark);
    border-radius: 14px;
    margin-bottom: 10px;
    transition: background .2s;
}

.rank-position {
    font-size: 22px;
    font-weight: 900;
    width: 32px;
    text-align: center;
}

.rank-1 .rank-position { color: var(--gold); }
.rank-2 .rank-position { color: #C0C0C0; }
.rank-3 .rank-position { color: #CD7F32; }

.rank-info { flex: 1; }
.rank-name  { font-weight: 700; font-size: 14px; }
.rank-books { font-size: 12px; color: var(--text-muted); }
.rank-coins { font-weight: 800; color: var(--gold); }

/* ===== PROGRESS BAR ===== */
.progress-wrap { margin-top: 8px; }
.progress-bar  { height: 8px; background: var(--dark); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.progress-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg,var(--primary),var(--gold)); transition: width .5s; }
.progress-label { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-muted); }

/* ===== ALERTS ===== */
.alert {
    padding: 14px 18px;
    border-radius: 12px;
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success { background: rgba(46,213,115,.15); color: var(--success); border: 1px solid rgba(46,213,115,.3); }
.alert-danger  { background: rgba(255,71,87,.15);  color: var(--danger);  border: 1px solid rgba(255,71,87,.3); }
.alert-warning { background: rgba(255,165,2,.15);  color: var(--warning); border: 1px solid rgba(255,165,2,.3); }

/* ===== BADGE ===== */
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
}
.badge-admin  { background: rgba(255,101,132,.15); color: var(--secondary); }
.badge-child  { background: rgba(108,99,255,.15);  color: var(--primary); }
.badge-credit { background: rgba(46,213,115,.15);  color: var(--success); }
.badge-debit  { background: rgba(255,71,87,.15);   color: var(--danger); }
.badge-transfer { background: rgba(108,99,255,.15); color: var(--primary); }

/* ===== TABLE ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { padding: 12px 16px; text-align: left; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; border-bottom: 1px solid var(--card-border); }
td { padding: 14px 16px; border-bottom: 1px solid rgba(255,255,255,.04); }
tr:hover td { background: rgba(108,99,255,.05); }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 200;
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 36px;
    width: 100%;
    max-width: 480px;
    transform: translateY(20px);
    transition: transform .2s;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.modal-title  { font-size: 20px; font-weight: 800; }
.modal-close  { background: none; border: none; color: var(--text-muted); font-size: 24px; cursor: pointer; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {

    /* Sidebar vira drawer por cima do conteúdo */
    .sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100vh;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 300;
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    /* Conteúdo ocupa tela inteira */
    .main-content {
        margin-left: 0 !important;
        padding: 16px;
        max-width: 100vw;
    }

    /* Overlay escuro atrás do sidebar */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.6);
        z-index: 299;
    }

    .sidebar-overlay.active {
        display: block;
    }

    /* Botão hamburguer visível */
    .menu-toggle {
        display: flex !important;
        align-items: center;
        gap: 8px;
        background: var(--card-bg);
        border: 1px solid var(--card-border);
        color: var(--text);
        padding: 10px 16px;
        border-radius: 12px;
        cursor: pointer;
        font-size: 16px;
        font-weight: 600;
        margin-bottom: 20px;
    }

    /* Grids viram coluna única */
    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr !important;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr !important;
    }

    /* Hero de saldo menor */
    .balance-hero .amount {
        font-size: 48px;
    }

    /* Topbar empilha */
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    /* Tabela com scroll horizontal */
    .table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Modal ocupa mais espaço */
    .modal {
        margin: 16px;
        max-width: calc(100vw - 32px) !important;
        padding: 24px 20px;
    }

    /* Children grid coluna única */
    .children-grid {
        grid-template-columns: 1fr !important;
    }

    /* Ajuste nos cards de filhos */
    .child-card {
        display: flex;
        align-items: center;
        text-align: left;
        gap: 16px;
    }

    .child-card .child-avatar {
        margin: 0;
        flex-shrink: 0;
    }
}

/* Desktop: menu-toggle sempre oculto */
@media (min-width: 769px) {
    .menu-toggle {
        display: none !important;
    }

    .sidebar-overlay {
        display: none !important;
    }
}

/* ===== MISC ===== */
.mb-20 { margin-bottom: 20px; }
.mb-28 { margin-bottom: 28px; }
.mt-20 { margin-top: 20px; }
.text-muted  { color: var(--text-muted); font-size: 13px; }
.text-gold   { color: var(--gold); }
.divider     { border: none; border-top: 1px solid var(--card-border); margin: 24px 0; }