html,
body {
  overflow-x: clip;
}

html {
  background: #0b1120;
  scroll-behavior: smooth; /* Smooth scrolling if needed */
}

body {
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto,
    Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  margin: 0;
  padding: 0px 20px 20px 20px;
  color: #e9edf7;
  position: relative;
  overflow-x: hidden;
  background: #0b1120; /* explicit dark base so Safari never blends with white */
  isolation: isolate; /* NEW: critical for Safari compositing */
  overflow-y: auto;
}

/* Subtle animated blobs for a “liquid” feel
   Safari washout usually comes from blurred, semi-transparent fixed layers.
   Use per-stop alpha instead of global opacity, keep them inside the body
   stacking context, and make them ignore pointer events. */
body::before,
body::after {
  content: "";
  position: fixed;
  width: 520px;
  height: 520px;
  border-radius: 50%;
  filter: blur(60px);
  z-index: -1; /* behind content, but still inside body due to isolation */
  will-change: transform, filter;
  pointer-events: none; /* NEW: never block clicks/selection */
}
body::before {
  /* use alpha in the color instead of element opacity */
  background: radial-gradient(
    circle at 30% 30%,
    rgba(127, 127, 255, 0.35) 0%,
    rgba(127, 127, 255, 0) 60%
  );
  top: -120px;
  left: -120px;
  animation: float1 18s ease-in-out infinite;
}
body::after {
  background: radial-gradient(
    circle at 70% 70%,
    rgba(77, 225, 255, 0.35) 0%,
    rgba(77, 225, 255, 0) 60%
  );
  bottom: -140px;
  right: -140px;
  animation: float2 22s ease-in-out infinite;
}
@keyframes float1 {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  50% {
    transform: translate(20px, 18px) scale(1.05);
  }
}
@keyframes float2 {
  0%,
  100% {
    transform: translate(0, 0) scale(1);
  }
  50% {
    transform: translate(-24px, -16px) scale(1.07);
  }
}

h1 {
  background: rgba(255, 255, 255, 0.08);
  color: #f4f7ff;
  text-align: center;
  padding: 10px 0;
  font-family: "Verdana", sans-serif;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(10, 14, 29, 0.4);
  backdrop-filter: blur(10px) saturate(120%);
  -webkit-backdrop-filter: blur(10px) saturate(120%);
  font-size: clamp(18px, 2.4vw, 28px);
  margin-top: 1rem; /* Add margin to the top of the h1 element */
}

h3 {
  margin: 10px 0px 0px 0px;
}

/* Dashboard grid */
.dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 20px;
  margin-top: 12px;
}

/* Glass card */
.server-container {
  background: rgba(255, 255, 255, 0.08);
  padding: 0px 10px 20px 10px;
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(10, 14, 29, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(12px) saturate(120%);
  -webkit-backdrop-filter: blur(12px) saturate(120%);
  transition: transform 200ms ease, box-shadow 200ms ease,
    border-color 200ms ease;
}
.server-container:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 50px rgba(10, 14, 29, 0.6);
  border-color: rgba(255, 255, 255, 0.32);
}

/* Card header */
.server-header {
  --header-icon-size: 50px;
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.08),
    rgba(255, 255, 255, 0.04)
  );
  min-height: 78px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  margin: 10px 0px 0px 0px;
  padding: 0px 8px;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
.server-header a {
  color: #bcd6ff !important;
}
.server-header-main {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  max-width: 100%;
}
.server-header-text {
  min-width: 0;
}
.deployment-type-image {
  width: var(--header-icon-size);
  height: var(--header-icon-size);
  object-fit: contain;
  flex: 0 0 auto;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}
.server-header h3 {
  margin: 0 0 4px 0;
  text-align: left;
  font-size: 1.05em;
}
.server-header-meta {
  margin: 0 !important;
  font-size: 0.75em;
  padding: 0;
  text-align: left;
}
.server-header-region {
  display: block;
  margin-top: 6px;
}

/* Section headings inside cards */
.server h3 {
  margin-top: 0;
  color: #cfe2ff;
}
.server h4 {
  margin: 10px 0 5px;
  color: #e6ecff;
  background-color: rgba(255, 255, 255, 0.1);
  display: inline-block;
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.95em;
  font-weight: 500; /* use 400 (normal) if you want even lighter */
}

