:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --secondary: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --bg-dark: #1e1e2e;
  --bg-card: #2a2a3e;
  --bg-light: #f8fafc;
  --text-light: #e2e8f0;
  --text-dark: #1e293b;
  --text-muted: #94a3b8;
  --border: #334155;
  --protein-color: #ef4444;
  --carbs-color: #3b82f6;
  --fat-color: #f59e0b;

  /* iOS Safe Area */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-dark);
  color: var(--text-light);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  -webkit-overflow-scrolling: touch;
}

html {
  height: 100%;
  height: -webkit-fill-available;
}

/* Auth Section */
.auth-container {
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #1e1e2e 0%, #2d2d44 100%);
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
}

.auth-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  border: 1px solid rgba(108, 92, 231, 0.3);
  box-shadow: 0 0 30px rgba(108, 92, 231, 0.4), 
              0 0 60px rgba(108, 92, 231, 0.2),
              0 25px 50px -12px rgba(0, 0, 0, 0.5),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  animation: authCardGlow 3s ease-in-out infinite;
}

@keyframes authCardGlow {
  0%, 100% { 
    box-shadow: 0 0 30px rgba(108, 92, 231, 0.4), 
                0 0 60px rgba(108, 92, 231, 0.2),
                0 25px 50px -12px rgba(0, 0, 0, 0.5),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }
  50% { 
    box-shadow: 0 0 40px rgba(108, 92, 231, 0.6), 
                0 0 80px rgba(108, 92, 231, 0.3),
                0 25px 50px -12px rgba(0, 0, 0, 0.5),
                inset 0 1px 0 rgba(255, 255, 255, 0.15);
  }
}

/* Service Status Indicator */
.service-status {
  margin-top: 20px;
  padding: 12px 16px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 10px;
  text-align: center;
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #94a3b8;
  animation: pulse 1.5s infinite;
}

.service-status.online .status-dot {
  background: #10b981;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.6);
  animation: pulseOnline 2s infinite;
}

.service-status.offline .status-dot {
  background: #ef4444;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.6);
  animation: pulseOffline 1s infinite;
}

.status-text {
  font-size: 13px;
  color: var(--text-muted);
}

.service-status.online .status-text {
  color: #10b981;
}

.service-status.offline .status-text {
  color: #ef4444;
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

@keyframes pulseOnline {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.7; transform: scale(1.15); }
}

@keyframes pulseOffline {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.logo {
  text-align: center;
  margin-bottom: 30px;
}

.logo-icon {
  font-size: 48px;
  display: inline-block;
  line-height: 1;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
}

.logo h1 {
  font-size: 28px;
  margin: 10px 0 5px;
}

.logo p {
  color: var(--text-muted);
  font-size: 14px;
  margin: 0;
}

.auth-form {
  display: none;
}

.auth-form.active {
  display: block;
}

.auth-form h2 {
  margin-bottom: 25px;
  font-size: 22px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  color: var(--text-muted);
}

.form-group input:not([type="checkbox"]),
.form-group select,
.form-group textarea,
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-dark);
  background-color: var(--bg-dark);
  color: var(--text-light);
  font-size: 15px;
  transition: border-color 0.2s;
  font-family: inherit;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* Custom dropdown arrow for select */
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca3af' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* Style select options for dark theme */
select option {
  background: var(--bg-dark);
  background-color: #1e1e2e;
  color: var(--text-light);
  padding: 10px;
}

.form-group input:not([type="checkbox"]):focus,
.form-group select:focus,
.form-group textarea:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
}

.form-group textarea::placeholder,
textarea::placeholder {
  color: var(--text-muted);
}

/* Privacy settings specific select styling */
.privacy-setting select {
  width: auto;
  min-width: 140px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 15px;
}

/* Checkbox styling */
.checkbox-group {
  margin-bottom: 18px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
  color: var(--text-light);
  gap: 10px;
}

.checkbox-label input[type="checkbox"] {
  -webkit-appearance: checkbox;
  -moz-appearance: checkbox;
  appearance: checkbox;
  width: 18px;
  height: 18px;
  min-width: 18px;
  accent-color: var(--primary);
  cursor: pointer;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-dark);
}

.checkbox-label .checkmark {
  display: none;
}

.auth-switch {
  text-align: center;
  margin-top: 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.auth-switch a {
  color: var(--primary);
  text-decoration: none;
}

.auth-switch a:hover {
  text-decoration: underline;
}

.error-message {
  color: var(--danger);
  font-size: 14px;
  margin-top: 15px;
  text-align: center;
}

.demo-hint {
  margin-top: 25px;
  padding: 12px;
  background: rgba(79, 70, 229, 0.1);
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--secondary);
  color: white;
}

.btn-secondary:hover {
  background: #0d9668;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-light);
}

.btn-outline:hover {
  background: var(--bg-dark);
}

.btn-full {
  width: 100%;
  box-sizing: border-box;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-small {
  padding: 8px 16px;
  font-size: 13px;
}

/* Main Layout */
.main-container {
  display: flex;
  min-height: 100vh;
}

.hidden {
  display: none !important;
}

/* Sidebar */
.sidebar {
  width: 240px;
  background: var(--bg-card);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile browsers */
  max-height: -webkit-fill-available;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.sidebar-header .logo-icon {
  font-size: 28px;
}

.logo-text {
  font-size: 20px;
  font-weight: 600;
}

.nav-menu {
  list-style: none;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.2s;
}

.nav-item:hover {
  background: var(--bg-dark);
  color: var(--text-light);
}

.nav-item.active {
  background: var(--primary);
  color: white;
}

.nav-icon {
  font-size: 18px;
}

.sidebar-footer {
  padding: 20px;
  border-top: 1px solid var(--border);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 240px;
  padding: 20px 30px;
  overflow-x: hidden;
}

/* When social page is active, lock to viewport */
.main-content.social-active {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.top-bar h2 {
  font-size: 24px;
}

.user-info {
  color: var(--text-muted);
}

/* Pages */
.page {
  display: none;
}

.page.active {
  display: block;
}

#page-social.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.page-header {
  margin-bottom: 20px;
}

/* Cards */
.card {
  background: var(--bg-card);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 20px;
  border: 1px solid rgba(108, 92, 231, 0.3);
  box-shadow: 0 0 30px rgba(108, 92, 231, 0.4), 
              0 0 60px rgba(108, 92, 231, 0.2),
              0 8px 32px rgba(0, 0, 0, 0.4),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  transition: box-shadow 0.3s ease, transform 0.3s ease, border-color 0.3s ease;
}

.card:hover {
  border-color: rgba(108, 92, 231, 0.5);
  box-shadow: 0 0 40px rgba(108, 92, 231, 0.6), 
              0 0 80px rgba(108, 92, 231, 0.3),
              0 12px 40px rgba(0, 0, 0, 0.5),
              inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transform: translateY(-4px);
}

.card h3 {
  font-size: 16px;
  color: var(--text-muted);
  margin-bottom: 15px;
}

/* Dashboard Grid */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

/* Calorie Ring */
.summary-card {
  grid-row: span 2;
}

.calorie-ring {
  position: relative;
  width: 200px;
  height: 200px;
  margin: 0 auto;
}

.calorie-ring svg {
  transform: rotate(-90deg);
}

.ring-bg {
  fill: none;
  stroke: var(--bg-dark);
  stroke-width: 10;
}

.ring-progress {
  fill: none;
  stroke: var(--primary);
  stroke-width: 10;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.5s ease;
}

.ring-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.ring-text span {
  display: block;
  font-size: 36px;
  font-weight: 600;
}

.ring-text small {
  color: var(--text-muted);
  font-size: 14px;
}

/* Progress Bars */
.macro-item {
  margin-bottom: 15px;
}

.macro-header {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  margin-bottom: 6px;
}

.progress-bar {
  height: 8px;
  background: var(--bg-dark);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.progress-fill.protein { background: var(--protein-color); }
.progress-fill.carbs { background: var(--carbs-color); }
.progress-fill.fat { background: var(--fat-color); }

/* Stats */
.stat-row {
  display: flex;
  gap: 30px;
}

.stat {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 32px;
  font-weight: 600;
}

.stat-label {
  color: var(--text-muted);
  font-size: 13px;
}

/* Water Tracker */
.water-tracker {
  text-align: center;
}

.water-display {
  font-size: 24px;
  margin-bottom: 15px;
}

.water-icon {
  font-size: 28px;
}

/* Quick Actions */
.action-buttons {
  display: flex;
  gap: 10px;
}

/* Weight Display */
.weight-display {
  text-align: center;
}

.weight-value {
  font-size: 42px;
  font-weight: 600;
}

.weight-unit {
  font-size: 18px;
  color: var(--text-muted);
}

.weight-change {
  display: block;
  margin-top: 5px;
  font-size: 14px;
}

.weight-change.positive { color: var(--danger); }
.weight-change.negative { color: var(--secondary); }

/* Search Box */
.search-box {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.search-box input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-dark);
  color: var(--text-light);
}

#barcode-scan-btn {
  padding: 12px 14px;
  min-width: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  box-shadow: 0 0 15px rgba(16, 185, 129, 0.4);
  animation: barcodeGlow 2s ease-in-out infinite;
}

#barcode-scan-btn:hover {
  box-shadow: 0 0 25px rgba(16, 185, 129, 0.6);
  transform: scale(1.05);
}

