/* Authentication UI Styles */

/* Auth Container and Placeholder */
.auth-container,
.auth-container-placeholder {
  display: flex;
  align-items: center;
  margin-right: 1rem;
}

.auth-container {
  display: flex;
  align-items: center;
  /* Position profile chip near top-right (scrolls with page, like home button) */
  position: absolute;
  top: 20px;
  right: 20px;
  margin-right: 0; /* override shared margin to align 20px from right */
  z-index: 1000;
}

/* RTL support for auth container position — keep profile on the right side in all languages */
html[dir="rtl"] .auth-container {
  right: 20px;
  left: auto;
}

@media (max-width: 768px) {
  .auth-container { top: calc(16px + env(safe-area-inset-top, 0px)); right: calc(16px + env(safe-area-inset-right, 0px)); }
  html[dir="rtl"] .auth-container { right: calc(16px + env(safe-area-inset-right, 0px)); left: auto; }
}

.auth-content {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Loading Spinner */
.auth-loading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--primary-color, #4A90E2);
  font-size: 0.875rem;
}

.auth-loading i {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Error Messages */
.auth-error {
  background: rgba(220, 53, 69, 0.1);
  color: #dc3545;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  border: 1px solid rgba(220, 53, 69, 0.2);
  font-size: 0.875rem;
  max-width: 250px;
  word-wrap: break-word;
}

/* Sign-in Button */
.btn-auth-signin {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: #fff;
  color: #333;
  border: 1px solid #dadce0;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.btn-auth-signin:hover {
  background: #f8f9fa;
  border-color: #c6c8ca;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.btn-auth-signin:active {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.btn-auth-signin i {
  color: #4285f4;
  font-size: 1rem;
}

/* User Profile Dropdown */
.user-profile-dropdown {
  position: relative;
  display: inline-block; /* shrink-wrap to button */
  width: auto;
}

.user-profile-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0.75rem;
  background: var(--card-bg, #fff);
  color: var(--text-primary, #333);
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 0.5rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  max-width: 200px;
}

.user-profile-btn:hover {
  background: var(--hover-bg, #f5f5f5);
  border-color: var(--border-hover, #d0d0d0);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-color, #4A90E2);
  color: white;
  flex-shrink: 0;
}

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 120px;
}

.dropdown-arrow {
  font-size: 0.75rem;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.user-profile-btn[aria-expanded="true"] .dropdown-arrow {
  transform: rotate(180deg);
}

/* User Dropdown Menu */
.user-dropdown-menu {
  position: absolute;
  top: calc(100% + 0.5rem);
  left: 0;
  right: 0; /* match width to parent (profile button) */
  width: 100%;
  min-width: unset;
  background: var(--card-bg, #fff);
  border: 1px solid var(--border-color, #e0e0e0);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  overflow: hidden;
}

.dropdown-header {
  padding: 1rem;
  background: var(--accent-bg, #f8f9fa);
  border-bottom: 1px solid var(--border-color, #e0e0e0);
}

.user-info .user-email {
  font-size: 0.875rem;
  color: var(--text-primary, #333);
  font-weight: 500;
  margin-bottom: 0.25rem;
  word-break: break-all;
}

.user-status {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-size: 0.75rem;
  color: var(--text-secondary, #666);
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-indicator.online {
  background: #28a745;
}

.dropdown-divider {
  height: 1px;
  background: var(--border-color, #e0e0e0);
  margin: 0;
}

.dropdown-body {
  padding: 0.5rem 0;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  color: var(--text-primary, #333);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background-color 0.2s ease;
  text-align: left;
}

.dropdown-item:hover {
  background: var(--hover-bg, #f5f5f5);
}

.dropdown-item i {
  width: 16px;
  font-size: 0.875rem;
  color: var(--text-secondary, #666);
  flex-shrink: 0;
}

.dropdown-item.text-danger {
  color: #dc3545;
}

.dropdown-item.text-danger i {
  color: #dc3545;
}

.dropdown-item.text-danger:hover {
  background: rgba(220, 53, 69, 0.1);
}

/* Responsive Design */
@media (max-width: 768px) {
  .auth-container {
    margin-right: 0; /* keep exactly 20px via right positioning */
  }
  
  .btn-auth-signin {
    padding: 0.375rem 0.75rem;
    font-size: 0.8125rem;
  }
  
  .btn-auth-signin span {
    display: none;
  }
  
  .user-profile-btn {
    padding: 0.375rem 0.5rem;
  }
  
  .user-name {
    display: none;
  }
  
  .user-dropdown-menu {
    left: 0;
    right: 0;
    width: 100%;
    min-width: unset;
  }
}

@media (max-width: 480px) {
  /* Adjust auth container for very small screens */
  .auth-container {
    top: calc(12px + env(safe-area-inset-top, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
  }
  
  html[dir="rtl"] .auth-container {
    right: calc(12px + env(safe-area-inset-right, 0px));
    left: auto;
  }
  
  /* Ensure sign-in button is visible and properly sized */
  .btn-auth-signin {
    padding: 0.375rem 0.5rem;
    font-size: 0.75rem;
    /* Ensure minimum tap target size */
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Icon-only on very small screens */
  .btn-auth-signin i {
    font-size: 1.1rem;
    margin: 0;
  }
  
  .user-dropdown-menu {
    left: 0;
    right: 0;
    width: 100%;
    min-width: unset;
  }
  
  .auth-error {
    max-width: 200px;
    font-size: 0.8125rem;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .btn-auth-signin {
    background: #2d2d2d;
    color: #e0e0e0;
    border-color: #404040;
  }
  
  .btn-auth-signin:hover {
    background: #3d3d3d;
    border-color: #505050;
  }
}

/* Animation for dropdown */
.user-dropdown-menu {
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.2s ease;
  pointer-events: none;
}

.user-dropdown-menu[style*="display: block"] {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Focus styles for accessibility */
.btn-auth-signin:focus,
.user-profile-btn:focus {
  outline: 2px solid var(--primary-color, #4A90E2);
  outline-offset: 2px;
}

.dropdown-item:focus {
  background: var(--hover-bg, #f5f5f5);
  outline: 2px solid var(--primary-color, #4A90E2);
  outline-offset: -2px;
}