:root {
  --bg: #0f1419;
  --bg-elev: #171d25;
  --bg-soft: #1e2630;
  --border: #2a3441;
  --text: #e8eef4;
  --muted: #8b9aab;
  --accent: #1aae8a;
  --accent-dim: rgba(26, 174, 138, 0.15);
  --warn: #e6a23c;
  --danger: #e25c5c;
  --info: #4d8ef7;
  --wa: #25d366;
  --radius: 12px;
  --font: "DM Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a { color: var(--accent); }

#app { height: 100%; }

/* ---- Login ---- */
.login-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(26,174,138,.22), transparent 60%),
    radial-gradient(700px 400px at 100% 100%, rgba(77,142,247,.12), transparent 55%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 32px;
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #0d7a62);
  display: grid; place-items: center;
  font-weight: 700; color: #04140f;
}
.brand h1 { margin: 0; font-size: 1.25rem; letter-spacing: -.02em; }
.login-card p.sub { margin: 0 0 24px; color: var(--muted); font-size: .95rem; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: .82rem; color: var(--muted); }
.field input, .field select, .field textarea,
.toolbar input, .toolbar select {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.field input:focus, .toolbar input:focus, .field textarea:focus {
  border-color: var(--accent);
}
.btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  transition: .15s ease;
}
.btn:hover { filter: brightness(1.08); }
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #04140f;
  font-weight: 600;
}
.btn-ghost { background: transparent; }
.btn-danger { background: rgba(226,92,92,.15); border-color: rgba(226,92,92,.35); color: #ffb4b4; }
.btn-block { width: 100%; }
.error {
  background: rgba(226,92,92,.12);
  border: 1px solid rgba(226,92,92,.35);
  color: #ffb4b4;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 12px;
  font-size: .9rem;
}

/* ---- Shell ---- */
.shell {
  height: 100%;
  display: grid;
  grid-template-columns: 72px 1fr;
  grid-template-rows: 56px 1fr;
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(15,20,25,.9);
  backdrop-filter: blur(8px);
}
.topbar .left { display: flex; align-items: center; gap: 14px; }
.topbar .nav-tabs { display: flex; gap: 4px; }
.topbar .nav-tabs button {
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
}
.topbar .nav-tabs button.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.topbar .right { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .9rem; }

.rail {
  border-right: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  gap: 8px;
}
.rail button {
  width: 44px; height: 44px;
  border-radius: 12px;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
}
.rail button.active {
  background: var(--accent-dim);
  color: var(--accent);
}

.main { min-height: 0; overflow: hidden; }

/* ---- Inbox ---- */
.inbox {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 320px;
  grid-template-rows: minmax(0, 1fr);
}
.col {
  min-height: 0;
  overflow: auto;
  border-right: 1px solid var(--border);
}
.col:last-child { border-right: 0; }
.col-head {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg);
  padding: 14px;
  border-bottom: 1px solid var(--border);
}
.col-head h2 { margin: 0 0 10px; font-size: 1rem; }
.toolbar { display: flex; gap: 8px; }
.toolbar input { flex: 1; min-width: 0; }

