/* ============================================================
   BeginThings — Master Responsive Stylesheet (bt-responsive.css)
   Ensures every element aligns, maintains margins, and looks
   polished on any device from 320px phones to 2K+ desktops.
   Load AFTER bt-facelift.css.
   ============================================================ */

/* ── Global resets ────────────────────────────────────────── */
/* IMPORTANT: overflow-x:hidden on <html> breaks position:sticky.
   Use clip on html (no scroll container), hidden on body only. */
html {
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}
body {
  overflow-x: hidden;
}

/* Ensure --bg-rgb-val is always available for glassmorphism */
html[data-theme='dark'] {
  --bg-rgb-val: 10, 10, 10;
}
html[data-theme='light'] {
  --bg-rgb-val: 248, 250, 252;
}

img, video, svg, canvas, iframe {
  max-width: 100%;
  height: auto;
}

/* Ensure all container classes are consistent */
.container {
  width: 100%;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 16px;
  padding-right: 16px;
}

/* ── HEADER & NAV ─────────────────────────────────────────── */
/* Fixed glassmorphism header — stays on top while scrolling.
   Using position:fixed (not sticky) to avoid overflow ancestor issues.
   JS in bt-design-system.js sets body padding-top to match header height. */
header.main-header {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100% !important;
  z-index: 1020 !important;
  padding: 0.7rem 0;
  /* Translucent glass background */
  background-color: rgba(var(--bg-rgb-val, 10, 10, 10), 0.72) !important;
  background: rgba(var(--bg-rgb-val, 10, 10, 10), 0.72) !important;
  /* Glass blur effect */
  backdrop-filter: blur(16px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(16px) saturate(180%) !important;
  /* Subtle bottom border + glow */
  border-bottom: 1px solid rgba(var(--bg-rgb-val, 10, 10, 10), 0.18) !important;
  box-shadow: 0 1px 12px rgba(0, 0, 0, 0.08);
  transition: background-color 0.3s ease, box-shadow 0.3s ease;
}
/* Light theme: lighter glass tint */
html[data-theme='light'] header.main-header {
  background-color: rgba(248, 250, 252, 0.68) !important;
  background: rgba(248, 250, 252, 0.68) !important;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06) !important;
  box-shadow: 0 1px 12px rgba(0, 0, 0, 0.04);
}
/* Body offset for fixed header — JS sets exact value, this is fallback */
body {
  padding-top: 60px !important;
}

.nav-container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  gap: 12px;
}

/* Logo */
.logo-container {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  flex-shrink: 0;
  min-width: 0;
}

.logo-container .logo {
  height: 32px;
  width: auto;
  flex-shrink: 0;
}

.logo-container .brand-text {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

/* Desktop nav */
.desktop-nav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: nowrap;
}

.desktop-nav a {
  white-space: nowrap;
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  color: var(--text-muted);
  transition: color 0.2s;
}

.desktop-nav a:hover,
.desktop-nav a.active {
  color: var(--text);
  text-decoration: none;
}

/* Hamburger button — hidden on desktop */
.mobile-menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}

