/* ============================================================
   ChatKu - Gaya Utama (WhatsApp-like, teks saja)
   ============================================================ */

:root {
  --wa-green: #00a884;
  --wa-green-dark: #008069;
  --wa-teal: #075e54;
  --wa-bg: #efeae2;
  --wa-bubble-out: #d9fdd3;
  --wa-bubble-in: #ffffff;
  --wa-text: #111b21;
  --wa-muted: #667781;
  --wa-hover: #f0f2f5;
  --wa-border: #e9edef;
  --wa-red: #ea0038;
}

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

html, body { height: 100%; }

body {
  font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--wa-text);
  background: #d1d7db;
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
a { color: var(--wa-green-dark); text-decoration: none; }

/* ============================ AUTH ============================ */
.auth-body {
  background: linear-gradient(160deg, #00a884 0%, #008069 55%, #075e54 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-wrap { width: 100%; max-width: 400px; }

.auth-card {
  background: #fff;
  border-radius: 16px;
  padding: 34px 32px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
  text-align: center;
}

.auth-logo {
  width: 64px; height: 64px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wa-green), var(--wa-green-dark));
  color: #fff;
  font-size: 30px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

.auth-card h1 { font-size: 24px; color: var(--wa-teal); }
.auth-sub { color: var(--wa-muted); margin: 4px 0 20px; font-size: 13.5px; }

.auth-error {
  background: #fdecea;
  color: #b00020;
  border: 1px solid #f5c6cb;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}

.auth-card form { display: flex; flex-direction: column; gap: 12px; }

.auth-card input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #e0e0e0;
  border-radius: 10px;
  font-size: 14.5px;
  outline: none;
  transition: border-color .15s;
}
.auth-card input:focus { border-color: var(--wa-green); }

.btn-wa {
  padding: 13px;
  border: none;
  border-radius: 10px;
  background: var(--wa-green);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  transition: background .15s;
}
.btn-wa:hover { background: var(--wa-green-dark); }

.auth-link { margin-top: 18px; font-size: 13.5px; color: var(--wa-muted); }

/* ============================ APPSHELL ============================ */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  max-width: 1600px;
  margin: 0 auto;
  background: #fff;
}

/* ============================ SIDEBAR ============================ */
.sidebar {
  width: 380px;
  min-width: 300px;
  border-right: 1px solid var(--wa-border);
  display: flex;
  flex-direction: column;
  background: #fff;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--wa-green);
  min-height: 59px;
}

.me { display: flex; align-items: center; gap: 12px; min-width: 0; }

.me-info { min-width: 0; color: #fff; }
.me-info strong { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.me-info small { color: rgba(255,255,255,.85); font-size: 12px; }

.avatar {
  position: relative;
  width: 42px; height: 42px;
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  user-select: none;
}

.avatar .dot {
  position: absolute;
  right: -2px; bottom: -2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: #c8c9cc;
  border: 2px solid #fff;
}
.avatar .dot.on { background: #22c55e; }

.header-actions { display: flex; gap: 6px; }

/* Daftar online (sidebar public chat) */
.ol-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--wa-border);
  background: #fafafa;
}
.ol-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--wa-muted);
  font-weight: 600;
}
.ol-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid #f5f6f6;
}
.ol-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}
.ol-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
  box-shadow: 0 0 0 2px #fff;
}

.chat-icon { font-size: 22px; }

.icon-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 18px;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.18); }

.search-box { padding: 8px 12px; border-bottom: 1px solid var(--wa-border); }

.search-box input {
  width: 100%;
  padding: 9px 14px;
  border: none;
  border-radius: 8px;
  background: var(--wa-hover);
  font-size: 13.5px;
  outline: none;
}

.conversations { flex: 1; overflow-y: auto; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid #f5f6f6;
  transition: background .12s;
}
.conv-item:hover { background: var(--wa-hover); }
.conv-item.active { background: var(--wa-hover); }

.conv-body { flex: 1; min-width: 0; }

