/* Portsmouth Buzz PWA - Enhanced App Styling */

/* CSS Custom Properties for theming */
:root {
  --primary-color: #2196F3;
  --primary-dark: #1976D2;
  --primary-light: #BBDEFB;
  --secondary-color: #FF9800;
  --background-color: #f5f5f5;
  --surface-color: #ffffff;
  --error-color: #F44336;
  --warning-color: #FF9800;
  --success-color: #4CAF50;
  --text-primary: #212121;
  --text-secondary: #757575;
  --divider-color: #BDBDBD;
  
  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  
  /* Border radius */
  --border-radius-sm: 4px;
  --border-radius-md: 8px;
  --border-radius-lg: 12px;
  --border-radius-xl: 16px;
  
  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.12);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 25px rgba(0,0,0,0.15);
  
  /* Animations */
  --transition-fast: 0.15s ease-out;
  --transition-normal: 0.3s ease-out;
  --transition-slow: 0.5s ease-out;
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  :root {
    --background-color: #121212;
    --surface-color: #1e1e1e;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --divider-color: #333333;
  }
}

/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--background-color);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Enhanced loading screen */
#loading-screen {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 1000;
  color: white;
  transition: all var(--transition-slow);
}

#loading-screen.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.logo {
  width: 80px;
  height: 80px;
  background: var(--surface-color);
  border-radius: var(--border-radius-xl);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: var(--spacing-lg);
  box-shadow: var(--shadow-lg);
  animation: logoFloat 2s ease-in-out infinite;
  overflow: hidden;
  padding: 8px;
}

@keyframes logoFloat {
  0%, 100% { transform: translateY(0px); }
  50% { transform: translateY(-10px); }
}

.app-name {
  font-size: 28px;
  font-weight: 600;
  margin-bottom: var(--spacing-sm);
  text-align: center;
}

.app-tagline {
  font-size: 16px;
  opacity: 0.9;
  margin-bottom: var(--spacing-xl);
  text-align: center;
  max-width: 280px;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top: 3px solid white;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Enhanced app container */
#app-container {
  width: 100%;
  height: 100vh;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--background-color);
}

/* Enhanced header */
#app-header {
  background: var(--primary-color);
  color: white;
  padding: var(--spacing-md) var(--spacing-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 100;
  min-height: 64px;
  backdrop-filter: blur(10px);
}

.header-left {
  display: flex;
  align-items: center;
  flex: 1;
}

.app-logo {
  width: 36px;
  height: 36px;
  background: rgba(255,255,255,0.95);
  border-radius: var(--border-radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--primary-color);
  margin-right: var(--spacing-md);
  font-size: 16px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  padding: 4px;
}

.app-title {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.header-actions {
  display: flex;
  gap: var(--spacing-sm);
}

.header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  padding: var(--spacing-sm);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  font-size: 18px;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  backdrop-filter: blur(10px);
}

.header-btn:hover {
  background: rgba(255,255,255,0.25);
  transform: translateY(-1px);
}

.header-btn:active {
  transform: translateY(0);
  background: rgba(255,255,255,0.35);
}

/* Enhanced web container */
#web-container {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--surface-color);
  border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
  margin-top: 2px;
  box-shadow: var(--shadow-lg);
}

iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: var(--surface-color);
  border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0;
}

/* Enhanced offline banner */
.offline-banner {
  background: linear-gradient(90deg, var(--warning-color), #FFB74D);
  color: white;
  text-align: center;
  padding: var(--spacing-md);
  font-size: 14px;
  font-weight: 500;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  transform: translateY(-100%);
  transition: transform var(--transition-normal);
  box-shadow: var(--shadow-md);
}

.offline-banner.visible {
  transform: translateY(0);
}

.offline-banner::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Enhanced bottom navigation */
#bottom-nav {
  background: var(--surface-color);
  border-top: 1px solid var(--divider-color);
  padding: var(--spacing-sm);
  display: none;
  justify-content: space-around;
  align-items: center;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.1);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--spacing-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 12px;
  font-weight: 500;
  border-radius: var(--border-radius-md);
  transition: all var(--transition-fast);
  min-width: 60px;
  text-align: center;
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary-dark);
  transform: translateY(-2px);
}

.nav-item.active {
  color: var(--primary-color);
  background: rgba(33, 150, 243, 0.1);
}

.nav-icon {
  font-size: 20px;
  margin-bottom: var(--spacing-xs);
}