@keyframes barcodeGlow {
  0%, 100% { box-shadow: 0 0 15px rgba(16, 185, 129, 0.4); }
  50% { box-shadow: 0 0 25px rgba(16, 185, 129, 0.7); }
}

.barcode-icon {
  width: 20px;
  height: 20px;
  animation: barcodeScan 1.5s ease-in-out infinite;
}

@keyframes barcodeScan {
  0%, 100% { 
    opacity: 1;
    transform: scaleX(1);
  }
  50% { 
    opacity: 0.7;
    transform: scaleX(0.95);
  }
}

svg.barcode-icon rect {
  fill: currentColor;
  stroke: none;
}

svg.barcode-icon rect:nth-child(1) { animation: barcodeLine 1.5s ease-in-out infinite 0s; }
svg.barcode-icon rect:nth-child(2) { animation: barcodeLine 1.5s ease-in-out infinite 0.1s; }
svg.barcode-icon rect:nth-child(3) { animation: barcodeLine 1.5s ease-in-out infinite 0.2s; }
svg.barcode-icon rect:nth-child(4) { animation: barcodeLine 1.5s ease-in-out infinite 0.3s; }
svg.barcode-icon rect:nth-child(5) { animation: barcodeLine 1.5s ease-in-out infinite 0.4s; }

@keyframes barcodeLine {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Barcode Scanner Modal */
.barcode-modal-content {
  max-width: 360px;
  width: 90%;
  padding: 15px;
  max-height: 90vh;
  overflow-y: auto;
}

.barcode-modal-content h3 {
  margin-bottom: 10px;
  font-size: 16px;
}

.barcode-scanner-container {
  position: relative;
  width: 100%;
  height: 200px;
  max-height: 200px;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 10px;
}

#barcode-reader {
  width: 100%;
  height: 200px;
  max-height: 200px;
  overflow: hidden;
}

#barcode-reader video {
  border-radius: 8px;
}

#barcode-reader__scan_region {
  border-radius: 8px !important;
}

/* Hide the default white corner lines from html5-qrcode */
#barcode-reader__scan_region img,
#barcode-reader img[alt="Info icon"],
#barcode-reader__scan_region > img,
#qr-shaded-region {
  display: none !important;
}

#barcode-reader__scan_region svg {
  display: none !important;
}

/* Hide the corner brackets */
#barcode-reader div[style*="border-width"] {
  border: none !important;
}

/* Hide all corner elements */
#barcode-reader__scan_region > div {
  display: none !important;
}

/* Make sure video is visible */
#barcode-reader video {
  display: block !important;
}

/* Hide shaded region corners */
[style*="border-left"][style*="border-top"],
[style*="border-right"][style*="border-top"],
[style*="border-left"][style*="border-bottom"],
[style*="border-right"][style*="border-bottom"] {
  border: none !important;
  opacity: 0 !important;
}

#barcode-reader__dashboard_section_csr button {
  background: var(--primary) !important;
  border: none !important;
  padding: 10px 20px !important;
  border-radius: 8px !important;
  color: white !important;
  cursor: pointer !important;
}

/* Animated scan line overlay */
.barcode-scan-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

.scan-region-box {
  width: 90%;
  height: 60px;
  border: 2px solid var(--primary);
  border-radius: 6px;
  position: relative;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.scan-line {
  position: absolute;
  top: 0;
  left: 5%;
  width: 90%;
  height: 3px;
  background: linear-gradient(90deg, transparent, #6c5ce7, #a29bfe, #6c5ce7, transparent);
  box-shadow: 0 0 15px #6c5ce7, 0 0 30px #6c5ce7;
  animation: scanLineMove 2s ease-in-out infinite;
  border-radius: 2px;
}

@keyframes scanLineMove {
  0%, 100% { 
    top: 5%;
    opacity: 1;
  }
  50% { 
    top: 90%;
    opacity: 0.8;
  }
}

.barcode-manual-entry {
  margin-bottom: 8px;
}

.barcode-actions {
  margin-top: 5px;
}

.barcode-actions .btn {
  width: 100%;
}

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
}

.barcode-status {
  padding: 6px 12px;
  background: var(--bg-dark);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
  margin-top: 10px;
}

.barcode-status.success {
  background: var(--secondary);
  color: white;
}

.barcode-status.error {
  background: var(--danger);
  color: white;
}

.barcode-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.barcode-actions .btn {
  flex: 1;
}

.barcode-result {
  background: var(--bg-dark);
  border-radius: 12px;
  padding: 15px;
  margin-top: 15px;
}

.barcode-result.hidden {
  display: none;
}

.barcode-result-content {
  display: flex;
  gap: 15px;
  align-items: center;
  margin-bottom: 15px;
}

.barcode-food-image {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg-card);
}

.barcode-food-info {
  flex: 1;
}

.barcode-food-info h4 {
  margin: 0 0 5px 0;
  font-size: 16px;
  color: var(--text-light);
}

.barcode-food-brand {
  margin: 0 0 5px 0;
  font-size: 13px;
  color: var(--text-muted);
}

.barcode-food-nutrition {
  margin: 0;
  font-size: 12px;
  color: var(--primary);
}

.search-results {
  max-height: 600px;
  min-height: 300px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
}

.search-section {
  margin-bottom: 15px;
}

.search-section-header {
  padding: 8px 12px;
  background: var(--bg-dark);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  z-index: 1;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.search-result-item:hover {
  background: var(--bg-dark);
}

.food-image-container {
  width: 50px;
  height: 50px;
  flex-shrink: 0;
}

.food-thumb {
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--bg-dark);
}

