/* ============================================================
   public/css/mobile.css
   Nhúng vào TẤT CẢ trang, sau main.css:
   <link rel="stylesheet" href="/css/mobile.css"/>

   Chiến lược: Mobile-first breakpoints
   - xs:  < 480px   (điện thoại nhỏ)
   - sm:  < 640px   (điện thoại thường)
   - md:  < 768px   (phablet / tablet dọc)
   - lg:  < 1024px  (tablet ngang)
   ============================================================ */

/* ── 1. BASE MOBILE FIXES ─────────────────────────────────── */
* { -webkit-tap-highlight-color: transparent; }

html {
  /* Ngăn iOS tự zoom khi focus input */
  -webkit-text-size-adjust: 100%;
}

input, select, textarea {
  /* iOS Safari: font-size < 16px → auto zoom → dùng 16px */
  font-size: 16px !important;
}

/* Override lại cho desktop */
@media (min-width: 769px) {
  input, select, textarea { font-size: inherit !important; }
}

/* Touch targets tối thiểu 44×44px */
button, .btn, .nbtn, .nav-dd-item,
.frame-action-btn, .page-btn,
.tab-btn, .filter-chip {
  min-height: 44px;
  min-width:  44px;
}

/* ── 2. NAVBAR MOBILE ─────────────────────────────────────── */
@media (max-width: 768px) {
  .nav {
    padding: 0 14px;
    height: 56px;
    --nav-h: 56px;
  }
  .nav-spacer { height: 56px; }

  /* Ẩn các nav link phụ trên mobile */
  .nav .nbtn:not(.nav-menu-btn) { display: none; }

  /* Search bar thu gọn */
  #navSearchArea { display: none; }

  /* Notification bell vẫn hiện */
  .notif-btn { padding: 4px 8px; }
  .notif-dropdown { width: calc(100vw - 28px); right: -14px; }

  /* User dropdown */
  .nav-dropdown { right: 0; width: 220px; }
}

/* ── 3. HAMBURGER MENU ────────────────────────────────────── */
.nav-hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  flex-direction: column;
  gap: 5px;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
}
.nav-hamburger span {
  display: block;
  width: 22px;
  height: 2.5px;
  background: var(--tx);
  border-radius: 2px;
  transition: all .3s;
}
.nav-hamburger.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.nav-hamburger.open span:nth-child(2) { opacity: 0; }
.nav-hamburger.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

@media (max-width: 768px) {
  .nav-hamburger { display: flex; }
}

/* Mobile slide-down menu */
.mobile-menu {
  display: none;
  position: fixed;
  top: 56px;
  left: 0; right: 0;
  background: #fff;
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  z-index: 199;
  padding: 12px 16px 20px;
  border-bottom: 2px solid var(--bo);
  animation: slideDown .25s ease;
}
.mobile-menu.open { display: block; }
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}
.mobile-menu-search {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--bo);
  border-radius: 24px;
  font-size: 16px !important;
  font-family: var(--fb);
  outline: none;
  margin-bottom: 14px;
  transition: border-color .2s;
}
.mobile-menu-search:focus { border-color: var(--or); }
.mobile-menu-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.mobile-menu-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 14px;
  border-radius: 10px;
  background: #f8f9fa;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
  color: var(--tx);
  border: none;
  font-family: var(--fb);
  text-decoration: none;
  transition: background .15s, color .15s;
}
.mobile-menu-link:hover { background: #fef3ec; color: var(--or); }
.mobile-menu-link.primary {
  background: var(--or);
  color: #fff;
  grid-column: 1/-1;
  justify-content: center;
  font-size: .95rem;
}

/* ── 4. HERO SECTION ──────────────────────────────────────── */
@media (max-width: 768px) {
  .hero {
    flex-direction: column;
    padding: 32px 16px 40px;
    min-height: auto;
    gap: 28px;
    text-align: center;
  }
  .hero-prev { display: none; }
  .h1 { font-size: 2rem; }
  .hsub { font-size: .92rem; }
  .hbtns { justify-content: center; }
  .hero-badge { font-size: .76rem; }
}

/* ── 5. FRAMES GRID ───────────────────────────────────────── */
@media (max-width: 768px) {
  .frames-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .frame-title { font-size: .82rem; }
  .frame-meta  { font-size: .7rem; gap: 6px; }
  /* Actions luôn hiện trên mobile (không cần hover) */
  .frame-actions { opacity: 1; }
  .frame-action-btn { width: 34px; height: 34px; font-size: .9rem; }
}

@media (max-width: 480px) {
  .frames-grid { gap: 10px; }
  .frame-info  { padding: 8px 10px; }
}

/* ── 6. FILTER BAR ────────────────────────────────────────── */
@media (max-width: 768px) {
  /* Search box full width trên cùng */
  .filter-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    flex-wrap: wrap;
  }
  .search-box {
    min-width: 100%;
    max-width: 100%;
    width: 100%;
    order: -1;
  }

  /* Category chips → scroll ngang */
  #catFilter {
    display: flex !important;
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    gap: 6px;
    scrollbar-width: none;
    order: 0;
  }
  #catFilter::-webkit-scrollbar { display: none; }
  .cat-btn { white-space: nowrap; flex-shrink: 0; }

  /* Sort buttons → hàng ngang */
  .filter-bar > div:last-child {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    order: 1;
  }
  .filter-bar > div:last-child::-webkit-scrollbar { display: none; }
  .sort-btn { white-space: nowrap; flex-shrink: 0; font-size: .78rem; }
}

