/* VD CRM — self-contained stylesheet (no CDNs). */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #e2e6ea;
  --border-strong: #cbd2d9;
  --text: #1f2933;
  --text-muted: #647280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #059669;
  --warn: #d97706;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- app shell: left sidebar + main column ---------- */
.app { display: flex; min-height: 100vh; }
.app-plain { display: block; }              /* logged-out (login): no sidebar */

.sidebar {
  width: 244px; flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; overflow-y: auto;
  z-index: 50;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 9px;
  padding: 15px 16px; font-weight: 700; font-size: 15px; letter-spacing: .3px;
  color: var(--text); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.brand-dot { width: 10px; height: 10px; border-radius: 3px; background: var(--primary); flex-shrink: 0; }

.sidebar-nav { flex: 1 1 auto; padding: 6px; }

/* leading icon shared by nav links + section headers (monochrome, inherits color) */
.nav-ico {
  width: 18px; height: 18px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 2;
  stroke-linecap: round; stroke-linejoin: round;
}

/* links: top-level (dark) + sub-items (muted) */
.sidebar-nav > a,
.navsec-items a {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px; border-radius: 7px; font-weight: 500; font-size: 13.5px;
}
.sidebar-nav > a { color: var(--text); }
.navsec-items a { color: var(--text-muted); padding-left: 40px; font-size: 13px; }
.sidebar-nav > a:hover,
.navsec-items a:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.sidebar-nav a.active {
  background: rgba(37, 99, 235, .1); color: var(--primary); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--primary);       /* left-accent bar */
}
.sidebar-nav a.active .nav-ico { stroke: var(--primary); }

/* section headers (collapsible) + workspace label — the grouping anchors */
.navsec { margin: 1px 0; }
.navsec > summary,
.navsec-label {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 12px; border-radius: 7px;
  font-size: 13.5px; font-weight: 600; color: var(--text);
}
.navsec > summary { list-style: none; cursor: pointer; user-select: none; }
.navsec > summary::-webkit-details-marker { display: none; }
.navsec > summary::after {
  content: "\25B8"; margin-left: auto; font-size: 11px; opacity: .5; transition: transform .15s;
}
.navsec[open] > summary::after { transform: rotate(90deg); }
.navsec > summary:hover { background: var(--bg); }
.navsec-items { margin: 0 0 3px; }
.navsec-label { margin-top: 8px; color: var(--text-muted); }

/* foot: presence pill + compact user block */
.sidebar-foot {
  border-top: 1px solid var(--border); padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
  position: sticky; bottom: 0; background: var(--surface);
}
.sidebar-foot .presence { align-self: flex-start; }
.sidebar-foot .foot-user { display: flex; align-items: center; gap: 9px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 13px;
  display: flex; align-items: center; justify-content: center;
}
.foot-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.foot-meta .user-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.foot-role { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .4px; }
.logout { margin-left: auto; color: var(--text-muted); display: flex; align-items: center; }
.logout:hover { color: var(--danger); }
.user-name { font-weight: 600; }

/* slim sidebar scrollbar */
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(100, 116, 139, .35); border-radius: 8px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

/* main column: top bar + page content */
.main-col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 20px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-weight: 600; }
.hamburger {
  display: none;                            /* shown only on small screens */
  width: 40px; height: 40px; flex-shrink: 0;
  align-items: center; justify-content: center;
  border: 1px solid var(--border-strong); background: #fff; border-radius: 8px;
  font-size: 18px; line-height: 1; cursor: pointer; color: var(--text);
}
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; }

/* mobile drawer backdrop */
.nav-overlay { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 40; }

/* ---------- layout ---------- */
.content { max-width: 1200px; margin: 0 auto; padding: 24px; width: 100%; }
.content.content-wide { max-width: 1640px; }

/* printable documents (receipts, rent demands): drop the app chrome */
@media print {
  .sidebar, .topbar, .nav-overlay, .no-print { display: none !important; }
  .app, .main-col { display: block; }
  .content { max-width: none; margin: 0; padding: 0; }
  .card.doc { border: none; box-shadow: none; }
}

