/* =========================================
   MOBILE RESPONSIVE STYLES
   Target: < 768px (phone), 768-1024px (tablet)
   ========================================= */

/* Prevent zoom on input focus (iOS) */
@media screen and (max-width: 767px) {
  input, textarea, select {
    font-size: 16px !important;
  }
}

/* Safe area padding for notched devices */
@supports (padding: env(safe-area-inset-bottom)) {
  @media screen and (max-width: 767px) {
    .biz-input-wrap.at-bottom,
    #biz-input-bottom-slot .biz-input-wrap,
    .collab-chat-input-wrap {
      padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }
    .top-nav {
      padding-top: env(safe-area-inset-top);
      height: calc(56px + env(safe-area-inset-top));
    }
  }
}

/* ===== MOBILE: < 768px ===== */
@media screen and (max-width: 767px) {

  /* --- Body & Layout --- */
  body {
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* --- Top Navigation --- */
  .top-nav {
    height: 56px;
    padding: 0 12px;
    position: sticky;
    top: 0;
    z-index: 200;
  }
  .logo-text {
    font-size: 14px;
  }
  .nav-center {
    position: static;
    transform: none;
    gap: 1px;
    padding: 2px;
    border-radius: 10px;
  }
  .tab-btn {
    padding: 4px 14px;
    font-size: 13px;
    border-radius: 8px;
  }
  .nav-right {
    gap: 10px;
  }
  .nav-search-wrap {
    display: none;
  }
  .nav-avatar {
    width: 26px;
    height: 26px;
  }

  /* --- Tab Panels --- */
  .tab-panels {
    overflow: auto;
    height: calc(100vh - 56px);
  }
  .tab-panel {
    flex-direction: column !important;
    height: auto;
    min-height: 100%;
  }

  /* ===== TAB 1: 协作 (Collab) ===== */
  #tab-collab {
    flex-direction: column !important;
  }

  /* Collab sidebar → horizontal scrollable or hidden */
  .collab-conv-sidebar {
    width: 100%;
    height: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 12px;
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    display: none; /* Hidden by default on mobile, toggled via JS */
  }
  .collab-conv-sidebar.mobile-show {
    display: flex;
    flex-direction: column;
    max-height: 50vh;
    overflow-y: auto;
  }

  .collab-conv-main {
    padding: 0 12px 16px;
    flex: 1;
  }
  .biz-center-group {
    padding-top: 15vh;
  }
  .biz-greeting {
    max-width: 100%;
    margin-bottom: 20px;
  }
  .biz-greeting-text,
  .biz-greeting-sub {
    font-size: 22px;
  }
  .biz-greeting-line {
    width: 100px;
  }

  /* Collab input */
  .collab-conv-input-wrap {
    max-width: 100%;
    border-radius: 20px;
    padding: 12px 8px 8px;
    margin-top: 20px;
  }
  .collab-conv-input {
    font-size: 15px;
    padding: 0 8px;
  }

  /* Collab chat view */
  .collab-chat-view {
    padding: 0;
  }
  .collab-chat-messages {
    padding: 12px 8px;
  }
  .collab-chat-input-wrap {
    border-radius: 18px;
    margin: 8px;
  }

  /* ===== Collab IM (Original hidden section) ===== */
  .collab-message {
    flex-direction: column !important;
  }
  .cmsg-list-panel {
    width: 100% !important;
    height: auto;
    max-height: 40vh;
    border-right: none !important;
    border-bottom: 1px solid #e8e8e8;
  }
  .cmsg-chat-panel {
    flex: 1;
    min-height: 50vh;
  }
  .cmsg-pinned-list {
    overflow-x: auto;
    flex-wrap: nowrap;
    padding-bottom: 8px;
  }

  /* ===== TAB 2: 业务 (Business) ===== */
  #tab-business {
    flex-direction: column !important;
  }

  /* Business sidebar → bottom tab bar or drawer */
  .biz-sidebar {
    width: 100%;
    height: auto;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 12px;
    flex-shrink: 0;
    overflow-x: auto;
    overflow-y: hidden;
    display: none; /* Hidden by default, toggled via hamburger */
  }
  .biz-sidebar.mobile-show {
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    max-height: none;
    overflow-y: auto;
    background: #f5f5f5;
    animation: slideInLeft 0.25s ease;
  }

  @keyframes slideInLeft {
    from { transform: translateX(-100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
  }

  /* Business main area */
  .biz-main {
    min-height: calc(100vh - 56px);
  }
  .biz-welcome {
    padding: 0 12px 16px;
  }
  .biz-agent-display {
    gap: 8px;
  }
  .biz-agent-globe {
    width: 70px;
    height: 70px;
  }
  .biz-globe-inner {
    width: 70px;
    height: 70px;
  }
  .biz-agent-label {
    font-size: 24px;
  }
  .biz-agent-tagline {
    font-size: 22px;
  }
  .biz-agent-subtitle {
    font-size: 22px;
  }

  /* Business input */
  .biz-input-wrap {
    max-width: 100%;
    margin-top: 20px;
  }
  .biz-input-box {
    border-radius: 20px;
    padding: 12px 8px 8px;
  }
  .biz-input-field {
    font-size: 15px;
  }
  .biz-input-wrap.at-bottom {
    padding: 8px 12px 12px;
  }
  #biz-input-bottom-slot .biz-input-wrap {
    padding: 8px 12px 12px;
  }

  /* Business chat area */
  .biz-chat-area {
    padding: 12px 12px;
  }
  .biz-msg {
    max-width: 92%;
  }

  /* Quick actions */
  .biz-quick-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .biz-quick-card {
    width: 100%;
    max-width: none;
  }

  /* Recommend cards */
  .biz-rec-cards {
    flex-direction: column;
    gap: 10px;
  }
  .biz-rec-card {
    max-width: none;
  }

  /* @ Mention popover */
  .at-overlay {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    margin-bottom: 0;
    z-index: 400;
  }
  .at-modal {
    width: 100%;
    max-height: 60vh;
    border-radius: 16px 16px 0 0;
  }

  /* Schedule page */
  .sched-page {
    padding: 16px 12px;
  }
  .sched-templates {
    flex-direction: column;
    gap: 10px;
  }
  .sched-table {
    display: block;
    overflow-x: auto;
  }
  .sched-modal {
    width: 95vw;
    max-height: 85vh;
  }

  /* ===== TAB 3: 开发 (Dev) ===== */
  #tab-dev {
    flex-direction: column !important;
  }

  /* Notification panel */
  .notif-panel {
    top: 56px;
  }
  .notif-header {
    padding: 16px 12px 0;
  }
  .notif-tabs {
    padding: 12px 12px 0;
    overflow-x: auto;
  }
  .notif-list {
    padding: 12px;
  }
  .notif-item {
    padding: 12px;
  }

  /* Search modal */
  .srch-overlay {
    padding-top: 0;
    align-items: flex-start;
  }
  .srch-modal {
    width: 100%;
    max-height: 100vh;
    border-radius: 0;
    height: 100vh;
  }
  .srch-input-wrap {
    padding: 14px 12px;
  }
  .srch-tabs {
    padding: 0 12px;
  }
  .srch-body {
    padding: 12px;
  }

  /* File manager overlay */
  .fm-overlay {
    flex-direction: column;
  }
  .fm-sidebar {
    width: 100% !important;
    height: auto;
    max-height: 30vh;
    border-right: none;
    border-bottom: 1px solid #e8e8e8;
  }
  .fm-main {
    flex: 1;
  }

  /* Avatar dropdown */
  #avatar-dropdown {
    right: 0 !important;
    min-width: 140px !important;
  }

  /* Footer disclaimer */
  .biz-footer-disclaimer,
  .collab-conv-disclaimer {
    font-size: 11px;
    position: static;
    margin-top: 16px;
    padding-bottom: 12px;
  }

  /* Mobile hamburger toggle button */
  .mobile-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    color: rgba(0,0,0,0.6);
    transition: background 0.15s;
  }
  .mobile-sidebar-toggle:hover {
    background: rgba(0,0,0,0.05);
  }
}