.session-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.session-item:hover, .session-item.active { background: var(--bg-soft); }
.session-item .title {
  font-weight: 600;
  display: flex; align-items: center; gap: 6px;
}
.wa-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--wa);
  box-shadow: 0 0 0 3px rgba(37,211,102,.15);
}
.session-item .snippet {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: .85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item .meta {
  color: var(--muted);
  font-size: .75rem;
  font-family: var(--mono);
}
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  text-transform: lowercase;
}
.badge.submitted, .badge.minat, .badge.deal { color: #7dffc8; border-color: rgba(26,174,138,.4); }
.badge.cold, .badge.blacklist { color: #ffb4b4; border-color: rgba(226,92,92,.35); }
.badge.dapat_harga, .badge.isi_form1, .badge.isi_form2, .badge.konfirmasi { color: #ffd59a; border-color: rgba(230,162,60,.35); }
.badge.human_handoff { color: #9ec1ff; border-color: rgba(77,142,247,.4); }
.badge.agent-human { color: #ffb4b4; border-color: rgba(226,92,92,.4); }
.badge.agent-bot { color: #7dffc8; border-color: rgba(26,174,138,.4); }
.session-badges { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; align-items: center; }
.cat-chip {
  display: inline-flex;
  padding: 1px 7px;
  border-radius: 6px;
  font-size: .68rem;
  background: rgba(77,142,247,.12);
  border: 1px solid rgba(77,142,247,.25);
  color: #9ec1ff;
}
.cat-chip.sm { font-size: .65rem; }
.cat-checks { display: flex; flex-direction: column; gap: 6px; }
.cat-check { display: flex; gap: 8px; align-items: center; font-size: .88rem; }
.cat-chips-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-admin-list { list-style: none; padding: 0; margin: 0; }
.cat-admin-list li {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
  font-size: .9rem;
}
.btn-sm { padding: 4px 10px; font-size: .78rem; }
.online-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: .85rem; color: var(--muted); margin-right: 12px;
}
.online-toggle input { accent-color: var(--accent); }

.chat-pane {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  border-right: 1px solid var(--border);
}
.chat-header {
  flex: 0 0 auto;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.chat-header h3 { margin: 0; font-size: 1.05rem; }
.chat-header .sub { color: var(--muted); font-size: .85rem; font-family: var(--mono); }
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    linear-gradient(180deg, rgba(26,174,138,.03), transparent 120px),
    var(--bg);
}
.bubble {
  max-width: min(78%, 560px);
  padding: 10px 12px;
  border-radius: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: .92rem;
}
.bubble.inbound {
  align-self: flex-start;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble.outbound {
  align-self: flex-end;
  background: rgba(26,174,138,.18);
  border: 1px solid rgba(26,174,138,.3);
  border-bottom-right-radius: 4px;
}
.bubble .time {
  display: block;
  margin-top: 6px;
  font-size: .7rem;
  color: var(--muted);
  font-family: var(--mono);
}
.bubble.typing {
  opacity: .85;
  min-width: 72px;
}
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 14px;
}
.typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1s infinite ease-in-out;
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: .45; }
  40% { transform: translateY(-3px); opacity: 1; }
}
.empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 24px;
}

.side-panel { padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.panel-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}
.panel-card h4 {
  margin: 0 0 10px;
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 8px; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.summary-box {
  white-space: pre-wrap;
  font-size: .88rem;
  background: var(--bg-soft);
  border-radius: 10px;
  padding: 10px;
  min-height: 80px;
  border: 1px solid var(--border);
}
.side-actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---- Users / Analytics ---- */
.page {
  height: 100%;
  overflow: auto;
  padding: 20px 24px 40px;
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 18px;
}
.page-head h2 { margin: 0; font-size: 1.35rem; letter-spacing: -.02em; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.kpi .label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 1.45rem; font-weight: 700; margin-top: 4px; font-family: var(--mono); }
.kpi .hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 980px) {
  .inbox { grid-template-columns: 280px 1fr; }
  .inbox .side-panel { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .shell { grid-template-columns: 56px 1fr; }
}

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.card h3 { margin: 0 0 12px; font-size: 1rem; }

.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 6px; font-size: .9rem; }
.bar-track {
  grid-column: 1 / -1;
  height: 8px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #4d8ef7);
  border-radius: 999px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}
.table th, .table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.table th { color: var(--muted); font-weight: 500; font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }

.spark {
  display: flex;
  align-items: end;
  gap: 3px;
  height: 72px;
}
.spark span {
  flex: 1;
  background: rgba(26,174,138,.35);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
}
.spark span.deals { background: rgba(77,142,247,.55); }

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  display: grid; place-items: center;
  z-index: 50;
  padding: 16px;
}
.modal {
  width: min(440px, 100%);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
}
.modal h3 { margin: 0 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

.composer {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
}
.composer textarea {
  flex: 1;
  min-height: 44px;
  max-height: 140px;
  resize: vertical;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.test-layout {
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-width: 920px;
  margin: 0 auto;
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.test-banner {
  flex: 0 0 auto;
  padding: 10px 16px;
  background: rgba(230,162,60,.12);
  border-bottom: 1px solid rgba(230,162,60,.3);
  color: #ffd59a;
  font-size: .88rem;
}
.test-layout .messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
}

.meta-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px 16px;
  margin: 0;
  font-size: .92rem;
}
.meta-grid dt { color: var(--muted); }
.meta-grid dd { margin: 0; }
.mono-sm { font-family: var(--mono); font-size: .78rem; color: var(--muted); }
.err-text { color: #f87171; font-size: .85rem; }
.hint.warn { color: #fbbf24; margin-top: 10px; font-size: .88rem; }
