/* ═══════════════════════════════════════════════════════════
   FRONTEND OPTIMIZATIONS - FINAL POLISH
   Comprehensive improvements for chat, products, and responsiveness
   ═══════════════════════════════════════════════════════════ */

/* ─── CRITICAL VIEWPORT & OVERFLOW FIXES ─────────────────── */
html {
  scroll-behavior: smooth;
  max-width: 100%;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  overscroll-behavior-x: none;
  position: relative;
}

* {
  box-sizing: border-box;
}

*::before,
*::after {
  box-sizing: border-box;
}

/* Prevent layout shift from images and media */
img, video, iframe, embed, object {
  max-width: 100%;
  height: auto;
  display: block;
}

/* ─── ENHANCED CHAT WIDGET POSITIONING ──────────────────── */
.hostiny-chat-widget {
  position: fixed;
  bottom: clamp(20px, 3vw, 28px);
  right: clamp(20px, 3vw, 28px);
  inset-inline-end: clamp(20px, 3vw, 28px);
  z-index: 9998;
  isolation: isolate;
}

.hostiny-chat-launcher {
  width: clamp(56px, 8vw, 64px);
  height: clamp(56px, 8vw, 64px);
  border-radius: 50%;
  border: 0;
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  font-size: clamp(1.5rem, 3vw, 1.8rem);
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(16, 185, 129, 0.4), 0 0 0 0 rgba(16, 185, 129, 0.6);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: chat-pulse 2.5s infinite;
}

.hostiny-chat-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 32px rgba(16, 185, 129, 0.5);
}

.hostiny-chat-launcher:active {
  transform: scale(0.96);
}

@keyframes chat-pulse {
  0%, 100% {
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.4), 0 0 0 0 rgba(16, 185, 129, 0.6);
  }
  50% {
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.4), 0 0 0 12px rgba(16, 185, 129, 0);
  }
}

.hostiny-chat-panel {
  position: fixed;
  bottom: clamp(96px, 12vw, 108px);
  right: clamp(20px, 3vw, 28px);
  inset-inline-end: clamp(20px, 3vw, 28px);
  width: min(380px, calc(100vw - 40px));
  max-height: min(520px, calc(100vh - 140px));
  border-radius: 20px;
  background: rgba(15, 23, 42, 0.98);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform-origin: bottom right;
  animation: chat-panel-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hostiny-chat-panel[hidden] {
  display: none;
}

@keyframes chat-panel-in {
  from {
    opacity: 0;
    transform: scale(0.85) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.hostiny-chat-panel-head {
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(255, 255, 255, 0.05));
}

.hostiny-chat-panel-head strong {
  display: block;
  font-size: 1.05rem;
  font-weight: 700;
  color: #eef4ff;
  margin-bottom: 4px;
}

.hostiny-chat-panel-head span {
  display: block;
  font-size: 0.88rem;
  color: rgba(158, 176, 209, 0.9);
}

.hostiny-chat-panel-body {
  padding: 20px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hostiny-chat-panel-body p {
  margin: 0;
  color: rgba(237, 243, 255, 0.95);
  line-height: 1.75;
  font-size: 0.94rem;
}

.inline-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.inline-actions .btn {
  width: 100%;
  justify-content: center;
  min-height: 46px;
  font-size: 0.92rem;
}

/* ─── ENHANCED PRODUCTS PAGE ────────────────────────────── */
.pricing-hero {
  padding-block: clamp(32px, 5vw, 56px);
}

.pricing-hero-shell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(24px, 4vw, 36px);
}

.pricing-hero-card {
  width: 100%;
  max-width: 920px;
  text-align: center;
}

.pricing-hero-card h1 {
  font-size: clamp(1.85rem, 4.5vw, 3rem);
  line-height: 1.3;
  margin: 0 0 clamp(14px, 2.5vw, 20px) 0;
  font-weight: 800;
  background: linear-gradient(135deg, #edf3ff, #b8d4ff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.pricing-hero-card .muted {
  font-size: clamp(1rem, 2vw, 1.15rem);
  line-height: 1.75;
  color: rgba(158, 176, 209, 0.95);
  margin-bottom: clamp(24px, 4vw, 32px);
}

/* Enhanced pricing toolbar */
.pricing-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 3vw, 24px);
  margin-top: clamp(20px, 3vw, 28px);
  width: 100%;
}

/* Segment control - improved scrolling */
.segment-control {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 100%;
}

.segment-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: clamp(11px, 1.5vw, 14px) clamp(18px, 2.5vw, 22px);
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  background: rgba(255, 255, 255, 0.04);
  color: rgba(158, 176, 209, 0.9);
  font-size: clamp(0.88rem, 1.5vw, 0.94rem);
  font-weight: 600;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  cursor: pointer;
  white-space: nowrap;
  min-height: 44px;
  flex-shrink: 0;
}

.segment-chip:hover {
  color: #edf3ff;
  border-color: rgba(94, 163, 255, 0.3);
  background: rgba(94, 163, 255, 0.1);
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(47, 125, 240, 0.15);
}

