/* ═══════════════════════════════════════════════════════════
   SattiChat — Mobile CSS  (loaded after style.css)
   Single source of truth for all responsive overrides.
═══════════════════════════════════════════════════════════ */

/* ── Safe-area variables ─────────────────────────────────── */
:root {
  --sat: env(safe-area-inset-top,    0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

/* ══════════════════════════════════════════════════════════
   BASE LAYOUT — works on both desktop and mobile
══════════════════════════════════════════════════════════ */
html, body { height: 100%; overflow: hidden; }

.app-container {
  display: flex;
  height: 100dvh;
  height: 100vh;   /* fallback */
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 360px;
  min-width: 280px;
  max-width: 400px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--bd);
  background: #fff;
  height: 100%;
  overflow: hidden;
}

/* Chat window */
.chat-window {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  min-width: 0;
}

/* Chat area — flex column, fills chat-window */
.chat-area {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.chat-area.hidden { display: none; }

/* Messages scroll */
.messages-container {
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Input area — always pinned to bottom */
.message-input-area {
  flex: 0 0 auto;
  background: var(--bi);
  padding: 6px 8px;
  border-top: 1px solid var(--bd);
  position: relative;
  z-index: 10;
}

/* Input row */
.input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  flex-wrap: nowrap;
}

/* Textarea */
#msgInput {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 22px;
  padding: 11px 16px;
  font-size: 15px;
  outline: none;
  resize: none;
  background: #fff;
  max-height: 120px;
  line-height: 1.45;
  font-family: inherit;
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
  color: var(--t1);
  -webkit-appearance: none;
  appearance: none;
}

/* Send / Mic buttons */
.send-btn, .mic-btn {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: var(--g);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(37,211,102,.4);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.send-btn.hidden, .mic-btn.hidden { display: none !important; }
.mic-btn:active, .mic-btn.recording { background: var(--red) !important; box-shadow: 0 2px 8px rgba(229,57,53,.4); }
.send-btn:active { transform: scale(.94); }
.send-btn:disabled { background: #ccc; box-shadow: none; cursor: not-allowed; }

/* Attach / emoji */
.attach-btn, .emoji-btn {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--t2);
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}

/* Attach menu */
.attach-menu {
  position: absolute;
  bottom: 70px;
  left: 8px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  z-index: 50;
  min-width: 180px;
}
.attach-menu.hidden { display: none; }
.attach-menu-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 14px;
  color: var(--t1);
  -webkit-tap-highlight-color: transparent;
}
.attach-menu-item:active { background: var(--bi); }
.ami-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

/* Recording bar */
.rec-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
  border-left: 4px solid var(--red);
}
.rec-bar.hidden { display: none; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--red); animation: blink 1s infinite; flex-shrink: 0; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
#recTimer { font-weight: 700; color: var(--red); min-width: 38px; font-size: 14px; }
#recLabel { flex: 1; color: var(--t2); font-size: 13px; }
.rec-cancel { background: none; border: none; cursor: pointer; color: var(--red); font-size: 18px; padding: 4px 8px; border-radius: 6px; }

/* File preview */
.file-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--bd);
}
.file-preview.hidden { display: none; }
.file-preview-thumb { width: 40px; height: 40px; border-radius: 6px; object-fit: cover; }
.file-preview-info { flex: 1; min-width: 0; }
.file-preview-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; font-size: 13px; }
.file-preview-size { font-size: 11px; color: var(--t3); }
.file-preview button { background: none; border: none; cursor: pointer; color: var(--t3); font-size: 18px; padding: 4px; border-radius: 50%; }