.food-thumb-placeholder {
  width: 50px;
  height: 50px;
  border-radius: 6px;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
}

.food-details {
  flex: 1;
  min-width: 0;
}

.food-name {
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.food-brand {
  font-size: 12px;
  color: var(--primary);
  font-weight: normal;
}

.food-info {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.external-badge {
  font-size: 9px;
  padding: 2px 5px;
  background: var(--secondary);
  color: white;
  border-radius: 3px;
  font-weight: 600;
}

/* Meals Container */
.meals-container {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.meal-items {
  min-height: 50px;
}

.meal-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background: var(--bg-dark);
  border-radius: 6px;
  margin-bottom: 8px;
}

.meal-item-info {
  font-size: 14px;
}

.meal-item-calories {
  color: var(--text-muted);
  font-size: 13px;
}

.delete-btn {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 16px;
}

/* Exercise List */
.exercise-list {
  min-height: 50px;
}

.exercise-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: var(--bg-dark);
  border-radius: 8px;
  margin-bottom: 10px;
}

.exercise-item-info h4 {
  font-size: 15px;
  margin-bottom: 4px;
}

.exercise-item-details {
  font-size: 13px;
  color: var(--text-muted);
}

/* Health Stats Grid */
.health-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
}

.health-stat {
  text-align: center;
  padding: 15px;
  background: var(--bg-dark);
  border-radius: 8px;
}

.health-stat-value {
  font-size: 28px;
  font-weight: 600;
  display: block;
}

.health-stat-label {
  font-size: 13px;
  color: var(--text-muted);
}

/* Summary Stats */
.summary-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.summary-stat {
  text-align: center;
  padding: 12px 8px;
  background: var(--bg-dark);
  border-radius: 8px;
  min-width: 0;
  overflow: hidden;
}

.summary-stat .stat-value {
  font-size: clamp(18px, 5vw, 28px);
  word-break: break-word;
}

.summary-stat .stat-label {
  font-size: clamp(10px, 2.5vw, 13px);
}

/* Charts */
.weight-chart,
.calorie-chart {
  min-height: 200px;
}

.chart-bar {
  display: flex;
  align-items: end;
  gap: 10px;
  height: 150px;
  padding-top: 20px;
}

.bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.bar {
  width: 100%;
  background: var(--primary);
  border-radius: 4px 4px 0 0;
  min-height: 5px;
}

.bar-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 5px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  padding: 30px;
  border-radius: 12px;
  width: 100%;
  max-width: 400px;
  position: relative;
  border: 1px solid rgba(108, 92, 231, 0.3);
  box-shadow: 0 0 30px rgba(108, 92, 231, 0.4), 
              0 0 60px rgba(108, 92, 231, 0.2),
              0 8px 32px rgba(0, 0, 0, 0.4),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  animation: modalGlow 3s ease-in-out infinite;
}

@keyframes modalGlow {
  0%, 100% { 
    box-shadow: 0 0 30px rgba(108, 92, 231, 0.4), 
                0 0 60px rgba(108, 92, 231, 0.2),
                0 8px 32px rgba(0, 0, 0, 0.4),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }
  50% { 
    box-shadow: 0 0 40px rgba(108, 92, 231, 0.6), 
                0 0 80px rgba(108, 92, 231, 0.3),
                0 12px 40px rgba(0, 0, 0, 0.5),
                inset 0 1px 0 rgba(255, 255, 255, 0.15);
  }
}

.modal-close {
  position: absolute;
  top: 15px;
  right: 20px;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-nutrition {
  background: var(--bg-dark);
  padding: 12px;
  border-radius: 8px;
  margin: 15px 0;
  font-size: 14px;
}

/* Date Picker */
.date-picker {
  padding: 10px 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-light);
  font-size: 14px;
}

/* Sidebar User Profile */
.sidebar-user {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 15px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.sidebar-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
  box-shadow: 0 0 15px rgba(79, 70, 229, 0.5), 0 0 30px rgba(79, 70, 229, 0.3);
  border: 2px solid var(--primary);
  animation: avatarGlow 3s ease-in-out infinite;
}

@keyframes avatarGlow {
  0%, 100% {
    box-shadow: 0 0 15px rgba(79, 70, 229, 0.5), 0 0 30px rgba(79, 70, 229, 0.3);
  }
  50% {
    box-shadow: 0 0 20px rgba(79, 70, 229, 0.7), 0 0 40px rgba(79, 70, 229, 0.4);
  }
}

.sidebar-avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.sidebar-avatar-placeholder {
  font-size: 28px;
}

.sidebar-user-name {
  font-size: 14px;
  color: var(--text-light);
  text-align: center;
}

/* Profile Image Section */
.profile-image-section {
  display: flex;
  align-items: center;
  gap: 25px;
}

.profile-image-container {
  position: relative;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  overflow: hidden;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.profile-image-large {
  width: 100%;
  height: 100%;
  object-fit: cover;
  position: absolute;
  top: 0;
  left: 0;
}

/* Hide broken image icon and alt text */
.profile-image-large[src=""],
.profile-image-large:not([src]) {
  display: none;
}

.profile-image-placeholder {
  font-size: 48px;
  position: relative;
  z-index: 1;
}

/* Hide placeholder when image is loaded */
.profile-image-container.has-image .profile-image-placeholder {
  display: none;
}

.profile-image-container.has-image .profile-image-large {
  display: block;
  z-index: 2;
}

.profile-image-actions {
  flex: 1;
}

.profile-image-actions .hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 8px;
}

/* Responsive */
@media (max-width: 1200px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .summary-card {
    grid-row: span 1;
  }
}

@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }

  .sidebar-header .logo-text,
  .nav-item span:not(.nav-icon) {
    display: none;
  }

  .main-content {
    margin-left: 60px;
  }

  .dashboard-grid,
  .meals-container {
    grid-template-columns: 1fr;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  /* Summary stats for tablets */
  .summary-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
  }

  .summary-stat {
    padding: 10px 6px;
  }

  .summary-stat .stat-value {
    font-size: 22px;
  }
}

/* =====================
   NEW FEATURE STYLES
   ===================== */

/* Page Header */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 15px;
}

.stat-item {
  background: var(--bg-dark);
  padding: 20px;
  border-radius: 10px;
  text-align: center;
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

/* History List */
.history-list {
  max-height: 300px;
  overflow-y: auto;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.history-item:last-child {
  border-bottom: none;
}

.history-date {
  font-weight: 500;
}

.history-details {
  color: var(--text-muted);
  font-size: 13px;
}

/* Fasting Timer */
.fasting-card {
  text-align: center;
}

.fasting-timer {
  padding: 20px;
}

.fasting-status {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--secondary);
}

.fasting-progress-ring {
  width: 200px;
  height: 200px;
  margin: 0 auto 20px;
  position: relative;
}

.fasting-progress-ring svg {
  transform: rotate(-90deg);
}

.fasting-ring {
  stroke: var(--secondary);
  transition: stroke-dashoffset 1s ease;
}

.fasting-info {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-bottom: 20px;
  color: var(--text-muted);
}

.fasting-controls {
  display: flex;
  justify-content: center;
  gap: 10px;
}

/* Sleep Quality Stars */
.quality-stars {
  color: var(--warning);
  font-size: 16px;
}

/* Achievements */
.achievements-header {
  display: flex;
  justify-content: space-around;
  padding: 20px 0;
}

.total-points {
  text-align: center;
}

.points-value {
  font-size: 48px;
  font-weight: 700;
  color: var(--warning);
  display: block;
}

.points-label {
  color: var(--text-muted);
}

.streak-info {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 24px;
  font-weight: 600;
}

.streak-icon {
  font-size: 32px;
}

.achievements-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 15px;
}

