:root {
  --bg: #f6f5f2; --panel: #ffffff; --ink: #1f2328; --muted: #6b7078; --line: #e3e1dc; --soft: #f0eee9;
  --accent: #a8742a; --accent-ink: #ffffff; --danger: #c2410c;
  --green: #1f8a4c; --green-bg: #e3f4ea; --amber: #a86400; --amber-bg: #fdf0d7; --red: #b42318; --red-bg: #fde7e4;
  --facebook: #3567d6; --google: #1f8a4c; --chatgpt: #0d8f86; --unknown: #8a8f98;
  --radius: 10px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 16px rgba(0,0,0,.06);
  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%236b7078' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171a; --panel: #1d2024; --ink: #e8e6e1; --muted: #9aa0a8; --line: #2d3136; --soft: #24282d;
    --accent: #d4a24c; --accent-ink: #1a1a1a;
    --green: #4cc483; --green-bg: #183626; --amber: #e3a640; --amber-bg: #3a2c12; --red: #f0796b; --red-bg: #3d1d1a;
    --facebook: #7aa2ff; --google: #4cc483; --chatgpt: #3fc9bd; --unknown: #9aa0a8;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239aa0a8' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 36px; }
/* Own chevron for every dropdown: the native one sits flush against the edge. */
select {
  -webkit-appearance: none; appearance: none; cursor: pointer;
  padding-right: 36px;
  background-image: var(--chevron);
  background-repeat: no-repeat; background-position: right 12px center; background-size: 12px 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.btn { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 14px; cursor: pointer; min-height: 36px; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.small { padding: 4px 10px; min-height: 30px; }
.btn.danger { color: var(--danger); }
.link { background: none; border: 0; color: var(--muted); cursor: pointer; text-decoration: underline; padding: 4px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; width: min(360px, 100%); display: grid; gap: 12px; }
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 4px; font-weight: 500; }

/* top bar */
.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.brand b { color: var(--accent); }
.logo { width: 48px; height: 48px; border-radius: 50%; display: block; }
.login-logo { width: 120px; height: 120px; border-radius: 50%; justify-self: center; }
.center { text-align: center; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.active { background: var(--soft); color: var(--ink); }
.me { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.by-1mde { display: flex; align-items: center; margin-left: 8px; padding-left: 14px; border-left: 1px solid var(--line); opacity: .85; }
.by-1mde:hover { opacity: 1; }
.by-1mde img { display: block; height: 20px; width: auto; }
main { padding: 16px 20px 40px; max-width: 1500px; margin: 0 auto; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type=search] { min-width: 240px; flex: 1 1 240px; max-width: 360px; }
.spacer { flex: 1; }
.inline { display: flex; align-items: center; gap: 6px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.chips button.active { border-color: var(--accent); color: var(--accent); }
.alert { background: var(--red-bg); color: var(--red); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-weight: 500; }
.bulk { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--amber-bg); color: var(--amber); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; }

/* table */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; }
table.leads { width: 100%; border-collapse: collapse; }
.leads th, .leads td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.leads th { position: sticky; top: 0; background: var(--soft); font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.leads tbody tr { cursor: pointer; }
.leads tbody tr:hover { background: var(--soft); }
.leads tr.won td { background: var(--green-bg); }
.leads a { color: inherit; }
.leads .name { font-weight: 600; }
.tag { display: inline-block; font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--soft); color: var(--muted); margin-left: 6px; font-weight: 500; }

.src { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
.src::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c, var(--unknown)); }
.src.facebook { --c: var(--facebook); } .src.google { --c: var(--google); } .src.chatgpt { --c: var(--chatgpt); }
.src.unknown { color: var(--muted); }
.stage { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--soft); }
.stage.won { background: var(--green-bg); color: var(--green); }
.stage.lost { color: var(--muted); }
.stage.new { background: var(--red-bg); color: var(--red); }
.stage.booked, .stage.quoted { background: var(--amber-bg); color: var(--amber); }
.speed { font-variant-numeric: tabular-nums; font-weight: 600; padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.speed.g { background: var(--green-bg); color: var(--green); }
.speed.a { background: var(--amber-bg); color: var(--amber); }
.speed.r { background: var(--red-bg); color: var(--red); }

/* board */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 10px; overflow-x: auto; padding-bottom: 8px; }
.col { background: var(--soft); border-radius: var(--radius); padding: 8px; min-height: 300px; display: flex; flex-direction: column; gap: 6px; }
.col.over { outline: 2px dashed var(--accent); }
.col h3 { margin: 2px 4px 6px; font-size: 13px; display: flex; justify-content: space-between; }
.col h3 span { color: var(--muted); font-weight: 500; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; cursor: grab; display: grid; gap: 3px; }
.card:hover { border-color: var(--accent); }
.card .t { font-weight: 600; }
.card .s { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }
.more { font-size: 12px; }

/* dashboard */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.kpi .v { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--muted); font-size: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; overflow-x: auto; }
.panel h2 { font-size: 15px; margin: 0 0 10px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
table.t { border-collapse: collapse; width: 100%; }
.t th, .t td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.t th:first-child, .t td:first-child { text-align: left; }
.t th { font-size: 12px; color: var(--muted); font-weight: 600; }
.t tr.total td { font-weight: 700; border-bottom: 0; }
.funnel { display: grid; gap: 6px; }
.frow { display: grid; grid-template-columns: 110px 1fr 70px; gap: 10px; align-items: center; }
.fbar { height: 22px; background: var(--soft); border-radius: 4px; overflow: hidden; display: flex; }
.fbar i { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; margin-top: 8px; }
.weeks { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding-top: 8px; }
.week { flex: 1; display: flex; flex-direction: column-reverse; min-width: 10px; gap: 1px; position: relative; }
.week i { display: block; border-radius: 2px; }
.week:hover::after { content: attr(data-tip); position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); font-size: 11px; padding: 4px 6px; border-radius: 4px; white-space: pre; z-index: 2; }
.wk-labels { display: flex; gap: 4px; font-size: 10px; color: var(--muted); }
.wk-labels span { flex: 1; text-align: center; min-width: 10px; overflow: hidden; }

