:root {
    --bg: #f1f2f6;
    --card: #ffffff;
    --primary: #ff4757;
    --primary-glow: rgba(255, 71, 87, 0.2);
    --green: #25d366;
    --purple: #0088cc;
    --orange: #e0404e;
    --red: #ff4757;
    --text: #2f3542;
    --muted: #747d8c;
    --border: rgba(47, 53, 66, 0.1);
    --glass: rgba(255, 255, 255, 0.8);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Poppins', sans-serif;
}

body {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--card);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem 1rem;
    gap: 1.5rem;
    overflow-y: auto;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: .5rem;
}

.logo-icon {
    font-size: 2rem;
}

.logo h2 {
    font-weight: 800;
    background: linear-gradient(to right, var(--primary), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    line-height: 1.2;
    letter-spacing: -1px;
}

.logo small {
    color: var(--muted);
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tenant-selector {
    padding: .5rem;
    background: var(--glass);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.tenant-selector label {
    font-size: .7rem;
    color: var(--muted);
    display: block;
    margin-bottom: .4rem;
}

.tenant-selector select {
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: .85rem;
    cursor: pointer;
    outline: none;
    font-weight: 600;
}

.tenant-selector select option {
    background: var(--card);
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: .3rem;
}

.nav-links a {
    text-decoration: none;
    color: var(--muted);
    padding: .7rem 1rem;
    display: block;
    border-radius: 8px;
    transition: all .25s;
    font-size: .9rem;
    font-weight: 500;
}

.nav-links li.active a, .nav-links a:hover {
    background: rgba(255, 71, 87, 0.12);
    color: var(--primary);
    transform: translateX(4px);
}

/* Main */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.top-header {
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.top-header h1 {
    font-size: 1.4rem;
    font-weight: 700;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    box-shadow: 0 0 12px var(--primary-glow);
}

/* Sections */
.content-section {
    padding: 2rem;
    animation: fadeIn .4s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

.section-desc {
    color: var(--muted);
    font-size: .85rem;
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1.2rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--card);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.4rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: transform .3s, box-shadow .3s;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(47, 53, 66, 0.15);
}

.stat-card.blue { border-left: 3px solid var(--primary); }
.stat-card.green { border-left: 3px solid var(--green); }
.stat-card.purple { border-left: 3px solid var(--purple); }
.stat-card.orange { border-left: 3px solid var(--primary); }

.stat-icon {
    font-size: 2rem;
}

.stat-card h3 {
    font-size: .8rem;
    color: var(--muted);
    font-weight: 500;
}

.stat-value {
    font-size: 1.9rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-sub {
    font-size: .72rem;
    color: var(--muted);
}

/* Widgets */
.dashboard-widgets {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.2rem;
}

.dashboard-widgets-half {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.2rem;
    margin-top: 1.2rem;
}

@media (max-width: 768px) {
    .dashboard-widgets-half {
        grid-template-columns: 1fr;
    }
}

.widget {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.5rem;
}

.widget h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
    font-weight: 700;
}

.arch-diagram {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.arch-box {
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .8rem 1rem;
    text-align: center;
    font-size: .85rem;
    font-weight: 600;
}

.arch-box.global { border-color: var(--primary); }
.arch-box.link { border-color: var(--purple); }
.arch-box.tenant { border-color: var(--green); }

.badge-list {
    display: flex;
    flex-wrap: wrap;
    gap: .4rem;
}

.badge {
    padding: .3rem .8rem;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 600;
}

.badge.ativo { background: rgba(46, 213, 115, 0.2); color: var(--green); border: 1px solid rgba(46, 213, 115, 0.3); }
.badge.inadimplente { background: rgba(255, 71, 87, 0.2); color: var(--red); border: 1px solid rgba(255, 71, 87, 0.3); }
.badge.admin { background: rgba(255, 71, 87, 0.15); color: var(--primary); border: 1px solid rgba(255, 71, 87, 0.2); }

.tenant-meta {
    color: var(--muted);
    font-size: .8rem;
    margin-top: .8rem;
}

.card-footer {
    margin-top: 1rem;
}

.card-actions {
    display: flex;
    gap: .5rem;
}

.btn-compact {
    flex: 1;
    font-size: .75rem;
    padding: .4rem .75rem;
}

.btn-danger {
    background: var(--red);
    color: #fff;
}

.muted-small {
    color: var(--muted);
    font-size: .8rem;
}

.mt-1 {
    margin-top: 1rem;
}

.mt-half {
    margin-top: .5rem;
}

.ml-1 {
    margin-left: .5rem;
}

.avatar-thumb {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
    background: #eee;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-icon {
    margin: 10px;
    color: #ccc;
    font-size: 1rem;
}

.eye-toggle {
    right: 15px;
    left: auto;
    cursor: pointer;
    pointer-events: all;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
    cursor: pointer;
}

.checkbox-input {
    width: 14px;
    height: 14px;
    accent-color: var(--primary);
}

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

/* Tables */
.table-wrapper {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead tr {
    background: rgba(47, 53, 66, 0.04);
}

th {
    padding: .9rem 1rem;
    text-align: left;
    font-size: .75rem;
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
}

/* Sortable column headers */
th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
    padding-right: 1.6rem;
    transition: color .2s, background .2s;
}

th.sortable:hover {
    color: var(--primary);
    background: rgba(255, 71, 87, 0.06);
}

th.sortable::after {
    content: '⇅';
    position: absolute;
    right: .5rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: .65rem;
    opacity: .35;
    transition: opacity .2s, transform .25s;
}

th.sortable:hover::after {
    opacity: .6;
}

th.sortable.sort-asc::after {
    content: '▲';
    opacity: .85;
    color: var(--primary);
}

th.sortable.sort-desc::after {
    content: '▼';
    opacity: .85;
    color: var(--primary);
}

th.sortable.sort-asc,
th.sortable.sort-desc {
    color: var(--primary);
    background: rgba(255, 71, 87, 0.04);
}

td {
    padding: .85rem 1rem;
    border-top: 1px solid var(--border);
    font-size: .85rem;
}

tr:hover td {
    background: rgba(47, 53, 66, 0.02);
}

/* Buttons */
.btn-primary, .btn-secondary {
    padding: .6rem 1.2rem;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all .2s;
    font-size: .85rem;
}

.btn-primary {
    background: linear-gradient(to right, var(--primary), var(--purple));
    color: #fff;
    box-shadow: 0 3px 12px var(--primary-glow);
}

.btn-primary:hover {
    transform: scale(1.02);
    box-shadow: 0 5px 18px var(--primary-glow);
}

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--glass);
}

.top-header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.search-bar {
    display: none;
    position: relative;
}

.search-bar.open {
    display: block;
}

.search-bar i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.85rem;
}

.search-input {
    background: var(--glass);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.5rem 1rem 0.5rem 2.2rem;
    color: var(--text);
    outline: none;
    width: 250px;
    font-size: 0.85rem;
    transition: all 0.3s;
}

.avatar {
    cursor: pointer;
}

.hidden {
    display: none !important;
}

.btn-small {
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
}

.btn-inline-group {
    display: inline-flex;
    gap: 0.5rem;
    justify-content: center;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--muted);
}

.form-group input,
.form-group select {
    margin-bottom: 0;
}

.settings-panel {
    max-width: 600px;
}

.ml-8 {
    margin-left: 8px;
}

.photo-capture-container {
    margin-bottom: 1.5rem;
    text-align: center;
}

#photo-preview {
    width: 120px;
    height: 120px;
    border-radius: 60px;
    background: #2f3542;
    margin: 0 auto 1rem;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--primary);
    position: relative;
}

