/* ============================================================
   PRIVATE CHAT — Shared Stylesheet
   Font: Poppins | Icons: Remix Icon | Theme: Light
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap');
@import url('https://cdn.jsdelivr.net/npm/remixicon@4.2.0/fonts/remixicon.css');

/* ── CSS Variables ── */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface2: #f7f8fa;
  --border: #e4e6eb;
  --primary: #075e54;
  --primary-light: #128c7e;
  --accent: #25d366;
  --accent-light: #dcf8c6;
  --bubble-me: #dcf8c6;
  --bubble-other: #ffffff;
  --text: #111b21;
  --text-secondary: #667781;
  --text-meta: #8696a0;
  --header-bg: #075e54;
  --header-text: #ffffff;
  --input-bg: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.10);
  --radius: 18px;
  --radius-sm: 8px;
  --transition: 0.2s ease;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: 'Poppins', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  /* Prevent body scroll on Android WebView */
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
}

/* ============================================================
   LOGIN / LOADING SCREEN
   ============================================================ */

#loading-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(145deg, #075e54 0%, #128c7e 50%, #25d366 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.6s ease, transform 0.6s ease;
  padding: 24px;
  gap: 0;
}

#loading-screen.hide {
  opacity: 0;
  transform: scale(0.96);
  pointer-events: none;
}

.loading-logo {
  width: 90px;
  height: 90px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid rgba(255,255,255,0.5);
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  margin-bottom: 20px;
  animation: pulse-avatar 2s ease-in-out infinite;
}

@keyframes pulse-avatar {
  0%, 100% { box-shadow: 0 8px 32px rgba(0,0,0,0.25), 0 0 0 0 rgba(255,255,255,0.3); }
  50% { box-shadow: 0 8px 32px rgba(0,0,0,0.25), 0 0 0 12px rgba(255,255,255,0); }
}

.loading-app-name {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.loading-quote {
  font-size: 13px;
  font-weight: 400;
  color: rgba(255,255,255,0.85);
  text-align: center;
  max-width: 280px;
  line-height: 1.6;
  margin-bottom: 40px;
  min-height: 42px;
}

.loading-quote span {
  display: block;
  animation: fadeInUp 0.8s ease;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* PIN Input */
.pin-container {
  background: rgba(255,255,255,0.15);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 28px 32px;
  width: 100%;
  max-width: 320px;
  border: 1px solid rgba(255,255,255,0.25);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.pin-label {
  font-size: 14px;
  font-weight: 500;
  color: rgba(255,255,255,0.9);
  letter-spacing: 0.3px;
}

.pin-dots {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: center;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.7);
  background: transparent;
  transition: background 0.2s ease, transform 0.1s ease;
}

.pin-dot.filled {
  background: #fff;
  transform: scale(1.1);
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  width: 100%;
}

.pin-key {
  aspect-ratio: 1;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-family: 'Poppins', sans-serif;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.1s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 56px;
  border: 1px solid rgba(255,255,255,0.2);
  user-select: none;
}

.pin-key:active {
  background: rgba(255,255,255,0.4);
  transform: scale(0.94);
}

.pin-key.delete {
  background: rgba(255,255,255,0.08);
  font-size: 20px;
}

.pin-key.empty {
  background: transparent;
  border-color: transparent;
  pointer-events: none;
}

.pin-error {
  font-size: 12px;
  color: #ffcdd2;
  text-align: center;
  min-height: 18px;
  animation: shake 0.4s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}

/* ============================================================
   APP SHELL
   ============================================================ */

#app {
  display: none;
  flex-direction: column;
  height: 100%;
  width: 100%;
  position: fixed;
  inset: 0;
  background: var(--bg);
}

#app.visible {
  display: flex;
}

/* ── Header ── */
.app-header {
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0 16px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 10;
}