/* Text */
.server p {
  margin: 5px 0;
  color: #e9edf7;
  padding: 0 0 0 15px;
  font-size: 0.85em;
}
strong {
  color: #ffffff;
}

/* Collapsible JSON pane */
.json-display {
  padding: 10px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 0.85em;
  display: none;
  max-height: none;
  overflow: visible;
  border-radius: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.json-display.is-open {
  display: block;
}

.json-toggle {
  cursor: pointer;
  color: #aeb7ff;
  margin-bottom: 10px;
  display: inline-block;
  transition: color 160ms ease;
  font-size: 0.65em;
  font-weight: 500;
  letter-spacing: 0.2px;
  padding: 0 0 0 15px;
}
.json-toggle:hover {
  text-decoration: underline;
  color: #d3daff;
}
/* Animate the chevron */
.json-toggle .fa-chevron-right {
  display: inline-block;
  transition: transform 200ms ease;
  will-change: transform;
}
.json-toggle.expanded .fa-chevron-right {
  transform: rotate(90deg);
}

pre {
  margin-top: 5px;
  color: #e6ebff;
  white-space: pre-wrap;
  word-break: break-word;
}

.footer {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 50px;
  gap: 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(10, 14, 29, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #d9e1ff;
  margin: 15px 0 0 0;
  font-size: 0.85rem;
}

/* Icons + errors */
.fa {
  margin-right: 5px;
}
.error-message {
  color: #ff8585 !important;
}

.error-message .fa {
  font-size: 1.6em;
}

/* Links */
a {
  color: #bcd6ff;
}
a:hover {
  color: #e2ecff;
}

/* Emphasize EU-WEST-1 card */
#eu-west-1.server-container {
  border: 2px solid rgba(255, 255, 255, 0.55) !important;
}

/* Title with qTest icon */
.app-title {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: clamp(6px, 1.5vw, 12px); /* Responsive gap */
  flex-wrap: nowrap;
  text-align: left;
  margin-top: 0;
}
.app-title-main {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 1.2vw, 10px);
  flex: 1 1 auto;
  min-width: 0;
}
.header-controls {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  margin-right: 8px;
  flex: 0 0 auto;
}
.auth-action {
  display: inline-flex;
  align-items: center;
}
.auth-action a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 36px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #e9edf7;
  border-radius: 10px;
  padding: 0 12px;
  text-decoration: none;
  transition: background-color 160ms ease, border-color 160ms ease,
    color 160ms ease;
}
.auth-icon {
  display: inline-flex;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
}
.auth-icon svg {
  width: 100%;
  height: 100%;
}
.auth-label {
  line-height: 1;
}
.auth-action a:hover {
  background: rgba(124, 196, 255, 0.16);
  border-color: rgba(124, 196, 255, 0.55);
  color: #ffffff;
}
/* Favicon tied directly to title text */
.app-title-icon {
  width: clamp(24px, 6vw, 36px); /* 24px min, 6vw preferred, 36px max */
  height: clamp(24px, 6vw, 36px); /* Responsive height */
  background: url("/favicon.ico") no-repeat center / contain;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
  flex-shrink: 0;
}
.app-title-text {
  white-space: nowrap;
}

.title-row {
  margin-top: 1rem;
  position: relative;
  z-index: 40;
}

.title-row .app-title {
  margin-bottom: 0;
  width: 100%;
}

.filters-dropdown {
  position: relative;
  margin-left: 0;
  margin-right: 0;
  flex: 0 0 auto;
  z-index: 50;
  font-size: 1rem;
  line-height: 1.3;
  font-weight: 400;
}

.filters-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.filters-toggle {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #e9edf7;
  border-radius: 10px;
  height: 36px;
  padding: 0 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background-color 160ms ease, border-color 160ms ease,
    color 160ms ease;
}
.filters-icon {
  display: inline-flex;
  width: 14px;
  height: 14px;
  flex: 0 0 14px;
}
.filters-icon svg {
  width: 100%;
  height: 100%;
}

.auth-action a,
.filters-toggle,
.filters-reset-btn {
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: 0.2px;
}

.auth-action a,
.filters-toggle {
  box-sizing: border-box;
  height: 36px;
}

