:root {
  --bg: #f4f6f5;
  --panel: #ffffff;
  --ink: #17201d;
  --muted: #5f6b67;
  --line: #e1e6e4;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f2ef;
  --ok: #15803d;
  --ok-soft: #e4f4e8;
  --warn: #b45309;
  --warn-soft: #fbf0dd;
  --bad: #b91c1c;
  --bad-soft: #fbe4e4;
  --info: #1d4ed8;
  --info-soft: #e3eafc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 22, 0.06), 0 1px 1px rgba(16, 24, 22, 0.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1413;
    --panel: #171e1c;
    --ink: #e7eeeb;
    --muted: #94a19c;
    --line: #2a3431;
    --accent: #2bb3a3;
    --accent-ink: #062320;
    --accent-soft: #143430;
    --ok: #4ade80;
    --ok-soft: #13301d;
    --warn: #fbbf24;
    --warn-soft: #33270e;
    --bad: #f87171;
    --bad-soft: #3a1717;
    --info: #93b4ff;
    --info-soft: #18233d;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* layout */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 10px 18px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 16px; height: 16px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--ink);
}
.nav a:hover { background: var(--bg); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-foot { margin-top: auto; padding: 10px; font-size: 13px; color: var(--muted); }
.main { padding: 28px 32px 60px; max-width: 1100px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* forms */
label { display: block; font-weight: 600; font-size: 13px; margin: 0 0 6px; }
.field { margin-bottom: 16px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 5px; }
input[type=text], input[type=password], input[type=datetime-local], input[type=date], input[type=tel], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel); color: var(--ink); font: inherit;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; gap: 8px; align-items: center; font-weight: 400; font-size: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink); font: inherit; font-weight: 600; cursor: pointer;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); color: var(--ink); padding: 7px 14px; font: inherit; cursor: pointer; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--bg); }
.empty { padding: 26px; text-align: center; color: var(--muted); }

