:root {
  --paper: #eef1f4;
  --panel: #ffffff;
  --ink: #17202b;
  --ink-2: #4a5666;
  --ink-3: #7c8796;
  --line: #d9dfe6;
  --signal: #2f5bea;
  --signal-soft: #e3eafd;
  --bubble-out: #dce5fd;
  --green: #23875b;
  --amber: #c98612;
  --red: #c23b3b;
  --rail: #1c2633;
  --radius-s: 6px;
  --radius-m: 10px;
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--paper);
  font-size: 14px;
  line-height: 1.45;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
#root { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }

/* Buttons & fields */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: var(--radius-s); cursor: pointer; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--signal); border-color: var(--signal); color: #fff; }
.btn.primary:hover { background: #244bd0; }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.field { display: grid; gap: 4px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--ink-2); font-weight: 500; }
.input, select.input, textarea.input { width: 100%; border: 1px solid var(--line); border-radius: var(--radius-s); padding: 8px 10px; background: #fff; }
.input:focus { border-color: var(--signal); outline: none; box-shadow: 0 0 0 3px var(--signal-soft); }
.check { display: flex; gap: 8px; align-items: center; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.login form { width: 100%; max-width: 360px; background: var(--panel); padding: 28px; border-radius: var(--radius-m); border: 1px solid var(--line); }
.login h1 { margin-bottom: 4px; }
.login p { margin: 0 0 20px; }
.error { color: var(--red); font-size: 13px; min-height: 18px; margin-bottom: 8px; }

/* Shell */
.shell { display: grid; grid-template-columns: 200px 1fr; height: 100%; }
.rail { background: var(--rail); color: #c9d2de; display: flex; flex-direction: column; padding: 16px 10px; gap: 2px; }
.brand { color: #fff; font-weight: 600; padding: 4px 10px 18px; font-size: 15px; }
.rail a { color: inherit; text-decoration: none; padding: 8px 10px; border-radius: var(--radius-s); display: flex; justify-content: space-between; }
.rail a:hover { background: rgba(255,255,255,.06); }
.rail a.active { background: rgba(255,255,255,.12); color: #fff; }
.rail .count { background: var(--signal); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.rail .spacer { flex: 1; }
.me { border-top: 1px solid rgba(255,255,255,.1); padding: 12px 10px 0; display: grid; gap: 8px; }
.me .name { color: #fff; }
.avail { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.avail input { accent-color: var(--green); }
.rail .btn { background: transparent; color: #c9d2de; border-color: rgba(255,255,255,.2); }
.main { min-width: 0; min-height: 0; overflow: hidden; }
.page { padding: 24px 28px; overflow: auto; height: 100%; }
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; gap: 12px; flex-wrap: wrap; }

/* Inbox */
.inbox { display: grid; grid-template-columns: 320px 1fr 290px; height: 100%; }
.list { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 14px 14px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; }
.tabs button { flex: 1; border: 0; background: var(--paper); padding: 6px; border-radius: var(--radius-s); cursor: pointer; font-size: 13px; }
.tabs button.on { background: var(--ink); color: #fff; }
.list-row { display: flex; gap: 8px; }
.convs { overflow-y: auto; flex: 1; }
.conv { padding: 11px 14px; border-bottom: 1px solid #eef1f4; cursor: pointer; display: grid; gap: 2px; border-left: 3px solid transparent; }
.conv:hover { background: #f7f9fb; }
.conv.active { background: var(--signal-soft); border-left-color: var(--signal); }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .preview { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv .meta { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); }
.conv.unread .who { font-weight: 600; }
.badge { background: var(--signal); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.pill { display: inline-block; font-size: 11px; padding: 0 7px; border-radius: 10px; background: var(--paper); color: var(--ink-2); line-height: 18px; }
.pill.ad { background: #fff4df; color: #8a5a00; }
.empty { padding: 40px 24px; text-align: center; color: var(--ink-3); }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--paper); }
.chat-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.chat-head .actions { display: flex; gap: 8px; align-items: center; }

/* The reply-window meter: the one thing agents glance at constantly. */
.window { background: var(--panel); padding: 0 16px 10px; border-bottom: 1px solid var(--line); }
.window .label { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-2); margin-bottom: 5px; }
.window .track { height: 5px; background: var(--paper); border-radius: 3px; overflow: hidden; }
.window .fill { height: 100%; border-radius: 3px; transition: width .6s ease; }
.window.ok .fill { background: var(--green); }
.window.soon .fill { background: var(--amber); }
.window.soon .label strong { color: var(--amber); }
.window.closed .label strong { color: var(--red); }

.msgs { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--ink-3); margin: 10px 0 4px; }
.bubble { max-width: min(560px, 78%); padding: 8px 11px 6px; border-radius: var(--radius-m); background: var(--panel); border: 1px solid var(--line); word-wrap: break-word; }
.bubble .text { white-space: pre-wrap; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-color: #c8d5fa; }
.bubble.failed { border-color: var(--red); }
.bubble .foot { font-size: 11px; color: var(--ink-3); display: flex; justify-content: flex-end; gap: 6px; margin-top: 3px; }
.bubble .tick.read { color: var(--signal); }
.bubble .err { color: var(--red); font-size: 12px; margin-top: 4px; }
.bubble img, .bubble video { max-width: 100%; max-height: 320px; border-radius: var(--radius-s); display: block; }
.bubble audio { max-width: 100%; }
.bubble .tpl { font-size: 11px; color: var(--ink-3); margin-bottom: 2px; }

.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 12px; display: grid; gap: 8px; position: relative; }
.typing-line { font-size: 12px; color: var(--signal); padding: 0 20px; height: 0; overflow: hidden; transition: height .15s; }
.typing-line.on { height: 20px; }

/* Quick-reply picker ("/" in the reply box) */
.qr-pop { position: absolute; left: 12px; right: 12px; bottom: calc(100% - 4px); max-height: 260px; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); box-shadow: 0 8px 24px rgba(23,32,43,.14); z-index: 5; }
.qr { padding: 8px 12px; cursor: pointer; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr span { color: var(--ink-2); }
.qr.on, .qr:hover { background: var(--signal-soft); }
.composer textarea { resize: none; min-height: 42px; max-height: 160px; }
.composer .row { display: flex; gap: 8px; align-items: center; }
.composer .row .grow { flex: 1; }
.composer .locked { font-size: 13px; color: var(--ink-2); }

.side { border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 16px; }
.side section { margin-bottom: 20px; }
.side h3 { margin-bottom: 8px; }
.kv { display: grid; grid-template-columns: 80px 1fr; gap: 4px 8px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; word-break: break-all; }
.note { border-left: 2px solid var(--line); padding: 2px 0 2px 10px; margin-bottom: 10px; font-size: 13px; white-space: pre-wrap; }

/* Tables & panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 16px 18px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 10px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #edf0f3; vertical-align: middle; }
th { font-size: 12px; color: var(--ink-2); font-weight: 500; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { overflow-x: auto; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #c3cad3; margin-right: 6px; }
.dot.on { background: var(--green); }
.dot.away { background: var(--amber); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 14px 16px; }
.stat strong { display: block; font-size: 24px; font-weight: 600; }
.stat.warn strong { color: var(--red); }
.bad { color: var(--red); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .input { width: auto; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 10px; }
table.clickable tbody tr { cursor: pointer; }
table.clickable tbody tr:hover { background: #f7f9fb; }
.pre { white-space: pre-wrap; }
.share { display: inline-block; height: 6px; background: var(--signal); border-radius: 3px; vertical-align: middle; margin-right: 6px; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(23,32,43,.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: var(--panel); border-radius: var(--radius-m); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; padding: 20px 22px; }
.modal h2 { margin-bottom: 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.tpl-preview { background: var(--paper); border-radius: var(--radius-s); padding: 10px 12px; white-space: pre-wrap; font-size: 13px; margin-bottom: 12px; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius-s); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; }
#toast.bad { background: var(--red); }

.back { display: none; }
@media (max-width: 1100px) {
  .inbox { grid-template-columns: 300px 1fr; }
  .side { display: none; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .rail { flex-direction: row; flex-wrap: wrap; padding: 8px; gap: 4px; }
  .rail .brand, .rail .spacer { display: none; }
  .me { border: 0; padding: 0; display: flex; gap: 8px; align-items: center; }
  .me .name { display: none; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.has-active .list { display: none; }
  .inbox:not(.has-active) .chat { display: none; }
  .back { display: inline-block; }
  .grid3 { grid-template-columns: 1fr; }
  .page { padding: 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* WhatsApp call bar */
.callbar { position: fixed; top: 16px; right: 16px; z-index: 60; display: flex; gap: 16px; align-items: center; background: var(--rail); color: #fff; padding: 12px 14px; border-radius: var(--radius-m); box-shadow: 0 8px 24px rgba(23,32,43,.3); max-width: calc(100vw - 32px); }
.callbar .who { display: grid; min-width: 0; }
.callbar .linkish { background: none; border: 0; padding: 0; color: #fff; font-weight: 600; cursor: pointer; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.callbar .small { color: #c9d2de; font-variant-numeric: tabular-nums; }
.callbar .acts { display: flex; gap: 8px; flex-shrink: 0; }
.callbar .btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }
.callbar .btn.accept { background: var(--green); border-color: var(--green); }
.callbar .btn.decline { background: var(--red); border-color: var(--red); }
.callbar.ringing { animation: callpulse 1.2s ease-in-out infinite; }
@keyframes callpulse { 50% { box-shadow: 0 0 0 6px rgba(35,135,91,.45); } }
@media (prefers-reduced-motion: reduce) { .callbar.ringing { animation: none; } }
