:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #a40200;      /* Speed dark red, from the logo */
  --accent: #a40200;
  --accent-soft: #fbeceb;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --green: #15803d;
  --green-bg: #f0fdf4;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 4px 0 12px; }
h2 { font-size: 15px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 0 8px; }
.container { max-width: 1000px; margin: 0 auto; padding: 16px 16px 96px; }
[hidden] { display: none !important; }

/* ---------- Top bar & navigation ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: #fff; color: var(--text); padding: 8px 16px;
  border-bottom: 3px solid var(--brand);
}
.brand { display: flex; align-items: center; }
.brand img { height: 40px; display: block; }
.me { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.me .btn-link { color: var(--muted); }
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: #fff; border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav a {
  flex: 1; text-align: center; padding: 14px 4px; color: var(--muted); font-weight: 600; font-size: 15px;
}
.nav a.active { color: var(--accent); }
.nav a.nav-add { color: var(--accent); }
@media (max-width: 480px) { .nav a { font-size: 13px; padding: 14px 2px; } }
#me-name { display: none; }

@media (min-width: 768px) {
  .nav { position: static; background: none; border: 0; gap: 4px; padding: 0; flex: 1; margin-left: 24px; }
  .nav a { flex: 0 0 auto; color: var(--muted); padding: 8px 14px; border-radius: 8px; }
  .nav a.active { background: var(--accent-soft); color: var(--accent); }
  .nav a.nav-add { color: #fff; margin-left: auto; background: var(--accent); }
  #me-name { display: inline; }
  .container { padding-bottom: 40px; }
}

/* ---------- Section switch (Speed Marketing | Reflection Car Care) ---------- */
.section-bar {
  display: flex; gap: 4px; padding: 6px; margin: 12px auto 0; max-width: 520px; width: calc(100% - 32px);
  background: #e5e7eb; border-radius: 12px;
}
.section-bar button {
  flex: 1; border: 0; background: none; border-radius: 9px; padding: 10px 8px;
  font-weight: 700; font-size: 14px; color: var(--muted);
}
.section-bar button.on { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* ---------- Buttons & forms ---------- */
button { font: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 10px; padding: 12px 16px; font-weight: 600; min-height: 46px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--red); border-color: #fecaca; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-link { background: none; border: 0; color: var(--accent); padding: 4px; font-weight: 600; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

label { display: block; font-size: 14px; font-weight: 600; color: #374151; margin: 14px 0 6px; }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; padding: 11px 12px;
  border: 1px solid #d1d5db; border-radius: 10px; background: #fff; color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #f3c4c2; border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
@media (min-width: 768px) { .form-grid { grid-template-columns: 1fr 1fr; } .span-2 { grid-column: span 2; } }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid #d1d5db; background: #fff; border-radius: 999px;
  padding: 9px 14px; font-size: 15px; font-weight: 500; color: #374151;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips-scroll { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; -webkit-overflow-scrolling: touch; }
.chips-scroll .chip { white-space: nowrap; }
.checks label { display: flex; align-items: center; gap: 10px; font-weight: 500; margin: 8px 0; }
.checks input { width: 20px; height: 20px; }

/* ---------- Cards & lists ---------- */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.list { display: grid; gap: 8px; }
@media (min-width: 1000px) { .list-wide { grid-template-columns: 1fr 1fr; } }
.lead-card { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.lead-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.lead-main { flex: 1; min-width: 0; }
.lead-name { font-weight: 700; }
.lead-owner { font-size: 16px; margin-bottom: 8px; }
.meet-actions { display: flex; flex-direction: column; gap: 6px; }
.lead-sub { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: #f3f4f6; color: #374151; }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-blue { background: #eff6ff; color: #1d4ed8; }
.call-btn {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--green-bg); color: var(--green); font-size: 20px;
}
.lead-card.selected { outline: 2px solid var(--accent); background: var(--accent-soft); }
.check {
  flex: 0 0 auto; width: 26px; height: 26px; border-radius: 7px; border: 2px solid #d1d5db; background: #fff;
  display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 800;
}
.check.on { background: var(--accent); border-color: var(--accent); }
.bulk-bar {
  position: fixed; left: 0; right: 0; bottom: calc(50px + env(safe-area-inset-bottom)); z-index: 11;
  background: #fff; border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(0,0,0,.08); padding: 10px 16px;
}
.bulk-inner { max-width: 1000px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bulk-count { flex: 1 0 100%; }
.bulk-inner select { width: auto; flex: 1; min-height: 46px; }
@media (min-width: 768px) {
  .bulk-bar { bottom: 0; }
  .bulk-count { flex: 1; }
}
#app:has(.bulk-bar:not([hidden])) { padding-bottom: 220px; }
.empty { color: var(--muted); padding: 10px 2px; font-size: 15px; }
.section-count { color: var(--muted); font-weight: 500; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar input { flex: 1; min-width: 180px; }
.toolbar select { width: auto; }

/* ---------- Lead page ---------- */
.lead-layout { display: grid; gap: 16px; }
@media (min-width: 900px) { .lead-layout { grid-template-columns: 1.1fr 1fr; align-items: start; } }
.info-row { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.info-row:last-child { border-bottom: 0; }
.info-row .k { color: var(--muted); font-size: 14px; flex: 0 0 auto; }
.info-row .v { text-align: right; word-break: break-word; }
.notes { white-space: pre-wrap; }
.timeline { display: grid; gap: 0; }
.tl-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.tl-item:last-child { border-bottom: 0; }
.tl-head { font-weight: 600; font-size: 15px; }
.tl-meta { color: var(--muted); font-size: 13px; }
.tl-note { margin-top: 4px; white-space: pre-wrap; }
.won-box { background: var(--green-bg); border-radius: 10px; padding: 12px; margin-top: 10px; }

/* ---------- Bottom sheet (log a call, etc.) ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: #fff; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
@media (min-width: 768px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: 18px; }
}
.sheet h3 { margin: 0 0 4px; font-size: 19px; }
.sheet .sub { color: var(--muted); margin: 0 0 6px; font-size: 14px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 20px; }
.sheet-actions .btn { flex: 1; }

/* ---------- Login ---------- */
.login { max-width: 380px; margin: 12vh auto 0; }
.login h1 { text-align: center; }
.login-logo { display: block; width: 200px; max-width: 70%; margin: 0 auto 8px; }
.login .hint { color: var(--muted); font-size: 14px; text-align: center; margin-top: 14px; }

/* ---------- Dashboard ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (min-width: 768px) { .tiles { grid-template-columns: repeat(4, 1fr); } }
.tile-num { font-size: 26px; font-weight: 800; color: var(--text); }
.tile-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.tile-wide .tile-num { color: var(--accent); }
.table-wrap { overflow-x: auto; padding: 0; }
table.stats { border-collapse: collapse; width: 100%; font-size: 14px; white-space: nowrap; }
table.stats th, table.stats td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--line); }
table.stats th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: normal; min-width: 80px; }
table.stats th:first-child, table.stats td:first-child { text-align: left; position: sticky; left: 0; background: #fff; }
table.stats tr.total td { font-weight: 700; border-bottom: 0; background: #fafafa; }
.delta { font-size: 12px; color: var(--muted); margin-top: 4px; }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }

@media print {
  .topbar, .nav, .no-print, .toast { display: none !important; }
  body { background: #fff; }
  .container { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .tiles { grid-template-columns: repeat(4, 1fr); }
  .lead-layout { grid-template-columns: 1fr 1fr; }
  .table-wrap { overflow: visible; }
}

pre.code {
  background: #f3f4f6; border-radius: 10px; padding: 12px; margin: 0;
  font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-all; max-height: 360px; overflow: auto;
}

details summary { cursor: pointer; color: var(--accent); font-weight: 600; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 60;
  background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 15px;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.toast.error { background: var(--red); }
.banner { background: var(--amber-bg); color: var(--amber); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }

/* ---------- Work: tasks, progress, video review, bell ---------- */
.hide-sm { display: none; }
@media (min-width: 768px) { .hide-sm { display: inline; } }
@media (max-width: 480px) { .nav[data-count="6"] a { font-size: 12px; } }

.bell { position: relative; font-size: 18px; padding: 4px 6px; text-decoration: none; }
.bell-count {
  position: absolute; top: -4px; right: -6px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--red); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

.tick {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; border: 2px solid #cbd5e1; background: #fff;
  color: #fff; font-weight: 800; font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.tick:hover:not(:disabled) { border-color: var(--green); }
.tick.on { background: var(--green); border-color: var(--green); }
.tick:disabled { opacity: .35; cursor: not-allowed; }
.task-card.is-done .lead-name { text-decoration: line-through; color: var(--muted); }
.task-card.is-overdue { box-shadow: inset 4px 0 0 var(--red); }
.is-done { opacity: .7; }
h2.h-red { color: var(--red); }
.prio-high { background: var(--red-bg); color: var(--red); }
.prio-medium { background: var(--amber-bg); color: var(--amber); }
.prio-low { background: #f3f4f6; color: var(--muted); }

.progress-card { margin-top: 12px; display: grid; gap: 12px; }
@media (min-width: 768px) { .progress-card { grid-template-columns: 1fr 1fr; gap: 24px; } }
.progress-head { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.progress-head b { color: var(--text); }
.progress { height: 10px; border-radius: 999px; background: #eef0f3; overflow: hidden; }
.progress-bar { height: 100%; background: var(--green); border-radius: 999px; transition: width .3s; }

.tile-good .tile-num { color: var(--green); }
.tile-bad .tile-num { color: var(--red); }
.team-table td { vertical-align: middle; }
.row-link { cursor: pointer; }
.row-link:hover td { background: #fafafa; }
.cell-bad { color: var(--red); font-weight: 700; }
.filters select, .filters input { width: auto; }
.inline-date { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); font-weight: 600; margin: 0; }
.suggestion { border: 1px dashed #93c5fd; }
.template-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.assignees .tl-meta { margin-left: 4px; }

.video-wrap { margin-top: 10px; background: #000; border-radius: 10px; overflow: hidden; }
.video-wrap video { display: block; width: 100%; max-height: 70vh; background: #000; }
.timeline-bar {
  position: relative; height: 22px; margin-top: 8px; border-radius: 6px; background: #eef0f3; cursor: pointer;
}
.timeline-progress { position: absolute; left: 0; top: 0; bottom: 0; background: #dbe3ee; border-radius: 6px; pointer-events: none; }
.marker {
  position: absolute; top: 2px; width: 14px; height: 18px; margin-left: -7px; padding: 0; border: 2px solid #fff;
  border-radius: 4px; background: var(--accent); cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.marker.resolved { background: var(--green); }
.time-chip {
  border: 0; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 700;
  font-size: 13px; padding: 2px 8px; cursor: pointer; font-family: inherit;
}
.comment.resolved .tl-note { color: var(--muted); text-decoration: line-through; }
.comment.resolved .time-chip { background: var(--green-bg); color: var(--green); }
.resolve-box { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; margin-top: 6px; }
.resolve-box input { width: 18px; height: 18px; }
.btn-approve { background: var(--green); border-color: var(--green); color: #fff; }

.notif.unread { box-shadow: inset 4px 0 0 var(--accent); }
.notif.unread .lead-name { color: var(--text); }
.notif .tl-note { font-size: 14px; color: var(--text); }
.or-line { text-align: center; color: var(--muted); font-size: 13px; font-weight: 600; margin: 12px 0 8px; }

/* ---------- Install as an app ---------- */
.install-bar {
  display: flex; align-items: center; gap: 10px; margin: 10px auto 0; max-width: 1100px;
  padding: 10px 14px; background: var(--accent-soft); color: var(--text); border-radius: var(--radius); font-size: 14px;
}
.install-bar > span:first-child { flex: 1; }
.install-bar .btn { padding: 8px 14px; }
.share-ico { display: inline-block; border: 1.5px solid currentColor; border-radius: 4px; padding: 0 4px; font-size: 12px; }
@media (max-width: 767px) { .install-bar { margin: 10px 12px 0; } }
