* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
}

.container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    background: var(--surface);
    padding: 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.last-update {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* Month Selector */
.month-selector {
    background: var(--surface);
    padding: 16px 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.month-selector label {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
}

.month-selector select {
    padding: 10px 16px;
    border: 2px solid var(--primary-color);
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-color);
    background: white;
    cursor: pointer;
    min-width: 160px;
    transition: all 0.2s;
}

.month-selector select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.month-selector select:hover {
    background: #f0f6ff;
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.card {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.card-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.card-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.card-value.highlight {
    color: var(--primary-color);
}

.card-value.positive {
    color: var(--success-color);
}

.card-value.negative {
    color: var(--danger-color);
}

.card.cogs-idle {
    background: linear-gradient(135deg, #fff5f5 0%, #ffffff 100%);
    border-left: 4px solid var(--warning-color);
}

.card.cogs-idle:hover {
    background: linear-gradient(135deg, #fff1f1 0%, #ffffff 100%);
}

/* Filters */
.filters {
    background: var(--surface);
    padding: 24px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.filter-group label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
}

.filter-group input,
.filter-group select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    background: var(--surface);
    color: var(--text-primary);
    transition: border-color 0.2s;
}

.filter-group input:focus,
.filter-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-clear {
    padding: 10px 20px;
    background: var(--secondary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    height: fit-content;
}

.btn-clear:hover {
    background: #475569;
}

/* Results Info */
.results-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 0 4px;
}

.results-info span {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.btn-export {
    padding: 8px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-export:hover {
    background: #1d4ed8;
}

/* Table */
.table-container {
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead {
    background: var(--background);
    position: sticky;
    top: 0;
    z-index: 10;
}

th {
    padding: 16px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

th:hover {
    background: #f1f5f9;
}

.sort-icon {
    margin-left: 4px;
    color: var(--text-secondary);
    font-size: 0.75rem;
}

th.sorted-asc .sort-icon::before {
    content: '↑';
}

th.sorted-desc .sort-icon::before {
    content: '↓';
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

tbody tr:hover {
    background: var(--background);
}

td {
    padding: 12px;
    color: var(--text-primary);
}

td.currency {
    font-family: 'Monaco', 'Courier New', monospace;
    font-weight: 500;
    text-align: right;
}

td.positive {
    color: var(--success-color);
}

td.negative {
    color: var(--danger-color);
}

td.center {
    text-align: center;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge.pj {
    background: #dbeafe;
    color: #1e40af;
}

.badge.clt {
    background: #dcfce7;
    color: #15803d;
}

/* Scrollbar */
.table-container {
    max-height: calc(100vh - 400px);
    overflow: auto;
    min-height: 500px;
}

.table-container::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

.table-container::-webkit-scrollbar-track {
    background: var(--background);
}

.table-container::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 6px;
}

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

.table-container::-webkit-scrollbar-corner {
    background: var(--background);
}

/* Loading State */
.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 1200px) {
    .container {
        padding: 16px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .summary-cards {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: 12px;
    }

    .card {
        padding: 16px;
    }

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

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

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

    table {
        min-width: 1600px;
    }
}

@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }

    .results-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

/* Insights Section */
.insights-section {
    background: var(--surface);
    padding: 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

.insights-section h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
}

.insight-card {
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 20px;
}

.insight-card.wide {
    grid-column: span 2;
}

.insight-card.alert {
    background: #fef3c7;
    border-color: var(--warning-color);
}

.insight-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 15px;
}

.insight-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.metric-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.metric-row:last-child {
    border-bottom: none;
}

.metric-label {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.metric-value {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
}

.metric-value.positive {
    color: var(--success-color);
}

.metric-value.negative {
    color: var(--danger-color);
}

.metric-value.warning {
    color: var(--warning-color);
}

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

.insight-table th {
    background: var(--surface);
    padding: 10px;
    text-align: left;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
}

.insight-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.insight-table tbody tr:hover {
    background: rgba(37, 99, 235, 0.05);
}

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

.opportunities-list li {
    padding: 10px;
    margin-bottom: 8px;
    background: white;
    border-left: 3px solid var(--warning-color);
    border-radius: 4px;
    font-size: 0.95rem;
}

.opportunities-list li:last-child {
    margin-bottom: 0;
}

@media (max-width: 1024px) {
    .insight-card.wide {
        grid-column: span 1;
    }

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

/* Idle Section */
.idle-section {
    background: var(--surface);
    padding: 30px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    margin-bottom: 30px;
}

.idle-section h2 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.idle-filters {
    display: flex;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.idle-filters .filter-group {
    min-width: 200px;
}

.idle-section .table-container {
    max-height: 400px;
    min-height: auto;
}

/* Idle badges */
.badge.idle-total {
    background: #fee2e2;
    color: #b91c1c;
}

.badge.idle-partial {
    background: #fef3c7;
    color: #b45309;
}

.badge.idle-sem-previsao {
    background: #fee2e2;
    color: #b91c1c;
}

.badge.idle-com-previsao {
    background: #dcfce7;
    color: #15803d;
}

.badge.idle-desalocacao {
    background: #ffedd5;
    color: #c2410c;
}

.badge.idle-preview {
    background: #ffedd5;
    color: #c2410c;
}

/* ============================================================
   ACCESS MGMT BUTTON
   ============================================================ */
.btn-access-mgmt {
    background: #6366f1;
    color: #fff;
}

.btn-access-mgmt:hover {
    background: #4f46e5;
}

/* ============================================================
   MODAL GESTÃO DE ACESSO
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-container {
    background: #fff;
    border-radius: 12px;
    width: 100%;
    max-width: 860px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 16px;
    border-bottom: 1px solid #e2e8f0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
    color: #1e293b;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #64748b;
    line-height: 1;
    padding: 0 4px;
}

.modal-close:hover { color: #1e293b; }

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
}

.modal-toolbar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.btn-primary {
    background: #3b82f6;
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
}

.btn-primary:hover { background: #2563eb; }

.btn-cancel {
    background: #f1f5f9;
    color: #475569;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
}

.btn-cancel:hover { background: #e2e8f0; }

.btn-edit {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-edit:hover { background: #dcfce7; }

.btn-delete {
    background: #fff1f2;
    color: #be123c;
    border: 1px solid #fecdd3;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
}

.btn-delete:hover { background: #ffe4e6; }

#usersTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

#usersTable th {
    background: #f8fafc;
    color: #475569;
    font-weight: 600;
    padding: 10px 12px;
    text-align: left;
    border-bottom: 2px solid #e2e8f0;
}

#usersTable td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

#usersTable tr:last-child td { border-bottom: none; }

.user-form-section {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

.user-form-section h3 {
    margin: 0 0 16px;
    font-size: 1rem;
    color: #1e293b;
}

.user-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 12px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.form-group input, .form-group select {
    padding: 8px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #1e293b;
    background: #fff;
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.15);
}

.clientes-checkbox-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 160px;
    overflow-y: auto;
    padding: 10px;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
}

.clientes-checkbox-list label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: 4px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.clientes-checkbox-list label:hover { background: #f0f9ff; border-color: #93c5fd; }

.user-form-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 16px;
}

.clientes-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.cliente-tag {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 0.75rem;
}

/* ============================================================
   LOGIN OVERLAY
   ============================================================ */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.login-card {
    background: white;
    padding: 48px;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 420px;
    width: 90%;
}

.login-logo {
    font-size: 3rem;
    margin-bottom: 16px;
}

.login-card h1 {
    font-size: 1.75rem;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 32px;
    font-size: 0.95rem;
}

.login-error {
    color: var(--danger-color);
    margin-bottom: 16px;
    font-size: 0.875rem;
    padding: 10px;
    background: #fef2f2;
    border-radius: 8px;
}

#googleSignInButton {
    display: flex;
    justify-content: center;
}

/* ============================================================
   HEADER COM USER INFO
   ============================================================ */
.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border);
}

#userName {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--text-primary);
}

.user-role-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.user-role-badge.role-admin {
    background: #dbeafe;
    color: #1e40af;
}

.user-role-badge.role-gestor {
    background: #dcfce7;
    color: #15803d;
}

.btn-logout {
    padding: 6px 14px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
    transition: all 0.2s;
}

.btn-logout:hover {
    background: var(--background);
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.btn-sync {
    padding: 8px 16px;
    background: var(--success-color);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-sync:hover {
    background: #059669;
}

.btn-sync:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-auth-sync {
    background: var(--primary-color);
}

.btn-auth-sync:hover {
    background: #1d4ed8;
}

@media (max-width: 768px) {
    .header-right {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .user-info {
        flex-wrap: wrap;
    }

    .login-card {
        padding: 32px 24px;
    }
}
