:root {
  --bg: #f6f4f0;
  --surface: #ffffff;
  --surface-2: #fbfaf8;
  --ink: #16181a;
  --ink-2: #4b5157;
  --ink-3: #838b93;
  --line: #e6e2db;
  --graphite: #1b1f1e;
  --graphite-2: #262b2a;
  --accent: #1f6f52;
  --accent-soft: #e8f1ec;
  --accent-ink: #14513c;
  --danger: #a8332a;
  --danger-soft: #fbeae8;
  --warn: #9a6a12;
  --warn-soft: #fdf3e2;
  --info-soft: #eaeff5;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 22, 24, .05), 0 10px 30px -18px rgba(20, 22, 24, .35);
  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
input[type=checkbox], input[type=radio], progress { accent-color: var(--accent); }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; font-weight: 620; letter-spacing: -.015em; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink-3); }

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

.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--graphite);
  color: #d6d9d7;
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; }
.brand-mark { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 14px; }
.brand small { display: block; color: #8d9591; font-weight: 400; font-size: 11.5px; letter-spacing: .02em; }
.nav-group { margin-top: 14px; padding: 0 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: #6f7773; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px; cursor: pointer;
  color: #cdd2cf; font-size: 14.2px; border: 0; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--graphite-2); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .count { margin-left: auto; font-size: 12px; background: rgba(255,255,255,.14); border-radius: 20px; padding: 1px 8px; }
.nav-item.active .count { background: rgba(0,0,0,.2); }
.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid #2e3432; }
.who { display: flex; align-items: center; gap: 10px; padding: 8px 6px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-weight: 650; font-size: 13px; flex: none; }
.who b { color: #fff; font-weight: 560; font-size: 13.5px; display: block; }
.who span { color: #8d9591; font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 18px 26px; border-bottom: 1px solid var(--line);
  background: rgba(246,244,240,.86); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar .spacer { flex: 1; }
.page { padding: 24px 26px 60px; }
.page-narrow { max-width: 1120px; }

/* ---------------------------------------------------------------- atoms */

.btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; font-weight: 520;
  display: inline-flex; align-items: center; gap: 8px; transition: .12s ease;
}
.btn:hover { border-color: #d3cec5; background: #fff; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1a5f47; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: rgba(0,0,0,.04); }
.btn.danger { color: var(--danger); border-color: #eadbd9; background: var(--danger-soft); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.input, .select, textarea.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--surface); outline: none;
}
.input:focus, .select:focus, textarea.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label.field { display: block; margin-bottom: 12px; }
label.field span { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 20px;
  font-size: 12px; font-weight: 520; background: var(--info-soft); color: var(--ink-2); white-space: nowrap;
}
.chip.green { background: var(--accent-soft); color: var(--accent-ink); }
.chip.red { background: var(--danger-soft); color: var(--danger); }
.chip.amber { background: var(--warn-soft); color: var(--warn); }
.chip.grey { background: #eeece8; color: var(--ink-2); }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-size: 13.4px; }
.tab.active { background: var(--graphite); color: #fff; border-color: var(--graphite); }

.stat { padding: 16px 18px; }
.stat .label { font-size: 12.5px; color: var(--ink-3); }
.stat .value { font-size: 27px; font-weight: 640; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .delta { font-size: 12.5px; color: var(--ink-2); margin-top: 2px; }

table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 560; }
.table td { padding: 11px 12px; border-bottom: 1px solid #f0ede8; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr.clickable:hover td { background: var(--surface-2); cursor: pointer; }
.table-wrap { overflow-x: auto; }

.empty { padding: 44px 20px; text-align: center; color: var(--ink-3); }

/* ---------------------------------------------------------------- inbox */

.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr) 330px; height: calc(100vh - 69px); }
.inbox-list { border-right: 1px solid var(--line); overflow-y: auto; background: var(--surface); }
.inbox-filters { padding: 12px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); z-index: 2; }
.conv { padding: 12px 14px; border-bottom: 1px solid #f2efea; cursor: pointer; }
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--accent-soft); }
.conv .line1 { display: flex; align-items: center; gap: 8px; }
.conv .line1 b { font-weight: 570; font-size: 14.2px; }
.conv .prev { color: var(--ink-3); font-size: 12.8px; margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; }
.dot.red { background: var(--danger); }

.thread { display: flex; flex-direction: column; min-width: 0; background: var(--surface-2); }
.thread-head { padding: 12px 18px; border-bottom: 1px solid var(--line); background: var(--surface); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.thread-body { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 74%; padding: 10px 13px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); font-size: 14.2px; white-space: pre-wrap; word-break: break-word; }
.msg .meta { font-size: 11.5px; color: var(--ink-3); margin-top: 6px; }
.msg.in { align-self: flex-start; border-bottom-left-radius: 5px; }
.msg.ai { align-self: flex-end; background: var(--accent-soft); border-color: #d5e6dd; border-bottom-right-radius: 5px; }
.msg.manager { align-self: flex-end; background: var(--graphite); color: #f0f2f1; border-color: var(--graphite); border-bottom-right-radius: 5px; }
.msg.manager .meta { color: #9aa29e; }
.msg.system { align-self: center; background: var(--warn-soft); border-color: #f0e2c8; font-size: 13px; }
.composer { border-top: 1px solid var(--line); background: var(--surface); padding: 12px 16px; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { resize: none; min-height: 42px; max-height: 160px; }
.context { border-left: 1px solid var(--line); overflow-y: auto; background: var(--surface); padding: 16px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 7px 0; border-bottom: 1px dashed #eeeae3; font-size: 13.6px; }
.kv:last-child { border-bottom: 0; }
.kv span { color: var(--ink-3); }

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

.pipeline { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; }
.stage-col { min-width: 246px; width: 246px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; }
.stage-head { padding: 11px 13px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 560; }
.stage-head .count { margin-left: auto; color: var(--ink-3); font-size: 12.5px; }
.stage-body { padding: 10px; display: flex; flex-direction: column; gap: 9px; min-height: 90px; }
.lead-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 11px; background: var(--surface-2); cursor: grab; }
.lead-card:hover { border-color: #d3cec5; }
.lead-card.drag { opacity: .45; }
.stage-col.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }

/* ---------------------------------------------------------------- properties */

.prop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(268px, 1fr)); gap: 16px; }
.prop-card { overflow: hidden; display: flex; flex-direction: column; }
.prop-photo { height: 148px; background: linear-gradient(135deg, #e9e5dd, #d8d3c8); display: grid; place-items: center; color: #9a9386; font-size: 13px; }
.prop-body { padding: 13px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.price { font-size: 18px; font-weight: 650; letter-spacing: -.02em; }

/* ---------------------------------------------------------------- qr / auth */

.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 70% -10%, #e9efe9, var(--bg)); }
.auth-card { width: 100%; max-width: 420px; padding: 28px; }
.auth-card h1 { margin-bottom: 6px; }
.qr-box { display: grid; place-items: center; padding: 16px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.qr-box svg { width: 208px; height: 208px; }
.steps { counter-reset: s; padding: 0; margin: 0; list-style: none; }
.steps li { counter-increment: s; position: relative; padding-left: 30px; margin-bottom: 9px; font-size: 13.8px; color: var(--ink-2); }
.steps li::before { content: counter(s); position: absolute; left: 0; top: 0; width: 21px; height: 21px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-ink); display: grid; place-items: center; font-size: 11.5px; font-weight: 650; }

/* ---------------------------------------------------------------- modal / toast */

.modal-backdrop { position: fixed; inset: 0; background: rgba(22,24,26,.42); display: grid; place-items: center; padding: 20px; z-index: 60; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto; box-shadow: 0 30px 70px -30px rgba(0,0,0,.5); }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 9px; z-index: 80; }
.toast { background: var(--graphite); color: #fff; padding: 11px 15px; border-radius: var(--radius-sm); font-size: 13.6px; box-shadow: var(--shadow); max-width: 340px; }
.toast.err { background: var(--danger); }

/* ---------------------------------------------------------------- bars */

.bar { height: 8px; border-radius: 6px; background: #eeeae3; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); }
.funnel-row { display: grid; grid-template-columns: 190px 1fr 52px; align-items: center; gap: 12px; padding: 5px 0; font-size: 13.6px; }

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

.mobile-only { display: none; }
@media (max-width: 1180px) {
  .inbox { grid-template-columns: 280px minmax(0, 1fr); }
  .context { display: none; }
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; width: 258px; transform: translateX(-100%); transition: transform .18s ease; }
  .sidebar.open { transform: none; }
  .mobile-only { display: inline-flex; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox-list { max-height: 44vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .thread { height: 62vh; }
  .cols-3, .cols-2 { grid-template-columns: 1fr; }
  .page { padding: 16px; }
  .topbar { padding: 14px 16px; }
}
