:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a64;
  --line: #e4e1d8;
  --gold: #a87b16;
  --gold-soft: #f5ecd6;
  --ok: #1f7a4d;
  --ok-soft: #e3f3ea;
  --warn: #b4540a;
  --warn-soft: #fdf0e3;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --info-soft: #e7eef9;
  --info: #2c5aa0;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151513;
    --card: #1f1f1c;
    --text: #ecebe6;
    --muted: #a3a197;
    --line: #34332e;
    --gold: #d9a93b;
    --gold-soft: #3a3020;
    --ok: #4fc58a;
    --ok-soft: #1b3326;
    --warn: #f0a050;
    --warn-soft: #3a2a18;
    --bad: #f07064;
    --bad-soft: #3d1f1c;
    --info-soft: #1e2a3d;
    --info: #85a9e0;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
main { max-width: 1240px; margin: 0 auto; padding: 16px; }
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0.4rem 0 1rem; }
h2 { font-size: 1.02rem; margin: 0 0 0.75rem; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem; }
.muted { color: var(--muted); }
.small { font-size: 0.83rem; }
.nowrap { white-space: nowrap; }
.r { text-align: right; }
.pre { white-space: pre-wrap; word-break: break-word; }
.warn { color: var(--warn); }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand span, .login h1 span { color: var(--gold); }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.topbar nav a, .subnav a, .tabs a { padding: 6px 10px; border-radius: 8px; color: var(--text); }
.topbar nav a.on, .subnav a.on, .tabs a.on { background: var(--gold-soft); color: var(--gold); font-weight: 600; }
.topbar nav a:hover, .subnav a:hover, .tabs a:hover { text-decoration: none; background: var(--gold-soft); }
.me { display: flex; gap: 10px; align-items: center; font-size: 0.9rem; }
.me form { margin: 0; }
.subnav, .tabs { display: flex; gap: 4px; flex-wrap: wrap; max-width: 1240px; margin: 0 auto; padding: 10px 16px 0; }
.tabs { padding: 0 0 12px; }

/* Cards & layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card.flush { padding: 0; overflow-x: auto; }
.card.inactive { opacity: 0.6; }
.narrow { max-width: 640px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.grid2 > * { min-width: 0; }
.lead-grid { grid-template-columns: 1.4fr 1fr; }
@media (max-width: 900px) { .grid2, .lead-grid { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack > * { margin: 0; }

/* Forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 0.88rem; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input[type=checkbox] { width: auto; accent-color: var(--gold); }
input[type=file] { padding: 6px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: -1px; }
.fields { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.checks { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin-top: 10px; }
.btn {
  font: inherit; font-weight: 600; cursor: pointer; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
}
.btn:hover { border-color: var(--gold); }
.btn.primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.danger { color: var(--bad); }
.btn:disabled { cursor: default; opacity: 0.9; }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; }
.ok { background: var(--ok-soft); color: var(--ok); padding: 8px 12px; border-radius: 8px; }
.err { background: var(--bad-soft); color: var(--bad); padding: 8px 12px; border-radius: 8px; }
.warnbox { background: var(--warn-soft); color: var(--warn); padding: 8px 12px; border-radius: 8px; margin: 0 0 12px; }

/* Filters */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filters input[type=search] { flex: 1 1 220px; width: auto; }
.filters select { width: auto; flex: 0 1 auto; }

/* Tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); font-weight: 600; }
table.list th, table.list td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list th.r, table.list td.r { text-align: right; }

/* Tiles & pipeline */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; }
.tile .n { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.tile .l { color: var(--muted); font-size: 0.83rem; }
.tile.bad .n { color: var(--bad); }
.tile.good .n { color: var(--ok); }
.pipeline { display: grid; grid-template-columns: repeat(auto-fill, minmax(105px, 1fr)); gap: 8px; }
.stage { display: flex; flex-direction: column; padding: 10px; border-radius: 8px; background: var(--bg); color: var(--text); border-top: 3px solid var(--line); }
.stage:hover { text-decoration: none; border-top-color: var(--gold); }
.stage .n { font-size: 1.3rem; font-weight: 700; }
.stage .l { font-size: 0.8rem; color: var(--muted); }

/* Status pills */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; white-space: nowrap; background: var(--bg); border: 1px solid var(--line); }
.s-new, .s-qualifying { background: var(--info-soft); color: var(--info); border-color: transparent; }
.s-ready, .s-assigned { background: var(--gold-soft); color: var(--gold); border-color: transparent; }
.s-contacted, .s-in_ops, .s-quoted { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.s-booked { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.s-lost, .s-closed_unqualified { color: var(--muted); }
.stage.s-new, .stage.s-qualifying, .stage.s-ready, .stage.s-assigned, .stage.s-contacted,
.stage.s-in_ops, .stage.s-quoted, .stage.s-booked, .stage.s-lost, .stage.s-closed_unqualified { background: var(--bg); color: var(--text); }
.stage.s-booked { border-top-color: var(--ok); }

/* Meters, alerts */
.meter-row { margin-bottom: 12px; }
.meter { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin: 4px 0; border: 1px solid var(--line); }
.meter span { display: block; height: 100%; background: var(--gold); }
.meter.warn span { background: var(--warn); }
.alerts { list-style: none; padding: 0; margin: 0; }
.alerts li { padding: 6px 10px; border-left: 3px solid var(--line); margin-bottom: 6px; }
.alerts .sev-urgent { border-color: var(--bad); }
.alerts .sev-warning { border-color: var(--warn); }

/* Lead page */
.lead-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; margin-bottom: 12px; flex-wrap: wrap; }
.lead-head h1 { margin: 0 0 4px; }
.lead-head .right { text-align: right; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 10px 0 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 560px; overflow-y: auto; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); }
.msg.outbound { align-self: flex-end; background: var(--gold-soft); border-color: transparent; }
.msg.from-bot { background: var(--info-soft); }
.msg .meta { font-size: 0.75rem; color: var(--muted); margin-bottom: 2px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0 6px 14px; border-left: 2px solid var(--line); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--gold); }
.files { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 10px; }
.files img { max-width: 100%; max-height: 220px; border-radius: 8px; border: 1px solid var(--line); }
.pkg-img { max-width: 100%; max-height: 260px; object-fit: contain; border-radius: 8px; border: 1px solid var(--line); }
.price-row { display: grid; grid-template-columns: 1.2fr 1.4fr 1fr 0.6fr 1.4fr auto auto auto; gap: 8px; align-items: center; margin-bottom: 8px; }
@media (max-width: 900px) { .price-row { grid-template-columns: 1fr 1fr; padding-bottom: 10px; border-bottom: 1px solid var(--line); } }

/* Team page cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.lead-card { display: flex; flex-direction: column; gap: 6px; margin: 0; }
.lead-card header { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.lead-card.stuck { border-color: var(--warn); }
.taps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 6px; }
.taps .btn { padding: 10px 4px; font-size: 0.85rem; }
details summary { cursor: pointer; color: var(--gold); margin-top: 4px; }
details form { margin-top: 8px; }
.pager { display: flex; justify-content: center; gap: 16px; padding: 8px; }

/* Login */
.login { max-width: 380px; margin: 10vh auto 0; }
.login h1 { text-align: center; }

@media (max-width: 600px) {
  main { padding: 12px; }
  .topbar { gap: 8px; }
  .topbar nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .topbar nav a { white-space: nowrap; }
  .me { margin-left: auto; }
  table.list.leads th:nth-child(5), table.list.leads td:nth-child(5) { display: none; }
}

.chat-img { max-width: 240px; max-height: 240px; border-radius: 8px; display: block; margin-top: 4px; }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; background: var(--bg); padding: 2px 6px; border-radius: 4px; word-break: break-all; }
.msg.internal { background: transparent; border: 1px dashed var(--gold); align-self: stretch; max-width: 100%; }
.brief { white-space: pre-wrap; word-break: break-word; font: inherit; font-size: 0.88rem; margin: 0; background: var(--bg); padding: 10px; border-radius: 8px; }
.btn.small { padding: 3px 10px; font-size: 0.8rem; font-weight: 500; }
.ok-text { color: var(--ok); }
form.inline { display: inline; margin-left: 6px; }
.row-block { padding: 10px 0; border-bottom: 1px dashed var(--line); }
.row-block:last-child { border-bottom: 0; }
.taps.stages { grid-template-columns: repeat(4, 1fr); }
.quote-row { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; padding: 8px 0; border-bottom: 1px solid var(--line); }
.quote-row .checks { margin-top: 0; }
a.btn { display: inline-block; text-align: center; color: var(--text); }
a.btn:hover { text-decoration: none; }
@media (max-width: 600px) { .taps.stages { grid-template-columns: 1fr 1fr; } }
.msg.draft { border: 1px dashed var(--info); background: var(--info-soft); align-self: stretch; max-width: 100%; margin-top: 8px; }
.composer { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
.badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px; background: var(--bad); color: #fff; font-size: 0.72rem; font-weight: 700; text-align: center; margin-left: 4px; }

/* Phones: a thumb-friendly bottom bar for the screens used all day */
.bottomnav { display: none; }
@media (max-width: 600px) {
  .bottomnav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .bottomnav a { flex: 1; text-align: center; padding: 8px 2px; font-size: 0.8rem; color: var(--muted); border-radius: 8px; }
  .bottomnav a.on { color: var(--gold); font-weight: 700; background: var(--gold-soft); }
  body { padding-bottom: 64px; }
}