#photo-preview i {
    font-size: 3rem;
    color: #57606f;
}

#camera-feed,
#photo-img {
    display: none;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#camera-feed {
    transform: scaleX(-1);
}

.modal-desc {
    margin-bottom: 1rem;
}

/* Modals */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(4px);
    z-index: 90;
}

.modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    z-index: 100;
    width: 420px;
    max-width: 95vw;
    box-shadow: 0 20px 50px rgba(47, 53, 66, .15);
}

.modal input, .modal select, .modal textarea {
    width: 100%;
    background: rgba(47, 53, 66, 0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .75rem 1rem;
    color: var(--text);
    font-size: .85rem;
    margin-bottom: .8rem;
    outline: none;
}

.modal input:focus, .modal select:focus {
    border-color: var(--primary);
}

.modal-overlay.open {
    display: block;
}

.modal.open {
    display: block;
}

.modal-actions {
    display: flex;
    gap: .8rem;
    margin-top: 1.5rem;
}

.modal-actions button {
    flex: 1;
}

/* ============================================================ */
/* TOAST NOTIFICATIONS                                          */
/* ============================================================ */
.toast-notification {
    position: fixed;
    top: 24px;
    right: 24px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: 0 8px 30px rgba(47, 53, 66, 0.15);
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 8px;
    transform: translateX(120%);
    transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    max-width: 400px;
}

.toast-notification.show {
    transform: translateX(0);
}

.toast-success {
    border-left: 4px solid var(--green);
}

.toast-error {
    border-left: 4px solid var(--red);
}

.toast-info {
    border-left: 4px solid var(--purple);
}

/* ============================================================ */
/* PLAN / TENANT CARDS                                          */
/* ============================================================ */
.plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 1.2rem;
}

.plan-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.5rem;
    transition: transform 0.3s, box-shadow 0.3s;
}

.plan-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(47, 53, 66, 0.12);
}

