/* K-Sleep Care - True Responsive Web Design (RWD) */
/* Single Source for PC, Tablet, Mobile - Auto-optimized */

/* ============================================
   CSS CUSTOM PROPERTIES (CSS Variables)
   Automatically adjust based on viewport
   ============================================ */

:root {
  /* Fluid Typography - scales automatically */
  --font-size-xs: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  --font-size-sm: clamp(0.875rem, 0.8rem + 0.35vw, 1rem);
  --font-size-base: clamp(1rem, 0.9rem + 0.5vw, 1.125rem);
  --font-size-lg: clamp(1.125rem, 1rem + 0.625vw, 1.25rem);
  --font-size-xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
  --font-size-2xl: clamp(1.5rem, 1.3rem + 1vw, 2rem);
  --font-size-3xl: clamp(1.875rem, 1.5rem + 1.5vw, 2.5rem);
  --font-size-4xl: clamp(2.25rem, 1.8rem + 2vw, 3rem);
  
  /* Fluid Spacing - scales automatically */
  --space-xs: clamp(0.25rem, 0.2rem + 0.25vw, 0.5rem);
  --space-sm: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
  --space-md: clamp(0.75rem, 0.6rem + 0.75vw, 1rem);
  --space-lg: clamp(1rem, 0.8rem + 1vw, 1.5rem);
  --space-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
  --space-2xl: clamp(2rem, 1.5rem + 2vw, 3rem);
  --space-3xl: clamp(2.5rem, 2rem + 2.5vw, 4rem);
  
  /* Fluid Border Radius */
  --radius-sm: clamp(0.5rem, 0.4rem + 0.5vw, 0.75rem);
  --radius-md: clamp(0.75rem, 0.6rem + 0.75vw, 1rem);
  --radius-lg: clamp(1rem, 0.8rem + 1vw, 1.5rem);
  --radius-xl: clamp(1.5rem, 1.2rem + 1.5vw, 2rem);
  
  /* Container widths */
  --container-mobile: 100%;
  --container-tablet: 768px;
  --container-desktop: 1024px;
  --container-wide: 1280px;
  --container-max: 1440px;
  
  /* Touch target size (minimum 44px for accessibility) */
  --touch-target: clamp(44px, 10vw, 56px);
  
  /* Colors */
  --color-primary: #667eea;
  --color-primary-dark: #764ba2;
  --color-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  --color-text: #1f2937;
  --color-text-light: #6b7280;
  --color-bg-light: #f9fafb;
  --color-border: #e5e7eb;
}

/* ============================================
   UNIVERSAL BOX SIZING & RESET
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================
   BASE STYLES - FLUID & RESPONSIVE
   ============================================ */

html {
  /* Base font size for rem calculations */
  font-size: 100%;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-gradient);
  min-height: 100vh;
  overflow-x: hidden;
  font-size: var(--font-size-base);
}

/* ============================================
   NAVIGATION - GLASSMORPHISM DESIGN
   ============================================ */

nav {
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  position: sticky;
  top: 0;
  z-index: 1000;
}

nav .max-w-7xl {
  padding: clamp(0.75rem, 2vw, 1rem) var(--space-lg);
  max-width: var(--container-max);
  margin: 0 auto;
}