/* ===== TABLET: 768px - 1024px ===== */
@media screen and (min-width: 768px) and (max-width: 1024px) {

  .top-nav {
    padding: 0 14px;
  }

  /* Narrower sidebars */
  .biz-sidebar {
    width: 200px;
  }
  .collab-conv-sidebar {
    width: 200px;
  }
  .cmsg-list-panel {
    width: 240px !important;
  }

  /* Smaller greeting text */
  .biz-greeting-text,
  .biz-greeting-sub {
    font-size: 26px;
  }
  .biz-agent-subtitle {
    font-size: 26px;
  }

  /* Input adjustments */
  .biz-input-wrap,
  .collab-conv-input-wrap {
    max-width: 90%;
  }

  /* Schedule */
  .sched-templates {
    flex-wrap: wrap;
  }
  .sched-tpl-card {
    min-width: calc(50% - 8px);
  }
}

/* ===== DESKTOP: hide mobile-only elements ===== */
@media screen and (min-width: 768px) {
  .mobile-sidebar-toggle {
    display: none !important;
  }
  .mobile-back-btn {
    display: none !important;
  }
}

/* ===== Touch-friendly enhancements ===== */
@media (hover: none) and (pointer: coarse) {
  /* Larger tap targets */
  .biz-nav-item {
    padding: 10px 12px;
    min-height: 44px;
  }
  .tab-btn {
    min-height: 36px;
  }
  .nav-icon {
    width: 28px;
    height: 28px;
    min-width: 44px;
    min-height: 44px;
  }
  .collab-conv-hist-item {
    padding: 12px;
    min-height: 44px;
  }
  .cmsg-conv-item {
    padding: 12px;
    min-height: 56px;
  }
  .biz-tool-btn,
  .biz-send-btn {
    width: 44px;
    height: 44px;
  }
  .collab-conv-tool-btn,
  .collab-conv-send-btn {
    width: 40px;
    height: 40px;
  }

  /* Disable hover effects on touch */
  .biz-nav-item:hover,
  .biz-quick-card:hover,
  .biz-rec-card:hover {
    transform: none;
    box-shadow: none;
  }
}
