/* common.css - base styles + shared app chrome (sidebar, header, auth widget).
   Loaded by every page. */

/* Design tokens (CSS variables) live in their own file. */
@import "tokens.css";

/* ==========================================
   1. BASE STYLES & RESET
   ========================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

@font-face {
  font-family: "Lao Sangam MN";
  src: url("../assets/fonts/Lao Sangam MN.ttf") format("truetype");
  font-weight: normal;
  font-style: normal;
}

body {
  font-family: "Lao Sangam MN", sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

:focus-visible {
  outline: 2px solid rgba(var(--pink), 0.9);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  /* !important is required here: this accessibility reset must override every
     animation/transition declared elsewhere, regardless of selector specificity. */
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================
   2. ANIMATIONS & SCROLLBARS
   ========================================== */
@keyframes shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

::-webkit-scrollbar {
  width: 10px;
}
::-webkit-scrollbar-track {
  background: rgba(var(--ink), 0.8);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.3);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.5);
}

/* ==========================================
   3. TOAST NOTIFICATIONS
   ========================================== */
.toastify.mk-toast {
  width: -moz-fit-content;
  width: fit-content;
  white-space: nowrap;
  max-width: 90vw;
  line-height: 1.35;
}

/* ==========================================
   4. APP SHELL LAYOUT
   ========================================== */
.app-body {
  background-image: url("../assets/images/movie-knight-gradient-bg.svg");
  background-size: cover;
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  /* NOTE: no `overflow-x: hidden` here. Clipping the page horizontally hid
     content when the user zoomed in (notably on the wheel) with no way to
     scroll across to it. Spin/confetti overflow is contained at the component
     level instead (.wheel-visual-container clips its own canvas sweep). */
}

.app-container {
  --rail-width: clamp(200px, 14vw, 250px);
  display: flex;
  min-height: 100vh;
  align-items: stretch;
}

/* Feature pages (wheel / picker) keep their focused, standalone look on desktop:
   no left rail there. The sidebar nav is reached on mobile via the hamburger,
   exactly like the other pages (the responsive drawer rules below still apply). */
@media (min-width: 1025px) {
  .feature-page .sidebar,
  .feature-page .user-rail {
    display: none;
  }
}

/* ==========================================
   5. SIDEBAR NAVIGATION
   ========================================== */
.sidebar {
  width: var(--rail-width);
  display: flex;
  flex-direction: column;
  position: sticky;
  overflow-y: auto;
  flex-shrink: 0;
  top: 0;
  height: 100vh;
  /* 1. Hide scrollbar for Firefox */
  scrollbar-width: none;
  /* 2. Hide scrollbar for IE and Edge */
  -ms-overflow-style: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

.sidebar-logo .nav-logo {
  padding: 30px 20px;
  min-width: 137px;
  min-height: 182.66px;
  margin-bottom: 10px;
}

.nav-logo {
  transition: transform var(--t-slow) var(--ease-pop);
  transform-origin: center;
  display: block;
}

.main-nav {
  display: flex;
  flex-direction: column;
  gap: 15px;
  flex-grow: 1;
}

/* ==========================================
   6. SETTINGS MENU
   ========================================== */
.settings-container {
  display: flex;
  flex-direction: column;
  border-radius: 12px;
  transition: background-color 0.3s ease;
  width: fit-content;
}

.settings-container.open {
  background-color: var(--overlay-weak);
}

.settings-container.open .nav-link {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
  background-color: transparent;
}

#settingsToggleBtn {
  display: flex;
  align-items: center;
  gap: 18px;
}

.custom-gear {
  transition: transform 1s ease;
  transform-origin: 50% 50%;
  opacity: 0.7;
}

.settings-container.open .custom-gear {
  transform: rotate(360deg);
}

.settings-submenu a {
  color: var(--text-soft);
  text-decoration: none;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  transition:
    color 0.2s ease,
    transform var(--t-fast) var(--ease-snap);
}

