/* ==========================================================================
   Real Estate CRM — design tokens + Bootstrap 5.3 overrides
   Palette: Ink (sidebar), Stone (workspace), Teal (primary), Brass (hot / highlight)
   ========================================================================== */
:root {
  --crm-ink: #16212C;
  --crm-ink-2: #1F2D3B;
  --crm-ink-3: #2A3B4D;
  --crm-stone: #F2F3EF;
  --crm-paper: #FFFFFF;
  --crm-line: #E2E5DE;
  --crm-text: #1B2631;
  --crm-muted: #6A7684;
  --crm-teal: #0E6E6B;
  --crm-teal-dark: #0A5553;
  --crm-teal-soft: #E3F1F0;
  --crm-brass: #B7863A;
  --crm-brass-soft: #F7EEDC;
  --crm-danger: #B42318;
  --crm-sidebar-w: 248px;

  --bs-body-font-family: 'Plus Jakarta Sans', 'Hind Siliguri', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bs-body-font-size: .875rem;
  --bs-body-color: var(--crm-text);
  --bs-body-bg: var(--crm-stone);
  --bs-border-color: var(--crm-line);
  --bs-primary: #0E6E6B;
  --bs-primary-rgb: 14, 110, 107;
  --bs-link-color: #0E6E6B;
  --bs-link-color-rgb: 14, 110, 107;
  --bs-link-hover-color: #0A5553;
  --bs-border-radius: .5rem;
  --bs-border-radius-lg: .75rem;
}

