/**
 * LocalMarket Header & Footer - Theme override for Misago forum
 * Extracted from LocalMarket design system
 */

/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
  /* Spacing Scale */
  --spacing-xs: 0.125rem;
  --spacing-sm: 0.25rem;
  --spacing-base: 0.5rem;
  --spacing-md: 0.5rem;
  --spacing-lg: 0.75rem;
  --spacing-xl: 1rem;
  --spacing-2xl: 0;
  --spacing-3xl: 0;
  --spacing-4xl: 0;

  /* Component Sizes */
  --_padding: 10px;
  --header-height: 72px;
  --header-height-mobile: 3rem;
  --nav-height: 60px;
  --logo-size-desktop: 56px;
  --logo-size-mobile: 40px;
  --profile-image-size: 44px;
  --icon-size-sm: 20px;
  --icon-size-md: 24px;

  /* Breakpoints */
  --breakpoint-sm: 600px;
  --breakpoint-md: 768px;
  --breakpoint-lg: 1024px;
  --breakpoint-xl: 1600px;

  /* Z-Index */
  --z-dropdown: 1000;
  --z-sticky: 1001;
  --z-fixed: 1002;
  --z-modal: 1003;
  --z-bottom-nav: 9999;

  /* Border Radius */
  --radius-sm: 2px;
  --radius-md: 6px;
  --radius-lg: 8px;
  --radius-round-small: 2px;

  /* Shadows */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-nav: 0 -2px 8px rgba(0, 0, 0, 0.3);

  /* Transitions */
  --transition-fast: 0.2s ease;
  --transition-base: 0.3s ease;
  --transition-slow: 0.3s ease-in-out;

  /* LocalMarket light theme (forum) */
  --background: #F5F0E8;
  --on-surface: #000000;
  --primary: #4a7c59;
  --primary-container: #c8e6c9;
  --on-primary-container: #1a3d24;
  --surface-container: #f5f0e8;
  --surface-container-high: #e8e2d8;
  --outline-variant: rgba(0, 0, 0, 0.12);
  --font-weight-semibold: 600;
  --font-size-2xl: 1.0625rem;
  --font-size-nav-links: 1.25rem;
  --wordmark-filter: none;

  /* Background gradient palettes */
  --wheat: #E7CFA9;
  --champagne-mist: #F0DEC1;
  --champagne-mist-2: #F3E4C8;
  --pearl-beige: #EFE2C4;
  --wheat-2: #E9D0A9;
  /* Dark theme - Night-starry-sky2 */
  --vintage-grape: #262530;
  --charcoal-blue: #282930;
  --space-indigo: #181920;
  --space-indigo-2: #1e1f2a;
  --space-indigo-3: #14151c;
}

/* ============================================
   BODY BACKGROUND
   ============================================ */
body {
  background-color: var(--champagne-mist);
  background-image: linear-gradient(to right, var(--wheat) 0%, var(--wheat-2) 3%, var(--wheat) 6%, var(--pearl-beige) 10%, var(--champagne-mist-2) 50%, var(--pearl-beige) 90%, var(--wheat) 94%, var(--wheat-2) 97%, var(--wheat) 100%);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: #1c1b1e;
  transition: background-color var(--transition-base), background-image var(--transition-base), color var(--transition-base);
}

body.dark {
  background-color: var(--space-indigo-3);
  background-image: linear-gradient(to bottom, var(--space-indigo-3) 0%, var(--space-indigo-2) 25%, var(--space-indigo) 50%, var(--charcoal-blue) 75%, var(--vintage-grape) 100%);
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  color: #fffff1;
  transition: background-color var(--transition-base), background-image var(--transition-base), color var(--transition-base);
}

/* ============================================
   HEADER COMPONENT
   ============================================ */
header.top-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-dropdown);
  overflow: visible;
  height: var(--header-height);
  padding: var(--spacing-md) var(--spacing-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--background);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-slow);
  pointer-events: none;
}

header.top-header > * {
  pointer-events: auto;
}

header.top-header.header-hidden {
  transform: translateY(-100%);
}

.header-back-slot {
  flex-shrink: 0;
  width: 48px;
  min-width: 48px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

/* Back button - hidden on desktop, shown on mobile */
.header-back-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--on-surface);
  padding: 0;
}

.header-back-btn .material-icon {
  font-size: 24px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.header-wordmark {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
}

.wordmark-img {
  height: 40px;
  filter: var(--wordmark-filter);
}

/* Standard "+" add button */
.btn-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  border: 2px solid var(--outline-variant) !important;
  background-color: transparent !important;
  color: inherit;
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.btn-add:hover,
.btn-add:focus {
  background-color: var(--surface-container-high) !important;
}

.btn-add .material-icon {
  font-size: var(--icon-size-md);
}

.site-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--logo-size-desktop);
  height: var(--logo-size-desktop);
  cursor: pointer;
}