.segment-chip.active {
  color: #ffffff;
  border-color: rgba(94, 163, 255, 0.5);
  background: linear-gradient(135deg, rgba(47, 125, 240, 0.35), rgba(94, 163, 255, 0.22));
  box-shadow: 
    0 14px 32px rgba(47, 125, 240, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transform: translateY(-3px);
}

/* Billing switch - improved design */
.billing-switch {
  display: flex;
  padding: 5px;
  border-radius: 999px;
  width: fit-content;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
}

.billing-switch-option {
  border: 0;
  min-width: clamp(95px, 12vw, 110px);
  padding: clamp(10px, 1.5vw, 12px) clamp(18px, 2.5vw, 22px);
  border-radius: 999px;
  background: transparent;
  color: rgba(158, 176, 209, 0.85);
  cursor: pointer;
  font-size: clamp(0.88rem, 1.5vw, 0.92rem);
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  white-space: nowrap;
}

.billing-switch-option:hover {
  color: #edf3ff;
  background: rgba(255, 255, 255, 0.06);
}

.billing-switch-option.active {
  background: linear-gradient(135deg, #5ea3ff, #2f7df0);
  color: #ffffff;
  box-shadow: 0 10px 24px rgba(47, 125, 240, 0.35);
  transform: scale(1.03);
}

/* Enhanced pricing grid */
.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
  gap: clamp(22px, 3.5vw, 30px);
  align-items: stretch;
  margin-top: clamp(32px, 5vw, 48px);
}

/* Enhanced pricing cards */
.pricing-card {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 2.5vw, 22px);
  padding: clamp(24px, 3.5vw, 30px);
  border-radius: clamp(24px, 3vw, 30px);
  min-height: 100%;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), rgba(255, 255, 255, 0.02)),
    rgba(19, 31, 56, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), 
              box-shadow 0.35s ease, 
              border-color 0.35s ease;
}

.pricing-card:hover {
  transform: translateY(-10px);
  box-shadow: 0 24px 52px rgba(0, 0, 0, 0.35);
  border-color: rgba(94, 163, 255, 0.25);
}

.pricing-card.featured {
  transform: translateY(-12px) scale(1.02);
  border-color: rgba(94, 163, 255, 0.45);
  background:
    linear-gradient(160deg, rgba(94, 163, 255, 0.22), rgba(68, 215, 182, 0.1) 45%, rgba(255, 255, 255, 0.05)),
    rgba(19, 31, 56, 0.98);
  box-shadow: 
    0 22px 56px rgba(27, 97, 212, 0.32), 
    0 0 0 1px rgba(94, 163, 255, 0.25);
}

.pricing-card.featured:hover {
  transform: translateY(-16px) scale(1.025);
  box-shadow: 0 28px 64px rgba(27, 97, 212, 0.4);
}

/* Card billing toggle improvements */
.card-billing-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 10px;
  margin: 0 auto 8px;
  width: 100%;
  max-width: 280px;
}

.toggle-label {
  font-size: 0.88rem;
  color: rgba(158, 176, 209, 0.75);
  font-weight: 600;
  transition: color 0.25s ease;
  cursor: pointer;
  user-select: none;
}

.toggle-label.active-label {
  color: #edf3ff;
}

.toggle-track {
  position: relative;
  width: 48px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.12);
  cursor: pointer;
  transition: background 0.3s ease;
  flex-shrink: 0;
}

.toggle-track::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  inset-inline-start: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5ea3ff, #2f7df0);
  box-shadow: 0 4px 12px rgba(47, 125, 240, 0.4);
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.toggle-track[aria-checked="true"]::before {
  transform: translateX(22px);
}

/* Price display improvements */
.price-display {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.price-amount {
  font-size: clamp(1.85rem, 4vw, 2.2rem);
  font-weight: 800;
  color: #edf3ff;
  line-height: 1;
}

.price-currency {
  font-size: clamp(0.95rem, 1.5vw, 1.05rem);
  color: rgba(158, 176, 209, 0.85);
  font-weight: 600;
}

.price-cycle {
  font-size: clamp(0.92rem, 1.5vw, 1rem);
  color: rgba(158, 176, 209, 0.8);
  font-weight: 500;
}

/* Resource grid improvements */
.resource-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: clamp(10px, 1.5vw, 14px);
}

.resource-item {
  padding: clamp(13px, 2vw, 16px);
  border-radius: clamp(12px, 1.5vw, 16px);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.resource-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.12);
}

.resource-item strong {
  display: block;
  font-size: clamp(0.82rem, 1.3vw, 0.88rem);
  color: rgba(158, 176, 209, 0.85);
  margin-bottom: 4px;
  font-weight: 600;
}

.resource-item span {
  display: block;
  font-size: clamp(0.92rem, 1.5vw, 1rem);
  color: #edf3ff;
  font-weight: 600;
}

/* ─── RESPONSIVE BREAKPOINTS ────────────────────────────── */

/* Large tablets and small desktops (1024px and below) */
@media (max-width: 1024px) {
  .pricing-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 24px;
  }

  .pricing-card {
    padding: 26px;
  }

  .pricing-card.featured {
    transform: translateY(-8px) scale(1.01);
  }

  .pricing-card.featured:hover {
    transform: translateY(-12px) scale(1.015);
  }
}