/* ---------- responsive: sidebar becomes an off-canvas drawer on phones/tablets ---------- */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; height: 100vh; width: 270px; max-width: 82vw;
    transform: translateX(-100%); transition: transform .25s ease;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .28);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .nav-overlay { display: block; }
  .hamburger { display: inline-flex; }
  .topbar-user { display: none; }          /* keep the mobile bar uncluttered */
  .content { padding: 16px; }
}
.page-title { font-size: 22px; margin: 0 0 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 20px;
}
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h2 { font-size: 15px; margin: 0; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.empty { color: var(--text-muted); padding: 8px 0; }
.danger { color: var(--danger); }

/* ---------- stat cards ---------- */
.cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr) 2fr;
  gap: 16px;
  margin-bottom: 20px;
}
.stat { margin: 0; }
.stat-wide { grid-column: span 1; }
.stat-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 30px; font-weight: 700; margin-top: 4px; }

.status-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--bg); color: var(--text);
}
.status-pill:hover { text-decoration: none; border-color: var(--border-strong); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data thead th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-muted); background: var(--bg);
}
table.data tbody tr:hover { background: #fafbfc; }
.ai-summary { white-space: normal; }

/* ---------- polished shared admin table (scorecard, reports, integrity, attendance,
   logins, presence, contacts, users, …) — all use class="grid" ---------- */
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.grid thead th, table.grid tr:first-child th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--text-muted); background: var(--bg); font-weight: 700;
}
table.grid th:first-child, table.grid td:first-child { padding-left: 16px; }
table.grid th:last-child,  table.grid td:last-child  { padding-right: 16px; }
/* zebra + hover on the ROW so intentional inline highlights (flagged rows, heat cells) still win */
table.grid tbody tr:nth-child(even),
table.grid tr:nth-child(even):not(:first-child) { background: rgba(148,163,184,.06); }
table.grid tbody tr:hover,
table.grid tr:hover:not(:first-child) { background: rgba(59,130,246,.09); }
table.grid tr:last-child td { border-bottom: none; }

/* Dense, fit-to-width table (Leads): wrap long cells so every column is visible
   without horizontal scrolling. */
table.data.data-fit { font-size: 12px; }
table.data.data-fit th, table.data.data-fit td {
  /* overflow-wrap:anywhere breaks only over-long words; word-break:break-word wrongly broke
     every word to one char per line when a column got very narrow (e.g. next to an open drawer). */
  white-space: normal; overflow-wrap: anywhere; padding: 6px 8px; vertical-align: top;
}
table.data.data-fit td .badge, table.data.data-fit td .tag,
table.data.data-fit td .chip-sentiment { white-space: nowrap; }
.tag {
  display: inline-block; padding: 1px 7px; margin: 1px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; font-size: 12px; color: var(--text);
}

