/**
 * Suniar Liquid Glass — Apple “Adopting Liquid Glass” aligned
 *
 * Layer model:
 *  1) Content layer — readable surfaces, no liquid material
 *  2) Chrome layer — nav / docks / sheets (liquid + refraction)
 *  3) Control layer — buttons & pickers (soft frost only)
 *
 * Avoid overuse: glass elevates chrome so underlying content can shine.
 */

:root {
  --lg-ambient-base: #E8EEF6;
  --lg-ambient-mid: #F1F5FA;
  --lg-ambient-deep: #DDE6F2;
  --lg-blob-blue: rgba(32, 64, 152, 0.12);
  --lg-blob-teal: rgba(56, 140, 168, 0.08);
  --lg-blob-slate: rgba(90, 110, 140, 0.07);
  --lg-blob-gold: rgba(248, 184, 16, 0.04);

  /* Material — subtle; content stays primary */
  --lg-blur: 4px;
  --lg-blur-soft: 12px;
  --lg-saturate: 155%;
  --lg-tint: rgba(255, 255, 255, 0.16);
  --lg-tint-soft: rgba(255, 255, 255, 0.2);
  --lg-tint-active: color-mix(in srgb, #204098 18%, rgba(255, 255, 255, 0.28));
  --lg-tint-fab: color-mix(in srgb, #F8B810 58%, rgba(255, 255, 255, 0.34));
  --lg-tint-sheet: rgba(255, 255, 255, 0.28);
  --lg-shine-tl: rgba(255, 255, 255, 0.5);
  --lg-shine-br: rgba(255, 255, 255, 0.16);
  --lg-border: rgba(255, 255, 255, 0.42);
  --lg-border-strong: rgba(255, 255, 255, 0.55);

  --lg-content-bg: color-mix(in srgb, #FFFFFF 78%, transparent);
  --lg-content-border: color-mix(in srgb, #204098 8%, rgba(255, 255, 255, 0.55));

  --lg-radius: 1.5rem;
  --lg-radius-md: 1.25rem;
  --lg-radius-sm: 1.05rem;
  --lg-radius-pill: 999px;
  --lg-dock-radius: 1.75rem;

  --lg-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --lg-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --lg-dur-fast: 220ms;
  --lg-dur: 420ms;
  --lg-drift: 56s;
  --lg-shine: 12s;
  --lg-breathe: 12s;
}

html.dark {
  --lg-ambient-base: #0B1426;
  --lg-ambient-mid: #101A32;
  --lg-ambient-deep: #0E1630;
  --lg-blob-blue: rgba(80, 120, 200, 0.14);
  --lg-blob-teal: rgba(70, 150, 170, 0.08);
  --lg-blob-slate: rgba(40, 55, 90, 0.2);
  --lg-blob-gold: rgba(248, 184, 16, 0.04);
  --lg-tint: rgba(255, 255, 255, 0.06);
  --lg-tint-soft: rgba(255, 255, 255, 0.08);
  --lg-tint-active: color-mix(in srgb, #F8B810 18%, rgba(255, 255, 255, 0.05));
  --lg-tint-fab: color-mix(in srgb, #F8B810 55%, rgba(255, 255, 255, 0.08));
  --lg-tint-sheet: rgba(22, 32, 68, 0.72);
  --lg-shine-tl: rgba(255, 255, 255, 0.14);
  --lg-shine-br: rgba(255, 255, 255, 0.04);
  --lg-border: rgba(255, 255, 255, 0.12);
  --lg-border-strong: rgba(255, 255, 255, 0.2);
  --lg-content-bg: color-mix(in srgb, #162044 82%, transparent);
  --lg-content-border: rgba(255, 255, 255, 0.1);
}

.liquidGlass-svgDefs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
  pointer-events: none;
}

/* ═══════════════════════════════════════════
   PAGE CANVAS — content peeks through chrome
   ═══════════════════════════════════════════ */
body[data-theme-root],
body[data-page],
body.app-mobile-shell,
body.app-shell-body {
  background:
    radial-gradient(ellipse 85% 65% at 6% -8%, var(--lg-blob-blue), transparent 55%),
    radial-gradient(ellipse 70% 50% at 96% 8%, var(--lg-blob-teal), transparent 50%),
    radial-gradient(ellipse 55% 40% at 48% 100%, var(--lg-blob-slate), transparent 55%),
    radial-gradient(ellipse 40% 30% at 78% 72%, var(--lg-blob-gold), transparent 60%),
    linear-gradient(168deg, var(--lg-ambient-deep) 0%, var(--lg-ambient-mid) 46%, var(--lg-ambient-base) 100%) !important;
  background-attachment: fixed;
}

body[data-theme-root]::before,
body[data-theme-root]::after {
  content: "";
  position: fixed;
  inset: -18%;
  pointer-events: none;
  z-index: 0;
}

body[data-theme-root]::before {
  background:
    radial-gradient(circle 38% at 18% 24%, var(--lg-blob-blue), transparent 62%),
    radial-gradient(circle 32% at 82% 70%, var(--lg-blob-teal), transparent 60%);
  animation: lg-ambient-a var(--lg-drift) var(--lg-ease) infinite alternate;
  opacity: 0.75;
}

body[data-theme-root]::after {
  background:
    radial-gradient(circle 34% at 72% 18%, var(--lg-blob-slate), transparent 58%),
    radial-gradient(circle 28% at 28% 78%, var(--lg-blob-blue), transparent 62%);
  animation: lg-ambient-b calc(var(--lg-drift) * 1.15) var(--lg-ease) infinite alternate-reverse;
  opacity: 0.6;
}

@keyframes lg-ambient-a {
  0%   { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-1.5%, 2%) scale(1.05); }
}

@keyframes lg-ambient-b {
  0%   { transform: translate(0, 0) scale(1.02); }
  100% { transform: translate(2%, -1%) scale(1.03); }
}

body[data-theme-root] .min-h-screen {
  position: relative;
  z-index: 1;
}

/* ═══════════════════════════════════════════
   CONTENT LAYER — no liquid material
   ═══════════════════════════════════════════ */
.lg-content-surface,
.dashboard-panel:not(.liquidGlass-wrapper),
.linear-panel:not(.liquidGlass-wrapper),
.linear-card:not(.liquidGlass-wrapper),
.dashboard-metric-card:not(.liquidGlass-wrapper),
.device-tile:not(.liquidGlass-wrapper),
.weather-card:not(.liquidGlass-wrapper),
.dashboard-insight-card:not(.liquidGlass-wrapper) {
  background: var(--lg-content-bg) !important;
  background-image: none !important;
  border: 1px solid var(--lg-content-border) !important;
  box-shadow: none !important;
  border-radius: var(--lg-radius-md);
  backdrop-filter: blur(8px) saturate(140%);
  -webkit-backdrop-filter: blur(8px) saturate(140%);
}

.dashboard-metric-card:not(.liquidGlass-wrapper),
.device-tile:not(.liquidGlass-wrapper),
.weather-card:not(.liquidGlass-wrapper) {
  border-radius: var(--lg-radius-sm);
}

/* Kill leftover glass ornaments on content */
.lg-content-surface.dashboard-panel::before,
.lg-content-surface.dashboard-panel::after,
.dashboard-panel:not(.liquidGlass-wrapper)::before,
.dashboard-panel:not(.liquidGlass-wrapper)::after {
  content: none !important;
  display: none !important;
}

/* ═══════════════════════════════════════════
   CHROME / CONTROL — Liquid Glass material
   ═══════════════════════════════════════════ */
.liquidGlass-wrapper {
  position: relative !important;
  isolation: isolate;
  background: transparent !important;
  background-image: none !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  border: 1px solid var(--lg-border) !important;
  box-shadow: none !important;
  border-radius: var(--lg-radius-md) !important;
  overflow: visible;
  transition:
    border-color var(--lg-dur-fast) var(--lg-ease),
    transform var(--lg-dur) var(--lg-ease);
}

/* Docks must stay viewport-fixed — never inherit position:relative from wrapper */
.liquidGlass-wrapper.liquidGlass-wrapper--dock.app-bottom-nav,
.liquidGlass-wrapper.liquidGlass-wrapper--dock.app-bottom-nav--taskbar,
.liquidGlass-wrapper.liquidGlass-wrapper--fixed-chrome.chart-mobile-action-bar,
.liquidGlass-wrapper.chart-mobile-action-bar {
  position: fixed !important;
}

.liquidGlass-wrapper.app-header,
.liquidGlass-wrapper.dashboard-topbar {
  /* Sticky/fixed chrome — never force relative from glass base */
  position: sticky !important;
}

@media (max-width: 760px) {
  body.app-mobile-shell .liquidGlass-wrapper.app-header,
  body.app-mobile-shell .liquidGlass-wrapper.dashboard-topbar {
    position: fixed !important;
  }
}

.liquidGlass-wrapper.app-bottom-nav__cluster,
.liquidGlass-wrapper.app-bottom-nav__menu-slot {
  position: relative !important;
  border: 0 !important;
  border-radius: 999px !important;
}

/* Section tabs must stay sticky under the top bar — not relative */
.liquidGlass-wrapper.dashboard-section-nav,
.liquidGlass-wrapper.dashboard-section-nav.liquidGlass-wrapper--dock,
.liquidGlass-wrapper.dashboard-section-nav.liquidGlass-wrapper--sheet {
  position: sticky !important;
}

.liquidGlass-wrapper--soft { border-radius: var(--lg-radius-sm) !important; }
.liquidGlass-wrapper--pill { border-radius: var(--lg-radius-pill) !important; }
.liquidGlass-wrapper--dock { border-radius: var(--lg-dock-radius) !important; }
.liquidGlass-wrapper--dock.app-bottom-nav__cluster,
.liquidGlass-wrapper--dock.app-bottom-nav__menu-slot {
  border-radius: 999px !important;
  border: 0 !important;
}
.liquidGlass-wrapper--sheet { border-radius: var(--lg-radius) !important; }

.liquidGlass-effect,
.liquidGlass-tint,
.liquidGlass-shine {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  overflow: hidden;
}

.liquidGlass-effect {
  z-index: -3;
  backdrop-filter: blur(var(--lg-blur)) saturate(var(--lg-saturate));
  -webkit-backdrop-filter: blur(var(--lg-blur)) saturate(var(--lg-saturate));
  filter: url(#glass-distortion);
  isolation: isolate;
}

.liquidGlass-tint {
  z-index: -2;
  background: var(--lg-tint);
  animation: lg-tint-breathe var(--lg-breathe) var(--lg-ease) infinite alternate;
}

.liquidGlass-shine {
  z-index: -1;
  box-shadow:
    inset 1.5px 1.5px 0 0 var(--lg-shine-tl),
    inset -1px -1px 0 0 var(--lg-shine-br);
}

/* Soft controls — frost only (Apple: spare custom glass) */
.liquidGlass-wrapper--soft > .liquidGlass-effect {
  filter: none;
  backdrop-filter: blur(var(--lg-blur-soft)) saturate(150%);
  -webkit-backdrop-filter: blur(var(--lg-blur-soft)) saturate(150%);
}

.liquidGlass-wrapper--soft > .liquidGlass-tint {
  background: var(--lg-tint-soft);
  animation: none;
}

.liquidGlass-wrapper--soft > .liquidGlass-shine::after {
  display: none;
}

/* Sheets denser when focused (Apple half→full sheet cue) */
.liquidGlass-wrapper--sheet > .liquidGlass-tint {
  background: var(--lg-tint-sheet);
  animation: none;
}

.liquidGlass-wrapper--sheet > .liquidGlass-effect {
  backdrop-filter: blur(18px) saturate(160%);
  -webkit-backdrop-filter: blur(18px) saturate(160%);
}

.liquidGlass-shine::after {
  content: "";
  position: absolute;
  inset: -20% -40%;
  background: linear-gradient(
    105deg,
    transparent 42%,
    rgba(255, 255, 255, 0.18) 50%,
    transparent 58%
  );
  animation: lg-shine-sweep var(--lg-shine) var(--lg-ease) infinite;
  opacity: 0.4;
}

@keyframes lg-shine-sweep {
  0%   { transform: translateX(-28%) skewX(-8deg); opacity: 0; }
  15%  { opacity: 0.4; }
  100% { transform: translateX(28%) skewX(-8deg); opacity: 0; }
}

@keyframes lg-tint-breathe {
  from { opacity: 0.9; }
  to   { opacity: 1; }
}

/* GlassEffectContainer — group toolbar controls without stacking glass-on-glass */
.liquidGlass-container,
.dashboard-panel-controls,
.app-header-toolbar-group--actions,
.dashboard-topbar-main-actions,
.dashboard-topbar-ops {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2, 0.5rem);
}

.liquidGlass-container > .liquidGlass-wrapper,
.dashboard-panel-controls > .liquidGlass-wrapper,
.dashboard-topbar-ops > .liquidGlass-wrapper {
  /* Shared visual group: avoid crowding */
  margin: 0;
}

@media (hover: hover) and (pointer: fine) {
  .liquidGlass-wrapper--soft.app-control:hover,
  .liquidGlass-wrapper--soft.suniar-dropdown-trigger:hover,
  .liquidGlass-wrapper--soft.dashboard-topbar-icon-button:hover,
  .liquidGlass-wrapper--soft.app-bottom-nav__icon-wrap:hover {
    transform: scale(1.04);
    border-color: var(--lg-border-strong) !important;
  }
}

/* Active states */
.liquidGlass-wrapper.is-active > .liquidGlass-tint,
.app-bottom-nav__item.is-active .liquidGlass-wrapper > .liquidGlass-tint,
.dashboard-section-nav__item.is-active .liquidGlass-wrapper > .liquidGlass-tint,
.dashboard-range-btn.is-active.liquidGlass-wrapper > .liquidGlass-tint,
.linear-sidebar-link.is-active.liquidGlass-wrapper > .liquidGlass-tint {
  background: var(--lg-tint-active) !important;
  animation: none;
}

.app-bottom-nav__item:not(.is-active) { opacity: 0.7; }
.app-bottom-nav__item.is-active { opacity: 1; }

.app-bottom-nav__icon-wrap--fab.liquidGlass-wrapper > .liquidGlass-tint,
.app-bottom-nav__item--fab .app-bottom-nav__icon-wrap.liquidGlass-wrapper > .liquidGlass-tint {
  background: var(--lg-tint-fab) !important;
  animation: none;
}

.dashboard-topbar-ops-chip--alert.is-alerting.liquidGlass-wrapper > .liquidGlass-tint {
  background: color-mix(in srgb, #E74C3C 22%, rgba(255, 255, 255, 0.2)) !important;
  animation: none;
}

/* ═══════════════════════════════════════════
   SCROLL EDGE — legibility under sticky chrome
   ═══════════════════════════════════════════ */
@media (max-width: 760px) {
  body.app-mobile-shell .app-header.liquidGlass-wrapper,
  body.app-mobile-shell .dashboard-topbar.liquidGlass-wrapper {
    position: fixed !important;
    top: max(0.35rem, env(safe-area-inset-top, 0px)) !important;
    margin-top: 0 !important;
    margin-inline: 0.75rem !important;
  }

  /* Fade content that scrolls under the bar (scroll edge effect) */
  body.app-mobile-shell .app-header.liquidGlass-wrapper::after,
  body.app-mobile-shell .dashboard-topbar.liquidGlass-wrapper::after {
    display: none !important;
  }

  body.app-mobile-shell .app-header-page-badge {
    display: inline-flex !important;
    align-items: center;
    max-width: 7.5rem;
    min-height: 1.35rem;
    padding: 0.12rem 0.5rem;
    font-size: 0.62rem;
    font-weight: 800;
    color: #204098;
    border-radius: var(--lg-radius-pill) !important;
  }

  html.dark body.app-mobile-shell .app-header-page-badge {
    color: #F8B810;
  }

  .app-bottom-nav,
  .app-bottom-nav--taskbar {
    /* Shell is transparent; material lives on __cluster / __menu-slot (app-nav.css) */
    display: flex !important;
    position: fixed !important;
    inset-inline: var(--app-nav-inset, 0.5rem) !important;
    bottom: calc(var(--app-nav-bottom, 0.4rem) + env(safe-area-inset-bottom, 0px)) !important;
    z-index: 55;
    align-items: stretch;
    justify-content: stretch;
    gap: 0.4rem;
    min-height: 0;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    overflow: visible !important;
    pointer-events: none;
  }

  .app-bottom-nav__cluster,
  .app-bottom-nav__menu-slot {
    pointer-events: auto;
    border: 0 !important;
  }

  .app-bottom-nav__icon-wrap,
  .app-bottom-nav__icon-wrap--fab {
    background: transparent !important;
  }

  .app-bottom-nav .app-liquid-tabs__blob,
  .app-bottom-nav [data-liquid-blob] {
    display: block !important;
    position: absolute;
    z-index: 0;
    border-radius: 1.05rem;
    pointer-events: none;
  }

  .app-bottom-nav__item { z-index: 1; }
}

/* Transparent chrome fills */
.liquidGlass-wrapper.app-header,
.liquidGlass-wrapper.dashboard-topbar,
.liquidGlass-wrapper.app-bottom-nav__cluster,
.liquidGlass-wrapper.app-bottom-nav__menu-slot,
.liquidGlass-wrapper.dashboard-section-nav,
.liquidGlass-wrapper.dashboard-sidebar-shell,
.liquidGlass-wrapper.dashboard-modal-content,
.liquidGlass-wrapper.dashboard-notification-panel,
.liquidGlass-wrapper.app-control,
.liquidGlass-wrapper.suniar-dropdown-trigger,
.liquidGlass-wrapper.dashboard-topbar-icon-button {
  background: transparent !important;
  box-shadow: none !important;
}

.liquidGlass-wrapper.app-bottom-nav__cluster,
.liquidGlass-wrapper.app-bottom-nav__menu-slot {
  border: 0 !important;
}

.liquidGlass-wrapper.app-bottom-nav__cluster > .liquidGlass-shine,
.liquidGlass-wrapper.app-bottom-nav__menu-slot > .liquidGlass-shine {
  box-shadow: none !important;
}

/* ═══════════════════════════════════════════
   ACCESSIBILITY — Apple settings parity
   ═══════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
  body[data-theme-root]::before,
  body[data-theme-root]::after,
  .liquidGlass-tint,
  .liquidGlass-shine::after,
  .liquidGlass-wrapper,
  .app-bottom-nav .app-liquid-tabs__blob {
    animation: none !important;
    transition: none !important;
  }

  .liquidGlass-effect {
    filter: none !important;
  }

  .liquidGlass-wrapper {
    transform: none !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .liquidGlass-effect {
    filter: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  .liquidGlass-tint {
    background: color-mix(in srgb, var(--surface, #fff) 92%, transparent) !important;
    animation: none !important;
  }

  html.dark .liquidGlass-tint {
    background: color-mix(in srgb, var(--surface, #162044) 92%, transparent) !important;
  }

  .lg-content-surface,
  .dashboard-panel:not(.liquidGlass-wrapper),
  .linear-panel:not(.liquidGlass-wrapper) {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: var(--surface, #fff) !important;
  }

  html.dark .lg-content-surface,
  html.dark .dashboard-panel:not(.liquidGlass-wrapper) {
    background: var(--surface, #162044) !important;
  }
}