/* ── 7. SECTION PADDING ───────────────────────────────────── */
@media (max-width: 768px) {
  .sec, .sec-alt { padding: 32px 16px; }
  .sec-hd h2 { font-size: 1.4rem; }
}

/* ── 8. MODAL ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal-box {
    border-radius: 20px 20px 0 0;
    padding: 24px 20px 32px;
    max-height: 92vh;
    animation: slideUp .3s ease;
  }
  @keyframes slideUp {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: none; opacity: 1; }
  }
  /* Frame type modal: 1 cột */
  .ftypes { grid-template-columns: 1fr; gap: 10px; }
  .ftype  { padding: 14px; }
  .ftico  { width: 56px; height: 56px; font-size: 1.5rem; }
  .fti h3 { font-size: .88rem; }
  .fti p  { font-size: .74rem; display: none; } /* ẩn mô tả dài */
}

/* ── 9. EDITOR PAGE ───────────────────────────────────────── */
@media (max-width: 1024px) {
  .ep-left { display: none; } /* ẩn frame list – dùng bottom sheet */
}

@media (max-width: 768px) {
  .editor-layout {
    flex-direction: column;
    height: auto;
    min-height: calc(100vh - 56px);
  }

  /* Canvas area */
  .ep-center { min-height: 55vw; }
  .ep-canvas-wrap { padding: 12px; }
  .ep-canvas-box canvas { max-height: 60vw; }

  /* Toolbar – scroll ngang */
  .ep-toolbar {
    padding: 8px 12px;
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .ep-toolbar::-webkit-scrollbar { display: none; }
  .ep-tbtn {
    white-space: nowrap;
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: .78rem;
  }
  .tlbl { display: none; } /* ẩn type label */

  /* Right sidebar → scroll bình thường, không dùng max-height cố định */
  .ep-right {
    width: 100%;
    height: auto;
    border-left: none;
    border-top: 2px solid var(--bo);
    /* Không dùng overflow-y: auto ở đây – để scroll tự nhiên theo trang */
    overflow-y: visible;
  }
  .ep-right-head {
    background: #fff;
    padding: 10px 14px;
    border-bottom: 1px solid var(--bo);
  }

  /* Sidebar: 1 cột, scroll tự nhiên theo trang */
  .ep-right-body {
    display: block;
    padding: 12px 14px;
  }
  .ep-sec {
    margin-bottom: 14px;
    padding-bottom: 14px;
    border-bottom: 1px solid #f0f0f0;
  }
  .ep-sec:last-child { border-bottom: none; margin-bottom: 0; }

  /* Slider rows – không bị squeeze */
  .ep-srow {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
  }
  .ep-srow label { min-width: 60px; font-size: .78rem; color: var(--mu); }
  .ep-srow input[type=range] { flex: 1; height: 4px; }
  .ep-srow .sv { min-width: 36px; font-size: .78rem; text-align: right; }

  /* Upload buttons */
  .ep-ubtn {
    padding: 10px;
    font-size: .82rem;
    width: 100%;
    text-align: center;
  }

  /* Nút "Chọn khung" floating → dưới canvas, trên sidebar */
  .mobile-frame-picker-btn {
    position: relative !important;
    bottom: auto !important;
    right: auto !important;
    width: calc(100% - 32px) !important;
    margin: -8px 16px 8px !important;
    border-radius: 10px !important;
    padding: 12px !important;
    font-size: .88rem !important;
    z-index: 10 !important;
    display: flex !important;
  }

  /* Photobooth slot list */
  .pb-slot-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

  /* Export btn */
  .ep-export-btn { padding: 14px; font-size: .88rem; }

  /* Frame source section – "Chọn khung" nằm trên "Tải khung lên" */
  .frame-source-section { display: flex; flex-direction: column; }
  .frame-active-box     { order: 1; }
  .frame-upload-sec     { order: 2; }
  .mobile-frame-picker-btn-inline {
    order: 0;
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    background: var(--th-grad, linear-gradient(135deg,#36B793,#238483));
    color: #fff;
    border: none;
    border-radius: 10px;
    font-weight: 700;
    font-size: .88rem;
    cursor: pointer;
    font-family: var(--fb);
    text-align: center;
  }
}

@media (max-width: 480px) {
  .ep-right-body { display: block; }
  .ep-canvas-box canvas { max-height: 72vw; }
}

/* Floating frame picker button (mobile) */
.mobile-frame-picker-btn {
  display: none;
  position: fixed;
  bottom: calc(50vh + 16px);
  left: 16px;
  z-index: 50;
  background: var(--or);
  color: #fff;
  border: none;
  border-radius: 28px;
  padding: 10px 18px;
  font-weight: 700;
  font-size: .84rem;
  box-shadow: 0 4px 16px rgba(255,107,53,.45);
  cursor: pointer;
  font-family: var(--fb);
  gap: 6px;
  align-items: center;
}
@media (max-width: 1024px) {
  .mobile-frame-picker-btn { display: flex; }
}

/* Bottom sheet – frame picker */
.frame-picker-sheet {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 800;
}
.frame-picker-sheet.open { display: block; }
.fps-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
}
.fps-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-radius: 20px 20px 0 0;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  animation: slideUp .3s ease;
}
.fps-handle {
  width: 40px; height: 4px;
  background: #e0e0e0;
  border-radius: 2px;
  margin: 10px auto 0;
  flex-shrink: 0;
}
.fps-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px 10px;
  border-bottom: 1px solid var(--bo);
  flex-shrink: 0;
}
.fps-head h4 { font-family: var(--fm); font-size: 1rem; font-weight: 700; }
.fps-close {
  background: none; border: none; font-size: 1.4rem;
  cursor: pointer; color: var(--mu); min-width: 36px; min-height: 36px;
  display: flex; align-items: center; justify-content: center;
}
.fps-search {
  padding: 10px 16px;
  border-bottom: 1px solid var(--bo);
  flex-shrink: 0;
}
.fps-search input {
  width: 100%;
  padding: 9px 14px;
  border: 1.5px solid var(--bo);
  border-radius: 20px;
  font-size: 16px !important;
  font-family: var(--fb);
  outline: none;
}
.fps-grid {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  align-content: start;
}

