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

:root {
    --bg: #f8f9fb;
    --surface: #ffffff;
    --card-bg: #ffffff;
    --hover-bg: #f0f4ff;
    --border: #eaecf0;
    --text: #18181b;
    --text-primary: #18181b;
    --text-secondary: #71717a;
    --text-muted: #a1a1aa;
    --primary: #1e293b;
    --primary-light: #f0f4ff;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --green: #22c55e;
    --red: #ef4444;
    --yellow: #f59e0b;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.06);
    --transition: 0.15s ease;
}

/* Dark mode */
[data-theme="dark"] {
    --bg: #0f1117;
    --surface: #1a1d2e;
    --card-bg: #1a1d2e;
    --hover-bg: #252840;
    --border: #2d3148;
    --text: #e2e8f0;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --primary: #e2e8f0;
    --primary-light: #1e2235;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
}
[data-theme="dark"] body { background: var(--bg); color: var(--text); }
[data-theme="dark"] .header { background: #131627; border-color: var(--border); }
[data-theme="dark"] select, [data-theme="dark"] input[type="text"], [data-theme="dark"] input[type="number"] {
    background: var(--surface); color: var(--text); border-color: var(--border);
}
[data-theme="dark"] select:focus, [data-theme="dark"] input:focus {
    border-color: #4b5563; box-shadow: 0 0 0 3px rgba(255,255,255,0.05);
}
[data-theme="dark"] .multiselect-input { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] .multiselect-dropdown { background: var(--surface); border-color: var(--border); }
[data-theme="dark"] .multiselect-search { background: var(--surface); color: var(--text); border-color: var(--border); }
[data-theme="dark"] table { color: var(--text); }
[data-theme="dark"] th { background: var(--primary-light); color: var(--text-muted); }
[data-theme="dark"] tr:hover td { background: var(--hover-bg); }
[data-theme="dark"] .btn-outline { background: var(--surface); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .btn-outline:hover { background: var(--hover-bg); }
[data-theme="dark"] .pagination button { background: var(--surface); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .sc-notes { background: var(--surface); color: var(--text); border-color: var(--border); }
[data-theme="dark"] .geo-dl-btn { background: var(--surface); color: var(--accent); border-color: var(--border); }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
.header {
    background: #1e293b;
    color: white;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.3px;
    color: white;
}

.header-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn-header {
    padding: 6px 12px;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    background: transparent;
    color: white;
    transition: var(--transition);
}

.btn-header:hover { background: rgba(255,255,255,0.1); }

/* ── Layout ── */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px 24px;
}

/* ── Stats ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow); }

.stat-card .label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-card .value {
    font-size: 24px;
    font-weight: 600;
    margin-top: 2px;
    color: var(--text);
    letter-spacing: -0.5px;
}

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
}

.tab {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    color: var(--text-secondary);
    transition: var(--transition);
}

.tab:hover { color: var(--text); }
.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
    font-weight: 600;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── Search bar ── */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 14px;
    margin-bottom: 12px;
}

.search-bar svg {
    flex-shrink: 0;
    color: var(--text-muted);
}

.search-bar input {
    border: none;
    background: none;
    font-size: 14px;
    color: var(--text);
    width: 100%;
    padding: 2px 0;
}

.search-bar input:focus {
    outline: none;
    box-shadow: none;
}

.search-bar input::placeholder { color: var(--text-muted); }

/* ── Filters ── */
.filters-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 12px;
    overflow: visible;
}

.filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    cursor: pointer;
    user-select: none;
    transition: var(--transition);
}

.filters-header:hover { background: var(--primary-light); }

.filters-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.filters-actions { display: flex; align-items: center; gap: 8px; }

.chevron {
    color: var(--text-muted);
    transition: transform 0.2s ease;
}

.chevron.collapsed { transform: rotate(-90deg); }

.filters-body { padding: 0 16px 14px; }
.filters-body.collapsed { display: none; }

.filters-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 130px;
    flex: 1;
    max-width: 200px;
}

.filter-group-niche {
    min-width: 200px;
    max-width: 300px;
    position: relative;
}

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

/* Multi-select component */
.multiselect { position: relative; }

.multiselect-input {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    cursor: pointer;
    font-size: 14px;
    min-height: 38px;
    transition: border-color var(--transition);
}
.multiselect-input:hover { border-color: var(--accent); }

.multiselect-placeholder { color: var(--text-secondary); }
.multiselect-placeholder.has-selection { color: var(--text); font-weight: 500; }

.multiselect-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    min-width: 280px;
    background: var(--surface);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 100;
    overflow: hidden;
}

.multiselect-search {
    width: 100%;
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    font-size: 13px;
    outline: none;
}

