/* Mema CRM. One stylesheet, no framework. Stage colours: New blue, Contacted amber, Booked violet,
   Visited teal, Won green, Lost grey. The chat follows WhatsApp's look so the team reads it at a glance. */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --surface-3: #e7eaee; --text: #101828; --muted: #667085;
  --border: #e4e7ec; --accent: #0f766e; --accent-hover: #115e59; --accent-text: #ffffff; --accent-soft: #e3f4f1;
  --warn: #9a5b00; --warn-soft: #fff3dc; --danger: #b42318; --danger-soft: #fdecea; --ok: #067647; --ok-soft: #e3f8ec;
  --st-new: #2e6fe8; --st-contacted: #e28a00; --st-booked: #7a4ae2; --st-visited: #0f9a8c; --st-won: #16a34a; --st-lost: #98a2b3;
  --wa-bg: #efeae2; --wa-in: #ffffff; --wa-out: #d9fdd3; --wa-tick: #53bdeb;
  --shadow-1: 0 1px 2px rgb(16 24 40 / 6%); --shadow-2: 0 4px 14px rgb(16 24 40 / 9%); --shadow-3: -8px 0 40px rgb(16 24 40 / 16%);
  --radius: 12px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1214; --surface: #161b1f; --surface-2: #1c2227; --surface-3: #252c32; --text: #e6eaee; --muted: #94a0ab;
    --border: #2a3238; --accent: #2bb39f; --accent-hover: #3ccab5; --accent-text: #06201c; --accent-soft: #143a34;
    --warn: #f0b858; --warn-soft: #3a2c12; --danger: #f2877d; --danger-soft: #3c1c1a; --ok: #5fd38b; --ok-soft: #133523;
    --wa-bg: #0b141a; --wa-in: #202c33; --wa-out: #005c4b; --wa-tick: #53bdeb;
    --shadow-1: 0 1px 2px rgb(0 0 0 / 40%); --shadow-2: 0 6px 18px rgb(0 0 0 / 45%); --shadow-3: -8px 0 40px rgb(0 0 0 / 55%);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14.5px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px 11px; width: 100%; transition: border-color .15s, box-shadow .15s; }
input:hover, select:hover, textarea:hover { border-color: var(--surface-3); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button { cursor: pointer; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); padding: 8px 13px; font-weight: 500; transition: background .15s, border-color .15s, transform .05s; }
button:hover { background: var(--surface-2); }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--surface-2); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); text-decoration: underline; text-underline-offset: 2px; font-weight: 500; }
button:disabled { opacity: .5; cursor: not-allowed; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.badge { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 99px; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }

/* Header: brand, search, what's live, actions. */
.top { display: flex; align-items: center; gap: 14px; padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15.5px; white-space: nowrap; letter-spacing: -.01em; }
.brand img { width: 30px; height: 30px; padding: 5px; border-radius: 9px; background: var(--accent-soft); }
.top #search { max-width: 320px; padding-left: 34px; background: var(--surface-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23667085' stroke-width='2' stroke-linecap='round' viewBox='0 0 24 24'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 11px center; border-color: transparent; }
.top #search:focus { background-color: var(--surface); border-color: var(--accent); }
.status { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 4px 10px 4px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--st-lost); }
.pill.on { color: var(--ok); background: var(--ok-soft); }
.pill.on::before { background: var(--ok); box-shadow: 0 0 0 3px rgb(22 163 74 / 18%); }
.pill.warn { color: var(--warn); background: var(--warn-soft); }
.pill.warn::before { background: var(--warn); }
.top-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.logout { display: flex; gap: 8px; align-items: center; white-space: nowrap; font-size: 13px; }

/* Numbers: how many leads, and the two targets with a bar. */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; padding: 16px 20px 4px; max-width: 980px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow-1); display: flex; flex-direction: column; gap: 2px; }
.stat b { font-size: 24px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.stat span { font-size: 12.5px; color: var(--muted); }
.meter { height: 6px; border-radius: 99px; background: var(--surface-3); margin-top: 8px; overflow: hidden; position: relative; }
.meter i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--accent); transition: width .4s; }
.meter.low i { background: var(--st-contacted); }