body { background: var(--crm-stone); letter-spacing: -.003em; }
h1,h2,h3,h4,h5,h6 { font-weight: 650; letter-spacing: -.015em; }
.text-muted, .text-secondary { color: var(--crm-muted) !important; }
a { text-decoration: none; }
.tabular { font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
.btn-primary {
  --bs-btn-bg: var(--crm-teal); --bs-btn-border-color: var(--crm-teal);
  --bs-btn-hover-bg: var(--crm-teal-dark); --bs-btn-hover-border-color: var(--crm-teal-dark);
  --bs-btn-active-bg: var(--crm-teal-dark); --bs-btn-active-border-color: var(--crm-teal-dark);
  --bs-btn-disabled-bg: var(--crm-teal); --bs-btn-disabled-border-color: var(--crm-teal);
  --bs-btn-focus-shadow-rgb: 14,110,107;
}
.btn-outline-primary {
  --bs-btn-color: var(--crm-teal); --bs-btn-border-color: var(--crm-teal);
  --bs-btn-hover-bg: var(--crm-teal); --bs-btn-hover-border-color: var(--crm-teal);
  --bs-btn-active-bg: var(--crm-teal); --bs-btn-active-border-color: var(--crm-teal);
}
.btn { font-weight: 550; }
.btn-light { --bs-btn-bg: var(--crm-paper); --bs-btn-border-color: var(--crm-line); --bs-btn-hover-bg: #F6F7F4; --bs-btn-hover-border-color: #D2D6CD; }
.btn-icon { width: 2rem; height: 2rem; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.form-control, .form-select { border-color: #D5D9D1; background-color: #fff; }
.form-control:focus, .form-select:focus { border-color: var(--crm-teal); box-shadow: 0 0 0 .2rem rgba(14,110,107,.15); }
.form-label { font-weight: 600; font-size: .8125rem; margin-bottom: .3rem; color: #34414E; }
.form-check-input:checked { background-color: var(--crm-teal); border-color: var(--crm-teal); }
.form-text { color: var(--crm-muted); }
:focus-visible { outline: 2px solid var(--crm-teal); outline-offset: 2px; }

/* ---------- Shell ---------- */
.crm-sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--crm-sidebar-w); background: var(--crm-ink);
  color: #B9C4CF; display: flex; flex-direction: column; z-index: 1040; transition: transform .2s ease;
}
.crm-brand { display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1.25rem; color: #fff; font-weight: 700; font-size: 1rem; }
.crm-brand .mark { width: 32px; height: 32px; border-radius: 8px; background: var(--crm-brass); color: var(--crm-ink); display: grid; place-items: center; font-size: 1.05rem; }
.crm-nav { flex: 1; overflow-y: auto; padding: .25rem .75rem 1rem; scrollbar-width: thin; scrollbar-color: #33475B transparent; }
.crm-nav .group { margin: 1.1rem .5rem .35rem; font-size: .72rem; color: #7F8FA0; font-weight: 600; letter-spacing: .02em; }
.crm-nav a {
  display: flex; align-items: center; gap: .7rem; padding: .5rem .75rem; border-radius: 8px; color: #B9C4CF; font-weight: 500; position: relative; margin-bottom: 2px;
}
.crm-nav a i { font-size: 1.05rem; width: 1.2rem; text-align: center; opacity: .9; }
.crm-nav a:hover { background: var(--crm-ink-2); color: #fff; }
.crm-nav a.active { background: var(--crm-ink-3); color: #fff; }
.crm-nav a.active::before { content: ''; position: absolute; left: -.75rem; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--crm-brass); }
.crm-nav .badge-count { margin-left: auto; font-size: .7rem; background: var(--crm-brass); color: var(--crm-ink); font-weight: 700; }
.crm-sidebar-foot { padding: .9rem 1.1rem; border-top: 1px solid #263646; font-size: .8rem; display: flex; align-items: center; gap: .65rem; }

.crm-main { margin-left: var(--crm-sidebar-w); min-height: 100vh; }
.crm-topbar {
  position: sticky; top: 0; z-index: 1020; background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--crm-line); padding: .6rem 1.5rem; display: flex; align-items: center; gap: 1rem;
}
.crm-search { position: relative; flex: 1; max-width: 480px; }
.crm-search i { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--crm-muted); }
.crm-search input { padding-left: 2.3rem; background: var(--crm-stone); border-color: transparent; }
.crm-search input:focus { background: #fff; }
.crm-content { padding: 1.5rem; max-width: 1680px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head h1 { font-size: 1.4rem; margin: 0; }
.page-head .sub { color: var(--crm-muted); margin-top: .15rem; }

.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--crm-teal-soft); color: var(--crm-teal-dark); display: inline-grid; place-items: center; font-weight: 700; font-size: .75rem; flex: none; }
.avatar-sm { width: 24px; height: 24px; font-size: .62rem; }
.avatar-lg { width: 56px; height: 56px; font-size: 1.1rem; }
.crm-sidebar .avatar { background: var(--crm-ink-3); color: #fff; }

/* ---------- Panels (cards) ---------- */
.panel { background: var(--crm-paper); border: 1px solid var(--crm-line); border-radius: 10px; }
.panel-head { padding: .85rem 1.1rem; border-bottom: 1px solid var(--crm-line); display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.panel-head h2, .panel-head h3 { font-size: .95rem; margin: 0; }
.panel-body { padding: 1.1rem; }
.panel-flush { padding: 0; }

/* KPI strip: one continuous band instead of identical cards */
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); background: var(--crm-paper); border: 1px solid var(--crm-line); border-radius: 10px; overflow: hidden; }
.kpi { padding: 1rem 1.15rem; border-right: 1px solid var(--crm-line); position: relative; display: block; color: inherit; }
.kpi:last-child { border-right: 0; }
.kpi:hover { background: #FAFBF9; color: inherit; }
.kpi .label { color: var(--crm-muted); font-size: .78rem; font-weight: 600; display: flex; align-items: center; gap: .4rem; }
.kpi .value { font-size: 1.75rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.25; font-variant-numeric: tabular-nums; }
.kpi .hint { font-size: .75rem; color: var(--crm-muted); }
.kpi.alert-kpi .value { color: var(--crm-danger); }

/* ---------- Tables ---------- */
.table { --bs-table-bg: transparent; margin: 0; }
.table > :not(caption) > * > * { padding: .7rem 1rem; border-bottom-color: var(--crm-line); vertical-align: middle; }
.table thead th { font-size: .75rem; font-weight: 650; color: var(--crm-muted); background: #F8F9F6; white-space: nowrap; border-bottom: 1px solid var(--crm-line); }
.table-hover > tbody > tr:hover > * { --bs-table-bg-state: #F8FAF8; }
.table a.row-link { color: var(--crm-text); font-weight: 600; }
.table a.row-link:hover { color: var(--crm-teal); }
.table-responsive { border-radius: 0 0 10px 10px; }

/* ---------- Chips / badges ---------- */
.chip { display: inline-flex; align-items: center; gap: .35rem; padding: .18rem .6rem; border-radius: 999px; font-size: .74rem; font-weight: 600; background: #EEF0EB; color: #3D4A57; white-space: nowrap; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-hot { background: var(--crm-brass-soft); color: #8A5F14; }
.chip-warm { background: #FDF1E3; color: #A35A12; }
.chip-cold { background: #E7F0F8; color: #25577F; }
.chip-open { background: var(--crm-teal-soft); color: var(--crm-teal-dark); }
.chip-won { background: #DDF3E4; color: #176B36; }
.chip-lost, .chip-dead { background: #FBE6E4; color: #9B2318; }
.score { display: inline-flex; align-items: center; gap: .35rem; font-weight: 650; font-variant-numeric: tabular-nums; font-size: .78rem; }
.score .bar { width: 38px; height: 5px; border-radius: 3px; background: #E8EAE4; overflow: hidden; }
.score .bar > i { display: block; height: 100%; background: var(--crm-teal); }
.aging-ok { color: var(--crm-muted); }
.aging-warn { color: #B56A00; font-weight: 600; }
.aging-bad { color: var(--crm-danger); font-weight: 650; }

/* ---------- Lead view tabs ---------- */
.lead-views { display: flex; gap: .25rem; flex-wrap: wrap; }
.lead-views a { padding: .4rem .8rem; border-radius: 8px; color: var(--crm-muted); font-weight: 600; font-size: .82rem; display: inline-flex; gap: .4rem; align-items: center; }
.lead-views a:hover { background: #E8EAE4; color: var(--crm-text); }
.lead-views a.active { background: var(--crm-ink); color: #fff; }
.lead-views .n { font-size: .7rem; opacity: .75; font-variant-numeric: tabular-nums; }
.bulk-bar { display: none; align-items: center; gap: .75rem; padding: .6rem 1rem; background: var(--crm-ink); color: #fff; border-radius: 10px; margin-bottom: .75rem; }
.bulk-bar.show { display: flex; }

/* ---------- Kanban ---------- */
.kanban { display: flex; gap: .85rem; overflow-x: auto; padding-bottom: 1rem; align-items: flex-start; min-height: 60vh; }
.kanban-col { flex: 0 0 292px; background: #E9EBE5; border-radius: 10px; display: flex; flex-direction: column; max-height: calc(100vh - 230px); }
.kanban-col-head { padding: .75rem .9rem .6rem; border-top: 4px solid var(--stage, #64748B); border-radius: 10px 10px 0 0; display: flex; justify-content: space-between; align-items: center; }
.kanban-col-head .name { font-weight: 700; font-size: .85rem; }
.kanban-col-head .count { font-size: .75rem; color: var(--crm-muted); font-variant-numeric: tabular-nums; }
.kanban-col-body { padding: .25rem .6rem .6rem; overflow-y: auto; flex: 1; min-height: 80px; }
.kcard { background: #fff; border: 1px solid var(--crm-line); border-radius: 8px; padding: .7rem .8rem; margin-bottom: .55rem; cursor: grab; position: relative; }
.kcard:hover { border-color: #C8CEC2; }
.kcard.priority-hot { border-left: 3px solid var(--crm-brass); }
.kcard .nm { font-weight: 650; color: var(--crm-text); display: block; margin-bottom: .1rem; }
.kcard .meta { font-size: .76rem; color: var(--crm-muted); display: flex; flex-wrap: wrap; gap: .25rem .7rem; }
.kcard .foot { display: flex; align-items: center; justify-content: space-between; margin-top: .55rem; font-size: .74rem; }
.sortable-ghost { opacity: .35; }
.sortable-chosen { cursor: grabbing; box-shadow: 0 8px 22px rgba(22,33,44,.18); }

/* ---------- Timeline ---------- */
.timeline { position: relative; padding-left: 2.3rem; }
.timeline::before { content: ''; position: absolute; left: 13px; top: 6px; bottom: 6px; width: 2px; background: var(--crm-line); }
.t-item { position: relative; padding-bottom: 1.05rem; }
.t-item .ico { position: absolute; left: -2.3rem; top: 0; width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; background: #fff; border: 2px solid var(--crm-line); color: var(--crm-muted); }
.t-item .ico.c-success { color: #176B36; border-color: #BFE5CC; }
.t-item .ico.c-primary { color: var(--crm-teal); border-color: #B5DAD8; }
.t-item .ico.c-warning { color: #A35A12; border-color: #F2D9B0; }
.t-item .ico.c-info { color: #25577F; border-color: #BCD6EA; }
.t-item .ico.c-danger { color: var(--crm-danger); border-color: #F1C2BD; }
.t-item .when { color: var(--crm-muted); font-size: .76rem; }

/* ---------- Detail lists ---------- */
.dl { display: grid; grid-template-columns: 128px 1fr; gap: .45rem .75rem; margin: 0; }
.dl dt { color: var(--crm-muted); font-weight: 500; }
.dl dd { margin: 0; font-weight: 550; word-break: break-word; }
.form-section { padding-bottom: 1.25rem; margin-bottom: 1.25rem; border-bottom: 1px dashed var(--crm-line); }
.form-section:last-child { border-bottom: 0; margin-bottom: 0; padding-bottom: 0; }
.form-section h3 { font-size: .95rem; margin-bottom: .15rem; }
.form-section .desc { color: var(--crm-muted); margin-bottom: 1rem; font-size: .8rem; }
.req::after { content: ' *'; color: var(--crm-danger); }
.dup-box { border: 1px solid #F0D49B; background: #FFF8E8; border-radius: 10px; padding: .75rem 1rem; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-aside { background: var(--crm-ink); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
  background-image: linear-gradient(0deg, rgba(22,33,44,.55), rgba(22,33,44,.55)), repeating-linear-gradient(90deg, transparent 0 79px, rgba(255,255,255,.035) 79px 80px), repeating-linear-gradient(0deg, transparent 0 79px, rgba(255,255,255,.035) 79px 80px); }
.auth-aside h2 { font-size: 2rem; line-height: 1.2; max-width: 22ch; }
.auth-form { display: grid; place-items: center; padding: 2rem; background: #fff; }
@media (max-width: 900px) { .auth-wrap { grid-template-columns: 1fr; } .auth-aside { display: none; } }

/* ---------- Misc ---------- */
.empty { text-align: center; padding: 3rem 1rem; color: var(--crm-muted); }
.empty i { font-size: 2.2rem; display: block; margin-bottom: .5rem; opacity: .55; }
.matrix th, .matrix td { text-align: center; }
.matrix th:first-child, .matrix td:first-child { text-align: left; }
.notif-item { padding: .65rem 1rem; display: flex; gap: .7rem; border-bottom: 1px solid var(--crm-line); color: inherit; }
.notif-item.unread { background: #F5FAF9; }
.notif-item:hover { background: #F0F5F4; color: inherit; }
.toast-container { z-index: 2000; }
.sidebar-toggle { display: none; }
@media (max-width: 991.98px) {
  .crm-sidebar { transform: translateX(-100%); }
  .crm-sidebar.open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(10,15,20,.45); }
  .crm-main { margin-left: 0; }
  .sidebar-toggle { display: inline-flex; }
  .crm-content { padding: 1rem; }
  .crm-topbar { padding: .6rem 1rem; }
  .dl { grid-template-columns: 105px 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