/* badges & progress */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-bad { background: var(--bad-soft); color: var(--bad); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-muted { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.progress { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; min-width: 90px; }
.progress > div { height: 100%; background: var(--accent); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { background: var(--bg); border-radius: 8px; padding: 12px; }
.stat b { display: block; font-size: 22px; }
.stat span { font-size: 12px; color: var(--muted); }

/* whatsapp card */
.wa { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.wa-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.qr { background: #fff; padding: 10px; border-radius: 10px; border: 1px solid var(--line); }
.qr img { display: block; width: 240px; height: 240px; }
.steps { margin: 0; padding-left: 18px; color: var(--muted); }

.bubble { white-space: pre-wrap; background: var(--accent-soft); padding: 12px 14px; border-radius: 10px; max-width: 520px; }
.note { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 14px; margin-bottom: 14px; }
.note.info { background: var(--info-soft); color: var(--info); }
.drop { border: 2px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; color: var(--muted); }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: 100%; max-width: 380px; }

/* toast & modal */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 50; max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; padding: 16px; z-index: 40; }
.modal .card { width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; margin: 0; }
.list-box { max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 14px; margin: 8px 0 14px; }

@media (max-width: 800px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { padding: 4px 6px; width: 100%; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .side-foot { margin-top: 0; width: 100%; padding: 6px 6px 2px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
  .main { padding: 18px 16px 50px; }
  .grid2, .stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

input.num { width: 84px; text-align: center; }

/* SaaS additions */
.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar { background: var(--accent-soft); color: var(--text); padding: 10px 32px; font-size: 14px; border-bottom: 1px solid var(--line); }
.topbar.warn { background: #fff4e0; color: #7a4a00; }
.topbar.bad { background: #fde8e8; color: #8a1c1c; }
.biz-name { font-size: 13px; color: var(--muted); padding: 0 10px 10px; margin-top: -4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; }
.usage-main { flex: 1 1 260px; }
.usage-num { font-size: 15px; margin: 2px 0 8px; }
.usage-num b { font-size: 24px; }
.usage-facts { display: grid; grid-template-columns: repeat(4, auto); gap: 6px 22px; }
.usage-facts div { display: flex; flex-direction: column; gap: 2px; }
.progress.hot > div { background: var(--bad); }
.stats.stats5 { grid-template-columns: repeat(5, 1fr); }
.grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2col > .card { margin-bottom: 18px; }
table.mini td { padding: 6px 4px; font-size: 14px; }
h3.sub { font-size: 14px; margin: 18px 0 10px; padding-top: 14px; border-top: 1px solid var(--line); }
@media (prefers-color-scheme: dark) {
  .topbar.warn { background: #3a2a10; color: #f3c77a; }
  .topbar.bad { background: #3a1616; color: #f3a3a3; }
}
@media (max-width: 800px) {
  .topbar { padding: 10px 16px; }
  .usage-facts { grid-template-columns: repeat(2, auto); }
  .stats.stats5 { grid-template-columns: 1fr 1fr; }
  .grid-2col { grid-template-columns: 1fr; gap: 0; }
}
.note.bad { background: #fde8e8; border-color: #f3b4b4; color: #8a1c1c; }
@media (prefers-color-scheme: dark) { .note.bad { background: #3a1616; border-color: #6b2525; color: #f3a3a3; } }

/* ---------- CRM ---------- */
.main.wide { max-width: 1400px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.tag.t-teal { background: #dff3ef; color: #0f6a62; }
.tag.t-blue { background: #e2ecfb; color: #1d4f9a; }
.tag.t-green { background: #e3f4e1; color: #2d6a1f; }
.tag.t-amber { background: #fdf0d6; color: #8a5a00; }
.tag.t-red { background: #fde2e2; color: #9b1c1c; }
.tag.t-purple { background: #eee5fb; color: #5b2a9a; }
.tag.t-pink { background: #fbe4f0; color: #9a2463; }
.tag.t-gray { background: #eceeed; color: #4b5552; }
@media (prefers-color-scheme: dark) {
  .tag { filter: saturate(.9); }
  .tag.t-teal { background: #143a35; color: #8fe0d4; } .tag.t-blue { background: #172a47; color: #9cc0f5; }
  .tag.t-green { background: #1a3317; color: #a6dc97; } .tag.t-amber { background: #3a2c10; color: #f3c77a; }
  .tag.t-red { background: #3a1616; color: #f3a3a3; } .tag.t-purple { background: #2a1c40; color: #c9a9f5; }
  .tag.t-pink { background: #3a1729; color: #f3a6cd; } .tag.t-gray { background: #262d2b; color: #b5bfbb; }
}
.count { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 99px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; text-align: center; line-height: 18px; }
.nav a .count { margin-left: 4px; }
.filters { margin-bottom: 12px; }
.bulk { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 12px; margin-bottom: 10px; border-radius: 8px; background: var(--accent-soft); }
.small-select { width: auto; max-width: 170px; padding: 4px 8px; font-size: 13px; }
table.contacts td { vertical-align: middle; }
.tag-pick { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-opt { display: inline-flex; align-items: center; gap: 5px; font-weight: 400; cursor: pointer; }
.tag-row { padding: 6px 0; border-bottom: 1px solid var(--line); }
.kv td:first-child { width: 40%; }
.frow { margin-bottom: 6px; flex-wrap: nowrap; }
.deal-line { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.deal-line:last-child { border-bottom: 0; }

/* chat bubbles */
.thread { display: flex; flex-direction: column; gap: 6px; padding: 14px; overflow-y: auto; }
.mini-thread { padding: 0; max-height: 320px; }
.msg { max-width: 78%; display: flex; flex-direction: column; }
.msg .b { padding: 8px 11px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.4; }
.msg.in { align-self: flex-start; }
.msg.in .b { background: var(--panel); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.out .b { background: #d9f5e9; color: #0d3b2e; border-top-right-radius: 4px; }
.msg .meta { font-size: 11px; color: var(--muted); margin: 2px 4px 0; }
.msg .kind { font-size: 12px; font-weight: 600; opacity: .8; margin-bottom: 2px; }
@media (prefers-color-scheme: dark) { .msg.out .b { background: #14463a; color: #d8f5ea; } }

/* inbox */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr); height: calc(100vh - 88px); min-height: 480px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); overflow: hidden; }
.chats { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chats-head { padding: 14px; display: flex; flex-direction: column; gap: 10px; border-bottom: 1px solid var(--line); }
.clist { overflow-y: auto; flex: 1; }
.chat-item { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.chat-item:hover { background: var(--bg); text-decoration: none; }
.chat-item.on { background: var(--accent-soft); }
.chat-item .row { flex-wrap: nowrap; gap: 6px; }
.cname, .cprev { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.thread-pane { display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.thread-pane > .empty { margin: auto; text-align: center; }
.thread-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.thread-pane .thread { flex: 1; }
.composer { display: flex; gap: 8px; padding: 10px 14px 4px; background: var(--panel); border-top: 1px solid var(--line); }
.composer textarea { min-height: 44px; height: 44px; max-height: 140px; resize: vertical; }
.composer-note { padding: 0 14px 10px; background: var(--panel); }
.back-link { display: none; font-size: 20px; text-decoration: none; }
@media (max-width: 800px) {
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 150px); }
  .inbox.has-open .chats { display: none; }
  .inbox:not(.has-open) .thread-pane { display: none; }
  .back-link { display: inline; }
  .msg { max-width: 90%; }
}

/* pipeline board */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { flex: 0 0 250px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 190px); }
.col.won { border-top: 3px solid var(--ok); }
.col.lost { border-top: 3px solid var(--muted); }
.col.open { border-top: 3px solid var(--accent); }
.col.over { outline: 2px dashed var(--accent); outline-offset: -4px; }
.col-head { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.col-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 60px; }
.col-empty { text-align: center; padding: 14px 0; }
.deal { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; cursor: grab; display: flex; flex-direction: column; gap: 2px; }
.deal:hover { border-color: var(--accent); }
.deal.dragging { opacity: .5; }
.cres { margin-top: 6px; border-radius: 8px; overflow: hidden; }
.cres-item { padding: 7px 10px; cursor: pointer; border: 1px solid var(--line); border-top: 0; }
.cres-item:first-child { border-top: 1px solid var(--line); border-radius: 8px 8px 0 0; }
.cres-item:hover { background: var(--accent-soft); }
.picked { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; }
.stage-row { margin-bottom: 6px; flex-wrap: nowrap; }

/* ---------- Settings + placeholder picker ---------- */
.settings-tabs { display: inline-flex; }
.btn.tiny { padding: 1px 7px; font-size: 12px; min-height: 0; }
.nowrap { white-space: nowrap; }
code.copy { cursor: pointer; }
code.copy:hover { outline: 1px dashed var(--accent); }
.value-cell { max-width: 360px; white-space: pre-wrap; word-break: break-word; }
.code-preview code { font-size: 14px; }
.color-pick { display: flex; flex-wrap: wrap; gap: 10px; }
.field > .picker-btn { margin-bottom: 6px; }
.picker-btn { position: relative; }
.field, .composer-note { position: relative; }
.picker-pop { position: absolute; z-index: 60; left: 0; top: 34px; width: 330px; max-width: calc(100vw - 40px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 8px; }
.composer-note .picker-pop { top: auto; bottom: 100%; }
.pk-search { margin-bottom: 6px; }
.pk-list { max-height: 300px; overflow-y: auto; }
.pk-group { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 6px 4px; }
.pk-item { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 6px; cursor: pointer; color: inherit; font: inherit; font-size: 14px; }
.pk-item:hover { background: var(--accent-soft); }
.pk-item code { font-size: 12px; }
.pk-sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-manage { display: block; padding: 8px 6px 2px; }
.composer-note { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.nowrap-head { flex-wrap: nowrap; align-items: flex-start; }
@media (max-width: 600px) { .nowrap-head { flex-wrap: wrap; } }
