/* Responsive Design System for HANQ Chat App
   ==========================================
   모바일 퍼스트 반응형 디자인 시스템
*/

/* ===================================
   Mobile First Base Styles (< 640px)
   =================================== */

/* Base Typography Scaling */
@media (max-width: 639px) {
  :root {
    /* Adjusted font sizes for mobile */
    --font-size-xs: 0.75rem;    /* 12px */
    --font-size-sm: 0.813rem;   /* 13px */
    --font-size-base: 0.875rem; /* 14px */
    --font-size-lg: 1rem;        /* 16px */
    --font-size-xl: 1.125rem;   /* 18px */
    --font-size-2xl: 1.25rem;   /* 20px */
    --font-size-3xl: 1.5rem;    /* 24px */
    
    /* Adjusted spacing for mobile */
    --spacing-xs: 0.25rem;   /* 4px */
    --spacing-sm: 0.375rem;  /* 6px */
    --spacing-md: 0.75rem;   /* 12px */
    --spacing-lg: 1rem;      /* 16px */
    --spacing-xl: 1.5rem;    /* 24px */
    --spacing-2xl: 2rem;     /* 32px */
  }
  
  /* Container adjustments */
  .container {
    padding-left: var(--spacing-md);
    padding-right: var(--spacing-md);
  }
  
  /* Navigation Mobile */
  .nav-gradient {
    padding: var(--spacing-sm) var(--spacing-md);
  }
  
  .nav-gradient .brand-text {
    font-size: var(--font-size-lg);
  }
  
  .nav-gradient .logout-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-sm);
  }
  
  /* Hide text on mobile, show only icons */
  .nav-gradient .logout-btn span {
    display: none;
  }
  
  .nav-gradient .logout-btn i {
    margin: 0;
  }
  
  /* Main content area */
  main {
    padding: var(--spacing-md);
  }
  
  /* Chat Room List Mobile */
  .chatroom-premium-bg {
    padding: var(--spacing-md);
    border-radius: var(--radius-lg);
  }
  
  .premium-card {
    padding: var(--spacing-md);
  }
  
  /* Chat Messages Mobile */
  .chat-container {
    height: calc(100vh - 120px);
  }
  
  .chat-message {
    max-width: 85%;
    font-size: var(--font-size-sm);
  }
  
  .chat-sidebar {
    position: fixed;
    left: -100%;
    top: 0;
    width: 80%;
    height: 100%;
    z-index: var(--z-index-modal);
    transition: left var(--transition-base);
  }
  
  .chat-sidebar.open {
    left: 0;
  }
  
  /* Mobile Menu Overlay */
  .mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: var(--z-index-modal-backdrop);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-base);
  }
  
  .mobile-overlay.active {
    opacity: 1;
    visibility: visible;
  }
  
  /* Form Elements Mobile */
  .input-enhanced {
    padding: var(--spacing-md);
    font-size: var(--font-size-base);
  }
  
  .btn-primary {
    padding: var(--spacing-md);
    font-size: var(--font-size-base);
  }
  
  /* Modal Mobile */
  .modal {
    width: calc(100% - var(--spacing-xl));
    margin: var(--spacing-md);
  }
  
  /* Cards Grid Mobile */
  .grid {
    grid-template-columns: 1fr;
    gap: var(--spacing-md);
  }
  
  /* Touch Target Optimization */
  button, 
  a, 
  input, 
  select, 
  textarea {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Floating Action Button */
  .fab {
    position: fixed;
    bottom: var(--spacing-lg);
    right: var(--spacing-lg);
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    background: var(--gradient-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    z-index: var(--z-index-fixed);
  }
}

/* ===================================
   Small Tablets (640px - 767px)
   =================================== */
@media (min-width: 640px) and (max-width: 767px) {
  :root {
    --font-size-base: 0.938rem; /* 15px */
  }
  
  .container {
    max-width: 640px;
    padding-left: var(--spacing-lg);
    padding-right: var(--spacing-lg);
  }
  
  /* Grid adjustments */
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  /* Chat messages */
  .chat-message {
    max-width: 75%;
  }
  
  /* Sidebar partial view */
  .chat-sidebar {
    width: 280px;
    position: relative;
    left: 0;
  }
}

/* ===================================
   Tablets (768px - 1023px)
   =================================== */
@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --font-size-base: 1rem; /* 16px */
  }
  
  .container {
    max-width: 768px;
  }
  
  /* Grid adjustments */
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .grid.lg\:grid-cols-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  /* Navigation adjustments */
  .nav-gradient .logout-btn span {
    display: inline;
  }
  
  /* Chat layout */
  .chat-container {
    display: grid;
    grid-template-columns: 300px 1fr;
  }
}

