/* =========================================================
   MODERN DASHBOARD CSS (SETSFREEE.AI) - MOBILE FIXES
========================================================= */

/* 1. THEME VARIABLES */
:root {
  /* Core Colors */
  --bg-body: #0f172a;       
  --bg-sidebar: #1e293b;    
  --bg-surface: #1e293b;    
  --bg-input: #334155;
  
  /* Typography */
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  
  /* Borders & Accents */
  --border-color: rgba(255, 255, 255, 0.1);
  --accent-primary: #3b82f6; 
  --accent-hover: #2563eb;
  --accent-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  
  /* Status Colors */
  --success: #10b981;
  
  /* Spacing & Layout */
  --sidebar-width: 280px;
  --header-height: 60px;
  --radius-md: 12px;
  --radius-lg: 16px;
}

[data-theme="light"] {
  --bg-body: #f1f5f9;
  --bg-sidebar: #ffffff;
  --bg-surface: #ffffff;
  --bg-input: #e2e8f0;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: rgba(0, 0, 0, 0.1);
}

/* 2. RESET & BASE STYLES */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  outline: none;
  -webkit-tap-highlight-color: transparent; /* Removes blue highlight on mobile tap */
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  /* MOBILE FIX: Use dvh (dynamic viewport height) to handle mobile browser bars */
  height: 100dvh; 
  width: 100vw;
  overflow: hidden;
  font-size: 15px;
  line-height: 1.5;
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }
button { border: none; background: none; cursor: pointer; color: inherit; }

/* Scrollbar Styling */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(156, 163, 175, 0.3); border-radius: 10px; }

/* 3. MAIN APP LAYOUT */
.app-container {
  display: flex;
  height: 100%;
  width: 100%;
  position: relative;
  overflow: hidden; /* Prevents body scroll, ensures inner elements scroll */
}

/* 4. SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border-color);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 100;
}

.sidebar-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  border-bottom: 1px solid var(--border-color);
}

.brand-logo {
  font-weight: 700;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-main);
}

.brand-logo i { color: var(--accent-primary); }

.new-chat-btn {
  margin: 20px;
  padding: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.new-chat-btn:active { transform: scale(0.98); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0 10px; }

.nav-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  margin: 20px 10px 10px;
  letter-spacing: 0.5px;
}

/* Sidebar Links - Ensure they are fully clickable */
.history-list li { margin-bottom: 4px; }

.history-list a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px; /* Increased padding for better touch target */
  border-radius: 8px;
  color: var(--text-main);
  font-size: 0.9rem;
  transition: background 0.2s;
  width: 100%;
}

.history-list a:active { background: var(--bg-input); }
.history-list a i { width: 20px; text-align: center; color: var(--text-muted); }

.sidebar-footer { padding: 20px; border-top: 1px solid var(--border-color); }
.user-profile { display: flex; align-items: center; gap: 12px; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border-color); }
.user-info { flex: 1; display: flex; flex-direction: column; }
.user-name { font-size: 0.9rem; font-weight: 600; }
.user-plan { font-size: 0.75rem; color: var(--text-muted); }

/* 5. MAIN CHAT INTERFACE */
.chat-interface {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--bg-body);
  width: 100%; /* Prevent overflow on mobile */
}

/* 5a. TOP HEADER */
.top-header {
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px; /* Slightly less padding on mobile */
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-body); /* Solid background for better readability */
  border-bottom: 1px solid var(--border-color);
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
}

.header-right { display: flex; gap: 8px; align-items: center; }

/* Version Switcher */
.version-switcher {
  display: flex;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 3px;
}
.version-option {
  padding: 4px 10px; /* Smaller padding for mobile */
  border-radius: 16px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
}
.version-option.active { background: var(--accent-primary); color: white; }

.icon-btn {
  width: 40px; /* Larger touch target */
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

/* Share Dropdown */
.share-dropdown {
  position: absolute;
  top: 55px;
  right: 10px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 8px;
  width: 200px;
  display: none;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  z-index: 101;
}
.share-dropdown.active { display: flex; }
.share-item { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 8px; color: var(--text-main); font-size: 0.9rem; cursor: pointer; }
.share-item:active { background: var(--bg-input); }

.mobile-menu-toggle { display: none; font-size: 1.2rem; margin-right: 10px; color: var(--text-main); }

/* 5b. CHAT SCROLL AREA */
.chat-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
}

