:root {
    --bg-primary: #0d0d0d;
    --bg-secondary: #111111;
    --bg-card: #181818;
    --bg-input: #1f1f1f;
    --border: #2a2a2a;
    --text-primary: #f0f0f0;
    --text-secondary: #888888;
    --accent: #FF7A0A;
    --accent-hover: #FF5F00;
    --accent-glow: rgba(255, 122, 10, 0.12);
    --accent-cyan: #00EBFF;
    --success: #37ca37;
    --warning: #f5a623;
    --danger: #ef4444;
    --radius: 8px;
}

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

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

h1, h2, h3, h4, h5, h6 {
    font-family: 'Montserrat', sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Layout */
.app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 220px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    padding: 24px 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
    border-top: 3px solid var(--accent);
}

.sidebar-logo {
    padding: 0 20px 24px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}

.sidebar-logo-img {
    height: 56px;
    width: 100%;
    max-width: 100%;
    object-fit: contain;
    object-position: left center;
    display: block;
    margin-bottom: 6px;
    background: transparent;
}

.sidebar-logo span {
    font-size: 11px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar nav a:hover,
.sidebar nav a.active {
    color: var(--text-primary);
    background: var(--accent-glow);
    border-right: 3px solid var(--accent);
}

.sidebar nav a.active {
    color: var(--accent);
}

.sidebar nav a svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.main {
    flex: 1;
    margin-left: 220px;
    padding: 32px;
}

.page-header {
    margin-bottom: 24px;
}

.page-header h2 {
    font-size: 24px;
    font-weight: 700;
}

.page-header p {
    color: var(--text-secondary);
    font-size: 14px;
    margin-top: 4px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

.card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
}

/* Stats */
.stats-row, .stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--accent);
}

.stat-card .stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 4px;
}

/* Forms */
.form-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    flex-wrap: wrap;
}

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