.achievement-badge {
  background: var(--bg-dark);
  border-radius: 12px;
  padding: 20px 15px;
  text-align: center;
  transition: transform 0.2s;
}

.achievement-badge:hover {
  transform: translateY(-3px);
}

.achievement-badge.earned {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.2), rgba(16, 185, 129, 0.2));
  border: 1px solid var(--secondary);
}

.achievement-badge.locked {
  opacity: 0.5;
  filter: grayscale(1);
}

.badge-icon {
  font-size: 36px;
  display: block;
  margin-bottom: 10px;
}

.badge-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 5px;
}

.badge-description {
  font-size: 11px;
  color: var(--text-muted);
}

.badge-points {
  font-size: 12px;
  color: var(--warning);
  margin-top: 8px;
}

/* Recipes */
.recipes-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

.recipe-card {
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s;
}

.recipe-card:hover {
  transform: translateY(-5px);
}

.recipe-image {
  height: 150px;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
}

.recipe-content {
  padding: 15px;
}

.recipe-title {
  font-weight: 600;
  margin-bottom: 5px;
}

.recipe-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 15px;
}

.recipe-nutrition {
  display: flex;
  gap: 10px;
  margin-top: 10px;
  font-size: 12px;
}

.recipe-nutrition span {
  background: var(--bg-dark);
  padding: 4px 8px;
  border-radius: 4px;
}

/* Modal Large */
.modal-large {
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

/* Ingredients List */
.ingredients-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 10px;
}

.ingredient-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg-dark);
  border-radius: 6px;
  margin-bottom: 5px;
}

.ingredient-item button {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 18px;
}

.add-ingredient {
  display: flex;
  gap: 10px;
}

.add-ingredient input {
  flex: 1;
}

.ingredient-results {
  max-height: 150px;
  overflow-y: auto;
  margin-top: 10px;
}

.ingredient-result {
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 4px;
}

.ingredient-result:hover {
  background: var(--bg-dark);
}

/* Recipe Nutrition Preview */
.recipe-nutrition-preview {
  background: var(--bg-dark);
  padding: 15px;
  border-radius: 8px;
  margin: 15px 0;
}

.recipe-nutrition-preview h4 {
  margin-bottom: 10px;
  font-size: 14px;
}

.nutrition-preview-grid {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  font-size: 14px;
}

/* Daily Tip Toast */
.daily-tip {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--bg-card);
  padding: 15px 20px;
  border-radius: 10px;
  border: 1px solid rgba(108, 92, 231, 0.3);
  box-shadow: 0 0 30px rgba(108, 92, 231, 0.4), 
              0 0 60px rgba(108, 92, 231, 0.2),
              0 10px 30px rgba(0,0,0,0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: 400px;
  z-index: 1001;
  animation: slideIn 0.3s ease, tipGlow 3s ease-in-out infinite 0.3s;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes tipGlow {
  0%, 100% { 
    box-shadow: 0 0 30px rgba(108, 92, 231, 0.4), 
                0 0 60px rgba(108, 92, 231, 0.2),
                0 10px 30px rgba(0,0,0,0.3),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }
  50% { 
    box-shadow: 0 0 40px rgba(108, 92, 231, 0.6), 
                0 0 80px rgba(108, 92, 231, 0.3),
                0 10px 30px rgba(0,0,0,0.3),
                inset 0 1px 0 rgba(255, 255, 255, 0.15);
  }
}

.tip-icon {
  font-size: 24px;
}

.tip-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  margin-left: auto;
}

/* Button Variants */
.btn-success {
  background: var(--secondary);
  color: white;
}

.btn-success:hover {
  background: #059669;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-warning {
  background: var(--warning);
  color: white;
}

/* Ingredient Search Styles */
.ingredient-results {
  max-height: 350px;
  overflow-y: auto;
  margin-top: 10px;
  border-radius: 8px;
  background: var(--bg-dark);
}

.ingredient-section {
  padding: 8px 12px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

.section-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
}

.ingredient-result {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.ingredient-result:hover {
  background: var(--primary);
  color: white;
}

.ingredient-result:hover .ingredient-brand,
.ingredient-result:hover .ingredient-cal {
  color: rgba(255,255,255,0.8);
}

.ingredient-result.external {
  background: rgba(79, 70, 229, 0.05);
}

.ingredient-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.ingredient-info {
  flex: 1;
  min-width: 0;
}

.ingredient-name {
  display: block;
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ingredient-brand {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.ingredient-cal {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.ingredient-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-dark);
  border-radius: 6px;
  margin-bottom: 6px;
}

.ingredient-item button {
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  font-size: 14px;
}

.loading-text {
  padding: 15px;
  text-align: center;
  color: var(--text-muted);
}

.error-text {
  padding: 15px;
  text-align: center;
  color: var(--danger);
}

.empty-text {
  padding: 15px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
}

/* Theme Toggle */
.theme-toggle {
  display: flex;
  gap: 10px;
}

.theme-btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
}

.theme-btn.active {
  background: var(--primary);
  border-color: var(--primary);
}

/* Light Theme */
body.light-theme {
  --bg-dark: #f8fafc;
  --bg-card: #ffffff;
  --text-light: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
}

body.light-theme .sidebar {
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
}

body.light-theme .nav-item:hover,
body.light-theme .nav-item.active {
  background: #f1f5f9;
}

/* Chart Containers */
.chart-container {
  position: relative;
  height: 250px;
  margin-bottom: 20px;
}

.chart-container-small {
  position: relative;
  height: 200px;
  max-width: 300px;
  margin: 0 auto;
}

/* Quick Add Section */
.quick-add-section {
  margin-bottom: 20px;
}

.quick-add-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 15px;
}

.quick-add-tab {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-light);
  cursor: pointer;
  font-size: 13px;
}

.quick-add-tab.active {
  background: var(--primary);
  border-color: var(--primary);
}

.quick-foods-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.quick-food-chip {
  background: var(--bg-dark);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
}

.quick-food-chip:hover {
  background: var(--primary);
}

/* Favorite Button */
.favorite-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity 0.2s, transform 0.2s;
}

.favorite-btn:hover {
  opacity: 1;
  transform: scale(1.2);
}

.favorite-btn.favorited {
  opacity: 1;
}

/* Progress Photos */
.photos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 15px;
}

.photo-card {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 3/4;
  background: var(--bg-dark);
}

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-date {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.8));
  padding: 20px 10px 10px;
  font-size: 13px;
}

/* Body Measurements */
.measurements-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 15px;
}

.measurement-input {
  display: flex;
  flex-direction: column;
}

.measurement-input label {
  font-size: 12px;
  margin-bottom: 5px;
  color: var(--text-muted);
}

.measurement-input input {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-dark);
  color: var(--text-light);
}

/* Comparison View */
.comparison-container {
  display: flex;
  gap: 20px;
}

.comparison-photo {
  flex: 1;
  text-align: center;
}

.comparison-photo img {
  max-width: 100%;
  border-radius: 10px;
}

.comparison-label {
  margin-top: 10px;
  font-weight: 600;
}

/* =====================
   SOCIAL & CHAT STYLES
   ===================== */

/* Navigation Badge */
.nav-badge {
  background: var(--danger);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: auto;
}

