/* The sky sits behind Emerald's existing globe, controls and live node grid. */
html[data-emerald-sky] {
  --sky-zenith: #8ab7d7;
  --sky-horizon: #e9f1f5;
  --sky-bloom: rgb(255 249 223 / 55%);
  --sky-glass: rgb(250 253 255 / 62%);
  --sky-glass-hover: rgb(255 255 255 / 86%);
  --sky-edge: rgb(255 255 255 / 24%);
  --sky-border: rgb(249 253 255 / 75%);
  --sky-moon: #f9f2d8;
  --sky-haze: rgb(255 255 255 / 34%);
  --sky-stars: 0;
}

html[data-emerald-sky="dawn"] {
  --sky-zenith: #9eafce;
  --sky-horizon: #f8e4d2;
  --sky-bloom: rgb(255 204 159 / 70%);
}

html[data-emerald-sky="dusk"] {
  --sky-zenith: #aaa8c8;
  --sky-horizon: #efcfbf;
  --sky-bloom: rgb(253 189 146 / 58%);
}

html[data-emerald-sky="night"] {
  --sky-zenith: #a1b0cf;
  --sky-horizon: #e0e6f1;
  --sky-bloom: rgb(197 211 235 / 38%);
  --sky-stars: .55;
}

html.dark[data-emerald-sky] {
  --sky-zenith: #17374e;
  --sky-horizon: #111e2b;
  --sky-bloom: rgb(91 151 172 / 19%);
  --sky-glass: rgb(77 87 107 / 29%);
  --sky-glass-hover: rgb(82 97 119 / 58%);
  --sky-edge: rgb(199 215 247 / 5%);
  --sky-border: rgb(197 207 231 / 19%);
  --sky-haze: rgb(189 213 238 / 10%);
}

html.dark[data-emerald-sky="dawn"] {
  --sky-zenith: #26304b;
  --sky-horizon: #323141;
  --sky-bloom: rgb(240 155 114 / 24%);
  --sky-stars: .2;
}

html.dark[data-emerald-sky="dusk"] {
  --sky-zenith: #292e4c;
  --sky-horizon: #242534;
  --sky-bloom: rgb(218 133 123 / 22%);
  --sky-stars: .35;
}

html.dark[data-emerald-sky="night"] {
  --sky-zenith: #0a1025;
  --sky-horizon: #101727;
  --sky-bloom: rgb(67 87 150 / 23%);
  --sky-haze: rgb(146 172 217 / 9%);
  --sky-stars: 1;
}

html[data-emerald-sky] body {
  isolation: isolate;
}

#emerald-sky-backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  pointer-events: none;
  contain: strict;
  background:
    radial-gradient(ellipse at 28% -4%, var(--sky-bloom), transparent 62%),
    linear-gradient(172deg, var(--sky-zenith), var(--sky-horizon) 78%);
}

/* Only replace Emerald's stock geometric wallpaper. An administrator's own
   image or video, when configured, remains above this backdrop. */
html[data-emerald-sky] #app > .background-container > .bg-slate-50 {
  visibility: hidden;
}

#emerald-sky-backdrop canvas {
  width: 100%;
  height: 100%;
  display: block;
  opacity: var(--sky-stars);
  transition: opacity 1.2s ease;
}

/* A few soft, sloping veils instead of a tiled cloud texture. */
#emerald-sky-backdrop::before {
  content: "";
  position: absolute;
  inset: -12% -20%;
  transform: rotate(-11deg);
  background:
    radial-gradient(ellipse 40% 2.7% at 28% 30%, var(--sky-haze), transparent 85%),
    radial-gradient(ellipse 29% 1.4% at 58% 24%, var(--sky-haze), transparent 87%),
    radial-gradient(ellipse 25% 3.3% at 77% 55%, var(--sky-haze), transparent 85%);
}

#emerald-sky-backdrop::after {
  content: "";
  position: absolute;
  top: clamp(30px, 6.5vh, 74px);
  left: clamp(90px, calc(50% - 230px), 46%);
  width: clamp(30px, 2.6vw, 46px);
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--sky-moon);
  box-shadow: 0 0 34px 4px rgb(255 229 181 / 30%);
}

html[data-emerald-sky="night"] #emerald-sky-backdrop::after {
  /* The cutout follows the actual sky underneath. */
  background: linear-gradient(145deg, #fff7df, #ccdafa);
  box-shadow: none;
  -webkit-mask-image: radial-gradient(circle at 69% 28%, transparent 48%, black 50%);
  mask-image: radial-gradient(circle at 69% 28%, transparent 48%, black 50%);
}

html[data-emerald-sky] #app .home-view :is(.group.h-full.text-card-foreground, .monitor-summary-tile, .node-card) {
  background-color: var(--sky-glass);
  background-image: linear-gradient(125deg, var(--sky-edge), transparent 48%);
  border: 1px solid var(--sky-border);
  border-radius: 15px;
  -webkit-backdrop-filter: blur(9px);
  backdrop-filter: blur(9px);
}

