:root {
  --accent: #263a7c;
  --gold: #c9a86f;
  --bg: #ecedf3;
  --card: #ffffff;
  --ink: #1b1f2e;
  --ink2: #5b6176;
  --line: #dfe1ea;
  --in: #ffffff;
  --out: #e4e9f8;
  --hot: #c4402f;
  --warm: #c98a1a;
  --cold: #4b7bb5;
  --ok: #1f8a5b;
  --bad: #c4402f;
  --r: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--ink2); text-align: center; gap: 12px; }
.muted { color: var(--ink2); }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand b { display: block; font-size: 17px; }
.brand small { display: block; color: var(--ink2); font-size: 12.5px; }
.brand small.off { color: var(--bad); }
.brand.small b { font-size: 15.5px; }
.logo { width: 38px; height: 38px; border-radius: 11px; background: var(--accent); color: var(--gold);
  display: grid; place-items: center; font-weight: 700; font-size: 18px; flex: none; }
.logo.big { width: 64px; height: 64px; font-size: 30px; border-radius: 18px; opacity: .9; }

/* ---------- buttons ---------- */
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px 16px; font-weight: 600; font-size: 15.5px; cursor: pointer; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:disabled { opacity: .6; }
.btn.ghost { background: transparent; color: var(--accent); }
.iconbtn { border: 0; background: transparent; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  cursor: pointer; color: var(--ink); flex: none; text-decoration: none; }
.iconbtn:active { background: var(--bg); }

/* ---------- login ---------- */
#app.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: 100%; max-width: 380px; background: var(--card); border-radius: 20px; padding: 28px 22px; box-shadow: 0 10px 40px #1b1f2e14; }
.login-card .brand { margin-bottom: 24px; }
.login-card form { display: grid; gap: 10px; }
.login-card label { font-weight: 600; font-size: 14px; }
.login-card input { border: 1.5px solid var(--line); border-radius: 12px; padding: 14px; font-size: 16px; }
.login-card input:focus { outline: none; border-color: var(--accent); }
#code { letter-spacing: .4em; text-align: center; font-size: 22px; font-weight: 600; }
.hint { color: var(--ink2); font-size: 13.5px; line-height: 1.45; margin: 0 0 6px; }
.err { color: var(--bad); font-size: 14px; }
.foot { color: var(--ink2); font-size: 13px; text-align: center; margin: 22px 0 0; line-height: 1.6; }

/* ---------- shell ---------- */
#app.shell { height: 100vh; height: 100dvh; display: grid; grid-template-columns: 100%; overflow: hidden; }
.pane { min-height: 0; display: flex; flex-direction: column; background: var(--card); }
.pane.chat { display: none; background: var(--bg); }
#app.show-chat .pane.inbox { display: none; }
#app.show-chat .pane.chat { display: flex; }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--card); min-height: 62px; position: relative; }
.bar .brand { flex: 1; }