.filters-toggle:hover {
  background: rgba(124, 196, 255, 0.16);
  border-color: rgba(124, 196, 255, 0.55);
  color: #ffffff;
}

.filters-reset-btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: rgba(255, 255, 255, 0.08);
  color: #e9edf7;
  border-radius: 10px;
  padding: 7px 10px;
  cursor: pointer;
  transition: background-color 160ms ease, border-color 160ms ease,
    color 160ms ease;
}

.filters-reset-btn:hover:not(:disabled) {
  background: rgba(124, 196, 255, 0.16);
  border-color: rgba(124, 196, 255, 0.55);
  color: #ffffff;
}

.filters-reset-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.filters-toggle[aria-expanded="true"] {
  border-color: rgba(124, 196, 255, 0.55);
}

.active-filter-count {
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #0b1120;
  background: #7cc4ff;
}

.top-filters {
  position: absolute;
  right: 0;
  top: calc(90% + 10px);
  z-index: 1200;
  width: min(92vw, 560px);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(11, 17, 32, 0.92);
  box-shadow: 0 20px 38px rgba(8, 12, 24, 0.55);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  font-size: 1rem;
  font-weight: 400;
  isolation: isolate;
  transform: translateZ(0);
}

/* Safari can drop the top border on blurred/translucent layers. */
.top-filters::before {
  content: "";
  position: absolute;
  left: 1px;
  top: 0;
  height: 1px;
  border-radius: 14px 14px 0 0;
  background: rgba(255, 255, 255, 0.25);
  pointer-events: none;
}

.top-filters[hidden] {
  display: none;
}

.filter-group {
  margin: 0;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.filter-group-title {
  display: inline-flex;
  align-self: flex-start;
  font-weight: 600;
  font-size: 0.95rem;
  color: #dfe7ff;
  padding: 0 4px;
  margin-bottom: 2px;
}

.filter-group label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: #e9edf7;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 6px;
  transition: background-color 140ms ease, color 140ms ease,
    box-shadow 140ms ease;
}

.filter-group label:hover {
  background: rgba(124, 196, 255, 0.16);
  color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(124, 196, 255, 0.35);
}

.filter-group input[type="checkbox"] {
  accent-color: #7cc4ff;
  cursor: pointer;
}

.empty-results {
  margin: 8px 0 0;
  padding: 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.22);
  text-align: center;
  grid-column: 1 / -1;
  justify-self: center;
  width: 100%;
  box-sizing: border-box;
}

/* Tweak grid density on large-ish screens */
@media (max-width: 1200px) {
  .dashboard {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  }
}

/* Tablets: two columns, softer paddings, wrapping footer */
@media (max-width: 992px) {
  body {
    padding: 0px 16px 16px 16px;
  }
  .dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .server-container {
    padding: 0px 16px 16px 16px;
  }
  .server-header {
    height: auto;
    padding: 8px;
  }
  .server-header p {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    font-size: 12px !important;
  }
  .footer {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 12px;
    text-align: center;
  }
  .app-title {
    flex-wrap: wrap;
  }
  .app-title-main {
    width: 100%;
    text-align: center;
  }
  .app-title-text {
    white-space: normal;
  }
  .header-controls {
    width: calc(100% - 24px);
    margin-left: 0;
    margin-right: 0;
    margin-inline: 12px;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
  }
  .auth-action,
  .auth-action a {
    width: 100%;
  }
  .filters-dropdown {
    width: 100%;
  }
  .filters-actions {
    display: flex;
    flex-direction: column;
    width: 100%;
    gap: 8px;
  }
  .filters-toggle {
    width: 100%;
    justify-content: center;
  }
  .filters-reset-btn {
    width: 100%;
    padding: 8px 12px;
  }
  .top-filters {
    position: static;
    margin-top: 10px;
    width: 100%;
  }
}

/* Phones: single column, smaller JSON pane and monospace text */
@media (max-width: 768px) {
  :root {
    --network-size: 210px;
    --network-line-length: 95px;
    --network-signal-width: 34px;
  }
  .app-title-main {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
  }
  .app-title-text {
    text-align: center;
    line-height: 1.1;
  }
  .app-title-icon {
    width: 32px;
    height: 32px;
  }
  .dashboard {
    grid-template-columns: 1fr;
  }
  .json-display {
    max-height: none;
  }
  pre {
    font-size: 0.85em;
  }
  h1 {
    padding: 8px 0;
  }
  .top-filters {
    grid-template-columns: 1fr;
  }
}