/* Notification Button */
.notification-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  position: relative;
  margin-right: 15px;
}

.notification-badge {
  position: absolute;
  top: -5px;
  right: -5px;
  background: var(--danger);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 10px;
}

/* Notifications Panel */
.notifications-panel {
  position: absolute;
  top: 60px;
  right: 20px;
  width: 350px;
  max-height: 400px;
  background: var(--bg-card);
  border-radius: 12px;
  border: 1px solid rgba(108, 92, 231, 0.3);
  box-shadow: 0 0 30px rgba(108, 92, 231, 0.4), 
              0 0 60px rgba(108, 92, 231, 0.2),
              0 10px 40px rgba(0,0,0,0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
  z-index: 100;
  overflow: hidden;
  animation: notificationsGlow 3s ease-in-out infinite;
}

@keyframes notificationsGlow {
  0%, 100% { 
    box-shadow: 0 0 30px rgba(108, 92, 231, 0.4), 
                0 0 60px rgba(108, 92, 231, 0.2),
                0 10px 40px rgba(0,0,0,0.3),
                inset 0 1px 0 rgba(255, 255, 255, 0.1);
  }
  50% { 
    box-shadow: 0 0 40px rgba(108, 92, 231, 0.6), 
                0 0 80px rgba(108, 92, 231, 0.3),
                0 10px 40px rgba(0,0,0,0.3),
                inset 0 1px 0 rgba(255, 255, 255, 0.15);
  }
}

.notifications-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px;
  border-bottom: 1px solid var(--border);
}

.notifications-list {
  max-height: 340px;
  overflow-y: auto;
}

.notification-item {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  gap: 10px;
}

.notification-item:hover {
  background: var(--bg-dark);
}

.notification-item.unread {
  background: rgba(79, 70, 229, 0.1);
}

.notification-icon {
  font-size: 24px;
}

.notification-content {
  flex: 1;
}

.notification-title {
  font-weight: 500;
  font-size: 14px;
}

.notification-body {
  font-size: 12px;
  color: var(--text-muted);
}

.notification-time {
  font-size: 11px;
  color: var(--text-muted);
}

/* Social Layout */
.social-layout {
  display: flex;
  gap: 0;
  flex: 1;
  min-height: 0;
  margin: 0 -30px 0 -30px;
  overflow: hidden;
  box-sizing: border-box;
}

.social-sidebar {
  width: 320px;
  min-width: 280px;
  max-width: 350px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  box-sizing: border-box;
  padding-left: 30px;
}

.social-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.social-tabs::-webkit-scrollbar {
  display: none;
}

.social-tab {
  flex: 1;
  padding: 12px 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.social-tab.active {
  color: var(--primary);
  border-bottom: 2px solid var(--primary);
}

.social-tab-content {
  display: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px;
  box-sizing: border-box;
  width: 100%;
}

.social-tab-content.active {
  display: block;
}

/* Generic h4 styling for social tab content sections */
.social-tab-content h4 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.social-search {
  margin-bottom: 10px;
}

.social-search input {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-dark);
  color: var(--text-light);
}

.search-results {
  max-height: 200px;
  overflow-y: auto;
}

.friends-section {
  margin-top: 15px;
  overflow: hidden;
}

.friends-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.count-badge {
  background: var(--bg-dark);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
}

/* User/Friend Items */
.user-item, .friend-item, .conversation-item, .room-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 5px;
  min-width: 0;
  overflow: hidden;
  box-sizing: border-box;
  width: 100%;
}

.user-item:hover, .friend-item:hover, .conversation-item:hover, .room-item:hover {
  background: var(--bg-dark);
}

.conversation-item.active, .room-item.active {
  background: rgba(79, 70, 229, 0.2);
}

.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  position: relative;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
}

.online-indicator {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: var(--secondary);
  border: 2px solid var(--bg-card);
  border-radius: 50%;
}

.user-info-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}

.user-name {
  font-weight: 500;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-status, .last-message {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-actions {
  display: flex;
  gap: 5px;
}

.user-actions button {
  padding: 5px 10px;
  font-size: 12px;
}

.unread-badge {
  background: var(--primary);
  color: white;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
}

/* Chat Area */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
  min-height: 0;
  overflow: hidden;
  padding-right: 30px;
}

.chat-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

.chat-placeholder-icon {
  font-size: 64px;
  margin-bottom: 20px;
  opacity: 0.5;
}

.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
}

.chat-name {
  font-weight: 600;
}

.chat-status {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-status.online {
  color: var(--secondary);
}

.chat-status.offline {
  color: var(--text-muted);
}

.chat-status .online-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--secondary);
  border-radius: 50%;
  animation: pulse-online 2s ease-in-out infinite;
}

@keyframes pulse-online {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

.message {
  max-width: 70%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.message.sent {
  align-self: flex-end;
}

.message.received {
  align-self: flex-start;
}

.message-content {
  padding: 10px 15px;
  border-radius: 18px;
  font-size: 14px;
  word-break: break-word;
  overflow: hidden;
}

/* Ensure media content stays within message bounds */
.message-content video,
.message-content img {
  max-width: 100%;
  height: auto;
  display: block;
}

.message.sent .message-content {
  background: var(--primary);
  color: white;
  border-bottom-right-radius: 4px;
}

.message.received .message-content {
  background: var(--bg-card);
  border-bottom-left-radius: 4px;
}

.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  display: flex;
  gap: 8px;
}

.message.sent .message-meta {
  justify-content: flex-end;
}

.message-sender {
  font-size: 12px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--primary);
}

/* Media Messages */
.message-image {
  max-width: 250px;
  border-radius: 12px;
  cursor: pointer;
  display: block;
}

.message-video {
  max-width: 100%;
  width: 100%;
  border-radius: 12px;
  display: block;
}

.message-audio {
  width: 250px;
}

/* Custom Audio Player with Waveform */
.audio-player {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-dark);
  border-radius: 20px;
  min-width: 250px;
  max-width: 320px;
}

.audio-player audio {
  display: none;
}

.audio-play-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all 0.2s ease;
  box-shadow: 0 0 15px rgba(108, 92, 231, 0.4);
}

.audio-play-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 0 20px rgba(108, 92, 231, 0.6);
}

.audio-waveform {
  flex: 1;
  height: 36px;
  position: relative;
  cursor: pointer;
  overflow: hidden;
  border-radius: 4px;
}

.waveform-bars {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 100%;
}

.waveform-bar {
  flex: 1;
  background: var(--text-muted);
  border-radius: 2px;
  min-width: 3px;
  transition: background 0.1s ease;
}

.waveform-progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0%;
  overflow: hidden;
  pointer-events: none;
}

.waveform-progress::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, var(--primary) 0%, var(--primary) 100%);
  mix-blend-mode: color;
}

.audio-player.playing .waveform-bar {
  animation: waveformPulse 0.5s ease-in-out infinite alternate;
}

.audio-player.playing .waveform-bar:nth-child(odd) {
  animation-delay: 0.1s;
}

.audio-player.playing .waveform-bar:nth-child(3n) {
  animation-delay: 0.2s;
}

@keyframes waveformPulse {
  from { opacity: 0.6; }
  to { opacity: 1; }
}

.audio-time {
  font-size: 12px;
  color: var(--text-muted);
  min-width: 35px;
  text-align: right;
}

.message.sent .audio-player {
  background: rgba(0, 0, 0, 0.2);
}

.message.sent .waveform-bar {
  background: rgba(255, 255, 255, 0.5);
}