/* Reply bar */
.reply-bar, .reply-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: 6px;
  border-left: 4px solid var(--g);
}
.reply-bar.hidden, .reply-preview.hidden { display: none; }
.reply-bar-content { flex: 1; min-width: 0; }
.reply-bar-name { font-size: 12px; font-weight: 700; color: var(--gm); }
.reply-bar-text, .reply-bar-text { font-size: 13px; color: var(--t2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-close, .reply-preview button { background: none; border: none; cursor: pointer; color: var(--t3); font-size: 18px; padding: 2px; }

/* Desktop hint */
.input-hint { text-align: center; font-size: 11px; color: var(--t3); padding: 2px 0 0; }

/* ══════════════════════════════════════════════════════════
   MOBILE  ≤ 768px
══════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Lock app to viewport */
  html, body { height: 100%; height: 100dvh; overflow: hidden; }

  .app-container {
    position: fixed !important;
    inset: 0;
    display: block !important;
    height: 100% !important;
    overflow: hidden;
  }

  /* Sidebar: full screen, shown by default */
  .sidebar {
    position: absolute !important;
    inset: 0;
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    height: 100% !important;
    z-index: 10;
    display: flex;
    flex-direction: column;
    border-right: none;
  }
  .sidebar.sc-hide { display: none !important; }

  /* Chat window: full screen, hidden until opened */
  .chat-window {
    position: absolute !important;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
    z-index: 20;
    display: none !important;
    flex-direction: column;
  }
  .chat-window.sc-show { display: flex !important; }

  /* Chat area fills window */
  .chat-area {
    position: absolute !important;
    inset: 0;
    display: flex !important;
    flex-direction: column !important;
    height: 100% !important;
    overflow: hidden !important;
  }

  /* Messages */
  .messages-container {
    flex: 1 1 auto !important;
    overflow-y: auto !important;
    min-height: 0 !important;
    padding: 8px 3% !important;
  }

  /* Input area — above keyboard, above home bar */
  .message-input-area {
    flex: 0 0 auto !important;
    padding: 6px 8px !important;
    padding-bottom: max(8px, var(--sab)) !important;
    z-index: 20 !important;
  }

  /* Input row */
  .input-row {
    gap: 5px !important;
    min-height: 50px;
  }

  /* Textarea — 16px prevents iOS zoom */
  #msgInput {
    font-size: 16px !important;
    padding: 10px 14px !important;
    max-height: 100px !important;
  }

  /* Bigger touch targets */
  .send-btn, .mic-btn {
    width: 50px !important;
    height: 50px !important;
    font-size: 22px !important;
  }
  .attach-btn, .emoji-btn {
    width: 44px !important;
    height: 44px !important;
    font-size: 22px !important;
  }

  /* Attach menu — slides up from bottom */
  .attach-menu {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    border-radius: 20px 20px 0 0 !important;
    padding: 16px 12px !important;
    padding-bottom: max(16px, var(--sab)) !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: space-around !important;
    gap: 8px !important;
    min-width: unset !important;
    box-shadow: 0 -4px 24px rgba(0,0,0,.18) !important;
    z-index: 200 !important;
  }
  .attach-menu-item {
    flex-direction: column !important;
    align-items: center !important;
    gap: 6px !important;
    padding: 12px 16px !important;
    font-size: 12px !important;
    min-width: 70px !important;
    border-radius: 12px !important;
  }
  .ami-icon {
    width: 52px !important;
    height: 52px !important;
    font-size: 22px !important;
  }

  /* Sidebar header */
  .sidebar-header {
    padding: 10px 14px !important;
    padding-top: max(10px, var(--sat)) !important;
    height: auto !important;
    min-height: 56px !important;
  }

  /* Chat header */
  .chat-header {
    padding: 8px 10px !important;
    padding-top: max(8px, var(--sat)) !important;
    height: auto !important;
    min-height: 56px !important;
  }
  .back-btn { display: flex !important; }

  /* Tabs */
  .sidebar-tabs { overflow-x: auto; scrollbar-width: none; }
  .sidebar-tabs::-webkit-scrollbar { display: none; }
  .stab { min-width: 52px; padding: 10px 6px !important; }
  .stab i { font-size: 20px !important; }
  .stab span { display: block !important; font-size: 9px !important; }

  /* Bubbles */
  .bubble { max-width: 88%; }
  .msg-text { font-size: 15px; }
  .msg-image { max-width: 100%; max-height: 260px; }
  .msg-video { max-width: 100%; }
  .msg-audio { max-width: 100%; min-width: 200px; width: 100%; }
  .doc-link { max-width: 100%; }

  /* Contact items */
  .contact-item { padding: 12px 14px; min-height: 68px; }
  .contact-avatar img, .contact-avatar .avatar-initials { width: 52px; height: 52px; font-size: 22px; }

  /* Context menu */
  .ctx-menu { min-width: 200px; }
  .ctx-item { padding: 14px 18px; font-size: 15px; }
  .ctx-emoji { font-size: 28px; }

  /* Modals — slide up */
  .modal { align-items: flex-end; padding: 0; }
  .modal-box {
    border-radius: 20px 20px 0 0;
    max-width: 100%;
    width: 100%;
    padding: 20px 18px;
    padding-bottom: max(20px, var(--sab));
    max-height: 85vh;
  }

  /* Room header */
  .room-header {
    padding: 8px 10px !important;
    padding-top: max(8px, var(--sat)) !important;
    min-height: 56px !important;
  }
  .room-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

  /* Info panel — full screen */
  .info-panel { position: fixed; inset: 0; z-index: 50; overflow-y: auto; border-radius: 0; width: 100% !important; }

  /* Toast */
  #toast { bottom: max(80px, calc(60px + var(--sab))); font-size: 13px; }

  /* Video overlay */
  .vid-overlay { padding-bottom: var(--sab); }
  .vid-ctrl-btn.record { width: 76px; height: 76px; font-size: 30px; }

  /* Lightbox */
  .lightbox-close { top: max(16px, var(--sat)); right: 16px; width: 48px; height: 48px; font-size: 24px; }

  /* Hide desktop hint */
  .input-hint { display: none !important; }

  /* Recording bar compact */
  .rec-bar { padding: 6px 10px; margin-bottom: 4px; }
  .file-preview { padding: 6px 10px; margin-bottom: 4px; }
  .file-preview-thumb { width: 32px; height: 32px; }
  .reply-bar, .reply-preview { padding: 6px 10px; margin-bottom: 4px; }
}

/* ── Very small phones ≤ 380px ───────────────────────────── */
@media (max-width: 380px) {
  .send-btn, .mic-btn { width: 46px !important; height: 46px !important; }
  .attach-btn, .emoji-btn { width: 38px !important; height: 38px !important; font-size: 18px !important; }
  #msgInput { padding: 8px 10px !important; }
  .stab span { display: none !important; }
  .stab { min-width: 44px; padding: 10px 4px !important; }
  .bubble { max-width: 92%; }
}

/* ── Landscape mobile ────────────────────────────────────── */
@media (max-width: 768px) and (orientation: landscape) {
  .sidebar-header, .chat-header, .room-header { padding-top: 6px !important; min-height: 48px !important; }
  .messages-container { padding: 4px 3% !important; }
  .message-input-area { padding: 4px 8px !important; padding-bottom: max(4px, var(--sab)) !important; }
  .contact-item { min-height: 56px; padding: 8px 14px; }
  .contact-avatar img, .contact-avatar .avatar-initials { width: 44px; height: 44px; }
  #msgInput { max-height: 60px !important; }
}