.header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-name {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-status {
  font-size: 11px;
  color: rgba(255,255,255,0.7);
  font-weight: 400;
}

.header-actions {
  display: flex;
  gap: 4px;
}

.header-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  padding: 8px;
  border-radius: 50%;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.header-btn:active {
  background: rgba(255,255,255,0.15);
}

/* ── Tab Bar ── */
.tab-bar {
  background: var(--header-bg);
  display: flex;
  border-top: 1px solid rgba(255,255,255,0.1);
  flex-shrink: 0;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: rgba(255,255,255,0.6);
  font-family: 'Poppins', sans-serif;
  font-size: 12px;
  font-weight: 500;
  padding: 10px 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: color 0.2s, border-bottom 0.2s;
  border-bottom: 2px solid transparent;
  position: relative;
}

.tab-btn i {
  font-size: 18px;
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-badge {
  position: absolute;
  top: 6px;
  right: calc(50% - 18px);
  background: #ff3b30;
  color: #fff;
  font-size: 9px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 3px;
}

/* ── Tab Content ── */
.tab-content {
  display: none;
  flex: 1;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.tab-content.active {
  display: flex;
}

/* ============================================================
   CHAT ROOM
   ============================================================ */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  background: var(--bg);
  /* custom scrollbar */
  scrollbar-width: thin;
  scrollbar-color: rgba(0,0,0,0.1) transparent;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.1); border-radius: 2px; }

/* Date Separator */
.date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 0;
  padding: 0 8px;
}

.date-separator::before,
.date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.date-separator span {
  font-size: 11px;
  color: var(--text-meta);
  background: var(--bg);
  padding: 2px 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  white-space: nowrap;
}

/* Bubble */
.bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 80%;
  animation: bubbleIn 0.2s ease;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.bubble-wrap.me {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.bubble-wrap.other {
  align-self: flex-start;
}

.bubble-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.bubble-wrap.me .bubble-avatar {
  display: none;
}

.bubble {
  background: var(--bubble-other);
  border-radius: 16px 16px 16px 4px;
  padding: 8px 12px;
  box-shadow: var(--shadow);
  max-width: 100%;
  word-break: break-word;
  position: relative;
}

.bubble-wrap.me .bubble {
  background: var(--bubble-me);
  border-radius: 16px 16px 4px 16px;
}

.bubble-text {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text);
  white-space: pre-wrap;
}

.bubble-image {
  max-width: 220px;
  max-height: 260px;
  width: 100%;
  border-radius: 12px;
  display: block;
  object-fit: cover;
  cursor: pointer;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
}

.bubble-time {
  font-size: 10px;
  color: var(--text-meta);
  white-space: nowrap;
}

.bubble-status {
  font-size: 12px;
  color: var(--text-meta);
}

.bubble-status.read {
  color: #53bdeb;
}

/* consecutive messages: reduce gap */
.bubble-wrap.same-sender {
  margin-top: -2px;
}

.bubble-wrap.same-sender .bubble-avatar {
  visibility: hidden;
}

/* ── Chat Input ── */
.chat-input-area {
  background: var(--surface2);
  border-top: 1px solid var(--border);
  padding: 8px 8px;
  padding-bottom: calc(8px + var(--safe-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
  position: relative;
  z-index: 5;
}

.chat-input-wrap {
  flex: 1;
  background: var(--input-bg);
  border-radius: 24px;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: flex-end;
  overflow: hidden;
  padding: 2px 4px 2px 14px;
  transition: border-color 0.2s;
  min-height: 44px;
  max-height: 120px;
}

.chat-input-wrap:focus-within {
  border-color: var(--primary-light);
}

.chat-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: 'Poppins', sans-serif;
  font-size: 14px;
  color: var(--text);
  resize: none;
  max-height: 100px;
  min-height: 24px;
  line-height: 1.5;
  padding: 9px 4px;
  /* Fix Android WebView keyboard issues */
  -webkit-appearance: none;
  appearance: none;
}

.chat-input::placeholder {
  color: var(--text-meta);
}

.attach-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
  padding: 8px 6px;
  display: flex;
  align-items: center;
  transition: color 0.2s;
  flex-shrink: 0;
}

.attach-btn:active { color: var(--primary); }

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(37,211,102,0.35);
}

.send-btn:active {
  background: #1da851;
  transform: scale(0.93);
}

/* Image preview before send */
.image-preview-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 12px;
  display: none;
  align-items: center;
  gap: 10px;
}

.image-preview-bar.show { display: flex; }

.preview-img {
  width: 50px;
  height: 50px;
  border-radius: 8px;
  object-fit: cover;
}

.preview-name {
  flex: 1;
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.preview-remove {
  background: none;
  border: none;
  color: #ff3b30;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
}

/* ============================================================
   STATUS ROOM
   ============================================================ */

.status-room {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* My Status / Other Status header strip */
.status-section-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 12px 16px 6px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

/* Status Card (like a tweet) */
.status-card {
  background: var(--surface);
  border-radius: 16px;
  margin: 4px 10px;
  padding: 14px;
  box-shadow: var(--shadow);
  animation: bubbleIn 0.2s ease;
}

.status-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.status-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--accent);
  flex-shrink: 0;
}