/* Tablets (768px and below) */
@media (max-width: 768px) {
  .pricing-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
  }

  .segment-control {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    flex-wrap: nowrap;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(94, 163, 255, 0.3) rgba(255, 255, 255, 0.05);
    justify-content: flex-start;
  }

  .segment-control::-webkit-scrollbar {
    height: 6px;
  }

  .segment-control::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 3px;
  }

  .segment-control::-webkit-scrollbar-thumb {
    background: rgba(94, 163, 255, 0.3);
    border-radius: 3px;
  }

  .segment-chip {
    flex-shrink: 0;
    padding: 12px 18px;
  }

  .billing-switch {
    width: 100%;
    justify-content: center;
  }

  .pricing-grid {
    grid-template-columns: 1fr;
    gap: 22px;
  }

  .pricing-card {
    padding: 24px;
    gap: 18px;
  }

  .pricing-card.featured {
    transform: translateY(0) scale(1);
  }

  .pricing-card:hover,
  .pricing-card.featured:hover {
    transform: translateY(-6px);
  }

  .resource-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .hostiny-chat-widget {
    bottom: 16px;
    right: 16px;
    inset-inline-end: 16px;
  }

  .hostiny-chat-panel {
    bottom: 88px;
    right: 16px;
    inset-inline-end: 16px;
    width: min(360px, calc(100vw - 32px));
  }
}

/* Mobile (480px and below) */
@media (max-width: 480px) {
  .pricing-hero {
    padding-block: 24px;
  }

  .pricing-hero-card h1 {
    font-size: 1.75rem;
  }

  .pricing-hero-card .muted {
    font-size: 0.96rem;
  }

  .pricing-card {
    padding: 20px;
    gap: 16px;
    border-radius: 24px;
  }

  .pricing-card-head h2 {
    font-size: 1.4rem;
  }

  .segment-chip {
    padding: 11px 16px;
    font-size: 0.88rem;
  }

  .billing-switch-option {
    min-width: 90px;
    padding: 10px 16px;
    font-size: 0.87rem;
  }

  .price-amount {
    font-size: 1.75rem;
  }

  .resource-item {
    padding: 13px;
  }

  .card-cta .btn {
    min-height: 48px;
    font-size: 0.94rem;
  }

  .hostiny-chat-launcher {
    width: 54px;
    height: 54px;
    font-size: 1.4rem;
  }

  .hostiny-chat-panel {
    bottom: 82px;
    width: calc(100vw - 32px);
    max-height: calc(100vh - 120px);
  }
}

/* Very small screens (360px and below) */
@media (max-width: 360px) {
  .pricing-hero-card h1 {
    font-size: 1.5rem;
  }

  .pricing-card {
    padding: 18px;
  }

  .segment-chip {
    padding: 10px 14px;
    font-size: 0.85rem;
  }

  .billing-switch-option {
    min-width: 85px;
    padding: 9px 14px;
    font-size: 0.85rem;
  }

  .hostiny-chat-launcher {
    width: 52px;
    height: 52px;
  }
}

/* ─── ACCESSIBILITY IMPROVEMENTS ────────────────────────── */
:focus-visible {
  outline: 2px solid #5ea3ff;
  outline-offset: 3px;
  border-radius: 4px;
}

@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;
  }

  .hostiny-chat-launcher {
    animation: none !important;
  }
}

/* ─── HIGH DPI DISPLAYS ──────────────────────────────────── */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  body {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
}

/* ─── PRINT STYLES ───────────────────────────────────────── */
@media print {
  .hostiny-chat-widget,
  .site-banner,
  .back-to-top {
    display: none !important;
  }
}

/* ─── SEO GUIDE PAGES ────────────────────────────────────── */
.guides-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
}

.guide-card {
  display: block;
  padding: 1.25rem 1.35rem;
  border-radius: 16px;
  border: 1px solid rgba(94, 163, 255, 0.18);
  background: rgba(10, 21, 40, 0.72);
  color: inherit;
  text-decoration: none;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.guide-card:hover {
  transform: translateY(-2px);
  border-color: rgba(68, 215, 182, 0.45);
}

.guide-card h2 {
  font-size: 1.05rem;
  margin: 0 0 0.65rem;
}

.guide-card p {
  margin: 0 0 0.85rem;
  color: #c8d6f0;
  line-height: 1.7;
}

.guide-link {
  color: #44d7b6;
  font-weight: 600;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 1.5rem;
}

.feature-list {
  margin: 1rem 0 1.5rem;
  padding-right: 1.2rem;
  line-height: 1.9;
}

.plan-mini-list {
  display: grid;
  gap: 0.75rem;
}

.plan-mini-item {
  display: block;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  background: rgba(19, 39, 70, 0.75);
  color: inherit;
  text-decoration: none;
}

.plan-mini-item span {
  display: block;
  margin-top: 0.25rem;
  color: #9eb0d1;
  font-size: 0.92rem;
}

@media (max-width: 768px) {
  .content-grid {
    grid-template-columns: 1fr;
  }
}
