/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #1a5276;
    --primary-light: #2980b9;
    --accent: #27ae60;
    --danger: #e74c3c;
    --warning: #f39c12;
    --bg: #f5f7fa;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-muted: #7f8c8d;
    --border: #e1e8ed;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding-bottom: 80px;
}

/* === Layout === */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

/* === Navigation (Bottom) === */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    z-index: 1000;
    padding: 0.25rem 0;
    padding-bottom: env(safe-area-inset-bottom);
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.5rem;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 0.7rem;
    transition: color 0.2s;
}

.nav-item.active { color: var(--primary); }
.nav-item:hover { color: var(--primary-light); }
.nav-icon { font-size: 1.4rem; line-height: 1; }

/* === Typography === */
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }
.text-muted { color: var(--text-muted); }
.back-link { color: var(--primary); text-decoration: none; font-size: 0.9rem; }

/* === Page Header === */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* === Buttons === */
.btn {
    display: inline-block;
    padding: 0.6rem 1.2rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: opacity 0.2s;
    min-height: 44px;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-full { display: block; width: 100%; }

/* === Cards === */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.lead-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

/* === Lead Header === */
.lead-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
    gap: 1rem;
}

.lead-company { font-size: 1.1rem; color: var(--text-muted); }

/* === Status Badges === */
.status-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.status-new { background: #e8f8f5; color: #1abc9c; }
.status-contacted { background: #ebf5fb; color: #3498db; }
.status-meeting_scheduled { background: #fef9e7; color: #f39c12; }
.status-follow_up { background: #fdf2e9; color: #e67e22; }
.status-converted { background: #eafaf1; color: #27ae60; }
.status-inactive { background: #f2f3f4; color: #95a5a6; }

/* === Info List === */
.info-list { display: flex; flex-direction: column; gap: 0.5rem; }
.info-item { display: flex; justify-content: space-between; align-items: center; }
.info-label { font-size: 0.85rem; color: var(--text-muted); }
.info-item a { color: var(--primary); text-decoration: none; }

/* === Tables === */
.table-wrapper { overflow-x: auto; }

.leads-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.leads-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    background: var(--bg);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.leads-table td {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
}

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #f8f9fa; }

/* === Filters === */
.filter-form {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.search-input, .status-select {
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    min-height: 44px;
}

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

/* === Forms === */
.lead-form { max-width: 700px; }

.form-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.form-group { margin-bottom: 0.75rem; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    min-height: 44px;
}

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

.form-row { display: grid; gap: 0.75rem; grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: 2fr 1fr 1fr; }

.form-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 1rem;
}

/* === Upload === */
.upload-drop {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.2s;
    position: relative;
}

.upload-drop:hover { border-color: var(--primary-light); }
.upload-icon { font-size: 3rem; margin-bottom: 0.5rem; }
.upload-drop input[type="file"] {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

#preview-container { margin-top: 1rem; }

/* === Batch Review === */
.batch-card { transition: opacity 0.2s; }
.batch-card-header {
    display: flex;
    align-items: center;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}
.batch-check { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.batch-check input { width: 18px; height: 18px; cursor: pointer; }
.batch-card-image { max-width: 300px; margin-bottom: 0.75rem; }

/* === Card Image === */
.card-image {
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* === Email Result === */
.email-result { background: #f0f7ff; }
.research-section {
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.research-section h3 { font-size: 0.9rem; margin-bottom: 0.5rem; color: var(--text-muted); }
.research-body {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-muted);
    padding: 0.75rem;
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.research-body h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text);
    margin: 0.75rem 0 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.research-body h4:first-child { margin-top: 0; }
.research-body p { margin: 0.35rem 0; }
.research-body ul {
    margin: 0.25rem 0;
    padding-left: 1.2rem;
    list-style-type: disc;
}
.research-body li {
    margin-bottom: 0.3rem;
}
.research-body li:last-child { margin-bottom: 0; }
.email-actions {
    display: flex;
    gap: 0.5rem;
}
.email-subject { margin-bottom: 0.75rem; }
.email-body {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    padding: 1rem;
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* === Timeline === */
.timeline { display: flex; flex-direction: column; gap: 1rem; }
.timeline-item {
    padding: 0.75rem;
    border-left: 3px solid var(--primary-light);
    background: var(--bg);
    border-radius: 0 var(--radius) var(--radius) 0;
}
.timeline-header {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
}
.timeline-type { font-weight: 600; color: var(--primary); }
.timeline-date { color: var(--text-muted); }
.timeline-subject { font-weight: 500; margin-bottom: 0.25rem; }
.timeline-body {
    white-space: pre-wrap;
    font-family: inherit;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.timeline-research {
    margin-top: 0.5rem;
    font-size: 0.8rem;
}
.timeline-research summary {
    cursor: pointer;
    color: var(--primary);
    font-weight: 500;
}
.timeline-research .research-body {
    margin-top: 0.25rem;
    font-size: 0.8rem;
}

/* === Map === */
.map-container { height: 60vh; border-radius: var(--radius); overflow: hidden; }

/* === Alerts === */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error { background: #fdeaea; color: var(--danger); }
.alert-warning { background: #fff8e1; color: #8d6e00; }
.alert-warning a { color: #6d5500; font-weight: 600; }
.dupe-badge {
    font-size: 0.75rem;
    background: #fff3cd;
    color: #856404;
    padding: 0.15rem 0.5rem;
    border-radius: 1rem;
}

/* === Login === */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

.login-card {
    background: var(--card-bg);
    padding: 2rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 380px;
    text-align: center;
}

.login-card h1 { margin-bottom: 0.25rem; color: var(--primary); }
.login-subtitle { color: var(--text-muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.login-card .form-group { text-align: left; }

/* === Empty State === */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-state p { margin-bottom: 1rem; }

/* === Action Buttons === */
.action-buttons { display: flex; flex-direction: column; gap: 0.5rem; }
.action-buttons select {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    min-height: 44px;
}

/* === Notes === */
.notes-textarea {
    width: 100%;
    min-height: 80px;
    padding: 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.5;
    resize: vertical;
}

/* === Contacts === */
.contact-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}
.contact-item:last-of-type { border-bottom: none; }
.contact-info { flex: 1; min-width: 0; }
.contact-actions {
    display: flex;
    gap: 0.75rem;
    margin-left: 0.5rem;
    flex-shrink: 0;
}
.contact-edit-form {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.contact-edit-form .form-group { margin-bottom: 0.5rem; }
.contact-edit-form input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
}

/* === Status Form === */
.status-form { width: 100%; }

/* === Toast === */
.toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: white;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    z-index: 2000;
    animation: fadeInUp 0.3s, fadeOut 0.3s 2.2s;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
@keyframes fadeOut {
    to { opacity: 0; }
}

/* === Loading Spinner === */
.loading { opacity: 0.6; pointer-events: none; }
.spinner::after {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid white;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 0.5rem;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* === Mobile Helpers === */
.hide-mobile { display: table-cell; }
.mobile-only { display: none; }

/* === Responsive === */
@media (max-width: 768px) {
    .hide-mobile { display: none; }
    .mobile-only { display: block; font-size: 0.85rem; }
    .form-row { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr; }
    h1 { font-size: 1.3rem; }
}

@media (min-width: 768px) {
    .lead-grid { grid-template-columns: 1fr 1fr; }
    .map-container { height: 75vh; }
}

@media (min-width: 1024px) {
    .map-container { height: 80vh; }
}
