/**
 * Zone2Cal UX Enhancements
 * Mobile responsiveness, touch targets, and engagement features
 */

/* ========================================
   MOBILE TOUCH TARGETS & ACCESSIBILITY
   ======================================== */

/* Ensure all interactive elements meet 48x48px minimum */
button,
.btn,
.btn-primary,
.btn-secondary,
.header-nav__item,
select,
input[type="radio"],
input[type="checkbox"],
.time-preset-btn,
.help-toggle,
a.feature-card,
a.resource-card {
  min-height: 48px;
  min-width: 48px;
  cursor: pointer;
}

/* Improve radio/checkbox visibility and touch area */
input[type="radio"],
input[type="checkbox"] {
  width: 24px;
  height: 24px;
  margin-right: 12px;
  cursor: pointer;
  accent-color: #0ea5e9;
}

label:has(input[type="radio"]),
label:has(input[type="checkbox"]) {
  padding: 12px 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

label:has(input[type="radio"]:checked),
label:has(input[type="checkbox"]:checked) {
  background-color: rgba(14, 165, 233, 0.1);
  border-color: #0ea5e9 !important;
}

/* ========================================
   CALCULATOR INPUT ENHANCEMENTS
   ======================================== */

/* Larger, more accessible input fields */
input[type="number"],
input[type="text"],
select {
  font-size: 16px; /* Prevents iOS zoom on focus */
  padding: 14px 16px;
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  transition: all 0.2s ease;
  -webkit-appearance: none;
  appearance: none;
}

input[type="number"]:focus,
input[type="text"]:focus,
select:focus {
  outline: none;
  border-color: #0ea5e9;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}

/* Number input spinners - better mobile experience */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
  height: 32px;
}

/* ========================================
   RESULT DISPLAY & SHARING
   ======================================== */

.result-highlight {
  position: relative;
  animation: highlightPulse 0.5s ease-out;
}

@keyframes highlightPulse {
  0% { transform: scale(1); }
  50% { transform: scale(1.05); }
  100% { transform: scale(1); }
}

.share-result-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
  color: white;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3);
}

.share-result-btn:hover,
.share-result-btn:focus {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(14, 165, 233, 0.4);
  outline: none;
}

.share-result-btn:active {
  transform: translateY(0);
}

/* ========================================
   PROGRESSIVE DISCLOSURE
   ======================================== */

.advanced-options {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: all 0.3s ease;
}

.advanced-options.expanded {
  max-height: 800px;
  opacity: 1;
  margin-top: 16px;
}

.toggle-advanced {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #0369a1;
  font-weight: 600;
  font-size: 14px;
  background: none;
  border: 1px dashed #94c5fd;
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.toggle-advanced:hover {
  background-color: rgba(14, 165, 233, 0.05);
  border-color: #0ea5e9;
}

.toggle-advanced::after {
  content: '▼';
  font-size: 10px;
  transition: transform 0.3s ease;
}

.toggle-advanced.active::after {
  transform: rotate(180deg);
}

/* ========================================
   STICKY CTA BAR (MOBILE)
   ======================================== */

.sticky-cta-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(to top, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.95));
  backdrop-filter: blur(10px);
  border-top: 1px solid #e2e8f0;
  padding: 12px 16px;
  box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
  z-index: 50;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.sticky-cta-bar.visible {
  transform: translateY(0);
}

.sticky-cta-bar .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 16px;
  font-size: 16px;
}

@media (min-width: 768px) {
  .sticky-cta-bar {
    display: none;
  }
}

/* ========================================
   CALCULATOR RESULT CARDS
   ======================================== */

.result-card {
  background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
  border: 2px solid #bae6fd;
  border-radius: 16px;
  padding: 20px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(2, 132, 199, 0.15);
  transition: all 0.3s ease;
}

.result-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 32px rgba(2, 132, 199, 0.2);
}

.result-card-value {
  font-size: 2.5rem;
  font-weight: 800;
  color: #0369a1;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', 'Roboto Mono', Consolas, 'Courier New', monospace;
  letter-spacing: -0.02em;
  line-height: 1.2;
  margin: 8px 0;
}

.result-card-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.result-card-description {
  font-size: 0.8125rem;
  color: #475569;
  margin-top: 8px;
}

@media (max-width: 640px) {
  .result-card-value {
    font-size: 2rem;
  }
}

/* ========================================
   TOOLTIP & HELP SYSTEM
   ======================================== */

.tooltip-trigger {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: #e0f2fe;
  color: #0369a1;
  font-size: 12px;
  font-weight: 700;
  cursor: help;
  margin-left: 6px;
}

.tooltip-content {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background-color: #1e293b;
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.4;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 100;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.tooltip-content::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: #1e293b;
}