.status-user-info {
  flex: 1;
}

.status-username {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}

.status-time {
  font-size: 11px;
  color: var(--text-meta);
}

.status-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 8px;
}

.status-image {
  width: 100%;
  max-height: 300px;
  object-fit: cover;
  border-radius: 12px;
  margin-bottom: 8px;
  cursor: pointer;
}

.status-actions {
  display: flex;
  gap: 20px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.status-action-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: 'Poppins', sans-serif;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 0;
  transition: color 0.2s;
}

.status-action-btn i { font-size: 16px; }
.status-action-btn:active { color: var(--primary); }

.status-action-btn.liked i { color: #e91e63; }
.status-action-btn.liked { color: #e91e63; }

/* Comments section */
.status-comments {
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.status-comment {
  background: var(--surface2);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  gap: 8px;
}

.comment-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.comment-content { flex: 1; }

.comment-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 2px;
}

.comment-text {
  font-size: 12px;
  color: var(--text);
  line-height: 1.4;
  word-break: break-word;
}

.comment-time {
  font-size: 10px;
  color: var(--text-meta);
  margin-top: 2px;
}

/* ── Status Input Area ── */
.status-input-area {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 10px 10px;
  padding-bottom: calc(10px + var(--safe-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.status-input-wrap {
  flex: 1;
  background: var(--surface2);
  border-radius: 22px;
  border: 1.5px solid var(--border);
  display: flex;
  align-items: flex-end;
  padding: 2px 4px 2px 14px;
  min-height: 44px;
  max-height: 100px;
  transition: border-color 0.2s;
}

.status-input-wrap:focus-within {
  border-color: var(--primary-light);
}

.status-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: 'Poppins', sans-serif;
  font-size: 13px;
  color: var(--text);
  resize: none;
  max-height: 80px;
  min-height: 24px;
  line-height: 1.5;
  padding: 9px 4px;
  -webkit-appearance: none;
  appearance: none;
}

.status-input::placeholder { color: var(--text-meta); }

.status-post-btn {
  height: 44px;
  padding: 0 18px;
  border-radius: 22px;
  background: var(--primary);
  border: none;
  color: #fff;
  font-family: 'Poppins', sans-serif;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.status-post-btn:active {
  background: var(--primary-light);
  transform: scale(0.95);
}

.status-post-btn i { font-size: 16px; }

/* ── Comment Input (inline) ── */
.comment-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0 0;
  border-top: 1px solid var(--border);
  margin-top: 6px;
}

.comment-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 7px 14px;
  font-family: 'Poppins', sans-serif;
  font-size: 12px;
  color: var(--text);
  background: var(--surface2);
  outline: none;
  -webkit-appearance: none;
  transition: border-color 0.2s;
}

.comment-input:focus { border-color: var(--primary-light); }

.comment-send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s;
}

.comment-send-btn:active { background: #1da851; }

/* Status image preview */
.status-img-preview-bar {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 12px;
  display: none;
  align-items: center;
  gap: 10px;
}

.status-img-preview-bar.show { display: flex; }

/* ============================================================
   IMAGE LIGHTBOX
   ============================================================ */

.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.lightbox.show { display: flex; }

.lightbox img {
  max-width: 96vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 8px;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   UPLOAD PROGRESS TOAST
   ============================================================ */

.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(0,0,0,0.78);
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 12px;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
  z-index: 990;
  white-space: nowrap;
  max-width: 90vw;
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px 20px;
  color: var(--text-meta);
  flex: 1;
}

.empty-state i {
  font-size: 48px;
  opacity: 0.3;
}

.empty-state p {
  font-size: 13px;
  text-align: center;
}

/* ============================================================
   TYPING INDICATOR
   ============================================================ */

.typing-indicator {
  display: none;
  align-self: flex-start;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
}

.typing-indicator.show { display: flex; }

.typing-bubble {
  background: var(--bubble-other);
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  display: flex;
  gap: 4px;
  align-items: center;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-meta);
  animation: typingBounce 1.2s ease infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* ============================================================
   WEBVIEW / ANDROID KEYBOARD FIX
   ============================================================ */

/* When input is focused, push content up */
.keyboard-open .chat-messages {
  padding-bottom: 8px;
}

/* Prevent zoom on input focus in WebView */
input, textarea, select {
  font-size: 16px; /* >= 16px prevents iOS zoom; we override with JS for Android */
}

/* Hide file inputs */
input[type="file"] {
  display: none;
}

/* ============================================================
   UTILITY
   ============================================================ */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}