/*
MIT License

Copyright (c) 2019 Mark Harkin, 2016 Dylan Hicks (aka. dylanh333)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

/* ==========================================================================
   CSS Custom Properties (Theme Variables)
   ========================================================================== */
:root {
  /* General Menu & Item Sizing/Layout */
  --menu-line-height: 30px;
  --menu-item-height: 30px;
  --menu-icon-dimension: 30px;
  --menu-item-padding-left-with-icon: 30px;
  --menu-item-padding-horizontal: 12px;
  --menu-item-submenu-indicator-padding-right: 28px;
  --menu-dropdown-min-width: 200px;
  --menu-chevron-size: 8px;
  --menu-chevron-border-width: 1px;
  --menu-horizontal-chevron-size: 4px;
  --menu-horizontal-chevron-bottom-offset: 4px;
  --menu-submenu-chevron-indent-right: 12px;

  /* Fonts */
  --menu-font-family: var(--font-family-sans);
  --menu-font-size: var(--font-size-base);
  --menu-icon-font-size: 24px;
  --menu-submenu-icon-font-size: 18px;

  /* Colors (Base Light Theme) */
  --menu-text-color: var(--text-strong);
  --menu-border-color: var(--border-weak-base); /* Also for chevron color */
  --menu-submenu-bg-color: var(--surface-raised-stronger-non-alpha);
  --menu-item-hover-bg-color: var(--surface-raised-base-hover);

  /* Toggle Switch (Base Light Theme) */
  --toggle-switch-width: 28px;
  --toggle-switch-height: 16px;
  --toggle-switch-border-radius: 3px;
  --toggle-switch-bg-color: var(--surface-base);
  --toggle-switch-bg-color-active: var(--icon-strong-base);
  --toggle-slider-offset: 0px;
  --toggle-slider-dimension: 14px;
  --toggle-slider-bg-color: var(--icon-invert-base);
  --toggle-slider-translate-x-active: 12px;
  --toggle-item-padding-vertical: 8px;
  --toggle-item-text-color: inherit; /* Default, can be overridden */

  /* Menu Bottom Section (Base Light Theme) */
  --menu-bottom-section-border-top-color: var(--border-weak-base);
  --latency-display-bg-color: transparent;
  --latency-display-text-color: var(--text-weak);
  --latency-display-font-family: var(--font-family-mono);
  --latency-display-font-size: 0.75em;
  --latency-display-padding-vertical: 6px;
  --latency-display-border-bottom-color: var(--border-weak-base);
  --latency-value-good-color: #4CAF50;
  --latency-value-fair-color: #FF9800;
  --latency-value-poor-color: #f44336;
  --latency-separator-color: #999;
  --hoody-footer-bg-color: transparent;
  --hoody-footer-padding-vertical: 8px;
  --hoody-footer-font-size: 0.7em;
  --hoody-footer-font-family: var(--font-family-sans);
  --hoody-footer-link-color: var(--text-weak);

  /* Animation */
  --menu-animation-duration: 0.1s;
  --menu-hover-animation-duration: 0.2s;
}

/* ==========================================================================
   Dark Mode Theme Overrides
   ========================================================================== */
:root[data-color-scheme="dark"], .dark-mode {
  --menu-text-color: var(--text-strong);
  --menu-border-color: var(--border-weak-base);
  --menu-submenu-bg-color: var(--surface-raised-stronger-non-alpha);
  --menu-item-hover-bg-color: var(--surface-raised-base-hover);

  --toggle-switch-bg-color: var(--surface-base);
  --toggle-switch-bg-color-active: var(--icon-strong-base);
  --toggle-slider-bg-color: var(--icon-invert-base);
  --toggle-item-text-color: #e0e0e0; /* For .toggle-text in dark mode */

  --menu-bottom-section-border-top-color: var(--border-weak-base);
  --latency-display-bg-color: transparent;
  --latency-display-text-color: var(--text-weak);
  --latency-display-border-bottom-color: var(--border-weak-base);
  /* Latency value colors (good, fair, poor) could also be overridden if needed for contrast */
  --hoody-footer-bg-color: transparent;
  --hoody-footer-link-color: var(--text-weak);
}

