:root {
  --green-900: #0f3322;
  --green-800: #14432c;
  --green-700: #1f6b45;
  --green-600: #23804f;
  --green-100: #e3f1e8;
  --green-50:  #f1f8f3;
  --ink:       #15211a;
  --ink-2:     #4b5a52;
  --ink-3:     #7c8a82;
  --line:      #e3e9e5;
  --bg:        #f5f7f5;
  --card:      #ffffff;
  --red:       #c4320a;
  --red-bg:    #fdf0ec;
  --amber:     #b25e09;
  --amber-bg:  #fdf5e7;
  --blue:      #1f5fbf;
  --blue-bg:   #edf3fc;
  --radius:    14px;
  --shadow:    0 1px 2px rgba(16, 40, 27, .06), 0 1px 1px rgba(16, 40, 27, .04);
  --shadow-lg: 0 10px 30px rgba(16, 40, 27, .14);
  --safe-b:    env(safe-area-inset-bottom, 0px);
  --safe-t:    env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--green-700); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-3); }
.muted { color: var(--ink-3); }
.small { font-size: 13px; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; }
.sidebar { display: none; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--green-800); color: #fff;
  padding: calc(var(--safe-t) + 12px) 16px 12px;
  display: flex; align-items: center; gap: 12px;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 700; flex: 1; letter-spacing: -.01em; }
