/* ===================================================================
   Aria App v9 — Mobile-Specific Overrides
   Bottom nav, swipeable channels, pull-to-refresh, touch optimizations
   =================================================================== */

/* ═══ Mobile Bottom Navigation Bar ═══ */
#mobile-bottom-bar {
  display: none;
  position: fixed; bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-h);
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  z-index: 30;
  align-items: center;
  justify-content: space-around;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  backdrop-filter: blur(10px);
}

.mobile-bottom-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 20px; cursor: pointer;
  padding: 8px 12px;
  border-radius: var(--radius);
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: var(--touch-target);
  min-height: var(--touch-target);
  position: relative;
}

.mobile-bottom-btn .nav-label {
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.7;
}

.mobile-bottom-btn.active {
  color: var(--theme-primary);
  background: rgba(var(--theme-primary-rgb), 0.12);
}

.mobile-bottom-btn:hover { color: var(--text); }

/* Unread badge on bottom nav */
.mobile-bottom-btn .nav-badge {
  position: absolute; top: 2px; right: 2px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: var(--red);
  color: #fff; font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 6px var(--red-glow);
}
.mobile-bottom-btn .nav-badge.hidden { display: none; }

/* ═══ Slide-out Channel List (mobile) ═══ */
#mobile-drawer-overlay {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(8, 8, 13, 0.5);
  backdrop-filter: blur(4px);
  display: none;
}
#mobile-drawer-overlay:not(.hidden) { display: block; }

/* ═══ Swipeable Channel Views ═══ */
#content-area {
  touch-action: pan-y;
}

.channel-view {
  will-change: transform;
}

/* Swipe transition */
.channel-view.swiping {
  transition: none !important;
}

/* ═══ Pull-to-Refresh ═══ */
.pull-to-refresh {
  position: relative;
  overflow: hidden;
}

.pull-to-refresh-indicator {
  position: absolute;
  top: -60px;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--theme-primary);
  font-size: 13px;
  font-weight: 600;
  transition: transform 0.2s ease;
  z-index: 5;
}