/* Pull-to-refresh indicator */
.pull-to-refresh {
  position: absolute;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  color: var(--primary-color);
  box-shadow: var(--shadow-md);
  transition: all var(--transition-normal);
  z-index: 150;
}

.pull-to-refresh.visible {
  top: 20px;
}

/* Toast notifications */
.toast {
  position: fixed;
  bottom: var(--spacing-lg);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--surface-color);
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: 24px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-lg);
  max-width: 90%;
  word-wrap: break-word;
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(-10px);
}

/* Accessibility enhancements */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* High contrast mode */
@media (prefers-contrast: high) {
  :root {
    --primary-color: #0066CC;
    --text-primary: #000000;
    --text-secondary: #333333;
    --divider-color: #666666;
  }
}

/* Responsive design enhancements */
@media (max-width: 480px) {
  #app-header {
    padding: var(--spacing-sm) var(--spacing-md);
    min-height: 56px;
  }
  
  .app-title {
    font-size: 18px;
  }
  
  .header-btn {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
  
  .app-logo {
    width: 32px;
    height: 32px;
    font-size: 14px;
    padding: 3px;
  }
  
  #web-container {
    border-radius: var(--border-radius-md) var(--border-radius-md) 0 0;
  }
}

@media (max-width: 320px) {
  .app-name {
    font-size: 24px;
  }
  
  .app-tagline {
    font-size: 14px;
  }
  
  .logo {
    width: 64px;
    height: 64px;
    font-size: 24px;
  }
}

/* Landscape orientation */
@media (orientation: landscape) and (max-height: 600px) {
  #app-header {
    min-height: 48px;
    padding: var(--spacing-sm) var(--spacing-md);
  }
  
  .app-title {
    font-size: 16px;
  }
  
  .header-btn {
    width: 32px;
    height: 32px;
    font-size: 14px;
  }
}

/* iOS safe area support */
@supports (padding-top: env(safe-area-inset-top)) {
  #app-header {
    padding-top: calc(var(--spacing-md) + env(safe-area-inset-top));
  }
  
  #bottom-nav {
    padding-bottom: calc(var(--spacing-sm) + env(safe-area-inset-bottom));
  }
}

/* Standalone app mode (when added to home screen) */
@media (display-mode: standalone) {
  body {
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
  
  #app-container {
    border-radius: 0;
  }
}

/* Fullscreen mode */
@media (display-mode: fullscreen) {
  #app-header {
    padding-top: calc(var(--spacing-md) + 20px);
  }
}

/* Print styles */
@media print {
  #app-header,
  #bottom-nav,
  .offline-banner {
    display: none;
  }
  
  #web-container {
    height: auto;
    box-shadow: none;
    border-radius: 0;
  }
}

/* Login button enhancements */
#login-btn {
  transition: all 0.3s ease;
  position: relative;
}

#login-btn.logged-in {
  background-color: rgba(76, 175, 80, 0.3) !important;
  color: #4CAF50 !important;
}

#login-btn.session-expired {
  background-color: rgba(255, 152, 0, 0.3) !important;
  color: #FF9800 !important;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Login modal styles */
.login-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  backdrop-filter: blur(5px);
}

.login-modal.visible {
  display: flex;
}

.login-modal-content {
  background: var(--surface-color);
  color: var(--text-primary);
  padding: var(--spacing-xl);
  border-radius: var(--border-radius-lg);
  max-width: 400px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    transform: translateY(-50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.login-modal h3 {
  margin-bottom: var(--spacing-md);
  color: var(--primary-color);
}

.login-modal p {
  margin-bottom: var(--spacing-lg);
  color: var(--text-secondary);
}

.login-modal button {
  background: var(--primary-color);
  color: white;
  border: none;
  padding: var(--spacing-md) var(--spacing-lg);
  border-radius: var(--border-radius-md);
  cursor: pointer;
  margin: var(--spacing-sm);
  font-size: 16px;
  font-weight: 500;
  transition: all var(--transition-fast);
}

.login-modal button:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
}

.login-modal button.secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--divider-color);
}

.login-modal button.secondary:hover {
  background: var(--background-color);
  color: var(--text-primary);
}

/* Focus styles for accessibility */
.header-btn:focus,
.nav-item:focus {
  outline: 2px solid var(--surface-color);
  outline-offset: 2px;
}

/* Loading states */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.skeleton {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: loading 1.5s infinite;
}

@keyframes loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}