/* Base Styles & Typography */
:root {
  /* Typography */
  --font-body: 'DM Sans', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-display: 'Newsreader', Georgia, serif;

  /* Legacy Color Variables - Now using theme.css variables */
  --dark-blue: var(--text-primary);
  --neutral-gray: var(--text-secondary);
  --light-gray: var(--text-tertiary);
  --background-color: var(--bg-primary);
  --white: var(--bg-secondary);
  
  /* Spacing */
  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 16px;
  --spacing-lg: 24px;
  --spacing-xl: 32px;
  
  /* Border Radius */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
}

html {
  background-color: var(--bg-primary);
  color-scheme: dark;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  background-image: none;
  background-attachment: fixed;
  margin: 0;
  padding: 0;
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text-secondary);
  line-height: 1.6;
}

h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.75em;
  letter-spacing: -0.01em;
}

h1 {
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 2.5vw, 2rem);
  font-weight: 500;
  letter-spacing: -0.025em;
}

h2 {
  font-size: clamp(1.25rem, 2vw, 1.5rem);
  letter-spacing: -0.015em;
}

h3 { font-size: 1.25rem; }

/* Main area (sits beside fixed sidebar) */
.main-area {
  margin-left: 180px;
  display: flex;
  height: 100vh;
  width: calc(100% - 180px);
  box-sizing: border-box;
  overflow: hidden;
  position: relative;
}

/* Content Layout */
.content {
  flex: 1;
  min-width: 0;
  padding: var(--spacing-lg) clamp(24px, 4vw, 60px);
  background-color: var(--bg-primary);
  height: 100%;
  box-sizing: border-box;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

/* All direct children of .content fill the centered column */
.content > * {
  width: 100%;
  max-width: 1400px;
  margin-left: auto;
  margin-right: auto;
}

/* Override max-width for fixed/absolute positioned children */
.content > #loading-animation {
  max-width: none;
}

/* Messages are position:fixed toasts — reset width from .content > * */
.content > .messages {
  width: auto;
  max-width: 400px;
}

/* Loading Animation */
#loading-animation {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--loading-overlay);
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

#loading-animation ul {
  position: static;
  transform: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#loading-animation ul li {
  list-style: none;
  width: 20px;
  height: 20px;
  margin: 0 6px;
  background: var(--bg-secondary);
  border-radius: 50%;
  animation: grow 1.6s ease-in-out infinite;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
}

@keyframes grow {
  0%, 40%, 100% {
    transform: scale(0.2);
  }
  20% {
    transform: scale(1);
  }
}

#loading-animation ul li:nth-child(1) { background: var(--accent-hover); box-shadow: 0 0 20px var(--accent-hover); animation-delay: -1.4s; }
#loading-animation ul li:nth-child(2) { background: var(--accent); box-shadow: 0 0 20px var(--accent); animation-delay: -1.2s; }
#loading-animation ul li:nth-child(3) { background: var(--accent); box-shadow: 0 0 20px var(--accent); animation-delay: -1s; opacity: 0.85; }
#loading-animation ul li:nth-child(4) { background: var(--accent); box-shadow: 0 0 20px var(--accent); animation-delay: -0.8s; opacity: 0.7; }
#loading-animation ul li:nth-child(5) { background: var(--accent); box-shadow: 0 0 20px var(--accent); animation-delay: -0.6s; opacity: 0.55; }
#loading-animation ul li:nth-child(6) { background: var(--accent); box-shadow: 0 0 20px var(--accent); animation-delay: -0.4s; opacity: 0.4; }
#loading-animation ul li:nth-child(7) { background: var(--accent); box-shadow: 0 0 20px var(--accent); animation-delay: -0.2s; opacity: 0.6; }

/* Utility Classes */
.grid-container {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  grid-gap: clamp(12px, 2vw, 24px);
  padding: clamp(12px, 2vw, 24px) 0;
  width: 100%;
  box-sizing: border-box;
}

.grid-item {
  background-color: var(--card-bg);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--card-border);
  padding: clamp(12px, 2vw, 24px);
  transition: box-shadow 0.2s ease, background-color 0.3s ease;
  min-height: 280px;
  position: relative;
}

.grid-item:hover {
  box-shadow: var(--shadow-lg);
}

/* Common Button Styles */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: var(--spacing-sm);
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  box-sizing: border-box;
}

.btn-primary {
  background-color: var(--accent);
  color: var(--accent-text);
  box-shadow: 0 2px 4px var(--accent-shadow);
}

.btn-primary:hover {
  background-color: var(--accent-hover);
  box-shadow: 0 4px 6px var(--accent-shadow-hover);
  transform: translateY(-1px);
}

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

.btn-secondary:hover {
  background-color: var(--bg-hover);
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

/* Messages styling */
.messages {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  max-width: 400px;
}

.alert {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  animation: slideInRight 0.3s ease-out;
}

.alert-success {
  background-color: var(--success-bg);
  color: var(--success-text);
  border-left: 4px solid var(--success-color);
}

.alert-error {
  background-color: var(--error-bg);
  color: var(--error-text);
  border-left: 4px solid var(--error-color);
}

.alert-info {
  background-color: var(--info-bg);
  color: var(--info-text);
  border-left: 4px solid var(--info-color);
}

.alert .close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: inherit;
  opacity: 0.7;
  transition: opacity 0.2s ease;
}

.alert .close:hover {
  opacity: 1;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* View Transitions (Chrome/Edge — gracefully ignored elsewhere) */
@view-transition {
  navigation: auto;
}

::view-transition-old(root) {
  background: var(--bg-primary);
  animation: 0.2s ease-out both fade-out;
}

::view-transition-new(root) {
  background: var(--bg-primary);
  animation: 0.3s ease-out 0.1s both fade-in;
}

@keyframes fade-out {
  to { opacity: 0; }
}

@keyframes fade-in {
  from { opacity: 0; }
}

/* Focus states — visible ring for keyboard users, hidden for mouse */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

:focus:not(:focus-visible) {
  outline: none;
}

/* Links */
a {
  color: var(--primary-blue);
  transition: color 0.2s ease;
}

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

/* Responsive Design */
@media (max-width: 1024px) {
  .content {
    padding: var(--spacing-lg) var(--spacing-md);
  }
}

@media (max-width: 768px) {
  .main-area {
    margin-left: 0;
    width: 100%;
    height: auto;
    min-height: 100vh;
    flex-direction: column;
  }

  .content {
    width: 100%;
    padding: 56px var(--spacing-md) var(--spacing-lg);
    min-height: auto;
    overflow-y: visible;
  }

  .grid-container {
    grid-template-columns: 1fr;
  }

  /* Ensure touch targets are at least 44px */
  .btn,
  button,
  a.btn,
  .profile-btn,
  .tile-cta-btn {
    min-height: 44px;
    min-width: 44px;
  }

  h1 {
    font-size: 1.5rem;
  }
}

/* Site footer (privacy / cookie settings) */
.site-footer {
  margin-top: 48px;
  padding: 16px 0 12px;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: center;
}

.site-footer a {
  color: var(--text-muted);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--text-secondary);
  text-decoration: underline;
}