/* ============================================
   PREMIUM RESPONSIVE DESIGN SYSTEM
   Mobile-First Approach with Glassmorphism
   ============================================ */

:root {
  --breakpoint-xs: 320px;
  --breakpoint-sm: 576px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 992px;
  --breakpoint-xl: 1200px;
  --breakpoint-xxl: 1400px;
}

/* ============================================
   BASE MOBILE STYLES (320px+)
   ============================================ */

html {
  font-size: 15px;
}

body,
html {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
}

.app-container {
  width: 100%;
  max-width: 100vw;
  overflow-x: hidden;
  min-width: 320px;
}

/* Logo - Hide on mobile for space */
.top-left-logo {
  display: none;
}

.logo-container {
  height: 38px;
}

/* Main Content */
.main-content {
  padding-top: 60px;
  width: 100%;
  max-width: 100vw;
}

.main-content.sidebar-open {
  margin-left: 0;
}

/* Chat Container */
.chat-container {
  width: 100%;
  padding: var(--space-sm);
  padding-bottom: 100px;
}

/* Messages */
.chat-stream {
  padding: var(--space-sm);
  height: calc(100vh - 180px);
}

.chat-stream::-webkit-scrollbar {
  width: 4px;
}

.message {
  margin-bottom: var(--space-md);
}

.message-content {
  max-width: 90%;
  padding: var(--space-sm) var(--space-md);
  font-size: 0.875rem;
}

.message-text {
  font-size: 0.875rem;
  line-height: 1.6;
}

/* Input Area */
.input-area {
  position: fixed;
  bottom: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - var(--space-lg));
  max-width: 100%;
  padding: 0;
}

.input-container {
  padding: var(--space-xs);
}

#input {
  font-size: 16px;
  /* Prevent iOS zoom */
  padding: var(--space-sm);
  min-height: 40px;
  max-height: 120px;
}

.input-buttons button {
  width: 32px;
  height: 32px;
  font-size: 0.875rem;
}

#send {
  width: 36px;
  height: 36px;
}

/* Sidebar */
.app-container .sidebar {
  width: 85%;
  max-width: 300px;
  height: 100vh;
  left: -100%;
  padding: var(--space-lg);
  box-shadow: var(--shadow-2xl);
}

.app-container .sidebar.show {
  left: 0;
  box-shadow: var(--shadow-2xl), 20px 0 40px rgba(0, 0, 0, 0.3);
}

.app-container .sidebar h2 {
  font-size: 1rem;
  margin-bottom: var(--space-md);
}

#saved-chats-list li {
  padding: var(--space-sm);
  font-size: 0.8125rem;
}

.app-container .sidebar-actions {
  gap: var(--space-sm);
}

.app-container .sidebar-actions button {
  padding: var(--space-sm);
  font-size: 0.8125rem;
}

/* Sidebar Toggle */
.toggle-sidebar-btn {
  width: 36px;
  height: 36px;
  top: 8px;
}

.toggle-sidebar-icon {
  width: 18px;
  height: 18px;
}

.toggle-sidebar-btn.is-open {
  left: calc(85vw - 18px);
}

/* Top Right Buttons */
.top-right-buttons {
  top: 8px;
  right: var(--space-sm);
  gap: var(--space-xs);
}

.icon-button {
  width: 36px !important;
  height: 36px !important;
  font-size: 0.875rem;
}

.icon-button i {
  font-size: 0.875rem;
}

.profile-icon {
  width: 36px !important;
  height: 36px !important;
}

/* Hide export button on mobile */
#export-chat-button {
  display: none;
}

/* Model Selector */
.model-selector {
  min-width: 100px;
  max-width: 120px;
}

.model-selector__toggle {
  padding: var(--space-xs) var(--space-sm);
  height: 36px;
  font-size: 0.75rem;
  gap: var(--space-xs);
}

.model-selector__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-selector__list-wrapper {
  right: 0;
  width: min(90vw, 240px);
}

.model-selector__list {
  min-width: 0;
}

.model-selector__option {
  padding: var(--space-sm);
}