.settings-submenu a:hover {
  color: var(--text);
  transform: translateX(3px);
}

.settings-arrow {
  margin-left: auto;
  width: 14px;
  height: 14px;
  display: inline-block;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;

  transition: transform 0.6s ease;
  opacity: 0.7;
  transform: rotate(-90deg);
}

.settings-container.open .settings-arrow {
  transform: rotate(0deg);
}

.settings-submenu {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition:
    max-height 0.8s ease-out,
    opacity 0.7s ease,
    padding 0.7s ease;
  display: flex;
  flex-direction: column;
  gap: 15px;
  padding-left: 50px;
}

.settings-container.open .settings-submenu {
  max-height: 200px;
  opacity: 1;
  padding-top: 5px;
  padding-bottom: 20px;
}
.about-link {
  margin-top: auto;
  margin-bottom: 110px;
}

.about-link img {
  opacity: 70%;
  padding-left: 18px;
}

.about-link span {
  padding-left: 10px;
}

/* --- NAV LINKS --- */
.nav-link {
  width: 194px;
  min-height: 50px;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 18px;
  background-color: rgba(var(--pink), 0.03);
  color: var(--text-dim);
  text-decoration: none;
  padding: 10px 15px;
  border-top-right-radius: 12px;
  border-bottom-right-radius: 12px;
  transition:
    background-color var(--t-base),
    color var(--t-base),
    transform var(--t-base) var(--ease-snap),
    box-shadow var(--t-base);
}

.nav-link img,
.nav-link .nav-logo {
  width: 26px;
  height: 26px;
  object-fit: contain;
  padding: 0;
}

.nav-link:hover img {
  transform: scale(1.12);
}

.nav-link:hover {
  background-color: var(--overlay);
  color: var(--text);
  transform: translateX(4px);
  box-shadow: inset 3px 0 0 0 rgba(var(--pink), 0.9);
}
.nav-link.active {
  background-color: var(--overlay);
  color: var(--text);
}

/* ==========================================
   7. MAIN CONTENT WRAPPER
   ========================================== */
