/* Global app styles */

/* Fixed-width digits and box to prevent jitter while time updates */
:root {
  --time-ago-ch: 12; /* adjust if you show longer strings like "1d 23h ago" */
}

/* iOS notch / safe area support: gently push hero content below the notch in standalone mode */
@supports(padding-top: env(safe-area-inset-top)) {
  /* Add only a small offset so large screens are unaffected */
  .dashboard-hero { padding-top: calc(env(safe-area-inset-top) + 0.35rem); }

  /* Tighten on very small phones so we do not waste vertical space */
  @media (max-width: 480px) {
    .dashboard-hero { padding-top: calc(env(safe-area-inset-top) + 0.25rem); }
  }

  /* If we detect a Dynamic Island style device, increase clearance */
  .dynamic-island .dashboard-hero { padding-top: calc(env(safe-area-inset-top) + 1.15rem); }
  @media (max-width: 480px) {
    .dynamic-island .dashboard-hero { padding-top: calc(env(safe-area-inset-top) + 0.9rem); }
  }
}

/* Global futuristic font stack */
body, button, input, textarea, select {
  font-family: 'Space Grotesk', 'Orbitron', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  letter-spacing: .2px;
}

.time-ago {
  display: inline-block;
  width: calc(var(--time-ago-ch) * 1ch);
  text-align: right;
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* Helpful utility if you have other numeric cells */
.numeric {
  font-variant-numeric: tabular-nums lining-nums;
  font-feature-settings: "tnum" 1, "lnum" 1;
}

/* Responsive YouTube embed (16:9) */
.yt-embed {
  position: relative;
  padding-top: 56.25%;
  margin-bottom: 12px;
  background: #000;
  border-radius: 14px; /* match card softer radius */
  overflow: hidden;
}
.yt-embed .yt-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}
.yt-embed .yt-open {
  position: absolute;
  right: 8px;
  bottom: 8px;
  background: rgba(0,0,0,.55);
  color: #fff;
  text-decoration: none;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
}
.yt-embed .yt-open:hover { background: rgba(0,0,0,.75); }

/* Custom overlay badge */
.yt-embed .yt-badge {
  position: absolute;
  left: 12px;
  top: 12px;
  background: linear-gradient(135deg, rgba(120,90,255,0.85), rgba(60,150,255,0.85));
  color: #fff;
  font-size: .65rem;
  letter-spacing: .8px;
  text-transform: uppercase;
  padding: 6px 10px 5px;
  border-radius: 999px;
  font-weight: 600;
  box-shadow: 0 2px 6px -2px rgba(0,0,0,.6), 0 0 0 1px rgba(255,255,255,0.12);
  pointer-events: none;
  backdrop-filter: blur(2px) saturate(140%);
}

.app-hero-icon {
  text-align: center;
}

.hero-icon-img {
  display: inline-block;
  width: 180px;
  max-width: 55%;
  height: auto;
  aspect-ratio: 1 / 1;
  border-radius: 28px;
  background: radial-gradient(circle at 45% 40%, rgba(255,255,255,0.07), rgba(255,255,255,0) 60%);
  box-shadow:
    0 4px 12px rgba(0,0,0,0.4),
    0 0 0 1px rgba(255,255,255,0.05),
    0 0 22px -4px #5B5BFF;
  transition: transform .4s cubic-bezier(.22,.8,.24,1), box-shadow .4s;
  pointer-events: none;
}

/* Enhanced dashboard hero layout */
/* Dashboard hero: permanently stacked & centered (remove wide-screen side-by-side) */
.dashboard-hero {
  display: block;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding-bottom: .6rem;  /* increased breathing room above divider (was .05rem) */
  margin-bottom: .5rem;   /* space below divider before status line (was .18rem) */
}

/* Center icon block */
.dashboard-hero .hero-media { margin: 0 auto 1.05rem; }

/* Natural width text */
.dashboard-hero .hero-text { max-width: 100%; margin: 0 auto; }