/* Profile Dropdown */
.profile-dropdown {
  right: 0;
  min-width: 200px;
  max-width: calc(100vw - var(--space-xl));
}

.profile-dropdown a {
  padding: var(--space-sm) var(--space-md);
  font-size: 0.8125rem;
}

/* Attachments */
.attachments-preview {
  bottom: 120px;
  width: calc(100% - var(--space-lg));
  padding: var(--space-sm);
}

.attachments-track {
  gap: var(--space-sm);
  padding-bottom: var(--space-xs);
}

.attachments-track::-webkit-scrollbar {
  height: 4px;
}

.attachment-card {
  width: 80px;
  height: 80px;
  padding: var(--space-sm);
}

.attachment-card__icon {
  font-size: 1.25rem;
}

.attachment-card__name {
  font-size: 0.6875rem;
}

/* Modal */
.modal-content {
  width: 90%;
  margin: var(--space-lg) auto;
  max-height: 80vh;
  overflow-y: auto;
}

/* Typing Indicator */
.typing-indicator {
  padding: var(--space-sm) var(--space-md);
}

.typing-indicator span {
  width: 6px;
  height: 6px;
}

/* ============================================
   SMALL DEVICES (576px and up)
   ============================================ */

@media (min-width: 576px) {
  html {
    font-size: 15px;
  }

  .message-content {
    max-width: 85%;
    padding: var(--space-md);
    font-size: 0.9rem;
  }

  .input-area {
    width: calc(100% - var(--space-xl));
  }

  .input-container {
    padding: var(--space-sm);
  }

  #input {
    padding: var(--space-sm) var(--space-md);
  }

  .app-container .sidebar {
    width: 320px;
    max-width: 320px;
    left: -320px;
  }

  .toggle-sidebar-btn.is-open {
    left: 302px;
  }

  .top-right-buttons {
    gap: var(--space-sm);
  }

  .icon-button {
    width: 38px !important;
    height: 38px !important;
  }

  .profile-icon {
    width: 38px !important;
    height: 38px !important;
  }

  .model-selector {
    min-width: 130px;
    max-width: 150px;
  }

  .model-selector__toggle {
    padding: var(--space-sm) var(--space-md);
    height: 38px;
    font-size: 0.8125rem;
  }

  .attachments-preview {
    width: calc(100% - var(--space-2xl));
  }

  .attachment-card {
    width: 90px;
    height: 90px;
  }
}

/* ============================================
   MEDIUM DEVICES (768px and up)
   ============================================ */

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }

  /* Show logo on tablet and up */
  .top-left-logo {
    display: block;
    top: 12px;
    left: 60px;
  }

  .logo-container {
    height: 42px;
  }

  .main-content {
    padding-top: 70px;
  }

  .main-content.sidebar-open {
    margin-left: 280px;
  }

  .chat-container {
    padding: 0 var(--space-xl);
    max-width: 900px;
    margin: 0 auto;
  }

  .chat-stream {
    padding: var(--space-lg) 0;
  }

  .chat-stream::-webkit-scrollbar {
    width: 8px;
  }

  .message-content {
    max-width: 75%;
    padding: var(--space-md) var(--space-lg);
    font-size: 0.9375rem;
  }

  .message-text {
    font-size: 0.9375rem;
  }

  .input-area {
    position: sticky;
    bottom: 0;
    left: 0;
    transform: none;
    width: 100%;
    padding: var(--space-lg) 0;
  }

  .input-container {
    padding: var(--space-sm);
  }

  #input {
    max-height: 200px;
  }

  .input-buttons button {
    width: 36px;
    height: 36px;
  }

  #send {
    width: 36px;
    height: 36px;
  }

  .app-container .sidebar {
    width: 280px;
    max-width: 280px;
    left: -280px;
    padding: var(--space-xl);
  }

  .app-container .sidebar.show {
    left: 0;
  }

  .toggle-sidebar-btn {
    width: 40px;
    height: 40px;
    top: 10px;
  }

  .toggle-sidebar-icon {
    width: 20px;
    height: 20px;
  }

  .toggle-sidebar-btn.is-open {
    left: 280px;
  }

  .top-right-buttons {
    top: 12px;
    right: var(--space-lg);
    gap: var(--space-sm);
  }

  /* Show export button on tablet and up */
  #export-chat-button {
    display: flex;
  }

  .icon-button {
    width: 40px !important;
    height: 40px !important;
    font-size: 1rem;
  }

  .icon-button i {
    font-size: 1rem;
  }

  .profile-icon {
    width: 40px !important;
    height: 40px !important;
  }

  .model-selector {
    min-width: 150px;
    max-width: none;
  }

  .model-selector__toggle {
    padding: var(--space-sm) var(--space-md);
    height: 40px;
    font-size: 0.875rem;
    gap: var(--space-sm);
  }

  .model-selector__list {
    min-width: 260px;
  }

  .model-selector__option {
    padding: var(--space-md);
  }

  .profile-dropdown {
    min-width: 220px;
  }

  .profile-dropdown a {
    padding: var(--space-md);
    font-size: 0.875rem;
  }

  .attachments-preview {
    bottom: 140px;
    width: calc(100% - 40px);
    max-width: 900px;
    padding: var(--space-md);
  }

  .attachments-track {
    gap: var(--space-md);
  }

  .attachment-card {
    width: 100px;
    height: 100px;
    padding: var(--space-md);
  }

  .attachment-card__icon {
    font-size: 1.5rem;
  }

  .attachment-card__name {
    font-size: 0.75rem;
  }

  .modal-content {
    width: 80%;
    max-width: 600px;
  }
}