/* The board: one column per stage. */
.board { display: grid; grid-template-columns: repeat(6, minmax(236px, 1fr)); gap: 14px; padding: 14px 20px 28px; overflow-x: auto; align-items: stretch; }
.col { background: var(--surface-2); border-radius: 14px; padding: 10px; min-height: calc(100vh - 220px); border-top: 3px solid var(--st, var(--st-lost)); }
.col h2 { font-size: 12.5px; text-transform: uppercase; letter-spacing: .06em; margin: 2px 4px 10px; display: flex; align-items: center; gap: 8px; color: var(--muted); }
.col h2::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--st, var(--st-lost)); }
.col h2 .count { margin-left: auto; font-weight: 700; background: var(--surface); color: var(--text); border-radius: 99px; padding: 1px 8px; font-size: 12px; letter-spacing: 0; }
.col .empty { font-size: 12.5px; color: var(--muted); text-align: center; padding: 18px 6px; border: 1px dashed var(--border); border-radius: 10px; }
.st-new { --st: var(--st-new); } .st-contacted { --st: var(--st-contacted); } .st-booked { --st: var(--st-booked); }
.st-visited { --st: var(--st-visited); } .st-won { --st: var(--st-won); } .st-lost { --st: var(--st-lost); }
.card { display: block; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--st, var(--border)); border-radius: 11px; padding: 10px 12px; margin-bottom: 9px; box-shadow: var(--shadow-1); transition: box-shadow .15s, transform .15s, border-color .15s; }
.card:hover { box-shadow: var(--shadow-2); transform: translateY(-1px); background: var(--surface); }
.card.active { border-color: var(--accent); border-left-color: var(--st, var(--accent)); box-shadow: 0 0 0 2px var(--accent-soft), var(--shadow-2); }
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; }
.card-top strong { font-size: 14.5px; line-height: 1.3; overflow-wrap: anywhere; }
.card .where { font-size: 13px; color: var(--muted); margin-top: 2px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; margin-top: 8px; }
.card-meta .ago { margin-left: auto; font-size: 12px; color: var(--muted); }
.unread { background: var(--accent); color: var(--accent-text); border-radius: 99px; font-size: 11.5px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center; }
.chip { font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--muted); border-radius: 6px; padding: 2px 7px; white-space: nowrap; }
.chip.q-good { background: var(--ok-soft); color: var(--ok); }
.chip.q-bad, .chip.q-spam { background: var(--danger-soft); color: var(--danger); }
.chip.src-whatsapp { background: var(--ok-soft); color: var(--ok); }
.chip.src-funnel { background: var(--accent-soft); color: var(--accent); }
.chip.bot-ai { background: #efe9ff; color: #5b34c4; }
.chip.bot-off, .chip.bot-handoff { background: var(--warn-soft); color: var(--warn); }
@media (prefers-color-scheme: dark) { .chip.bot-ai { background: #2a2147; color: #b9a3ff; } }

/* The lead panel. */
.panel { position: fixed; top: 0; right: 0; bottom: 0; width: min(600px, 100%); background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-3); display: flex; flex-direction: column; z-index: 10; animation: slide .18s ease-out; }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } }
.panel[hidden] { display: none; }
.p-head { display: flex; align-items: center; gap: 12px; padding: 16px 18px 10px; }
.avatar { width: 46px; height: 46px; flex: none; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 16px; color: #fff; background: var(--st, var(--accent)); }
.p-head > .who { flex: 1; min-width: 0; }
.p-head h2 { margin: 0; font-size: 19px; letter-spacing: -.01em; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stage-badge { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 2px 8px; border-radius: 99px; color: var(--st); background: var(--surface-2); }
.contact { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13.5px; margin-top: 2px; }
.contact a { color: var(--accent); text-decoration: none; font-weight: 500; }
.contact a:hover { text-decoration: underline; }
.p-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; padding: 4px 18px 14px; border-bottom: 1px solid var(--border); }
.p-controls label { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.p-controls .wide { grid-column: 1 / -1; }
.seg { display: flex; gap: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; padding: 7px 4px; font-size: 13px; border: 0; border-radius: 0; border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.facts { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.facts > span { display: flex; flex-direction: column; font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.facts b { color: var(--text); font-weight: 600; font-size: 13.5px; text-transform: none; letter-spacing: 0; overflow-wrap: anywhere; }
.tabs { display: flex; gap: 2px; padding: 0 12px; border-bottom: 1px solid var(--border); }
.tabs button { border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: none; padding: 10px 12px; color: var(--muted); font-weight: 600; }
.tabs button:hover { color: var(--text); background: none; }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--accent); }
.tab-body { flex: 1; overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
.tab-body[hidden] { display: none; }

/* The chat, in WhatsApp's colours. */
.chat-list { flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 6px; background: var(--wa-bg); }
.msg { max-width: 82%; padding: 7px 10px 6px; border-radius: 10px; box-shadow: 0 1px .5px rgb(11 20 26 / 13%); position: relative; }
.msg.in { align-self: flex-start; background: var(--wa-in); border-top-left-radius: 3px; }
.msg.out { align-self: flex-end; background: var(--wa-out); border-top-right-radius: 3px; }
.msg.failed { outline: 1.5px solid var(--danger); }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 3px; text-align: right; display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.msg .meta .by { font-weight: 600; }
.msg .meta .tick.read { color: var(--wa-tick); font-weight: 700; }
.msg .meta .tick.failed { color: var(--danger); font-weight: 700; }
.msg .error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.msg img { max-width: 100%; max-height: 320px; border-radius: 7px; display: block; margin-bottom: 4px; }
.composer { border-top: 1px solid var(--border); padding: 12px 18px; display: flex; flex-direction: column; gap: 8px; background: var(--surface); }
.composer .send { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: vertical; min-height: 44px; border-radius: 12px; }
.notice { font-size: 13px; background: var(--warn-soft); color: var(--warn); border-radius: 10px; padding: 8px 12px; }
.sim { border: 1px dashed var(--border); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.sim .send { display: flex; gap: 8px; }
.sim .quick { display: flex; flex-wrap: wrap; gap: 5px; }
.sim .quick button { font-size: 12px; padding: 4px 9px; }

/* Timeline and notes. */
.note-form { display: flex; gap: 8px; padding: 14px 18px; }
.jobs { padding: 0 18px 4px; font-size: 12.5px; color: var(--muted); }
.timeline { list-style: none; margin: 0; padding: 6px 18px 18px; }
.timeline li { position: relative; padding: 2px 0 12px 20px; overflow-wrap: anywhere; font-size: 13.5px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; bottom: -6px; width: 2px; background: var(--border); }
.timeline li::after { content: ""; position: absolute; left: 0; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--muted); }
.timeline li:last-child::before { display: none; }
.timeline li.note::after { border-color: var(--accent); background: var(--accent-soft); }
.timeline .when { font-size: 11.5px; color: var(--muted); }

/* Forms and dialogs. */
.form { display: flex; flex-direction: column; gap: 12px; padding: 20px; min-width: min(440px, 90vw); }
.form h2 { margin: 0 0 4px; font-size: 18px; }
.form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.form label.check { flex-direction: row; align-items: flex-start; gap: 8px; color: var(--text); font-weight: 500; }
.form label.check input { width: auto; margin-top: 3px; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; }
dialog { border: 1px solid var(--border); border-radius: 16px; padding: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow-2); }
dialog::backdrop { background: rgb(16 24 40 / 45%); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 20; max-width: calc(100% - 32px); box-shadow: var(--shadow-2); font-weight: 500; }

/* Login. */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; background: radial-gradient(circle at 20% 10%, var(--accent-soft), transparent 45%), var(--bg); }
.login { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow-2); }
.login h1 { margin: 0; font-size: 21px; letter-spacing: -.01em; }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.login-msg { margin: 0; color: var(--danger); background: var(--danger-soft); padding: 8px 10px; border-radius: 8px; }

button, .pill { white-space: nowrap; }
.status { flex-wrap: nowrap; }
/* Laptops: the status pills move to their own row under the header. */
@media (max-width: 1180px) {
  .top { flex-wrap: wrap; row-gap: 8px; }
  .status { order: 5; flex-basis: 100%; flex-wrap: wrap; }
}

/* Phones: one column at a time, the lead panel full screen. */
@media (max-width: 760px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 10px 14px; }
  .top #search { order: 3; max-width: none; flex-basis: 100%; }
  .status { order: 4; flex-basis: 100%; }
  .logout .muted, #sim-open { display: none; }
  .stats { grid-template-columns: 1fr 1fr; padding: 12px 14px 0; gap: 8px; }
  .board { grid-template-columns: repeat(6, 86vw); scroll-snap-type: x mandatory; padding: 12px 14px 20px; }
  .col { scroll-snap-align: start; min-height: 60vh; }
  .panel { width: 100%; border-left: 0; }
  .p-controls { grid-template-columns: 1fr; }
  .msg { max-width: 92%; }
}
