/* ================================================================
   CALBTOOLS TEMPLATE GALLERY
   Professional Responsive Stylesheet v3.0
   ================================================================
   - Fixed: Footer positioning (flexbox layout)
   - Fixed: Toast peek issue (opacity + visibility)
   - Fixed: WordPress admin bar overlap
   - Added: Professional polish, scrollbar, focus states
   - Added: Accessibility (reduced motion, focus-visible)
   - Fully responsive: 320px → 1920px
   ================================================================ */

/* ================================================================
   1. RESET & BOX MODEL
   ================================================================ */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

/* ================================================================
   2. DESIGN TOKENS (CSS Variables)
   ================================================================ */
:root {
  /* Colors - Light Mode */
  --bg: #f4f6fb;
  --bg-alt: #ffffff;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-soft: #475569;
  --muted: #64748b;
  --border: #e2e8f0;
  --border-soft: #f1f5f9;

  /* Brand */
  --accent: #667eea;
  --accent-2: #764ba2;
  --accent-3: #f093fb;
  --accent-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  --btn-gradient: linear-gradient(135deg, #667eea, #764ba2);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --shadow-hover: 0 16px 40px rgba(102, 126, 234, 0.22);
  --shadow-toast: 0 10px 30px rgba(0, 0, 0, 0.25);

  /* Radii */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  /* Spacing */
  --gap-sm: 8px;
  --gap: 14px;
  --gap-md: 18px;
  --gap-lg: 24px;

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --ease-bounce: cubic-bezier(0.2, 0.9, 0.3, 1.2);
  --transition-fast: 0.15s var(--ease);
  --transition: 0.25s var(--ease);
  --transition-slow: 0.35s var(--ease);
}

/* Dark Mode */
body.dark {
  --bg: #0f1120;
  --bg-alt: #161a2e;
  --card-bg: #1a1d33;
  --text: #e8ecf6;
  --text-soft: #cbd5e1;
  --muted: #94a3b8;
  --border: #2a2f4a;
  --border-soft: #1f2438;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-hover: 0 16px 40px rgba(102, 126, 234, 0.35);
  --shadow-toast: 0 10px 30px rgba(0, 0, 0, 0.6);
}

/* ================================================================
   3. BASE TYPOGRAPHY & BODY
   ================================================================ */
body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont,
               'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  padding: 16px;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition), color var(--transition);
  overflow-x: hidden;
}

/* Selection */
::selection {
  background: var(--accent);
  color: #ffffff;
}
::-moz-selection {
  background: var(--accent);
  color: #ffffff;
}

/* Custom Scrollbar (Webkit) */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: var(--bg);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* Firefox Scrollbar */
html {
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}

/* Focus Visible (Accessibility) */
:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}
button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ================================================================
   4. LAYOUT – MAIN FLEXBOX (Fixes Footer Position)
   ================================================================ */
main {
  flex: 1 0 auto;
  width: 100%;
}

header.hero,
.search-wrap,
.category-filter,
footer {
  flex-shrink: 0;
}

/* ================================================================
   5. HERO SECTION
   ================================================================ */
.hero {
  background: var(--accent-gradient);
  border-radius: var(--radius-lg);
  padding: 30px 24px;
  margin-bottom: var(--gap-md);
  color: #ffffff;
  position: relative;
  overflow: hidden;
  isolation: isolate;
}

.hero::before {
  content: "";
  position: absolute;
  top: -60px;
  right: -60px;
  width: 240px;
  height: 240px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 50%;
  z-index: 0;
  pointer-events: none;
}

.hero::after {
  content: "";
  position: absolute;
  bottom: -90px;
  left: -50px;
  width: 200px;
  height: 200px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 50%;
  z-index: 0;
  pointer-events: none;
}

.hero-inner {
  position: relative;
  z-index: 2;
  max-width: 1140px;
  margin: 0 auto;
}

.hero-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.hero h1 {
  font-size: clamp(20px, 3vw, 28px);
  font-weight: 800;
  letter-spacing: -0.5px;
  line-height: 1.2;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.hero h1 span {
  font-weight: 400;
  opacity: 0.92;
}

.hero-sub {
  margin-top: 10px;
  font-size: clamp(13px, 1.8vw, 15.5px);
  opacity: 0.96;
  max-width: 680px;
  line-height: 1.55;
}

/* Theme Toggle Button */
.theme-toggle {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.4);
  color: #ffffff;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 19px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform var(--transition), background var(--transition);
  user-select: none;
}
.theme-toggle:hover {
  transform: scale(1.1) rotate(15deg);
  background: rgba(255, 255, 255, 0.35);
}
.theme-toggle:active {
  transform: scale(0.95) rotate(15deg);
}

