:root {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --card-bg: #1e293b;
    --accent-color: #6366f1;
    --accent-hover: #4f46e5;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: rgba(255, 255, 255, 0.1);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;

    /* Recovered/Missing Variables */
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --primary-color: #0f172a;
    /* Used for scrollbar tracks (dark) */
    --secondary-color: #334155;
    /* Used for scrollbar thumbs */
    --glass-bg: rgba(30, 41, 59, 0.7);
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-color);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    background: var(--card-bg);
    padding: 3rem;
    border-radius: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    width: 100%;
    max-width: 440px;
    text-align: center;
    border: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
}

.login-card h2 {
    margin-bottom: 2rem;
    color: var(--text-primary);
    font-size: 1.8rem;
    font-weight: 700;
}

#login-partner-select {
    font-size: 1.1rem;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.8);
    transition: all 0.3s ease;
    cursor: pointer;
}

#login-partner-select:focus {
    background: rgba(15, 23, 42, 1);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
    outline: none;
}

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

body {
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    overflow: hidden;
}

/* Scrollbar Style */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--primary-color);
}

::-webkit-scrollbar-thumb {
    background: var(--secondary-color);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-color);
}

/* Redução de ruído visual: remove setas de inputs numéricos */
input[type=number]::-webkit-inner-spin-button,
input[type=number]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    appearance: none;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 3rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.logo img {
    max-width: 100%;
    height: auto;
    transition: all 0.3s ease;
}

.nav-menu {
    list-style: none;
}

.nav-item {
    margin-bottom: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.8rem 1rem;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 12px;
    transition: all 0.3s ease;
    cursor: pointer;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(56, 189, 248, 0.1);
    color: var(--text-primary);
}

.nav-link.active {
    box-shadow: inset 4px 0 0 var(--accent-color);
    background: rgba(56, 189, 248, 0.15);
}

/* Submenu Styles */
.nav-group {
    margin-bottom: 0.5rem;
}

.nav-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.8rem 1rem;
    color: var(--text-secondary);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.nav-group-header:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.nav-group-header .group-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-group-header i[data-lucide="chevron-down"] {
    width: 16px;
    height: 16px;
    transition: transform 0.3s ease;
}

.nav-group.open .nav-group-header i[data-lucide="chevron-down"] {
    transform: rotate(180deg);
}

.nav-submenu {
    list-style: none;
    padding-left: 2.5rem;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.nav-group.open .nav-submenu {
    max-height: 500px;
    margin-top: 0.2rem;
    margin-bottom: 1rem;
}

.submenu-link {
    display: block;
    padding: 0.5rem 1rem;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.submenu-link:hover,
.submenu-link.active {
    color: var(--accent-color);
    background: rgba(56, 189, 248, 0.05);
}

/* Main Content */
.sidebar-footer {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.8rem 1rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.8rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 12px;
    transition: all 0.3s ease;
    width: 100%;
    text-align: left;
    font-size: 0.9rem;
}

.btn-logout:hover {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* Sidebar toggle buttons - hidden by default on desktop */
.btn-sidebar-toggle,
.btn-sidebar-toggle-mobile,
.sidebar-header-mobile {
    display: none !important;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 998;
}

.btn-sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-sidebar-toggle-mobile {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    padding: 0.6rem;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
    transition: all 0.3s;
}

.btn-sidebar-toggle-mobile:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Sidebar */
.sidebar {
    width: 280px;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 2rem 1.5rem;
    height: 100vh;
    position: sticky;
    top: 0;
    overflow-y: auto;
    overflow-x: hidden;
}

/* Main Content */
main {
    flex: 1;
    padding: 2rem 4rem;
    overflow-y: auto;
    height: 100vh;
}

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

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

.header h1 {
    font-size: 2rem;
    font-weight: 600;
    background: linear-gradient(to right, #fff, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Base Components */
.section {
    display: none;
    animation: fadeIn 0.3s ease-out;
}

.section.active {
    display: block;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 1.5rem;
    padding: 2rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    margin-bottom: 2rem;
    backdrop-filter: blur(10px);
    width: 100%;
}

.card-compact {
    width: fit-content !important;
    min-width: 450px;
}

.grid-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.input-group label {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input,
select,
textarea,
.input-field {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.8rem 1rem;
    color: var(--text-primary);
    font-size: 1rem;
    width: 100%;
    transition: all 0.3s ease;
}

input:focus,
select:focus,
textarea:focus,
.input-field:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
    outline: none;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 0.8rem 1.5rem;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    font-size: 0.95rem;
    justify-content: center;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
}

.btn-primary:hover {
    background: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 10px 20px -10px var(--accent-color);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-icon i {
    width: 16px;
    height: 16px;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    transform: translateY(-2px);
}

.btn-edit {
    color: var(--accent-color);
    border-color: rgba(99, 102, 241, 0.2);
}

.btn-edit:hover {
    color: var(--accent-hover);
    border-color: rgba(99, 102, 241, 0.5);
    background: rgba(99, 102, 241, 0.1);
}

.btn-delete {
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.2);
}

.btn-delete:hover {
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.5);
    background: rgba(239, 68, 68, 0.1);
}

.btn-save {
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.2);
}

.btn-save:hover {
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.5);
    background: rgba(16, 185, 129, 0.1);
}

.btn-cancel {
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.2);
}

.btn-cancel:hover {
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.5);
    background: rgba(245, 158, 11, 0.1);
}