.pull-to-refresh-indicator .ptr-spinner {
  width: 20px; height: 20px;
  border: 2px solid rgba(var(--theme-primary-rgb), 0.2);
  border-top-color: var(--theme-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.pull-to-refresh-indicator .ptr-icon {
  font-size: 20px;
  transition: transform 0.2s ease;
}

.pull-to-refresh-indicator.pulling .ptr-icon {
  transform: rotate(180deg);
}

.pull-to-refresh-indicator.refreshing .ptr-icon {
  display: none;
}

/* ═══ Compact Message Bubbles (mobile) ═══ */
@media (max-width: 767px) {
  .bubble { max-width: 88%; }
  .bubble-content { padding: 8px 12px; font-size: 14px; }
  .msg-text { font-size: 14px; }
  .msg-media img, .msg-media video { max-width: 200px; }
  .message .msg-actions { display: flex; opacity: 0.6; }
  .message .msg-actions { position: static; margin-top: 4px; gap: 4px; }
  .user-message .msg-actions { left: auto; right: -4px; }
  .msg-action-btn { width: 28px; height: 28px; font-size: 14px; }
  .voice-msg-player { min-width: 140px; padding: 8px 10px; }
}

/* ═══ Full-width Inputs (mobile) ═══ */
@media (max-width: 480px) {
  #chat-input-area { padding: 8px 8px 12px; }
  #chat-input-wrapper { padding: 2px 2px 2px 6px; }
  #chat-input { font-size: 16px; } /* Prevents iOS zoom */
  #thought-input-area { padding: 8px 8px 12px; }
  #thought-input-wrapper { padding: 6px 6px 6px 10px; }
  #thought-input { font-size: 16px; }
  #search-input { font-size: 16px; }
  .settings-input { font-size: 16px; }
  .login-input { font-size: 16px; }
}

/* ═══ Mobile-specific layout adjustments ═══ */
@media (max-width: 767px) {
  #app {
    padding-bottom: var(--bottom-nav-h);
  }

  #mobile-bottom-bar {
    display: flex;
  }

  #server-bar {
    display: none;
  }

  #channel-list {
    left: 0;
    z-index: 95;
    box-shadow: 4px 0 30px rgba(0,0,0,0.6);
  }

  #channel-header {
    padding: 0 12px;
  }

  .channel-header-hash { font-size: 18px; }
  .channel-header-name { font-size: 14px; }

  .mobile-menu-btn {
    display: flex !important;
    background: none; border: none; color: var(--text-muted);
    padding: 8px; border-radius: 50%; cursor: pointer;
    align-items: center; justify-content: center;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
  }
  .mobile-menu-btn:hover { color: var(--text); background: var(--bg-hover); }

  /* Settings page on mobile */
  #settings-view { padding: 16px; }
  .settings-card { padding: 12px; }
  .settings-row { flex-direction: column; align-items: flex-start; gap: 8px; }
  .settings-input { max-width: 100%; width: 100%; }

  /* Dashboard on mobile */
  #home-content { padding: 12px; }
  .dashboard-grid { gap: 10px; }
  .dashboard-status-card { padding: 14px; flex-direction: column; text-align: center; }
  .dashboard-status-energy { justify-content: center; }
  .dashboard-action-btn { min-width: 100%; }

  /* Finance on mobile */
  .tx-card { flex-direction: column; align-items: flex-start; gap: 8px; }
  .tx-amount { min-width: auto; text-align: left; }

  /* Mail on mobile */
  .mail-card-header { flex-wrap: wrap; }
  .mail-card-date { width: 100%; margin-top: 4px; }

  /* Timeline on mobile */
  .timeline-item { gap: 10px; }
  .timeline-dot { width: 28px; height: 28px; font-size: 14px; }

  /* Briefings on mobile */
  .briefing-card-header { flex-direction: column; }
  .briefing-thumb-placeholder { width: 100%; height: 120px; }

  /* Call screen on mobile */
  .call-screen { padding: 24px 16px; }
  .call-avatar svg { width: 80px; height: 80px; }
  .call-name { font-size: 22px; }
  .call-controls { gap: 14px; }
  .call-control-btn { width: 48px; height: 48px; }

  /* Search on mobile */
  #search-header { padding: 12px; }
  #search-results { padding: 12px; }

  /* Info panel on mobile */
  #info-panel-right {
    position: fixed;
    right: 0; top: 0; bottom: 0;
    z-index: 96;
    width: 280px;
    display: none;
    box-shadow: -4px 0 20px rgba(0,0,0,0.5);
  }
  #info-panel-right.mobile-open { display: flex; }
}

/* ═══ Safe area for notched devices ═══ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  #mobile-bottom-bar {
    padding-bottom: env(safe-area-inset-bottom, 0px);
    height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0px));
  }
  #chat-input-area {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
  #thought-input-area {
    padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  }
}

/* ═══ Landscape mobile ═══ */
@media (max-width: 767px) and (orientation: landscape) {
  #server-bar { display: flex; }
  #mobile-bottom-bar { display: none; }
  #app { padding-bottom: 0; }
  .channel-header-desc { display: none; }
}

/* ═══ Touch optimization — larger hit areas ═══ */
@media (hover: none) and (pointer: coarse) {
  .server-icon, .channel-item, .icon-btn, .refresh-btn,
  .dashboard-action-btn, .settings-btn, .mobile-bottom-btn,
  .attach-btn, .mic-btn, .organize-btn, .login-btn {
    min-height: var(--touch-target);
  }

  .message .msg-actions { display: flex; opacity: 0.5; }
  .thought-actions { opacity: 1; }

  /* Remove hover states on touch devices */
  .server-icon:hover, .channel-item:hover, .icon-btn:hover,
  .dashboard-stat-card:hover, .tx-card:hover, .mail-card:hover,
  .briefing-card:hover, .thought-item:hover, .timeline-item:hover {
    transform: none;
    box-shadow: none;
  }
}

/* ═══ Swipeable channel indicator ═══ */
.swipe-indicator {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 24px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 18px;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  z-index: 5;
}
.swipe-indicator.left { left: 4px; }
.swipe-indicator.right { right: 4px; }
.swipe-indicator.visible { opacity: 0.5; }
