/* CSS Custom Properties - Status Colors */
:root {
    --color-new: #3b82f6;
    --color-contacted: #8b5cf6;
    --color-meeting: #ec4899;
    --color-proposal: #f59e0b;
    --color-won: #10b981;
    --color-lost: #6b7280;
    --color-rejected: #dc2626;
    --color-bg: #ffffff;
    --color-bg-alt: #f9fafb;
    --color-border: #e5e7eb;
    --color-text: #111827;
    --color-text-secondary: #6b7280;
    --color-primary: #3b82f6;
    --color-danger: #ef4444;
}

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

/* System Font Stack */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg-alt);
}

/* Header - Sticky */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--color-bg);
    border-bottom: 2px solid var(--color-border);
    padding: 1rem 2rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}

/* Stats Bar */
.stats {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.stat-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.375rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: white;
}

.stat-badge.total {
    background: var(--color-text);
}

.stat-badge.new {
    background: var(--color-new);
}

.stat-badge.contacted {
    background: var(--color-contacted);
}

.stat-badge.meeting {
    background: var(--color-meeting);
}

.stat-badge.proposal {
    background: var(--color-proposal);
}

.stat-badge.won {
    background: var(--color-won);
}

.stat-badge.lost {
    background: var(--color-lost);
}

.stat-badge.rejected {
    background: var(--color-rejected);
}

/* Main Content */
.main {
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem;
}

/* Controls */
.controls {
    display: flex;
    gap: 2rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-group label {
    font-weight: 500;
    color: var(--color-text-secondary);
}

.range-inputs {
    display: flex;
    gap: 0.5rem;
}

select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 0.875rem;
    cursor: pointer;
    transition: border-color 0.2s;
}

select:hover {
    border-color: var(--color-primary);
}

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

/* Table Container */
.table-container {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    overflow-x: auto;
}

/* Leads Table */
.leads-table {
    width: 100%;
    border-collapse: collapse;
}

.leads-table thead {
    position: sticky;
    top: 0;
    background: var(--color-bg-alt);
    z-index: 10;
}

.leads-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    border-bottom: 2px solid var(--color-border);
    white-space: nowrap;
}

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

.leads-table tbody tr:nth-child(even) {
    background: var(--color-bg-alt);
}

.leads-table tbody tr:hover {
    background: #f3f4f6;
}

.leads-table td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

/* Table Cell Styles */
.leads-table td.company {
    font-weight: 500;
}

.leads-table td.phone {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    min-width: 150px;
}

.leads-table td.website {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.leads-table td.website a {
    color: var(--color-primary);
    text-decoration: none;
}

.leads-table td.website a:hover {
    text-decoration: underline;
}

.leads-table td.updated {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    white-space: nowrap;
}

/* Contact Email Column - wider input for better usability */
.leads-table td:has(.editable-input[data-field="contact_email"]) {
    min-width: 200px;
}

/* Inline Editable Fields */
.editable-input {
    width: 100%;
    padding: 0.375rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    background: transparent;
    font-size: 0.875rem;
    transition: all 0.2s;
}

.editable-input:hover {
    background: white;
    border-color: var(--color-border);
}

.editable-input:focus {
    outline: none;
    background: white;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.status-select {
    padding: 0.375rem 0.5rem;
    border: 1px solid transparent;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.status-select:hover {
    border-color: var(--color-border);
}

.status-select:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.status-select.new {
    color: var(--color-new);
}

.status-select.contacted {
    color: var(--color-contacted);
}

.status-select.meeting {
    color: var(--color-meeting);
}

.status-select.proposal {
    color: var(--color-proposal);
}

.status-select.won {
    color: var(--color-won);
}

.status-select.lost {
    color: var(--color-lost);
}

.status-select.rejected {
    color: var(--color-rejected);
}

/* Notes Cell */
.notes-cell {
    max-width: 300px;
}

.notes-preview {
    color: var(--color-text-secondary);
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notes-empty {
    color: var(--color-text-secondary);
    font-style: italic;
}

.edit-notes-btn {
    margin-top: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    cursor: pointer;
    transition: background 0.2s;
}

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

/* Action Buttons */
.btn-delete {
    padding: 0.375rem 0.75rem;
    background: var(--color-danger);
    color: white;
    border: none;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: background 0.2s;
}

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
}

.modal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    max-width: 1200px;
    margin: 2rem auto;
    background: var(--color-bg);
    border-radius: 0.5rem;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    max-height: calc(100vh - 4rem);
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.5rem;
    border-bottom: 1px solid var(--color-border);
}

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: 0;
    width: 2rem;
    height: 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.25rem;
    transition: background 0.2s;
}

.modal-close:hover {
    background: var(--color-bg-alt);
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    min-height: 0;
}

.modal-panes {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: 600px;
}

.modal-pane {
    display: flex;
    flex-direction: column;
}

.modal-pane h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.notes-textarea {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875rem;
    resize: none;
}

.notes-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

#notes-preview {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    overflow-y: auto;
    background: var(--color-bg-alt);
}

