/* ============================================================
   Smart Tools Hub Pro – Frontend CSS
   ============================================================ */

/* ─── CSS Variables ──────────────────────────────────────── */
:root {
  --sth-bg:           #f7f8fc;
  --sth-surface:      #ffffff;
  --sth-border:       #e8eaf0;
  --sth-text:         #1a1d2e;
  --sth-muted:        #6b7080;
  --sth-accent:       #4f46e5;        /* indigo */
  --sth-accent-light: #eef2ff;
  --sth-accent-hover: #4338ca;
  --sth-success:      #10b981;
  --sth-card-shadow:  0 2px 8px rgba(0,0,0,.07), 0 0 1px rgba(0,0,0,.05);
  --sth-card-hover:   0 8px 24px rgba(79,70,229,.15), 0 0 1px rgba(0,0,0,.05);
  --sth-radius:       12px;
  --sth-radius-sm:    8px;
  --sth-font:         -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --sth-ad-width:     160px;
  --sth-topbar-h:     60px;
}

/* ─── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.sth-page {
  font-family: var(--sth-font);
  color: var(--sth-text);
  background: var(--sth-bg);
  line-height: 1.6;
}

/* ─── Top Bar ────────────────────────────────────────────── */
.sth-topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: var(--sth-surface);
  border-bottom: 1px solid var(--sth-border);
  height: var(--sth-topbar-h);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}
.sth-topbar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sth-logo {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--sth-accent);
  text-decoration: none;
  letter-spacing: -.3px;
}
.sth-nav { display: flex; gap: 20px; }
.sth-nav a {
  color: var(--sth-muted);
  text-decoration: none;
  font-size: .9rem;
  transition: color .2s;
}
.sth-nav a:hover { color: var(--sth-accent); }

/* ─── Hero ───────────────────────────────────────────────── */
.sth-hero {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff;
  padding: 60px 24px 48px;
  text-align: center;
}
.sth-hero-inner { max-width: 720px; margin: 0 auto; }
.sth-hero-emoji { font-size: 2.8rem; display: block; margin-bottom: 10px; }
.sth-hero-title {
  font-size: clamp(1.8rem, 4vw, 3rem);
  font-weight: 800;
  letter-spacing: -.5px;
  margin-bottom: 12px;
}
.sth-hero-desc {
  font-size: 1.05rem;
  opacity: .85;
  margin-bottom: 32px;
}

/* Search bar */
.sth-search-wrap {
  display: flex;
  max-width: 540px;
  margin: 0 auto;
  background: #fff;
  border-radius: 50px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0,0,0,.2);
}
.sth-search-input {
  flex: 1;
  border: none;
  outline: none;
  padding: 14px 20px;
  font-size: 1rem;
  color: var(--sth-text);
  background: transparent;
}
.sth-search-btn {
  background: var(--sth-accent);
  border: none;
  color: #fff;
  padding: 0 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background .2s;
}
.sth-search-btn:hover { background: var(--sth-accent-hover); }

/* ─── Filter Bar ─────────────────────────────────────────── */
.sth-filter-section {
  background: var(--sth-surface);
  border-bottom: 1px solid var(--sth-border);
  position: sticky;
  top: var(--sth-topbar-h);
  z-index: 900;
}
.sth-filter-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow-x: auto;
  scrollbar-width: none;
}
.sth-filter-inner::-webkit-scrollbar { display: none; }

.sth-categories { display: flex; gap: 8px; flex: 1; flex-wrap: nowrap; }
.sth-cat-btn {
  background: none;
  border: 1.5px solid var(--sth-border);
  color: var(--sth-muted);
  border-radius: 50px;
  padding: 6px 16px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all .18s;
}
.sth-cat-btn:hover {
  border-color: var(--sth-accent);
  color: var(--sth-accent);
}
.sth-cat-btn.active {
  background: var(--sth-accent);
  border-color: var(--sth-accent);
  color: #fff;
}

