:root {
    --entreaga-primary: #4f46e5;
    --entreaga-primary-strong: #4338ca;
    --entreaga-primary-soft: #eef2ff;
    --entreaga-accent: #14b8a6;
    --entreaga-dark: #0f172a;
    --entreaga-sidebar-w: 260px;
    --entreaga-sidebar-collapsed-w: 86px;
    --entreaga-surface: #ffffff;
    --entreaga-surface-alt: #f8fafc;
    --entreaga-border: #e5e7eb;
    --entreaga-text: #162033;
    --entreaga-muted: #64748b;
    --entreaga-sidebar-bg: #ffffff;
    --entreaga-sidebar-text: #162033;
    --entreaga-sidebar-muted: #64748b;
    --entreaga-sidebar-border: rgba(148, 163, 184, 0.18);
    --entreaga-shadow: 0 18px 40px rgba(15, 23, 42, .08);
}

body {
    background: linear-gradient(180deg, #eef4ff 0%, #f8fafc 100%);
    color: var(--entreaga-text);
    font-family: "Segoe UI", Inter, "Helvetica Neue", Arial, sans-serif;
}

body.dark-theme {
    --entreaga-primary: #8b5cf6;
    --entreaga-primary-strong: #7c3aed;
    --entreaga-primary-soft: rgba(139, 92, 246, 0.16);
    --entreaga-accent: #2dd4bf;
    --entreaga-dark: #020817;
    --entreaga-surface: rgba(15, 23, 42, 0.82);
    --entreaga-surface-alt: #0f172a;
    --entreaga-border: rgba(148, 163, 184, 0.18);
    --entreaga-text: #e2e8f0;
    --entreaga-muted: #94a3b8;
    --entreaga-sidebar-bg: #020817;
    --entreaga-sidebar-text: #e2e8f0;
    --entreaga-sidebar-muted: #94a3b8;
    --entreaga-sidebar-border: rgba(148, 163, 184, 0.18);
    --entreaga-shadow: 0 18px 40px rgba(2, 8, 23, 0.42);
    background: linear-gradient(180deg, #020817 0%, #0f172a 100%);
    color: var(--entreaga-text);
}

body.dark-theme .entreaga-sidebar {
    background: linear-gradient(180deg, #020817 0%, #0b1120 100%);
}

body.dark-theme .entreaga-topbar,
body.dark-theme .entreaga-stat-card,
body.dark-theme .quick-action-card,
body.dark-theme .settings-panel,
body.dark-theme .table-shell,
body.dark-theme .table-responsive table,
body.dark-theme .card {
    background: rgba(15, 23, 42, 0.86);
    color: var(--entreaga-text);
    border-color: var(--entreaga-border);
}

body.dark-theme .table-light,
body.dark-theme .table thead th {
    background: rgba(30, 41, 59, 0.9) !important;
    color: var(--entreaga-text) !important;
}

body.dark-theme .table td,
body.dark-theme .table th,
body.dark-theme .list-plain li,
body.dark-theme .text-muted,
body.dark-theme .small,
body.dark-theme .text-muted.small,
body.dark-theme .text-secondary,
body.dark-theme .form-label,
body.dark-theme .form-text,
body.dark-theme .form-check-label,
body.dark-theme .card-title-row h2,
body.dark-theme .card-title-row h3 {
    color: var(--entreaga-text) !important;
}

body.dark-theme .form-control,
body.dark-theme .form-select,
body.dark-theme .form-check-input {
    background: rgba(15, 23, 42, 0.9);
    color: var(--entreaga-text);
    border-color: var(--entreaga-border);
}

body.dark-theme .text-muted,
body.dark-theme .small,
body.dark-theme .text-muted.small,
body.dark-theme .text-secondary {
    color: var(--entreaga-muted) !important;
}

body.dark-theme .page-hero {
    background: linear-gradient(135deg, rgba(91, 33, 182, 0.96), rgba(59, 130, 246, 0.8));
}

body.dark-theme .quick-action-card .icon-wrap {
    background: rgba(139, 92, 246, 0.18);
    color: #ddd6fe;
}

body.dark-theme .btn-outline-secondary {
    color: #e2e8f0;
    border-color: rgba(148, 163, 184, 0.35);
    background: rgba(15, 23, 42, 0.7);
}

body.dark-theme .btn-outline-primary,
body.dark-theme .btn-outline-danger,
body.dark-theme .btn-outline-light {
    color: #e2e8f0;
}

#themeToggle,
#sidebarToggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.26);
    color: var(--entreaga-text);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.06);
}

body.dark-theme #themeToggle,
body.dark-theme #sidebarToggle {
    background: rgba(15, 23, 42, 0.85);
    border-color: rgba(148, 163, 184, 0.25);
    color: #e2e8f0;
}

#themeToggle i,
#sidebarToggle i {
    font-size: 1rem;
}

