/**
 * mobile.css — Mobile-optimized styles for LensPilot
 * Touch-friendly, safe-area-aware, responsive.
 */

/* ── Bottom Tab Navigation ── */
.mobile-tabs {
  display: none;
  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: var(--bg2);
  border-top: 1px solid var(--border);
  z-index: 1100;
  justify-content: space-around;
  align-items: center;
}
.mobile-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 56px;
  min-width: 56px;
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text3);
  cursor: pointer;
  font-size: 20px;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.mobile-tab .icon { display:block; margin:0 auto; }
.mobile-tab.active { color: var(--accent); }
.mobile-tab span { font-size: 10px; line-height: 1; }

/* Show on mobile */
@media (max-width: 768px) {
  .mobile-tabs { display: flex; }
  body { padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px)); }
}

/* ── Topbar Mobile ── */
@media (max-width: 768px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 12px;
    gap: 6px;
    padding-top: max(8px, env(safe-area-inset-top, 0px));
  }
  .topbar-brand { font-size: 14px; }
  .topbar-nav { display: none; }  /* redundant with bottom tabs on mobile */
  .topbar-right { font-size: 11px; gap: 4px; }
  .token-input { width: 100px; font-size: 11px; }
  .nav-btn { padding: 5px 10px; font-size: 12px; }
}

/* ── Sidebar → Hidden on mobile, accessible via tabs ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 280px;
    z-index: 1200;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 24px rgba(0,0,0,.15);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1199;
  }
  .sidebar-backdrop.open { display: block; }
}

/* ── Photo Grid Mobile ── */
@media (max-width: 768px) {
  .photo-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 4px;
  }
  .photo-card .card-name { font-size: 11px; }
  .photo-card .card-meta { font-size: 10px; }
}

@media (max-width: 480px) {
  .photo-grid { grid-template-columns: 1fr 1fr; gap: 4px; }
}

/* ── Touch-Safe Buttons ── */
@media (max-width: 768px) {
  .btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px 14px;
    font-size: 13px;
  }
  .btn-sm {
    min-height: 36px;
    min-width: 36px;
    padding: 6px 12px;
    font-size: 12px;
  }
}

/* ── Main Layout Mobile ── */
@media (max-width: 768px) {
  .main-layout { flex-direction: column; }
  .content {
    padding: 8px;
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }
}

/* ── Lightbox Mobile (touch gestures) ── */
@media (max-width: 768px) {
  .lightbox {
    padding: 8px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
  }
  .lightbox-content { max-width: 100vw; max-height: 80vh; }
  .lightbox-close {
    top: 8px; right: 8px;
    width: 40px; height: 40px;
    font-size: 28px;
  }
  .lightbox-prev { left: 4px; width: 40px; height: 72px; font-size: 28px; }
  .lightbox-next { right: 4px; width: 40px; height: 72px; font-size: 28px; }
  .lightbox-actions { gap: 4px; }
  .lightbox-actions .btn { min-width: 36px; min-height: 36px; font-size: 11px; padding: 5px 10px; }
  .lightbox-media img, .lightbox-media video { max-width: 96vw; max-height: 60vh; }
}

/* ── Upload Button (FAB) ── */
/* Base positioning & sizing are in studio.css — here we only toggle visibility for mobile. */
.mobile-fab:active { transform: scale(.92); box-shadow: 0 2px 8px rgba(59,130,246,.3); }
@media (max-width: 768px) {
  .mobile-fab:not(.hidden) { display: flex; }
}

/* ── Stats cards mobile ── */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-card .stat-value { font-size: 22px; }
}

/* ── Album list mobile ── */
@media (max-width: 768px) {
  .fb-album-item { padding: 14px 12px; }
  .fb-album-icon { font-size: 22px; }
  .fb-album-title { font-size: 13px; }
}

/* ── Album detail photos mobile ── */
@media (max-width: 768px) {
  .fb-album-detail .photo-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
}

/* ── File browser mobile ── */
@media (max-width: 768px) {
  .file-browser-grid { grid-template-columns: 1fr; }
  .fb-item { padding: 10px; min-height: 44px; }
}

/* ── User table scroll on mobile ── */
@media (max-width: 768px) {
  .user-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .user-table { min-width: 700px; }
}

/* ── Input/Select touch-friendly ── */
@media (max-width: 768px) {
  input, select, textarea {
    font-size: 16px !important; /* prevent iOS zoom on focus */
    min-height: 44px;
    padding: 8px 12px;
  }
  .token-input { min-height: 36px; }
  .search-input { min-height: 40px; }
  .sort-select { min-height: 40px; }
}

/* ── Browse Photos Button ── */
.btn-browse-entry {
  background: var(--bg3);
  border: 2px dashed var(--border);
  color: var(--text);
  border-radius: 12px;
  cursor: pointer;
  font-weight: 600;
  transition: border-color .15s, background .15s;
  -webkit-tap-highlight-color: transparent;
}
.btn-browse-entry:hover, .btn-browse-entry:active {
  border-color: var(--accent);
  background: rgba(59,130,246,.08);
}

/* ── Transfer Gallery ── */
.transfer-gallery {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.transfer-card {
  position: relative;
  aspect-ratio: 1;
  background: var(--bg3);
  border-radius: 8px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s;
}
.transfer-card img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.transfer-card.selected {
  border-color: var(--accent);
}
.transfer-card .card-info {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 4px 6px;
  background: linear-gradient(transparent, rgba(0,0,0,.7));
  font-size: 10px;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.transfer-card .transfer-check {
  position: absolute;
  top: 6px; left: 6px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}
.transfer-video-badge {
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
  color: var(--text3);
  font-size: 20px;
}

/* ── iOS Safezone helpers ── */
@supports (-webkit-touch-callout: none) {
  .mobile-tabs { padding-bottom: env(safe-area-inset-bottom, 12px); }
  body { padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px)); }
}