/* ── 10. DASHBOARD PAGE ────────────────────────────────────── */
@media (max-width: 768px) {
  .dash-header { padding: 24px 16px 20px; }
  .dash-header h1 { font-size: 1.4rem; }
  .stats-row { gap: 10px; }
  .stat-card { min-width: 100px; padding: 12px 16px; }
  .stat-num  { font-size: 1.4rem; }
  .dash-tabs { gap: 0; }
  .dash-tab  { padding: 10px 14px; font-size: .82rem; }

  /* Upload modal bottom sheet */
  .modal-overlay.upload-modal { align-items: flex-end; padding: 0; }
}

/* ── 11. AUTH PAGES ────────────────────────────────────────── */
@media (max-width: 480px) {
  body.auth-page {
    align-items: flex-start;
    padding: 20px 0 0;
    min-height: 100vh;
  }
  .auth-card {
    border-radius: 20px 20px 0 0;
    min-height: calc(100vh - 20px);
    box-shadow: none;
    padding: 28px 20px 40px;
  }
}

/* ── 12. PROFILE PAGE ──────────────────────────────────────── */
@media (max-width: 768px) {
  .profile-header {
    padding: 28px 16px 20px;
    gap: 16px;
  }
  .profile-avatar { width: 72px; height: 72px; font-size: 1.8rem; }
  .profile-info h1 { font-size: 1.3rem; }
  .profile-stats { gap: 14px; }
  .pstat-num { font-size: 1.1rem; }

  .settings-layout { padding: 24px 16px 48px; }
  .settings-card   { padding: 18px 16px; }
}

