/**
 * Ghi Nhớ Mobile Stylesheet
 * Tối ưu hóa toàn diện giao diện cho Điện thoại (Android & iOS)
 */

/* Mặc định trên màn hình lớn (PC / Tablet ngang) ẩn các phần tử di động */
.mobile-bottom-nav,
.mobile-fab,
.mobile-menu-toggle,
.mobile-detail-header,
.sidebar-backdrop {
  display: none !important;
}

/* =========================================================================
   GIAO DIỆN DI ĐỘNG (DƯỚI 768PX)
   ========================================================================= */
@media (max-width: 768px) {
  /* Cho phép hiển thị các phần tử di động */
  .mobile-bottom-nav,
  .mobile-fab,
  .mobile-menu-toggle {
    display: flex !important;
  }

  /* Khung ứng dụng chính */
  body, html {
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
  }

  .app {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height cho trình duyệt di động */
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* Topbar trên di động */
  .topbar {
    padding: 8px 12px !important;
    gap: 8px !important;
    height: auto !important;
    min-height: 52px;
  }

  /* Nút menu 3 gạch mở danh mục */
  .mobile-menu-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 8px;
    background: #17212f;
    border: 1px solid #28394e;
    color: #e2ecf8;
    font-size: 19px;
    cursor: pointer;
    flex-shrink: 0;
  }
  .mobile-menu-toggle:active {
    background: #25364b;
  }

  /* Logo & Tiêu đề Topbar */
  .brand {
    gap: 6px !important;
  }
  .brand .logo {
    width: 28px !important;
    height: 28px !important;
    font-size: 14px !important;
  }
  .brand-title {
    font-size: 14px !important;
  }
  .brand-sub {
    display: none !important;
  }

  /* Ô tìm kiếm Topbar */
  .search {
    flex: 1 !important;
    min-width: 0 !important;
    max-width: none !important;
    height: 36px !important;
    padding: 0 10px !important;
  }
  .search input {
    font-size: 13px !important;
  }
  .search .shortcut {
    display: none !important; /* Ẩn Ctrl K trên điện thoại */
  }

  /* Các nút hành động góc phải Topbar */
  .top-actions {
    gap: 6px !important;
  }
  .sync#syncStatusBadge {
    display: none !important; /* Ẩn badge đồng bộ dài trên thanh topbar nhỏ */
  }
  #btnTopReminders,
  #btnTopSettings {
    display: none !important; /* Đã có trong thanh điều hướng đáy */
  }

  .user-capsule {
    padding: 3px !important;
    background: transparent !important;
    border: none !important;
  }
  .user-info-text,
  .capsule-caret {
    display: none !important;
  }
  .avatar-circle {
    width: 32px !important;
    height: 32px !important;
    font-size: 13px !important;
  }

  /* Menu xổ xuống tài khoản */
  .user-dropdown-menu {
    right: 8px !important;
    top: 56px !important;
    width: calc(100vw - 24px) !important;
    max-width: 320px !important;
  }

  /* ==================== WORKSPACE & SIDEBAR (DRAWER TRƯỢT) ==================== */
  .workspace {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
  }

  .content-container {
    width: 100% !important;
    height: 100% !important;
  }

  /* Sidebar biến thành Drawer trượt từ mép trái ra */
  .sidebar#appSidebar {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px !important;
    max-width: 82vw !important;
    height: 100% !important;
    z-index: 100;
    background: #141c28 !important;
    box-shadow: 10px 0 35px rgba(0, 0, 0, 0.7);
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    padding-bottom: 30px !important;
  }

  .sidebar#appSidebar.sidebar-open {
    transform: translateX(0) !important;
  }

  /* Màn đen mờ khi mở Drawer */
  .sidebar-backdrop {
    display: block !important;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(2px);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
  }

  .sidebar-backdrop.active {
    opacity: 1 !important;
    pointer-events: auto !important;
  }

  /* Nút tạo nhanh trong sidebar */
  .sidebar .quick {
    margin: 14px 12px 10px !important;
    height: 42px !important;
    font-size: 14px !important;
  }

  /* ==================== DANH SÁCH GHI CHÚ (VIEW NOTES) ==================== */
  #viewNotes {
    padding-bottom: 70px !important; /* Chừa khoảng trống cho Bottom Bar */
  }

  .notes-header {
    padding: 10px 14px 6px !important;
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .view-heading {
    font-size: 16px !important;
  }

  .filters {
    padding: 0 14px 8px !important;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none; /* Ẩn thanh cuộn */
    display: flex;
    gap: 6px;
  }
  .filters::-webkit-scrollbar {
    display: none;
  }

  .filter {
    padding: 6px 14px !important;
    font-size: 12.5px !important;
    border-radius: 20px !important;
    flex-shrink: 0;
  }

  .interaction-hint {
    display: none !important;
  }

  /* Danh sách thẻ bài viết */
  .note-list {
    padding: 6px 12px 20px !important;
    gap: 10px !important;
  }

  .note-card {
    padding: 13px 15px !important;
    border-radius: 10px !important;
    touch-action: pan-y;
  }
  .note-card:active {
    transform: scale(0.985);
    background: #1a2433 !important;
  }

  .note-title {
    font-size: 14.5px !important;
    line-height: 1.4 !important;
  }

  .note-excerpt {
    font-size: 12.5px !important;
    -webkit-line-clamp: 2 !important;
  }

  /* ==================== MÀN HÌNH SOẠN THẢO (VIEW DETAIL) ==================== */
  #viewDetail {
    padding: 0 !important;
    position: relative;
    background: #10151e !important;
    padding-bottom: 75px !important;
  }

  /* Thanh tiêu đề di động trong chế độ Soạn thảo */
  .mobile-detail-header {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: #151c27;
    border-bottom: 1px solid #233245;
    position: sticky;
    top: 0;
    z-index: 10;
  }

  .btn-detail-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: #38bdf8;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 8px;
    margin-left: -8px;
    border-radius: 6px;
  }
  .btn-detail-back:active {
    background: rgba(56, 189, 248, 0.12);
  }
  .btn-detail-back .back-arrow {
    font-size: 22px;
    line-height: 1;
  }

  .detail-mobile-actions {
    display: flex;
    align-items: center;
    gap: 8px;
  }

  .btn-mobile-act {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: #1d2736;
    border: 1px solid #2e4159;
    color: #cbd5e1;
    display: grid;
    place-items: center;
    font-size: 15px;
    cursor: pointer;
  }
  .btn-mobile-act:active {
    background: #2b394d;
  }

  /* Tiêu đề ghi nhớ trong Editor */
  .detail-title {
    font-size: 18px !important;
    padding: 14px 16px 8px !important;
    border-bottom: 1px solid #1c2738 !important;
  }

  .detail-meta-line {
    padding: 6px 16px !important;
    font-size: 11.5px !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  /* Quill Editor Toolbar trên di động */
  .ql-toolbar.ql-snow {
    padding: 6px 8px !important;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    display: flex;
    align-items: center;
    background: #131a25 !important;
    border-color: #212e40 !important;
  }
  .ql-toolbar.ql-snow::-webkit-scrollbar {
    display: none;
  }
  .ql-snow .ql-formats {
    margin-right: 8px !important;
    flex-shrink: 0;
  }
  .ql-snow button {
    width: 34px !important;
    height: 32px !important;
  }

  .ql-container.ql-snow {
    font-size: 14.5px !important;
    border: none !important;
  }
  .ql-editor {
    padding: 14px 16px !important;
    min-height: 350px !important;
  }

  /* ==================== NÚT TRÒN (+) NỔI DI ĐỘNG (FAB) ==================== */
  .mobile-fab {
    position: fixed;
    right: 18px;
    bottom: calc(64px + env(safe-area-inset-bottom, 0px) + 12px);
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0284c7, #2563eb);
    border: 2px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 8px 24px rgba(2, 132, 199, 0.45);
    color: #ffffff;
    font-size: 26px;
    font-weight: 300;
    display: grid;
    place-items: center;
    cursor: pointer;
    z-index: 80;
    transition: transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.18s ease;
  }
  .mobile-fab:active {
    transform: scale(0.92);
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.35);
  }

  /* ==================== THANH ĐIỀU HƯỚNG ĐÁY (BOTTOM NAVIGATION) ==================== */
  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(18, 25, 36, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid #233347;
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 90;
  }

  .mobile-nav-item {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: transparent;
    border: none;
    color: #8fa0b5;
    cursor: pointer;
    transition: all 0.16s ease;
    padding: 0;
  }

  .mobile-nav-item .mob-icon {
    font-size: 18px;
    line-height: 1;
    transition: transform 0.16s ease;
  }

  .mobile-nav-item .mob-label {
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.1px;
  }

  .mobile-nav-item.active {
    color: #38bdf8;
  }
  .mobile-nav-item.active .mob-icon {
    transform: translateY(-2px);
  }
  .mobile-nav-item.active .mob-label {
    font-weight: 700;
  }

  /* Ẩn FAB khi đang trong màn hình soạn thảo hoặc mở modal */
  body.viewing-detail .mobile-fab {
    display: none !important;
  }
}
