@tailwind base;
@tailwind components;
@tailwind utilities;

/* Light Theme (Default) */
:root {
  --bg-color: #f9fafb;
  --text-color: #111827;
  --primary-color: #3b82f6;
  --secondary-color: #6b7280;
  --navbar-height: 8rem;
}

html {
  color-scheme: light;
}

/* Dark Theme */
html.dark {
  --bg-color: #111827;
  --text-color: #f9fafb;
  --primary-color: #60a5fa;
  --secondary-color: #9ca3af;
  color-scheme: dark;
}

/* Apply Variables */
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg-color);
  color: var(--text-color);
}

main {
  padding-top: 0 !important;
}

button:not(.theme-toggle):not(#menu-toggle):not(.mobile-menu-button):not(#admin-menu-button),
.btn {
  background-color: var(--primary-color);
  color: white;
  padding: 10px 20px;
  border-radius: 6px;
  transition: background 0.3s ease;
}

button:not(.theme-toggle):not(#menu-toggle):not(.mobile-menu-button):not(#admin-menu-button):hover,
.btn:hover {
  background-color: var(--secondary-color);
}

/* Ensure these fallbacks are present */
.hover\:bg-blue-600:hover {
  background-color: #2563eb !important; /* Tailwind's blue-600 */
}

.dark .dark\:bg-gray-900 {
  background-color: #111827 !important; /* Tailwind's gray-900 */
}

.dark .dark\:bg-gray-800 {
  background-color: #1f2937 !important; /* Tailwind's gray-800 */
}

.dark .dark\:bg-gray-700 {
  background-color: #374151 !important; /* Tailwind's gray-700 */
}

.dark .dark\:text-white {
  color: #ffffff !important;
}

.dark .dark\:text-gray-300 {
  color: #d1d5db !important; /* Tailwind's gray-300 */
}

.dark .dark\:text-primary-dark {
  color: #60a5fa !important;
}

.dark .dark\:bg-primary-dark {
  background-color: #60a5fa !important;
}

.dark .dark\:hover\:bg-blue-800:hover {
  background-color: #1e40af !important; /* Tailwind's blue-800 */
}

a.bg-primary {
  background-color: #003366 !important; /* Specific to <a> tags with bg-primary */
}

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

.animate-fade-in {
  animation: fadeIn 0.8s ease-out forwards;
}

@keyframes scroll {
  0% { transform: translateX(0); }
  100% { transform: translateX(-50%); }
}

.animate-scroll {
  animation: scroll 20s linear infinite;
  width: 200%;
}

.animate-scroll > * {
  flex-shrink: 0;
}

/* Desktop nav + mobile hamburger visibility (do not rely on md: utilities alone) */
.navbar-desktop-menu {
  display: none;
}

@media (min-width: 768px) {
  .navbar-desktop-menu {
    display: flex !important;
  }

  #mobile-menu {
    display: none !important;
  }
}

.mobile-menu-button {
  display: none;
  flex: 0 0 auto;
  position: relative;
  z-index: 20;
  pointer-events: auto;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 2.5rem;
  min-width: 2.5rem;
  min-height: 2.5rem;
  padding: 0.5rem;
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  color: #111827;
}

@media (max-width: 767px) {
  .mobile-menu-button {
    display: inline-flex;
  }
}

.mobile-menu-button__bar {
  display: block;
  width: 1.5rem;
  height: 2px;
  background-color: #111827;
}

.mobile-menu-button__bar--middle {
  margin-top: 0.375rem;
  margin-bottom: 0.375rem;
}

html.dark .mobile-menu-button,
body.dark .mobile-menu-button {
  color: #ffffff;
}

html.dark .mobile-menu-button__bar,
body.dark .mobile-menu-button__bar {
  background-color: #ffffff;
}

/* Animate hamburger into X */
#menu-toggle.open .mobile-menu-button__bar:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

#menu-toggle.open .mobile-menu-button__bar:nth-child(2) {
  opacity: 0;
}

#menu-toggle.open .mobile-menu-button__bar:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}


#navbar {
  @apply transition-all duration-300 ease-in-out;
}

/* Navbar right-side controls: theme toggle + hamburger */
.navbar-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
}

.navbar-theme-toggle,
.mobile-menu-theme-toggle {
  flex: 0 0 auto;
}

.mobile-menu-theme-toggle {
  display: none;
}

@media (max-width: 399px) {
  .navbar-theme-toggle {
    display: none;
  }

  .mobile-menu-theme-toggle {
    display: block;
  }
}