.main-content {
  --content-width: 1640px;
  flex: 1;
  min-width: 0;
  padding: 30px 40px 100px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

/* ==========================================
   8. TOP HEADER & USER RAIL
   ========================================== */
.top-header {
  margin-top: 42px;
  width: 100%;
  max-width: var(--content-width);
  display: flex;
  align-items: flex-start;
  gap: 30px;
}

.user-rail {
  width: var(--rail-width);
  flex-shrink: 0;
  padding: 24px 0 0 0;
  justify-content: center;
  display: flex;
  position: sticky;
  top: 0;
  align-self: flex-start;
}

/* ==========================================
   9. HEADER AUTHENTICATION WIDGET
   ========================================== */
.header-login-btn {
  appearance: none;
  border: 0px;
  border-radius: 12px;
  min-width: 129.63px;
  min-height: 48.85px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(var(--pink-alt), 0.13);
  color: var(--text-muted);
  font-size: 25px;
  cursor: pointer;
  transition:
    background-color var(--t-slow),
    transform var(--t-fast) var(--ease-snap);
}
.header-login-btn p {
  margin: 0;
  padding: 0;
}

.header-login-btn:hover {
  background-color: rgba(var(--pink-alt), 0.3);
  cursor: pointer;
}

.header-login-btn:active {
  background: rgba(var(--pink-alt), 0.7);
  transform: scale(0.96); /* tactile press */
}

/* --- LOGGED-IN USER WIDGET + DROPDOWN (shared header) --- */
.user-profile-display {
  display: flex;
  align-items: center;
  gap: 15px;
  cursor: pointer;
  position: relative;
}

.user-welcome {
  display: flex;
  flex-direction: column;
  text-align: right;
  line-height: 1.2;
}

.welcome-text {
  color: var(--text-muted);
  font-size: 16px;
}

.username-text {
  color: var(--text);
  font-size: 16px;
}

.header-profile-btn {
  background: transparent;
  border: none;
  /* !important: beats the global :focus-visible rule (equal specificity) so the
     ring renders on .profile-pic instead of the button box. */
  outline: none !important;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
}

.profile-pic {
  width: 65px;
  height: 65px;
  border-radius: 50%;
  object-fit: cover;
  background-color: rgba(var(--pink), 0.13);
  transition:
    box-shadow var(--t-base) ease,
    background-color var(--t-base) ease,
    transform var(--t-base) var(--ease-pop);
}

.user-profile-display:hover .profile-pic {
  background-color: rgba(var(--pink), 0.25);
  box-shadow: 0 0 0 2px rgba(var(--pink), 0.8);
  transform: scale(1.05);
}

/* keyboard focus shows the same ring (the button kills its own outline) */
.header-profile-btn:focus-visible .profile-pic {
  box-shadow: 0 0 0 2px rgba(var(--pink), 0.8);
}

/* The Dropdown Menu Box */
.header-dropdown {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 150px;
  background-color: var(
    --surface-menu
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-10px);
  transition:
    opacity var(--t-base) ease,
    transform var(--t-base) var(--ease-snap);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

/* The class JS adds to show the menu */
.header-dropdown.show {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* Menu Links */
.header-dropdown a {
  padding: 10px 20px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 14px;
  transition:
    background-color 0.2s,
    color 0.2s;
}

.header-dropdown a:hover {
  background-color: var(--overlay-weak);
  color: var(--text);
}

/* !important: these win over the more specific `.header-dropdown a` /
   `.header-dropdown a:hover` rules (0,1,1 / 0,2,1) that would otherwise set the
   sign-out link's color and hover background. */
.danger-text {
  color: rgb(var(--danger)) !important;
}
.danger-text:hover {
  background-color: rgba(var(--danger), 0.1) !important;
}

/* ==========================================
   10. GLOBAL MODALS
   ========================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--t-base) ease,
    visibility var(--t-base);
}

.modal-overlay.show {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background-color: var(--surface-dropdown);
  border: 1px solid var(--overlay);
  border-radius: 16px;
  padding: 28px 32px;
  width: 360px;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  transform: translateY(12px) scale(0.97);
  transition: transform var(--t-base) var(--ease-pop);
}

.modal-overlay.show .modal-card {
  transform: translateY(0) scale(1);
}

.modal-title {
  font-size: 26px;
  font-weight: 300;
  letter-spacing: 1px;
  margin-bottom: 10px;
}

.modal-text {
  color: var(--text-soft);
  font-size: 16px;
  margin-bottom: 24px;
}

.modal-actions {
  display: flex;
  gap: 14px;
  justify-content: center;
}

.modal-btn {
  border: 0;
  border-radius: 10px;
  padding: 12px 22px;
  font-family: inherit;
  font-size: 16px;
  cursor: pointer;
  transition:
    background-color var(--t-base) ease,
    transform var(--t-fast) var(--ease-snap);
}

.modal-btn:active {
  transform: scale(0.96);
}

.modal-btn--ghost {
  background: var(--overlay);
  color: var(--text);
}

.modal-btn--ghost:hover {
  background: rgba(255, 255, 255, 0.18);
}

.modal-btn--danger {
  background: rgba(var(--danger), 0.85);
  color: #fff;
}

.modal-btn--danger:hover {
  background: rgb(var(--danger));
}

/* ==========================================
   11. MOBILE NAVIGATION TOPBAR
   ========================================== */
.mobile-topbar {
  display: none;
}
.mobile-nav-toggle {
  display: none;
}
.nav-backdrop {
  display: none;
}

/* ==========================================
   12. RESPONSIVE DESIGN (MEDIA QUERIES)
   ========================================== */
@media (max-width: 1024px) {
  /* The sidebar becomes a dropdown menu under the bar. */
  .app-container {
    flex-direction: column;
  }

  /* --- Top app bar --- */
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 1100;
    width: 100%;
    padding: 12px 16px;
    background: rgba(30, 16, 22, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    min-width: 0;
    margin-right: auto; /* keep the auth widget pinned right */
  }

  .mobile-brand-knight {
    height: 38px;
    width: auto;
    filter: brightness(0) invert(1);
  }

  .mobile-brand-text {
    height: 19px;
    width: auto;
    max-width: 52vw;
    object-fit: contain;
  }

  /* --- Hamburger --- */
  .mobile-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 46px;
    height: 46px;
    padding: 0;
    border: 0;
    border-radius: 12px;
    background: rgba(var(--pink), 0.13);
    cursor: pointer;
    transition:
      background-color var(--t-base) ease,
      transform var(--t-fast) var(--ease-snap);
  }

  .mobile-nav-toggle:hover {
    background: rgba(var(--pink), 0.25);
  }

  .mobile-nav-toggle:active {
    transform: scale(0.94);
  }

  .mobile-nav-toggle img {
    width: 22px;
    height: 22px;
  }

  /* --- Sidebar becomes a dropdown menu that opens under the bar --- */
  .sidebar-logo {
    display: none;
  }

  .sidebar {
    position: fixed;
    top: 64px;
    left: 12px;
    width: min(76vw, 270px);
    height: auto;
    max-height: calc(100dvh - 80px);
    overflow-y: auto;
    padding: 10px;
    background: rgba(42, 22, 30, 0.98);
    border: 1px solid var(--overlay);
    border-radius: 16px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.5);
    z-index: 1300;
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none;
    transition:
      opacity var(--t-base) ease,
      transform var(--t-base) var(--ease-snap);
  }

  body.nav-open .sidebar {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
  }

  .main-nav {
    gap: 6px;
  }

  .settings-container {
    width: 100%;
  }

  .nav-link {
    width: 100%;
    min-height: 50px;
    font-size: 20px;
    padding: 12px 16px;
    border-radius: 12px;
    gap: 14px;
  }

  .nav-link:hover {
    transform: none;
  }

  .nav-link.active {
    background: rgba(var(--pink), 0.15);
  }

  .nav-link img,
  .nav-link .nav-logo {
    width: 24px;
    height: 24px;
    object-fit: contain;
    padding: 0;
  }

  .about-link img {
    padding-left: 0;
  }

  .about-link span {
    padding-left: 0;
  }

  .about-link {
    margin-top: 14px;
    margin-bottom: 4px;
  }

  /* --- Backdrop: light dim that closes the menu on tap --- */
  .nav-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--t-base) ease;
    z-index: 1200;
  }

  body.nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .user-rail {
    display: none;
  }

  .main-content {
    padding: 16px 16px 64px;
    gap: 16px;
  }

  .top-header {
    margin-top: 0;
  }

  /* --- Auth widget once relocated into the top bar --- */
  .mobile-topbar .user-welcome {
    text-align: right;
  }

  .mobile-topbar .welcome-text {
    font-size: 13px;
  }

  .mobile-topbar .username-text {
    font-size: 14px;
  }

  .mobile-topbar .header-login-btn {
    font-size: 18px;
    min-width: 0;
    min-height: 42px;
    padding: 0 18px;
  }

  .mobile-topbar .profile-pic {
    width: 44px;
    height: 44px;
  }
}

/* Phones: tighten the bar and drop the greeting line to save room. */
@media (max-width: 560px) {
  .mobile-brand-knight {
    height: 32px;
  }

  .mobile-brand-text {
    height: 16px;
  }

  .mobile-topbar .user-welcome {
    display: none;
  }
  
  .mobile-topbar .profile-pic {
    width: 40px;
    height: 40px;
  }
}