/* ---------- badges ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; line-height: 1.5;
  background: #eef1f4; color: var(--text);
}
.badge.big { font-size: 12px; padding: 4px 10px; }
.badge-role { background: #ede9fe; color: #6d28d9; text-transform: uppercase; }
.badge-yes { background: #dcfce7; color: var(--ok); }
.badge-no { background: #fee2e2; color: var(--danger); }
.badge-review { background: #fef3c7; color: var(--warn); }

/* status colors */
.status-pending  { background: #e5e7eb; color: #374151; }
.status-calling  { background: #dbeafe; color: #1d4ed8; }
.status-done     { background: #dcfce7; color: #047857; }
.status-no_answer{ background: #fef3c7; color: #b45309; }
.status-voicemail{ background: #fae8ff; color: #a21caf; }
.status-declined { background: #fee2e2; color: #b91c1c; }
.status-invalid  { background: #f3f4f6; color: #6b7280; }
.status-open      { background: #dbeafe; color: #1d4ed8; }
.status-contacted { background: #dcfce7; color: #047857; }
.status-scheduled { background: #fef3c7; color: #b45309; }
.status-closed    { background: #e5e7eb; color: #374151; }
.status-active   { background: #dcfce7; color: #047857; }
.status-paused   { background: #fef3c7; color: #b45309; }

/* ---------- flags / sentiment chips ---------- */
.flags { white-space: nowrap; }
.flags span { margin-right: 4px; }
.chip-sentiment {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: 11px; font-weight: 600; background: #eef1f4; color: var(--text);
}
.sentiment-interested    { background: #dcfce7; color: #047857; }
.sentiment-neutral       { background: #e5e7eb; color: #374151; }
.sentiment-hesitant      { background: #fef3c7; color: #b45309; }
.sentiment-not_interested{ background: #fee2e2; color: #b91c1c; }
.sentiment-annoyed       { background: #fee2e2; color: #b91c1c; }
.sentiment-busy          { background: #fae8ff; color: #a21caf; }
.verify-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.verify-form { display: inline; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.field.inline { margin-bottom: 0; }
.field.check { flex-direction: row; align-items: center; gap: 8px; }
.field.check input { width: auto; }
input, select, textarea {
  font-family: inherit; font-size: 14px; color: var(--text);
  padding: 8px 10px; border: 1px solid var(--border-strong);
  border-radius: 6px; background: #fff; width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
textarea { resize: vertical; }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; }
.filter-actions { display: flex; gap: 8px; }
.grid-form { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; align-items: end; }
.grid-form .wide { grid-column: span 2; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-block; padding: 8px 14px; border-radius: 6px;
  border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  font-size: 13px; font-weight: 600; cursor: pointer; text-align: center;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; }
.btn-block { display: block; width: 100%; }

.alert { padding: 10px 12px; border-radius: 6px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: #fee2e2; color: var(--danger); border: 1px solid #fecaca; }

/* ---------- login ---------- */
.login-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 340px; }
.login-title { margin: 0 0 2px; font-size: 22px; }

/* ---------- lead detail ---------- */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.detail-head .page-title { margin: 0; }
.back { font-size: 13px; }
.detail-grid { display: grid; grid-template-columns: 1fr 340px; gap: 20px; align-items: start; }
.detail-side .card { margin-bottom: 16px; }

.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 24px; }
.kv > div { display: flex; flex-direction: column; }
.kv .k { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.kv .v { font-weight: 500; }

.action-row { margin-bottom: 14px; }
.followups { list-style: none; margin: 0; padding: 0; }
.followups li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.followups li:last-child { border-bottom: none; }
.fu-notes { margin: 4px 0; }

/* ---------- calls / transcript ---------- */
.call { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 14px; }
.call-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.call audio { width: 100%; margin: 6px 0 10px; }
.transcript-raw { background: var(--bg); padding: 10px; border-radius: 6px; white-space: pre-wrap; font-size: 13px; }

.chat { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 12px; }
.bubble .who { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .4px; opacity: .7; margin-bottom: 2px; }
.bubble.owner { align-self: flex-start; background: #eef1f4; border-bottom-left-radius: 3px; }
.bubble.agent { align-self: flex-end; background: #dbeafe; color: #0b3aa3; border-bottom-right-radius: 3px; }

/* ---------- campaigns ---------- */
.campaign { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; }
.campaign-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.import-form { display: flex; gap: 8px; align-items: center; }
.import-form input[type=file] { width: auto; font-size: 12px; }

/* ---------- campaign detail: progress + KPIs ---------- */
.progress {
  height: 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; overflow: hidden;
}
.progress-fill {
  height: 100%; background: var(--primary);
  width: 0%; transition: width .4s ease;
}
.kpis {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 10px; margin-top: 16px;
}
.kpi {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
}
.kpi b { font-size: 22px; font-weight: 700; }
.kpi-calling { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37, 99, 235, .12); }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr; }
  .grid-form { grid-template-columns: 1fr 1fr; }
  .grid-form .wide { grid-column: span 2; }
  .kpis { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 560px) {
  .cards { grid-template-columns: 1fr; }
  .grid-2, .grid-form { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}