.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input, select {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    padding: 10px 14px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus {
    border-color: var(--accent);
}

input::placeholder {
    color: var(--text-secondary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
}

.btn-primary {
    background: linear-gradient(135deg, #FF7A0A, #FF5F00);
    color: #fff;
    box-shadow: 0 2px 12px rgba(255, 122, 10, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #FF8C1A, #FF6A00);
    box-shadow: 0 2px 18px rgba(255, 122, 10, 0.45);
}

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

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--accent);
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover {
    opacity: 0.85;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

/* Status */
.status-bar {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-top: 16px;
    display: none;
    align-items: center;
    gap: 12px;
}

.status-bar.active {
    display: flex;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

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

.status-count {
    margin-left: auto;
    font-weight: 700;
    color: var(--accent);
}

/* Table */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    background: var(--bg-input);
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

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

thead th.sorted-asc::after { content: " \u25B2"; font-size: 10px; }
thead th.sorted-desc::after { content: " \u25BC"; font-size: 10px; }

tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

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

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
}

.badge-zillow {
    background: rgba(0, 106, 255, 0.15);
    color: #4da3ff;
}

.badge-realtor {
    background: rgba(210, 55, 55, 0.15);
    color: #e87070;
}

.badge-running {
    background: rgba(255, 122, 10, 0.15);
    color: var(--accent);
}

.badge-completed {
    background: rgba(52, 199, 89, 0.15);
    color: var(--success);
}

.badge-failed {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.badge-pending {
    background: rgba(245, 166, 35, 0.15);
    color: var(--warning);
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.toolbar input {
    flex: 1;
    min-width: 200px;
}

/* Schedule cards */
.schedule-list {
    display: grid;
    gap: 12px;
}

.schedule-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.schedule-card .schedule-info { flex: 1; }
.schedule-card .schedule-info h4 { font-size: 14px; }
.schedule-card .schedule-info p { font-size: 12px; color: var(--text-secondary); }

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border-radius: 24px;
    cursor: pointer;
    transition: 0.3s;
    border: 1px solid var(--border);
}

.toggle-slider::before {
    content: "";
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: 0.3s;
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: #fff;
}

/* History table */
.history-table {
    margin-top: 24px;
}

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

.empty-state svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.3;
}

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

/* Settings form */
.settings-form {
    display: grid;
    gap: 16px;
    max-width: 400px;
}

.settings-form .form-group {
    gap: 8px;
}

.settings-form input {
    width: 100%;
}

/* Topbar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    margin-bottom: 16px;
}

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

/* Export badges */
.badge-exported {
    background: rgba(52, 199, 89, 0.15);
    color: var(--success);
}

.badge-not-exported {
    background: rgba(139, 143, 163, 0.15);
    color: var(--text-secondary);
}

tr.exported-row td {
    opacity: 0.5;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 420px;
}

.modal h3 {
    margin-bottom: 16px;
}

.modal .form-group {
    margin-bottom: 16px;
}

.modal select {
    width: 100%;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 20px;
    font-size: 13px;
    color: var(--text-primary);
    z-index: 2000;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    animation: slideUp 0.3s ease;
}

.toast.toast-success {
    border-color: var(--success);
}

.toast.toast-error {
    border-color: var(--danger);
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

/* Scrape-complete banner */
.scrape-banner {
    background: var(--bg-input);
    border: 1px solid var(--success);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-top: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}

.scrape-banner .banner-text {
    flex: 1;
    color: var(--text-primary);
}

/* ── Leads table: compact layout, no horizontal scroll ── */
.leads-table {
    font-size: 12px;
    table-layout: fixed;
    width: 100%;
}

/* Base cell — padding only, no overflow clip (handled per-column below) */
.leads-table thead th,
.leads-table tbody td {
    padding: 8px 6px;
    white-space: nowrap;
}

/* Text columns: truncate with ellipsis */
.leads-table td:nth-child(2),
.leads-table td:nth-child(3),
.leads-table td:nth-child(4),
.leads-table td:nth-child(5),
.leads-table td:nth-child(9) {
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Checkbox — 26px */
.leads-table th:nth-child(1),
.leads-table td:nth-child(1) { width: 26px; text-align: center; }

/* Name — 115px */
.leads-table th:nth-child(2),
.leads-table td:nth-child(2) { width: 115px; }

/* Phone — 108px */
.leads-table th:nth-child(3),
.leads-table td:nth-child(3) { width: 108px; }

/* Brokerage — 115px */
.leads-table th:nth-child(4),
.leads-table td:nth-child(4) { width: 115px; }

/* Location — 88px */
.leads-table th:nth-child(5),
.leads-table td:nth-child(5) { width: 88px; }

/* Rating — 48px */
.leads-table th:nth-child(6),
.leads-table td:nth-child(6) { width: 48px; text-align: center; }

/* Reviews — 54px */
.leads-table th:nth-child(7),
.leads-table td:nth-child(7) { width: 54px; text-align: center; }

/* Sales — 48px */
.leads-table th:nth-child(8),
.leads-table td:nth-child(8) { width: 48px; text-align: center; }

/* Avg Price — 76px */
.leads-table th:nth-child(9),
.leads-table td:nth-child(9) { width: 76px; }

/* Listings — 50px */
.leads-table th:nth-child(10),
.leads-table td:nth-child(10) { width: 50px; text-align: center; }

/* Experience — 38px */
.leads-table th:nth-child(11),
.leads-table td:nth-child(11) { width: 38px; text-align: center; }

/* Source — 70px */
.leads-table th:nth-child(12),
.leads-table td:nth-child(12) { width: 70px; }

/* Export Status — 135px, allow wrap for tag pills */
.leads-table th:nth-child(13),
.leads-table td:nth-child(13) {
    width: 135px;
    white-space: normal;
    overflow: visible;
    line-height: 1.6;
}

/* Profile link — 46px, never clip */
.leads-table th:nth-child(14),
.leads-table td:nth-child(14) { width: 46px; text-align: center; overflow: visible; }

/* Delete button — 43px, never clip */
.leads-table th:nth-child(15),
.leads-table td:nth-child(15) { width: 43px; text-align: center; overflow: visible; }

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
        overflow: hidden;
    }

    .sidebar-logo h1,
    .sidebar-logo span,
    .sidebar nav a span {
        display: none;
    }

    .sidebar nav a {
        justify-content: center;
        padding: 12px;
    }

    .main {
        margin-left: 60px;
        padding: 16px;
    }

    .form-row {
        flex-direction: column;
    }

    .form-group {
        width: 100%;
    }
}