.sth-sort-select {
  border: 1.5px solid var(--sth-border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: .85rem;
  color: var(--sth-text);
  background: var(--sth-surface);
  cursor: pointer;
  outline: none;
}
.sth-sort-select:focus { border-color: var(--sth-accent); }

/* ─── Grid Section ───────────────────────────────────────── */
.sth-grid-section { padding: 32px 24px 64px; }
.sth-container { max-width: 1400px; margin: 0 auto; }

.sth-results-info {
  font-size: .85rem;
  color: var(--sth-muted);
  margin-bottom: 16px;
}

.sth-tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

/* Tool Card */
.sth-tool-card {
  display: flex;
  flex-direction: column;
  background: var(--sth-surface);
  border: 1.5px solid var(--sth-border);
  border-radius: var(--sth-radius);
  padding: 20px;
  text-decoration: none;
  color: var(--sth-text);
  transition: all .2s;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.sth-tool-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 4px; height: 100%;
  background: var(--sth-accent);
  opacity: 0;
  transition: opacity .2s;
}
.sth-tool-card:hover {
  box-shadow: var(--sth-card-hover);
  border-color: var(--sth-accent);
  transform: translateY(-2px);
}
.sth-tool-card:hover::before { opacity: 1; }

.sth-card-icon {
  font-size: 2rem;
  margin-bottom: 10px;
  line-height: 1;
}
.sth-card-name {
  font-weight: 600;
  font-size: .95rem;
  margin-bottom: 4px;
  color: var(--sth-text);
}
.sth-card-cat {
  font-size: .78rem;
  color: var(--sth-muted);
}
.sth-card-body { flex: 1; }
.sth-card-arrow {
  margin-top: 12px;
  color: var(--sth-accent);
  font-size: 1.1rem;
  transition: transform .2s;
}
.sth-tool-card:hover .sth-card-arrow { transform: translateX(4px); }

/* Small grid variant (related tools) */
.sth-tool-grid--sm {
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.sth-tool-grid--sm .sth-tool-card {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
}
.sth-tool-grid--sm .sth-card-icon { font-size: 1.5rem; margin-bottom: 0; }

/* ─── Skeleton Loader ────────────────────────────────────── */
.sth-loading-skeleton {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.sth-skeleton-card {
  background: var(--sth-surface);
  border: 1.5px solid var(--sth-border);
  border-radius: var(--sth-radius);
  padding: 20px;
  animation: sth-pulse 1.5s ease-in-out infinite;
}
.sth-skeleton-icon {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--sth-border);
  margin-bottom: 12px;
}
.sth-skeleton-text {
  height: 14px;
  border-radius: 4px;
  background: var(--sth-border);
  margin-bottom: 8px;
}
.sth-skeleton-short { width: 60%; }

@keyframes sth-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .5; }
}