.entreaga-app-body {
    min-height: 100vh;
}

.entreaga-auth-body {
    background: linear-gradient(135deg, #0f172a, #4f46e5 55%, #7c3aed);
}

.entreaga-auth-card {
    width: 100%;
    max-width: 420px;
    border-radius: 20px;
    border: none;
    box-shadow: 0 28px 60px rgba(15, 23, 42, .28);
}

.entreaga-brand-mark {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff;
    font-weight: 700;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 14px 26px rgba(79, 70, 229, .28);
}

/* App shell */
.entreaga-sidebar {
    width: var(--entreaga-sidebar-w);
    height: 100vh;
    min-height: 100vh;
    max-height: 100vh;
    background: var(--entreaga-sidebar-bg);
    color: var(--entreaga-sidebar-text);
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overscroll-behavior: contain;
    z-index: 1030;
    border-right: 1px solid var(--entreaga-sidebar-border);
    transition: width .2s ease, transform .2s ease;
}

.entreaga-sidebar .nav {
    flex: 1 1 auto;
    max-height: calc(100vh - 82px);
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 1rem;
    scrollbar-gutter: stable;
    -webkit-overflow-scrolling: touch;
}

.entreaga-sidebar .nav::-webkit-scrollbar {
    width: 8px;
}

.entreaga-sidebar .nav::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.45);
    border-radius: 999px;
}

.entreaga-sidebar .nav::-webkit-scrollbar-track {
    background: transparent;
}

.entreaga-sidebar.collapsed {
    width: var(--entreaga-sidebar-collapsed-w);
}

.entreaga-sidebar .brand {
    color: var(--entreaga-sidebar-text);
    font-weight: 700;
    padding: 1.15rem 1.25rem;
    display: flex;
    align-items: center;
    gap: .75rem;
    border-bottom: 1px solid var(--entreaga-sidebar-border);
}

.brand-lockup {
    padding-top: 1.2rem;
    padding-bottom: 1.2rem;
}

.brand-mark-large {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    position: relative;
    background: linear-gradient(135deg, #8b5cf6 0%, #4f46e5 50%, #22d3ee 100%);
    box-shadow: 0 14px 24px rgba(79, 70, 229, .28);
}

.brand-mark-large::after {
    content: "";
    position: absolute;
    inset: 5px;
    border: 1px solid rgba(255,255,255,.4);
    border-radius: 10px;
}

.brand-copy {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-title {
    font-size: .95rem;
    line-height: 1.1;
    letter-spacing: .02em;
}

.brand-subtitle {
    display: block;
    color: rgba(255,255,255,.64);
    letter-spacing: .1em;
    text-transform: uppercase;
    font-size: .62rem;
}

.topbar-brand-chip {
    display: inline-flex;
    align-items: center;
    gap: .7rem;
}

.brand-pill-mark {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #4f46e5, #8b5cf6);
    box-shadow: 0 8px 16px rgba(79, 70, 229, .2);
}

.entreaga-sidebar .nav-link {
    color: var(--entreaga-sidebar-text);
    padding: .7rem .95rem;
    margin: .12rem .75rem;
    border-radius: 12px;
    font-size: .9rem;
    font-weight: 500;
    transition: all .16s ease;
    width: calc(100% - 1.5rem);
}

.entreaga-sidebar .nav-link.active,
.entreaga-sidebar .nav-link:hover {
    color: #fff;
    background: linear-gradient(135deg, rgba(79,70,229,.9), rgba(99,102,241,.9));
    box-shadow: 0 12px 20px rgba(79, 70, 229, .22);
}

.nav-dropdown {
    margin: .18rem .75rem .12rem;
    border-radius: 16px;
    overflow: hidden;
    background: linear-gradient(180deg, rgba(79, 70, 229, 0.08), rgba(79, 70, 229, 0.02));
    border: 1px solid rgba(79, 70, 229, 0.14);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.18);
    transition: all .2s ease;
}

.nav-dropdown summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    width: 100%;
}

.nav-dropdown summary::-webkit-details-marker {
    display: none;
}

.nav-dropdown .nav-link {
    margin: 0;
    width: 100%;
    position: relative;
    border-radius: 14px 14px 0 0;
    background: linear-gradient(135deg, rgba(79,70,229,.92), rgba(99,102,241,.9));
    color: #fff;
    box-shadow: 0 12px 20px rgba(79, 70, 229, .22);
}

.nav-dropdown .nav-link .nav-link-label,
.nav-dropdown .nav-link .nav-link-icon,
.nav-dropdown .nav-link .nav-dropdown-caret {
    color: #fff;
}

.nav-dropdown-caret {
    margin-left: auto;
    font-size: .72rem;
    opacity: .9;
    transition: transform .18s ease;
}

