/* TwitcherDeck — td-mobile.css
   Comprehensive mobile/responsive overrides.
   Loaded on all pages via functions.php.
   Breakpoints: 1024px (tablet), 768px (mobile-l), 480px (mobile), 375px (small)
*/

/* ── CONTAINER ──────────────────────────────────────────── */
.td-container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box;
}

/* ── NAV ────────────────────────────────────────────────── */
.td-nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  padding: 0 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.td-nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 40px;
  height: 40px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  flex-shrink: 0;
}
.td-nav-toggle span {
  display: block;
  width: 22px;
  height: 2.5px;
  background: #e8f0e9;
  border-radius: 2px;
  transition: all .25s;
}
.td-nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.td-nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.td-nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.td-nav-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  justify-content: flex-end;
}

.td-nav-links {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
  gap: 4px;
}
.td-nav-links li a {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color .2s, background .2s;
  white-space: nowrap;
  display: block;
}

.td-nav-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-left: 12px;
}

/* Nav button styles */
.td-btn { display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; font-family: inherit; font-weight: 600; cursor: pointer; text-decoration: none; transition: all .2s; white-space: nowrap; }
.td-btn-sm { padding: 7px 14px; font-size: 0.8rem; }
.td-btn-outline { border: 1px solid rgba(255,255,255,.2); color: #e8f0e9; background: transparent; }
.td-btn-outline:hover { border-color: #5fbf7a; color: #5fbf7a; }
.td-btn-ghost { border: none; background: transparent; color: #8fa896; }
.td-btn-ghost:hover { color: #e8f0e9; }
.td-btn-leaf { background: #5fbf7a; color: #06140b; border: none; }
.td-btn-leaf:hover { background: #4aad65; }

/* ── PAGE HERO ──────────────────────────────────────────── */
.td-page-hero .td-container { max-width: 800px; }
.td-page-hero h1 { font-size: clamp(1.8rem, 5vw, 3rem); }
.td-page-hero p  { font-size: clamp(0.9rem, 2.5vw, 1.1rem); }

/* ── TOUCH TARGETS ──────────────────────────────────────── */
.td-btn-primary,
.td-btn-ghost,
.td-filter-btn,
.td-nav-toggle {
  min-height: 44px;
}

/* ── FORM INPUTS ────────────────────────────────────────── */
.td-field input[type="text"],
.td-field input[type="number"],
.td-field input[type="datetime-local"],
.td-field input[type="url"],
.td-field input[type="email"],
.td-field textarea,
.td-field select {
  font-size: 16px !important; /* Prevents iOS zoom on focus */
  min-height: 44px;
}

/* ── SECTION SPACING ────────────────────────────────────── */
.td-section { padding: 2rem 0; }
.td-section .td-container { padding: 0 16px; }

@media (max-width: 1024px) {
  .td-nav-actions .td-btn-outline,
  .td-nav-actions .td-btn-ghost { display: none; }
  .td-nav-actions .td-btn-leaf  { display: inline-flex; }
}

/* ── TABLET + MOBILE NAV ────────────────────────────────── */
@media (max-width: 768px) {
  .td-nav-toggle { display: flex !important; }

  .td-nav-menu,
  .td-nav-menu.open {
    position: fixed !important;
    top: 64px !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: calc(100vh - 64px) !important;
    max-height: none !important;
    background: #0a1209 !important;
    flex-direction: column !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    gap: 0 !important;
    padding: 24px 20px 40px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    z-index: 9999 !important;
    border-top: 1px solid rgba(255,255,255,.08) !important;
    box-sizing: border-box !important;
  }

  .td-nav-menu { display: none !important; }
  .td-nav-menu.open { display: flex !important; }

  .td-nav-links {
    flex-direction: column !important;
    gap: 4px !important;
    width: 100% !important;
    list-style: none !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  .td-nav-links li a {
    padding: 16px 16px !important;
    font-size: 1.15rem !important;
    border-radius: 10px !important;
    border-bottom: 1px solid rgba(255,255,255,.06) !important;
    display: block !important;
    color: #e8f0e9 !important;
    text-decoration: none !important;
    font-weight: 500 !important;
  }
  .td-nav-links li:last-child a { border-bottom: none !important; }

  .td-nav-actions {
    flex-direction: column !important;
    margin-left: 0 !important;
    margin-top: 24px !important;
    gap: 10px !important;
    width: 100% !important;
    display: flex !important;
  }
  .td-nav-actions .td-btn {
    display: flex !important;
    width: 100% !important;
    padding: 16px !important;
    font-size: 1rem !important;
    justify-content: center !important;
    border-radius: 10px !important;
    box-sizing: border-box !important;
  }

  /* Page hero */
  .td-page-hero {
    padding: calc(64px + 2rem) 20px 2rem !important;
  }

  /* Journal */
  .td-journal-cols { grid-template-columns: 1fr !important; }
  .td-journal-stats { gap: 8px; }
  .td-jstat-box { padding: 12px 10px; min-width: 60px; }
  .td-jstat-num { font-size: 1.4rem; }
  .td-quick-actions { gap: 8px; }
  .td-quick-btn { padding: 12px 8px; min-width: 0; }
  .td-quick-icon { font-size: 1.2rem; }
  .td-quick-label { font-size: 0.7rem; }

  /* Community */
  .td-community-layout { grid-template-columns: 1fr !important; }
  .td-community-sidebar { position: static !important; }
  .td-feed-img { width: 60px; }

  /* Profile */
  .td-profile-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
  .td-profile-cols { grid-template-columns: 1fr !important; }
  .td-profile-sidebar { position: static !important; }
  .td-badges-grid { grid-template-columns: repeat(3, 1fr) !important; }
  .td-profile-name-row { flex-wrap: wrap; }
  .td-profile-name-row h1 { font-size: 1.5rem; }

  /* Leaderboard */
  .td-lb-tabs { flex-wrap: wrap; }
  .td-lb-row { padding: 10px 12px; gap: 10px; }
  .td-lb-rank { width: 28px; font-size: 1.1rem; }
  .td-lb-num { font-size: 1.2rem; }

  /* Donate */
  .td-flock-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 12px !important; }
  .td-flock-card { padding: 1.25rem 1rem; }
  .td-flock-amount { font-size: 1.4rem; }

  /* Species page */
  .td-species-cta { flex-direction: column; align-items: flex-start; }
  .td-observer-list { gap: 6px; }

  /* Map */
  .td-map-toolbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .td-map-filters { flex-wrap: wrap; gap: 6px; }
  #td-map { height: 380px !important; }

  /* Log sighting */
  .td-field-row { flex-direction: column !important; }

  /* Import & migrate admin */
  .td-journal-section { padding: 1rem; }
}

@media (max-width: 480px) {
  .td-container { padding: 0 12px; }

  /* Stats row — 3 per row on small screens */
  .td-journal-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .td-jstat-num { font-size: 1.2rem; }
  .td-jstat-label { font-size: 0.6rem; }

  /* Species grid — 2 columns */
  .td-species-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
  }
  .td-card-name { font-size: 0.78rem; }
  .td-card-latin { font-size: 0.65rem; }

  /* Flock tiers — single column */
  .td-flock-grid { grid-template-columns: 1fr !important; }

  /* Badges — 2 per row */
  .td-badges-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Profile stats */
  .td-profile-stats-row { gap: 12px; }
  .td-pstat-num { font-size: 1.2rem; }

  /* Feed items */
  .td-feed-meta { gap: 6px; flex-direction: column; }
  .td-feed-date { margin-left: 0 !important; }

  /* Page hero */
  .td-page-hero { padding: calc(64px + 1.5rem) 12px 1.5rem !important; }
  .td-label { font-size: 0.7rem; }

  /* Nav */
  .td-nav-inner { padding: 0 12px; }

  /* Leaderboard */
  .td-lb-avatar { display: none; }
  .td-lb-badge { display: none; }

  /* Observer chips */
  .td-observer-chip { padding: 4px 8px 4px 4px; }
  .td-obs-avatar { width: 20px; height: 20px; }
  .td-obs-name { font-size: 0.72rem; }

  /* Sighting rows */
  .td-sighting-row { flex-wrap: wrap; gap: 6px; }

  /* Map */
  #td-map { height: 300px !important; }
  .td-filter-btn { padding: 5px 10px; font-size: 0.72rem; }
}

@media (max-width: 375px) {
  .td-journal-stats { grid-template-columns: repeat(2, 1fr); }
  .td-quick-actions { grid-template-columns: repeat(2, 1fr); display: grid; }
  .td-species-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 6px !important; }
}

/* ── PREVENT HORIZONTAL SCROLL ──────────────────────────── */
html, body { overflow-x: hidden; max-width: 100vw; }
img, video, iframe { max-width: 100%; height: auto; }
table { max-width: 100%; overflow-x: auto; display: block; }

/* ── STICKY MOBILE LOG CTA ──────────────────────────────── */
@media (max-width: 768px) {
  .td-mobile-log-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(10,18,13,.96);
    border-top: 1px solid rgba(255,255,255,.1);
    padding: 12px 16px;
    display: flex;
    gap: 10px;
    z-index: 100;
    backdrop-filter: blur(10px);
    transition: transform .3s ease;
  }
  .td-mobile-log-bar .td-btn-primary { flex: 1; justify-content: center; }
  .td-mobile-log-bar .td-btn-ghost   { padding: 10px 14px; border: 1px solid rgba(255,255,255,.15); border-radius: 8px; }

  /* Push page content above sticky bar on journal/community */
  .td-journal-wrap,
  .td-section:last-of-type { padding-bottom: 80px; }
}

/* ── FOOTER MOBILE ──────────────────────────────────────── */
@media (max-width: 768px) {
  .td-footer-inner {
    flex-direction: column !important;
    gap: 2rem !important;
    padding: 2rem 16px !important;
  }
  .td-footer-links {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 1.5rem !important;
    width: 100%;
  }
  .td-footer-col:last-child {
    grid-column: 1 / -1;
  }
  .td-footer-col ul { margin: 0; padding: 0; }
  .td-footer-col ul li { margin-bottom: 6px; }
  .td-footer-col ul li a { font-size: 0.9rem; }
  .td-footer-col-title { font-size: 0.7rem; margin-bottom: 8px; }
  .td-footer-bottom .td-container {
    flex-direction: column !important;
    gap: 6px !important;
    text-align: center;
    font-size: 0.75rem;
  }
}
@media (max-width: 768px) {
  .td-mobile-log-bar { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  .td-nav { padding-top: env(safe-area-inset-top); }
}

/* ── FOCUS STYLES (accessibility) ──────────────────────── */
a:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid #5fbf7a;
  outline-offset: 2px;
}