/* drawer */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 9; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--panel); z-index: 10; box-shadow: var(--shadow); overflow-y: auto; }
.drawer-inner { padding: 18px 20px 40px; display: grid; gap: 16px; }
.dh { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.dh h2 { margin: 0; font-size: 20px; }
.contact { display: flex; gap: 12px; flex-wrap: wrap; }
.contact a { color: var(--accent); font-weight: 600; text-decoration: none; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form label { display: grid; gap: 3px; font-size: 12px; color: var(--muted); font-weight: 500; }
.form label.full { grid-column: 1 / -1; }
.form .check { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.form .check input { min-height: 0; width: 18px; height: 18px; }
.quiz { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; background: var(--soft); border-radius: 8px; padding: 10px 12px; }
.quiz dt { color: var(--muted); }
.quiz dd { margin: 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; margin: 0 0 6px; }
.note-form { display: flex; gap: 8px; }
.note-form textarea { flex: 1; min-height: 60px; resize: vertical; }
.acts { display: grid; gap: 8px; }
.act { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; }
.act.note { border-color: var(--accent); }
.act .m { font-size: 12px; color: var(--muted); }
.act .x { white-space: pre-wrap; word-break: break-word; }
.sheet-notes { background: var(--amber-bg); border-radius: 8px; padding: 8px 12px; white-space: pre-wrap; }

.setup { display: grid; gap: 16px; max-width: 900px; }
.setup code, .setup pre { background: var(--soft); border-radius: 6px; padding: 2px 6px; font: 12.5px ui-monospace, Menlo, monospace; }
.setup pre { padding: 12px; overflow-x: auto; white-space: pre; }
.hookrow { display: grid; grid-template-columns: 140px 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.hookrow code { overflow-wrap: anywhere; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 20; }

@media (max-width: 720px) {
  .topbar { padding: 10px 16px; }
  main { padding: 12px 16px 40px; }
  .me { margin-left: 0; }
  .form { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .hookrow { grid-template-columns: 1fr; }
  .toolbar input[type=search] { max-width: none; }
}

/* team */
.pw-box { background: var(--green-bg); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.pw-box p { margin: 4px 0; }
.pw-box code { font-size: 14px; background: var(--panel); padding: 2px 8px; border-radius: 4px; }
.leads tr.off td { color: var(--muted); }
.leads td.actions { display: flex; gap: 6px; align-items: center; }
.leads td select { min-height: 30px; padding-top: 3px; padding-bottom: 3px; }
#me-role { text-transform: capitalize; }