.multiselect-options {
    max-height: 240px;
    overflow-y: auto;
}

.multiselect-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    transition: background var(--transition);
}
.multiselect-option:hover { background: var(--primary-light); }

.multiselect-option input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.multiselect-option .count {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 11px;
}

.multiselect-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 4px;
}

.multiselect-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: var(--primary-light);
    color: var(--accent);
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

.multiselect-pill .remove {
    cursor: pointer;
    font-size: 13px;
    line-height: 1;
    opacity: 0.6;
}
.multiselect-pill .remove:hover { opacity: 1; }

.active-filters-count {
    background: var(--accent);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 0 6px;
    border-radius: 8px;
    display: none;
    line-height: 18px;
}

.active-filters-count.visible { display: inline-block; }

select, input[type="text"], input[type="number"], input[type="password"], textarea {
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    background: var(--surface);
    color: var(--text);
    width: 100%;
    min-height: 38px;
    transition: var(--transition);
}

select:focus, input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

/* ── Buttons ── */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    white-space: nowrap;
    min-height: 38px;
    transition: var(--transition);
}

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

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

.btn-outline {
    background: var(--surface);
    color: var(--text);
    border: 1.5px solid var(--border);
}
.btn-outline:hover { background: var(--primary-light); border-color: var(--accent); }

.btn-sm { padding: 6px 12px; font-size: 13px; min-height: 32px; }

/* ── Table ── */
.table-wrapper {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 220px);
}

#tab-leads thead th {
    position: sticky;
    top: 0;
    z-index: 10;
}

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

.table-toolbar .count {
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}

table { width: 100%; border-collapse: collapse; }
#tab-leads table { table-layout: fixed; }

th {
    text-align: left;
    padding: 8px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--primary-light);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    font-weight: 600;
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
}

th:hover { color: var(--text-secondary); }

/* Column resize handle */
.th-resize {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 5px;
    cursor: col-resize;
    user-select: none;
}

.th-resize:hover,
.th-resize.active {
    background: var(--border);
}

td {
    padding: 8px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    overflow: hidden;
    text-overflow: ellipsis;
}

td, th { white-space: nowrap; }

tr:hover td { background: #f8faff; }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    letter-spacing: 0.2px;
}