/* Small phones and notched devices: safe padding and readable sizes */
@media (max-width: 480px) {
  :root {
    --network-size: 170px;
    --network-line-length: 78px;
    --network-signal-width: 30px;
  }
  body {
    padding: 0px max(12px, env(safe-area-inset-left))
      max(12px, env(safe-area-inset-bottom))
      max(12px, env(safe-area-inset-right));
  }
  h1 {
    font-size: clamp(16px, 6vw, 22px);
  }
  .server h4 {
    font-size: 0.9em;
  }
  .server p,
  .json-toggle {
    font-size: 0.95em;
  }
  .footer {
    gap: 6px;
    font-size: 0.85rem;
  }
  .server-header a {
    overflow-wrap: anywhere;
  }
}

/* Accessibility: reduce motion if user prefers */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* Backdrop-filter fallback when unsupported */
@supports not (
  (backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))
) {
  .server-container,
  .server-header,
  .json-display,
  .footer {
    background: rgba(15, 23, 42, 0.75);
  }
}

/* Ensure loading container doesn't cause layout shift */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  grid-column: 1 / -1;
  justify-self: center;
  width: 100%;
  gap: 14px;
  padding: 32px 16px;
  color: #aeb7ff;
  font-size: 1em;
  min-height: 300px; /* Reserve space for loading state */
  text-align: center;
}

.loading-container span {
  letter-spacing: 0.2px;
}

/* Network loader variables */
:root {
  --network-size: 260px;
  --network-line-length: 120px;
  --network-accent: #38bdf8;
  --network-endpoint-bg: #1e293b;
  --network-signal-width: 40px;
}

/* Network loader */
.network {
  position: relative;
  width: var(--network-size);
  height: var(--network-size);
}

.center {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  background: var(--network-accent);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 20px var(--network-accent);
  z-index: 10;
}

.line {
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--network-line-length);
  height: 2px;
  background: rgba(56, 189, 248, 0.08);
  transform-origin: left center;
}

.line::before {
  content: "";
  position: absolute;
  right: -4px;
  top: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: 1px solid var(--network-accent);
  background: var(--network-endpoint-bg);
}

.line::after {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  width: var(--network-signal-width);
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    var(--network-accent),
    transparent
  );
  animation: poll 3s infinite ease-in-out;
  opacity: 0;
}

.l1 { transform: rotate(0deg); } .l2 { transform: rotate(18deg); }
.l3 { transform: rotate(36deg); } .l4 { transform: rotate(54deg); }
.l5 { transform: rotate(72deg); } .l6 { transform: rotate(90deg); }
.l7 { transform: rotate(108deg); } .l8 { transform: rotate(126deg); }
.l9 { transform: rotate(144deg); } .l10 { transform: rotate(162deg); }
.l11 { transform: rotate(180deg); } .l12 { transform: rotate(198deg); }
.l13 { transform: rotate(216deg); } .l14 { transform: rotate(234deg); }
.l15 { transform: rotate(252deg); } .l16 { transform: rotate(270deg); }
.l17 { transform: rotate(288deg); } .l18 { transform: rotate(306deg); }
.l19 { transform: rotate(324deg); } .l20 { transform: rotate(342deg); }

.l1::after, .l6::after, .l11::after, .l16::after { animation-delay: 0s; }
.l2::after, .l7::after, .l12::after, .l17::after { animation-delay: 0.6s; }
.l3::after, .l8::after, .l13::after, .l18::after { animation-delay: 1.2s; }
.l4::after, .l9::after, .l14::after, .l19::after { animation-delay: 1.8s; }
.l5::after, .l10::after, .l15::after, .l20::after { animation-delay: 2.4s; }

@keyframes poll {
  0% { left: 0; opacity: 0; transform: scaleX(1); }
  10% { opacity: 1; }
  48% { left: calc(100% - var(--network-signal-width)); opacity: 1; transform: scaleX(1); }
  50% { left: calc(100% - var(--network-signal-width)); transform: scaleX(-1); }
  90% { left: 0; opacity: 1; transform: scaleX(-1); }
  100% { left: 0; opacity: 0; transform: scaleX(-1); }
}
