/* fagmob neon / daylight for Traccar (6.15).
 * fagmob.js sets html[data-fm="dark"|"light"] from the shared fagmob_theme cookie and
 * feeds MUI the mode, primary and secondary colours through /api/server. This file does
 * what MUI's palette can't: surfaces, lines, font, glow, map controls and the login page.
 * Tokens mirror fagmob-dash/public/themes.css. */

@font-face {
  font-family: 'Quicksand Variable';
  font-style: normal;
  font-display: swap;
  font-weight: 300 700;
  src: url('fonts/quicksand-latin-wght-normal.woff2') format('woff2-variations');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304,
    U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

html,
html[data-fm='dark'] {
  --fm-bg: #130a1a;
  --fm-surface: #1c1125;
  --fm-raised: #241631;
  --fm-hover: #2a1838;
  --fm-line: #3a2446;
  --fm-text: #f7ecf8;
  --fm-muted: #ad96b8;
  --fm-neon: #ff2e97;
  --fm-accent: #2ee8ff;
  --fm-on-neon: #130a1a;
  --fm-glow: rgba(255, 46, 151, 0.5);
  --fm-ring: rgba(255, 46, 151, 0.28);
  --fm-select: rgba(255, 46, 151, 0.14);
  --fm-shadow: rgba(0, 0, 0, 0.45);
  --fm-field: rgba(0, 0, 0, 0.25);
  --fm-icon-filter: invert(0.92) sepia(0.15) saturate(2) hue-rotate(250deg);
  --fm-font: 'Quicksand Variable', ui-rounded, system-ui, sans-serif;
}

html[data-fm='light'] {
  --fm-bg: #eefafd;
  --fm-surface: #ffffff;
  --fm-raised: #f6fdff;
  --fm-hover: #def3f8;
  --fm-line: #bfe0e9;
  --fm-text: #0b2830;
  --fm-muted: #4b6a73;
  --fm-neon: #008ea8;
  --fm-accent: #d8167b;
  --fm-on-neon: #ffffff;
  --fm-glow: rgba(0, 196, 226, 0.35);
  --fm-ring: rgba(0, 142, 168, 0.22);
  --fm-select: rgba(0, 142, 168, 0.12);
  --fm-shadow: rgba(11, 40, 48, 0.12);
  --fm-field: #ffffff;
  --fm-icon-filter: none;
}

/* ---------- Base ---------- */

html[data-fm],
html[data-fm] body {
  background: var(--fm-bg) !important;
  color: var(--fm-text);
}

html[data-fm] body,
html[data-fm] .MuiTypography-root,
html[data-fm] .MuiButtonBase-root,
html[data-fm] .MuiInputBase-root,
html[data-fm] .MuiInputLabel-root,
html[data-fm] .MuiFormLabel-root,
html[data-fm] .MuiFormHelperText-root,
html[data-fm] .MuiTableCell-root,
html[data-fm] .MuiChip-root,
html[data-fm] .MuiTooltip-tooltip,
html[data-fm] .MuiMenuItem-root,
html[data-fm] .MuiAlert-message,
html[data-fm] .MuiSnackbarContent-message,
html[data-fm] .maplibregl-popup-content {
  font-family: var(--fm-font) !important;
}

html[data-fm] .MuiTypography-root {
  font-weight: 500;
}

html[data-fm] .MuiTypography-h6,
html[data-fm] .MuiTypography-subtitle1,
html[data-fm] .MuiButton-root,
html[data-fm] .MuiTab-root {
  font-weight: 650 !important;
}

html[data-fm] ::selection {
  background: var(--fm-neon);
  color: var(--fm-on-neon);
}

html[data-fm] :focus-visible {
  outline: 2px solid var(--fm-neon);
  outline-offset: 2px;
}

/* Text fields show focus on their outline (below), not on the inner <input> */
html[data-fm] .MuiInputBase-input:focus-visible,
html[data-fm] .MuiButtonBase-root:focus-visible {
  outline: none;
}

html[data-fm] * {
  scrollbar-color: var(--fm-line) transparent;
}

/* The pre-React spinner in index.html */
html[data-fm] .loader {
  border-color: var(--fm-line) !important;
  border-right-color: var(--fm-neon) !important;
  filter: drop-shadow(0 0 6px var(--fm-glow));
}

/* ---------- Surfaces ---------- */

html[data-fm] .MuiPaper-root {
  background-color: var(--fm-surface) !important;
  background-image: none !important;
  color: var(--fm-text);
}

html[data-fm] .MuiDrawer-paper,
html[data-fm] .MuiMenu-paper,
html[data-fm] .MuiPopover-paper,
html[data-fm] .MuiAutocomplete-paper,
html[data-fm] .MuiDialog-paper,
html[data-fm] .MuiAccordion-root {
  background-color: var(--fm-raised) !important;
}

html[data-fm] .MuiDrawer-paper {
  border-color: var(--fm-line) !important;
}

html[data-fm] .MuiMenu-paper,
html[data-fm] .MuiPopover-paper,
html[data-fm] .MuiAutocomplete-paper,
html[data-fm] .MuiDialog-paper {
  border: 1px solid var(--fm-line);
  box-shadow: 0 12px 32px var(--fm-shadow) !important;
}

html[data-fm] .MuiAppBar-root {
  background-color: color-mix(in srgb, var(--fm-bg) 88%, transparent) !important;
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--fm-line);
  box-shadow: none !important;
  color: var(--fm-text) !important;
}