/* WELCOME SCREEN */
.welcome-container { max-width: 800px; width: 100%; margin-top: 5vh; text-align: center; }
.welcome-icon { font-size: 2.5rem; margin-bottom: 20px; background: var(--accent-gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.welcome-container h2 { font-size: 1.5rem; margin-bottom: 10px; }
.welcome-container p { color: var(--text-muted); margin-bottom: 30px; font-size: 0.9rem; }

.suggestion-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; text-align: left; }
.suggestion-card { background: var(--bg-surface); border: 1px solid var(--border-color); padding: 15px; border-radius: var(--radius-md); cursor: pointer; }
.suggestion-card:active { background: var(--bg-input); }
.card-icon { width: 30px; height: 30px; background: rgba(59, 130, 246, 0.1); color: var(--accent-primary); border-radius: 8px; display: flex; align-items: center; justify-content: center; margin-bottom: 10px; }
.suggestion-card h3 { font-size: 0.9rem; margin-bottom: 4px; }
.suggestion-card p { font-size: 0.75rem; color: var(--text-muted); margin: 0; }

/* 5c. INPUT AREA */
.input-container {
  padding: 15px;
  background: var(--bg-body);
  /* MOBILE FIX: Safe area inset for iPhone Home Bar */
  padding-bottom: max(15px, env(safe-area-inset-bottom)); 
  border-top: 1px solid var(--border-color);
}

.input-box-wrapper {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: 24px;
  padding: 6px 6px 6px 12px;
  display: flex;
  align-items: flex-end;
}

#user-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-main);
  font-family: inherit;
  font-size: 16px; /* Prevents iOS zoom */
  resize: none;
  max-height: 120px;
  padding: 10px 8px;
  line-height: 1.4;
}

.attach-btn, .voice-btn { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-muted); margin-bottom: 2px; }
.input-actions { display: flex; align-items: center; gap: 5px; margin-bottom: 2px; }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent-primary);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}

.disclaimer-text { text-align: center; font-size: 0.7rem; color: var(--text-muted); margin-top: 8px; opacity: 0.7; }

/* 6. MESSAGE STYLES */
.message-row {
  width: 100%;
  max-width: 100%; /* Full width on mobile */
  padding: 15px;
  display: flex;
  gap: 10px;
  animation: message-appear 0.3s ease;
}

.message-avatar { width: 30px; height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 0.8rem; }
.bot-avatar .message-avatar { background: var(--accent-gradient); color: white; }
.user-avatar .message-avatar { background: #475569; color: white; }

.message-content { line-height: 1.5; flex: 1; font-size: 0.95rem; }
.user-message .message-row { flex-direction: row-reverse; }

/* Cards */
.info-card { background: var(--bg-surface); border: 1px solid var(--border-color); border-left: 4px solid var(--accent-primary); padding: 12px; border-radius: 10px; margin-top: 5px; font-size: 0.9rem; }
.card-link { display: inline-block; margin-top: 10px; color: var(--accent-primary); font-weight: 500; }
.generated-image { width: 100%; max-width: 100%; border-radius: 8px; margin-top: 8px; }

/* 7. RESPONSIVE DESIGN (CRITICAL MOBILE FIXES) */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 85%; /* Wider for touch */
    max-width: 320px;
    transform: translateX(-100%); /* Start hidden off-screen */
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    will-change: transform; /* Performance optimization */
  }

  /* When active, slide in */
  .sidebar.active {
    transform: translateX(0);
  }

  /* Dark Overlay when sidebar is open */
  .sidebar.active::after {
    content: '';
    position: fixed;
    top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0, 0, 0, 0.6);
    z-index: -1; /* Behind sidebar, above content */
    backdrop-filter: blur(2px);
  }

  .mobile-menu-toggle { display: flex; }

  /* Stack suggestions on small phones */
  .suggestion-grid {
    grid-template-columns: 1fr; 
  }

  /* Reduce padding on mobile for more space */
  .message-row { padding: 10px 15px; }
  
  /* Hide model name text on very small screens to save space */
  .model-selector span { display: none; }
  
  /* Ensure input doesn't get hidden by keyboard */
  .chat-scroll-area {
    padding-bottom: 20px;
  }
}

/* Listening Animation */
.listening { color: #ef4444 !important; animation: pulse-red 1.5s infinite; }
@keyframes pulse-red { 0% { transform: scale(1); } 50% { transform: scale(1.2); } 100% { transform: scale(1); } }
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px;
}

.sidebar-header img {
    width: 200px;
    height: auto;
}

/* 📱 Mobile */
@media (max-width: 768px) {
    .sidebar-header img {
        width: 150px;
    }
}