/* ==========================================================================
   Base Menu Styles
   ========================================================================== */
.Menu {
  display: none;
  position: relative;
  z-index: 100000;
  font-family: var(--menu-font-family);
  font-size: var(--menu-font-size);
  line-height: var(--menu-line-height);
  color: var(--menu-text-color);
}

/* Three basic menu layouts */
/* This also enforces that menu is a ul, and that
 * layout modifier is specified
 */
ul.Menu.-horizontal,
ul.Menu.-vertical {
  display: block; /* Changed from inline-block for better vertical stacking */
  width: 100%;    /* Ensure it takes full available width */
}

ul.Menu.-floating {
  display: block;
  position: absolute;
}

/* Menu and menu-item layout */
.Menu,
.Menu li,
.Menu li>ul {
  list-style: none;
  padding: 0px;
  margin: 0px;
}

.Menu li {
  display: block;
  position: relative;
  white-space: nowrap;
  word-break: keep-all;
  /* height: var(--menu-item-height); /* Removed fixed height, allow content and padding to define height */
}

.Menu.-horizontal>li {
  display: inline-block;
  float: left; /* Consider flexbox for future refactor of horizontal menu */
}

.Menu li>* {
  display: block;
  position: relative;
  padding: 0px var(--menu-item-padding-horizontal);
}

.Menu li> :first-child {
  height: var(--menu-item-height);
}

.Menu li>ul {
  position: absolute;
  min-width: 100%;
  top: 0px;
  left: 100%;
  background: var(--menu-submenu-bg-color);
}

.Menu.-horizontal.-alignRight li>ul {
  left: auto;
  right: 100%;
}

.Menu.-horizontal.-alignRight>li>ul {
  right: 0px;
}

.Menu.-horizontal>li>ul {
  top: auto;
  left: auto;
  min-width: var(--menu-dropdown-min-width);
}

/* ==========================================================================
   Menu Behavior (Visibility)
   ========================================================================== */
.Menu li>ul,
.Menu.-floating {
  display: none;
}

.Menu li>ul.-visible,
ul.Menu.-floating.-visible {
  display: block;
}

/* ==========================================================================
   Menu Animations
   ========================================================================== */
.Menu li>ul,
.Menu.-horizontal.-alignRight li>ul,
.Menu.-floating {
  opacity: 1;
  transform: scale(1) translateY(0px);
  transform-origin: left top;
  transition: width var(--menu-animation-duration), height var(--menu-animation-duration), transform var(--menu-animation-duration), opacity var(--menu-animation-duration);
}

.Menu.-alignRight li>ul,
.Menu.-floating.-alignRight {
  transform-origin: right top;
}

.Menu li>ul.-animating,
.Menu.-floating.-animating {
  opacity: 0 !important;
  transform: scale(0.96) translateX(-16px);
}

.Menu li>ul.-animating {
  z-index: -1 !important;
}

.Menu.-horizontal>li>ul.-animating {
  transform: scale(0.96) translateY(-16px);
}

.Menu.-alignRight li>ul.-animating,
.Menu.-floating.-alignRight.-animating {
  transform: scale(0.96) translateX(16px);
}

.Menu.-horizontal.-alignRight>li>ul.-animating {
  transform: scale(0.96) translateY(-16px);
}

/* ==========================================================================
   Menu Item Icons
   ========================================================================== */
.Menu *[data-icon]:before {
  position: absolute;
  left: 0px;
  top: 0px;
  bottom: 0px;
  margin: auto 0px;
  width: var(--menu-icon-dimension);
  height: var(--menu-icon-dimension);
  font-size: var(--menu-icon-font-size);
}