.nav-dropdown[open] .nav-dropdown-caret {
    transform: rotate(180deg);
}

.nav-submenu {
    display: flex;
    flex-direction: column;
    gap: .15rem;
    padding: .3rem .45rem .5rem;
    background: rgba(255,255,255,0.18);
}

.nav-submenu-link {
    display: flex;
    align-items: center;
    gap: .68rem;
    padding: .62rem .72rem;
    border-radius: 10px;
    color: var(--entreaga-sidebar-text);
    text-decoration: none;
    font-size: .82rem;
    font-weight: 500;
    transition: all .16s ease;
    margin-left: .2rem;
    border-left: 2px solid transparent;
    background: rgba(255,255,255,0.18);
}

.nav-submenu-link:hover,
.nav-submenu-link.active {
    background: rgba(79, 70, 229, 0.10);
    color: #312e81;
    text-decoration: none;
    border-left-color: rgba(79, 70, 229, 0.9);
    box-shadow: inset 0 0 0 1px rgba(79, 70, 229, 0.06);
}

.nav-submenu-icon {
    width: 1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: inherit;
}

.entreaga-sidebar .nav-link-icon {
    width: 1.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 800;
}

.entreaga-sidebar .nav-link-icon i,
.entreaga-sidebar .nav-link i {
    font-weight: 800;
    font-size: 1.05rem;
}

.entreaga-sidebar .nav-link-label {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
}

.entreaga-sidebar.collapsed .brand-copy,
.entreaga-sidebar.collapsed .nav-link-label,
.entreaga-sidebar.collapsed .nav-section-title {
    display: none;
}

.entreaga-sidebar.collapsed .brand,
.entreaga-sidebar.collapsed .nav-link {
    justify-content: center;
    padding-left: .5rem;
    padding-right: .5rem;
    width: calc(100% - .75rem);
    margin-left: .375rem;
    margin-right: .375rem;
}

.entreaga-sidebar .nav-section-title {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--entreaga-sidebar-muted);
    padding: 1.05rem 1.25rem .3rem;
}

.entreaga-content {
    margin-left: var(--entreaga-sidebar-w);
    min-height: 100vh;
    transition: margin-left .2s ease;
}

body.sidebar-collapsed .entreaga-content {
    margin-left: var(--entreaga-sidebar-collapsed-w);
}

.entreaga-topbar {
    background: rgba(255,255,255,.82);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(148, 163, 184, .15);
    border-radius: 0 0 18px 18px;
    padding: .9rem 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1020;
    box-shadow: 0 12px 22px rgba(15, 23, 42, .04);
}

.tracking {
    letter-spacing: .12em;
    font-size: .68rem;
    font-weight: 700;
}

.topbar-cta {
    border-radius: 10px;
    box-shadow: 0 10px 18px rgba(79, 70, 229, .22);
}

.page-shell {
    max-width: 1500px;
}

.page-hero {
    background: linear-gradient(135deg, rgba(79,70,229,.95), rgba(96,165,250,.7));
    border-radius: 24px;
    padding: 1.5rem 1.5rem 1.2rem;
    color: #fff;
    margin-bottom: 1.25rem;
    box-shadow: var(--entreaga-shadow);
}

.page-hero h2 {
    font-size: clamp(1.6rem, 2vw, 2.2rem);
    margin: 0;
    letter-spacing: -.02em;
}

.page-hero p {
    margin: .45rem 0 0;
    max-width: 700px;
    color: rgba(255,255,255,.82);
}

.page-hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    justify-content: flex-end;
    align-items: center;
}

.badge-soft {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    padding: .45rem .7rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    background: rgba(255,255,255,.12);
    color: #fff;
    border: 1px solid rgba(255,255,255,.18);
}

.entreaga-stat-card {
    border: 1px solid rgba(148, 163, 184, .12);
    border-radius: 18px;
    background: rgba(255,255,255,.9);
    box-shadow: 0 12px 25px rgba(15, 23, 42, .04);
    transition: transform .15s ease, box-shadow .15s ease;
}

.entreaga-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 28px rgba(15, 23, 42, .08);
}

.entreaga-stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    flex-shrink: 0;
}

.entreaga-stat-card .card-body {
    padding: 1rem 1.05rem;
}

.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: .8rem;
}

.card-title-row h2,
.card-title-row h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 700;
}

.mini-chart {
    height: 180px;
}

.table-responsive .badge {
    font-weight: 500;
    letter-spacing: .01em;
}

.quick-action-card {
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border: 1px solid var(--entreaga-border);
    border-radius: 18px;
    padding: 1rem;
    height: 100%;
}

.quick-action-card .icon-wrap {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--entreaga-primary-soft);
    color: var(--entreaga-primary);
    font-size: 1.1rem;
}

.settings-panel {
    background: rgba(255,255,255,.9);
    border: 1px solid var(--entreaga-border);
    border-radius: 18px;
    box-shadow: 0 12px 26px rgba(15, 23, 42, .04);
}

