/* ==========================================================================
   CRM Styles
   ========================================================================== */

:root {
    --color-bg: #f8fafc;
    --color-card: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-text-light: #94a3b8;
    --color-primary: #7c3aed;
    --color-primary-hover: #6d28d9;
    --color-primary-soft: #ede9fe;
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
}

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

body {
    font-family: var(--font-family);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ==========================================================================
   Login Screen
   ========================================================================== */

.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-card {
    background: white;
    border-radius: var(--radius-xl);
    padding: 48px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
}

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

.login-icon {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
}

.login-header p {
    color: var(--color-text-muted);
}

.login-form input {
    width: 100%;
    padding: 14px 16px;
    font-size: 16px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    transition: border-color 0.2s;
}

.login-form input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.login-error {
    color: var(--color-danger);
    font-size: 14px;
    text-align: center;
    margin-top: 12px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

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

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

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

.btn-ghost {
    background: transparent;
    color: var(--color-text-muted);
}

.btn-ghost:hover {
    color: var(--color-text);
    background: var(--color-bg);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 13px;
}

.btn-icon {
    padding: 8px;
    border-radius: var(--radius-sm);
}

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

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

/* ==========================================================================
   Header
   ========================================================================== */

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

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

.logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--color-primary);
}

.header-nav {
    display: flex;
    gap: 8px;
}

.nav-link {
    padding: 8px 16px;
    color: var(--color-text-muted);
    text-decoration: none;
    font-weight: 500;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.nav-link:hover,
.nav-link.active {
    color: var(--color-primary);
    background: var(--color-primary-soft);
}

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

/* ==========================================================================
   Main Content
   ========================================================================== */

.main-content {
    padding: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

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

.page-title {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 4px;
}

.page-subtitle {
    color: var(--color-text-muted);
}

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}

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

.card-title {
    font-size: 16px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-count {
    background: var(--color-primary-soft);
    color: var(--color-primary);
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

/* ==========================================================================
   Action List (Dashboard)
   ========================================================================== */

.action-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.action-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--color-bg);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s;
}

.action-item:hover {
    background: var(--color-primary-soft);
}

.action-item-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.action-item-info {
    display: flex;
    flex-direction: column;
}

.action-item-name {
    font-weight: 600;
    font-size: 14px;
}

.action-item-meta {
    font-size: 13px;
    color: var(--color-text-muted);
}

.action-item-actions {
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.action-item:hover .action-item-actions {
    opacity: 1;
}

/* ==========================================================================
   Contacts Table
   ========================================================================== */

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

.contacts-table th,
.contacts-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.contacts-table th {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.contacts-table tr:hover {
    background: var(--color-bg);
    cursor: pointer;
}

.contact-name {
    font-weight: 600;
}

/* ==========================================================================
   Badges
   ========================================================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    font-size: 12px;
    font-weight: 500;
    border-radius: 999px;
}

.badge-new {
    background: #dbeafe;
    color: #1d4ed8;
}

.badge-active {
    background: #d1fae5;
    color: #047857;
}

.badge-won {
    background: #dcfce7;
    color: #15803d;
}

.badge-lost {
    background: #fee2e2;
    color: #b91c1c;
}

.badge-nurture {
    background: #fef3c7;
    color: #b45309;
}

.badge-notafit {
    background: #f1f5f9;
    color: #64748b;
}

.badge-spark {
    background: var(--color-primary-soft);
    color: var(--color-primary);
}

.badge-met {
    background: #e0e7ff;
    color: #4338ca;
}

.badge-clay {
    background: #fce7f3;
    color: #be185d;
}

/* ==========================================================================
   Modal
   ========================================================================== */

.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
}

.modal-content {
    position: relative;
    background: white;
    border-radius: var(--radius-xl);
    padding: 24px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.modal-header h2 {
    font-size: 20px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--color-text-muted);
    padding: 4px;
}

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

/* ==========================================================================
   Forms
   ========================================================================== */

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

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: var(--font-family);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-soft);
}

.form-group textarea {
    resize: vertical;
    min-height: 80px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--color-border);
}

.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    cursor: pointer;
}

.radio-label input {
    width: auto;
}

/* ==========================================================================
   Contact Detail
   ========================================================================== */

.contact-detail {
    max-width: 700px;
}

.contact-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 24px;
}

.contact-detail-name {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}

.contact-detail-title {
    color: var(--color-text-muted);
    font-size: 16px;
}

.contact-detail-meta {
    display: flex;
    gap: 16px;
    margin-top: 12px;
    font-size: 14px;
    color: var(--color-text-muted);
}

.contact-detail-meta a {
    color: var(--color-primary);
    text-decoration: none;
}

.contact-detail-meta a:hover {
    text-decoration: underline;
}

