/* ============================================
   TeamMid Mobile Enhancements — Sprint 64
   Bottom Nav, Swipe Gestures, Mobile-First UX
   ============================================ */

/* CRITICAL: Prevent horizontal scroll everywhere */
html, body, .app-layout, .main-content, .page-content {
  overflow-x: hidden !important;
  max-width: 100vw !important;
}

/* ===== MOBILE BOTTOM NAVIGATION ===== */
.mobile-bottom-nav {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 200;
  padding: 4px 0;
  padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.mobile-bottom-nav .bottom-nav-items {
  display: flex; justify-content: space-around; align-items: center;
}
.mobile-bottom-nav .bottom-nav-item {
  display: flex; flex-direction: column; align-items: center;
  padding: 6px 12px; gap: 2px;
  color: var(--text-muted); font-size: 10px; font-weight: 500;
  text-decoration: none; transition: color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  position: relative;
}
.mobile-bottom-nav .bottom-nav-item.active {
  color: var(--primary);
}
.mobile-bottom-nav .bottom-nav-item.active::before {
  content: ''; position: absolute; top: 0; left: 50%;
  transform: translateX(-50%); width: 24px; height: 3px;
  background: var(--primary); border-radius: 0 0 3px 3px;
}
.mobile-bottom-nav .bottom-nav-item svg,
.mobile-bottom-nav .bottom-nav-item i {
  width: 20px; height: 20px;
}
.bottom-nav-badge {
  position: absolute; top: 2px; right: 6px;
  background: var(--danger); color: #fff;
  font-size: 8px; font-weight: 700;
  min-width: 14px; height: 14px;
  border-radius: 7px; display: flex;
  align-items: center; justify-content: center;
  padding: 0 3px;
}

/* ===== MOBILE SEARCH MODAL ===== */
.mobile-search-overlay {
  display: none; position: fixed; inset: 0;
  background: var(--bg-body); z-index: 500;
  padding: env(safe-area-inset-top, 0) 12px 12px;
}
.mobile-search-overlay.active { display: block; }
.mobile-search-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 0; margin-bottom: 8px;
}
.mobile-search-bar input {
  flex: 1; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 16px; font-size: 16px;
  color: var(--text-primary); outline: none;
}
.mobile-search-bar input:focus {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-glow);
}
.mobile-search-cancel {
  background: none; border: none; color: var(--primary);
  font-size: 14px; font-weight: 600; padding: 8px;
  cursor: pointer;
}

