/* LeadLoop CRM — application shell.
   One stylesheet, no build step, no framework. Custom properties up top so a
   rebrand is a handful of edits rather than a find-and-replace. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e5e8ec;
  --border-strong: #d3d8df;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #0f172a;
  --accent-ink: #ffffff;
  --focus: #2563eb;

  --blue: #2563eb;    --blue-bg: #eff6ff;
  --sky: #0284c7;     --sky-bg: #f0f9ff;
  --violet: #7c3aed;  --violet-bg: #f5f3ff;
  --emerald: #059669; --emerald-bg: #ecfdf5;
  --amber: #d97706;   --amber-bg: #fffbeb;
  --rose: #e11d48;    --rose-bg: #fff1f2;
  --slate: #475569;   --slate-bg: #f8fafc;

  --radius: 12px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15,23,42,.05);
  --shadow-md: 0 4px 16px rgba(15,23,42,.08);
  --sidebar-w: 236px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
.ic { flex-shrink: 0; vertical-align: -.15em; }

/* Visible focus rings — keyboard users work these screens all day. */
a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ layout */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 9px;
  padding: 17px 18px;
  font-weight: 800; font-size: 15px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .dot {
  width: 26px; height: 26px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 900;
}

.sidebar-nav { padding: 10px; flex: 1; overflow-y: auto; }
.nav-label {
  font-size: 10px; font-weight: 800; letter-spacing: .08em;
  text-transform: uppercase; color: var(--faint);
  padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--muted); font-weight: 600;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent); color: var(--accent-ink); }