/* ============================================
   LARGE DEVICES (992px and up)
   ============================================ */

@media (min-width: 992px) {
  .chat-container {
    max-width: 1000px;
  }

  .message-content {
    max-width: 70%;
  }

  .app-container .sidebar h2 {
    font-size: 1.125rem;
  }

  #saved-chats-list li {
    font-size: 0.875rem;
  }

  .app-container .sidebar-actions button {
    font-size: 0.875rem;
  }
}

/* ============================================
   EXTRA LARGE DEVICES (1200px and up)
   ============================================ */

@media (min-width: 1200px) {
  .chat-container {
    max-width: 1100px;
  }

  .top-left-logo {
    left: 70px;
  }

  .logo-container {
    height: 44px;
  }

  .top-right-buttons {
    right: var(--space-xl);
    gap: var(--space-md);
  }

  .icon-button {
    width: 42px !important;
    height: 42px !important;
  }

  .profile-icon {
    width: 44px !important;
    height: 44px !important;
  }

  .model-selector__toggle {
    padding: var(--space-sm) var(--space-lg);
    font-size: 0.9375rem;
  }
}

/* ============================================
   XXL DEVICES (1400px and up)
   ============================================ */

@media (min-width: 1400px) {
  .chat-container {
    max-width: 1200px;
  }
}

/* ============================================
   SPECIAL CASES
   ============================================ */

/* Short Screens */
@media (max-height: 600px) {
  .main-content {
    padding-top: 50px;
  }

  .chat-container {
    padding-bottom: 70px;
  }

  .chat-stream {
    height: calc(100vh - 150px);
  }

  .input-area {
    padding: var(--space-sm) 0;
  }

  #input {
    max-height: 80px;
  }

  .message {
    margin-bottom: var(--space-sm);
  }

  .message-content {
    padding: var(--space-sm) var(--space-md);
  }

  .app-container .sidebar {
    padding: var(--space-lg);
  }

  .app-container .sidebar h2 {
    font-size: 1rem;
    margin-bottom: var(--space-sm);
  }

  #saved-chats-list li {
    padding: var(--space-xs) var(--space-sm);
    margin-bottom: var(--space-xs);
    font-size: 0.8125rem;
  }

  .app-container .sidebar-actions {
    padding-top: var(--space-md);
    margin-top: var(--space-md);
  }

  .app-container .sidebar-actions button {
    padding: var(--space-sm);
    font-size: 0.8125rem;
  }
}

