/* SleepSimSocial - Global Styles */
/* Design System: Sleep lab at 2 AM energy */

/* CSS Variables */
:root {
  /* Colors */
  --color-bg: #0f0f1a;
  --color-surface: #1a1a2e;
  --color-surface-elevated: #252540;
  --color-primary: #4a9eff;
  --color-primary-hover: #3a8eef;
  --color-success: #22c55e;
  --color-error: #ef4444;
  --color-text: #e2e8f0;
  --color-text-muted: #94a3b8;
  --color-border: #2a2a4a;

  /* Typography - Fluid sizing */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-size-xs: clamp(0.7rem, 0.65rem + 0.25vw, 0.75rem);
  --font-size-sm: clamp(0.8rem, 0.75rem + 0.25vw, 0.875rem);
  --font-size-base: clamp(0.9rem, 0.85rem + 0.25vw, 1rem);
  --font-size-lg: clamp(1rem, 0.95rem + 0.25vw, 1.125rem);
  --font-size-xl: clamp(1.1rem, 1rem + 0.5vw, 1.25rem);
  --font-size-2xl: clamp(1.25rem, 1.1rem + 0.75vw, 1.5rem);
  --font-size-3xl: clamp(1.5rem, 1.25rem + 1vw, 2rem);

  /* Spacing - Fluid */
  --space-1: clamp(0.2rem, 0.15rem + 0.25vw, 0.25rem);
  --space-2: clamp(0.4rem, 0.35rem + 0.25vw, 0.5rem);
  --space-3: clamp(0.6rem, 0.5rem + 0.5vw, 0.75rem);
  --space-4: clamp(0.8rem, 0.7rem + 0.5vw, 1rem);
  --space-5: clamp(1rem, 0.9rem + 0.5vw, 1.25rem);
  --space-6: clamp(1.2rem, 1rem + 0.75vw, 1.5rem);
  --space-8: clamp(1.5rem, 1.25rem + 1vw, 2rem);
  --space-10: clamp(2rem, 1.5rem + 1.5vw, 2.5rem);
  --space-12: clamp(2.5rem, 2rem + 1.5vw, 3rem);

  /* Border Radius */
  --radius-sm: 0.25rem;
  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  --radius-xl: 1rem;
  --radius-2xl: 1.5rem;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.3);
  --shadow-glow: 0 0 20px rgba(74, 158, 255, 0.15);

  /* Transitions */
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;

  /* Safe areas for notched phones */
  --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);

  /* Touch target minimum */
  --touch-target: 44px;
}

/* Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.5;
  color: var(--color-text);
  background-color: var(--color-bg);
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  overflow-x: hidden;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
  padding-left: var(--safe-area-left);
  padding-right: var(--safe-area-right);
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.2;
  word-wrap: break-word;
}

h1 { font-size: var(--font-size-3xl); }
h2 { font-size: var(--font-size-2xl); }
h3 { font-size: var(--font-size-xl); }

p {
  color: var(--color-text-muted);
  word-wrap: break-word;
}

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-primary-hover);
}

/* Improve touch targets */
a, button, input, select, textarea {
  touch-action: manipulation;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3) var(--space-6);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  font-weight: 500;
  line-height: 1;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  min-height: var(--touch-target);
  min-width: var(--touch-target);
  user-select: none;
  -webkit-user-select: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--color-primary-hover);
  box-shadow: var(--shadow-glow);
}

.btn-primary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-secondary {
  background-color: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: var(--color-surface-elevated);
  border-color: var(--color-primary);
}

.btn-secondary:active:not(:disabled) {
  transform: scale(0.98);
}

.btn-success {
  background-color: var(--color-success);
  color: white;
}

.btn-error {
  background-color: var(--color-error);
  color: white;
}

.btn-sm {
  padding: var(--space-2) var(--space-4);
  font-size: var(--font-size-sm);
  min-height: 36px;
}

.btn-lg {
  padding: var(--space-4) var(--space-8);
  font-size: var(--font-size-lg);
}

/* Forms */
.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--color-text);
}

.form-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  color: var(--color-text);
  background-color: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  min-height: var(--touch-target);
}

.form-input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(74, 158, 255, 0.1);
}

.form-input::placeholder {
  color: var(--color-text-muted);
}

/* Cards */
.card {
  background-color: var(--color-surface);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
}

/* Utility Classes */
.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-error { color: var(--color-error); }

.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }

.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.hidden { display: none !important; }

/* Flex utilities */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-4 { gap: var(--space-4); }

/* Animations */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
  animation: shake 0.5s ease-in-out;
}

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

.fade-in {
  animation: fadeIn 0.3s ease-out;
}

/* Loading Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-surface);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: calc(var(--space-6) + var(--safe-area-bottom));
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-3) var(--space-6);
  background-color: var(--color-surface-elevated);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  animation: fadeIn 0.3s ease-out;
  max-width: calc(100vw - var(--space-8));
}

.toast-success {
  border-left: 3px solid var(--color-success);
}

.toast-error {
  border-left: 3px solid var(--color-error);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: var(--space-4);
  padding-top: calc(var(--space-4) + var(--safe-area-top));
  padding-bottom: calc(var(--space-4) + var(--safe-area-bottom));
}

.modal {
  background-color: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  max-width: 400px;
  width: 100%;
  max-height: calc(100vh - var(--space-8));
  max-height: calc(100dvh - var(--space-8));
  overflow-y: auto;
  animation: fadeIn 0.3s ease-out;
}

.modal-title {
  margin-bottom: var(--space-6);
}

/* Responsive Container */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

/* Landscape orientation adjustments */
@media (orientation: landscape) and (max-height: 500px) {
  :root {
    --space-4: 0.75rem;
    --space-6: 1rem;
    --space-8: 1.25rem;
  }
}

/* Small phones */
@media (max-width: 360px) {
  :root {
    --font-size-3xl: 1.5rem;
    --font-size-2xl: 1.25rem;
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html {
    scroll-behavior: auto;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  :root {
    --color-border: #4a4a6a;
    --color-text-muted: #b0b8c8;
  }
}

/* Dark mode is default, but support light mode preference */
@media (prefers-color-scheme: light) {
  /* Keep dark mode - it's our brand */
}

/* Print styles */
@media print {
  body {
    background-color: white;
    color: black;
  }

  .btn, .modal-overlay, .toast {
    display: none;
  }
}