html[data-emerald-sky] #app .home-view {
  --muted-foreground: #47556b;
}

html.dark[data-emerald-sky] #app .home-view {
  --muted-foreground: #b4c1d4;
}

html[data-emerald-sky] .monitor-summary-tile[data-metric="cpu"] { --sky-icon: #8269db; }
html[data-emerald-sky] .monitor-summary-tile[data-metric="memory"] { --sky-icon: #298db0; }
html[data-emerald-sky] .monitor-summary-tile[data-metric="disk"] { --sky-icon: #4785d7; }
html[data-emerald-sky] .monitor-summary-tile[data-metric="upload"] { --sky-icon: #27a075; }
html[data-emerald-sky] .monitor-summary-tile[data-metric="download"] { --sky-icon: #379ab1; }
html[data-emerald-sky] .monitor-summary-tile[data-metric="traffic"] { --sky-icon: #c38835; }

html[data-emerald-sky] .monitor-summary-tile svg[aria-hidden="true"] {
  box-sizing: border-box;
  width: 26px;
  height: 26px;
  padding: 5px;
  border-radius: 7px;
  color: var(--sky-icon);
  background-color: color-mix(in srgb, var(--sky-icon) 14%, transparent);
}

html.dark[data-emerald-sky] .monitor-summary-tile svg[aria-hidden="true"] {
  color: color-mix(in srgb, var(--sky-icon) 64%, white);
}

/* Group selection is on its own scrollable row. Search opens to the right
   so keyboard focus cannot cover the two view-mode controls to its left. */
html[data-emerald-sky] .home-view .nodes div:has(> .search) {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 16px;
}

html[data-emerald-sky] .home-view .nodes div:has(> .search) > :first-child {
  max-width: 100%;
}

html[data-emerald-sky] .home-view .nodes .search {
  margin-inline: 0;
  max-width: 100%;
}

html[data-emerald-sky] .home-view .nodes .search > .relative {
  width: 224px;
  max-width: calc(100vw - 120px);
}

html[data-emerald-sky] .home-view .nodes .search > .relative:focus-within {
  width: min(240px, calc(100vw - 120px));
}

html[data-emerald-sky] .home-view .nodes .search > .relative > .absolute {
  inset: 0;
}

html[data-emerald-sky] .home-view .nodes .search input,
html[data-emerald-sky] .home-view .nodes .search input:focus {
  width: 100% !important;
  padding-inline-start: 30px;
}

html[data-emerald-sky] .home-view .nodes .search input::placeholder {
  color: var(--muted-foreground);
}

@media (min-width: 768px) {
  html[data-emerald-sky] .home-view .monitor-summary:has(.earth-globe-canvas) {
    height: 328px;
    overflow-x: clip;
  }

  html[data-emerald-sky] .monitor-summary:has(.earth-globe-canvas) > .monitor-summary-grid {
    height: 200px;
    align-self: end;
    margin: 0;
  }

  html[data-emerald-sky] .monitor-summary:has(.earth-globe-canvas) > .aspect-square {
    width: min(113%, 720px);
    max-width: none;
    margin-inline: 0;
    justify-self: center;
    align-self: start;
    translate: 0 clamp(-110px, calc(100px - 16.4vw), -32px);
  }
}

@media (hover: hover) {
  html[data-emerald-sky] #app .home-view :is(.group.h-full.text-card-foreground, .monitor-summary-tile, .node-card):hover {
    background-color: var(--sky-glass-hover);
  }
}

@media (max-width: 767px) {
  html[data-emerald-sky] .monitor-summary-tile .tracking-wider {
    font-size: 11px;
    letter-spacing: 0;
  }

  html[data-emerald-sky] .monitor-summary-tile svg[aria-hidden="true"] {
    width: 21px;
    height: 21px;
  }

  #emerald-sky-backdrop::after {
    left: 60%;
    top: 58px;
    width: 32px;
  }

  html[data-emerald-sky] #app .home-view :is(.group.h-full.text-card-foreground, .monitor-summary-tile, .node-card) {
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
  }

  html[data-emerald-sky] .home-view .monitor-summary:has(.earth-globe-canvas) {
    height: auto;
    grid-template-rows: auto auto;
    row-gap: 10px;
  }

  html[data-emerald-sky] .monitor-summary:has(.earth-globe-canvas) > .aspect-square {
    grid-row: 1;
    translate: 0 18px;
  }

  html[data-emerald-sky] .monitor-summary:has(.earth-globe-canvas) > .monitor-summary-grid {
    grid-row: 2;
    margin: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #emerald-sky-backdrop canvas {
    transition: none;
  }
}