.Menu .Icon,
.Menu *[data-icon]:before {
  line-height: inherit; /* Was var(--menu-icon-dimension), inherit is better */
}

.Menu .Icon {
  padding: 0px;
  width: var(--menu-icon-dimension);
  height: var(--menu-icon-dimension);
  font-size: var(--menu-icon-font-size);
}

.Menu *[data-icon] {
  min-width: var(--menu-icon-dimension);
  min-height: var(--menu-icon-dimension);
  padding-left: var(--menu-item-padding-left-with-icon);
}

.Menu *:empty[data-icon] {
  padding-left: 0px !important;
  padding-right: 0px !important;
}

/* For submenus */
.Menu>li ul .Icon,
.Menu.-floating .Icon,
.Menu>li ul *[data-icon]:before,
.Menu.-floating *[data-icon]:before {
  font-size: var(--menu-submenu-icon-font-size);
}

/* ==========================================================================
   Submenu Chevrons (Indicators)
   ========================================================================== */
.Menu li.-hasSubmenu>a:after {
  display: block;
  position: absolute;
  width: var(--menu-chevron-size);
  height: var(--menu-chevron-size);
  right: var(--menu-submenu-chevron-indent-right); /* Default for vertical */
  bottom: 0px;
  top: 0px;
  margin: auto 0px;
  transform: rotate(45deg);
  border-width: var(--menu-chevron-border-width);
  border-color: var(--menu-border-color);
  border-style: solid solid none none;
  content: "";
}

.Menu.-horizontal>li.-hasSubmenu>a:after {
  width: var(--menu-horizontal-chevron-size);
  height: var(--menu-horizontal-chevron-size);
  bottom: var(--menu-horizontal-chevron-bottom-offset);
  top: auto;
  left: 0px;
  right: 0px;
  margin: 0px auto;
  border-style: none solid solid none;
}

.Menu li.-hasSubmenu.-noChevron>a:after {
  display: none;
}

/* Indent of chevron for non-horizontal menus */
.Menu:not(.-horizontal)>li.-hasSubmenu>a {
  padding-right: var(--menu-item-submenu-indicator-padding-right);
}
/* .Menu li li.-hasSubmenu>a:after was combined with the default above */
.Menu li li.-hasSubmenu>a {
  padding-right: var(--menu-item-submenu-indicator-padding-right);
}


/* ==========================================================================
   Styling of Hyperlink Text & Hover Effects
   ========================================================================== */
.Menu li>a {
  text-decoration: none;
  color: inherit; /* Will inherit from .Menu's color var */
}

.Menu li>a:first-child {
  transition: background-color var(--menu-hover-animation-duration);
}

.Menu li:hover>a:first-child,
.Menu li.-active>a:first-child {
  background-color: var(--menu-item-hover-bg-color);
}

/* ==========================================================================
   Component: Toggle Switch
   ========================================================================== */
.toggle-menu-item {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    /* padding-left: var(--menu-item-padding-horizontal) !important; /* Standard padding if no icon */
}

.toggle-text {
    flex: 1;
    color: var(--toggle-item-text-color); /* Uses variable, overridden in .dark-mode */
}

.toggle-switch {
    position: relative;
    width: var(--toggle-switch-width);
    height: var(--toggle-switch-height);
    background-color: var(--toggle-switch-bg-color);
    border-radius: var(--toggle-switch-border-radius);
    transition: background-color 0.3s ease;
    cursor: pointer;
    margin-left: var(--menu-item-padding-horizontal);
    flex-shrink: 0;
}

.toggle-switch.active {
    background-color: var(--toggle-switch-bg-color-active);
}

