:root {
  --bg: #f4f5f7; --card: #ffffff; --line: #e3e5ea; --text: #14161a; --muted: #6a7080;
  --accent: #3b66f0; --accent-ink: #ffffff; --accent-soft: #e8eeff;
  --bad: #d0342c; --bad-soft: #fdeceb; --ok: #1d8a4f; --ok-soft: #e5f6ec; --warn: #b36b00; --warn-soft: #fff3dc;
  --me: #3b66f0; --me-ink: #fff; --them: #e9ebf0; --them-ink: #14161a;
  --nav-h: 58px; --top-h: 52px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #171a20; --line: #272b34; --text: #eceef3; --muted: #8b93a5;
    --accent: #6c8dff; --accent-ink: #0b1020; --accent-soft: #1d2540;
    --bad: #ff6b62; --bad-soft: #3a1b1a; --ok: #45c47f; --ok-soft: #14301f; --warn: #f0b04a; --warn-soft: #33260e;
    --me: #3d5fd0; --me-ink: #fff; --them: #232833; --them-ink: #eceef3;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.err { color: var(--bad); min-height: 1.4em; margin: 8px 0 0; }

/* shell */
#shell { display: flex; flex-direction: column; height: 100dvh; }
.top { display: flex; align-items: center; justify-content: space-between; height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0; background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
.top h1 { font-size: 20px; margin: 0; }
.icon-btn { width: 44px; height: 44px; border: 0; background: none; font-size: 22px; border-radius: 12px; cursor: pointer; color: var(--muted); }
.icon-btn:active { background: var(--accent-soft); }
#view { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 12px 16px 20px; }
.tabs { display: flex; flex: none; height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line); }
.tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; position: relative;
  text-decoration: none; color: var(--muted); font-size: 12px; font-weight: 600; }
.tabs a.on { color: var(--accent); }
.ti { font-size: 20px; line-height: 1; }
#badge { position: absolute; top: 5px; left: calc(50% + 8px); min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 11px; line-height: 18px; text-align: center; }

/* login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px; text-align: center; }
.logo { width: 52px; height: 52px; margin: 0 auto 10px; border-radius: 14px; background: var(--accent); color: var(--accent-ink);
  font-size: 28px; font-weight: 800; display: grid; place-items: center; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card input { width: 100%; margin: 14px 0 12px; }

/* controls */
input[type=text], input[type=password], input[type=search], textarea {
  width: 100%; padding: 12px 14px; font-size: 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); outline: none; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.btn { min-height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); font-weight: 600; cursor: pointer; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; }
.row-btns { display: flex; gap: 8px; margin-top: 10px; }
.row-btns .btn { flex: 1; }

/* filters + list */
.search { margin-bottom: 10px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 10px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; min-height: 36px; padding: 0 14px; border-radius: 18px; border: 1px solid var(--line); background: var(--card);
  font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip i { font-style: normal; opacity: .75; margin-left: 4px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.lead { display: block; width: 100%; text-align: left; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; cursor: pointer; }
.lead:active { background: var(--accent-soft); }
.lead-top { display: flex; align-items: baseline; gap: 8px; }
.lead-name { font-weight: 700; font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--bad); flex: none; align-self: center; }
.when { font-size: 12px; color: var(--muted); flex: none; }
.lead-mid { display: flex; align-items: center; gap: 8px; margin: 6px 0 4px; flex-wrap: wrap; }
.phone { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; cursor: pointer; }
.phone:active { background: var(--accent-soft); border-color: var(--accent); }
.phone svg { width: 14px; height: 14px; opacity: .6; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.preview { color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }

/* approve + stats cards */
.sec { margin: 18px 2px 8px; font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.sec:first-child { margin-top: 4px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.card.alert { border-color: var(--bad); background: var(--bad-soft); }
.card h3 { margin: 0 0 4px; font-size: 17px; }
.card p { margin: 6px 0; }
.quote { margin: 8px 0 0; padding: 8px 12px; border-left: 3px solid var(--accent); background: var(--accent-soft); border-radius: 0 10px 10px 0; font-size: 15px; white-space: pre-wrap; word-break: break-word; }
.mono { white-space: pre-wrap; font-size: 14px; }
.bar { height: 10px; border-radius: 5px; background: var(--line); overflow: hidden; margin-top: 8px; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border: 0; }
.kv span:first-child { color: var(--muted); }
.sticky-act { position: sticky; bottom: 0; padding: 10px 0 0; background: linear-gradient(transparent, var(--bg) 40%); }

/* chat */
.chat { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; background: var(--bg); height: 100dvh; }
.chat-top { flex: none; display: flex; align-items: center; gap: 4px; padding: env(safe-area-inset-top) 8px 0 4px;
  min-height: calc(56px + env(safe-area-inset-top)); background: var(--card); border-bottom: 1px solid var(--line); }
.chat-who { flex: 1; min-width: 0; padding: 4px 4px; }
.chat-who b { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 17px; line-height: 1.2; }
.chat-who .phone { min-height: 28px; margin-top: 2px; font-size: 13px; }
.info { flex: none; background: var(--card); border-bottom: 1px solid var(--line); padding: 4px 16px 10px; max-height: 40vh; overflow-y: auto; }
.msgs { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 8px 0 2px; }
.bubble { max-width: 82%; padding: 9px 13px; border-radius: 18px; white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.bubble.them { align-self: flex-start; background: var(--them); color: var(--them-ink); border-bottom-left-radius: 6px; }
.bubble.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 6px; }
.bubble.failed { background: var(--bad-soft); color: var(--bad); border: 1px solid var(--bad); }
.bubble small { display: block; margin-top: 3px; font-size: 11px; opacity: .7; }
.banner { flex: none; margin: 0; padding: 10px 16px; font-size: 14px; background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--line); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.actions { flex: none; display: flex; gap: 8px; padding: 8px 12px 0; }
.actions .btn { flex: 1; min-height: 40px; font-size: 14px; }
.composer { flex: none; display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); background: var(--bg); }
.composer textarea { resize: none; max-height: 140px; min-height: 44px; border-radius: 22px; padding: 10px 16px; }
.send { flex: none; width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 20px; cursor: pointer; }
.send[disabled] { opacity: .4; }

/* sheet + toast */
.sheet { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-end; }
.sheet-card { width: 100%; max-width: 560px; margin: 0 auto; background: var(--card); border-radius: 20px 20px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); }
.sheet-card h2 { margin: 0 0 6px; font-size: 18px; }
.sheet-card p { margin: 0 0 14px; color: var(--muted); }
.toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 50;
  max-width: 88vw; padding: 10px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600;
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.skel { height: 74px; border-radius: 14px; background: linear-gradient(90deg, var(--card), var(--line), var(--card)); background-size: 200% 100%; animation: sh 1.2s infinite; margin-bottom: 8px; }
@keyframes sh { to { background-position: -200% 0; } }
@media (min-width: 760px) {
  #view, .msgs, .info, .banner, .actions, .composer { max-width: 720px; width: 100%; margin-left: auto; margin-right: auto; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