/* ===================================
   Desktop (1024px - 1279px)
   =================================== */
@media (min-width: 1024px) and (max-width: 1279px) {
  .container {
    max-width: 1024px;
  }
  
  /* Grid adjustments */
  .grid {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .grid.xl\:grid-cols-4 {
    grid-template-columns: repeat(3, 1fr);
  }
}

/* ===================================
   Large Desktop (1280px+)
   =================================== */
@media (min-width: 1280px) {
  .container {
    max-width: 1280px;
  }
  
  /* Grid adjustments */
  .grid.xl\:grid-cols-4 {
    grid-template-columns: repeat(4, 1fr);
  }
  
  /* Chat messages */
  .chat-message {
    max-width: 60%;
  }
  
  /* Sidebar expanded */
  .chat-sidebar {
    width: 320px;
  }
}

/* ===================================
   Extra Large Desktop (1536px+)
   =================================== */
@media (min-width: 1536px) {
  .container {
    max-width: 1536px;
  }
  
  /* Grid adjustments */
  .grid.2xl\:grid-cols-5 {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ===================================
   Landscape Mobile Specific
   =================================== */
@media (max-height: 500px) and (orientation: landscape) {
  /* Reduce vertical spacing */
  :root {
    --spacing-md: 0.5rem;
    --spacing-lg: 0.75rem;
    --spacing-xl: 1rem;
  }
  
  /* Adjust navigation height */
  .nav-gradient {
    height: 48px;
  }
  
  /* Adjust chat container */
  .chat-container {
    height: calc(100vh - 48px);
  }
  
  /* Hide less important elements */
  .chat-timestamp {
    display: none;
  }
}

/* ===================================
   Touch Device Optimizations
   =================================== */
@media (hover: none) and (pointer: coarse) {
  /* Remove hover effects on touch devices */
  .premium-card:hover {
    transform: none;
  }
  
  .btn-primary:hover::before {
    display: none;
  }
  
  /* Increase tap targets */
  button, a {
    padding: var(--spacing-md);
  }
  
  /* Add active states for better feedback */
  button:active,
  a:active {
    opacity: 0.8;
    transform: scale(0.98);
  }
  
  /* Disable text selection on interactive elements */
  button, a {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
}

/* ===================================
   Print Styles
   =================================== */
@media print {
  /* Hide navigation and controls */
  .nav-gradient,
  .logout-btn,
  .fab,
  .mobile-overlay,
  button[type="submit"] {
    display: none !important;
  }
  
  /* Optimize for printing */
  body {
    font-size: 12pt;
    line-height: 1.5;
    color: black;
    background: white;
  }
  
  /* Remove shadows and backgrounds */
  * {
    box-shadow: none !important;
    text-shadow: none !important;
    background: transparent !important;
  }
  
  /* Ensure text is black */
  h1, h2, h3, h4, h5, h6, p, span, div {
    color: black !important;
  }
}

/* ===================================
   High DPI Display Optimizations
   =================================== */
@media (-webkit-min-device-pixel-ratio: 2), 
       (min-resolution: 192dpi) {
  /* Use higher resolution images */
  .logo {
    background-image: url('/static/img/logo@2x.jpg');
    background-size: contain;
  }
  
  /* Thinner borders for crisp display */
  .premium-card {
    border-width: 0.5px;
  }
}

/* ===================================
   Foldable Device Support
   =================================== */
@media (min-width: 320px) and (max-width: 427px) {
  /* Galaxy Fold closed */
  .container {
    padding: var(--spacing-sm);
  }
  
  .chat-message {
    max-width: 90%;
  }
}

@media (min-width: 653px) and (max-width: 767px) {
  /* Galaxy Fold open */
  .grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ===================================
   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;
  }
}

/* ===================================
   Accessibility - High Contrast
   =================================== */
@media (prefers-contrast: high) {
  /* Increase contrast for better visibility */
  .premium-card {
    border: 2px solid currentColor;
  }
  
  .btn-primary {
    border: 2px solid currentColor;
  }
  
  .input-enhanced {
    border-width: 2px;
  }
  
  /* Ensure sufficient color contrast */
  body {
    background: white;
    color: black;
  }
}

/* ===================================
   Dark Mode Support
   =================================== */
@media (prefers-color-scheme: dark) {
  body {
    background: var(--color-gray-900);
    color: var(--color-gray-100);
  }
  
  .premium-card {
    background: var(--color-gray-800);
    border-color: var(--color-gray-700);
  }
  
  .input-enhanced {
    background: var(--color-gray-800);
    color: var(--color-gray-100);
    border-color: var(--color-gray-700);
  }
  
  .btn-primary {
    background: var(--gradient-dark);
  }
}