/* ================================================================
   6. SEARCH BOX
   ================================================================ */
.search-wrap {
  max-width: 760px;
  margin: 0 auto var(--gap-md);
  width: 100%;
}

#searchBox {
  width: 100%;
  padding: 15px 20px 15px 48px;
  font-size: 15px;
  font-family: inherit;
  border: 2px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card-bg)
              url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E")
              no-repeat 18px center;
  background-size: 20px;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
  appearance: none;
}
#searchBox::placeholder {
  color: var(--muted);
  opacity: 0.9;
}
#searchBox:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.15);
}

/* ================================================================
   7. CATEGORY FILTER
   ================================================================ */
.category-filter {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap-sm);
  justify-content: center;
  margin-bottom: var(--gap-md);
  max-width: 1140px;
  margin-left: auto;
  margin-right: auto;
}

.filter-btn {
  padding: 10px 20px;
  border: 2px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  font-weight: 600;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.filter-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-sm);
}

.filter-btn:active {
  transform: translateY(0);
}

.filter-btn.active {
  background: var(--btn-gradient);
  color: #ffffff;
  border-color: transparent;
  box-shadow: 0 6px 18px rgba(102, 126, 234, 0.35);
}
.filter-btn.active:hover {
  color: #ffffff;
  transform: translateY(-2px);
}

/* ================================================================
   8. RESULT INFO
   ================================================================ */
.result-info {
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: var(--gap);
  min-height: 20px;
}

/* ================================================================
   9. TEMPLATE GRID
   ================================================================ */
.template-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--gap-md);
  max-width: 1240px;
  margin: 0 auto;
  padding-bottom: var(--gap-lg);
}

/* ================================================================
   10. TEMPLATE CARD
   ================================================================ */
.template-card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), box-shadow var(--transition);
  animation: fadeUp 0.45s var(--ease) both;
  will-change: transform;
  border: 1px solid var(--border-soft);
}

.template-card:hover {
  transform: translateY(-6px);
  box-shadow: var(--shadow-hover);
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Thumbnail */
.card-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  display: block;
  object-fit: cover;
  background: var(--border-soft);
  transition: transform var(--transition-slow);
}

.template-card:hover .card-thumb {
  transform: scale(1.02);
}

/* Card Body */
.card-body {
  padding: 16px 18px 18px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.card-cat {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.3px;
  font-weight: 800;
  color: var(--accent-2);
  margin-bottom: 8px;
}

body.dark .card-cat {
  color: var(--accent);
}

.card-title {
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
  margin-bottom: 8px;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-desc {
  font-size: 13.5px;
  color: var(--muted);
  line-height: 1.55;
  flex: 1;
  margin-bottom: 16px;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Card Actions */
.card-actions {
  display: flex;
  gap: var(--gap-sm);
}

.btn {
  flex: 1;
  padding: 11px 10px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform var(--transition-fast), opacity var(--transition),
              background var(--transition), box-shadow var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  user-select: none;
  white-space: nowrap;
  min-height: 42px;
}

.btn:active {
  transform: scale(0.96);
}

.btn-copy {
  background: var(--btn-gradient);
  color: #ffffff;
  box-shadow: 0 3px 10px rgba(102, 126, 234, 0.3);
}
.btn-copy:hover {
  opacity: 0.92;
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.45);
  transform: translateY(-1px);
}

.btn-download {
  background: transparent;
  color: var(--accent);
  border: 2px solid var(--accent);
}
.btn-download:hover {
  background: var(--accent);
  color: #ffffff;
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(102, 126, 234, 0.3);
}

/* ================================================================
   11. EMPTY STATE
   ================================================================ */
.empty-state {
  text-align: center;
  padding: 70px 20px;
  color: var(--muted);
  max-width: 500px;
  margin: 0 auto;
}

.empty-emoji {
  font-size: 54px;
  margin-bottom: 16px;
  opacity: 0.85;
}

.empty-state h3 {
  color: var(--text);
  margin-bottom: 8px;
  font-size: 20px;
  font-weight: 700;
}

.empty-state p {
  font-size: 14.5px;
  line-height: 1.6;
}

/* ================================================================
   12. FOOTER (Fixed Positioning)
   ================================================================ */
footer {
  text-align: center;
  padding: 26px 16px 32px;
  color: var(--muted);
  font-size: 14px;
  margin-top: var(--gap-lg);
  border-top: 1px solid var(--border);
  line-height: 1.6;
  flex-shrink: 0;
}

footer p {
  margin-bottom: 6px;
}

footer strong {
  color: var(--text);
  font-weight: 700;
}

.footer-small {
  font-size: 12.5px;
  margin-top: 6px;
  opacity: 0.85;
}

/* ================================================================
   13. TOAST (Fixed Peek Issue)
   ================================================================ */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(180%);
  background: #1a1a2e;
  color: #ffffff;
  padding: 13px 24px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-toast);
  transition: transform var(--transition-slow) var(--ease-bounce),
              opacity 0.3s var(--ease),
              visibility 0.3s var(--ease);
  z-index: 9999;
  pointer-events: none;
  max-width: calc(100vw - 40px);
  text-align: center;
  opacity: 0;
  visibility: hidden;
  line-height: 1.4;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
  visibility: visible;
}