/* ---------- inbox ---------- */
.searchbox { margin: 10px 12px 4px; display: flex; align-items: center; gap: 8px; background: var(--bg); border-radius: 12px; padding: 0 12px; color: var(--ink2); }
.searchbox svg { width: 18px; height: 18px; }
.searchbox input { flex: 1; border: 0; background: transparent; padding: 11px 0; font-size: 15px; outline: none; }
.chips { display: flex; gap: 8px; padding: 8px 12px 10px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1.5px solid var(--line); background: var(--card); border-radius: 999px; padding: 7px 13px; font-size: 14px; font-weight: 500; white-space: nowrap; cursor: pointer; }
.chip span { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--bg); font-size: 12px; font-weight: 600; margin-left: 2px; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.on span { background: #ffffff2b; }
.list { list-style: none; margin: 0; padding: 0 0 var(--safe-b); overflow-y: auto; flex: 1; }
.list .empty { text-align: center; color: var(--ink2); padding: 48px 20px; }
.row { display: flex; gap: 12px; padding: 12px 14px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.row:active, .row.active { background: #f3f4f9; }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: #dfe4f3; color: var(--accent); font-weight: 600; display: grid; place-items: center; flex: none; font-size: 15px; }
.avatar.sm { width: 38px; height: 38px; font-size: 13.5px; }
.mid { flex: 1; min-width: 0; display: grid; gap: 3px; }
.l1, .l2 { display: flex; align-items: center; gap: 8px; min-width: 0; }
.name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 15.5px; }
.l1 time { color: var(--ink2); font-size: 12.5px; flex: none; }
.row.unread .l1 time { color: var(--accent); font-weight: 600; }
.prev { flex: 1; min-width: 0; color: var(--ink2); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .prev { color: var(--ink); font-weight: 500; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; min-width: 22px; height: 22px; padding: 0 7px; font-size: 12px; font-weight: 700; display: grid; place-items: center; flex: none; }
.l3 { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-height: 0; }
.l3:empty { display: none; }
.tag { font-size: 11.5px; font-weight: 600; border-radius: 6px; padding: 2px 7px; background: var(--bg); color: var(--ink2); }
.tag.hot { background: #fbe4e0; color: var(--hot); }
.tag.warm { background: #fbefd9; color: #9c6a10; }
.tag.cold { background: #e2ecf8; color: var(--cold); }
.tag.ad { background: #f3ecdf; color: #7a5d27; }
.tag.wait { background: #e8f2ec; color: var(--ok); }
.tag.wait.late { background: #fbe4e0; color: var(--hot); }
.who { font-size: 12px; color: var(--ink2); margin-left: auto; }

/* ---------- chat ---------- */
.placeholder { flex: 1; display: grid; place-items: center; align-content: center; gap: 14px; color: var(--ink2); }
.chathead { gap: 4px; padding-left: 4px; }
.who-btn { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; border: 0; background: transparent; text-align: left; cursor: pointer; padding: 4px; border-radius: 10px; }
.who-btn b { display: block; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-btn small { display: block; color: var(--ink2); font-size: 12.5px; }
.who-btn > span:last-child { min-width: 0; }
.assignbar { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: #f7f3ea; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.assignbar label { color: #7a5d27; font-weight: 600; }
.assignbar select { flex: 1; border: 1px solid var(--line); border-radius: 9px; padding: 7px 9px; background: #fff; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.loading { text-align: center; color: var(--ink2); padding: 30px; font-size: 14px; }
.day { text-align: center; margin: 10px 0 6px; }
.day span { background: #dfe1ea; color: var(--ink2); font-size: 12px; font-weight: 500; padding: 4px 10px; border-radius: 8px; }
.adcard { display: flex; gap: 10px; align-items: flex-start; background: #f7f3ea; border: 1px solid #ebdfc6; border-radius: 12px; padding: 10px 12px; margin: 0 auto 8px; max-width: 92%; color: #7a5d27; }
.adcard small { display: block; font-size: 11.5px; }
.adcard b { display: block; font-size: 14px; color: var(--ink); }
.adcard p { margin: 4px 0 0; font-size: 13px; color: var(--ink2); }
.bubble { max-width: min(80%, 520px); padding: 8px 10px 5px; border-radius: 14px; font-size: 15px; line-height: 1.42; box-shadow: 0 1px 1px #1b1f2e0f; word-wrap: break-word; overflow-wrap: anywhere; }
.bubble.in { background: var(--in); align-self: flex-start; border-top-left-radius: 4px; }
.bubble.out { background: var(--out); align-self: flex-end; border-top-right-radius: 4px; }
.bubble.failed { background: #fbe4e0; }
.bubble .txt a { word-break: break-all; }
.meta { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11.5px; color: var(--ink2); margin-top: 2px; }
.meta .by { font-weight: 600; color: var(--accent); }
.tick { font-weight: 700; letter-spacing: -2px; }
.tick.read { color: #2f7de1; }
.tick.failed { color: var(--bad); letter-spacing: 0; }
.fail { color: var(--bad); font-size: 12.5px; margin-top: 3px; }
.mediabox { min-width: 200px; min-height: 60px; display: grid; place-items: center; background: #f0f1f6; border-radius: 10px; margin-bottom: 4px; overflow: hidden; font-size: 13px; }
.mediabox img, .mediabox video { display: block; max-width: 100%; max-height: 340px; border-radius: 10px; cursor: zoom-in; }
.mediabox audio { width: 240px; }
.docbtn { display: flex; gap: 8px; align-items: center; border: 0; background: #f0f1f6; border-radius: 10px; padding: 10px 12px; cursor: pointer; margin-bottom: 4px; text-align: left; }
.banner { margin: 0 10px 8px; padding: 10px 12px; border-radius: 12px; background: #f0f1f6; font-size: 13.5px; line-height: 1.45; color: var(--ink2); }
.banner.warn { background: #fbefd9; color: #6d4b0c; }
.banner.soft { background: #e8f2ec; color: #18603f; padding: 7px 12px; }
#composer { padding-bottom: var(--safe-b); background: var(--bg); }
#composer:has(.banner.warn) { padding-bottom: calc(var(--safe-b) + 10px); }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px 10px; }
.composer textarea { flex: 1; resize: none; border: 0; border-radius: 22px; padding: 12px 16px; font-size: 16px; line-height: 1.35; background: #fff; max-height: 140px; outline: none; box-shadow: 0 1px 2px #1b1f2e12; }
.sendbtn { width: 46px; height: 46px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.sendbtn svg { width: 20px; height: 20px; fill: currentColor; stroke: none; }

/* ---------- menus ---------- */
.menu { position: absolute; z-index: 40; background: var(--card); border-radius: 14px; box-shadow: 0 12px 40px #1b1f2e26; padding: 6px; min-width: 240px; }
#me-menu { position: fixed; top: 60px; left: 12px; }
.chatmenu { right: 10px; top: 56px; }
.menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 12px; border-radius: 10px; cursor: pointer; font-size: 14.5px; }
.menu button:hover { background: var(--bg); }
.menu .danger { color: var(--bad); }
.menu .me { padding: 10px 12px 8px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu .me small { display: block; color: var(--ink2); font-size: 12.5px; }
.menu .ver { display: block; color: var(--ink2); font-size: 11px; padding: 4px 12px; }

/* ---------- lead panel (sheet di HP) ---------- */
.pane.lead { position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; max-height: 86vh; border-radius: 20px 20px 0 0;
  transform: translateY(105%); transition: transform .25s ease; box-shadow: 0 -10px 40px #1b1f2e22; }
.pane.lead.open { transform: none; }
.pane.lead .bar { border-radius: 20px 20px 0 0; }
.pane.lead .bar b { flex: 1; font-size: 16px; padding-left: 4px; }
.sheet-backdrop { position: fixed; inset: 0; background: #1b1f2e55; z-index: 45; opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet-backdrop.on { opacity: 1; pointer-events: auto; }
.leadbody { overflow-y: auto; padding: 14px 16px calc(24px + var(--safe-b)); display: grid; gap: 12px; }
.leadbody label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink2); }
.leadbody input, .leadbody select, .leadbody textarea { border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 15px; font-weight: 400; color: var(--ink); background: #fff; }
.leadbody input:focus, .leadbody select:focus, .leadbody textarea:focus { outline: none; border-color: var(--accent); }
.leadbody .ro { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; }
.leadbody .ro span { color: var(--ink2); }
.leadbody .ro b { text-align: right; font-weight: 500; }
.labels { border: 0; padding: 0; margin: 0; display: flex; gap: 8px; }
.labels legend { font-size: 13px; font-weight: 600; color: var(--ink2); margin-bottom: 6px; padding: 0; }
.lab { flex: 1; border: 1.5px solid var(--line); background: #fff; border-radius: 10px; padding: 10px 0; font-weight: 600; cursor: pointer; }
.lab.hot.on { background: var(--hot); border-color: var(--hot); color: #fff; }
.lab.warm.on { background: var(--warm); border-color: var(--warm); color: #fff; }
.lab.cold.on { background: var(--cold); border-color: var(--cold); color: #fff; }
.saved { font-size: 12.5px; margin: 0; min-height: 16px; }
.saved.ok { color: var(--ok); } .saved.bad { color: var(--bad); }
.leadbody h4 { margin: 8px 0 0; font-size: 13px; color: var(--ink2); }
.acts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; font-size: 13.5px; }
.acts time { color: var(--ink2); font-size: 12px; margin-right: 6px; }

/* ---------- toast ---------- */
#toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translate(-50%, 20px); background: #1b1f2e; color: #fff;
  padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 99; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); } #toast.ok { background: var(--ok); }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  #app.shell { grid-template-columns: 380px 1fr 340px; }
  .pane.inbox { border-right: 1px solid var(--line); }
  .pane.chat, #app.show-chat .pane.chat { display: flex; }
  #app.show-chat .pane.inbox { display: flex; }
  .chathead .back { display: none; }
  .chathead { padding-left: 12px; }
  .pane.lead { position: static; transform: none; max-height: none; border-radius: 0; box-shadow: none; border-left: 1px solid var(--line); transition: none; }
  .pane.lead .bar { border-radius: 0; }
  .pane.lead .closebtn { display: none; }
  .sheet-backdrop { display: none; }
  #toast { bottom: 28px; }
}
@media (min-width: 900px) and (max-width: 1180px) {
  #app.shell { grid-template-columns: 340px 1fr 300px; }
}
