/* ============================================================
   wa-bigs — UI emesys (turunan emesys Core · Design Guide Ekosistem)
   Navy memimpin · gold = "denyut" (CTA/aksen, hemat) · aksen app = Koral (Reach).
   Hanya lapisan visual: semua kelas/ID & perilaku JS tetap sama.
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* —— Brand emesys (navy #182C61 · gold #FBC531) —— */
  --navy:#182C61; --navy-900:#101F47; --navy-800:#1F356F; --navy-700:#2A4488; --navy-100:#E7ECF7;
  --gold:#FBC531; --gold-600:#E6A91A; --gold-100:#FEF3D3;

  /* —— Ink & netral (undertone navy) —— */
  --ink-900:#0E1B33; --ink-700:#33415E; --ink-500:#5C6A88; --ink-300:#99A6BE;
  --line:#E2E8F1; --paper:#FFFFFF; --mist:#F4F7FB;

  /* —— Semantik (status) —— */
  --success:#1E9E6A; --success-bg:#E3F5EC;
  --warning:#E8841A; --warning-bg:#FCEEDD;
  --danger:#D64242;  --danger-bg:#FBE6E6;
  --info:#2E6BD6;    --info-bg:#E6EEFB;

  /* —— Aksen aplikasi = Koral (emesys Reach) —— */
  --app-accent:#E8662E; --app-accent-bg:#FCE9E0;

  /* —— Radius & elevasi (bayangan undertone navy) —— */
  --r-sm:8px; --r-md:12px; --r-lg:16px; --r-pill:999px;
  --sh-1:0 1px 3px rgba(24,44,97,.06);
  --sh-2:0 6px 18px rgba(24,44,97,.08);
  --sh-3:0 16px 40px rgba(24,44,97,.12);

  /* —— Tipografi —— */
  --font-display:'Poppins', system-ui, sans-serif;
  --font-body:'Inter', system-ui, sans-serif;
  --font-mono:'JetBrains Mono', monospace;

  /* —— Alias legacy (dipakai markup lama yang masih merujuk var ini) —— */
  --bg2:var(--mist);
  --border:var(--line);
  --muted:var(--ink-500);
  --text:var(--ink-900);
  --accent:var(--app-accent);
  --radius:var(--r-lg);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--mist);
  color: var(--ink-700);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--navy-700); text-decoration: none; }
a:hover { color: var(--navy); }
button { font-family: inherit; cursor: pointer; }
h1, h2, h3, h4 { font-family: var(--font-display); color: var(--ink-900); }

/* ---- Form controls ---- */
input, select, textarea {
  font-family: inherit;
  background: var(--paper);
  border: 1px solid var(--line);
  color: var(--ink-900);
  border-radius: var(--r-md);
  padding: 10px 13px;
  width: 100%;
  outline: none;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(24,44,97,.12);
}
input::placeholder, textarea::placeholder { color: var(--ink-300); }
label { font-size: 13px; font-weight: 500; color: var(--ink-700); display: block; margin-bottom: 6px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--navy);
  color: #fff;
  border: 1px solid var(--navy);
  padding: 10px 16px;
  border-radius: var(--r-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 14px;
  transition: background .15s, border-color .15s, filter .15s;
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.sm svg { width: 14px; height: 14px; }
.btn:hover { background: var(--navy-700); border-color: var(--navy-700); }
.btn.secondary { background: var(--paper); color: var(--navy); border: 1px solid var(--line); }
.btn.secondary:hover { background: var(--mist); border-color: var(--ink-300); }
.btn.danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.danger:hover { filter: brightness(.95); background: var(--danger); }
.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: var(--r-sm); }
/* CTA emas tunggal per layar: "+ Device Baru" (di sidebar navy) */
#newSessionBtn { background: var(--gold); color: var(--navy); border-color: var(--gold); }
#newSessionBtn:hover { background: var(--gold-600); border-color: var(--gold-600); filter: none; }

/* ---- Utility ---- */
.row { display: flex; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 12px; }
.muted { color: var(--ink-500); }
.hidden { display: none !important; }

/* ---- Status pill (titik denyut + latar semantik lembut) ---- */
.pill {
  font-size: 11px; font-weight: 600;
  padding: 3px 10px; border-radius: var(--r-pill);
  display: inline-flex; align-items: center; gap: 5px;
  text-transform: capitalize;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.connected    { background: var(--success-bg); color: var(--success); }
.pill.connecting   { background: var(--warning-bg); color: var(--warning); }
.pill.qr           { background: var(--info-bg);    color: var(--info); }
.pill.disconnected { background: var(--danger-bg);  color: var(--danger); }

/* ---- Brand lockup (wordmark + denyut emas) ---- */
.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -.01em;
  display: inline-flex;
  align-items: flex-start;
}
.brand::after {                       /* titik emas "denyut" */
  content: "";
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--gold);
  margin-left: 3px; margin-top: 3px;
  flex: none;
}
.sidebar .brand { color: #fff; }
.sidebar .brand span { color: rgba(255,255,255,.55); }
.brand-sub { font-size: 11px; color: rgba(255,255,255,.5); letter-spacing: .02em; margin-top: 5px; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--navy-800), var(--navy-900));
}
.login-card {
  background: var(--paper);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-3);
  padding: 34px;
  width: 100%; max-width: 380px;
  text-align: center;
}
.login-card .brand { color: var(--navy); justify-content: center; }
.login-card .brand span { color: var(--app-accent); }
.login-card .col { text-align: left; margin-top: 4px; }
.login-sub { color: var(--ink-500); font-size: 13px; }

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app { display: grid; grid-template-columns: 264px 1fr; height: 100vh; }