.toast.success {
  background: linear-gradient(135deg, #10b981, #059669);
}

.toast.error {
  background: linear-gradient(135deg, #ef4444, #b91c1c);
}

/* ================================================================
   14. RESPONSIVE BREAKPOINTS
   ================================================================ */

/* Extra Small (320px - 400px) */
@media (max-width: 400px) {
  body {
    padding: 8px;
    font-size: 14px;
  }
  .hero {
    padding: 22px 16px;
    border-radius: var(--radius-md);
  }
  .hero h1 {
    font-size: 19px;
  }
  .hero-sub {
    font-size: 13px;
  }
  .theme-toggle {
    width: 40px;
    height: 40px;
    min-width: 40px;
    font-size: 17px;
  }
  .template-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }
  .filter-btn {
    padding: 8px 14px;
    font-size: 12.5px;
  }
  #searchBox {
    padding: 12px 16px 12px 44px;
    font-size: 14px;
    background-size: 18px;
    background-position: 15px center;
  }
  .btn {
    font-size: 12.5px;
    padding: 10px 8px;
  }
  .card-body {
    padding: 14px 14px 16px;
  }
  .card-title {
    font-size: 15.5px;
  }
  .card-desc {
    font-size: 12.5px;
  }
  footer {
    padding: 20px 12px 26px;
    font-size: 12.5px;
  }
  .toast {
    font-size: 13px;
    padding: 11px 18px;
  }
}

/* Small Mobile (401px - 600px) */
@media (min-width: 401px) and (max-width: 600px) {
  .template-grid {
    grid-template-columns: 1fr;
  }
  .hero h1 {
    font-size: 21px;
  }
}

/* Tablet (601px - 900px) */
@media (min-width: 601px) and (max-width: 900px) {
  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Desktop (901px - 1099px) */
@media (min-width: 901px) and (max-width: 1099px) {
  .template-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Large Desktop (1100px+) */
@media (min-width: 1100px) {
  .template-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* Extra Large (1500px+) */
@media (min-width: 1500px) {
  .template-grid {
    grid-template-columns: repeat(4, 1fr);
  }
  body {
    padding: 22px 32px;
  }
}

/* Ultra Wide (1920px+) */
@media (min-width: 1920px) {
  .template-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ================================================================
   15. WORDPRESS ADMIN BAR SUPPORT
   ================================================================ */
body.admin-bar {
  padding-top: 32px;
}

@media (max-width: 782px) {
  body.admin-bar {
    padding-top: 46px;
  }
}

/* ================================================================
   16. ACCESSIBILITY – REDUCED MOTION
   ================================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .template-card:hover {
    transform: none;
  }
  .theme-toggle:hover {
    transform: none;
  }
  .filter-btn:hover {
    transform: none;
  }
}

/* ================================================================
   17. HIGH CONTRAST MODE
   ================================================================ */
@media (prefers-contrast: high) {
  .template-card {
    border: 2px solid var(--text);
  }
  .filter-btn {
    border-width: 2.5px;
  }
  .btn {
    border-width: 2.5px;
  }
}

/* ================================================================
   18. PRINT STYLES
   ================================================================ */
@media print {
  body {
    background: #ffffff;
    color: #000000;
    padding: 0;
  }
  .category-filter,
  .search-wrap,
  .theme-toggle,
  .card-actions,
  .toast,
  footer {
    display: none !important;
  }
  .template-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  .template-card {
    box-shadow: none;
    border: 1px solid #cccccc;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .hero {
    background: #f0f0f0;
    color: #000000;
  }
}

/* ================================================================
   19. UTILITY CLASSES
   ================================================================ */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hidden {
  display: none !important;
}

/* ================================================================
   20. SMOOTH THEME TRANSITION
   ================================================================ */
body,
.template-card,
.filter-btn,
#searchBox,
footer,
.hero {
  transition: background-color 0.3s var(--ease),
              border-color 0.3s var(--ease),
              color 0.3s var(--ease);
}

/* Avoid transition on transform hover states */
.template-card:hover,
.filter-btn:hover,
.btn:hover {
  transition: transform var(--transition), box-shadow var(--transition),
              opacity var(--transition), background var(--transition);
}