/* ==========================================================================
   MHENT WORKSPACE - MOBILE UI & APP-LIKE EXPERIENCE (V2.0 COMPACT)
   Tối ưu chuyên biệt cho thiết bị di động (< 768px): Nhẹ nhàng, thanh thoát, không ngộp
   ========================================================================== */

/* ==============================================================
   0. THIẾT LẬP NỀN TẢNG & TỐI ƯU CẢM ỨNG
   ============================================================== */
@media screen and (max-width: 768px) {
  * {
    -webkit-tap-highlight-color: transparent;
  }

  body, #app-container, #main-stage {
    height: 100% !important;
    height: 100dvh !important;
    overflow: hidden !important;
  }

  #stage-content {
    padding-bottom: 60px !important;
    box-sizing: border-box !important;
    -webkit-overflow-scrolling: touch;
  }

  .panel-resizer {
    display: none !important;
  }

  #nav-rail {
    display: none !important;
  }
}

/* ==============================================================
   1. THANH ĐIỀU HƯỚNG ĐÁY GỌN GÀNG (BOTTOM NAVIGATION BAR)
   ============================================================== */
#mobile-nav-bar {
  display: none;
}

@media screen and (max-width: 768px) {
  #mobile-nav-bar {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 54px;
    background: var(--bg-surface-elevated, rgba(14, 20, 32, 0.96)) !important;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-top: 1px solid var(--border-medium, rgba(255, 255, 255, 0.08)) !important;
    justify-content: space-around;
    align-items: center;
    z-index: 99999;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-sizing: content-box;
  }

  body.light-mode #mobile-nav-bar {
    background: rgba(255, 255, 255, 0.96) !important;
    border-top-color: rgba(203, 213, 225, 0.7) !important;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
  }

  .mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-muted, #64748b);
    font-family: inherit;
    font-size: 10px;
    font-weight: 700;
    gap: 2px;
    height: 100%;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    user-select: none;
  }

  .mobile-nav-btn svg {
    width: 18px;
    height: 18px;
    stroke-width: 2.2;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  }

  .mobile-nav-btn.active {
    font-weight: 900;
  }

  .mobile-nav-btn.active svg {
    transform: scale(1.15) translateY(-1px);
    animation: navIconBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  }

  .mobile-nav-btn.active::after {
    content: '';
    width: 3.5px;
    height: 3.5px;
    border-radius: 50%;
    position: absolute;
    bottom: 3px;
  }

  .mobile-nav-btn[data-app="chat"].active { color: #06b6d4 !important; }
  .mobile-nav-btn[data-app="chat"].active::after { background: #06b6d4; box-shadow: 0 0 6px #06b6d4; }

  .mobile-nav-btn[data-app="mail"].active { color: #f43f5e !important; }
  .mobile-nav-btn[data-app="mail"].active::after { background: #f43f5e; box-shadow: 0 0 6px #f43f5e; }

  .mobile-nav-btn[data-app="todo"].active { color: #f59e0b !important; }
  .mobile-nav-btn[data-app="todo"].active::after { background: #f59e0b; box-shadow: 0 0 6px #f59e0b; }

  .mobile-nav-btn[data-app="drive"].active { color: #10b981 !important; }
  .mobile-nav-btn[data-app="drive"].active::after { background: #10b981; box-shadow: 0 0 6px #10b981; }

  .mobile-nav-btn[data-app="more"].active { color: #a855f7 !important; }
  .mobile-nav-btn[data-app="more"].active::after { background: #a855f7; box-shadow: 0 0 6px #a855f7; }

  .mobile-nav-btn:active {
    transform: scale(0.9);
  }
}

/* ==============================================================
   2. CONTEXT SIDEBAR - MENU TRƯỢT TRÁI (LEFT DRAWER)
   ============================================================== */
@media screen and (max-width: 768px) {
  #context-sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 82% !important;
    max-width: 300px !important;
    height: 100% !important;
    height: 100dvh !important;
    background: var(--bg-surface-elevated, rgba(14, 20, 32, 0.98)) !important;
    backdrop-filter: blur(28px) !important;
    -webkit-backdrop-filter: blur(28px) !important;
    border-right: 1px solid var(--border-medium, rgba(255, 255, 255, 0.12)) !important;
    z-index: 1000001 !important;
    display: flex !important;
    flex-direction: column !important;
    transform: translateX(-100%) !important;
    box-shadow: none !important;
    transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.35s ease !important;
    overflow-y: auto !important;
    padding-bottom: 24px !important;
  }

  body.light-mode #context-sidebar {
    background: rgba(255, 255, 255, 0.98) !important;
    border-right-color: rgba(203, 213, 225, 0.8) !important;
  }

  #context-sidebar.open {
    transform: translateX(0) !important;
    box-shadow: 20px 0 40px rgba(0, 0, 0, 0.6) !important;
  }

  .mhent-workspace-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(5, 8, 15, 0.65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    z-index: 1000000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

  .mhent-workspace-overlay.show {
    opacity: 1;
    pointer-events: auto;
  }

  .sidebar-nav-item, .chat-channel-item, .chat-dm-item, .folder-item {
    min-height: 38px !important;
    padding: 8px 12px !important;
    border-radius: 10px !important;
    margin-bottom: 3px !important;
    font-size: 13px !important;
  }
}

/* ==============================================================
   3. MENU TRƯỢT TIỆN ÍCH PHẢI (SIDE DRAWER V2.0)
   ============================================================== */
@media screen and (max-width: 768px) {
  .mhent-ws-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 84%;
    max-width: 300px;
    height: 100%;
    height: 100dvh;
    background: var(--bg-surface-elevated, rgba(14, 20, 32, 0.98));
    backdrop-filter: blur(28px);
    -webkit-backdrop-filter: blur(28px);
    box-shadow: -15px 0 35px rgba(0, 0, 0, 0.5);
    z-index: 1000002;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.2, 0.8, 0.2, 1);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    box-sizing: border-box;
    border-left: 1px solid var(--border-medium, rgba(255, 255, 255, 0.12));
    overflow-y: auto;
  }

  body.light-mode .mhent-ws-drawer {
    background: rgba(255, 255, 255, 0.98);
    border-left-color: rgba(203, 213, 225, 0.8);
    box-shadow: -15px 0 30px rgba(0, 0, 0, 0.12);
  }

  .mhent-ws-drawer.open {
    transform: translateX(0);
  }

  .ws-drawer-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 12px;
    position: relative;
  }

  .ws-drawer-avt {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    font-size: 18px;
  }

  .ws-drawer-user-name {
    font-weight: 800;
    font-size: 15px;
  }

  .ws-drawer-item {
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
  }
}

/* ==============================================================
   4. TINH CHỈNH TOPBAR WORKSPACE GỌN GÀNG, KHÔNG BỊ NGỘP
   ============================================================== */
@media screen and (max-width: 768px) {
  .stage-topbar {
    height: 44px !important;
    padding: 0 10px !important;
    box-sizing: border-box !important;
  }

  .mobile-sidebar-toggle-btn {
    display: inline-flex !important;
    width: 30px !important;
    height: 30px !important;
    border-radius: 8px !important;
    font-size: 14px !important;
    flex-shrink: 0 !important;
  }

  .stage-title {
    font-size: 14px !important;
    font-weight: 800 !important;
    white-space: nowrap !important;
  }

  .stage-desc {
    display: none !important;
  }

  .topbar-right {
    gap: 6px !important;
  }

  /* Ô tìm kiếm rút gọn thành icon nhỏ */
  .quick-search-btn {
    width: 30px !important;
    height: 30px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 8px !important;
    flex-shrink: 0 !important;
  }
  .quick-search-btn span,
  .quick-search-btn kbd,
  .quick-search-btn .kbd-shortcut {
    display: none !important;
  }

  /* Nút AISA Copilot trên Topbar nhỏ gọn */
  #btn-toggle-aisa {
    height: 30px !important;
    padding: 0 8px !important;
    font-size: 11px !important;
    border-radius: 8px !important;
    gap: 4px !important;
    flex-shrink: 0 !important;
  }
}

/* ==============================================================
   5. TỐI ƯU GIAO DIỆN LỊCH (CALENDAR) TRÊN DI ĐỘNG (DOT SYSTEM)
   Trị dứt điểm tình trạng 7 cột bị nhồi nhét chữ nhật dày đặc
   ============================================================== */
@media screen and (max-width: 768px) {
  /* Toolbar Lịch: 1 HÀNG DUY NHẤT GỌN GÀNG, KHÔNG XẾP TẦNG */
  .calendar-header-bar {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 4px !important;
    padding: 6px 8px !important;
    flex-wrap: nowrap !important;
    box-sizing: border-box !important;
  }

  .calendar-nav-controls {
    display: flex !important;
    align-items: center !important;
    gap: 4px !important;
    width: auto !important;
    flex-shrink: 0 !important;
  }

  .calendar-title {
    font-size: 12.5px !important;
    font-weight: 800 !important;
    margin: 0 0 0 2px !important;
    min-width: auto !important;
    white-space: nowrap !important;
  }

  .calendar-btn-group {
    display: inline-flex !important;
    height: 26px !important;
  }

  .calendar-btn-group .btn {
    padding: 2px 6px !important;
    font-size: 10px !important;
    height: 26px !important;
    line-height: 1 !important;
  }

  .cal-icon-btn {
    padding: 2px 6px !important;
    width: 24px !important;
  }

  .cal-icon-btn svg {
    width: 12px !important;
    height: 12px !important;
  }

  .calendar-actions-bar {
    display: flex !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 4px !important;
    width: auto !important;
    flex-shrink: 0 !important;
    flex-wrap: nowrap !important;
  }

  .calendar-view-switcher {
    display: inline-flex !important;
    height: 26px !important;
  }

  .cal-view-btn {
    padding: 2px 6px !important;
    font-size: 10.5px !important;
    height: 26px !important;
    gap: 2px !important;
  }

  .cal-view-btn svg {
    display: none !important;
  }

  #btn-find-free-time {
    display: none !important;
  }

  #btn-calendar-add-event {
    height: 26px !important;
    padding: 0 8px !important;
    font-size: 10.5px !important;
    border-radius: 7px !important;
    white-space: nowrap !important;
    line-height: 1 !important;
  }

  /* Lưới Lịch Tháng (Calendar Grid Dot System) */
  .calendar-month-container {
    padding: 2px 4px !important;
    flex: 1 !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
    overflow: hidden !important;
  }

  .calendar-grid {
    min-height: auto !important;
    padding: 4px 2px !important;
    gap: 2.5px !important;
    border-radius: 10px !important;
    flex: 1 !important;
    auto-rows: 1fr !important;
    grid-template-rows: repeat(5, 1fr) !important;
  }

  .calendar-weekday {
    padding: 3px 0 !important;
    font-size: 8.5px !important;
    font-weight: 800 !important;
  }

  .calendar-day-cell {
    min-height: 0 !important;
    height: 100% !important;
    max-height: 52px !important;
    padding: 2px 1px !important;
    border-radius: 6px !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: flex-start !important;
    gap: 1.5px !important;
    cursor: pointer !important;
    box-sizing: border-box !important;
  }

  .day-header {
    width: 100% !important;
    justify-content: center !important;
  }

  .day-number {
    font-size: 11px !important;
    font-weight: 800 !important;
    line-height: 1.1 !important;
  }

  .today-badge, .cell-split-stripe {
    display: none !important;
  }

  .calendar-day-cell.today .day-number {
    background: var(--app-calendar, #0ea5e9);
    color: #ffffff !important;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9.5px !important;
  }

  /* Biến các event pill dài dòng thành chấm tròn màu (dots) thanh lịch */
  .event-pills-list {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 2.5px !important;
    width: 100% !important;
    max-height: 12px !important;
    overflow: hidden !important;
    margin-top: 1px !important;
  }

  .event-pill {
    width: 5px !important;
    height: 5px !important;
    min-width: 5px !important;
    max-width: 5px !important;
    min-height: 5px !important;
    max-height: 5px !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 50% !important;
    border: none !important;
    border-left: none !important;
    box-shadow: 0 0 2px currentColor !important;
    flex-shrink: 0 !important;
    cursor: pointer !important;
  }

  .event-pill * {
    display: none !important;
  }

  .event-more-count {
    display: none !important;
  }
}

/* ==============================================================
   6. TỐI ƯU CÁC GIAO DIỆN APP CON KHÁC (CHAT, MAIL, TODO, DRIVE)
   ============================================================== */
@media screen and (max-width: 768px) {
  /* --- CHAT --- */
  .chat-messages-container {
    padding: 10px 8px !important;
  }

  .chat-bubble {
    max-width: 86% !important;
    font-size: 13.5px !important;
    padding: 8px 12px !important;
    border-radius: 16px !important;
  }

  .chat-input-bar {
    padding: 6px 8px !important;
  }

  .chat-input-bar textarea, .chat-input-bar input {
    font-size: 13.5px !important;
    padding: 6px 10px !important;
  }

  /* --- MAIL --- */
  #mail-split-container {
    flex-direction: column !important;
  }

  /* --- TODO KANBAN --- */
  .kanban-board {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    scroll-snap-type: x mandatory !important;
    gap: 10px !important;
    padding: 10px !important;
    scrollbar-width: none;
  }

  .kanban-column {
    flex: 0 0 82vw !important;
    max-width: 300px !important;
    scroll-snap-align: center !important;
    border-radius: 14px !important;
    padding: 12px !important;
  }

  .kanban-task-card {
    padding: 10px !important;
    border-radius: 10px !important;
  }

  /* --- DRIVE --- */
  .drive-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    padding: 8px !important;
  }

  .drive-file-card {
    padding: 10px 8px !important;
    border-radius: 10px !important;
  }

  .drive-file-name {
    font-size: 12px !important;
  }

  /* --- MODALS CĂN GIỮA VỪA VẶN --- */
  .modal-overlay, .mhent-ui-overlay {
    align-items: center !important;
    justify-content: center !important;
    padding: 14px !important;
  }

  .modal-box, .mhent-ui-box {
    width: calc(100vw - 28px) !important;
    max-width: 400px !important;
    border-radius: 18px !important;
    padding: 18px 16px !important;
  }

  /* Safe AISA Drawer */
  #aisa-drawer {
    width: 88% !important;
    max-width: 340px !important;
  }
}

/* ==============================================================
   7. APP ANIMATIONS
   ============================================================== */
@media screen and (max-width: 768px) {
  .app-stage-view {
    animation: appPageSlideUp 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) forwards !important;
  }

  @keyframes appPageSlideUp {
    0% { opacity: 0; transform: translateY(12px); }
    100% { opacity: 1; transform: translateY(0); }
  }

  @keyframes navIconBounce {
    0% { transform: scale(1) translateY(0); }
    40% { transform: scale(1.25) translateY(-4px); }
    70% { transform: scale(1.05) translateY(-1px); }
    100% { transform: scale(1.15) translateY(-1px); }
  }
}