.message.sent .audio-time {
  color: rgba(255, 255, 255, 0.8);
}

.message-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: var(--bg-dark);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-light);
}

.file-icon {
  font-size: 24px;
}

.file-info {
  flex: 1;
}

.file-name {
  font-size: 13px;
  font-weight: 500;
}

.file-size {
  font-size: 11px;
  color: var(--text-muted);
}

/* Reply Preview */
.reply-preview {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 15px;
  background: var(--bg-card);
  border-left: 3px solid var(--primary);
  font-size: 13px;
  color: var(--text-muted);
}

.reply-preview button {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
}

/* Typing Indicator */
.typing-indicator {
  padding: 5px 20px;
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* Chat Input */
.chat-input-area {
  padding: 15px 20px;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
}

.chat-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.chat-input-row input {
  flex: 1;
  padding: 12px 15px;
  border: 1px solid var(--border);
  border-radius: 25px;
  background: var(--bg-dark);
  color: var(--text-light);
  font-size: 14px;
}

.chat-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--bg-card);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  box-shadow: 0 0 15px rgba(108, 92, 231, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.chat-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-light);
  box-shadow: 0 0 20px rgba(108, 92, 231, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.chat-btn.send-btn {
  background: var(--primary);
  color: white;
  border-radius: 12px;
  box-shadow: 0 0 20px rgba(108, 92, 231, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.chat-btn.send-btn:hover {
  box-shadow: 0 0 25px rgba(108, 92, 231, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* Chat Attach Menu */
.chat-attach-menu {
  position: relative;
}

.chat-menu-toggle {
  background: var(--primary) !important;
  color: white !important;
}

.chat-menu-toggle .menu-icon {
  font-size: 24px;
  font-weight: bold;
  line-height: 1;
  transition: transform 0.3s ease;
}

.chat-attach-menu.open .menu-icon {
  transform: rotate(45deg);
}

.chat-attach-options {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(10px);
  transition: all 0.3s ease;
}

.chat-attach-menu.open .chat-attach-options {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.chat-attach-options .chat-btn {
  animation: popIn 0.2s ease forwards;
  opacity: 0;
}

.chat-attach-menu.open .chat-attach-options .chat-btn:nth-child(1) {
  animation-delay: 0.05s;
}

.chat-attach-menu.open .chat-attach-options .chat-btn:nth-child(2) {
  animation-delay: 0.1s;
}

.chat-attach-menu.open .chat-attach-options .chat-btn:nth-child(3) {
  animation-delay: 0.15s;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.8);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Voice Note Recording */
.recording-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--danger);
}

.recording-dot {
  width: 10px;
  height: 10px;
  background: var(--danger);
  border-radius: 50%;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* System Messages */
.system-message {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  padding: 10px;
}

/* Disappearing Message Indicator */
.disappearing-indicator {
  font-size: 11px;
  color: var(--warning);
}

/* Room Members */
.room-members-list {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 10px;
}

.room-member-chip {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--bg-dark);
  border-radius: 15px;
  font-size: 12px;
}

.member-role {
  font-size: 10px;
  color: var(--primary);
}

/* Privacy Toggle */
.privacy-setting {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid var(--border);
}

.privacy-label {
  font-weight: 500;
}

.privacy-description {
  font-size: 12px;
  color: var(--text-muted);
}

.toggle-switch {
  position: relative;
  width: 50px;
  height: 26px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--border);
  transition: .3s;
  border-radius: 26px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: var(--primary);
}

input:checked + .toggle-slider:before {
  transform: translateX(24px);
}

/* ===========================================
   COMPREHENSIVE RESPONSIVE DESIGN
   =========================================== */

/* Mobile Menu Toggle Button */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  top: 15px;
  left: 15px;
  z-index: 1001;
  background: var(--primary);
  border: none;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  font-size: 24px;
  cursor: pointer;
  color: white;
}

.mobile-menu-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 999;
}

/* ============ TABLET (768px - 1024px) ============ */
@media (max-width: 1024px) {
  .dashboard-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .summary-card {
    grid-column: span 1;
    grid-row: span 1;
  }

  .meals-container {
    grid-template-columns: repeat(2, 1fr);
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-row {
    grid-template-columns: 1fr 1fr;
  }

  .sidebar {
    width: 200px;
    height: 100dvh;
    max-height: -webkit-fill-available;
    overflow-y: auto;
  }

  /* Compact nav for tablet */
  .sidebar .nav-item {
    padding: 12px 16px;
    font-size: 14px;
  }

  .sidebar .nav-icon {
    font-size: 16px;
  }

  .main-content {
    margin-left: 200px;
  }

  .main-content.social-active {
    height: 100vh;
    height: 100dvh;
    padding-bottom: 0;
  }

  .social-layout {
    flex-direction: column;
    margin: 0 -20px 0 -20px;
    overflow-x: hidden;
  }

  .social-sidebar {
    width: 100%;
    max-width: 100%;
    max-height: 45vh;
    min-height: 180px;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: hidden;
    padding-left: 20px;
    padding-right: 20px;
  }

  .chat-area {
    padding-left: 20px;
    padding-right: 20px;
  }

  .modal-content {
    width: 90%;
    max-width: 600px;
  }

  .modal-large {
    width: 95%;
  }
}

/* ============ MOBILE LANDSCAPE & SMALL TABLETS (576px - 768px) ============ */
@media (max-width: 768px) {
  /* Show mobile menu toggle */
  .mobile-menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .mobile-menu-overlay.active {
    display: block;
  }

  /* Hide sidebar by default on mobile */
  .sidebar {
    position: fixed;
    left: -280px;
    top: 0;
    width: 280px;
    height: 100%;
    height: 100dvh; /* Dynamic viewport height - accounts for mobile browser chrome */
    max-height: -webkit-fill-available;
    z-index: 1000;
    transition: left 0.3s ease;
    padding-top: 60px;
    padding-bottom: 20px;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
  }

  .sidebar.open {
    left: 0;
  }

  /* Make nav menu scrollable */
  .sidebar .nav-menu {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding-bottom: 10px;
  }

  /* Compact nav items on mobile */
  .sidebar .nav-item {
    padding: 12px 20px;
    font-size: 14px;
  }

  .sidebar .nav-icon {
    font-size: 16px;
  }

  /* Sidebar footer stays at bottom */
  .sidebar .sidebar-footer {
    flex-shrink: 0;
    padding: 15px 20px;
    margin-top: auto;
  }

  /* Sidebar user profile compact */
  .sidebar .sidebar-user {
    padding: 10px 15px;
  }

  .sidebar .sidebar-avatar {
    width: 36px;
    height: 36px;
  }

  .sidebar .sidebar-user-name {
    font-size: 13px;
  }

  .main-content {
    margin-left: 0;
    padding: 70px 15px 15px;
  }

  /* Top bar adjustments */
  .top-bar {
    padding: 15px;
    padding-left: 70px;
  }

  #page-title {
    font-size: 18px;
  }

  /* Dashboard */
  .dashboard-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }

  .meals-container {
    grid-template-columns: 1fr;
  }

  .card {
    padding: 15px;
  }

  /* Calorie Ring */
  .calorie-ring {
    width: 160px;
    height: 160px;
  }

  .ring-text span {
    font-size: 28px;
  }

  /* Forms */
  .form-row {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .form-group input,
  .form-group select,
  .form-group textarea,
  select {
    padding: 14px;
    font-size: 16px; /* Prevents zoom on iOS */
  }

  /* Buttons */
  .btn {
    padding: 12px 20px;
    font-size: 15px;
  }

  .btn-small {
    padding: 10px 14px;
  }

  /* Stats */
  .stat-row {
    flex-wrap: wrap;
    gap: 15px;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

  /* Food search */
  .search-container {
    flex-direction: column;
  }

  .search-container input {
    width: 100%;
  }

  /* Exercise form */
  .exercise-form-grid {
    grid-template-columns: 1fr;
  }

  /* Progress page */
  .progress-grid {
    grid-template-columns: 1fr;
  }

  .chart-container {
    height: 250px;
  }

  /* Profile */
  .profile-image-section {
    flex-direction: column;
    text-align: center;
  }

  .health-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Recipes */
  .recipes-grid {
    grid-template-columns: 1fr;
  }

  /* Fasting */
  .fasting-progress-ring svg {
    width: 180px;
    height: 180px;
  }

  .fasting-presets {
    flex-wrap: wrap;
    justify-content: center;
  }

  /* Social */
  .main-content.social-active {
    height: 100vh;
    height: 100dvh;
    padding-bottom: 0;
  }

  .social-layout {
    flex-direction: column;
    margin: 0 -15px 0 -15px;
    overflow-x: hidden;
  }

  .social-sidebar {
    width: 100%;
    max-width: 100%;
    max-height: 40vh;
    min-height: 150px;
    min-width: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: hidden;
    padding-left: 15px;
    padding-right: 15px;
  }

  .chat-area {
    flex: 1;
    min-height: 0;
    padding-right: 15px;
    padding-left: 15px;
  }

  .chat-messages {
    padding: 10px;
  }

  .message {
    max-width: 85%;
  }

  .chat-input-area {
    padding: 10px;
  }

  /* Notifications panel */
  .notifications-panel {
    right: 10px;
    left: 10px;
    width: auto;
  }

  /* Modal */
  .modal-content {
    width: 95%;
    max-height: 90vh;
    margin: 20px auto;
    padding: 15px;
  }

  .modal-large {
    width: 98%;
  }

  /* Privacy settings */
  .privacy-setting {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .privacy-setting select {
    width: 100%;
  }

  /* Photos grid */
  .photos-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Measurements */
  .measurements-form {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Achievements */
  .achievements-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .achievements-header {
    flex-direction: column;
    gap: 15px;
  }
}

/* ============ MOBILE PORTRAIT (up to 576px) ============ */
@media (max-width: 576px) {
  body {
    font-size: 14px;
  }

  .main-content {
    padding: 60px 10px 10px;
  }

  .top-bar {
    padding: 10px;
    padding-left: 60px;
  }

  #page-title {
    font-size: 16px;
  }

  .card {
    padding: 12px;
    border-radius: 10px;
  }

  .card h3 {
    font-size: 16px;
  }

  /* Calorie ring smaller */
  .calorie-ring {
    width: 140px;
    height: 140px;
  }

  .ring-text span {
    font-size: 24px;
  }

  /* Macros */
  .macro-header {
    font-size: 13px;
  }

  /* Stats grid single column */
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-item {
    padding: 12px;
  }

  /* Summary stats responsive */
  .summary-stats {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .summary-stat {
    padding: 10px 6px;
  }

  .summary-stat .stat-value {
    font-size: 20px;
  }

  .summary-stat .stat-label {
    font-size: 11px;
  }

  /* Food items */
  .food-item {
    padding: 10px;
  }

  .food-item-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 5px;
  }

  .food-macros {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Exercise items */
  .exercise-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  /* Goals */
  .goal-item {
    flex-direction: column;
    align-items: stretch;
  }

  /* Buttons full width on very small screens */
  .btn-full-mobile {
    width: 100%;
  }

  /* Health stats */
  .health-stats-grid {
    grid-template-columns: 1fr;
  }

  /* Social chat */
  .main-content.social-active {
    height: 100vh;
    height: 100dvh;
    padding-bottom: 0;
  }

  .social-layout {
    margin: 0 -10px 0 -10px;
    overflow-x: hidden;
  }

  .social-sidebar {
    max-width: 100%;
    max-height: 35vh;
    min-height: 130px;
    overflow-x: hidden;
    padding-left: 10px;
    padding-right: 10px;
  }

  .chat-area {
    padding-left: 10px;
    padding-right: 10px;
  }

  .user-item,
  .friend-item,
  .conversation-item,
  .room-item {
    padding: 8px;
  }

  .user-avatar {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }

  .chat-header {
    padding: 10px 12px;
  }

  .chat-avatar {
    width: 32px;
    height: 32px;
  }

  .chat-name {
    font-size: 14px;
  }

  .message-content {
    padding: 8px 12px;
    font-size: 14px;
  }

  .chat-input-row input {
    padding: 10px 12px;
    font-size: 16px;
  }

  .chat-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    font-size: 16px;
    border-radius: 10px;
  }

  /* Photos */
  .photos-grid {
    grid-template-columns: 1fr;
  }

  /* Measurements */
  .measurements-form {
    grid-template-columns: 1fr;
  }

  /* Achievements */
  .achievements-grid {
    grid-template-columns: 1fr;
  }

  .achievement-card {
    padding: 15px;
  }

  /* Fasting */
  .fasting-progress-ring svg {
    width: 150px;
    height: 150px;
  }

  .fasting-presets .btn {
    padding: 8px 12px;
    font-size: 13px;
  }

  /* Ingredient results */
  .ingredient-results {
    max-height: 250px;
  }

  /* Recipe nutrition preview */
  .nutrition-preview-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  /* Daily tip */
  .daily-tip {
    left: 10px;
    right: 10px;
    bottom: 10px;
    font-size: 13px;
  }
}

/* ============ TOUCH DEVICE OPTIMIZATIONS ============ */
@media (hover: none) and (pointer: coarse) {
  /* Larger touch targets */
  .btn {
    min-height: 44px;
  }

  .nav-item {
    padding: 14px 20px;
  }

  .food-item,
  .exercise-item,
  .user-item,
  .friend-item,
  .conversation-item,
  .room-item {
    min-height: 48px;
  }

  /* Remove hover effects that don't work on touch */
  .btn:hover {
    transform: none;
  }

  /* Add active states instead */
  .btn:active {
    transform: scale(0.98);
    opacity: 0.9;
  }

  .nav-item:active,
  .food-item:active,
  .user-item:active {
    background: var(--primary);
  }
}

/* ============ LANDSCAPE PHONE ============ */
@media (max-height: 500px) and (orientation: landscape) {
  .sidebar {
    padding-top: 10px;
  }

  .nav-item {
    padding: 10px 20px;
  }

  .modal-content {
    max-height: 95vh;
    margin: 10px auto;
  }

  .calorie-ring {
    width: 120px;
    height: 120px;
  }
}

/* ============ PRINT STYLES ============ */
@media print {
  .sidebar,
  .mobile-menu-toggle,
  .top-bar,
  .btn,
  .modal {
    display: none !important;
  }

  .main-content {
    margin: 0;
    padding: 0;
  }

  .card {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
  }
}

/* ============ HIGH CONTRAST / ACCESSIBILITY ============ */
@media (prefers-contrast: high) {
  :root {
    --border: #666;
  }

  .btn {
    border: 2px solid currentColor;
  }
}

/* ============ REDUCED MOTION ============ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============ TOAST NOTIFICATIONS ============ */
@keyframes toastSlideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

@keyframes toastSlideDown {
  from {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
  to {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
}

/* ============ LINK PREVIEWS ============ */
.link-preview {
  margin-top: 8px;
  border-radius: 8px;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border);
}

.link-preview.loading {
  padding: 12px;
  color: var(--text-muted);
  font-size: 12px;
}

.link-preview.video-embed {
  aspect-ratio: 16/9;
  max-width: 400px;
}

.link-preview.video-embed iframe {
  width: 100%;
  height: 100%;
}

.link-preview .preview-link {
  display: flex;
  flex-direction: column;
  text-decoration: none;
  color: inherit;
}

.link-preview .preview-image {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
}

.link-preview .preview-content {
  padding: 10px;
}

.link-preview .preview-title {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  color: var(--text-light);
}

.link-preview .preview-description {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  line-height: 1.4;
}

.link-preview .preview-site {
  font-size: 11px;
  color: var(--primary);
}

.message-link {
  color: var(--primary);
  word-break: break-all;
}

/* ============ FILE PREVIEWS ============ */
.message-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
  border: 1px solid var(--border);
}

.message-file:hover {
  background: rgba(0, 0, 0, 0.3);
}

.message-file .file-icon {
  font-size: 24px;
}

.message-file .file-info {
  flex: 1;
  min-width: 0;
}

.message-file .file-name {
  font-weight: 500;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-file .file-size {
  font-size: 11px;
  color: var(--text-muted);
}

.message-image {
  max-width: 300px;
  max-height: 300px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
}

.message-video {
  max-width: 100%;
  width: 100%;
  max-height: 300px;
  border-radius: 8px;
  display: block;
}

.message-audio {
  width: 100%;
  max-width: 250px;
}

/* ============ CHAT ACTION BUTTONS ============ */
.chat-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.chat-action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(145deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
}

.chat-action-btn:hover {
  transform: translateY(-2px);
  background: linear-gradient(145deg, rgba(255,255,255,0.15), rgba(255,255,255,0.08));
  box-shadow: 0 4px 12px rgba(0,0,0,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}

.chat-action-btn:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(0,0,0,0.2), inset 0 1px 0 rgba(255,255,255,0.1);
}

.chat-action-btn.primary {
  background: linear-gradient(145deg, var(--primary), var(--primary-dark));
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.4), inset 0 1px 0 rgba(255,255,255,0.2);
}

.chat-action-btn.primary:hover {
  background: linear-gradient(145deg, #5b52f0, var(--primary));
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.5), inset 0 1px 0 rgba(255,255,255,0.25);
}

.chat-action-btn .action-icon {
  font-size: 18px;
  line-height: 1;
}

/* ============ ROOM MEMBERS MODAL ============ */
.member-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  margin-bottom: 8px;
}

.member-actions {
  display: flex;
  gap: 5px;
  align-items: center;
}

.role-select {
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-light);
  border: 1px solid var(--border);
  font-size: 12px;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.section-divider {
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ============ ROOM SETTINGS MODAL ============ */
.room-settings-content {
  max-width: 480px;
  width: 100%;
}

.room-settings-content h3 {
  margin-bottom: 20px;
}

.room-settings-content .form-group {
  margin-bottom: 20px;
}

.room-settings-content label:not(.permission-item) {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-light);
}

.room-settings-content input[type="text"],
.room-settings-content textarea {
  width: 100%;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-dark);
  color: var(--text-light);
  font-size: 14px;
  box-sizing: border-box;
}

.room-settings-content input[type="file"] {
  padding: 10px;
  background: var(--bg-dark);
  border: 1px dashed var(--border);
  border-radius: 8px;
  width: 100%;
  cursor: pointer;
  box-sizing: border-box;
}

.settings-section {
  background: rgba(255, 255, 255, 0.03);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}

.settings-section h4 {
  margin: 0 0 4px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
}

.settings-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 16px 0;
}

