:root {
  --bg: #f5f6f8; --panel: #fff; --ink: #18212f; --muted: #6b7686; --line: #e5e8ee;
  --brand: #128c7e; --brand-2: #25d366; --brand-ink: #075e54; --soft: #e9f7f3;
  --danger: #d93f4c; --warn: #d98a00; --ok: #1a9b5c; --info: #2f6fdb;
  --rainbow: linear-gradient(90deg,#ff5f6d,#ffa95f,#ffe066,#5fd38d,#4fb3ff,#8a6bff,#d36bff);
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, Segoe UI, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 20px; margin: 0; font-weight: 700; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; height: 100vh; }
.side { background: #0f2a28; color: #d7ebe7; display: flex; flex-direction: column; position: relative; }
.side::before { content: ''; height: 4px; background: var(--rainbow); }
.brand { padding: 18px 18px 14px; }
.brand b { display: block; font-size: 15px; color: #fff; }
.brand span { font-size: 11px; opacity: .7; letter-spacing: .02em; }
.nav { display: flex; flex-direction: column; padding: 6px 10px; gap: 2px; }
.nav a { color: #cfe4e0; padding: 9px 12px; border-radius: 8px; display: flex; align-items: center; gap: 10px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); }
.nav a.active { background: rgba(37,211,102,.16); color: #fff; }
.nav .count { margin-left: auto; background: var(--brand-2); color: #04332b; font-size: 11px; font-weight: 700; border-radius: 99px; padding: 1px 7px; }
.side .me { margin-top: auto; padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.side .me button { background: none; border: 0; color: #9fc9c1; cursor: pointer; padding: 0; margin-top: 4px; }
.main { overflow: auto; display: flex; flex-direction: column; min-width: 0; }
.page { padding: 22px 26px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.sim-banner { background: #fff7e0; border-bottom: 1px solid #f3dfa4; color: #7a5600; padding: 8px 26px; font-size: 13px; }

/* cards & tables */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card.flush { padding: 0; overflow: hidden; }
.stat .v { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat .l { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; } tr.click:hover td { background: #f8fbfa; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* controls */
.btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 8px 14px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #f6f7f9; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; outline: none; }
.input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(18,140,126,.12); }
textarea.input { resize: vertical; min-height: 80px; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs a { padding: 9px 14px; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; }
.tabs a.active { color: var(--brand-ink); border-color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 2px 9px; font-size: 12px; font-weight: 600; background: #eef0f4; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip.pick { cursor: pointer; border: 1px solid transparent; }
.chip.pick.on { border-color: currentColor; background: #fff; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; letter-spacing: .02em; text-transform: uppercase; }
.b-gray { background: #eef0f4; color: #4b5565; } .b-green { background: #dcf5e7; color: #10703f; }
.b-amber { background: #fff1d6; color: #8a5a00; } .b-red { background: #fde4e6; color: #a8232f; }
.b-blue { background: #e1ecff; color: #2350a8; } .b-purple { background: #efe6ff; color: #5b2ea8; }
.progress { height: 8px; background: #edf0f3; border-radius: 99px; overflow: hidden; display: flex; }
.progress i { display: block; height: 100%; }

/* modal & toast */
.modal-wrap { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow: auto; z-index: 50; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.wide { max-width: 980px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px 20px; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.x { margin-left: auto; background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast { background: #18212f; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; }
.toast.err { background: var(--danger); }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(circle at 20% 10%, #e3f7ef, transparent 50%), radial-gradient(circle at 90% 90%, #efe6ff, transparent 50%), var(--bg); }
.login .card { width: 360px; padding: 28px; position: relative; overflow: hidden; }
.login .card::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 5px; background: var(--rainbow); }
.login h1 { margin-bottom: 4px; }
.motto { font-style: italic; color: var(--brand-ink); font-size: 13px; }

/* inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr 300px; height: 100vh; min-height: 0; }
.inbox > * { min-height: 0; }
.convos { border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; }
.convos .top { padding: 14px; border-bottom: 1px solid var(--line); }
.convos .filters { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }
.convos .filters a { font-size: 12px; padding: 4px 9px; border-radius: 99px; color: var(--muted); cursor: pointer; font-weight: 600; }
.convos .filters a.on { background: var(--soft); color: var(--brand-ink); }
.convo-list { overflow: auto; flex: 1; }
.convo { padding: 12px 14px; border-bottom: 1px solid #f0f2f5; cursor: pointer; display: grid; grid-template-columns: 38px 1fr auto; gap: 10px; align-items: center; }
.convo:hover { background: #f8faf9; } .convo.on { background: var(--soft); }
.avatar { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 14px; }
.convo .n { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo .p { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convo .meta { text-align: right; font-size: 11px; color: var(--muted); }
.unread { background: var(--brand-2); color: #04332b; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; display: inline-block; margin-top: 4px; }
.thread { display: flex; flex-direction: column; background: #efeae2; min-width: 0; }
.thread .head { background: #fff; padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.msgs { flex: 1; overflow: auto; padding: 18px 8%; display: flex; flex-direction: column; gap: 6px;
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 18px 18px; }
.bubble { max-width: 70%; padding: 7px 10px 5px; border-radius: 9px; box-shadow: 0 1px 1px rgba(0,0,0,.08); word-wrap: break-word; position: relative; }
.bubble.in { background: #fff; align-self: flex-start; border-top-left-radius: 2px; }
.bubble.out { background: #d9fdd3; align-self: flex-end; border-top-right-radius: 2px; }
.bubble.bot { background: #e7f0ff; }
.bubble .who { font-size: 11px; font-weight: 700; color: var(--brand-ink); margin-bottom: 2px; }
.bubble.bot .who { color: var(--info); }
.bubble .t { font-size: 10.5px; color: #667781; text-align: right; margin-top: 2px; display: flex; gap: 4px; justify-content: flex-end; align-items: center; }
.bubble .err { color: var(--danger); font-size: 11px; margin-top: 3px; }
.tick { font-weight: 700; letter-spacing: -3px; padding-right: 3px; } .tick.read { color: #34b7f1; } .tick.failed { color: var(--danger); letter-spacing: 0; }
.daysep { align-self: center; background: #fff; color: var(--muted); font-size: 11px; padding: 3px 10px; border-radius: 6px; margin: 6px 0; box-shadow: 0 1px 1px rgba(0,0,0,.06); }
.composer { background: #f0f2f5; padding: 10px 14px; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; border: 0; border-radius: 8px; padding: 10px 12px; resize: none; max-height: 140px; min-height: 42px; outline: none; }
.window-note { background: #fff7e0; color: #7a5600; padding: 8px 14px; font-size: 12px; border-top: 1px solid #f3dfa4; display: flex; gap: 10px; align-items: center; }
.details { background: #fff; border-left: 1px solid var(--line); overflow: auto; padding: 16px; }
.details .sec { border-top: 1px solid var(--line); padding-top: 12px; margin-top: 12px; }
.kv { display: grid; grid-template-columns: 1fr; gap: 2px; margin-bottom: 8px; }
.kv b { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.mode { display: flex; background: #f0f2f5; border-radius: 8px; padding: 3px; }
.mode a { flex: 1; text-align: center; padding: 6px; border-radius: 6px; color: var(--muted); font-weight: 600; cursor: pointer; font-size: 12px; }
.mode a.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.sim { background: #fffaf0; border: 1px dashed #e7c56e; border-radius: 10px; padding: 12px; margin: 12px; }
.noconv { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; }

/* template preview */
.wa-preview { background: #efeae2; border-radius: 12px; padding: 20px; min-height: 260px;
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 18px 18px; }
.wa-card { background: #fff; border-radius: 8px; max-width: 300px; box-shadow: 0 1px 1px rgba(0,0,0,.1); overflow: hidden; }
.wa-card .media { background: #cfd8dc; height: 140px; display: grid; place-items: center; color: #546e7a; font-weight: 600; background-size: cover; background-position: center; }
.wa-card .c { padding: 8px 10px; word-wrap: break-word; }
.pre { white-space: pre-wrap; }
.wa-card .h { font-weight: 700; margin-bottom: 4px; }
.wa-card .f { color: #8696a0; font-size: 12px; margin-top: 4px; }
.wa-card .btns div { border-top: 1px solid #eef0f2; text-align: center; padding: 9px; color: #027eb5; font-weight: 600; }
.var { background: #fff3c4; border-radius: 3px; padding: 0 2px; white-space: nowrap; }
.btn-row { display: grid; grid-template-columns: 130px 1fr 1fr 32px; gap: 6px; margin-bottom: 6px; }
.cond { display: grid; grid-template-columns: 1fr 120px 1fr 32px; gap: 6px; margin-bottom: 6px; }
.map-row { display: grid; grid-template-columns: 105px 150px 1fr 1fr; gap: 6px; align-items: center; margin-bottom: 6px; }
.review-note { background: #fff1d6; border-radius: 8px; padding: 8px 10px; font-size: 13px; margin-bottom: 12px; }

@media (max-width: 1100px) { .inbox { grid-template-columns: 280px 1fr; } .details { display: none; } .g4 { grid-template-columns: repeat(2,1fr); } }
