:root {
  --blue: #0A84FF;
  --blue-deep: #0060DF;
  --green: #34C759;
  --red: #FF3B30;
  --amber: #FF9F0A;
  --ink: #1C1C1E;
  --ink-soft: #3A3A3C;
  --muted: #8E8E93;
  --glass-bg: rgba(255, 255, 255, 0.55);
  --glass-bg-strong: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(255, 255, 255, 0.45);
  --glass-shadow: 0 8px 32px rgba(31, 41, 55, 0.12);
  --radius-lg: 26px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: var(--font); -webkit-font-smoothing: antialiased; }
html, body { height: 100%; overflow: hidden; }
body { color: var(--ink); position: relative; }

/* --- Animasi --- */
@keyframes fadeSlideUp { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes messageIn { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }
@keyframes stickerPop {
  0% { opacity: 0; transform: scale(0.3) rotate(-8deg); }
  60% { opacity: 1; transform: scale(1.18) rotate(3deg); }
  100% { transform: scale(1) rotate(0deg); }
}
@keyframes modalIn { from { opacity: 0; transform: scale(0.88); } to { opacity: 1; transform: scale(1); } }
@keyframes overlayFade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pickerSlideUp { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes ringPulse {
  0% { box-shadow: 0 0 0 0 rgba(52,199,89,0.55); }
  70% { box-shadow: 0 0 0 14px rgba(52,199,89,0); }
  100% { box-shadow: 0 0 0 0 rgba(52,199,89,0); }
}
@keyframes typingDot {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30% { opacity: 1; transform: translateY(-2px); }
}
@keyframes bounceIn {
  0% { opacity: 0; transform: scale(0.6); }
  50% { transform: scale(1.05); }
  100% { opacity: 1; transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}

/* --- Wallpaper ala iOS: gradient lembut di belakang semua panel kaca --- */
.wallpaper {
  position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(circle at 15% 20%, #a6c8ff 0%, transparent 45%),
    radial-gradient(circle at 85% 15%, #ffd6e8 0%, transparent 40%),
    radial-gradient(circle at 50% 90%, #c9f7e6 0%, transparent 45%),
    linear-gradient(160deg, #eef2fb 0%, #f7f2fa 50%, #eef8f5 100%);
}
body:has(.auth-container) .wallpaper,
body:has(.admin-wrapper) .wallpaper { position: fixed; }

/* --- Kaca (glassmorphism) --- */
.glass {
  background: var(--glass-bg);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
  border: 1px solid var(--glass-border);
}

/* --- Auth pages --- */
.auth-container {
  max-width: 380px;
  margin: 70px auto;
  background: var(--glass-bg-strong);
  backdrop-filter: blur(30px) saturate(180%);
  -webkit-backdrop-filter: blur(30px) saturate(180%);
  border: 1px solid var(--glass-border);
  padding: 34px 30px;
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow);
  animation: fadeSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
.auth-container h1 { margin-bottom: 22px; font-size: 24px; font-weight: 700; text-align: center; letter-spacing: -0.02em; color: var(--ink); }
.auth-container input {
  width: 100%; padding: 13px 16px; margin-bottom: 12px;
  border: 1px solid rgba(0,0,0,0.08); border-radius: var(--radius-sm); font-size: 16px;
  background: rgba(255,255,255,0.6);
}
.auth-container input:focus { outline: none; border-color: var(--blue); background: #fff; }
.auth-container button {
  width: 100%; padding: 13px; background: var(--blue); color: #fff;
  border: none; border-radius: var(--radius-sm); font-size: 16px; font-weight: 600; cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}
.auth-container button:hover { opacity: 0.88; }
.auth-container button:active { transform: scale(0.97); }
.error {
  color: var(--red); font-size: 13px; margin-bottom: 12px; padding: 10px 12px;
  background: rgba(255,59,48,0.1); border-radius: var(--radius-sm);
  animation: fadeSlideUp 0.25s ease;
}
.divider { text-align: center; margin: 18px 0; color: var(--muted); font-size: 13px; }
.oauth-buttons a {
  display: block; text-align: center; padding: 12px; margin-bottom: 10px;
  border-radius: var(--radius-sm); text-decoration: none; font-size: 14px; font-weight: 600; color: #fff;
  transition: opacity 0.15s, transform 0.1s;
}
.oauth-buttons a:hover { opacity: 0.88; }
.oauth-buttons a:active { transform: scale(0.97); }
.oauth-google { background: #db4437; }
.oauth-facebook { background: #1877f2; }
.oauth-twitter { background: #1da1f2; }
.switch-link { text-align: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.switch-link a { color: var(--blue); font-weight: 600; text-decoration: none; }

/* --- Chat layout --- */
.chat-wrapper {
  display: flex; height: 100vh; height: 100dvh; min-height: 0;
  padding: 14px; gap: 14px;
  animation: fadeSlideUp 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.sidebar {
  width: 320px; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0;
  border-radius: var(--radius-lg); box-shadow: var(--glass-shadow); overflow: hidden;
}
.sidebar-header {
  padding: 16px; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
}
.me-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-chip strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-icons { display: flex; gap: 6px; align-items: center; }

.avatar-circle {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; color: #fff;
  background: linear-gradient(135deg, var(--blue), #7c5cff);
  transition: transform 0.15s ease;
}
.avatar-circle:hover { transform: scale(1.08); }
.room-avatar { background: linear-gradient(135deg, #34C759, #0A84FF); font-size: 16px; }

.icon-btn {
  background: rgba(120,120,128,0.12); border: none; width: 32px; height: 32px; border-radius: 50%;
  cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center;
  text-decoration: none; color: var(--ink); transition: background 0.15s, transform 0.1s;
}
.icon-btn:hover { background: rgba(120,120,128,0.22); }
.icon-btn:active { transform: scale(0.9); }

.search-box { padding: 10px 14px; flex-shrink: 0; }
.search-box input {
  width: 100%; padding: 9px 14px; border: none; border-radius: 999px; font-size: 15px;
  background: rgba(120,120,128,0.14);
}
.search-box input:focus { outline: none; background: rgba(120,120,128,0.2); }

.section-label { padding: 12px 16px 6px; font-size: 12px; color: var(--muted); font-weight: 600; flex-shrink: 0; }

.conversation-item {
  padding: 10px 14px; margin: 2px 8px; cursor: pointer; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 10px; transition: background 0.15s ease, transform 0.1s;
}
.conversation-item:active { transform: scale(0.98); }
.conversation-item .convo-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.conversation-item:hover, .conversation-item.active-item { background: rgba(10,132,255,0.12); }
.conversation-item .convo-name { font-weight: 600; font-size: 14px; }
.conversation-item .convo-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-hint { padding: 10px 16px; font-size: 12px; color: var(--muted); animation: fadeSlideUp 0.25s ease; }

.user-list { flex: 0 0 auto; max-height: 220px; overflow-y: auto; }
.user-item, .room-item {
  padding: 10px 14px; margin: 2px 8px; cursor: pointer; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500;
  transition: background 0.15s ease, transform 0.1s;
}
.user-item:active, .room-item:active { transform: scale(0.98); }
.user-item:hover, .room-item:hover, .active-item { background: rgba(10,132,255,0.12); }
.logout-btn { background: none; border: none; cursor: pointer; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; border-radius: var(--radius-lg); box-shadow: var(--glass-shadow); overflow: hidden; }
.chat-header {
  padding: 12px 16px; border-bottom: 1px solid rgba(0,0,0,0.06); font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; gap: 8px;
}
.chat-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chat-header-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 15px; }
.chat-header-actions { display: flex; gap: 8px; flex-shrink: 0; }
.back-btn { display: none; background: none; border: none; font-size: 26px; cursor: pointer; padding: 0 4px; color: var(--blue); }

.pinned-banner {
  background: rgba(255,159,10,0.12); border-bottom: 1px solid rgba(255,159,10,0.25); padding: 8px 16px;
  font-size: 12px; display: none; flex-direction: column; gap: 4px; flex-shrink: 0; max-height: 90px; overflow-y: auto;
}
.pinned-banner.has-pins { display: flex; }
.pinned-item { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.pinned-item .pinned-text { color: #92400e; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; }

.message {
  max-width: 68%; padding: 9px 14px; border-radius: 20px; background: rgba(120,120,128,0.14);
  position: relative; color: var(--ink); font-size: 15px; line-height: 1.35;
  animation: messageIn 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
.message.own {
  align-self: flex-end; color: #fff;
  background: linear-gradient(135deg, var(--blue), var(--blue-deep));
}
.message.sticker {
  background: none; padding: 2px; font-size: 52px; line-height: 1; max-width: none;
  animation: stickerPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.message .meta { font-size: 11px; opacity: 0.65; margin-bottom: 2px; display: flex; gap: 6px; align-items: center; }
.message .mention { font-weight: 700; text-decoration: none; cursor: pointer; }
.message.own .mention { color: #fff; text-decoration: underline; }
.message:not(.own) .mention { color: var(--blue); }
.message-actions { display: none; gap: 6px; margin-top: 4px; }
.message:hover .message-actions { display: flex; }
.message-actions button {
  background: rgba(0,0,0,0.08); border: none; border-radius: 8px; font-size: 10px; padding: 3px 8px; cursor: pointer;
}
.message.own .message-actions button { background: rgba(255,255,255,0.22); color: #fff; }
.pin-badge { font-size: 10px; }

.message img.chat-media { max-width: 240px; border-radius: 14px; display: block; margin-top: 4px; }
.message video.chat-media { max-width: 260px; border-radius: 14px; display: block; margin-top: 4px; }
.message .file-attachment {
  display: flex; align-items: center; gap: 8px; margin-top: 4px; padding: 9px 12px; background: rgba(0,0,0,0.06); border-radius: 14px;
  text-decoration: none; color: inherit; font-size: 13px;
}
.message.own .file-attachment { background: rgba(255,255,255,0.18); }

.typing-indicator { font-size: 12px; color: var(--muted); padding: 0 18px; height: 20px; flex-shrink: 0; display: flex; align-items: center; gap: 6px; }
.typing-indicator .dot {
  width: 5px; height: 5px; border-radius: 50%; background: var(--muted); display: inline-block;
  animation: typingDot 1s infinite ease-in-out;
}
.typing-indicator .dot:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator .dot:nth-child(3) { animation-delay: 0.3s; }

.message-form {
  display: flex; align-items: center; padding: 10px 14px; gap: 8px; flex-shrink: 0;
  border-top: 1px solid rgba(0,0,0,0.06);
}
.message-form input[type="text"] {
  flex: 1; min-width: 0; padding: 11px 16px; border: none; border-radius: 999px; font-size: 16px;
  background: rgba(120,120,128,0.14);
}
.message-form input[type="text"]:focus { outline: none; background: rgba(120,120,128,0.2); }
.send-btn {
  width: 38px; height: 38px; border-radius: 50%; background: var(--blue); color: #fff; border: none;
  cursor: pointer; font-size: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: transform 0.12s ease;
}
.send-btn:active { transform: scale(0.85); }
.round-btn {
  background: rgba(120,120,128,0.14); color: var(--ink); border: none; width: 38px; height: 38px; border-radius: 50%;
  cursor: pointer; font-size: 18px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.12s;
}
.round-btn:hover { background: rgba(120,120,128,0.22); }
.round-btn:active { transform: scale(0.88); }

/* --- Sticker picker (popover kaca) --- */
.sticker-picker {
  display: none; grid-template-columns: repeat(6, 1fr); gap: 4px; padding: 12px;
  max-height: 220px; overflow-y: auto; border-top: 1px solid rgba(0,0,0,0.06);
  background: var(--glass-bg-strong); backdrop-filter: blur(24px);
}
.sticker-picker.show { display: grid; animation: pickerSlideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
.sticker-picker button {
  background: none; border: none; font-size: 30px; cursor: pointer; padding: 6px; border-radius: 12px;
  transition: transform 0.12s, background 0.12s;
}
.sticker-picker button:hover { background: rgba(120,120,128,0.14); transform: scale(1.2); }
.sticker-picker button:active { transform: scale(0.9); }

/* --- Modal telepon (kaca) --- */
.modal-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.25);
  align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(4px);
}
.modal-overlay.show { display: flex; animation: overlayFade 0.2s ease; }
.call-modal {
  background: var(--glass-bg-strong); backdrop-filter: blur(30px) saturate(180%);
  border-radius: var(--radius-lg); padding: 30px; text-align: center; width: 280px;
  box-shadow: var(--glass-shadow); border: 1px solid var(--glass-border);
  animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.call-modal .call-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: linear-gradient(135deg, var(--blue), #7c5cff); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 28px; margin: 0 auto 14px;
  animation: ringPulse 1.6s infinite;
}
.call-modal h3 { margin-bottom: 4px; font-size: 17px; }
.call-modal p { font-size: 13px; color: var(--muted); margin-bottom: 20px; }
.call-modal .call-buttons { display: flex; justify-content: center; gap: 18px; }
.call-btn {
  width: 54px; height: 54px; border-radius: 50%; border: none; cursor: pointer; font-size: 20px; color: #fff;
  transition: transform 0.12s ease;
}
.call-btn:active { transform: scale(0.88); }
.call-btn.accept { background: var(--green); }
.call-btn.reject { background: var(--red); }
.call-status-bar {
  display: none; align-items: center; justify-content: space-between;
  background: rgba(28,28,30,0.85); backdrop-filter: blur(20px); color: #fff;
  padding: 10px 16px; font-size: 13px; flex-shrink: 0;
}
.call-status-bar.show { display: flex; animation: fadeSlideUp 0.25s ease; }
.call-status-bar button { background: var(--red); border: none; color: #fff; padding: 6px 14px; border-radius: 16px; cursor: pointer; font-size: 12px; }

/* --- Mobile responsive --- */
@media (max-width: 768px) {
  .chat-wrapper { position: relative; padding: 8px; gap: 8px; }
  .sidebar {
    position: absolute; inset: 8px; width: auto; z-index: 20;
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }
  .sidebar.hide-mobile { transform: translateX(-110%); }
  .chat-main { position: absolute; inset: 8px; width: auto; z-index: 10; transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1); }
  .chat-main.hide-mobile { transform: translateX(110%); }
  .back-btn { display: inline-block; }
  .message { max-width: 85%; }
  .me-chip strong { font-size: 14px; }
  .chat-header { padding: 10px 12px; }
  .messages { padding: 12px; }
  .message-form { padding: 8px; }
  .sticker-picker { grid-template-columns: repeat(5, 1fr); }
}