.conv-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.conv-name {
  font-size: 14.5px;
  font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-time { font-size: 11.5px; color: var(--wa-muted); flex-shrink: 0; }

.conv-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conv-preview {
  font-size: 12.5px;
  color: var(--wa-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge {
  background: var(--wa-green);
  color: #fff;
  border-radius: 50%;
  min-width: 20px; height: 20px;
  padding: 0 6px;
  font-size: 11px;
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.empty-list { text-align: center; color: var(--wa-muted); padding: 40px 20px; font-size: 13.5px; }

/* Hasil pencarian user */
.search-results { border-bottom: 1px solid var(--wa-border); }
.sr-label {
  padding: 8px 16px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--wa-muted);
  background: #fafafa;
  font-weight: 600;
}
.sr-item { border-bottom: 1px solid #f5f6f6; }

/* ============================ CHAT AREA ============================ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--wa-bg);
  position: relative;
  min-width: 0;
}

.chat-area::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .35;
  background-image:
    radial-gradient(circle at 20% 30%, rgba(0,0,0,.05) 2px, transparent 2.5px),
    radial-gradient(circle at 70% 60%, rgba(0,0,0,.05) 2px, transparent 2.5px),
    radial-gradient(circle at 40% 85%, rgba(0,0,0,.05) 2px, transparent 2.5px),
    radial-gradient(circle at 90% 15%, rgba(0,0,0,.05) 2px, transparent 2.5px);
  background-size: 120px 120px, 150px 150px, 180px 180px, 140px 140px;
  pointer-events: none;
}

/* Layar kosong */
.empty-chat {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.empty-chat-inner { text-align: center; padding: 30px; }
.empty-logo {
  width: 90px; height: 90px;
  margin: 0 auto 18px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--wa-green), var(--wa-green-dark));
  color: #fff;
  font-size: 42px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.empty-chat h2 { color: var(--wa-teal); font-size: 26px; margin-bottom: 8px; }
.empty-chat p { color: var(--wa-muted); max-width: 380px; }

/* Percakapan aktif */
.active-chat { display: none; flex: 1; flex-direction: column; position: relative; min-height: 0; }

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--wa-green);
  min-height: 60px;
  position: relative;
  z-index: 2;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}

.chat-title { flex: 1; min-width: 0; color: #fff; }
.chat-title strong { display: block; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title small { font-size: 12.5px; color: rgba(255,255,255,.85); }

.typing-badge {
  color: #dcf8c6;
  font-size: 12px;
  font-style: italic;
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: .4; } }

.back-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 20px;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
}
.back-btn:hover { background: rgba(255,255,255,.18); }

/* Daftar pesan */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 6%;
  position: relative;
  z-index: 1;
  scroll-behavior: smooth;
}

.msg {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.msg.out { justify-content: flex-end; }
.msg.in { justify-content: flex-start; }

.mini-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 3px;
  user-select: none;
}

.msg-body {
  max-width: 65%;
  padding: 6px 9px 7px;
  border-radius: 8px;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: break-word;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
}
.msg.out .msg-body {
  background: var(--wa-bubble-out);
  border-top-right-radius: 2px;
}
.msg.in .msg-body {
  background: var(--wa-bubble-in);
  border-top-left-radius: 2px;
}

.msg-sender {
  font-size: 12px;
  font-weight: 600;
  color: #008069;
  margin-bottom: 2px;
}

.msg-text { white-space: pre-wrap; line-height: 1.4; font-size: 14px; }

.msg-meta {
  float: right;
  margin: 6px -2px -3px 8px;
  font-size: 11px;
  color: var(--wa-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}
.msg.out .msg-meta { color: rgba(17,27,33,.55); }
.ticks { color: #53bdeb; font-size: 12px; letter-spacing: -2px; }

/* Penanda tanggal */
.day-sep {
  text-align: center;
  margin: 14px 0;
}
.day-sep span {
  background: #fff;
  color: var(--wa-muted);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 8px;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}

/* Komposer */
.composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: var(--wa-hover);
  position: relative;
  z-index: 2;
}

.composer input {
  flex: 1;
  padding: 11px 16px;
  border: none;
  border-radius: 24px;
  font-size: 14.5px;
  outline: none;
}

.send-btn {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--wa-green);
  color: #fff;
  font-size: 18px;
  transition: background .15s, transform .1s;
}
.send-btn:hover { background: var(--wa-green-dark); }
.send-btn:active { transform: scale(.92); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.2); border-radius: 3px; }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .msg-body { max-width: 85%; }
  .messages { padding: 18px 10px; }
}