.site-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.header-nav {
  display: none;
  align-items: center;
  gap: var(--spacing-xl);
  margin: 0 auto;
}

.header-nav a {
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
  text-decoration: none;
  color: var(--on-surface);
  font-weight: var(--font-weight-semibold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-size: var(--font-size-nav-links);
  transition: color var(--transition-fast);
}

.header-nav a:hover,
.header-nav a:focus {
  color: var(--primary);
}

.header-nav a.active {
  color: var(--primary);
}

.header-nav .material-icon {
  font-size: var(--icon-size-sm);
}

.header-right {
  display: flex;
  align-items: center;
  gap: var(--spacing-lg);
  margin-left: auto;
}

.circle.transparent {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 40px;
  min-height: 40px;
  color: var(--on-surface);
  text-decoration: none;
  border: none;
  background: transparent;
  border-radius: 50%;
  transition: color var(--transition-fast), background-color var(--transition-fast);
}

.circle.transparent:hover,
.circle.transparent:focus {
  background-color: var(--surface-container-high);
}

.margin-left-tiny {
  margin-left: var(--spacing-xs);
}

/* Message icon - transparent with outline, flipped color scheme */
.header-icon-messages {
  color: var(--primary);
}

.header-icon-messages:hover,
.header-icon-messages:focus {
  color: var(--on-primary-container);
}

.header-profile {
  display: none;
  align-items: center;
  justify-content: center;
  width: var(--profile-image-size);
  height: var(--profile-image-size);
  min-width: var(--profile-image-size);
  min-height: var(--profile-image-size);
  border-radius: var(--radius-lg);
  overflow: hidden;
  text-decoration: none;
}

.header-profile img,
.header-profile .avatar-initial {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.header-profile .avatar-initial {
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--surface-container-high);
  color: var(--on-surface);
  font-weight: bold;
}

.header-profile-wrapper {
  position: relative;
}

/* Global menu (Create dropdown) */
#global-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: var(--spacing-sm);
  padding: var(--spacing-sm);
  min-width: 200px;
  max-width: 280px;
  list-style: none;
  background-color: var(--surface-container);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: 10010;
  display: none;
  overflow: visible;
}

#global-menu[aria-expanded="true"] {
  display: block;
}

#global-menu li {
  list-style: none;
  margin: 0;
}

#global-menu a {
  display: flex;
  align-items: center;
  gap: var(--spacing-md);
  padding: 12px 16px;
  text-decoration: none;
  color: var(--on-surface);
  transition: background-color var(--transition-fast);
  border-radius: var(--radius-sm);
}

#global-menu a:hover {
  background-color: var(--surface-container-high);
}

#global-menu .material-icon {
  font-size: 20px;
  flex-shrink: 0;
}

#global-menu .middle-align {
  align-items: center;
}

#global-menu .no-space {
  gap: 0;
}

#global-menu .padding-vertical-small {
  padding-top: var(--spacing-sm);
  padding-bottom: var(--spacing-sm);
}

#global-menu .small-text {
  font-size: 0.875rem;
}

/* ============================================
   BOTTOM NAV (MOBILE) - body-level for fixed positioning
   ============================================ */
nav.bottom-nav,
nav.bottom-nav-fixed {
  position: fixed !important;
  top: auto !important;
  bottom: 0 !important;
  left: 0 !important;
  right: 0 !important;
  width: 100%;
  max-width: 100vw;
  box-sizing: border-box;
  overflow-x: hidden;
  z-index: var(--z-bottom-nav);
  height: var(--nav-height);
  background-color: var(--surface-container);
  border-top: 1px solid var(--outline-variant);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 2px;
  padding: 0 2px;
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: var(--shadow-nav);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}

nav.bottom-nav .nav-item {
  flex: 1 1 0;
  min-width: 0;
  padding: 6px 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--on-surface);
  transition: background-color var(--transition-fast);
  border-radius: var(--radius-md);
  margin: 0 1px;
  min-height: 48px;
  box-sizing: border-box;
}

nav.bottom-nav .nav-item:hover {
  background-color: var(--surface-container-high);
}

nav.bottom-nav .nav-item.active {
  background-color: var(--primary-container);
  color: var(--on-primary-container);
}

nav.bottom-nav .nav-item .material-icon {
  font-size: 22px;
  flex-shrink: 0;
}

nav.bottom-nav .nav-item-profile img,
nav.bottom-nav .nav-item img.circle {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  object-fit: cover;
  border-radius: 50%;
}