.plan-card h4 {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.price {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(to right, var(--primary), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.5rem;
}

.price small {
    font-size: 0.7rem;
    font-weight: 500;
    -webkit-text-fill-color: var(--muted);
}

/* ============================================================ */
/* FINANCIAL SUMMARY                                            */
/* ============================================================ */
.financial-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.fin-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.2rem 1.5rem;
    text-align: center;
}

.fin-card h4 {
    font-size: 0.8rem;
    color: var(--muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.4rem;
}

.fin-card p {
    font-size: 1.4rem;
    font-weight: 700;
}

.fin-card.receita {
    border-left: 4px solid var(--green);
}

.fin-card.receita p {
    color: var(--green);
}

.fin-card.despesa {
    border-left: 4px solid var(--red);
}

.fin-card.despesa p {
    color: var(--red);
}

.fin-card.saldo {
    border-left: 4px solid var(--purple);
}

.fin-card.saldo p {
    color: var(--purple);
}

/* ============================================================ */
/* BADGES COMPLETOS                                             */
/* ============================================================ */
.badge.instrutor {
    background: rgba(0, 136, 204, 0.15);
    color: var(--purple);
    border: 1px solid rgba(0, 136, 204, 0.25);
}

.badge.aluno {
    background: rgba(46, 213, 115, 0.15);
    color: var(--green);
    border: 1px solid rgba(46, 213, 115, 0.25);
}

.badge.recepcao {
    background: rgba(255, 159, 67, 0.15);
    color: #ff9f43;
    border: 1px solid rgba(255, 159, 67, 0.25);
}

.badge.gerente {
    background: rgba(10, 189, 227, 0.15);
    color: #0abde3;
    border: 1px solid rgba(10, 189, 227, 0.25);
}

.badge.root {
    background: rgba(238, 90, 36, 0.15);
    color: #ee5a24;
    border: 1px solid rgba(238, 90, 36, 0.25);
}

.badge.suspenso {
    background: rgba(255, 165, 2, 0.15);
    color: #e67e22;
    border: 1px solid rgba(255, 165, 2, 0.25);
}

.badge.inativo {
    background: rgba(116, 125, 140, 0.15);
    color: var(--muted);
    border: 1px solid rgba(116, 125, 140, 0.25);
}

.badge.pago {
    background: rgba(46, 213, 115, 0.15);
    color: var(--green);
    border: 1px solid rgba(46, 213, 115, 0.25);
}

.badge.vencido {
    background: rgba(255, 71, 87, 0.15);
    color: var(--red);
    border: 1px solid rgba(255, 71, 87, 0.25);
}

.badge.pendente {
    background: rgba(255, 165, 2, 0.15);
    color: #e67e22;
    border: 1px solid rgba(255, 165, 2, 0.25);
}

/* ============================================================ */
/* TEXT UTILITIES                                                */
/* ============================================================ */
.text-success {
    color: var(--green);
}

.text-danger {
    color: var(--red);
}

.text-strong {
    font-weight: 700;
}

/* ============================================================ */
/* LOADING / EMPTY STATES                                       */
/* ============================================================ */
.loading {
    text-align: center;
    color: var(--muted);
    padding: 2rem !important;
    font-style: italic;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 3rem 1.5rem;
    font-style: italic;
}

/* ============================================================ */
/* AVATAR (text color)                                          */
/* ============================================================ */
.avatar {
    color: #ffffff;
    font-size: 0.85rem;
    cursor: pointer;
}

/* ============================================================ */
/* RESPONSIVE                                                   */
/* ============================================================ */
@media (max-width: 1024px) {
    .dashboard-widgets {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 1rem;
        gap: 0.5rem;
        overflow-x: auto;
    }

    .logo {
        width: 100%;
    }

    .tenant-selector {
        width: 100%;
    }

    .nav-links {
        flex-direction: row;
        overflow-x: auto;
        width: 100%;
        gap: 0.2rem;
    }

    .nav-links a {
        white-space: nowrap;
        font-size: 0.8rem;
        padding: 0.5rem 0.8rem;
    }

    .main-content {
        height: auto;
    }

    .top-header {
        flex-direction: column;
        gap: 0.8rem;
        padding: 1rem;
    }

    .top-header-left {
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
    }

    .header-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .content-section {
        padding: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }

    .section-header {
        flex-direction: column;
        gap: 0.8rem;
        align-items: flex-start;
    }

    .plans-grid {
        grid-template-columns: 1fr;
    }

    .modal {
        width: 95vw;
        padding: 1.5rem;
    }

    .table-wrapper {
        overflow-x: auto;
    }

    table {
        min-width: 600px;
    }

    .financial-summary {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-value {
        font-size: 1.5rem;
    }
}

/* ============================================================ */
/* MODAL TABS                                                   */
/* ============================================================ */
.modal-tabs {
    display: flex;
    gap: 6px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 8px;
}

.modal-tab-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 14px;
    border-radius: 8px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.modal-tab-btn i {
    font-size: 0.85rem;
}

.modal-tab-btn:hover {
    color: var(--primary);
    background: rgba(255, 71, 87, 0.05);
}

.modal-tab-btn.active {
    background: var(--primary-glow);
    color: var(--primary);
}

.modal-tab-content {
    display: none;
    animation: tabFadeIn 0.3s ease;
}

.modal-tab-content.active {
    display: block;
}

@keyframes tabFadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
