:root {
  --bg: #f3f3f1;
  --panel: #ffffff;
  --ink: #1c1b1f;
  --ink-2: #4d4b55;
  --ink-3: #807e88;
  --line: #e4e3df;
  --hover: rgba(28, 27, 31, 0.04);
  --brand: #5b2bd6;
  --brand-soft: rgba(91, 43, 214, 0.1);
  --hot: #d93025;
  --warm: #e8a317;
  --cold: #7aa7d8;
  --good: #188038;
  --bad: #c5221f;
  --after: #1a73e8;
  --sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --panel: #1b1b1f;
    --ink: #ececf0;
    --ink-2: #b4b3bb;
    --ink-3: #84838c;
    --line: #2d2d33;
    --hover: rgba(236, 236, 240, 0.05);
    --brand: #a17dff;
    --brand-soft: rgba(161, 125, 255, 0.14);
    --good: #4cc38a;
    --after: #6ea8ff;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }

.loading { padding: 40vh 0; text-align: center; color: var(--ink-3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.ghost { border: 1px solid var(--line); background: var(--panel); color: var(--ink); }
.link { padding: 0; border: 0; background: none; color: var(--brand); font-weight: 500; cursor: pointer; text-decoration: none; }
.muted { color: var(--ink-3); }
.error { color: var(--bad); }

/* ---------- sign-in ---------- */

.signin { display: grid; place-items: center; min-height: 100dvh; padding: 20px; }
.signin-card { width: min(380px, 100%); padding: 32px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); text-align: center; }
.signin-card img { border-radius: 12px; }
.signin-card h1 { margin: 16px 0 4px; font-size: 1.3rem; }
.signin-card p { color: var(--ink-2); }
.signin-card .btn { width: 100%; margin-top: 12px; }

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

.app { display: grid; grid-template-columns: 228px 1fr; min-height: 100dvh; }

.nav { position: sticky; top: 0; display: flex; flex-direction: column; gap: 4px; height: 100dvh; padding: 18px 14px; border-right: 1px solid var(--line); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 10px; margin: 0 8px 16px; font-weight: 700; font-size: 1.05rem; }
.brand img { border-radius: 7px; }
.biz-picker { display: grid; gap: 4px; margin: 0 8px 14px; color: var(--ink-3); font-size: 0.78rem; }
.biz-picker select { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font-size: 0.92rem; }
.biz-name { margin: 0 8px 14px; font-weight: 600; font-size: 0.92rem; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 9px; color: var(--ink-2); text-decoration: none; }
.nav a:hover { background: var(--hover); }
.nav a.on { background: var(--brand-soft); color: var(--ink); font-weight: 600; }
.count { min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--brand); color: #fff; font-size: 0.75rem; text-align: center; }
.nav-foot { display: grid; gap: 4px; margin-top: auto; padding: 0 10px; font-size: 0.82rem; color: var(--ink-3); overflow-wrap: anywhere; }
.nav-foot .link { justify-self: start; }

main { min-width: 0; max-width: 1180px; padding: 28px 32px 60px; }

.view-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.view-head h1 { margin: 0; font-size: 1.7rem; font-weight: 700; letter-spacing: -0.01em; }
.sub { margin: 4px 0 0; color: var(--ink-3); font-size: 0.92rem; }

.tile { margin: 0 0 16px; padding: 18px 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.tile h2, .tile legend { margin: 0 0 12px; padding: 0; font-size: 1rem; font-weight: 700; }
.tile-head { display: flex; align-items: baseline; justify-content: space-between; }

.seg { display: inline-flex; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.seg button { padding: 5px 12px; border: 0; border-radius: 7px; background: none; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--brand-soft); color: var(--ink); font-weight: 600; }

/* ---------- overview ---------- */

.away { margin: 0 0 16px; padding: 14px 18px; border-radius: 12px; background: var(--brand-soft); font-weight: 500; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { display: grid; gap: 2px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.kpi span { color: var(--ink-3); font-size: 0.85rem; }
.kpi b { font-size: 2rem; line-height: 1.1; letter-spacing: -0.02em; }
.kpi small { color: var(--ink-3); font-size: 0.8rem; }

.chart { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 4px; }
.bar { display: flex; flex: 1 1 0; flex-direction: column; align-items: stretch; gap: 6px; min-width: 6px; }
.fill { position: relative; display: flex; flex-direction: column; justify-content: flex-end; min-height: 2px; max-height: 160px; border-radius: 4px 4px 0 0; background: var(--brand); overflow: hidden; }
.bar { height: 186px; justify-content: flex-end; }
.fill .after { display: block; width: 100%; background: var(--after); }
.bar small { height: 16px; overflow: hidden; color: var(--ink-3); font-size: 0.7rem; text-align: center; white-space: nowrap; }
.legend { flex-basis: 100%; display: flex; align-items: center; gap: 6px; margin: 10px 0 0; color: var(--ink-3); font-size: 0.8rem; }
.sw { display: inline-block; width: 10px; height: 10px; margin-left: 10px; border-radius: 3px; }
.sw.all { margin-left: 0; background: var(--brand); }
.sw.after { background: var(--after); }

.mini-leads { margin: 0; padding: 0; list-style: none; }
.mini-leads li { border-top: 1px solid var(--line); }
.mini-leads li:first-child { border-top: 0; }
.mini-leads li.muted { padding: 8px 0; }
.mini-leads button { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 12px; width: 100%; padding: 10px 2px; border: 0; background: none; text-align: left; cursor: pointer; }
.mini-leads button:hover { background: var(--hover); }
.mini-leads .who { display: grid; min-width: 0; }
.mini-leads small, .mini-leads time { color: var(--ink-3); font-size: 0.85rem; }

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

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 14px; }
.filters input[type="search"], .filters select, .row select { padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.filters input[type="search"] { flex: 1 1 240px; }
.check { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 0.92rem; font-weight: 400; }

.leads { display: grid; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.leads:empty { display: none; }
.lead {
  display: grid;
  grid-template-columns: 12px minmax(160px, 1.4fr) minmax(130px, 1fr) auto 86px 76px;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 12px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  text-align: left;
  cursor: pointer;
}
.lead:last-child { border-bottom: 0; }
.lead:hover { background: var(--hover); }
.lead.on { background: var(--brand-soft); }
.lead .who { display: grid; min-width: 0; }
.lead .who b, .lead .who small, .lead .contact { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.lead .who b { font-weight: 500; }
.lead.unread .who b { font-weight: 700; }
.lead .who small, .lead .contact, .lead time { color: var(--ink-3); font-size: 0.86rem; }
.lead time { text-align: right; }

.temp { width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.temp-hot { background: var(--hot); }
.temp-warm { background: var(--warm); }
.temp-cold { background: var(--cold); }

.tags { display: flex; gap: 6px; }
.tag { padding: 2px 8px; border-radius: 999px; background: var(--hover); color: var(--ink-2); font-size: 0.75rem; font-style: normal; white-space: nowrap; text-transform: capitalize; }
.tag.good { background: rgba(24, 128, 56, 0.12); color: var(--good); }
.status { justify-self: start; padding: 2px 9px; border-radius: 999px; background: var(--hover); font-size: 0.78rem; text-transform: capitalize; }
.st-new { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.st-won { background: rgba(24, 128, 56, 0.12); color: var(--good); }
.st-lost, .st-archived { color: var(--ink-3); }
.empty { padding: 40px; text-align: center; color: var(--ink-3); }

/* ---------- conversation panel ---------- */

.panel { position: fixed; top: 0; right: 0; bottom: 0; z-index: 10; width: min(460px, 100%); padding: 22px 24px 40px; overflow-y: auto; border-left: 1px solid var(--line); background: var(--panel); box-shadow: -20px 0 50px rgba(0, 0, 0, 0.12); }
.panel header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.panel header h2 { margin: 0; font-size: 1.25rem; }
.panel header p { margin: 0; color: var(--ink-2); }
.panel .close { order: 3; margin-left: auto; border: 0; background: none; font-size: 1.6rem; line-height: 1; color: var(--ink-3); cursor: pointer; }
.panel h3 { margin: 22px 0 6px; font-size: 0.78rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); }
.panel p { margin: 0; }
.contact-block { display: grid; gap: 4px; padding: 12px 14px; border-radius: 12px; background: var(--hover); }
.contact-block a { color: var(--brand); overflow-wrap: anywhere; }
.row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: 14px; }
.row label, .notes { display: grid; gap: 4px; color: var(--ink-3); font-size: 0.82rem; }
.row select { text-transform: capitalize; }
.meta { color: var(--ink-3); font-size: 0.82rem; text-align: right; }
.notes { margin-top: 14px; }
.notes textarea { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); resize: vertical; }
.recording { margin-top: 14px; }
.recording audio { width: 100%; }
.checks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 14px; }
.check-chip { padding: 3px 10px; border-radius: 999px; background: var(--hover); font-size: 0.8rem; }
.check-chip.success { color: var(--good); }
.check-chip.failure { color: var(--bad); }
.transcript { display: flex; flex-direction: column; gap: 8px; }
.bubble { max-width: 88%; padding: 8px 12px; border-radius: 14px; font-size: 0.92rem; overflow-wrap: anywhere; }
.bubble.agent { align-self: flex-start; background: var(--hover); }
.bubble.them { align-self: flex-end; background: var(--brand); color: #fff; }
.event { align-self: center; color: var(--good); font-size: 0.82rem; font-weight: 600; }

/* ---------- business info ---------- */

.profile fieldset.tile { display: grid; gap: 12px; }
.profile label { display: grid; gap: 4px; color: var(--ink-2); font-size: 0.88rem; font-weight: 500; }
.profile label.check { display: inline-flex; }
.profile input:not([type="checkbox"]), .profile textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
  font-weight: 400;
}
.profile input:focus, .profile textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.hint { color: var(--ink-3); font-size: 0.8rem; font-weight: 400; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hours { display: grid; gap: 6px; }
.hours-row { display: grid; grid-template-columns: 110px 130px 130px auto; align-items: center; gap: 10px; }
.hours-row input[type="time"] { padding: 6px 10px; }
.hours-row input:disabled { opacity: 0.4; }
.rowset { display: grid; gap: 8px; }
.row-item { display: grid; grid-template-columns: 1fr 2fr; gap: 8px; }
.offer-row { grid-template-columns: 1.4fr 110px 100px 2fr 28px; align-items: center; }
.offer-row .price { display: flex; flex-direction: row; align-items: center; gap: 4px; color: var(--ink-3); }
.faq-row { grid-template-columns: 1fr 1.6fr 28px; align-items: start; }
.remove { font-size: 1.3rem; line-height: 1; color: var(--ink-3); }
.savebar { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 0; background: linear-gradient(transparent, var(--bg) 30%); }
.savebar input { flex: 1 1 240px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.save-status { color: var(--ink-2); font-size: 0.9rem; }

/* ---------- assistant script ---------- */

.script-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 24px; align-items: start; }
.editor { display: grid; gap: 16px; }
.editor label { display: grid; gap: 6px; font-weight: 600; }
.editor textarea { width: 100%; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); font-weight: 400; line-height: 1.6; resize: vertical; }
#prompt { min-height: 62vh; font-family: var(--mono); font-size: 0.86rem; }
.editor textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.history { position: sticky; top: 20px; padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.history h2 { margin: 0 0 10px; font-size: 1rem; }
.history ol { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; max-height: 70vh; overflow-y: auto; }
.history li { display: grid; gap: 2px; padding-bottom: 10px; border-bottom: 1px solid var(--line); font-size: 0.88rem; }
.history li:last-child { border-bottom: 0; }
.history small { color: var(--ink-3); }

/* ---------- small screens ---------- */

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: static; flex-direction: row; flex-wrap: wrap; align-items: center; height: auto; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand, .biz-name, .biz-picker { margin: 0 10px 0 0; }
  .nav-foot { flex-direction: row; margin: 0 0 0 auto; }
  main { padding: 18px 14px 60px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .lead { grid-template-columns: 12px 1fr auto; }
  .lead .contact, .lead .tags, .lead time { display: none; }
  .script-layout, .two { grid-template-columns: 1fr; }
  .history { position: static; }
  .hours-row { grid-template-columns: 90px 1fr 1fr; }
  .hours-row .check { grid-column: 2 / -1; }
  .offer-row, .faq-row, .row-item { grid-template-columns: 1fr; }
}