nav.bottom-nav .nav-item .avatar-initial {
  width: 28px;
  height: 28px;
  min-width: 28px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--surface-container-high);
  border-radius: 50%;
  font-weight: bold;
}

/* Profile placeholder - compact circle on mobile */
nav.bottom-nav .nav-item-profile-placeholder .avatar-initial,
nav.bottom-nav .nav-item-profile-placeholder img {
  width: 28px !important;
  height: 28px !important;
  min-width: 28px !important;
  min-height: 28px !important;
  flex-shrink: 0;
}

/* Very narrow screens - reduce icon size to fit */
@media (max-width: 360px) {
  nav.bottom-nav .nav-item .material-icon {
    font-size: 20px !important;
  }

  nav.bottom-nav .nav-item-profile img,
  nav.bottom-nav .nav-item img.circle,
  nav.bottom-nav .nav-item .avatar-initial,
  nav.bottom-nav .nav-item-profile-placeholder .avatar-initial,
  nav.bottom-nav .nav-item-profile-placeholder img {
    width: 24px !important;
    height: 24px !important;
    min-width: 24px !important;
    min-height: 24px !important;
  }
}

/* ============================================
   FOOTER - hidden on desktop (nav in header)
   ============================================ */
footer.misago-footer.top-header-footer {
  background-color: var(--background);
  border-top: 1px solid var(--outline-variant);
  padding: var(--spacing-xl) 0;
}

footer.misago-footer .footer-nav a {
  color: var(--on-surface);
  text-decoration: none;
}

footer.misago-footer .footer-nav a:hover {
  color: var(--primary);
}

/* Hide footer on desktop - all nav is in header */
@media (min-width: 768px) {
  footer.misago-footer {
    display: none !important;
  }
}

/* ============================================
   RESPONSIVE - MOBILE (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {
  /* Hide footer on mobile - bottom nav handles navigation */
  footer.misago-footer.top-header-footer {
    display: none !important;
  }

  /* Root overflow - prevent horizontal scroll (important to override any conflicting rules) */
  html,
  body {
    overflow-x: hidden !important;
    max-width: 100vw;
    width: 100%;
  }

  /* Container - constrain width and clip overflow */
  #misago-container {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box;
    width: 100%;
  }

  .header-wordmark {
    display: none;
  }

  .site-logo {
    display: none;
  }

  nav.top.desktop-nav {
    display: none;
  }

  /* Header - constrain width and allow flex children to shrink */
  header.top-header {
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box;
    height: var(--header-height-mobile);
    min-height: 3rem;
    padding: var(--spacing-sm) 1.25rem;
    overflow: hidden;
  }

  header.top-header .header-left,
  header.top-header .header-right {
    min-width: 0;
  }

  .header-back-slot {
    width: 32px;
    min-width: 32px;
  }

  .header-back-btn {
    display: flex;
  }

  .header-right {
    gap: 6px;
    flex-shrink: 0;
    min-width: 0;
    margin-left: auto;
    margin-right: 0.5rem;
  }

  .header-right .circle.transparent,
  .header-right .btn-add {
    width: 34px !important;
    height: 34px !important;
    min-width: 34px !important;
    min-height: 34px !important;
    flex-shrink: 0;
  }

  /* Smaller message icon on mobile */
  .header-icon-messages .material-icon {
    font-size: 22px !important;
  }

  /* Ensure create button and dropdown visible on mobile */
  .header-create-wrapper {
    display: flex !important;
    align-items: center;
    position: relative;
  }

  .header-create-wrapper .btn-add .material-icon {
    font-size: 22px !important;
  }

  /* Smaller profile on mobile */
  .header-right .header-profile,
  .header-right .header-profile img,
  .header-right .header-profile .avatar-initial {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
  }

  /* Bottom nav - reinforce fixed positioning (stays above page content) */
  nav.bottom-nav,
  nav.bottom-nav-fixed {
    position: fixed !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box;
    z-index: var(--z-bottom-nav);
  }
}

/* ============================================
   RESPONSIVE - DESKTOP (min-width: 768px)
   ============================================ */
@media (min-width: 768px) {
  .header-nav {
    display: flex;
  }

  .header-nav a {
    font-size: 1.5rem;
  }

  .header-profile {
    display: flex;
  }

  .header-icon-messages .material-icon {
    font-size: 28px !important;
  }

  nav.bottom-nav {
    display: none;
  }

  /* Reserve space for fixed header */
  #misago-container {
    padding-top: var(--header-height);
  }
}

/* Reserve space for mobile bottom nav */
@media (max-width: 768px) {
  #misago-container {
    padding-top: var(--header-height-mobile);
    padding-bottom: var(--nav-height);
  }
}
