/* ============================================================
   LEADS PANEL — DESIGN SYSTEM
   ============================================================ */
:root {
    --primary:    #4f46e5;
    --primary-h:  #4338ca;
    --success:    #16a34a;
    --danger:     #dc2626;
    --warning:    #d97706;
    --bg:         #f1f5f9;
    --surface:    #ffffff;
    --border:     #e2e8f0;
    --text:       #0f172a;
    --muted:      #64748b;
    --sidebar-w:  240px;
    --radius:     10px;
    --shadow:     0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

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

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.6;
}

/* ============================================================ SIDEBAR */
.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-w); height: 100vh;
    background: #1e1b4b;
    display: flex; flex-direction: column;
    z-index: 100;
    transition: transform .25s ease;
}
.sidebar-logo {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    color: #fff; font-size: 17px; font-weight: 700;
}
.sidebar-credits {
    display: flex; justify-content: space-between; align-items: center;
    margin: 12px 14px;
    background: rgba(255,255,255,.07);
    border-radius: 8px;
    padding: 8px 12px;
    color: #a5b4fc;
    font-size: 12px;
}
.credits-value { font-weight: 700; color: #c7d2fe; font-size: 15px; }

.sidebar-menu { list-style: none; flex: 1; overflow-y: auto; padding: 8px 0; }
.sidebar-menu li a {
    display: flex; align-items: center; gap: 9px;
    padding: 9px 18px;
    color: #c4c9e8;
    text-decoration: none;
    border-radius: 0;
    transition: background .15s, color .15s;
}
.sidebar-menu li a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-menu li.active a { background: var(--primary); color: #fff; }
.sidebar-menu .menu-group {
    padding: 14px 18px 4px;
    color: #6b7280;
    font-size: 10px;
    letter-spacing: .08em;
    text-transform: uppercase;
    font-weight: 600;
}
.ic { font-size: 15px; }

.sidebar-user {
    display: flex; align-items: center; gap: 10px;
    padding: 14px;
    border-top: 1px solid rgba(255,255,255,.08);
}
.user-avatar {
    width: 34px; height: 34px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-info { flex: 1; overflow: hidden; }
.user-info strong { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info span   { display: block; color: #8b92b8; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout { color: #8b92b8; font-size: 18px; text-decoration: none; }
.btn-logout:hover { color: #fff; }

/* ============================================================ MAIN */
.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex; flex-direction: column;
}
.topbar {
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 12px;
    padding: 0 20px;
    position: sticky; top: 0; z-index: 50;
}
.sidebar-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }
.topbar-title   { font-size: 16px; font-weight: 600; flex: 1; }
.topbar-right   { display: flex; align-items: center; gap: 10px; }
.badge-credits  { background: #ede9fe; color: var(--primary); padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.theme-toggle {
    width: 34px; height: 34px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 50%;
    font-size: 16px;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s, border-color .15s;
}
.theme-toggle:hover { background: var(--bg); border-color: var(--primary); }
.page-body      { padding: 20px; flex: 1; }

/* ============================================================ CARDS */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.card-header { margin-bottom: 16px; }
.card-header.between { display: flex; justify-content: space-between; align-items: flex-start; }
.card-header h2 { font-size: 16px; font-weight: 600; }

/* ============================================================ BUTTONS */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 13px; font-weight: 500;
    cursor: pointer; border: none; text-decoration: none;
    transition: background .15s, opacity .15s;
    white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover { opacity: .9; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-secondary { background: #e2e8f0; color: #334155; }
.btn-secondary:hover { background: #cbd5e1; }
.btn-outline  { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-block    { width: 100%; justify-content: center; }
.btn-sm       { padding: 4px 10px; font-size: 12px; }

/* ============================================================ FORMS */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
input[type=text],input[type=email],input[type=password],input[type=number],select,textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }

/* ============================================================ SEARCH BAR */
.search-bar {
    display: flex; gap: 10px;
    margin-bottom: 16px;
}
.input-cnpj {
    flex: 1;
    padding: 10px 14px;
    font-size: 16px;
    border: 2px solid var(--border);
    border-radius: 10px;
    font-family: 'Courier New', monospace;
    letter-spacing: .08em;
}
.input-cnpj:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px rgba(79,70,229,.12); }

/* ============================================================ FILTER BAR */
.filter-bar {
    display: flex; gap: 10px; flex-wrap: wrap;
    margin-bottom: 16px;
    padding: 14px;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}
.input-filter { flex: 1; min-width: 160px; padding: 7px 10px; }
.select-filter { flex: 0 0 auto; min-width: 140px; padding: 7px 10px; }

/* ============================================================ TABLES */
.table-wrapper { overflow-x: auto; }
.data-table {
    width: 100%; border-collapse: collapse;
    font-size: 13px;
}
.data-table th {
    background: var(--bg);
    padding: 9px 12px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
}
.data-table td {
    padding: 9px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.data-table.striped tbody tr:nth-child(even) { background: #f8fafc; }
.data-table.striped tbody tr:hover { background: #f0f4ff; }
.mono { font-family: 'Courier New', monospace; font-size: 12px; }

/* ============================================================ BADGES */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-danger  { background: #fee2e2; color: #b91c1c; }
.badge-warning { background: #fef9c3; color: #92400e; }
.badge-info    { background: #e0f2fe; color: #0369a1; }

/* ============================================================ ALERTS */
.alert {
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 13px;
    border-left: 4px solid transparent;
}
.alert.small { padding: 6px 10px; font-size: 12px; }
.alert-success { background: #f0fdf4; border-color: var(--success); color: #15803d; }
.alert-error   { background: #fef2f2; border-color: var(--danger);  color: #b91c1c; }
.alert-warning { background: #fffbeb; border-color: var(--warning); color: #92400e; }

/* ============================================================ RESULT CARD */
.result-area { margin-top: 16px; }
.result-area.hidden { display: none; }
.result-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.result-header {
    display: flex; justify-content: space-between; align-items: flex-start;
    padding: 16px 18px;
    background: #f8fafc;
    border-bottom: 1px solid var(--border);
}
.result-header h3 { font-size: 16px; font-weight: 700; margin-bottom: 2px; }
.socio-box { padding: 14px 18px; background: #f0f4ff; border-top: 1px solid var(--border); }
.socio-box h4 { font-size: 13px; margin-bottom: 8px; }
.result-actions { padding: 12px 18px; border-top: 1px solid var(--border); }

/* Abas do resultado (Geral / Bradesco / ...) */
.res-tabs { display: flex; gap: 2px; padding: 0 18px; background: #f8fafc; border-bottom: 1px solid var(--border); overflow-x: auto; }
.res-tab {
    padding: 10px 14px; border: none; background: none; cursor: pointer;
    font-size: 13px; font-weight: 600; color: #64748b;
    border-bottom: 2px solid transparent; white-space: nowrap;
}
.res-tab:hover { color: var(--primary); }
.res-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.res-pane { display: none; }
.res-pane.active { display: block; }
.res-pane > .bradesco-box { padding: 14px 18px; background: #fff7ed; }
.res-pane > .bradesco-box h4 { font-size: 13px; margin-bottom: 8px; }

/* ============================================================ LOTE */
.textarea-lote {
    width: 100%; height: 150px;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    resize: vertical;
}
.lote-footer { display: flex; justify-content: space-between; align-items: center; margin: 10px 0; }
.lote-progress { margin: 10px 0; }
.lote-progress.hidden { display: none; }
.progress-bar { height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
.progress-fill { height: 100%; background: var(--primary); transition: width .3s; }
.lote-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 10px; font-size: 12px;
    border-bottom: 1px solid #f1f5f9;
}
.lote-item.ok { background: #f0fdf4; }
.lote-item.err { background: #fef2f2; }

/* ============================================================ PAGINATION */
.pagination { display: flex; gap: 6px; align-items: center; padding-top: 16px; flex-wrap: wrap; }
.pag-info { font-size: 12px; color: var(--muted); margin-right: 8px; }

/* ============================================================ PLANS */
.plans-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px,1fr)); gap: 16px; margin-top: 16px; }
.plan-card {
    border: 2px solid var(--border);
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    transition: border-color .2s;
}
.plan-card:hover { border-color: var(--primary); }
.plan-name { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; }
.plan-credits { font-size: 36px; font-weight: 800; color: var(--primary); }
.plan-label { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.plan-price { font-size: 20px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.plan-desc { font-size: 12px; color: var(--muted); margin-bottom: 14px; min-height: 30px; }

/* ============================================================ STATS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px,1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 16px;
    text-align: center;
    box-shadow: var(--shadow);
}
.stat-card.stat-alert { border-color: var(--warning); background: #fffbeb; }
.stat-num { font-size: 30px; font-weight: 800; color: var(--primary); }
.stat-card.stat-alert .stat-num { color: var(--warning); }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ============================================================ MODAL */
.modal {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.4); z-index: 200;
    align-items: center; justify-content: center;
}
.modal.open { display: flex; }
.modal-box {
    background: var(--surface);
    border-radius: 14px;
    padding: 24px;
    width: 100%; max-width: 460px;
    box-shadow: 0 20px 60px rgba(0,0,0,.2);
}
.modal-box h3 { font-size: 16px; margin-bottom: 18px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.format-btns { display: flex; gap: 18px; }
.format-btns label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; font-weight: 500; }

/* ============================================================ AUTH PAGE */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: #0f0e2a; }
.auth-box {
    background: var(--surface);
    border-radius: 16px;
    padding: 36px 32px;
    width: 100%; max-width: 400px;
    box-shadow: 0 24px 80px rgba(0,0,0,.3);
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; font-size: 20px; font-weight: 700; }
.auth-box h2 { font-size: 20px; margin-bottom: 20px; }
.auth-footer { margin-top: 18px; text-align: center; font-size: 13px; color: var(--muted); }
.auth-footer a { color: var(--primary); text-decoration: none; font-weight: 600; }

/* ============================================================ SPINNER */
.spinner {
    width: 40px; height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================ UTILITIES */
.text-center { text-align: center; }
.text-muted  { color: var(--muted); font-size: 13px; }
.actions-group { display: flex; gap: 8px; flex-wrap: wrap; }
.hidden { display: none !important; }

/* ============================================================ RESPONSIVE */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .sidebar-toggle { display: block; }
    .filter-bar { flex-direction: column; }
    .search-bar { flex-direction: column; }
    .plans-grid { grid-template-columns: 1fr 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .plans-grid, .stats-grid { grid-template-columns: 1fr; }
    .page-body { padding: 12px; }
}

/* ============================================================ PIPELINE CNPJ */
.pipeline-banner { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; }
.pipeline-banner h2 { font-size: 18px; font-weight: 700; }
.pipeline-banner p { color: var(--muted); font-size: 13px; max-width: 560px; }

.steps-bar { display: flex; margin: 14px 0 4px; }
.step-dot { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; position: relative; }
.step-dot .num {
    width: 34px; height: 34px; border-radius: 50%;
    background: #e2e8f0; color: #94a3b8;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px; border: 3px solid #fff;
    box-shadow: 0 0 0 1px var(--border); z-index: 1;
}
.step-dot.done .num { background: var(--success); color: #fff; box-shadow: 0 0 0 1px var(--success); }
.step-dot.cur  .num { background: var(--primary); color: #fff; box-shadow: 0 0 0 1px var(--primary); }
.step-dot .lbl { font-size: 11px; color: var(--muted); text-align: center; font-weight: 600; }
.step-dot.done .lbl { color: #15803d; }
.step-dot.cur .lbl { color: var(--primary); }
.step-dot::before {
    content: ''; position: absolute; top: 17px; z-index: 0;
    left: calc(-50% + 34px); width: calc(100% - 34px); height: 3px;
    background: #e2e8f0;
}
.step-dot.done::before { background: var(--success); }
.step-dot:first-child::before { display: none; }

.step-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.step-title { display: flex; gap: 12px; align-items: flex-start; }
.step-badge-num {
    width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 14px;
}
.step-title h3 { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.step-title p { color: var(--muted); font-size: 12px; }
.step-count { text-align: right; white-space: nowrap; }
.step-count .big { font-size: 22px; font-weight: 800; color: var(--primary); }
.step-count .lbl { font-size: 11px; color: var(--muted); }

.import-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.import-row input[type=number] { width: 90px; }
.grow { flex: 1; min-width: 200px; }
.progress-log { margin-top: 12px; font-size: 12px; }
.progress-log .ln { padding: 3px 0; border-bottom: 1px dashed #f1f5f9; color: var(--muted); }
.progress-log .ln.ok { color: #15803d; }
.progress-log .ln.err { color: #b91c1c; }
.tel-fonte { font-size: 10px; color: var(--muted); font-weight: 600; }

@media (max-width: 768px) { .steps-bar { flex-wrap: wrap; row-gap: 14px; } }

/* ============================================================ TEMA ESCURO
   Ativado via <html data-theme="dark"> (botao de tema no topbar) */
html[data-theme="dark"] {
    --primary:    #6366f1;
    --primary-h:  #818cf8;
    --success:    #22c55e;
    --danger:     #ef4444;
    --warning:    #f59e0b;
    --bg:         #0b1220;
    --surface:    #111a2c;
    --border:     #223052;
    --text:       #e2e8f0;
    --muted:      #7e8aa6;
    --shadow:     0 1px 4px rgba(0,0,0,.35), 0 4px 16px rgba(0,0,0,.30);
}

html[data-theme="dark"] body,
html[data-theme="dark"] .card,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .stat-card,
html[data-theme="dark"] .modal-box {
    transition: background-color .25s ease, color .25s ease, border-color .25s ease;
}

html[data-theme="dark"] .badge-credits { background: #2c2b5e; }
html[data-theme="dark"] .btn-secondary { background: #232e4a; color: #cbd5e1; }
html[data-theme="dark"] .btn-secondary:hover { background: #2b3959; }

html[data-theme="dark"] .data-table td { border-bottom: 1px solid #1c2740; }
html[data-theme="dark"] .data-table.striped tbody tr:nth-child(even) { background: #0f1830; }
html[data-theme="dark"] .data-table.striped tbody tr:hover { background: #162039; }

html[data-theme="dark"] .badge-success { background: #0f2b1a; color: #34d399; }
html[data-theme="dark"] .badge-danger  { background: #331418; color: #f87171; }
html[data-theme="dark"] .badge-warning { background: #332b12; color: #fbbf24; }
html[data-theme="dark"] .badge-info    { background: #0f2a3a; color: #38bdf8; }

html[data-theme="dark"] .alert-success { background: #0d2418; color: #34d399; }
html[data-theme="dark"] .alert-error   { background: #2a1215; color: #f87171; }
html[data-theme="dark"] .alert-warning { background: #2a2112; color: #fbbf24; }

html[data-theme="dark"] .result-header,
html[data-theme="dark"] .res-tabs { background: #0f1830; }
html[data-theme="dark"] .socio-box { background: #162039; }
html[data-theme="dark"] .res-pane > .bradesco-box { background: #2b2116; }

html[data-theme="dark"] .lote-item { border-bottom: 1px solid #1c2740; }
html[data-theme="dark"] .lote-item.ok { background: #0d2418; }
html[data-theme="dark"] .lote-item.err { background: #2a1215; }
html[data-theme="dark"] .progress-bar { background: #232e4a; }
html[data-theme="dark"] .progress-log .ln { border-bottom: 1px dashed #1c2740; }
html[data-theme="dark"] .progress-log .ln.ok { color: #34d399; }
html[data-theme="dark"] .progress-log .ln.err { color: #f87171; }

html[data-theme="dark"] .stat-card.stat-alert { background: #2a2112; }

html[data-theme="dark"] .step-dot .num {
    background: #232e4a; color: #94a3b8; border: 3px solid #111a2c;
}
html[data-theme="dark"] .step-dot.done .lbl { color: #34d399; }
html[data-theme="dark"] .step-dot::before { background: #232e4a; }