/* Permission Toggles */
.permission-toggles {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.permission-item {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center !important;
  justify-content: space-between !important;
  padding: 12px 16px;
  background: linear-gradient(135deg, rgba(255,255,255,0.08), rgba(255,255,255,0.03));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  gap: 16px;
}

.permission-item:hover {
  background: linear-gradient(135deg, rgba(255,255,255,0.12), rgba(255,255,255,0.06));
  border-color: rgba(255,255,255,0.15);
}

.permission-info {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center !important;
  gap: 10px;
}

.permission-icon {
  font-size: 16px;
  flex-shrink: 0;
}

.permission-text {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-light);
  white-space: nowrap;
}

/* Modern Toggle Switch */
.toggle-switch {
  flex-shrink: 0 !important;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  display: block;
  width: 46px;
  height: 26px;
  background: rgba(255,255,255,0.2);
  border-radius: 13px;
  position: relative;
  transition: all 0.3s ease;
}

.toggle-thumb {
  position: absolute;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  top: 3px;
  left: 3px;
  transition: all 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-track .toggle-thumb {
  transform: translateX(20px);
}

/* ============ PERMISSION ALERT ============ */
.permission-alert {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10001;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOut {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100px);
  }
}

.permission-alert-content {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: linear-gradient(135deg, #2a2a3e, #1e1e2e);
  border: 1px solid var(--primary);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 8px 32px rgba(79, 70, 229, 0.3), 0 4px 16px rgba(0,0,0,0.4);
  max-width: 320px;
}

.permission-alert-icon {
  font-size: 24px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(79, 70, 229, 0.2);
  border-radius: 10px;
  flex-shrink: 0;
}

.permission-alert-text {
  flex: 1;
}

.permission-alert-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.permission-alert-room {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.permission-alert-changes {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.permission-change {
  display: inline-block;
  font-size: 11px;
  padding: 4px 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 6px;
  color: var(--text-light);
}

.permission-alert-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.2s ease;
}

.permission-alert-close:hover {
  color: var(--text-light);
}

.toggle-label {
  font-size: 14px;
  color: var(--text-light);
}

.danger-section {
  background: rgba(239, 68, 68, 0.1);
  border-radius: 12px;
  padding: 16px;
}

.danger-section h4 {
  color: var(--danger);
  margin: 0 0 8px 0;
}

/* ============ VIDEO RECORDING MODAL ============ */
.video-modal-content {
  max-width: 400px;
  text-align: center;
}

.video-preview-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  margin: 15px 0;
}

.video-preview-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1); /* Mirror for selfie */
}

.recording-indicator {
  position: absolute;
  top: 12px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.6);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: #fff;
}

.recording-dot {
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  animation: recordingPulse 1s infinite;
}

@keyframes recordingPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.video-timer {
  position: absolute;
  bottom: 12px;
  right: 12px;
  background: rgba(0,0,0,0.6);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  font-family: monospace;
}

.video-controls {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin: 15px 0;
}

.btn-round {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-round:hover {
  transform: scale(1.1);
}

.btn-round.recording {
  background: #ef4444 !important;
  animation: recordingPulse 1s infinite;
}

.video-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0;
}

/* ============ MESSAGE ACTIONS (EDIT/DELETE) ============ */
.message {
  position: relative;
}

.message-actions {
  position: absolute;
  top: 4px;
  right: 4px;
  display: none;
  gap: 4px;
  background: rgba(0, 0, 0, 0.6);
  border-radius: 8px;
  padding: 4px;
}

.message.sent:hover .message-actions {
  display: flex;
}

.msg-action-btn {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s ease;
}

.msg-action-btn:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(1.1);
}

.msg-action-btn:last-child:hover {
  background: rgba(239, 68, 68, 0.5);
}

@keyframes fadeOut {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.9); }
}