.topbar .back { color: #fff; font-size: 22px; line-height: 1; padding: 4px 8px 4px 0; background: none; border: 0; cursor: pointer; }
.topbar .icon-btn { background: rgba(255,255,255,.12); color: #fff; border: 0; border-radius: 10px; padding: 7px 11px; font-weight: 600; cursor: pointer; }
.main { padding: 16px 14px calc(96px + var(--safe-b)); max-width: 1100px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(6px + var(--safe-b));
}
.tabbar a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; color: var(--ink-3); padding: 4px 0; position: relative;
}
.tabbar a svg { width: 23px; height: 23px; }
.tabbar a.active { color: var(--green-700); }
.tabbar a.add span.plus {
  width: 42px; height: 42px; border-radius: 50%; background: var(--green-700); color: #fff;
  display: grid; place-items: center; margin-top: -2px; box-shadow: var(--shadow-lg);
}
.tabbar a.add svg { width: 22px; height: 22px; }
.badge {
  position: absolute; top: 0; left: 50%; margin-left: 6px;
  background: var(--red); color: #fff; border-radius: 999px; font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px; padding: 0 5px; display: grid; place-items: center;
}

@media (min-width: 820px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; }
  .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 4px;
    position: sticky; top: 0; height: 100vh; background: var(--green-900); color: #cfe3d6; padding: 22px 14px;
  }
  .sidebar .brand { color: #fff; font-weight: 700; font-size: 17px; padding: 0 10px 18px; display: flex; gap: 10px; align-items: center; }
  .sidebar .brand img { width: 30px; height: 30px; border-radius: 8px; }
  .sidebar a {
    color: #cfe3d6; display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; font-weight: 500; position: relative;
  }
  .sidebar a svg { width: 19px; height: 19px; }
  .sidebar a:hover { background: rgba(255,255,255,.06); }
  .sidebar a.active { background: rgba(255,255,255,.12); color: #fff; }
  .sidebar .badge { position: static; margin-left: auto; }
  .sidebar .spacer { flex: 1; }
  .sidebar .me { font-size: 13px; padding: 10px 12px; color: #9fbfab; }
  .sidebar .newbtn { background: var(--green-600); color: #fff; justify-content: center; margin: 4px 0 14px; font-weight: 600; }
  .sidebar .newbtn:hover { background: var(--green-700); }
  .topbar { background: var(--bg); color: var(--ink); padding: 22px 28px 6px; position: static; }
  .topbar h1 { font-size: 24px; }
  .topbar .back { color: var(--ink-2); }
  .topbar .icon-btn { background: #fff; color: var(--ink); border: 1px solid var(--line); }
  .topbar .mobile-only { display: none; }
  .main { padding: 14px 28px 40px; }
}

/* ---------- generic ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.card + .card { margin-top: 12px; }
.pad { padding: 16px; }
.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2);
  margin: 22px 2px 10px;
}
.section-title:first-child { margin-top: 4px; }
.section-title .count { background: var(--line); color: var(--ink-2); border-radius: 999px; padding: 1px 8px; font-size: 12px; letter-spacing: 0; }
.section-title.red { color: var(--red); } .section-title.red .count { background: var(--red-bg); color: var(--red); }
.section-title.amber { color: var(--amber); } .section-title.amber .count { background: var(--amber-bg); color: var(--amber); }
.section-title.green { color: var(--green-700); } .section-title.green .count { background: var(--green-100); color: var(--green-700); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 10px 15px; border-radius: 11px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .12s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:hover { background: #fafcfb; }
.btn.primary { background: var(--green-700); border-color: var(--green-700); color: #fff; }
.btn.primary:hover { background: var(--green-800); }
.btn.claim { background: var(--amber); border-color: var(--amber); color: #fff; }
.btn.danger { color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.sm { padding: 6px 10px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }
.btn[disabled] { opacity: .5; pointer-events: none; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 3px 9px;
  font-size: 12px; font-weight: 600; background: var(--line); color: var(--ink-2); white-space: nowrap;
}
.chip.new { background: var(--amber-bg); color: var(--amber); }
.chip.talking { background: var(--blue-bg); color: var(--blue); }
.chip.offer { background: #f3eefd; color: #6438c2; }
.chip.contract { background: var(--green-100); color: var(--green-700); }
.chip.closed { background: var(--green-700); color: #fff; }
.chip.nurture { background: #eef3f1; color: #4f6b5d; }
.chip.dead { background: #f1f1f1; color: #8a8a8a; }
.chip.red { background: var(--red-bg); color: var(--red); }
.chip.owner { background: var(--green-50); color: var(--green-800); border: 1px solid var(--green-100); }
.chip.unowned { background: var(--amber-bg); color: var(--amber); }

input.field, select.field, textarea.field {
  width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 11px; padding: 10px 12px; outline: none;
}
input.field:focus, select.field:focus, textarea.field:focus { border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(35,128,79,.12); }
textarea.field { resize: vertical; min-height: 80px; }
label.lbl { display: block; font-size: 12px; font-weight: 600; color: var(--ink-2); margin: 0 0 5px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
@media (max-width: 520px) { .grid3 { grid-template-columns: 1fr 1fr; } }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.right { margin-left: auto; }
.stack > * + * { margin-top: 12px; }

/* ---------- lead cards ---------- */
.lead-card {
  display: flex; gap: 12px; align-items: center; padding: 13px 14px; cursor: pointer;
  border-bottom: 1px solid var(--line); background: #fff;
}
.lead-card:last-child { border-bottom: 0; }
.lead-card:hover { background: #fbfcfb; }
.lead-card .avatar {
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--green-50); color: var(--green-700);
}
.lead-card .avatar.hot { background: var(--amber-bg); color: var(--amber); }
.lead-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-card .sub { color: var(--ink-2); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lead-card .meta { display: flex; gap: 6px; margin-top: 5px; flex-wrap: wrap; }
.lead-card .when { font-size: 12px; font-weight: 600; color: var(--ink-3); text-align: right; white-space: nowrap; }
.lead-card .when.red { color: var(--red); }
.lead-card .when.green { color: var(--green-700); }
.list { overflow: hidden; }

.grab {
  background: #fff; border: 1px solid #f3dcb5; border-left: 4px solid var(--amber);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.grab + .grab { margin-top: 10px; }
.grab .msg {
  background: var(--amber-bg); border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: 14px;
  white-space: pre-wrap; max-height: 120px; overflow: hidden;
}

.empty { text-align: center; padding: 28px 16px; color: var(--ink-3); }
.empty b { color: var(--ink-2); display: block; margin-bottom: 4px; font-size: 16px; }

.segmented { display: inline-flex; background: #e8ede9; border-radius: 11px; padding: 3px; }
.segmented button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-weight: 600; font-size: 13px; color: var(--ink-2); cursor: pointer; }
.segmented button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 6px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.stat .n { font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
.stat .l { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.stat.red .n { color: var(--red); }
.stat.amber .n { color: var(--amber); }
@media (max-width: 520px) { .stat { padding: 8px 10px; } .stat .n { font-size: 19px; } .stat .l { font-size: 11px; } }

/* ---------- filters ---------- */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters .field { width: auto; padding: 8px 10px; font-size: 14px; }
.filters .search { flex: 1; min-width: 180px; }

/* ---------- lead page ---------- */
.lead-head h2 { margin: 0; font-size: 22px; letter-spacing: -.01em; }
.lead-head .addr { color: var(--ink-2); margin-top: 2px; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 14px; }
.actions .btn { flex-direction: column; gap: 3px; padding: 10px 6px; font-size: 13px; }
.lead-layout { display: grid; gap: 12px; }
@media (min-width: 820px) {
  .lead-layout { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); align-items: start; }
}
.fu-now { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.fu-now .big { font-size: 18px; font-weight: 700; }
.fu-now .big.red { color: var(--red); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.quick button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 11px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--ink-2); }
.quick button:hover { border-color: var(--green-600); color: var(--green-700); }
.quick button.on { background: var(--green-700); color: #fff; border-color: var(--green-700); }
.stages { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.stages::-webkit-scrollbar { display: none; }
.stages button { flex: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer; }
.stages button.on { background: var(--green-800); color: #fff; border-color: var(--green-800); }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; font-size: 14px; }
.kv dt { color: var(--ink-3); font-weight: 500; }
.kv dd { margin: 0; word-break: break-word; }
.edit-input { border: 1px solid transparent; background: transparent; padding: 3px 6px; margin: -3px -6px; border-radius: 7px; width: calc(100% + 12px); }
.edit-input:hover { background: var(--bg); }
.edit-input:focus { background: #fff; border-color: var(--green-600); outline: none; }
.money { font-variant-numeric: tabular-nums; }
.suggest { font-size: 12px; color: var(--green-700); margin-top: 3px; cursor: pointer; font-weight: 600; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: flex; gap: 10px; padding: 12px 0; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.timeline .dot { width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center; font-size: 14px; background: var(--bg); }
.timeline .dot.conversation { background: var(--amber-bg); }
.timeline .dot.call { background: var(--green-100); }
.timeline .dot.text { background: var(--blue-bg); }
.timeline .body { white-space: pre-wrap; font-size: 14px; word-break: break-word; }
.timeline .who { font-size: 12px; color: var(--ink-3); margin-bottom: 2px; }
.timeline .conversation-box { background: var(--amber-bg); border-radius: 10px; padding: 10px 12px; }
.outcomes { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }

/* ---------- pipeline board ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; scroll-snap-type: x mandatory; }
.col { background: #ebefec; border-radius: var(--radius); padding: 10px; min-height: 200px; scroll-snap-align: start; }
.col.drop { outline: 2px dashed var(--green-600); outline-offset: -4px; }
.col-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; padding: 2px 4px 10px; }
.col-head .sum { margin-left: auto; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.bcard { background: #fff; border-radius: 11px; padding: 10px 11px; box-shadow: var(--shadow); cursor: pointer; border: 1px solid var(--line); }
.bcard + .bcard { margin-top: 8px; }
.bcard .t { font-weight: 600; font-size: 14px; }
.bcard .s { font-size: 12px; color: var(--ink-2); }
.bcard .m { display: flex; gap: 6px; margin-top: 7px; flex-wrap: wrap; align-items: center; }
.bcard.dragging { opacity: .4; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(160deg, var(--green-900), var(--green-700)); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login img { width: 54px; height: 54px; border-radius: 14px; margin-bottom: 14px; }
.login h1 { margin: 0 0 4px; font-size: 22px; }

/* ---------- modal / sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 25, 17, .45); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: #fff; width: 100%; max-width: 520px; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + var(--safe-b)); max-height: 90vh; overflow: auto; }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 18px; } }
.sheet h3 { margin: 0 0 12px; }

#toast {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 80; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (min-width: 820px) { #toast { bottom: 28px; } }

.banner { background: var(--blue-bg); color: var(--blue); border-radius: 12px; padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.banner.amber { background: var(--amber-bg); color: var(--amber); }
.banner .btn { margin-left: auto; }

/* ---------- phone vs computer ---------- */
.desk-only { display: none; }
@media (min-width: 820px) { .phone-only { display: none; } .desk-only { display: block; } }
.table-wrap { overflow-x: auto; }
.ltable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ltable th { text-align: left; font-size: 12px; font-weight: 600; color: var(--ink-3); padding: 11px 14px; cursor: pointer; user-select: none; white-space: nowrap; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; }
.ltable th:hover, .ltable th.on { color: var(--green-700); }
.ltable td { padding: 11px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.ltable tbody tr { cursor: pointer; }
.ltable tbody tr:hover { background: var(--green-50); }
.ltable tbody tr:last-child td { border-bottom: 0; }
.ltable .t { font-weight: 600; }
.ltable .s, .ltable td.s { color: var(--ink-2); font-size: 13px; }
.ltable td.red { color: var(--red); font-weight: 600; }

/* ---------- history tabs + chat ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; border: 0; background: none; padding: 8px 10px 10px; font-weight: 600; font-size: 13px; color: var(--ink-3); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button.on { color: var(--green-800); border-bottom-color: var(--green-700); }
.tabs .n { background: var(--bg); color: var(--ink-2); border-radius: 999px; padding: 0 6px; font-size: 11px; margin-left: 2px; }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 520px; overflow-y: auto; padding: 2px; }
.bubble { max-width: 82%; padding: 9px 12px; border-radius: 16px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.bubble.in { align-self: flex-start; background: #eef1ef; border-bottom-left-radius: 5px; }
.bubble.out { align-self: flex-end; background: var(--green-700); color: #fff; border-bottom-right-radius: 5px; }
.bubble .bwho { font-size: 11px; font-weight: 600; opacity: .7; margin-bottom: 2px; }

.bulkbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: var(--green-800); color: #fff; border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; position: sticky; top: 8px; z-index: 5; }
.bulkbar .field { width: auto; padding: 7px 9px; font-size: 13px; }
.bulkbar .btn.ghost { color: #fff; }
.ltable tr.sel { background: var(--green-50); }
.ltable input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--green-700); cursor: pointer; }
.quick a.btn.sm { border-radius: 999px; }

/* ---------- never wider than the phone screen ---------- */
html, body { overflow-x: hidden; max-width: 100%; }
.shell > div, .main, .card, .grab, .lead-card .grow { min-width: 0; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { min-width: 0; }
.stat .l { overflow-wrap: anywhere; }
.topbar { min-width: 0; }
.topbar h1 { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filters .field { max-width: 100%; }
@media (max-width: 420px) {
  .stats { gap: 6px; }
  .stat { padding: 8px 8px; border-radius: 10px; }
  .stat .n { font-size: 18px; }
  .stat .l { font-size: 10.5px; line-height: 1.25; }
  .main { padding-left: 12px; padding-right: 12px; }
}