* {
  font-family: 'Orbitron', 'Space Grotesk', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  letter-spacing: 1.5px;
  font-weight: 600;
  text-transform: uppercase;
}

.app-title {
  font-weight: 600;
  font-size: clamp(1.9rem, 2.6vw + 1rem, 2.55rem);
  line-height: 1.08;
}

.app-tagline {
  font-size: .95rem;
  letter-spacing: .25px;
  margin: 0 0 .12rem; /* even smaller gap below tagline */
}

/* Simplified circular icon (remove framed boxes) */
.app-hero-icon {
  position: relative;
  padding: 0; /* no frame padding */
  border-radius: 50%;
  background: none;
  box-shadow: none;
  backdrop-filter: none;
}

.app-hero-icon::after { content: none; }

/* Circular icon with glow */
.hero-icon-img {
  width: 200px;
  max-width: 40vw;
  border-radius: 50%;
  background: #0d1020 radial-gradient(circle at 45% 40%, rgba(255,255,255,0.08), rgba(255,255,255,0) 60%);
  box-shadow:
    0 0 0 2px rgba(255,255,255,0.05),
    0 0 30px 10px rgba(120,90,255,0.55),
    0 0 60px 24px rgba(60,150,255,0.35);
  transition: transform .45s cubic-bezier(.22,.8,.24,1), box-shadow .45s;
  animation: velaGlow 5.5s ease-in-out infinite;
}

@media (hover:hover) {
  .app-hero-icon:hover .hero-icon-img {
    transform: translateY(-2px) scale(1.04);
    box-shadow:
      0 0 0 2px rgba(255,255,255,0.08),
      0 0 40px 14px rgba(140,110,255,0.75),
      0 0 70px 28px rgba(60,170,255,0.55);
  }
}

@media (max-width: 640px) {
  /* Only scale sizes on small screens now */
  .app-title { font-size: 2rem; line-height: 1.12; margin-bottom: .4rem; }
  .app-tagline { font-size: .9rem; margin: 0; }
  .hero-icon-img { width: 160px; }
}

/* Fine tune spacing of status line and tabs */
#wsStatus { margin-top: 0 !important; margin-bottom: .25rem !important; line-height:1.05; font-size:.8rem; }
.nav-tabs { margin-bottom: .75rem; }

/* Slightly reduce top padding of card body overall */
.card > .card-body { padding-top: 1.4rem; }
@media (max-width: 640px) { .card > .card-body { padding-top: 1.1rem; } }

/* (Removed gradient spacer beneath hero to minimize visual gap) */

/* Ultra-small phones & rigorous space optimization */
@media (max-width: 480px) {
  .hero-icon-img { width: 132px; }
  .app-title { font-size: 1.72rem; }
  .app-tagline { font-size: .82rem; }
}

@media (max-width: 360px) {
  .hero-icon-img { width: 118px; }
  .app-title { font-size: 1.55rem; }
  .app-tagline { font-size: .78rem; }
}

/* Page ambient background enhancement (card remains primary) */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 25% 18%, rgba(90,80,255,0.12), transparent 55%),
    radial-gradient(circle at 80% 70%, rgba(40,180,255,0.08), transparent 60%);
  opacity: .9;
  mix-blend-mode: plus-lighter;
  z-index: -1;
}

/* Card subtle glass refinement */
.card.shadow-sm {
  background: linear-gradient(150deg, rgba(35,35,45,0.88), rgba(25,25,32,0.88) 55%, rgba(22,26,32,0.9));
  backdrop-filter: blur(6px) saturate(140%);
  border: 1px solid rgba(255,255,255,0.06);
}