.nav-item .count {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--border); color: var(--muted);
  padding: 1px 7px; border-radius: 20px;
}
.nav-item.active .count { background: rgba(255,255,255,.2); color: #fff; }
.nav-item .count.alert { background: var(--rose-bg); color: var(--rose); }

.sidebar-foot { border-top: 1px solid var(--border); padding: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 13px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.topbar .spacer { flex: 1; }
.menu-toggle { display: none; }

.content { padding: 22px; flex: 1; }
.content > * + * { margin-top: 16px; }

/* --------------------------------------------------------------- utilities */

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.tight { gap: 6px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.bold { font-weight: 700; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.hide { display: none !important; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

/* ------------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}
.card-head h2, .card-head h3 { margin: 0; font-size: 13.5px; font-weight: 800; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
.card-foot {
  padding: 11px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* Stat tiles */
.stat { padding: 15px 16px; }
.stat .label {
  font-size: 10.5px; font-weight: 800; letter-spacing: .07em;
  text-transform: uppercase; color: var(--faint);
}
.stat .value {
  font-size: 25px; font-weight: 900; letter-spacing: -.02em;
  margin-top: 5px; font-variant-numeric: tabular-nums;
}
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.stat .sub.up { color: var(--emerald); }
.stat .sub.down { color: var(--rose); }

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; padding: 9px 14px;
  font-size: 10.5px; font-weight: 800; letter-spacing: .06em;
  text-transform: uppercase; color: var(--faint);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.data td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data td.shrink { width: 1%; white-space: nowrap; }
/* Action buttons in a narrow cell must stay on one line, not stack. */
table.data td.shrink .row { flex-wrap: nowrap; }

/* Inline stage / owner pickers in the lead list.
   Styled to read as the badge they replace — a row of full-height form controls
   turns a scannable list into a form, which is exactly what we don't want. */
select.stage-pick, select.owner-pick {
  width: auto;
  min-width: 108px;
  padding: 2px 22px 2px 9px;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 20px;
  border-color: transparent;
  background-color: var(--slate-bg);
  background-position: right 5px center;
  background-size: 13px;
  color: var(--slate);
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s;
}
select.owner-pick {
  border-radius: var(--radius-sm);
  background-color: transparent;
  color: var(--text);
  font-weight: 600;
  min-width: 118px;
}
select.stage-pick:hover, select.owner-pick:hover { border-color: var(--border-strong); }

select.stage-pick.blue    { background-color: var(--blue-bg);    color: var(--blue); }
select.stage-pick.sky     { background-color: var(--sky-bg);     color: var(--sky); }
select.stage-pick.violet  { background-color: var(--violet-bg);  color: var(--violet); }
select.stage-pick.emerald { background-color: var(--emerald-bg); color: var(--emerald); }
select.stage-pick.amber   { background-color: var(--amber-bg);   color: var(--amber); }
select.stage-pick.rose    { background-color: var(--rose-bg);    color: var(--rose); }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty .big { font-size: 15px; font-weight: 700; color: var(--text); margin-bottom: 5px; }

/* ------------------------------------------------------------------ badges */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 700; white-space: nowrap;
  background: var(--slate-bg); color: var(--slate);
}
.badge.blue { background: var(--blue-bg); color: var(--blue); }
.badge.sky { background: var(--sky-bg); color: var(--sky); }
.badge.violet { background: var(--violet-bg); color: var(--violet); }
.badge.emerald { background: var(--emerald-bg); color: var(--emerald); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.rose { background: var(--rose-bg); color: var(--rose); }
.badge.solid { background: var(--accent); color: #fff; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 10.5px; font-weight: 800; flex-shrink: 0;
}
.avatar.sm { width: 24px; height: 24px; font-size: 9px; }

/* ------------------------------------------------------------------ forms */

label.field { display: block; margin-bottom: 12px; }
label.field > span {
  display: block; font-size: 12px; font-weight: 700;
  color: var(--muted); margin-bottom: 5px;
}
label.field > span .req { color: var(--rose); }

input[type=text], input[type=email], input[type=password], input[type=tel],
input[type=number], input[type=date], input[type=datetime-local], input[type=search],
select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  font: inherit;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
  outline: none;
}
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-2); color: var(--muted); cursor: not-allowed;
}
textarea { min-height: 84px; resize: vertical; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 9px center; padding-right: 30px; }
.hint { font-size: 11.5px; color: var(--faint); margin-top: 4px; }

/* ----------------------------------------------------------------- buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: #fff; color: var(--text);
  font: inherit; font-weight: 700; font-size: 13px;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1e293b; }
.btn.danger { color: var(--rose); border-color: #fecdd3; background: var(--rose-bg); }
.btn.danger:hover { background: #ffe4e6; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ------------------------------------------------------------------ alerts */

.alert {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 13px;
}
.alert.success { background: var(--emerald-bg); border-color: #a7f3d0; color: #065f46; }
.alert.error   { background: var(--rose-bg); border-color: #fecdd3; color: #9f1239; }
.alert.warn    { background: var(--amber-bg); border-color: #fde68a; color: #92400e; }
.alert.info    { background: var(--blue-bg); border-color: #bfdbfe; color: #1e40af; }

/* Platform operator working inside a customer's workspace. Deliberately loud —
   the one state where a mistake damages someone else's data. */
.acting-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 22px;
  background: #f5f3ff;
  border-bottom: 2px solid #7c3aed;
  color: #4c1d95;
  font-size: 13px;
  position: sticky; top: 51px; z-index: 19;
}
.acting-bar .btn { background: #fff; border-color: #ddd6fe; color: #6d28d9; }

.flashes { position: fixed; top: 14px; right: 14px; z-index: 200; width: 330px; max-width: calc(100vw - 28px); }
.flashes .alert { box-shadow: var(--shadow-md); margin-bottom: 8px; background: #fff; }
.flashes .alert.success { background: #f0fdf4; }
.flashes .alert.error { background: #fff1f2; }

/* --------------------------------------------------------------- pipeline */

.pipeline { display: flex; gap: 4px; }
.pipeline .seg {
  flex: 1; min-width: 0;
  padding: 11px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.pipeline .seg .n { font-size: 20px; font-weight: 900; font-variant-numeric: tabular-nums; }
.pipeline .seg .t { font-size: 11px; font-weight: 700; color: var(--muted); }
.pipeline .seg .bar { height: 3px; border-radius: 3px; margin-top: 7px; background: var(--border); }

/* ------------------------------------------------------------------ charts
   Pure CSS bar chart — no JS charting dependency for one sparkline. */

.chart { display: flex; align-items: flex-end; gap: 3px; height: 132px; padding-top: 8px; }
.chart .col { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; position: relative; }
.chart .bar { background: var(--blue); border-radius: 3px 3px 0 0; min-height: 2px; transition: opacity .12s; }
.chart .bar.won { background: var(--emerald); }
.chart .col:hover .bar { opacity: .75; }
.chart .col .tip {
  display: none; position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; font-size: 11px; font-weight: 600;
  padding: 4px 8px; border-radius: 6px; white-space: nowrap; margin-bottom: 5px; z-index: 5;
}
.chart .col:hover .tip { display: block; }
.chart-labels { display: flex; gap: 3px; margin-top: 6px; }
.chart-labels span { flex: 1; min-width: 0; font-size: 9.5px; color: var(--faint); text-align: center; overflow: hidden; }

/* ---------------------------------------------------------------- timeline */

.timeline { position: relative; padding-left: 26px; }
.timeline::before {
  content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border);
}
.tl-item { position: relative; padding-bottom: 17px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ''; position: absolute; left: -22px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--faint); border: 2px solid var(--surface);
}
.tl-item.note::before   { background: var(--slate); }
.tl-item.call::before   { background: var(--blue); }
.tl-item.status::before { background: var(--violet); }
.tl-item.assign::before { background: var(--amber); }
.tl-item.capi::before   { background: var(--emerald); }
.tl-item.email::before  { background: var(--sky); }
.tl-item .tl-body { font-size: 13px; }
.tl-item .tl-meta { font-size: 11.5px; color: var(--faint); margin-top: 2px; }

/* ------------------------------------------------------------------ filters */

.filters {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.filters input, .filters select { width: auto; min-width: 130px; }
.filters .search { min-width: 220px; flex: 1; }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px;
  border: 1px solid var(--border-strong);
  font-size: 12px; font-weight: 700; color: var(--muted);
  background: #fff;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.pager { display: flex; gap: 6px; align-items: center; justify-content: center; padding: 12px; }

/* ------------------------------------------------------------------ modals */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: grid; place-items: center; z-index: 100; padding: 18px;
}
.modal {
  background: #fff; border-radius: 15px; width: 100%; max-width: 500px;
  max-height: 88vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(15,23,42,.25);
}
.modal .card-head { position: sticky; top: 0; background: #fff; border-radius: 15px 15px 0 0; }

/* ----------------------------------------------------------------- auth pages */

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 22px; background: var(--bg); }
.auth-card { width: 100%; max-width: 410px; }
.auth-card .card { padding: 26px; }
.auth-logo { display: flex; align-items: center; justify-content: center; gap: 9px; font-weight: 900; font-size: 18px; margin-bottom: 20px; }

/* ------------------------------------------------------------------- misc */

.kv { display: grid; grid-template-columns: 108px 1fr; gap: 7px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }

.copy-box {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 11px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.copy-box code { flex: 1; min-width: 0; overflow-x: auto; white-space: nowrap; font-size: 12px; }

.switch { display: inline-flex; align-items: center; gap: 9px; cursor: pointer; }
.switch input { display: none; }
.switch .track {
  width: 36px; height: 21px; border-radius: 20px; background: var(--border-strong);
  position: relative; transition: background .16s; flex-shrink: 0;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 17px; height: 17px; border-radius: 50%; background: #fff;
  transition: transform .16s; box-shadow: var(--shadow);
}
.switch input:checked + .track { background: var(--emerald); }
.switch input:checked + .track::after { transform: translateX(15px); }

/* ------------------------------------------------------------- responsive */

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 60;
    transform: translateX(-100%); transition: transform .2s;
    box-shadow: var(--shadow-md);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open::after {
    content: ''; position: fixed; inset: 0; background: rgba(15,23,42,.4); z-index: 50;
  }
  .menu-toggle { display: inline-flex; }
  .content { padding: 15px; }

  /* The topbar search would overflow and push "Add lead" off-screen. The Leads
     page has its own search box, so drop this one rather than squeeze it. */
  .topbar form { display: none; }
  .topbar h1 { font-size: 15px; }
  .topbar .badge { display: none; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .pipeline { flex-wrap: wrap; }
  .pipeline .seg { flex: 1 1 30%; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 8px; }
}

@media print {
  .sidebar, .topbar, .filters, .btn { display: none !important; }
  .content { padding: 0; }
  .card { border: 1px solid #ccc; box-shadow: none; }
}