nav .text-2xl {
  font-size: clamp(1.125rem, 4vw, 1.375rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

nav .w-10 {
  width: clamp(1.75rem, 5vw, 2.25rem);
  height: clamp(1.75rem, 5vw, 2.25rem);
}

nav .text-3xl {
  font-size: clamp(1.5rem, 5vw, 2rem);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* Responsive navigation menu */
nav .hidden.md\\:flex {
  display: none;
}

@media (min-width: 768px) {
  nav .hidden.md\\:flex {
    display: flex;
    gap: var(--space-xl);
  }
}

/* ============================================
   RESPONSIVE CONTAINER SYSTEM
   Automatically adjusts width based on viewport
   ============================================ */

.module-container {
  width: 100%;
  min-height: calc(100vh - 80px);
  padding: var(--space-lg);
  margin: 0 auto;
  background: transparent;
  
  /* Fluid max-width based on viewport */
  max-width: min(var(--container-max), 100vw - var(--space-xl));
}

/* Container queries for nested responsive elements */
@container (min-width: 768px) {
  .module-container {
    padding: var(--space-xl);
  }
}

@container (min-width: 1024px) {
  .module-container {
    padding: var(--space-2xl) var(--space-xl);
  }
}

/* ============================================
   CARDS & PANELS - FLUID RESPONSIVE
   ============================================ */

.bg-white {
  background: white;
  border-radius: var(--radius-xl);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
  
  /* Responsive padding */
  padding: clamp(1rem, 3vw, 2.5rem);
}

.shadow-lg {
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2) !important;
}

/* Responsive grid for feature cards */
.space-y-6 {
  display: grid;
  gap: var(--space-lg);
}

@media (min-width: 768px) {
  .space-y-6 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .space-y-6 {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-xl);
  }
}

/* ============================================
   WELCOME SCREEN - FULLY RESPONSIVE
   ============================================ */

.welcome-header {
  text-align: center;
  margin-bottom: var(--space-xl);
  padding: var(--space-lg);
  background: linear-gradient(135deg, rgba(255,255,255,0.95) 0%, rgba(255,255,255,0.85) 100%);
  border-radius: var(--radius-xl);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.welcome-header h1 {
  font-size: var(--font-size-3xl);
  font-weight: 800;
  background: var(--color-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-md);
  line-height: 1.2;
}

.welcome-header p {
  font-size: var(--font-size-lg);
  color: var(--color-text-light);
  line-height: 1.6;
  max-width: 40em; /* Optimal reading width */
  margin: 0 auto;
}

.logo-container i {
  font-size: var(--font-size-4xl);
  background: var(--color-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: var(--space-lg);
  display: inline-block;
}

/* ============================================
   BUTTONS - FULLY RESPONSIVE & ACCESSIBLE
   ============================================ */

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: var(--space-lg) var(--space-xl);
  background: var(--color-gradient);
  color: white;
  font-weight: 600;
  font-size: var(--font-size-lg);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
  text-decoration: none;
  min-height: var(--touch-target);
  touch-action: manipulation;
  white-space: nowrap;
}

/* Responsive width: full on mobile, auto on larger screens */
@media (min-width: 640px) {
  .btn-primary {
    width: auto;
    min-width: 200px;
    padding: var(--space-lg) var(--space-2xl);
  }
}

.btn-primary:hover, .btn-primary:active {
  transform: translateY(-2px);
  box-shadow: 0 12px 30px rgba(102, 126, 234, 0.5);
}

.btn-primary:disabled {
  background: #9ca3af;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
  opacity: 0.6;
}

/* ============================================
   INTERACTIVE SURVEY - MOBILE CHAT
   ============================================ */

/* Progress Header */
.bg-white.shadow-sm {
  background: white;
  border-radius: 0 0 1.5rem 1.5rem;
  padding: 1rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.progress-bar {
  height: 6px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-bar > div {
  height: 100%;
  background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
  transition: width 0.5s ease;
  border-radius: 999px;
}

/* Chat Bubbles - Responsive */
#interactiveSurveyChat {
  padding: var(--space-lg);
  max-height: calc(100vh - 300px);
  overflow-y: auto;
  overflow-x: hidden;
  margin-bottom: clamp(180px, 35vh, 250px);
  scroll-padding-top: 100px;
}

.chat-bubble {
  animation: slideUp 0.4s ease-out;
  margin-bottom: var(--space-lg);
}

.chat-bubble > div {
  padding: var(--space-lg) var(--space-xl);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-base);
  line-height: 1.6;
  word-wrap: break-word;
  max-width: min(85%, 600px);
}

/* Responsive chat bubble width */
@media (min-width: 640px) {
  .chat-bubble > div {
    max-width: min(75%, 600px);
  }
}

@media (min-width: 1024px) {
  .chat-bubble > div {
    max-width: min(65%, 700px);
  }
}

/* Bot messages - left side */
.justify-start > div {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  color: var(--color-text);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* User messages - right side */
.justify-end > div {
  background: var(--color-gradient);
  color: white;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

/* Typing Indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  border-radius: 1.25rem;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.typing-indicator span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #667eea;
  animation: typing 1.4s infinite;
}

/* Fixed Bottom Input Area - Glassmorphism */
.fixed.bottom-0 {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-top: 1px solid rgba(255, 255, 255, 0.3);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.12);
  padding: clamp(0.875rem, 3vw, 1.25rem);
  max-height: 55vh;
  overflow-y: auto;
}

/* Option Buttons - Fully Responsive */
.option-button {
  width: 100%;
  padding: var(--space-lg) var(--space-xl);
  background: white;
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-base);
  text-align: left;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  align-items: center;
  gap: var(--space-md);
  min-height: var(--touch-target);
  touch-action: manipulation;
}

/* Responsive grid for options on larger screens */
@media (min-width: 768px) {
  #interactiveSurveyOptions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: var(--space-md);
  }
  
  .option-button {
    min-height: 80px;
  }
}

.option-button:hover, .option-button:active {
  border-color: var(--color-primary);
  background: linear-gradient(135deg, #eef2ff 0%, #e0e7ff 100%);
  transform: translateX(4px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.2);
}

.option-button.selected {
  background: var(--color-gradient);
  border-color: var(--color-primary);
  color: white;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.option-button i {
  font-size: var(--font-size-xl);
  min-width: 24px;
}

.option-button.selected i {
  color: white;
}

/* ============================================
   FORM ELEMENTS - FULLY RESPONSIVE
   ============================================ */

.form-input, input[type="text"], input[type="number"], input[type="email"], select, textarea {
  width: 100%;
  padding: var(--space-lg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  font-size: var(--font-size-base);
  transition: all 0.2s ease;
  background: white;
  min-height: var(--touch-target);
  touch-action: manipulation;
}

.form-input:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

/* Responsive form layouts */
@media (min-width: 640px) {
  .form-group {
    display: grid;
    gap: var(--space-lg);
  }
}

@media (min-width: 768px) {
  .form-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ============================================
   FEATURE CARDS - FULLY RESPONSIVE
   ============================================ */

.flex.items-start {
  margin-bottom: 0; /* Remove for grid layout */
  background: linear-gradient(135deg, #f9fafb 0%, #f3f4f6 100%);
  padding: var(--space-xl);
  border-radius: var(--radius-lg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.flex.items-start:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.w-12.h-12 {
  width: clamp(3rem, 8vw, 4rem);
  height: clamp(3rem, 8vw, 4rem);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Icon size responsive */
.w-12.h-12 i {
  font-size: clamp(1.25rem, 4vw, 1.5rem);
}

.bg-blue-100 {
  background: linear-gradient(135deg, #dbeafe 0%, #bfdbfe 100%);
}

.bg-green-100 {
  background: linear-gradient(135deg, #d1fae5 0%, #a7f3d0 100%);
}

.bg-purple-100 {
  background: linear-gradient(135deg, #ede9fe 0%, #ddd6fe 100%);
}

.bg-orange-100 {
  background: linear-gradient(135deg, #fed7aa 0%, #fdba74 100%);
}

/* ============================================
   ALERT BOXES - ENHANCED
   ============================================ */

.bg-blue-50 {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-left: 4px solid #667eea;
  border-radius: 1rem;
  padding: 1.25rem;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

/* ============================================
   FOOTER - FULLY RESPONSIVE
   ============================================ */

footer {
  background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
  color: white;
  padding: var(--space-2xl) var(--space-lg);
  margin-top: var(--space-3xl);
}

footer h3, footer h4 {
  font-size: var(--font-size-xl);
  margin-bottom: var(--space-lg);
  font-weight: 700;
}

footer p, footer li {
  font-size: var(--font-size-sm);
  line-height: 1.8;
}

/* Responsive footer grid */
footer .grid {
  display: grid;
  gap: var(--space-2xl);
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  footer .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  footer .grid {
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-3xl);
  }
}

/* ============================================
   SCROLLBAR - CUSTOM STYLING
   ============================================ */

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(15px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.8;
  }
  30% {
    transform: translateY(-8px);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.fade-in {
  animation: fadeIn 0.5s ease-out;
}

/* ============================================
   RESPONSIVE BREAKPOINTS - PROGRESSIVE ENHANCEMENT
   ============================================ */

/* Small Tablets (640px+) */
@media (min-width: 640px) {
  body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 60%, #f093fb 100%);
  }
}

/* Tablets (768px+) */
@media (min-width: 768px) {
  body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
  }
  
  .module-container {
    max-width: min(var(--container-tablet), calc(100vw - var(--space-2xl)));
  }
}

/* Desktop (1024px+) */
@media (min-width: 1024px) {
  .module-container {
    max-width: min(var(--container-desktop), calc(100vw - var(--space-3xl)));
  }
  
  #interactiveSurveyChat {
    padding: var(--space-xl);
  }
}

/* Wide Desktop (1280px+) */
@media (min-width: 1280px) {
  .module-container {
    max-width: min(var(--container-wide), calc(100vw - 4rem));
  }
}

/* Ultra-Wide (1440px+) */
@media (min-width: 1440px) {
  .module-container {
    max-width: var(--container-max);
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.hidden {
  display: none !important;
}

.text-center {
  text-align: center;
}

.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.space-y-6 > * + * { margin-top: 1.5rem; }

/* ============================================
   LOADING SPINNER
   ============================================ */

.spinner, #app-loader > div > div {
  border: 4px solid #f3f4f6;
  border-top: 4px solid #667eea;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */

@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .option-button:hover {
    transform: none;
  }
  
  .btn-primary:hover {
    transform: none;
  }
  
  /* Add active states instead */
  .option-button:active {
    transform: scale(0.98);
  }
  
  .btn-primary:active {
    transform: scale(0.98);
  }
}

/* ============================================
   PRINT STYLES
   ============================================ */

@media print {
  body {
    background: white;
  }
  
  nav, footer, .btn-primary, button {
    display: none;
  }
  
  .module-container {
    max-width: 100%;
    padding: 0;
  }
  
  .bg-white {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* ============================================
   REDUCED MOTION ACCESSIBILITY
   ============================================ */

@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
   ============================================ */

@media (prefers-contrast: high) {
  .option-button {
    border-width: 3px;
  }
  
  .btn-primary {
    border: 3px solid white;
  }
}

/* ============================================
   DARK MODE SUPPORT (Future Enhancement)
   ============================================ */

@media (prefers-color-scheme: dark) {
  /* Uncomment to enable dark mode
  :root {
    --color-text: #f9fafb;
    --color-bg-light: #1f2937;
  }
  
  body {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  }
  */
}