/* ── 13. ADMIN PAGE ────────────────────────────────────────── */
@media (max-width: 960px) {
  /* Sidebar ẩn → dùng bottom nav */
  .admin-sb   { display: none; }
  .admin-content { padding: 16px; }

  /* Stats grid: 2 cột */
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card  { padding: 14px 16px; }
  .stat-num   { font-size: 1.6rem; }

  /* Charts row: 1 cột */
  .admin-content > div[style*="grid-template-columns:2fr"] {
    grid-template-columns: 1fr !important;
  }
  .admin-content > div[style*="grid-template-columns:3fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Table: scroll ngang */
  .admin-card { overflow-x: auto; }
  .admin-table { min-width: 600px; }
  .admin-table th, .admin-table td { padding: 8px 10px; font-size: .78rem; }

  /* Filter row: wrap */
  .filter-row { gap: 8px; }
  .filter-row input.search { min-width: 160px; }
  .filter-row .ml { margin-left: 0; }

  /* Settings: 1 cột */
  .settings-grid-2 { grid-template-columns: 1fr; }
}

/* Admin bottom nav (thay sidebar khi mobile) */
.admin-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #1a1a2e;
  height: 60px;
  z-index: 100;
  flex-direction: row;
  align-items: stretch;
  border-top: 1px solid rgba(255,255,255,.1);
  padding-bottom: env(safe-area-inset-bottom);
}
.admin-bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: rgba(255,255,255,.5);
  font-size: .6rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--fb);
  transition: color .15s;
  padding: 6px 4px;
}
.admin-bottom-nav-item .bni { font-size: 1.25rem; }
.admin-bottom-nav-item.active { color: var(--or); }
.admin-bottom-nav-item:hover  { color: #fff; }

@media (max-width: 960px) {
  .admin-bottom-nav { display: flex; }
  /* Thêm padding cho content không bị che */
  .admin-content { padding-bottom: 76px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-card  { padding: 12px 12px; }
  .stat-num   { font-size: 1.3rem; }
}

/* ── 14. SEARCH PAGE ───────────────────────────────────────── */
@media (max-width: 768px) {
  .search-hero { padding: 28px 16px 24px; }
  .search-hero h1 { font-size: 1.5rem; margin-bottom: 14px; }
  .search-big { padding: 13px 48px 13px 16px; font-size: 16px !important; }
  .search-filters {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    padding-bottom: 4px;
    gap: 6px;
  }
  .search-filters::-webkit-scrollbar { display: none; }
  .filter-chip { white-space: nowrap; flex-shrink: 0; min-height: 36px; }
}

/* ── 15. ANALYTICS PAGE ────────────────────────────────────── */
@media (max-width: 768px) {
  .analytics-grid { grid-template-columns: 1fr !important; }
  .analytics-grid .full { grid-column: 1 !important; }
  .heatmap {
    grid-template-columns: repeat(12, 1fr);
    gap: 4px;
  }
  .heat-cell { height: 28px; font-size: .55rem; }
}

/* ── 16. NOTIFICATIONS DROPDOWN ────────────────────────────── */
@media (max-width: 768px) {
  .notif-dropdown {
    position: fixed !important;
    top: 56px !important;
    left: 0 !important; right: 0 !important;
    width: 100% !important;
    max-height: 70vh;
    border-radius: 0 0 16px 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
  }
}

/* ── 17. PAGINATION ────────────────────────────────────────── */
@media (max-width: 480px) {
  .pagination { gap: 4px; }
  .page-btn   { padding: 8px 10px; font-size: .78rem; min-width: 36px; }
}

/* ── 18. TOAST ─────────────────────────────────────────────── */
@media (max-width: 640px) {
  #toast-container {
    bottom: 70px; /* trên bottom nav */
    right: 12px; left: 12px;
  }
  .toast { max-width: 100%; font-size: .84rem; }
}

/* ── 19. SAFE AREAS (iPhone notch / Dynamic Island) ─────────── */
@supports (padding-top: env(safe-area-inset-top)) {
  .nav {
    padding-left:  max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
  }
  .mobile-menu {
    padding-left:  max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .admin-bottom-nav {
    padding-bottom: env(safe-area-inset-bottom);
    height: calc(60px + env(safe-area-inset-bottom));
  }
}

/* ── 20. TOUCH FEEDBACK ────────────────────────────────────── */
@media (hover: none) {
  /* Trên thiết bị cảm ứng: active state thay hover */
  .btn:active,
  .frame-card:active,
  .scard:active,
  .tcard:active,
  .filter-chip:active { opacity: .75; transform: scale(.97); }

  /* Frame actions luôn hiện */
  .frame-actions { opacity: 1 !important; }

  /* Remove hover transform trên mobile (giật) */
  .frame-card:hover,
  .scard:hover,
  .tcard:hover { transform: none; }
}

/* ── 21. SCROLLBAR STYLING ────────────────────────────────── */
@media (max-width: 768px) {
  /* Sidebar scroll */
  .ep-right::-webkit-scrollbar { width: 3px; }
  .ep-right::-webkit-scrollbar-track { background: transparent; }
  .ep-right::-webkit-scrollbar-thumb { background: var(--bo); border-radius: 2px; }
}

/* ── 22. TYPOGRAPHY SCALE ─────────────────────────────────── */
@media (max-width: 480px) {
  /* Đảm bảo text không quá nhỏ */
  .badge        { font-size: .68rem; }
  .frame-meta   { font-size: .72rem; }
  .scard-lbl    { font-size: .78rem; }
  .tcc          { font-size: .74rem; }
  .form-hint    { font-size: .74rem; }
  .ep-hint      { font-size: .72rem; }
  .ep-lbl       { font-size: .76rem; }
}

/* ── FOOTER MOBILE ─────────────────────────────────────────── */
@media (max-width: 768px) {
  .footer {
    padding: 28px 16px 20px;
    text-align: center;
  }
  .footer-logo {
    font-size: 1.1rem;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
  }
  .footer p {
    font-size: .82rem;
    margin-bottom: 12px;
    color: rgba(255,255,255,.6);
  }
  .footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px 16px;
    margin-bottom: 12px;
  }
  .footer-links a {
    font-size: .8rem;
    color: rgba(255,255,255,.7);
    text-decoration: none;
  }
  .footer-links a:hover { color: #fff; }
  .footer-copyright {
    font-size: .72rem !important;
    line-height: 1.6 !important;
    padding: 12px 0 0 !important;
    color: rgba(255,255,255,.4) !important;
  }
  .footer-copyright a { color: var(--th-light, #36B793) !important; }
}

/* ── SEARCH HERO MOBILE ───────────────────────────────────── */
@media (max-width: 768px) {
  .search-hero { padding: 24px 16px; }
  .search-hero h1 { font-size: 1.4rem; margin-bottom: 12px; }
  .search-big { font-size: .95rem; padding: 13px 48px 13px 16px; }
  .search-filters {
    gap: 6px;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .search-filters::-webkit-scrollbar { display: none; }
  .filter-chip { white-space: nowrap; flex-shrink: 0; }
}

/* ── PROFILE MOBILE ───────────────────────────────────────── */
@media (max-width: 768px) {
  .profile-header { flex-direction: column; text-align: center; padding: 24px 16px; }
  .profile-stats { justify-content: center; }
  .settings-layout { padding: 20px 16px; }
  .settings-card { padding: 16px; }
}

/* ── AUTH PAGES MOBILE ────────────────────────────────────── */
@media (max-width: 480px) {
  .auth-card { padding: 24px 20px; border-radius: 16px; margin: 16px; }
}

/* ── 404 MOBILE ───────────────────────────────────────────── */
@media (max-width: 480px) {
  .err-icon { font-size: 4rem; }
  h1.err-num { font-size: 3rem; }
  .btns { flex-direction: column; align-items: center; }
}