/* ===== MOBILE-SPECIFIC OVERRIDES ===== */
@media (max-width: 768px) {
  /* Show bottom nav */
  .mobile-bottom-nav { display: block; }

  /* Adjust page content for bottom nav */
  .page-content {
    padding-bottom: calc(70px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Mobile search trigger in header */
  .mobile-search-btn { display: flex !important; }

  /* 3-column dashboard grids → 1 column */
  div[style*="grid-template-columns:1fr 1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  /* 4-column widget grid → 2 columns */
  div[style*="grid-template-columns:1fr 1fr 1fr 1fr"],
  div[style*="grid-template-columns: 1fr 1fr 1fr 1fr"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  /* 4-column team KPI grid → 2 columns */
  div[style*="grid-template-columns:repeat(4,1fr)"],
  div[style*="grid-template-columns: repeat(4,1fr)"],
  div[style*="grid-template-columns:repeat(4, 1fr)"] {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  /* Flex wrap for chip-style elements */
  div[style*="display:flex;flex-wrap:wrap"] {
    gap: 6px !important;
  }

  /* Tab buttons horizontal scroll */
  .tab-scroll {
    display: flex; overflow-x: auto; gap: 6px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tab-scroll::-webkit-scrollbar { display: none; }
  .tab-scroll .btn { white-space: nowrap; flex-shrink: 0; }

  /* Card headers stack on mobile */
  .card-header {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 8px;
  }

  /* Timeline more compact */
  .timeline-item { padding: 8px 0; }

  /* Notification dropdown mobile */
  .profile-dropdown .profile-menu[style*="width:340px"] {
    position: fixed !important;
    left: 8px !important; right: 8px !important;
    width: auto !important;
    top: calc(var(--header-h) + 4px) !important;
    max-height: 60vh !important;
  }

  /* Theme toggle compact */
  .theme-toggle {
    width: 32px; height: 32px;
    font-size: 14px; border: none;
  }

  /* Full-width buttons on mobile */
  .btn-full-mobile { width: 100% !important; justify-content: center; }

  /* Hide desktop-only elements */
  .desktop-only { display: none !important; }

  /* Sticky action bar at bottom of forms */
  .mobile-sticky-actions {
    position: sticky; bottom: 70px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 10px 0; margin-top: 12px;
    z-index: 10;
  }
}

/* Show on desktop only */
@media (min-width: 769px) {
  .mobile-only { display: none !important; }
  .mobile-search-btn { display: none !important; }
}

/* ===== PULL TO REFRESH INDICATOR ===== */
.pull-indicator {
  position: fixed; top: 0; left: 0; right: 0;
  height: 3px; background: var(--primary);
  transform: scaleX(0); transform-origin: left;
  transition: transform 0.2s ease;
  z-index: 1000;
}
.pull-indicator.active { transform: scaleX(1); }

/* ===== SWIPE ANIMATIONS ===== */
.swipe-card {
  transition: transform 0.15s ease;
  touch-action: pan-y;
}

/* ===== FLOATING ACTION BUTTON ===== */
.fab {
  display: none; position: fixed;
  bottom: calc(70px + env(safe-area-inset-bottom, 0px));
  right: 16px; width: 52px; height: 52px;
  border-radius: 50%; border: none;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff; font-size: 22px;
  box-shadow: 0 4px 16px rgba(79,70,229,0.4);
  cursor: pointer; transition: all 0.3s ease;
  z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
@media (max-width: 768px) {
  .fab { display: flex; }
  .fab:active { transform: scale(0.92); }
}
@media (min-width: 769px) {
  .fab { display: none !important; }
}

/* ===== DARK MODE MOBILE ===== */
[data-theme="dark"] .mobile-bottom-nav {
  background: rgba(30,41,59,0.95);
  border-color: var(--border);
}
[data-theme="dark"] .mobile-search-overlay {
  background: var(--bg-body);
}
[data-theme="dark"] .mobile-search-bar input {
  background: var(--bg-input);
  border-color: var(--border);
  color: var(--text-primary);
}

/* ============================================
   Chat / Mesajlar — Mobile Responsive
   ============================================ */
@media (max-width: 768px) {
  /* Chat container: stack vertically */
  div[style*="display:flex;height:calc(100vh - 70px)"] {
    flex-direction: column !important;
    height: calc(100vh - 60px) !important;
    margin: -12px -12px !important;
  }

  /* Left panel (room list): full width, scrollable */
  div[style*="width:320px;border-right"] {
    width: 100% !important;
    max-height: 100% !important;
    border-right: none !important;
    border-bottom: 1px solid var(--border-light);
  }

  /* When a room is selected: hide room list on mobile */
  .chat-room-selected div[style*="width:320px;border-right"] {
    display: none !important;
  }

  /* Right panel (messages): full screen overlay on mobile */
  .chat-room-selected div[style*="flex:1;display:flex;flex-direction:column;background:var(--bg-main)"] {
    position: fixed !important;
    inset: 0 !important;
    z-index: 300 !important;
    background: var(--bg-body) !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* Message bubble max-width on mobile */
  .msg-bubble {
    max-width: 85% !important;
    font-size: 13px !important;
  }

  /* Input area on mobile */
  div[style*="padding:10px 16px;border-top:1px solid var(--border-light);background:var(--bg-card);display:flex"] {
    padding: 8px 10px !important;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px)) !important;
  }

  /* Message input */
  #msgInput {
    font-size: 16px !important; /* prevent iOS zoom */
  }

  /* Emoji picker mobile full-width */
  #emojiPicker {
    left: 8px !important;
    right: 8px !important;
    bottom: 70px !important;
    max-width: none !important;
  }

  /* Reaction picker */
  #reactionPicker {
    left: 50% !important;
    transform: translateX(-50%);
  }

  /* Room search compact */
  .room-item {
    padding: 8px 10px !important;
  }

  /* Mobile back button in chat header */
  .chat-mobile-back {
    display: flex !important;
  }

  /* Group modal mobile */
  #newGroupModal > div.card {
    width: 95% !important;
    max-width: none !important;
    max-height: 80vh;
    overflow-y: auto;
  }

  /* Messages area proper height */
  #messagesArea {
    padding: 10px 12px !important;
  }

  /* Video call container mobile */
  .video-container {
    max-width: 100% !important;
    border-radius: 0 !important;
  }
  .video-container .self-video {
    width: 100px !important;
    height: 75px !important;
  }
}

@media (min-width: 769px) {
  .chat-mobile-back {
    display: none !important;
  }
}

/* ============================================
   Kanban / Tasks — Mobile Responsive
   ============================================ */
@media (max-width: 768px) {
  /* Kanban board: horizontal scroll */
  .kanban-board {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
    min-height: auto !important;
  }
  .kanban-column {
    padding: 8px !important;
    min-height: auto !important;
  }
  /* Kanban cards: no drag on mobile, tap to open */
  .kanban-card {
    cursor: pointer !important;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
  }

  /* Task Detail Modal — full screen on mobile */
  #taskDetailModal > .card {
    max-width: 100% !important;
    max-height: 100vh !important;
    height: 100vh !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }
  #taskDetailModal {
    padding: 0 !important;
  }

  /* Attachment buttons on mobile */
  .att-cell {
    flex-direction: column !important;
  }
  .att-files {
    gap: 4px !important;
  }
  .att-chip {
    font-size: 11px !important;
  }
  .att-actions, .att-cell > div:last-child {
    margin-top: 4px !important;
  }

  /* Table responsive — allow horizontal scroll */
  .table-container {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
  }
}