/* Markdown Rendered Content */
#notes-preview h1,
#notes-preview h2,
#notes-preview h3,
#notes-preview h4,
#notes-preview h5,
#notes-preview h6 {
    margin-top: 1rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

#notes-preview h1 {
    font-size: 1.5rem;
}

#notes-preview h2 {
    font-size: 1.25rem;
}

#notes-preview h3 {
    font-size: 1.125rem;
}

#notes-preview p {
    margin-bottom: 0.75rem;
}

#notes-preview ul,
#notes-preview ol {
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
}

#notes-preview li {
    margin-bottom: 0.25rem;
}

#notes-preview code {
    padding: 0.125rem 0.25rem;
    background: #f3f4f6;
    border-radius: 0.25rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875em;
}

#notes-preview pre {
    margin-bottom: 0.75rem;
    padding: 0.75rem;
    background: #f3f4f6;
    border-radius: 0.375rem;
    overflow-x: auto;
}

#notes-preview pre code {
    padding: 0;
    background: none;
}

#notes-preview a {
    color: var(--color-primary);
    text-decoration: none;
}

#notes-preview a:hover {
    text-decoration: underline;
}

#notes-preview blockquote {
    margin-bottom: 0.75rem;
    padding-left: 1rem;
    border-left: 3px solid var(--color-border);
    color: var(--color-text-secondary);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1.5rem;
    border-top: 1px solid var(--color-border);
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

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

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

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

.btn-secondary:hover {
    background: #f3f4f6;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: var(--color-text);
    color: white;
    border-radius: 0.375rem;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    z-index: 2000;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

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

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

/* Header Navigation */
.header-nav {
    margin-top: 0.5rem;
}

.nav-link {
    color: var(--color-primary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.2s;
}

.nav-link:hover {
    color: #2563eb;
    text-decoration: underline;
}

/* Scraper Page */
.scraper-container {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.scraper-section {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0.5rem;
    padding: 1.5rem;
}

.scraper-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.scraper-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.scraper-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--color-text-secondary);
}

.status-indicator.status-running {
    background: var(--color-won);
    animation: pulse 2s infinite;
}

.status-indicator.status-idle {
    background: var(--color-text-secondary);
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.scraper-controls {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.scraper-result {
    display: none;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    background: var(--color-bg-alt);
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
}

.scraper-logs h3 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--color-text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.log-output {
    padding: 1rem;
    background: #1f2937;
    color: #f9fafb;
    border-radius: 0.375rem;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.75rem;
    line-height: 1.5;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 400px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Enrichment Badges */
.enrichment-badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 0.25rem;
    text-transform: uppercase;
}

.enrichment-pending {
    background: #fef3c7;
    color: #92400e;
}

.enrichment-enriched {
    background: #d1fae5;
    color: #065f46;
}

.enrichment-failed {
    background: #fee2e2;
    color: #991b1b;
}

.enrichment-skipped {
    background: #e5e7eb;
    color: #374151;
}

.enrichment-cell {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.view-enrichment-btn {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background: var(--color-primary);
    color: white;
    border: none;
    border-radius: 0.25rem;
    cursor: pointer;
}

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

/* Enrichment Modal */
.modal-large {
    max-width: 800px;
}

.enrichment-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--color-bg-alt);
    border-radius: 0.5rem;
}

.enrichment-section h4 {
    margin-bottom: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text);
}

.enrichment-section p {
    margin-bottom: 0.5rem;
}

.enrichment-section ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.enrichment-section li {
    margin-bottom: 0.25rem;
}

.enrichment-section summary {
    cursor: pointer;
}

.enrichment-json {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: #111827;
    color: #f9fafb;
    border-radius: 0.375rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.8125rem;
    line-height: 1.4;
}

/* Checkbox Cell */
.checkbox-cell {
    text-align: center;
}

.bool-toggle {
    width: 1rem;
    height: 1rem;
    cursor: pointer;
    accent-color: var(--color-primary);
}

/* Column Picker */
.col-picker-wrapper {
    position: relative;
}

.col-picker-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    z-index: 50;
    min-width: 180px;
    padding: 0.375rem 0;
}

.col-picker-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--color-text);
    white-space: nowrap;
}

.col-picker-item:hover {
    background: var(--color-bg-alt);
}

.col-picker-item input[type="checkbox"] {
    cursor: pointer;
}