.toggle-slider {
    position: absolute;
    top: var(--toggle-slider-offset);
    left: var(--toggle-slider-offset);
    width: var(--toggle-slider-dimension);
    height: var(--toggle-slider-dimension);
    background-color: var(--toggle-slider-bg-color);
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-switch.active .toggle-slider {
    transform: translateX(var(--toggle-slider-translate-x-active));
}

/* Dark mode specific text color for settings items, handled by .dark-mode --toggle-item-text-color */
/* .dark-mode #settings_menu_entry .toggle-text,
.dark-mode #settings_menu_entry a {
    color: var(--menu-text-color) !important; /* Uses the general dark mode text color */
/* } */

/* Hover effects for toggle switches */
.toggle-switch:hover {
    opacity: 0.8;
}

/* Padding for toggle items */
#settings_menu_entry .toggle-menu-item {
    padding-top: var(--toggle-item-padding-vertical) !important;
    padding-bottom: var(--toggle-item-padding-vertical) !important;
    padding-left: var(--menu-item-padding-horizontal) !important; /* Standard padding */
    padding-right: var(--menu-item-padding-horizontal) !important;
}

/* Hover handled by general .Menu li:hover > a:first-child */
/* #settings_menu_entry .toggle-menu-item:hover {
    background-color: var(--menu-item-hover-bg-color);
} */

/* .dark-mode #settings_menu_entry .toggle-menu-item:hover {
    background-color: var(--menu-item-hover-bg-color); /* Already handled by .dark-mode var */
/* } */


/* ==========================================================================
   Component: Main Menu Container (#float_menu)
   ========================================================================== */
#float_menu {
    display: flex;
    flex-direction: column;
    height: 100vh; /* Consider max-height if issues with small viewports */
    max-height: 100vh; /* Ensures it doesn't exceed viewport */
    padding-top: 0;
    padding-bottom: 0;
}

#float_menu .Menu { /* The main ul.Menu inside #float_menu */
    flex: 1 1 auto; /* Grow and shrink, auto basis */
    overflow-y: auto;
    min-height: 0; /* Important for flex item to shrink properly */
    padding-top: 60px !important;
    /* max-height calculation removed, bottom section is now a sibling flex item */
}


/* ==========================================================================
   Component: Menu Bottom Section (#menu_bottom_section)
   ========================================================================== */
#menu_bottom_section {
    flex-shrink: 0; /* Prevent this section from shrinking */
    border-top: 1px solid var(--menu-bottom-section-border-top-color);
    /* position, bottom, etc. are handled by flex layout of parent */
}

/* Latency display styling - compact grid */
#latency_display {
    background-color: var(--latency-display-bg-color);
    color: var(--latency-display-text-color);
    font-family: var(--latency-display-font-family);
    padding: 8px var(--menu-item-padding-horizontal);
    font-size: var(--latency-display-font-size);
    border-bottom: 1px solid var(--latency-display-border-bottom-color);
}

.stats-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 3px 10px;
    align-items: baseline;
}

.stats-label {
    color: var(--latency-display-text-color);
    opacity: 0.6;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.stats-value {
    font-weight: 600;
    color: var(--text-base);
    text-align: right;
    font-size: 11px;
}

.stats-latency {
    color: #4CAF50; /* default good color, JS overrides per-value */
}

/* Hoody.com footer - part of bottom section */
#hoody_menu_footer {
    background-color: var(--hoody-footer-bg-color);
    text-align: center;
    padding: var(--hoody-footer-padding-vertical) var(--menu-item-padding-horizontal);
    font-size: var(--hoody-footer-font-size);
    font-family: var(--hoody-footer-font-family);
}

#hoody_menu_footer a {
    color: var(--hoody-footer-link-color);
    text-decoration: none;
    opacity: 0.8;
    transition: opacity 0.3s ease;
}

#hoody_menu_footer a:hover {
    opacity: 1;
}

/* Dark mode specific styling for bottom section elements is handled by .dark-mode variables */

/* ==========================================================================
   Component: Menu Separator
   ========================================================================== */
.menu-separator {
    height: 1px !important;
    background-color: var(--menu-bottom-section-border-top-color);
    margin: 8px var(--menu-item-padding-horizontal);
    padding: 0 !important;
    pointer-events: none;
    cursor: default;
}