.contact-section {
    margin-bottom: 24px;
}

.contact-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.contact-problem {
    font-style: italic;
    color: var(--color-text-muted);
    padding: 16px;
    background: var(--color-bg);
    border-radius: var(--radius-md);
}

.contact-notes {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.note-entry {
    padding: 12px;
    background: var(--color-bg);
    border-radius: var(--radius-md);
    font-size: 14px;
}

.note-date {
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 4px;
}

/* ==========================================================================
   Filters
   ========================================================================== */

.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 20px;
}

.filter-select {
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: white;
}

.search-input {
    flex: 1;
    max-width: 300px;
    padding: 8px 12px;
    font-size: 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
}

/* ==========================================================================
   Empty State
   ========================================================================== */

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--color-text-muted);
}

.empty-state-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 8px;
}

/* ==========================================================================
   Loading
   ========================================================================== */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
    color: var(--color-text-muted);
}

.loading::after {
    content: '';
    width: 24px;
    height: 24px;
    border: 3px solid var(--color-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-left: 12px;
}

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

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 768px) {
    .header {
        flex-wrap: wrap;
        gap: 12px;
    }

    .header-nav {
        order: 3;
        width: 100%;
        justify-content: center;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .filters {
        flex-wrap: wrap;
    }

    .search-input {
        max-width: 100%;
    }
}

/* ==========================================================================
   Dashboard Stats
   ========================================================================== */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

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

.stat-card {
    background: white;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: 20px;
    text-align: center;
}

.stat-number {
    font-size: 32px;
    font-weight: 700;
    color: var(--color-primary);
    line-height: 1;
    margin-bottom: 4px;
}

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

.stat-outcome {
    background: var(--color-bg);
    padding: 6px 12px;
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--color-text-muted);
}

.stat-outcome strong {
    color: var(--color-text);
}

/* ==========================================================================
   Activity Log
   ========================================================================== */

.activity-log-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--color-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
}

.activity-log-presets {
    display: flex;
    gap: 6px;
}

.activity-preset-btn {
    padding: 6px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    background: var(--color-bg);
    color: var(--color-text-muted);
    font-size: 13px;
    font-family: var(--font-family);
    cursor: pointer;
    transition: all 0.15s ease;
}

.activity-preset-btn:hover {
    border-color: var(--color-primary);
    color: var(--color-primary);
}

.activity-preset-btn.active {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: #fff;
}

.activity-log-custom {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

.activity-log-custom input[type="date"] {
    padding: 6px 10px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-size: 13px;
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg);
}

.activity-log-date-group {
    margin-bottom: 4px;
}

.activity-log-date-header {
    padding: 10px 16px;
    background: var(--color-bg);
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 1;
}

.activity-log-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.1s ease;
}

.activity-log-item:hover {
    background: #fafbfc;
}

.activity-log-item:last-child {
    border-bottom: none;
}

.activity-log-icon {
    font-size: 18px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
    padding-top: 2px;
}

.activity-log-content {
    flex: 1;
    min-width: 0;
}

.activity-log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.activity-log-type {
    font-weight: 600;
    font-size: 14px;
    color: var(--color-text);
}

.activity-log-time {
    font-size: 12px;
    color: var(--color-text-light);
    flex-shrink: 0;
}

.activity-log-contact {
    font-size: 13px;
    color: var(--color-primary);
    text-decoration: none;
    display: block;
    margin-bottom: 2px;
}

.activity-log-contact:hover {
    text-decoration: underline;
}

.activity-log-notes {
    font-size: 13px;
    color: var(--color-text-muted);
    margin-top: 4px;
    line-height: 1.4;
}

@media (max-width: 640px) {
    .activity-log-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .activity-log-custom {
        margin-left: 0;
    }

    .activity-log-presets {
        flex-wrap: wrap;
    }
}

/* ==========================================================================
   Quill Editor Overrides
   ========================================================================== */

.ql-container.ql-snow {
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    font-family: var(--font-family);
    font-size: 15px;
    line-height: 1.8;
    min-height: 400px;
}

.ql-toolbar.ql-snow {
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    background: var(--color-bg);
    font-family: var(--font-family);
}

.ql-editor {
    min-height: 380px;
}

.ql-editor img {
    width: 100%;
    max-width: 100%;
    border-radius: 8px;
    margin: 16px 0;
}

/* Blog Preview */
#blogPreviewContent img {
    width: 100%;
    max-width: 100%;
    border-radius: 8px;
    margin: 16px 0;
}

#blogPreviewContent h1,
#blogPreviewContent h2,
#blogPreviewContent h3 {
    margin: 24px 0 12px;
}

#blogPreviewContent p {
    margin-bottom: 16px;
}