.settings-panel .card-body {
    padding: 1.2rem;
}

.form-control,
.form-select,
.form-check-input {
    border-radius: 12px;
    border-color: #dbe2f1;
    min-height: 42px;
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: rgba(79,70,229,.5);
    box-shadow: 0 0 0 .2rem rgba(79,70,229,.12);
}

.list-plain {
    list-style: none;
    padding: 0;
    margin: 0;
}

.list-plain li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .7rem 0;
    border-bottom: 1px solid #eef2f7;
}

.list-plain li:last-child {
    border-bottom: none;
}

.filter-bar {
    display: flex;
    gap: .75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.filter-bar .form-control,
.filter-bar .form-select {
    min-width: 160px;
}

.filter-search {
    flex: 1 1 220px;
}

.table-shell {
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid var(--entreaga-border);
    background: rgba(255,255,255,.66);
}

.table-shell .table {
    margin-bottom: 0;
}

.table-status {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: .32rem .7rem;
    font-size: .74rem;
    font-weight: 600;
    letter-spacing: .02em;
}

.status-paid {
    background: rgba(16,185,129,.12);
    color: #047857;
}

.status-pending {
    background: rgba(245,158,11,.12);
    color: #b45309;
}

.status-draft {
    background: rgba(148,163,184,.12);
    color: #475569;
}

.status-cancelled {
    background: rgba(239,68,68,.12);
    color: #b91c1c;
}

.status-active {
    background: rgba(59,130,246,.12);
    color: #1d4ed8;
}

.status-inactive {
    background: rgba(107,114,128,.12);
    color: #374151;
}

body.dark-theme .em-stat,
body.dark-theme .em-panel,
body.dark-theme .em-toolbar,
body.dark-theme .em-table thead th,
body.dark-theme .em-table tbody td,
body.dark-theme .em-search input,
body.dark-theme .em-type select,
body.dark-theme .em-btn,
body.dark-theme .em-select,
body.dark-theme .modal-content,
body.dark-theme .modal-header,
body.dark-theme .modal-footer,
body.dark-theme .form-control,
body.dark-theme .form-select {
    background: rgba(15, 23, 42, 0.82) !important;
    color: var(--entreaga-text) !important;
    border-color: rgba(148, 163, 184, 0.22) !important;
}

body.dark-theme .em-stat,
body.dark-theme .em-panel {
    box-shadow: 0 18px 32px rgba(2, 8, 23, 0.28);
}

body.dark-theme .em-company-name,
body.dark-theme .em-table tbody td,
body.dark-theme .em-pill,
body.dark-theme .modal-title,
body.dark-theme .em-field label,
body.dark-theme .em-empty .fw-semibold,
body.dark-theme .em-stat .em-stat-value,
body.dark-theme .em-stat .em-stat-label,
body.dark-theme .em-stat .em-stat-foot,
body.dark-theme .em-panel-title {
    color: #e2e8f0 !important;
}

body.dark-theme .em-company-mail,
body.dark-theme .text-muted,
body.dark-theme .em-search input::placeholder,
body.dark-theme .em-pid-label,
body.dark-theme .em-empty {
    color: #94a3b8 !important;
}

body.dark-theme .em-toolbar,
body.dark-theme .modal-header,
body.dark-theme .modal-footer,
body.dark-theme .em-table thead th {
    background: rgba(15, 23, 42, 0.9) !important;
}

body.dark-theme .em-table tbody tr:hover {
    background: rgba(30, 41, 59, 0.7);
}

@media (max-width: 991.98px) {
    .entreaga-sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
    }
    .entreaga-sidebar.show {
        transform: translateX(0);
    }
    .entreaga-content {
        margin-left: 0;
    }

    .page-hero {
        padding: 1.2rem;
    }

    .page-hero-actions {
        justify-content: flex-start;
        margin-top: 1rem;
    }
}

@media (max-width: 767.98px) {
    .entreaga-topbar {
        padding: .8rem 1rem;
        border-radius: 0 0 14px 14px;
    }

    .topbar-brand-chip {
        gap: .45rem;
    }

    .topbar-brand-chip h1 {
        font-size: 1rem;
    }

    .page-shell {
        padding-left: .75rem !important;
        padding-right: .75rem !important;
    }

    .row.g-3 > [class*='col-'],
    .row.g-3 > [class*='col'] {
        padding-left: .45rem;
        padding-right: .45rem;
    }

    .card-body {
        padding: .9rem !important;
    }

    .entreaga-stat-icon {
        width: 42px;
        height: 42px;
        font-size: 1rem;
    }

    .quick-action-card {
        padding: .9rem;
    }

    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .filter-bar .form-select,
    .filter-bar form {
        width: 100% !important;
    }

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