html[data-fm] .MuiAppBar-root .MuiTypography-root {
  color: var(--fm-text);
}

html[data-fm] .MuiDivider-root,
html[data-fm] .MuiTableCell-root,
html[data-fm] .MuiAccordion-root::before {
  border-color: var(--fm-line) !important;
}

html[data-fm] .MuiAccordion-root::before {
  background-color: var(--fm-line) !important;
}

html[data-fm] .MuiTableHead-root .MuiTableCell-root {
  color: var(--fm-muted);
  font-weight: 650;
}

html[data-fm] .MuiTableRow-hover:hover,
html[data-fm] .MuiTableRow-root:hover {
  background-color: var(--fm-hover) !important;
}

/* ---------- Lists, menus, nav ---------- */

html[data-fm] .MuiListItemButton-root:hover,
html[data-fm] .MuiMenuItem-root:hover,
html[data-fm] .MuiAutocomplete-option:hover,
html[data-fm] .MuiAutocomplete-option.Mui-focused {
  background-color: var(--fm-hover) !important;
}

html[data-fm] .MuiListItemButton-root.Mui-selected,
html[data-fm] .MuiMenuItem-root.Mui-selected,
html[data-fm] .MuiAutocomplete-option[aria-selected='true'] {
  background-color: var(--fm-select) !important;
  box-shadow: inset 3px 0 0 var(--fm-neon);
}

html[data-fm] .MuiListItemButton-root.Mui-selected .MuiListItemIcon-root,
html[data-fm] .MuiListItemButton-root.Mui-selected .MuiListItemText-primary {
  color: var(--fm-neon);
}

html[data-fm] .MuiListItemText-secondary,
html[data-fm] .MuiListSubheader-root {
  color: var(--fm-muted) !important;
}

html[data-fm] .MuiListSubheader-root {
  background-color: transparent !important;
  font-weight: 650;
}

html[data-fm] .MuiListItemIcon-root {
  color: var(--fm-muted);
}

html[data-fm] .MuiBottomNavigation-root {
  background-color: var(--fm-surface) !important;
  border-top: 1px solid var(--fm-line);
}

html[data-fm] .MuiBottomNavigationAction-root {
  color: var(--fm-muted);
}

html[data-fm] .MuiBottomNavigationAction-root.Mui-selected {
  color: var(--fm-neon);
}

html[data-fm] .MuiTabs-indicator {
  box-shadow: 0 0 8px var(--fm-glow);
}

/* ---------- Inputs ---------- */

html[data-fm] .MuiOutlinedInput-root {
  background-color: var(--fm-field);
  border-radius: 10px;
}

html[data-fm] .MuiOutlinedInput-notchedOutline {
  border-color: var(--fm-line) !important;
}

html[data-fm] .MuiOutlinedInput-root:hover .MuiOutlinedInput-notchedOutline {
  border-color: var(--fm-muted) !important;
}

html[data-fm] .MuiOutlinedInput-root.Mui-focused .MuiOutlinedInput-notchedOutline {
  border-color: var(--fm-neon) !important;
  box-shadow: 0 0 0 3px var(--fm-ring);
}

html[data-fm] .MuiOutlinedInput-root.Mui-error .MuiOutlinedInput-notchedOutline {
  border-color: #ff5a6e !important;
}

html[data-fm] .MuiInputLabel-root {
  color: var(--fm-muted);
}