/* Sidebar navy (signature emesys) — daftar device */
.sidebar {
  background: var(--navy-900);
  color: rgba(255,255,255,.82);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar header { padding: 18px 16px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.sessions-list {
  flex: 1; overflow-y: auto; padding: 12px 10px;
  scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.22) transparent;
}
.sessions-list::-webkit-scrollbar { width: 8px; }
.sessions-list::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,.16); border-radius: 999px;
  border: 2px solid transparent; background-clip: padding-box;
}
.sessions-list:hover::-webkit-scrollbar-thumb { background: rgba(255,255,255,.3); background-clip: padding-box; }
.session-item {
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--r-md);
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.session-item:hover { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.16); }
.session-item.active { background: #2A3A57; border-color: transparent; box-shadow: inset 3px 0 0 var(--gold); }
.session-item .name { font-weight: 600; font-size: 14px; color: #fff; }
.session-item .phone { font-size: 12px; color: rgba(255,255,255,.55); font-family: var(--font-mono); }
.sidebar footer { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar footer .muted, #meLabel { color: rgba(255,255,255,.6); font-size: 12.5px; }
/* tombol "Keluar" di footer gelap → outline terang */
.sidebar footer .btn.secondary {
  background: rgba(255,255,255,.06); color: #fff; border-color: rgba(255,255,255,.16);
}
.sidebar footer .btn.secondary:hover { background: rgba(255,255,255,.12); border-color: rgba(255,255,255,.28); }

/* ---- Main ---- */
.main { display: flex; flex-direction: column; overflow: hidden; background: var(--mist); }
.tabs {
  display: flex; gap: 2px; padding: 0 22px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  overflow-x: auto; overflow-y: hidden;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  background: none; border: none; color: var(--ink-500);
  padding: 15px 14px;
  font-family: var(--font-display); font-weight: 600; font-size: 14px;
  white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  transition: color .15s, border-color .15s;
}
.tab svg { width: 17px; height: 17px; flex: none; }
.tab:hover { color: var(--navy); }
.tab.active { color: var(--navy); border-bottom-color: var(--app-accent); }
.tab-body {
  flex: 1; overflow-y: auto; padding: 24px;
  scrollbar-width: thin; scrollbar-color: var(--ink-300) transparent;
}

/* ---- Cards ---- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
  padding: 22px;
  margin-bottom: 18px;
}
.card h3 { font-family: var(--font-display); font-size: 16px; font-weight: 600; color: var(--ink-900); margin-bottom: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--line); }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .02em; color: var(--ink-500); font-weight: 600; }
td { color: var(--ink-900); }
tbody tr:hover { background: var(--mist); }
.empty { color: var(--ink-500); text-align: center; padding: 44px 0; }

/* ---- QR ---- */
.qr-box { text-align: center; padding: 10px; }
.qr-box img { width: 240px; height: 240px; background: #fff; border-radius: var(--r-md); padding: 10px; border: 1px solid var(--line); }

/* ============================================================
   INBOX
   ============================================================ */
.inbox {
  display: grid; grid-template-columns: 300px 1fr; height: 100%;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--sh-1);
}
.chat-list {
  border-right: 1px solid var(--line); overflow-y: auto; background: var(--paper);
  scrollbar-width: thin; scrollbar-color: var(--ink-300) transparent;
}
.chat-row { padding: 13px 15px; border-bottom: 1px solid var(--line); cursor: pointer; transition: background .12s; }
.chat-row:hover { background: var(--mist); }
.chat-row.active { background: var(--app-accent-bg); box-shadow: inset 3px 0 0 var(--app-accent); }
.chat-row .cname { font-weight: 600; font-size: 14px; color: var(--ink-900); display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.chat-row .cmsg { font-size: 12.5px; color: var(--ink-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.badge { background: var(--app-accent); color: #fff; font-size: 10px; border-radius: 999px; padding: 1px 7px; font-weight: 700; }
.chat-pane { display: flex; flex-direction: column; height: 100%; background: var(--mist); }
.chat-msgs {
  flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 8px;
  scrollbar-width: thin; scrollbar-color: var(--ink-300) transparent;
}

/* Scrollbar tipis pada area terang */
.tab-body::-webkit-scrollbar, .chat-list::-webkit-scrollbar, .chat-msgs::-webkit-scrollbar { width: 9px; }
.tab-body::-webkit-scrollbar-thumb, .chat-list::-webkit-scrollbar-thumb, .chat-msgs::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box;
}
.tab-body:hover::-webkit-scrollbar-thumb, .chat-list:hover::-webkit-scrollbar-thumb, .chat-msgs:hover::-webkit-scrollbar-thumb {
  background: var(--ink-300); background-clip: padding-box;
}

/* ---- Bubble ---- */
.bubble {
  max-width: 72%; padding: 9px 13px; border-radius: 14px;
  font-size: 14px; line-height: 1.45; word-break: break-word;
  position: relative; box-shadow: var(--sh-1);
}
.bubble.in  { background: var(--paper); color: var(--ink-900); align-self: flex-start; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble.out { background: var(--navy); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble .meta { font-size: 10px; margin-top: 4px; color: var(--ink-500); }
.bubble.out .meta { color: rgba(255,255,255,.7); }
.bubble .sender-name { font-size: 11px; font-weight: 600; color: var(--app-accent); margin-bottom: 3px; }
.bubble.revoked { opacity: .6; font-style: italic; }

/* Tombol reply / tarik pesan di bubble */
.bubble .reply-btn, .bubble .revoke-btn {
  position: absolute; top: 4px;
  background: rgba(0,0,0,.28); color: #fff; border: none;
  width: 22px; height: 22px; border-radius: 50%;
  font-size: 12px; cursor: pointer; opacity: 0; transition: opacity .12s; line-height: 1;
}
.bubble .reply-btn { right: 4px; }
.bubble .revoke-btn { right: 30px; font-size: 11px; }
.bubble:hover .reply-btn, .bubble:hover .revoke-btn { opacity: 1; }

/* ---- Quote (reply) ---- */
.quote-box {
  border-left: 3px solid var(--app-accent);
  background: rgba(14,27,51,.05);
  padding: 5px 9px; border-radius: 6px; margin-bottom: 5px;
  font-size: 12px; color: var(--ink-500); max-width: 100%;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bubble.out .quote-box { background: rgba(255,255,255,.14); color: rgba(255,255,255,.8); border-left-color: var(--gold); }

.chat-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); background: var(--paper); }
.chat-input input { flex: 1; }

/* ---- Reply bar (di atas input) ---- */
.reply-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--app-accent-bg);
  border-top: 1px solid var(--line);
  border-left: 3px solid var(--app-accent);
}
.reply-bar-text { flex: 1; min-width: 0; }
.reply-bar-label { font-size: 11px; color: var(--app-accent); font-weight: 600; }
.reply-bar-snippet { font-size: 13px; color: var(--ink-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-x { background: none; border: none; color: var(--ink-500); font-size: 16px; cursor: pointer; }

/* ============================================================
   LIGHTBOX
   ============================================================ */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(14,27,51,.94);
  display: flex; align-items: center; justify-content: center;
}
.lb-stage { max-width: 90vw; max-height: 86vh; overflow: hidden; display: flex; align-items: center; justify-content: center; }
.lb-stage img { max-width: 90vw; max-height: 86vh; transform-origin: center center; transition: transform .15s; cursor: grab; user-select: none; }
.lb-btn {
  background: rgba(255,255,255,.14); color: #fff; border: none;
  border-radius: var(--r-sm); cursor: pointer; font-size: 18px;
  width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center;
  text-decoration: none;
}
.lb-btn:hover { background: rgba(255,255,255,.26); }
.lb-close { position: fixed; top: 18px; right: 18px; }
.lb-prev, .lb-next { position: fixed; top: 50%; transform: translateY(-50%); font-size: 32px; }
.lb-prev { left: 18px; }
.lb-next { right: 18px; }
.lb-toolbar { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; gap: 8px; background: rgba(0,0,0,.4); padding: 8px; border-radius: var(--r-md); }
.lb-toolbar .lb-btn { width: auto; min-width: 44px; padding: 0 12px; font-size: 14px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 20px; right: 20px;
  background: var(--navy-900); color: #fff; border: 1px solid var(--navy-700);
  padding: 13px 18px; border-radius: var(--r-md); font-size: 14px; font-weight: 500;
  box-shadow: var(--sh-3); z-index: 999;
  transform: translateY(140%); transition: transform .25s;
}
.toast.show { transform: translateY(0); }
.toast.err { background: var(--danger); border-color: var(--danger); }

/* ---- Code & pre ---- */
code { font-family: var(--font-mono); font-size: 12.5px; color: var(--navy); background: var(--navy-100); padding: 2px 6px; border-radius: 6px; }
code.key { background: var(--mist); border: 1px solid var(--line); padding: 9px 12px; border-radius: var(--r-sm); font-size: 12px; word-break: break-all; display: block; color: var(--ink-900); }
pre { font-family: var(--font-mono); background: var(--mist); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 14px; overflow-x: auto; }

/* ============================================================
   RESPONSIF (fallback ringkas untuk layar sempit)
   ============================================================ */
@media (max-width: 820px) {
  body { overflow: auto; height: auto; }
  .app { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .sidebar { max-height: 44vh; }
  .main { overflow: visible; }
  .grid2 { grid-template-columns: 1fr; }
  .inbox { grid-template-columns: 1fr !important; height: auto !important; }
  .chat-list { max-height: 34vh; }
  .chat-msgs { min-height: 46vh; }
}