.tooltip-trigger:hover .tooltip-content,
.tooltip-trigger:focus .tooltip-content {
  opacity: 1;
  transform: translateX(-50%) translateY(-12px);
}

/* ========================================
   LOADING STATES & SKELETON
   ======================================== */

.skeleton {
  background: linear-gradient(90deg, #f1f5f9 25%, #e2e8f0 50%, #f1f5f9 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.calculating {
  opacity: 0.6;
  pointer-events: none;
  position: relative;
}

.calculating::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: repeating-linear-gradient(
    45deg,
    transparent,
    transparent 10px,
    rgba(14, 165, 233, 0.05) 10px,
    rgba(14, 165, 233, 0.05) 20px
  );
  animation: movingStripes 1s linear infinite;
  pointer-events: none;
}

@keyframes movingStripes {
  0% { background-position: 0 0; }
  100% { background-position: 28px 0; }
}

/* ========================================
   PRINT OPTIMIZATION
   ======================================== */

@media print {
  .ad-container,
  .sticky-cta-bar,
  .header-nav,
  footer,
  .btn-secondary,
  .share-result-btn {
    display: none !important;
  }

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

  .result-card {
    border: 2px solid #000;
    box-shadow: none;
  }

  body {
    background: white;
  }
}

/* ========================================
   AD CONTAINER ENHANCEMENTS
   ======================================== */

.ad-container {
  position: relative;
  transition: min-height 0.3s ease, background-color 0.3s ease;
}

.ad-container.ad-loaded {
  background-color: transparent;
}

.ad-container.ad-blocked,
.ad-container.ad-empty {
  display: none;
}

/* Smooth loading state */
.ad-container::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border: 3px solid #e2e8f0;
  border-top-color: #0ea5e9;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.ad-container[data-ad-loaded="false"]::before {
  opacity: 1;
}

.ad-container.ad-loaded::before {
  opacity: 0;
}

/* ========================================
   COMPARISON MODE
   ======================================== */

.comparison-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background-color: #f8fafc;
  border: 2px dashed #cbd5e1;
  border-radius: 10px;
  color: #475569;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.comparison-toggle:hover {
  background-color: #f1f5f9;
  border-color: #94a3b8;
}

.comparison-toggle.active {
  background-color: #e0f2fe;
  border-color: #0ea5e9;
  border-style: solid;
  color: #0369a1;
}

.comparison-panel {
  display: none;
  margin-top: 24px;
  padding: 24px;
  background: linear-gradient(135deg, #fefce8 0%, #fef3c7 100%);
  border: 2px solid #fde68a;
  border-radius: 16px;
}

.comparison-panel.active {
  display: block;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ========================================
   MOBILE-SPECIFIC OPTIMIZATIONS
   ======================================== */

@media (max-width: 640px) {
  /* Reduce calculator complexity on small screens */
  .mobile-stack > * + * {
    margin-top: 16px;
  }

  /* Horizontal scroll for tables */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    scroll-behavior: smooth;
  }

  /* Larger tap targets for calculator buttons */
  .time-preset-btn {
    padding: 12px 18px;
    font-size: 15px;
  }

  /* Improve spacing between form elements */
  label + label {
    margin-top: 16px;
  }

  /* Sticky header compression */
  .site-header__inner {
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .site-brand {
    font-size: 1.1rem;
  }

  /* Hero section optimization */
  .hero-wrapper {
    padding: 20px 16px;
  }

  .hero-title {
    font-size: 1.75rem;
    line-height: 1.2;
  }

  /* Result cards stack vertically */
  .grid.md\\:grid-cols-2,
  .grid.md\\:grid-cols-3 {
    gap: 16px;
  }
}

/* ========================================
   DARK MODE COMPATIBILITY
   ======================================== */

:root.dark .result-card {
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border-color: #475569;
}

:root.dark .result-card-value {
  color: #38bdf8;
}

:root.dark .result-card-label,
:root.dark .result-card-description {
  color: #cbd5e1;
}

:root.dark .share-result-btn {
  background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
}

:root.dark .tooltip-content {
  background-color: #0f172a;
}

:root.dark .sticky-cta-bar {
  background: linear-gradient(to top, rgba(15, 23, 42, 0.98), rgba(15, 23, 42, 0.95));
  border-top-color: #334155;
}

:root.dark .ad-container {
  background-color: #1e293b;
}

/* ========================================
   ACCESSIBILITY ENHANCEMENTS
   ======================================== */

/* Focus visible for keyboard navigation */
*:focus-visible {
  outline: 2px solid #0ea5e9;
  outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .btn-primary {
    border: 2px solid currentColor;
  }

  .result-card {
    border-width: 3px;
  }
}