@media (min-width: 400px) {
  .mobile-menu-theme-toggle {
    display: none;
  }
}

.mt-navbar {
  margin-top: 8rem; /* equal to your navbar height */
}

#navbar.scrolled {
  @apply py-2 shadow-md bg-gray-950 bg-opacity-95;
}

#navbar.scrolled a {
  @apply text-sm;
}

.animate-scroll:hover {
  animation-play-state: paused;
}

/* Theme toggle pill switch (shared partial: shared/_theme_toggle) */
button.theme-toggle,
.theme-toggle {
  --theme-toggle-width: 132px;
  --theme-toggle-height: 38px;
  --theme-toggle-knob: 32px;
  --theme-toggle-inset: 3px;

  box-sizing: border-box;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: var(--theme-toggle-width);
  height: var(--theme-toggle-height);
  min-width: var(--theme-toggle-width);
  max-width: var(--theme-toggle-width);
  min-height: var(--theme-toggle-height);
  max-height: var(--theme-toggle-height);
  padding: 0 !important;
  margin: 0;
  border: none !important;
  border-radius: 9999px !important;
  background: transparent !important;
  color: inherit !important;
  line-height: 1;
  font: inherit;
  vertical-align: middle;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  -webkit-tap-highlight-color: transparent;
  box-shadow: none !important;
}

button.theme-toggle:hover,
.theme-toggle:hover,
button.theme-toggle:focus,
.theme-toggle:focus {
  background: transparent !important;
  color: inherit !important;
}

.theme-toggle:focus {
  outline: none;
}

.theme-toggle:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

.theme-toggle__track {
  position: relative;
  box-sizing: border-box;
  display: block;
  flex: 0 0 auto;
  width: 100%;
  height: 100%;
  border-radius: 9999px;
  border: 1px solid #d1d5db;
  background: linear-gradient(180deg, #ffffff 0%, #f3f4f6 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.9), 0 1px 2px rgba(15, 23, 42, 0.08);
  overflow: hidden;
  transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.theme-toggle[aria-checked="true"] .theme-toggle__track {
  border-color: #334155;
  background: linear-gradient(180deg, #334155 0%, #1e293b 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), 0 1px 3px rgba(0, 0, 0, 0.35);
}

.theme-toggle__label {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: none;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0;
  font-family: inherit;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.05em;
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  user-select: none;
  pointer-events: none;
}

.theme-toggle__label--light {
  display: flex;
  padding-left: calc(var(--theme-toggle-knob) + var(--theme-toggle-inset) + 2px);
  padding-right: 6px;
  color: #374151;
}

.theme-toggle__label--dark {
  padding-left: 6px;
  padding-right: calc(var(--theme-toggle-knob) + var(--theme-toggle-inset) + 2px);
  color: #e2e8f0;
}

.theme-toggle[aria-checked="true"] .theme-toggle__label--light {
  display: none;
}

.theme-toggle[aria-checked="true"] .theme-toggle__label--dark {
  display: flex;
}

.theme-toggle__knob {
  position: absolute;
  top: var(--theme-toggle-inset);
  left: var(--theme-toggle-inset);
  z-index: 2;
  width: var(--theme-toggle-knob);
  height: var(--theme-toggle-knob);
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  color: #f59e0b;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
  transition: left 0.25s ease, background 0.25s ease, color 0.25s ease, box-shadow 0.25s ease;
}

.theme-toggle[aria-checked="true"] .theme-toggle__knob {
  left: calc(100% - var(--theme-toggle-knob) - var(--theme-toggle-inset));
  background: #475569;
  color: #cbd5e1;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}

.theme-toggle__icon {
  display: block;
  font-size: 13px;
  line-height: 1;
}

.theme-toggle__icon--moon {
  display: none;
}

.theme-toggle[aria-checked="true"] .theme-toggle__icon--sun {
  display: none;
}

.theme-toggle[aria-checked="true"] .theme-toggle__icon--moon {
  display: block;
}

.theme-toggle .sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  button.theme-toggle,
  .theme-toggle {
    --theme-toggle-width: 112px;
    --theme-toggle-height: 32px;
    --theme-toggle-knob: 26px;
    --theme-toggle-inset: 3px;
  }

  .theme-toggle__label {
    font-size: 8px;
    letter-spacing: 0.04em;
  }

  .theme-toggle__icon {
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .theme-toggle__track,
  .theme-toggle__knob,
  .theme-toggle__label {
    transition: none;
  }
}