/* Sidebar (mobile menu) */
.sidebar {
  position: fixed;
  top: 0;
  right: -300px;
  width: 280px;
  height: 100vh;
  height: 100dvh; /* dynamic viewport on mobile browsers */
  background: var(--bg);
  border-left: 1px solid var(--border);
  z-index: 1050;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  transition: right 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.sidebar.open {
  right: 0;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.sidebar-nav a {
  display: block;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 500;
  padding: 0.8rem 0;
  border-bottom: 1px solid var(--border);
  transition: color 0.2s;
}

.sidebar-nav a:last-child {
  border-bottom: none;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  color: var(--text);
  text-decoration: none;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 1.5rem;
}

/* Overlay */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1040;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

.overlay.open {
  opacity: 1;
  visibility: visible;
}

/* ── BREAKPOINT: ≤ 991px — Switch to hamburger ───────────── */
@media (max-width: 991.98px) {
  .desktop-nav {
    display: none !important;
  }

  .mobile-menu-toggle {
    display: block !important;
  }

  /* Ensure Bootstrap's d-lg-none also works in sync */
  .d-lg-none {
    display: block !important;
  }
}

/* ── BREAKPOINT: ≥ 992px — Desktop nav visible ───────────── */
@media (min-width: 992px) {
  .mobile-menu-toggle,
  .d-lg-none {
    display: none !important;
  }

  .desktop-nav {
    display: flex !important;
  }
}

/* ── FOOTER ───────────────────────────────────────────────── */
footer, .footer, .site-footer {
  padding: 2rem 1rem;
}

.footer-nav {
  text-align: center;
  line-height: 2;
  word-spacing: 0.15em;
}

.footer-nav a {
  display: inline;
  white-space: nowrap;
}

/* ── HERO SECTION ─────────────────────────────────────────── */
.hero-shell {
  border-radius: 1.25rem;
  overflow: hidden;
}

.btHeroGrid {
  display: grid;
  gap: 2rem;
  align-items: start;
  width: 100%;
}

/* ── TOOL GRIDS ───────────────────────────────────────────── */
.home-tool-grid {
  display: grid;
  gap: 1.25rem;
}

.home-category-grid {
  display: grid;
  gap: 1.25rem;
}

.home-saas-grid {
  display: grid;
  gap: 1.25rem;
}

/* ── TOOL CARDS ───────────────────────────────────────────── */
.home-tool-card,
.home-category-card,
.home-saas-card {
  min-width: 0; /* prevent flex/grid blowout */
  overflow: hidden;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.home-tool-card img,
.home-category-card img,
.home-saas-card img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

/* ── TOOL CONTAINER (individual tool pages) ───────────────── */
.tool-container {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.tool-container input,
.tool-container select,
.tool-container textarea {
  max-width: 100%;
  box-sizing: border-box;
}

/* Tables responsive */
.tool-container table {
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* ── COMMAND BAR / SEARCH ─────────────────────────────────── */
.command-bar-wrapper {
  position: relative;
  width: 100%;
}

.command-bar {
  width: 100%;
  box-sizing: border-box;
}

/* ── BUTTONS — full-width on tiny screens ─────────────────── */
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

/* ── PDF TOOLS PAGE ───────────────────────────────────────── */
.pdf-tools-grid {
  display: grid;
  gap: 1rem;
}

.pdf-upload-zone {
  padding: 2rem;
  text-align: center;
}

/* ── AD SLOTS ─────────────────────────────────────────────── */
.ad-slot, .bt-ad-slot {
  max-width: 100%;
  overflow: hidden;
}

/* ── OFFER STRIP / URGENCY BAR ────────────────────────────── */
.offer-strip,
.bt-urgency-bar {
  text-align: center;
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  line-height: 1.5;
}

/* ── SECTION HEADS ────────────────────────────────────────── */
.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ── PREMIUM CTA BANNERS ──────────────────────────────────── */
.bt-premium-cta {
  max-width: 100%;
  overflow: hidden;
}

/* ============================================================
   TABLET LANDSCAPE (≤ 1024px)
   ============================================================ */
@media (max-width: 1024px) {
  .container {
    padding-left: 20px;
    padding-right: 20px;
  }

  .btHeroGrid {
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
  }

  .home-tool-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .home-category-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .home-saas-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .pdf-tools-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ============================================================
   TABLET PORTRAIT (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {
  .container {
    padding-left: 16px;
    padding-right: 16px;
  }

  .btHeroGrid {
    grid-template-columns: 1fr;
    gap: 1.5rem;
  }

  .btHeroRight {
    max-width: 100%;
    justify-self: stretch;
    padding: 10px;
  }

  .hero-shell {
    padding: 2.5rem 1.5rem;
    border-radius: 1rem;
  }

  .hero-left h1,
  .hero-shell h1 {
    font-size: clamp(1.75rem, 5vw, 2.5rem);
    line-height: 1.1;
  }

  .home-tool-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .home-category-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .home-saas-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }

  .pdf-tools-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Section heads stack on tablet */
  .section-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  /* Reduce section spacing */
  section,
  .content-section {
    padding-top: 2.5rem;
    padding-bottom: 2.5rem;
  }

  .page-content-section {
    padding: 1.5rem 0 2rem;
  }

  /* Tool container spacing */
  .tool-container {
    padding: 20px;
    border-radius: 12px;
  }

  /* Page headline sizing */
  .page-headline {
    font-size: 1.75rem;
  }

  .page-subtext {
    font-size: 1rem;
  }

  /* Footer */
  .footer-nav {
    font-size: 0.85rem;
    line-height: 2.2;
  }

  /* PDF tools upload zone */
  .pdf-upload-zone {
    padding: 1.5rem 1rem;
  }

  /* Live widget */
  .bt-liveWidget {
    min-height: 380px;
  }
}

/* ============================================================
   LARGE PHONES (≤ 640px)
   ============================================================ */
@media (max-width: 640px) {
  .home-tool-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .home-category-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .home-saas-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .pdf-tools-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  /* Tool card text sizing */
  .home-tool-card h3 {
    font-size: 0.95rem;
  }

  .home-tool-card .tool-micro {
    font-size: 0.82rem;
  }

  /* Hero actions stack */
  .hero-actions {
    flex-direction: column;
    width: 100%;
  }

  .hero-actions .primary-btn,
  .hero-actions .ghost-btn {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  /* Tool container tighter */
  .tool-container {
    padding: 16px;
    margin-left: 4px;
    margin-right: 4px;
    border-radius: 10px;
  }

  /* Buttons full-width */
  .btn-tool,
  .btn-tool-secondary {
    width: 100%;
    padding: 14px 20px;
    text-align: center;
  }

  /* Chips wrap better */
  .bt-quick-chips {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Search suggestions */
  .search-suggestions {
    max-height: 60vh;
    overflow-y: auto;
  }
}

/* ============================================================
   SMALL PHONES (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
  .container {
    padding-left: 12px;
    padding-right: 12px;
  }

  /* Header */
  .nav-container {
    padding: 0 12px;
  }

  .logo-container .brand-text {
    font-size: 1rem;
  }

  .logo-container .logo {
    height: 28px;
  }

  /* Hero */
  .hero-shell {
    padding: 2rem 1rem;
    border-radius: 0.75rem;
    margin: 0 -4px;
  }

  .hero-left h1,
  .hero-shell h1 {
    font-size: 1.65rem;
    line-height: 1.12;
  }

  .hero-lead {
    font-size: 0.95rem;
  }

  .hero-badge {
    font-size: 0.65rem;
    padding: 0.25rem 0.6rem;
  }

  /* Command bar */
  .command-bar {
    font-size: 1rem;
    padding: 0.9rem 1rem 0.9rem 2.8rem;
  }

  .command-bar-wrapper .command-icon {
    left: 1rem;
    font-size: 1.1rem;
  }

  .command-bar-wrapper .command-kbd {
    display: none; /* Hide keyboard shortcut hint on mobile */
  }

  /* Cards */
  .home-tool-card {
    padding: 0.75rem;
  }

  .home-tool-card .tool-visual {
    height: 80px;
    overflow: hidden;
  }

  .home-tool-card .tool-visual img {
    object-fit: contain;
  }

  .home-tool-card .tool-open-btn {
    font-size: 0.82rem;
    padding: 0.5rem 0.8rem;
  }

  /* Section spacing */
  section,
  .content-section {
    padding-top: 2rem;
    padding-bottom: 2rem;
  }

  h2 {
    font-size: 1.35rem;
  }

  h3 {
    font-size: 1.1rem;
  }

  /* Footer */
  footer, .footer, .site-footer {
    padding: 1.5rem 0.75rem;
  }

  .footer-nav {
    font-size: 0.8rem;
    line-height: 2.4;
  }

  /* Offer strip */
  .offer-strip,
  .bt-urgency-bar {
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
  }

  /* Tool container */
  .tool-container {
    padding: 12px;
    margin-left: 0;
    margin-right: 0;
    border-radius: 8px;
  }

  .page-headline {
    font-size: 1.4rem;
  }

  /* SaaS card */
  .home-saas-card {
    padding: 1.2rem;
  }

  .home-saas-card h3 {
    font-size: 1rem;
  }

  /* PDF tools */
  .pdf-upload-zone {
    padding: 1rem 0.75rem;
  }

  .pdf-upload-zone h3 {
    font-size: 1rem;
  }

  /* Premium CTA banners */
  .bt-premium-cta {
    padding: 1rem;
    border-radius: 10px;
  }

  .bt-premium-cta h3 {
    font-size: 1.05rem;
  }

  .bt-premium-cta-btn {
    width: 100%;
    text-align: center;
  }

  /* Live widget */
  .bt-liveWidget {
    min-height: 280px;
  }

  .btHeroRight {
    padding: 8px;
    border-radius: 20px;
  }

  /* Theme switcher */
  .theme-label {
    font-size: 0.8rem;
  }
}

/* ============================================================
   TINY PHONES (≤ 375px) — iPhone SE, Galaxy S8, etc.
   ============================================================ */
@media (max-width: 375px) {
  .container {
    padding-left: 10px;
    padding-right: 10px;
  }

  .nav-container {
    padding: 0 10px;
  }

  .logo-container .brand-text {
    font-size: 0.9rem;
  }

  .logo-container .logo {
    height: 24px;
  }

  .hero-left h1,
  .hero-shell h1 {
    font-size: 1.45rem;
  }

  .hero-lead {
    font-size: 0.88rem;
  }

  .command-bar {
    font-size: 0.92rem;
    padding: 0.8rem 0.9rem 0.8rem 2.5rem;
  }

  .home-tool-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }

  .home-tool-card h3 {
    font-size: 0.85rem;
  }

  .home-tool-card .tool-micro {
    font-size: 0.75rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .home-tool-card .tool-open-btn {
    font-size: 0.78rem;
    padding: 0.4rem 0.65rem;
  }

  /* Footer pipe separators — stack on tiny screens */
  .footer-nav {
    font-size: 0.78rem;
    line-height: 2.5;
  }

  h2 {
    font-size: 1.2rem;
  }

  .section-head h2 {
    font-size: 1.2rem;
  }

  .section-head p {
    font-size: 0.85rem;
  }

  .primary-btn, .ghost-btn {
    font-size: 0.9rem;
    padding: 0.75rem 1.2rem;
  }

  /* Page headline */
  .page-headline {
    font-size: 1.25rem;
  }

  .page-subtext {
    font-size: 0.88rem;
  }
}

/* ============================================================
   MINIMUM WIDTH (≤ 320px) — Oldest small phones
   ============================================================ */
@media (max-width: 320px) {
  .container {
    padding-left: 8px;
    padding-right: 8px;
  }

  .logo-container .brand-text {
    display: none; /* Just show logo on very tiny screens */
  }

  .hero-shell {
    padding: 1.5rem 0.75rem;
    margin: 0;
  }

  .hero-left h1,
  .hero-shell h1 {
    font-size: 1.3rem;
  }

  .home-tool-grid {
    grid-template-columns: 1fr;
  }

  .home-tool-card .tool-visual {
    display: none; /* Hide thumbnails to save space */
  }

  /* Stack absolutely everything */
  .hero-quick {
    flex-direction: column;
    align-items: stretch;
  }

  .bt-quick-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
  }
}

/* ============================================================
   LARGE DESKTOP (≥ 1440px)
   ============================================================ */
@media (min-width: 1440px) {
  .container {
    max-width: 1320px;
  }

  .btHeroGrid {
    grid-template-columns: 1.15fr 0.85fr;
    gap: 3rem;
  }

  .home-tool-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .home-saas-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .pdf-tools-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ============================================================
   ULTRA-WIDE (≥ 1920px)
   ============================================================ */
@media (min-width: 1920px) {
  .container {
    max-width: 1440px;
  }

  .home-tool-grid {
    grid-template-columns: repeat(5, 1fr);
  }

  .pdf-tools-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ============================================================
   TOUCH DEVICE / HOVER SAFETY
   ============================================================ */
@media (hover: none) {
  .card:hover,
  .home-tool-card:hover,
  .home-category-card:hover,
  .home-saas-card:hover {
    transform: none;
    box-shadow: none;
  }

  .btn:hover:not(:disabled) {
    transform: none;
  }
}

/* ============================================================
   SAFE AREA INSETS (Notched phones — iPhone X+)
   ============================================================ */
@supports (padding-top: env(safe-area-inset-top)) {
  header.main-header {
    padding-top: calc(0.7rem + env(safe-area-inset-top));
  }

  .sidebar {
    padding-top: calc(1.5rem + env(safe-area-inset-top));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }

  footer, .footer, .site-footer {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
}

/* ============================================================
   PRINT — Clean output
   ============================================================ */
@media print {
  header.main-header,
  .sidebar,
  .overlay,
  .ad-slot,
  .bt-ad-slot,
  .offer-strip,
  .bt-urgency-bar,
  .mobile-menu-toggle,
  .hero-shell::before,
  .hero-shell::after,
  .background-subtle,
  #grid-background,
  .aurora-backdrop {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .container {
    max-width: 100%;
    padding: 0;
  }
}

/* ============================================================
   LANDSCAPE PHONE (short viewports)
   ============================================================ */
@media (max-height: 500px) and (orientation: landscape) {
  .hero-shell {
    padding: 1.5rem;
    min-height: auto;
  }

  .bt-liveWidget {
    min-height: 200px;
  }

  .sidebar {
    padding-top: 1rem;
  }

  .sidebar-nav a {
    padding: 0.5rem 0;
    font-size: 0.95rem;
  }
}