/* ─── Pagination ─────────────────────────────────────────── */
.sth-pagination {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 40px;
}
.sth-page-btn {
  min-width: 38px;
  height: 38px;
  border-radius: var(--sth-radius-sm);
  border: 1.5px solid var(--sth-border);
  background: var(--sth-surface);
  color: var(--sth-text);
  font-size: .9rem;
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sth-page-btn:hover, .sth-page-btn.active {
  background: var(--sth-accent);
  border-color: var(--sth-accent);
  color: #fff;
}

/* ─── Single Tool Page ───────────────────────────────────── */
.sth-single-page { max-width: 1400px; margin: 0 auto; padding: 0 24px 64px; }

/* Breadcrumb */
.sth-breadcrumb { padding: 14px 0 0; }
.sth-breadcrumb ol {
  list-style: none;
  display: flex;
  gap: 6px;
  font-size: .84rem;
  color: var(--sth-muted);
}
.sth-breadcrumb a { color: var(--sth-accent); text-decoration: none; }
.sth-breadcrumb a:hover { text-decoration: underline; }

/* Tool Header */
.sth-tool-header {
  padding: 24px 0 20px;
  border-bottom: 1px solid var(--sth-border);
  margin-bottom: 24px;
}
.sth-tool-header-inner { display: flex; align-items: center; gap: 16px; }
.sth-tool-icon-lg { font-size: 3rem; line-height: 1; }
.sth-tool-title {
  font-size: clamp(1.4rem, 3vw, 2rem);
  font-weight: 800;
  letter-spacing: -.4px;
  margin-bottom: 4px;
}
.sth-tool-desc { color: var(--sth-muted); font-size: .95rem; margin-bottom: 10px; }
.sth-tool-badges { display: flex; gap: 8px; flex-wrap: wrap; }
.sth-badge-cat, .sth-badge-free, .sth-badge-views {
  font-size: .78rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 50px;
  background: var(--sth-accent-light);
  color: var(--sth-accent);
}
.sth-badge-free { background: #d1fae5; color: #065f46; }
.sth-badge-views { background: #f3f4f6; color: var(--sth-muted); }

/* Three-column layout */
.sth-tool-layout {
  display: grid;
  grid-template-columns: var(--sth-ad-width) 1fr var(--sth-ad-width);
  gap: 20px;
  align-items: start;
}

/* Sidebar Ads */
.sth-sidebar-ad {
  position: sticky;
  top: calc(var(--sth-topbar-h) + 24px);
  min-height: 300px;
}
.sth-ad-label {
  font-size: .68rem;
  color: var(--sth-muted);
  text-align: center;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.sth-ad-placeholder {
  border: 2px dashed var(--sth-border);
  border-radius: var(--sth-radius-sm);
  min-height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sth-muted);
  font-size: .8rem;
  text-align: center;
}

/* Tool content area */
.sth-tool-content {
  background: var(--sth-surface);
  border: 1.5px solid var(--sth-border);
  border-radius: var(--sth-radius);
  padding: 28px;
  min-height: 400px;
  overflow: visible;  /* Must NOT be hidden — tools may have dropdowns/modals */
  min-width: 0;       /* Prevent grid blowout */
}
/* Tool scope wrapper (set by PHP) */
.sth-tool-scope {
  width: 100%;
  max-width: 100%;
}

/* Mobile Ad */
.sth-mobile-ad {
  display: none;
  margin-top: 24px;
  padding: 12px;
  background: var(--sth-surface);
  border: 1px solid var(--sth-border);
  border-radius: var(--sth-radius-sm);
  text-align: center;
}

/* Related Tools */
.sth-related-tools {
  margin-top: 40px;
  padding-top: 32px;
  border-top: 1px solid var(--sth-border);
}
.sth-related-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 16px;
}

/* Back Link */
.sth-back-link {
  margin-top: 32px;
  text-align: center;
}
.sth-back-link a {
  color: var(--sth-accent);
  text-decoration: none;
  font-weight: 600;
}
.sth-back-link a:hover { text-decoration: underline; }

/* ─── Footer ─────────────────────────────────────────────── */
.sth-footer {
  background: var(--sth-surface);
  border-top: 1px solid var(--sth-border);
  padding: 24px;
  margin-top: 48px;
}
.sth-footer-inner {
  max-width: 1400px;
  margin: 0 auto;
  text-align: center;
  color: var(--sth-muted);
  font-size: .85rem;
}

/* ─── Responsive ─────────────────────────────────────────── */
@media (max-width: 1100px) {
  .sth-tool-layout {
    grid-template-columns: var(--sth-ad-width) 1fr;
  }
  .sth-sidebar-ad--right { display: none; }
}

@media (max-width: 768px) {
  .sth-tool-layout {
    grid-template-columns: 1fr;
  }
  .sth-sidebar-ad--left, .sth-sidebar-ad--right { display: none; }
  .sth-mobile-ad { display: block; }

  .sth-hero { padding: 40px 16px 36px; }
  .sth-tool-header-inner { flex-direction: column; align-items: flex-start; }
  .sth-tool-icon-lg { font-size: 2.4rem; }
  .sth-single-page { padding: 0 16px 48px; }
  .sth-grid-section { padding: 24px 16px 48px; }

  .sth-tool-grid {
    grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  }
}

@media (max-width: 480px) {
  .sth-search-input { padding: 12px 14px; font-size: .9rem; }
  .sth-search-btn { padding: 0 16px; }
  .sth-tool-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ─── Tool Scope Container ───────────────────────────────── */
/*
 * .sth-tool-scope isolates the injected tool HTML so its CSS
 * doesn't bleed into the WordPress theme, and vice versa.
 * We reset box-sizing and font so tools render consistently.
 */
.sth-tool-scope {
  all: initial;           /* Hard reset inherited theme styles      */
  display: block;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #1a1d2e;
  box-sizing: border-box;
}
/* Re-apply box-sizing to all children */
.sth-tool-scope *,
.sth-tool-scope *::before,
.sth-tool-scope *::after {
  box-sizing: border-box;
}
/* Make sure images stay inside */
.sth-tool-scope img,
.sth-tool-scope video,
.sth-tool-scope canvas,
.sth-tool-scope iframe {
  max-width: 100%;
  height: auto;
}
/* Basic link reset so they're visible */
.sth-tool-scope a { color: #4f46e5; }

/* ─── Utilities ──────────────────────────────────────────── */
.sth-no-results {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--sth-muted);
}
.sth-no-results .sth-no-icon { font-size: 3rem; display: block; margin-bottom: 12px; }

/* ─── Reduced motion ─────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ─── Print isolation ────────────────────────────────────── */
/*
 * Many tools include their own "isolate the printable area" CSS, e.g.
 *   @media print {
 *     body * { visibility: hidden; }
 *     .resume-paper, .resume-paper * { visibility: visible; }
 *   }
 * This works perfectly in the tool's standalone HTML file, where the
 * tool's own <body> is the entire page. Once embedded in WordPress, that
 * same body now also contains the site header, footer, sidebars, ad
 * slots, and "More Tools" widgets — all SIBLINGS of (not descendants of)
 * the tool's #sth-ts-xxx wrapper. A tool's own print rule has no way to
 * reach those, since it only knows about elements inside its own scope.
 * Result: printing a tool page also prints the surrounding site chrome.
 *
 * Fix: explicitly hide Smart Tools Hub's own page chrome (breadcrumb,
 * tool header, ad slots, related-tools section) plus common WordPress
 * theme regions (header/footer/nav) whenever printing. Each tool's own
 * internal print rules then run unmodified inside its own scope, exactly
 * as they do standalone — we're only cleaning up what's around it.
 */
@media print {
  /* Smart Tools Hub's own page chrome (single-tool.php template) that
     sits as a SIBLING of .sth-tool-scope, not a descendant — a tool's
     own print rules (e.g. body * { visibility:hidden }) can't reach
     these because they only apply inside the tool's own scope. */
  .sth-breadcrumb,
  .sth-tool-header,
  .sth-sidebar-ad,
  .sth-mobile-ad,
  .sth-related-tools,
  .sth-back-link {
    display: none !important;
  }

  /* Common WordPress theme regions (header/footer/nav/widgets) that
     wrap the whole page outside our plugin's own markup. Covers the
     generic HTML5 landmark elements plus GenerateBlocks/typical theme
     class and id conventions. */
  body > header,
  body > footer,
  body > nav,
  #masthead,
  #colophon,
  #wpadminbar,
  .site-header,
  .site-footer,
  .gb-site-header,
  .gb-site-footer,
  .sth-sidebar-ad {
    display: none !important;
  }
}