/* ============================================
   CSS Variables & Base Styles
   ============================================ */
:root {
    --primary-color: #1a365d;
    --primary-light: #2c5282;
    --secondary-color: #4a5568;
    --accent-color: #3182ce;
    --success-color: #38a169;
    --warning-color: #dd6b20;
    --danger-color: #e53e3e;
    --purple-color: #805ad5;
    
    --bg-color: #f7fafc;
    --card-bg: #ffffff;
    --border-color: #e2e8f0;
    --text-primary: #1a202c;
    --text-secondary: #718096;
    --text-muted: #a0aec0;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --transition: all 0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.hidden {
    display: none !important;
}

/* ============================================
   Login Screen
   ============================================ */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
    padding: 20px;
}

.login-container {
    background: var(--card-bg);
    padding: 48px 40px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo {
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.login-logo i {
    font-size: 32px;
    color: white;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.login-header p {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 500;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

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

.form-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 15px;
    font-family: inherit;
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.15);
}

.btn-login {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 24px;
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: var(--transition);
    margin-top: 8px;
}

.btn-login:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.login-error {
    color: var(--danger-color);
    font-size: 14px;
    text-align: center;
    min-height: 20px;
}

/* ============================================
   Dashboard Layout
   ============================================ */
.dashboard {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: var(--card-bg);
    padding: 16px 32px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-sm);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--primary-color), var(--accent-color));
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo i {
    font-size: 22px;
    color: white;
}

.header-title h1 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.header-title p {
    font-size: 13px;
    color: var(--text-secondary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.user-info span {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.btn-logout {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.btn-logout:hover {
    background: var(--danger-color);
    border-color: var(--danger-color);
    color: white;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 24px 32px;
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
}

/* ============================================
   Metrics Cards
   ============================================ */
.metrics-section {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.card {
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.metric-card {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: var(--transition);
}

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

.metric-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.metric-icon i {
    font-size: 24px;
    color: white;
}

.metric-icon.blue {
    background: linear-gradient(135deg, #3182ce, #63b3ed);
}

.metric-icon.green {
    background: linear-gradient(135deg, #38a169, #68d391);
}

.metric-icon.purple {
    background: linear-gradient(135deg, #805ad5, #b794f4);
}

.metric-icon.orange {
    background: linear-gradient(135deg, #dd6b20, #f6ad55);
}

.metric-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.metric-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.metric-label {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ============================================
   Charts Section
   ============================================ */
.charts-section {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 24px;
}

.chart-card {
    padding: 20px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-header h3 i {
    color: var(--accent-color);
    font-size: 16px;
}

.chart-container {
    position: relative;
    height: 280px;
}

/* ============================================
   Table Section
   ============================================ */
.table-section .card {
    padding: 20px;
}

.table-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.search-box,
.filter-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.search-box:focus-within,
.filter-box:focus-within {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 3px rgba(49, 130, 206, 0.1);
}

.search-box i,
.filter-box i {
    color: var(--text-muted);
    font-size: 14px;
}

.search-box input,
.filter-box select {
    border: none;
    background: transparent;
    font-size: 14px;
    font-family: inherit;
    color: var(--text-primary);
    min-width: 180px;
}

.search-box input:focus,
.filter-box select:focus {
    outline: none;
}

.table-wrapper {
    overflow-x: auto;
    margin: 16px 0;
}

.leads-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.leads-table th {
    text-align: left;
    padding: 14px 16px;
    background: var(--bg-color);
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.leads-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}

.leads-table th.sortable:hover {
    color: var(--accent-color);
}

.leads-table th.sortable i {
    margin-left: 6px;
    font-size: 12px;
}

.leads-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
    vertical-align: middle;
}

.leads-table tbody tr {
    transition: var(--transition);
}

.leads-table tbody tr:hover {
    background: var(--bg-color);
}

.leads-table tbody tr:last-child td {
    border-bottom: none;
}

.btn-view {
    padding: 8px 14px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition);
}

.btn-view:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

#table-info {
    font-size: 13px;
    color: var(--text-secondary);
}

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

.btn-page {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

.btn-page:hover:not(:disabled) {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: white;
}

.btn-page:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#page-info {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 48px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 15px;
}

/* ============================================
   Side Panel
   ============================================ */
.side-panel {
    position: fixed;
    top: 0;
    right: -450px;
    width: 450px;
    height: 100vh;
    background: var(--card-bg);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
}

.side-panel.open {
    right: 0;
}

.side-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.side-panel-overlay.open {
    opacity: 1;
    visibility: visible;
}

.side-panel-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-color);
}

.side-panel-header h3 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.btn-close-panel {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--card-bg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.btn-close-panel:hover {
    background: var(--danger-color);
    color: white;
}

.side-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.lead-detail {
    margin-bottom: 20px;
}

.lead-detail label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.lead-detail p {
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.5;
}

.lead-detail.resumo {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.resumo-content {
    background: var(--bg-color);
    padding: 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.7;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
}

/* ============================================
   Loading Overlay
   ============================================ */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.loader {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1400px) {
    .charts-section {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .charts-section .chart-card:last-child {
        grid-column: span 2;
    }
}

@media (max-width: 1200px) {
    .metrics-section {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 992px) {
    .header {
        padding: 12px 20px;
    }
    
    .main-content {
        padding: 20px;
    }
    
    .charts-section {
        grid-template-columns: 1fr;
    }
    
    .charts-section .chart-card:last-child {
        grid-column: span 1;
    }
    
    .side-panel {
        width: 100%;
        right: -100%;
    }
}

@media (max-width: 768px) {
    .metrics-section {
        grid-template-columns: 1fr;
    }
    
    .header-left {
        gap: 12px;
    }
    
    .header-title h1 {
        font-size: 16px;
    }
    
    .header-title p {
        font-size: 12px;
    }
    
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .table-controls {
        width: 100%;
    }
    
    .search-box,
    .filter-box {
        width: 100%;
    }
    
    .search-box input,
    .filter-box select {
        width: 100%;
        min-width: auto;
    }
    
    .leads-table {
        font-size: 13px;
    }
    
    .leads-table th,
    .leads-table td {
        padding: 10px 12px;
    }
    
    .table-footer {
        flex-direction: column;
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .login-container {
        padding: 32px 24px;
    }
    
    .user-info span {
        display: none;
    }
}