html[data-fm] .MuiInputLabel-root.Mui-focused {
  color: var(--fm-neon);
}

/* Device list search bar sits on the map, borderless */
html[data-fm] .MuiInputBase-root:not(.MuiOutlinedInput-root) {
  color: var(--fm-text);
}

/* ---------- Buttons, chips, switches ---------- */

html[data-fm] .MuiButton-root,
html[data-fm] .MuiChip-root {
  border-radius: 999px;
  text-transform: none;
  letter-spacing: 0.01em;
}

html[data-fm] .MuiButton-containedPrimary,
html[data-fm] .MuiFab-primary {
  color: var(--fm-on-neon) !important;
  box-shadow: 0 0 0 1px var(--fm-neon), 0 0 14px var(--fm-glow) !important;
}

html[data-fm] .MuiButton-containedPrimary:hover,
html[data-fm] .MuiFab-primary:hover {
  box-shadow: 0 0 0 1px var(--fm-neon), 0 0 22px var(--fm-glow) !important;
}

html[data-fm] .MuiButton-containedPrimary.Mui-disabled {
  box-shadow: none !important;
}

html[data-fm] .MuiButton-outlinedPrimary {
  border-color: var(--fm-neon);
}

html[data-fm] .MuiSwitch-switchBase.Mui-checked + .MuiSwitch-track {
  opacity: 0.6;
}

html[data-fm] .MuiSwitch-switchBase.Mui-checked .MuiSwitch-thumb {
  box-shadow: 0 0 8px var(--fm-glow);
}

html[data-fm] .MuiTooltip-tooltip {
  background-color: var(--fm-raised) !important;
  color: var(--fm-text) !important;
  border: 1px solid var(--fm-line);
}

html[data-fm] .MuiLinearProgress-bar,
html[data-fm] .MuiCircularProgress-root {
  filter: drop-shadow(0 0 4px var(--fm-glow));
}

/* ---------- Light-mode neon is printed, not lit ---------- */

html[data-fm='light'] .MuiButton-containedPrimary,
html[data-fm='light'] .MuiFab-primary {
  box-shadow: 0 2px 8px var(--fm-ring) !important;
}

html[data-fm='light'] .MuiButton-containedPrimary:hover,
html[data-fm='light'] .MuiFab-primary:hover {
  box-shadow: 0 4px 14px var(--fm-ring) !important;
}

/* ---------- Login page ---------- */

/* LoginLayout: <main><div sidebar/><Paper/></main>. The sidebar is painted with the
   primary colour; make it the brand panel instead. */
html[data-fm] main:has(> div + .MuiPaper-root > form) > div:first-child {
  background:
    radial-gradient(120% 80% at 50% 45%, var(--fm-select), transparent 70%),
    var(--fm-bg) !important;
  border-right: 1px solid var(--fm-line);
}

html[data-fm] main:has(> div + .MuiPaper-root > form) > .MuiPaper-root {
  background-color: var(--fm-surface) !important;
  box-shadow: none !important;
}

/* ---------- Map ---------- */

html[data-fm] .maplibregl-ctrl-group {
  background-color: var(--fm-raised) !important;
  border: 1px solid var(--fm-line);
  box-shadow: 0 4px 14px var(--fm-shadow) !important;
  border-radius: 10px !important;
}

html[data-fm] .maplibregl-ctrl-group button + button {
  border-top-color: var(--fm-line) !important;
}

html[data-fm] .maplibregl-ctrl-group button:not(:disabled):hover {
  background-color: var(--fm-hover) !important;
}

html[data-fm] .maplibregl-ctrl-icon {
  filter: var(--fm-icon-filter);
}

html[data-fm] .maplibregl-ctrl-attrib,
html[data-fm] .maplibregl-ctrl-scale {
  background-color: color-mix(in srgb, var(--fm-surface) 80%, transparent) !important;
  color: var(--fm-muted) !important;
  border-color: var(--fm-line) !important;
}

html[data-fm] .maplibregl-ctrl-attrib a {
  color: var(--fm-muted) !important;
}

html[data-fm] .maplibregl-popup-content {
  background-color: var(--fm-raised) !important;
  color: var(--fm-text);
  border: 1px solid var(--fm-line);
  border-radius: 12px;
  box-shadow: 0 10px 28px var(--fm-shadow);
}

html[data-fm] .maplibregl-popup-tip {
  border-top-color: var(--fm-line) !important;
  border-bottom-color: var(--fm-line) !important;
}
