:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #1f5eff;
  --brand-ink: #ffffff;
  --brand-soft: #e8efff;
  --danger: #d92d20;
  --danger-soft: #fee4e2;
  --warn: #b54708;
  --warn-soft: #fef0c7;
  --ok: #067647;
  --ok-soft: #dcfae6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Arabic", Tahoma, sans-serif;
  color: var(--ink);
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 14px; padding: 32px; box-shadow: var(--shadow); }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 24px; color: var(--muted); }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: #101828; color: #d0d5dd; padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.side .logo { color: #fff; font-weight: 700; font-size: 17px; padding: 6px 10px 18px; }
.side button.nav { background: none; border: 0; text-align: left; padding: 9px 12px; border-radius: 8px; color: inherit; cursor: pointer; display: flex; justify-content: space-between; align-items: center; }
.side button.nav:hover { background: #1d2939; }
.side button.nav.active { background: #344054; color: #fff; }
.side .spacer { flex: 1; }
.side .who { padding: 10px 12px; font-size: 13px; border-top: 1px solid #344054; margin-top: 8px; }
.side .who b { color: #fff; display: block; }
.side .who a { color: #98a2b3; cursor: pointer; display: block; margin-top: 4px; }
.count { background: var(--danger); color: #fff; border-radius: 99px; font-size: 11px; padding: 1px 7px; font-weight: 600; }
.count.blue { background: var(--brand); }
main { padding: 24px 28px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 21px; }

/* ---------- controls ---------- */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { background: #f9fafb; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: #344054; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=search], input[type=datetime-local], select, textarea {
  border: 1px solid #d0d5dd; border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }
.muted { color: var(--muted); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type=search] { max-width: 260px; }
.filters select { width: auto; }

/* ---------- cards & tables ---------- */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; cursor: default; }
.stat.click { cursor: pointer; }
.stat.click:hover { outline: 2px solid var(--brand-soft); }
.stat .n { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stat.alert .n { color: var(--danger); }
.table-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: #f9fafb; white-space: nowrap; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f9fafb; }
tbody tr:last-child td { border-bottom: 0; }
td.check, th.check { width: 34px; cursor: default; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.name-cell b { display: block; }
.name-cell small { color: var(--muted); }
.bulkbar { position: sticky; top: 0; z-index: 5; background: var(--brand-soft); border: 1px solid #c7d7fe; padding: 10px 14px; border-radius: var(--radius); margin-bottom: 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.bulkbar select { width: auto; }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #f2f4f7; color: #344054; white-space: nowrap; }
.st-New { background: var(--brand-soft); color: var(--brand); }
.st-Contacted { background: #f4ebff; color: #6941c6; }
.st-No-answer { background: var(--warn-soft); color: var(--warn); }
.st-Interested { background: #e0f2fe; color: #026aa2; }
.st-Viewing-scheduled { background: #fdf2fa; color: #c11574; }
.st-Negotiation { background: #fff4ed; color: #c4320a; }
.st-Won { background: var(--ok-soft); color: var(--ok); }
.st-Lost { background: #f2f4f7; color: #667085; }
.src { font-size: 12px; color: var(--muted); }
.src-messenger::before { content: "💬 "; }
.src-lead_ad::before { content: "📋 "; }
.src-manual::before { content: "✍️ "; }
.due-over { color: var(--danger); font-weight: 600; }
.due-today { color: var(--warn); font-weight: 600; }
.dup { background: var(--warn-soft); color: var(--warn); }

/* ---------- drawer ---------- */
.overlay { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 50; display: flex; justify-content: flex-end; }
.overlay.center { justify-content: center; align-items: center; padding: 16px; }
.drawer { background: var(--bg); width: min(760px, 100%); height: 100%; overflow-y: auto; box-shadow: -10px 0 30px rgba(0,0,0,.15); }
.drawer-head { background: var(--panel); padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.drawer-head h3 { margin: 0 0 6px; font-size: 19px; }
.drawer-body { padding: 18px 22px; display: grid; gap: 16px; }
.dialog { background: var(--panel); border-radius: 14px; width: min(520px, 100%); max-height: 92vh; overflow-y: auto; padding: 22px; }
.dialog h3 { margin: 0 0 16px; }
.close { background: none; border: 0; font-size: 26px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 4px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }
.quick { display: flex; gap: 8px; flex-wrap: wrap; }
.call-btn { background: var(--ok); color: #fff; border-color: var(--ok); }
.wa-btn { background: #25d366; color: #fff; border-color: #25d366; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { padding: 10px 0; border-bottom: 1px solid var(--line); }
.tl-item:last-child { border-bottom: 0; }
.tl-item .meta { font-size: 12px; color: var(--muted); }
.tl-item.note .txt { background: #fffbea; border: 1px solid #fef0c7; padding: 8px 10px; border-radius: 8px; margin-top: 4px; white-space: pre-wrap; }
.chat { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; padding: 4px; }
.bubble { max-width: 80%; padding: 7px 11px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { background: #f2f4f7; align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble small { display: block; font-size: 11px; opacity: .65; margin-top: 2px; }
.rem { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.rem:last-child { border-bottom: 0; }
.rem.done { opacity: .55; text-decoration: line-through; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); }
.pre { white-space: pre-wrap; }

/* ---------- follow-ups ---------- */
.fu-group h4 { margin: 18px 0 8px; font-size: 14px; }
.fu { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.fu .who { cursor: pointer; }
.fu .who b { display: block; }

/* ---------- toasts ---------- */
#toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.toast { background: #101828; color: #fff; padding: 12px 14px; border-radius: 10px; box-shadow: 0 10px 25px rgba(0,0,0,.25); animation: pop .2s ease-out; }
.toast.err { background: var(--danger); }
.toast.remtoast { background: #fff; color: var(--ink); border-left: 4px solid var(--warn); }
.toast .actions { margin-top: 8px; display: flex; gap: 8px; }
@keyframes pop { from { transform: translateY(10px); opacity: 0; } }
.banner { background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }

/* ---------- mobile ---------- */
.mobile-top { display: none; }
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { display: none; }
  .side.open { display: flex; position: fixed; inset: 0 30% 0 0; z-index: 60; height: 100%; }
  .mobile-top { display: flex; position: sticky; top: 0; z-index: 20; background: #101828; color: #fff; padding: 10px 14px; align-items: center; justify-content: space-between; }
  .mobile-top button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; }
  main { padding: 16px 12px; }
  .grid2 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 100px 1fr; }
  /* lead table → cards */
  table.leads thead { display: none; }
  table.leads, table.leads tbody, table.leads tr, table.leads td { display: block; width: 100%; }
  table.leads tr { border-bottom: 1px solid var(--line); padding: 10px 12px; position: relative; }
  table.leads td { border: 0; padding: 2px 0; }
  table.leads td.check { position: absolute; right: 8px; top: 10px; width: auto; }
  table.leads td.hide-m { display: none; }
  .filters input[type=search] { max-width: none; flex: 1 1 100%; }
  .drawer-head, .drawer-body { padding-left: 14px; padding-right: 14px; }
}