.badge-brut { background: #f4f4f5; color: #71717a; }
.badge-enrichi { background: #eff6ff; color: #2563eb; }
.badge-exclu { background: #fef2f2; color: #dc2626; }
.badge-site_pret { background: #fffbeb; color: #d97706; }
.badge-deploye { background: #f0fdf4; color: #16a34a; }
.badge-contacte { background: #eef2ff; color: #4f46e5; }
.badge-ouvert { background: #fdf4ff; color: #a855f7; }
.badge-clique { background: #fdf4ff; color: #a855f7; }
.badge-repondu { background: #fdf2f8; color: #db2777; }
.badge-converti { background: #f0fdf4; color: #16a34a; }
.badge-refuse { background: #fef2f2; color: #dc2626; }

.badge-sm {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
    background: #f4f4f5;
    color: #71717a;
}

/* ── Link icons ── */
.links-cell {
    white-space: nowrap;
}

.link-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 5px;
    color: var(--accent);
    transition: var(--transition);
    vertical-align: middle;
}

a.link-icon:hover { background: var(--primary-light); }

.link-icon.disabled {
    color: #d4d4d8;
    cursor: default;
}

.link-icon.link-wa { color: #25d366; }
.link-icon.link-wa:hover { background: #dcfce7; }

.niche-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}

td[ondblclick] { cursor: text; }
td[ondblclick]:hover { background: #f0f4ff; }

td .sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 1px;
}

/* ── Rating ── */
.rating { color: var(--yellow); font-weight: 600; }

/* ── Pagination ── */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 4px;
    padding: 12px;
}

.pagination button {
    padding: 6px 12px;
    border: 1.5px solid var(--border);
    background: var(--surface);
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    transition: var(--transition);
}

.pagination button:hover { background: var(--primary-light); }
.pagination button:disabled { opacity: 0.3; cursor: default; }
.pagination .current { font-size: 13px; color: var(--text-secondary); font-weight: 500; }

/* ── Import / Scraper sections ── */
.import-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
}

.import-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar .fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s;
    border-radius: 3px;
}

.progress-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ── Sidecart ── */
.sidecart-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.2);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
}

.sidecart-overlay.open { opacity: 1; pointer-events: auto; }

.sidecart {
    position: fixed;
    top: 0;
    right: 0;
    width: 460px;
    max-width: 90vw;
    height: 100vh;
    background: var(--surface);
    box-shadow: -4px 0 20px rgba(0,0,0,0.08);
    z-index: 201;
    transform: translateX(100%);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidecart.open { transform: translateX(0); }

.sidecart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    flex-shrink: 0;
}

.sidecart-header h2 {
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 12px;
}

.sidecart-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    flex-shrink: 0;
    transition: var(--transition);
}

.sidecart-close:hover { color: var(--text); }

.sidecart-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.sc-section { margin-bottom: 16px; }

.sc-section h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 600;
}

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

.sc-table td {
    padding: 5px 0;
    font-size: 13px;
    border: none;
    vertical-align: top;
    white-space: normal;
}

.sc-table tr:hover td { background: transparent; }

.sc-label {
    color: var(--text-secondary);
    font-weight: 500;
    width: 120px;
    padding-right: 12px;
}

.sc-value { color: var(--text); word-break: break-word; }
.sc-value a { color: var(--text); text-decoration: underline; text-decoration-color: var(--border); text-underline-offset: 2px; }
.sc-value a:hover { text-decoration-color: var(--text); }

.sc-notes {
    width: 100%;
    min-height: 80px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    color: var(--text);
}

.sc-notes:focus {
    outline: none;
    border-color: #d4d4d8;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.04);
}

/* ── WP Scanner stats ── */
.wp-stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    margin-bottom: 16px;
}

.wp-stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    transition: var(--transition);
}

.wp-stat-card:hover { box-shadow: var(--shadow); }

.wp-stat-card .label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.wp-stat-card .value {
    font-size: 24px;
    font-weight: 600;
    margin-top: 2px;
    letter-spacing: -0.5px;
}

.wp-stat-infected .value { color: var(--red); }
.wp-stat-new .value { color: var(--yellow); }
.wp-stat-ongoing .value { color: #ea580c; }
.wp-stat-resolved .value { color: var(--green); }
.wp-stat-clean .value { color: var(--green); }
.wp-stat-pending .value { color: var(--text-muted); }
.wp-stat-errors .value { color: var(--yellow); }

/* ── Confirmation modal ── */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 9000;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal-box {
    background: var(--surface); border-radius: 12px; padding: 24px 28px;
    max-width: 420px; width: 90%; box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}
.modal-box h3 { font-size: 16px; font-weight: 600; margin-bottom: 8px; color: var(--text); }
.modal-box p { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.modal-actions .btn { min-width: 80px; justify-content: center; }

/* ── Dark mode toggle ── */
.theme-toggle {
    background: transparent; border: 1px solid rgba(255,255,255,0.3);
    color: white; padding: 4px 8px; border-radius: 6px; cursor: pointer;
    font-size: 16px; line-height: 1; transition: var(--transition);
}
.theme-toggle:hover { background: rgba(255,255,255,0.1); }

/* ── Scraper timer ── */
.scraper-timer {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 13px; font-weight: 600; color: var(--accent);
    padding: 4px 10px; background: var(--primary-light);
    border-radius: 6px; font-variant-numeric: tabular-nums;
}

/* ── Dashboard analytics ── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
.dashboard-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.dashboard-card h4 { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; font-weight: 600; }
.chart-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.chart-bar-label { font-size: 12px; color: var(--text-secondary); min-width: 80px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chart-bar-fill { height: 20px; border-radius: 4px; background: var(--accent); min-width: 2px; transition: width 0.3s; }
.chart-bar-value { font-size: 12px; font-weight: 600; color: var(--text); min-width: 40px; }

/* ── Responsive ── */
@media (max-width: 768px) {
    .header { padding: 0 12px; gap: 8px; }
    .header h1 { font-size: 13px; }
    .filter-group { max-width: none; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .wp-stats-grid { grid-template-columns: repeat(2, 1fr); }
    .dashboard-grid { grid-template-columns: 1fr; }
    td, th { padding: 6px 8px; font-size: 12px; }
    .container { padding: 12px; }
    /* Hide less useful columns on mobile */
    .hide-mobile { display: none !important; }
    .sidecart { width: 100%; max-width: 100vw; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .tabs { overflow-x: auto; flex-wrap: nowrap; }
    .tab { font-size: 12px; padding: 8px 10px; white-space: nowrap; }
}

/* Score grades */
.score-grade {
    display: inline-block;
    width: 22px; height: 22px;
    line-height: 22px;
    text-align: center;
    border-radius: 4px;
    font-weight: 700;
    font-size: 12px;
    color: #fff;
}
.score-A { background: #22c55e; }
.score-B { background: #3b82f6; }
.score-C { background: #f59e0b; }
.score-D { background: #ef4444; }

/* Geo download buttons */
.geo-dl-btn {
    padding: 3px 8px;
    font-size: 11px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--accent);
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}
.geo-dl-btn:hover {
    background: var(--accent);
    color: #fff;
}
