/* ============================================================
   PropIntel CRM — Main Stylesheet
   ============================================================ */

:root {
    --pi-blue:    #2563eb;
    --pi-blue-dk: #1d4ed8;
    --pi-amber:   #f59e0b;
    --pi-green:   #10b981;
    --pi-red:     #ef4444;
    --pi-gray:    #6b7280;
    --sidebar-w:  260px;
    --topbar-h:   64px;
    --bg-body:    #f3f4f6;
    --card-bg:    #ffffff;
    --text-main:  #111827;
    --text-muted: #6b7280;
    --border:     #e5e7eb;
}

/* ── Base ─────────────────────────────────────────────────── */
body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    background: var(--bg-body);
    color: var(--text-main);
    font-size: 0.9rem;
}

a { text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ───────────────────────────────────────────────── */
#wrapper {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
#sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: #0f1923;
    color: #e5e7eb;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 1000;
    transition: width 0.25s ease;
    overflow-x: hidden;
}

#sidebar .sidebar-brand {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

#sidebar .brand-text {
    font-size: 1.3rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: -.5px;
}

#sidebar .brand-text span { color: var(--pi-amber); }

#sidebar .nav-section-label {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: #6b7280;
    padding: .75rem 1.5rem .25rem;
}

#sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: .65rem;
    padding: .5rem 1.5rem;
    color: #9ca3af;
    border-left: 3px solid transparent;
    transition: all .15s;
    font-size: .875rem;
}

#sidebar .nav-link:hover,
#sidebar .nav-link.active {
    color: #fff;
    background: rgba(255,255,255,.06);
    border-left-color: var(--pi-blue);
    text-decoration: none;
}

#sidebar .nav-link .bi {
    font-size: 1rem;
    width: 20px;
}

#sidebar .sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,.08);
    font-size: .8rem;
    color: #6b7280;
}

/* ── Main content ─────────────────────────────────────────── */
#main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ── Topbar ───────────────────────────────────────────────── */
#topbar {
    height: var(--topbar-h);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 900;
}

#topbar .search-wrap {
    position: relative;
    flex: 1;
    max-width: 400px;
}

#topbar .search-wrap .bi {
    position: absolute;
    left: .75rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

#topbar .search-input {
    padding-left: 2.25rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-body);
    font-size: .875rem;
}

#topbar .search-input:focus {
    background: #fff;
    border-color: var(--pi-blue);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── Page content ─────────────────────────────────────────── */
.page-content {
    padding: 1.5rem;
    flex: 1;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.page-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-main);
}

/* ── Cards ────────────────────────────────────────────────── */
.card {
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* Stat cards */
.stat-card {
    border-radius: 12px;
    padding: 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-card .stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-card .stat-label {
    font-size: .78rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.1;
}

.stat-card .stat-sub {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: .15rem;
}

/* ── Badges ───────────────────────────────────────────────── */
.score-badge {
    font-size: .75rem;
    min-width: 2rem;
    text-align: center;
}

/* ── Lead table ───────────────────────────────────────────── */
.leads-table th {
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--text-muted);
    white-space: nowrap;
}

.leads-table td {
    vertical-align: middle;
    font-size: .875rem;
}

.leads-table tr:hover {
    background: #f9fafb;
}

.flag-icons .bi {
    font-size: .9rem;
}

/* ── Lead detail ──────────────────────────────────────────── */
.detail-section {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1.25rem;
}

.detail-section-header {
    padding: .875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: .9rem;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.detail-section-body {
    padding: 1.25rem;
}

.detail-label {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    margin-bottom: .25rem;
}

.detail-value {
    font-size: .9rem;
    font-weight: 500;
}

/* ── Notes Timeline ───────────────────────────────────────── */
.timeline {
    position: relative;
    padding-left: 1.5rem;
}

.timeline::before {
    content: '';
    position: absolute;
    left: .35rem;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border);
}

.timeline-item {
    position: relative;
    padding-bottom: 1.25rem;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -1.17rem;
    top: .35rem;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--pi-blue);
    border: 2px solid var(--card-bg);
}

.timeline-item.system::before { background: var(--text-muted); }
.timeline-item.email::before  { background: var(--pi-green); }
.timeline-item.sms::before    { background: var(--pi-amber); }
.timeline-item.call::before   { background: var(--pi-red); }

.timeline-meta {
    font-size: .75rem;
    color: var(--text-muted);
}

.timeline-body {
    background: var(--bg-body);
    border-radius: 8px;
    padding: .75rem 1rem;
    font-size: .875rem;
    white-space: pre-wrap;
}

/* ── Filters panel ────────────────────────────────────────── */
.filter-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
}

.filter-panel .form-label {
    font-size: .72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
    color: var(--text-muted);
    margin-bottom: .25rem;
}

/* ── Calculator ───────────────────────────────────────────── */
.calc-result-card {
    background: linear-gradient(135deg, #0f1923, #1a2d45);
    color: #e5e7eb;
    border-radius: 12px;
    padding: 1.5rem;
}

.calc-metric-label {
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #9ca3af;
}

.calc-metric-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: #fff;
}

.calc-metric-value.positive { color: #34d399; }
.calc-metric-value.negative { color: #f87171; }
.calc-metric-value.warning  { color: #fbbf24; }

/* ── HTMX loading indicator ───────────────────────────────── */
.htmx-indicator {
    display: none;
}
.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
    display: inline-block;
}

.htmx-request .hide-on-htmx {
    display: none !important;
}

/* Spinner */
.spin {
    animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Utilities ────────────────────────────────────────────── */
.text-green   { color: var(--pi-green) !important; }
.text-amber   { color: var(--pi-amber) !important; }
.text-purple  { color: #8b5cf6 !important; }
.bg-purple    { background-color: #8b5cf6 !important; }

.border-left-blue   { border-left: 4px solid var(--pi-blue) !important; }
.border-left-green  { border-left: 4px solid var(--pi-green) !important; }
.border-left-amber  { border-left: 4px solid var(--pi-amber) !important; }
.border-left-red    { border-left: 4px solid var(--pi-red) !important; }

/* Quick search dropdown */
#quick-search-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
    z-index: 9999;
    max-height: 320px;
    overflow-y: auto;
}

#quick-search-results .qs-item {
    padding: .6rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    font-size: .85rem;
}

#quick-search-results .qs-item:last-child { border-bottom: none; }
#quick-search-results .qs-item:hover { background: #f3f4f6; }

/* Print layout */
@media print {
    #sidebar, #topbar { display: none !important; }
    #main-content { margin-left: 0 !important; }
}

/* Mobile responsive */
@media (max-width: 992px) {
    #sidebar { width: 0; overflow: hidden; }
    #sidebar.show { width: var(--sidebar-w); }
    #main-content { margin-left: 0; }
}
