:root{
  --ink:#18181B; --ink2:#3F3F46; --muted:#5A5A55; --line:#ECEAE4; --bg:#F6F5F0; --card:#fff;
  --accent:#F5D40F; --accent-soft:#FFF7CC; --green:#157347; --red:#B42318; --orange:#9A3412;
  --sat:env(safe-area-inset-top,0px); --sab:env(safe-area-inset-bottom,0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}
html,body{margin:0;background:var(--bg);color:var(--ink)}
body{min-height:100dvh;overscroll-behavior-y:none}
button,input,select,textarea{font:inherit;color:inherit}
button{cursor:pointer}
a{color:inherit}
input,select,textarea{font-size:16px}
#app{display:flex;min-height:100dvh}
.main{flex:1;min-width:0;padding-bottom:calc(70px + var(--sab))}
.side{display:none}
/* top bar */
.top{position:sticky;top:0;z-index:5;background:var(--ink);color:#fff;padding:calc(var(--sat) + 12px) 16px 12px}
.row{display:flex;align-items:center;gap:10px}
.wrap{flex-wrap:wrap}
.grow{flex:1;min-width:0}
.logo{width:32px;height:32px;border-radius:9px;background:var(--accent);color:var(--ink);display:flex;align-items:center;justify-content:center;font-weight:800;font-size:13px;flex:none}
.h1{font-weight:800;font-size:19px}
.sub{font-size:12px;color:#C9C9C4}
.iconbtn{width:44px;height:44px;border:0;background:transparent;border-radius:12px;display:inline-flex;align-items:center;justify-content:center;flex:none;color:inherit}
.iconbtn:active{background:rgba(127,127,127,.15)}
.chips{display:flex;gap:6px;overflow-x:auto;scrollbar-width:none;padding:2px 0}
.chips::-webkit-scrollbar{display:none}
.chip{flex:none;border:1px solid #3F3F46;background:transparent;color:#E4E4E0;border-radius:99px;padding:7px 12px;font-size:13px;font-weight:600;white-space:nowrap}
.chip.on{background:var(--accent);border-color:var(--accent);color:var(--ink);font-weight:700}
.chips.light .chip{border-color:#DDD9CF;color:var(--ink2);background:#fff}
.chips.light .chip.on{background:var(--ink);border-color:var(--ink);color:#fff}
.seg{display:flex;background:#2E2E33;border-radius:10px;padding:3px;gap:3px}
.seg button{flex:1;border:0;background:transparent;color:#D4D4CF;border-radius:8px;padding:7px 8px;font-size:13px;font-weight:700}
.seg button.on{background:#fff;color:var(--ink)}
/* content */
.pad{padding:12px}
.card{background:var(--card);border:1px solid var(--line);border-radius:14px;padding:14px;margin-bottom:10px}
.lead{display:block;width:100%;text-align:left;background:#fff;border:1px solid var(--line);border-radius:14px;padding:12px 14px;margin-bottom:8px}
.lead:active{background:#FFFDF2}
.nm{font-weight:700;font-size:16px}
.muted{color:var(--muted)}
.small{font-size:13px}
.xs{font-size:12px}
.tag{display:inline-block;font-size:11px;font-weight:700;border-radius:6px;padding:2px 7px;white-space:nowrap}
.t-New{background:#E8EEFF;color:#2648B5}.t-Qualified{background:#FEF3C7;color:#7A5A00}.t-Quoted{background:#FFEDD5;color:#9A3412}.t-Booked{background:#DCFCE7;color:#14633A}.t-Lost{background:#F1F0EC;color:#55554F}
.when{font-weight:800;font-size:13px}
.late{color:var(--red)}
.meta{display:flex;flex-wrap:wrap;gap:6px;align-items:center;margin-top:6px;font-size:13px;color:var(--muted)}
.actions{display:flex;gap:8px;margin-top:10px}
.btn{border:1px solid #D6D3CB;background:#fff;border-radius:10px;min-height:42px;padding:0 14px;font-weight:700;font-size:14px;display:inline-flex;align-items:center;justify-content:center;gap:6px;text-decoration:none}
.btn.dark{background:var(--ink);border-color:var(--ink);color:#fff}
.btn.yellow{background:var(--accent);border-color:var(--accent);color:var(--ink)}
.btn.wa{background:#1F8F55;border-color:#1F8F55;color:#fff}
.btn.danger{color:var(--red)}
.btn.block{width:100%;min-height:50px;font-size:15px}
.btn:disabled{opacity:.55}
.stats{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:8px;margin:12px 0 4px}
.stat{background:#2E2E33;border-radius:12px;padding:8px 10px;border:0;text-align:left;color:#fff}
.stat b{display:block;font-size:20px}
.stat span{font-size:11px;color:#C9C9C4}
.stat.red b{color:#FF8A80}
.empty{text-align:center;color:var(--muted);padding:40px 20px;font-size:14px}
.section{font-size:12px;font-weight:800;color:var(--muted);text-transform:uppercase;letter-spacing:.05em;margin:16px 4px 8px}
/* forms */
label.f{display:block;margin-bottom:10px}
label.f span{display:block;font-size:12px;color:var(--muted);font-weight:600;margin-bottom:4px}
.inp{width:100%;border:1px solid #DDD9CF;border-radius:10px;padding:11px 12px;background:#fff;outline:none}
.inp:focus{border-color:var(--ink)}
textarea.inp{min-height:90px;resize:vertical;line-height:1.4}
.grid2{display:grid;grid-template-columns:1fr 1fr;gap:0 10px}
.ai-note{background:var(--accent-soft);border:1px solid #F0DC7A;border-radius:12px;padding:10px 12px;font-size:13px;margin-bottom:12px}
.fld{background:#F6F5F0;border-radius:10px;padding:8px 10px}
.fld .l{font-size:11px;color:var(--muted)}
.fld .v{font-size:14px;font-weight:700;margin-top:1px;word-break:break-word}
.dgrid{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.timeline .it{padding:10px 0;border-top:1px solid #F2F0EA;font-size:14px}
.timeline .it:first-child{border-top:0}
.pre{white-space:pre-wrap;word-break:break-word}
/* photos */
.cats{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px}
.cat{background:#fff;border:1px solid var(--line);border-radius:14px;padding:12px;text-align:left}
.cat.need{border-color:#F5B5AE;background:#FFF6F5}
.pgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(105px,1fr));gap:6px}
.ph{position:relative;aspect-ratio:1;border-radius:10px;overflow:hidden;background:#EEE;border:0;padding:0}
.ph img{width:100%;height:100%;object-fit:cover;display:block}
.ph .ck{position:absolute;top:6px;right:6px;width:24px;height:24px;border-radius:99px;border:2px solid #fff;background:rgba(0,0,0,.25)}
.ph.sel .ck{background:var(--accent);border-color:var(--ink)}
.ph .pr{position:absolute;left:4px;bottom:4px;background:rgba(0,0,0,.6);color:#fff;font-size:11px;border-radius:6px;padding:1px 5px}
/* tabs */
.tabs{position:fixed;left:0;right:0;bottom:0;z-index:10;display:grid;grid-template-columns:repeat(5,1fr);background:#fff;border-top:1px solid var(--line);padding-bottom:var(--sab)}
.tab{border:0;background:#fff;min-height:58px;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:3px;font-size:11px;font-weight:700;color:var(--muted);position:relative}
.tab.on{color:var(--ink);box-shadow:inset 0 3px 0 var(--accent)}
.tab svg{width:22px;height:22px}
.tab.add .plus{width:44px;height:44px;border-radius:14px;background:var(--accent);display:flex;align-items:center;justify-content:center;color:var(--ink)}
.badge{position:absolute;top:6px;left:calc(50% + 6px);background:var(--red);color:#fff;border-radius:99px;min-width:18px;height:18px;font-size:10px;display:flex;align-items:center;justify-content:center;padding:0 5px}
/* sheet + toast */
.scrim{position:fixed;inset:0;background:rgba(0,0,0,.4);opacity:0;pointer-events:none;transition:opacity .2s;z-index:30}
.scrim.show{opacity:1;pointer-events:auto}
.sheet{position:fixed;left:0;right:0;bottom:0;z-index:31;background:#fff;border-radius:20px 20px 0 0;padding:10px 16px calc(var(--sab) + 18px);transform:translateY(105%);transition:transform .25s cubic-bezier(.2,.8,.2,1);max-height:90dvh;overflow-y:auto;max-width:640px;margin:0 auto}
.sheet.show{transform:none}
.grab{width:40px;height:5px;border-radius:99px;background:#D6D3CB;margin:0 auto 12px}
.sh{font-size:18px;font-weight:800;margin-bottom:12px}
.toast{position:fixed;left:50%;bottom:calc(84px + var(--sab));transform:translate(-50%,20px);background:var(--ink);color:#fff;padding:10px 16px;border-radius:12px;font-size:14px;opacity:0;pointer-events:none;transition:all .25s;z-index:40;max-width:90vw;text-align:center}
.toast.show{opacity:1;transform:translate(-50%,0)}
.spin{display:inline-block;width:16px;height:16px;border:2px solid currentColor;border-right-color:transparent;border-radius:99px;animation:sp .7s linear infinite;vertical-align:-3px}
@keyframes sp{to{transform:rotate(360deg)}}
.login{min-height:100dvh;display:flex;align-items:center;justify-content:center;padding:20px;background:var(--ink)}
.login .card{width:100%;max-width:380px;padding:24px}
.sr{position:absolute;left:-9999px}
/* desktop */
@media (min-width:900px){
  .tabs{display:none}
  .main{padding-bottom:20px}
  .side{display:flex;flex-direction:column;gap:4px;width:220px;flex:none;background:var(--ink);color:#fff;padding:18px 12px;position:sticky;top:0;height:100dvh}
  .side .tab{background:transparent;color:#D4D4CF;flex-direction:row;justify-content:flex-start;gap:10px;min-height:44px;padding:0 12px;border-radius:10px;font-size:14px}
  .side .tab.on{background:#2E2E33;color:#fff;box-shadow:none}
  .side .tab.add .plus{width:26px;height:26px;border-radius:8px}
  .side .badge{position:static;margin-left:auto}
  .top{padding-top:16px}
  .pad{padding:16px 24px;max-width:1000px}
  .listgrid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:8px}
  .listgrid .lead{margin:0}
  .toast{bottom:24px}
}
/* ---- v2: stages, inbox, chat, pipeline ---- */
.t-Contacted{background:#E0F2FE;color:#075985}.t-Completed{background:#EDE9FE;color:#5B33C7}
.dot{display:inline-block;width:9px;height:9px;border-radius:99px;background:var(--red)}
.ibx{display:flex;gap:12px;width:100%;text-align:left;background:#fff;border:0;border-bottom:1px solid #F2F0EA;padding:12px 14px}
.ibx:active,.ibx.on{background:#FFFDF2}
.av{width:44px;height:44px;flex:none;border-radius:99px;background:#FDF0B5;display:flex;align-items:center;justify-content:center;font-weight:800;font-size:14px}
.cnt{background:#1F8F55;color:#fff;border-radius:99px;min-width:20px;height:20px;padding:0 6px;font-size:11px;font-weight:800;display:inline-flex;align-items:center;justify-content:center}
.chatwrap{display:flex;flex-direction:column;height:100dvh}
.split{display:flex;height:100dvh}
.split .listcol{display:none}
.msgs{flex:1;overflow-y:auto;background:#EFEDE6;padding:12px;display:flex;flex-direction:column;gap:6px}
.bb{max-width:80%;padding:7px 10px 5px;border-radius:12px;font-size:15px;line-height:1.4;word-wrap:break-word;box-shadow:0 1px 0 rgba(0,0,0,.05)}
.bb.in{align-self:flex-start;background:#fff;border-top-left-radius:4px}
.bb.agent{align-self:flex-end;background:#FFF3B0;border-top-right-radius:4px}
.bb.ai{align-self:flex-end;background:#E8EEFF;border-top-right-radius:4px}
.bb .who{font-size:11px;font-weight:800;color:#2648B5;margin-bottom:2px}
.bb.agent .who{color:#7A5A00}
.bb .mt{font-size:10.5px;color:#6B6B66;text-align:right;margin-top:2px}
.bb img{max-width:100%;border-radius:8px;display:block;margin-bottom:4px}
.sysm{align-self:center;font-size:12px;color:var(--muted);background:#FFF6CC;border:1px solid #F0DC7A;padding:4px 10px;border-radius:8px;text-align:center;max-width:90%}
.dayd{align-self:center;font-size:11px;color:var(--muted);background:#E2DFD5;padding:3px 10px;border-radius:99px}
.composer{background:#fff;border-top:1px solid var(--line);padding:8px 10px calc(var(--sab) + 8px)}
.composer textarea{flex:1;border:1px solid #DDD9CF;border-radius:20px;padding:10px 14px;resize:none;max-height:120px;line-height:1.35;outline:none}
.sendb{width:46px;height:46px;border-radius:99px;border:0;background:var(--accent);display:flex;align-items:center;justify-content:center;flex:none}
.qr{flex:none;border:1px solid #E2DFD5;background:#FAFAF7;border-radius:99px;padding:6px 11px;font-size:13px;font-weight:600}
.banner{padding:10px 12px;font-size:13px;border-radius:10px;margin-bottom:8px}
.pipe{display:flex;gap:10px;overflow-x:auto;padding:12px;align-items:flex-start;min-height:calc(100dvh - 190px)}
.col{flex:0 0 270px;background:#EFEDE6;border-radius:14px;padding:8px;max-height:calc(100dvh - 200px);display:flex;flex-direction:column}
.col.over{outline:2px dashed var(--ink)}
.colh{display:flex;align-items:center;gap:6px;padding:4px 6px 8px;font-weight:800;font-size:14px}
.colb{overflow-y:auto;display:flex;flex-direction:column;gap:6px;min-height:40px}
.pc{background:#fff;border:1px solid var(--line);border-radius:12px;padding:10px;cursor:grab;text-align:left}
.pc select{font-size:12px;padding:4px 6px;border-radius:8px;border:1px solid #DDD9CF;background:#fff;margin-top:6px;width:100%}
@media (min-width:900px){
  .chatwrap,.split{height:100dvh}
  .split .listcol{display:flex;flex-direction:column;width:340px;flex:none;border-right:1px solid var(--line);background:#fff;overflow:hidden}
  .split .listcol .scroll{overflow-y:auto;flex:1}
  .main.chatmode{padding-bottom:0}
}
@media (max-width:899px){ .main.chatmode{padding-bottom:0} body.chatopen .tabs{display:none} }