/* Tabs refinement */
.nav-tabs .nav-link {
  border: none;
  color: #b5c2d6;
  font-weight: 500;
  position: relative;
  background: transparent;
}
.nav-tabs .nav-link:hover { color: #d7e2ef; }
.nav-tabs .nav-link.active {
  color: #fff;
  background: linear-gradient(135deg, rgba(100,80,255,0.28), rgba(60,150,255,0.28));
  border-radius: 10px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.05), 0 2px 6px -2px rgba(0,0,0,0.6);
}
.nav-tabs { border-bottom: 1px solid rgba(255,255,255,0.08); }

/* Table tweaks */
table.table { --row-accent-bg: rgba(255,255,255,0.03); }
.table-striped > tbody > tr:nth-of-type(odd) > * { background: rgba(255,255,255,0.015) !important; }
.table-active > * { background: rgba(255,255,255,0.04) !important; }
table.table td, table.table th { border-color: rgba(255,255,255,0.08) !important; }

/* Sticky section headers within scroll (if table becomes tall) */
.table-responsive { max-height: 68vh; overflow: auto; }
.table-responsive .table-active:first-child { position: sticky; top: 0; z-index: 2; }
.table-active { font-size: .8rem; letter-spacing: .5px; text-transform: uppercase; }

/* Metric value cell subtle background bar driven by data-sum (relative scaling) */
td.hm-value {
  position: relative;
  font-variant-numeric: tabular-nums;
}
td.hm-value::before {
  content: "";
  position: absolute;
  inset: 4px 4px 4px 0;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(100,140,255,0.18), rgba(100,140,255,0));
  opacity: 0; /* default hidden until JS sets scale var */
  transform-origin: left center;
  transform: scaleX(var(--bar-scale, 0));
  transition: transform .6s ease, opacity .4s ease;
  pointer-events: none;
}
td.hm-value[data-sum] { --max-sum: 1; }
/* We'll compute max dynamically in a future enhancement; for now approximate via attr() not supported for calc widths -> simple reveal */
td.hm-value[data-sum]::before { opacity: .55; }

/* Row hover */
tbody tr[data-hae-type-row="1"]:hover td { background-color: rgba(255,255,255,0.035) !important; }

/* Compact age column styling */
td.hm-age .time-ago { font-size: .75rem; opacity: .8; }

/* Status indicator inline */
#wsStatus::before {
  content: "";
  display: inline-block;
  width: .55rem;
  height: .55rem;
  margin-right: .4rem;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff7a45, #ffb070);
  box-shadow: 0 0 0 2px rgba(255,122,69,0.25);
  animation: pulse 1.2s ease-in-out infinite;
}
#wsStatus:contains('Connected')::before {
  background: linear-gradient(135deg, #28d058, #5ddcff);
  box-shadow: 0 0 0 2px rgba(70,200,120,0.25);
}

@keyframes pulse {
  0%,100% { transform: scale(.9); opacity: .65; }
  50% { transform: scale(1.15); opacity: 1; }
}

/* Hero glow breathing */
@keyframes velaGlow {
  0% { box-shadow: 0 0 0 2px rgba(255,255,255,0.05), 0 0 28px 6px rgba(120,90,255,0.5), 0 0 50px 18px rgba(60,150,255,0.28); }
  45% { box-shadow: 0 0 0 2px rgba(255,255,255,0.07), 0 0 38px 12px rgba(140,110,255,0.7), 0 0 72px 28px rgba(60,170,255,0.45); }
  100% { box-shadow: 0 0 0 2px rgba(255,255,255,0.05), 0 0 28px 6px rgba(120,90,255,0.5), 0 0 50px 18px rgba(60,150,255,0.28); }
}

/* Utility: monospace-ish numeric columns already handled with .numeric */

/* Reduce bottom spacing when tables stack */
metrics-dashboard table { margin-bottom: 1.25rem; }

@media (hover:hover) {
  .app-hero-icon:hover .hero-icon-img {
    transform: scale(1.04);
    box-shadow:
      0 6px 18px rgba(0,0,0,0.48),
      0 0 0 1px rgba(255,255,255,0.07),
      0 0 26px -2px #6E66FF;
  }
}