/* Landscape Orientation on Mobile */
@media (orientation: landscape) and (max-height: 500px) {
  .main-content {
    padding-top: 50px;
  }

  .chat-container {
    height: calc(100vh - 100px);
    padding-bottom: 60px;
  }

  .chat-stream {
    height: calc(100vh - 140px);
  }

  .input-area {
    position: fixed;
    bottom: var(--space-sm);
    padding: 0;
  }

  .input-container {
    padding: var(--space-xs);
  }

  #input {
    min-height: 32px;
    max-height: 80px;
    padding: var(--space-xs) var(--space-sm);
  }

  .input-buttons button {
    width: 28px;
    height: 28px;
  }

  #send {
    width: 32px;
    height: 32px;
  }

  .attachments-preview {
    bottom: 90px;
    padding: var(--space-sm);
  }

  .attachment-card {
    width: 70px;
    height: 70px;
    padding: var(--space-xs);
  }

  .app-container .sidebar {
    height: 100vh;
    padding: var(--space-md);
  }

  .top-left-logo {
    display: none;
  }
}

/* Touch Device Optimizations */
@media (hover: none) and (pointer: coarse) {

  /* Larger touch targets */
  button,
  a,
  input,
  textarea,
  select {
    min-height: 44px;
  }

  .icon-button {
    min-width: 44px !important;
    min-height: 44px !important;
  }

  /* Remove hover effects on touch devices */
  .icon-button:hover,
  .message-content:hover,
  #saved-chats-list li:hover,
  .model-selector__option:hover,
  .profile-dropdown a:hover {
    transform: none;
  }

  /* Enhance tap feedback */
  button:active,
  a:active {
    opacity: 0.7;
    transition: opacity 0.1s;
  }

  /* Improve scrolling on touch */
  .chat-stream,
  #saved-chats-list,
  .attachments-track {
    -webkit-overflow-scrolling: touch;
  }
}

/* iOS Safari Fixes */
@supports (-webkit-touch-callout: none) {
  .app-container {
    min-height: -webkit-fill-available;
  }

  .chat-container {
    height: -webkit-fill-available;
  }

  .chat-stream {
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
  }

  /* Fix for iOS keyboard pushing content */
  .input-area {
    position: fixed;
    bottom: env(safe-area-inset-bottom);
  }

  .attachments-preview {
    bottom: calc(100px + env(safe-area-inset-bottom));
  }
}

/* Reduced Motion Preferences */
@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  .typing-indicator span {
    animation: none !important;
  }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
  :root {
    --border-default: rgba(100, 116, 139, 0.4);
    --border-strong: rgba(100, 116, 139, 0.6);
  }

  .dark-theme {
    --border-default: rgba(148, 163, 184, 0.3);
    --border-strong: rgba(148, 163, 184, 0.5);
  }
}

/* Print Styles */
@media print {

  .app-container .sidebar,
  .toggle-sidebar-btn,
  .top-right-buttons,
  .input-area,
  .attachments-preview,
  .message-actions {
    display: none !important;
  }

  body {
    background: white;
    color: black;
  }

  .main-content {
    margin: 0;
    padding: 0;
  }

  .message-content {
    max-width: 100%;
    break-inside: avoid;
  }

  .chat-stream {
    overflow: visible;
    height: auto;
  }
}

/* ============================================
   VISIBILITY UTILITIES
   ============================================ */

.hide-xs {
  display: none !important;
}

@media (min-width: 576px) {
  .hide-xs {
    display: initial !important;
  }

  .hide-sm {
    display: none !important;
  }

  .show-sm {
    display: initial !important;
  }
}

@media (min-width: 768px) {
  .hide-sm {
    display: initial !important;
  }

  .hide-md {
    display: none !important;
  }

  .show-md {
    display: initial !important;
  }
}

@media (min-width: 992px) {
  .hide-md {
    display: initial !important;
  }

  .hide-lg {
    display: none !important;
  }

  .show-lg {
    display: initial !important;
  }
}

@media (min-width: 1200px) {
  .hide-lg {
    display: initial !important;
  }

  .hide-xl {
    display: none !important;
  }

  .show-xl {
    display: initial !important;
  }
}