.btn-save {
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.2);
}

.btn-save:hover {
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.5);
    background: rgba(16, 185, 129, 0.1);
}

/* Tables */
.table-container {
    background: rgba(15, 23, 42, 0.2);
    border-radius: 1rem;
    overflow-x: auto;
    border: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.table-compact {
    width: auto !important;
    min-width: 100%;
}

.card-compact .table-compact {
    min-width: 100%;
}

th {
    background: rgba(15, 23, 42, 0.4);
    padding: 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 0.9rem;
}

.text-right {
    text-align: right;
}

.actions-cell {
    white-space: nowrap;
    width: 1%;
    text-align: center;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

td.actions-cell {
    display: table-cell;
    /* Fix for display: flex breaking td */
}

.actions-cell div {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsiveness */
@media screen and (max-width: 1024px) {
    main {
        padding: 2rem;
    }

    .grid-form {
        grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    }
}

@media screen and (max-width: 768px) {
    body {
        flex-direction: column !important;
        overflow-x: hidden !important;
        overflow-y: auto !important;
        display: block !important;
        /* Switch from flex to block to simplify layout */
    }

    .sidebar {
        position: fixed !important;
        left: -300px !important;
        top: 0;
        bottom: 0;
        z-index: 1001 !important;
        transition: left 0.3s ease-in-out;
        width: 280px;
        background: var(--sidebar-bg);
        /* Use solid color instead of glass-bg for mobil */
        display: flex !important;
        height: 100vh !important;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.5);
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar.active {
        left: 0 !important;
    }

    .sidebar-header-mobile {
        display: flex !important;
        justify-content: flex-end;
        padding: 1rem;
    }

    .btn-sidebar-toggle-mobile {
        display: flex !important;
    }

    .btn-sidebar-toggle {
        display: flex !important;
    }

    main {
        padding: 1rem !important;
        margin-top: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        flex: none !important;
    }

    .header {
        margin-bottom: 1rem;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
        gap: 1rem;
    }

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

    .grid-form {
        grid-template-columns: 1fr !important;
        gap: 1rem;
    }

    .card {
        padding: 1rem;
        margin-bottom: 1rem;
        border-radius: 12px;
    }

    .table-container {
        margin: 0 -1rem;
        padding: 0 1rem;
        width: calc(100% + 2rem);
    }

    .btn {
        width: 100%;
        justify-content: center;
    }
}

/* Editable cells indicator */
[contenteditable="true"] {
    background: rgba(56, 189, 248, 0.05);
    border-bottom: 1px dashed var(--accent-color);
    border-radius: 4px;
    padding: 0.2rem 0.5rem;
    cursor: text;
}

[contenteditable="true"]:focus {
    background: rgba(56, 189, 248, 0.1);
    outline: none;
    border-bottom: 1px solid var(--accent-color);
}

.table-container {
    overflow-x: auto;
    position: relative;
    width: 100%;
    -webkit-overflow-scrolling: touch;
}

/* History tables scroll indicators */
.card.table-container::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.card.table-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
}

.input-error {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.2);
}

/* Custom Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 1.5rem;
    border: 1px solid var(--border-color);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    max-width: 500px;
    width: 100%;
    text-align: center;
    animation: modal-in 0.3s ease-out;
}

@keyframes modal-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Print Helpers */
.print-only {
    display: none !important;
}

/* Print Styles */
@media print {
    @page {
        size: A4;
        margin: 0;
    }

    html,
    body {
        height: auto !important;
        overflow: visible !important;
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    body {
        display: block !important;
        color: black;
        font-family: 'Outfit', 'Inter', sans-serif;
    }

    /* Hide UI Elements */
    .sidebar,
    .login-overlay,
    #custom-modal,
    .no-print,
    .btn,
    .btn-icon,
    .section,
    header.header,
    .mobile-header-toggle,
    #sidebar-overlay {
        display: none !important;
    }

    main {
        display: none !important;
    }

    /* Show Print Containers and Flatten them */
    .print-only {
        display: none !important;
        position: static !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        height: auto !important;
        overflow: visible !important;
        line-height: normal !important;
    }

    /* Force specific display when printing class is active */
    body[class*="printing-"] .print-only {
        display: none !important;
    }

    body.printing-mentorias #print-container,
    body.printing-clientes #print-container-clientes,
    body.printing-balance-annual #print-container-balance-annual,
    body.printing-balance-analytic #print-container-balance-analytic,
    body.printing-distribution #print-container-distribution {
        display: block !important;
    }

    /* Print Layout Structure - Conservative height (A4 is 29.7cm) */
    .print-page {
        height: 28.7cm !important;
        width: 100% !important;
        position: relative;
        display: flex;
        flex-direction: column;
        padding: 1cm;
        box-sizing: border-box;
        overflow: hidden;
        page-break-after: always !important;
        break-after: page !important;
        background: white !important;
    }

    /* Prevent break on last child */
    .print-page:last-child,
    .print-page:last-of-type {
        page-break-after: avoid !important;
        break-after: avoid !important;
        margin-bottom: 0 !important;
    }

    /* Header */
    .print-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 2px solid #000;
        padding-bottom: 10px;
        margin-bottom: 20px;
    }

    .ph-left img {
        height: 40px;
    }

    .ph-center {
        font-weight: bold;
        font-size: 1.2rem;
        text-transform: uppercase;
        flex: 1;
        text-align: center;
    }

    .ph-right {
        font-size: 0.9rem;
        text-align: right;
        min-width: 150px;
    }

    /* Content */
    .text-center {
        text-align: center !important;
    }

    .print-date-col {
        width: 1%;
        white-space: nowrap;
        text-align: center !important;
    }

    .print-content table {
        width: 100%;
        border-collapse: collapse;
        margin-top: 10px;
        font-size: 0.9rem;
        color: black !important;
    }

    .print-title {
        font-size: calc(1.1rem + 2pt) !important;
        font-weight: bold;
        margin-bottom: 5px;
        color: black !important;
        text-align: center;
    }

    .print-subtitle {
        font-size: 1.1rem !important;
        margin-bottom: 30px;
        color: black !important;
        text-align: center;
    }

    /* Tables in Print - Centered and Auto width */
    table {
        width: auto !important;
        margin-left: auto !important;
        margin-right: auto !important;
        border-collapse: collapse;
        font-size: 0.85rem;
        margin-bottom: 20px;
    }

    th,
    td {
        border: 1px solid #000;
        /* Darker border for print */
        padding: 4px 12px;
        color: black !important;
        text-align: center;
    }

    th {
        background-color: #f0f0f0 !important;
        font-weight: bold;
    }

    /* Align first column to left */
    td:first-child,
    th:first-child {
        text-align: left !important;
    }

    /* Footer */
    .print-footer {
        text-align: center;
        font-size: 0.9rem;
        border-top: 1px solid #000;
        padding-top: 10px;
        margin-top: auto;
    }

    canvas {
        max-width: 100% !important;
    }
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.modal-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: 20px;
    border: 1px solid var(--border-color);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    width: 90%;
    max-width: 500px;
    text-align: center;
}

#modal-title {
    margin-bottom: 1.5rem;
    font-weight: 700;
}

#modal-title.warning {
    color: var(--warning);
    font-size: calc(1.5rem + 4pt);
    /* 4 points larger than default H2 */
}

#modal-title.error {
    color: var(--danger);
    font-size: calc(1.5rem + 4pt);
}

#modal-title.success {
    color: var(--success);
    font-size: calc(1.5rem + 4pt);
}

#modal-message {
    color: var(--text-primary);
    font-size: calc(1rem + 2pt);
    /* 2 points larger than default body */
    margin-bottom: 2rem;
    line-height: 1.6;
}

.modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1) !important;
    color: var(--text-primary) !important;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2) !important;
}
/* Sorting Styles */
th.sortable {
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: background 0.2s ease;
}

th.sortable:hover {
    background: rgba(15, 23, 42, 0.6);
    color: var(--text-primary);
}

th.sortable::after {
    content: "";
    position: absolute;
    right: 8px;
    opacity: 0.3;
    font-size: 0.8rem;
}

th.sortable.sort-asc::after {
    content: "";
    opacity: 1;
    color: var(--accent-color);
}

th.sortable.sort-desc::after {
    content: "";
    opacity: 1;
    color: var(--accent-color);
}

