/**
 * Hub `/` — iPadOS SpringBoard Home Screen
 * Status · App grid · Dock · App Library
 * Scoped under .sd-desktop--hub-ios / .ios-home
 */

/* ── Tokens ─────────────────────────────────────────────────── */
.sd-desktop--hub-ios {
  --ios-home-icon: 76px;
  --ios-home-gap: 28px;
  --ios-home-label: 12px;
  --ios-home-radius-squircle: 22.37%;
  --ios-home-blur: 28px;
  --ios-home-cols: 4;
  --ios-home-pad-x: clamp(20px, 4vw, 48px);
  --ios-home-pad-top: 28px;
  --ios-home-label-color: #fff;
  --ios-home-label-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  --ios-home-badge: #ff453a;
  --ios-parallax-x: 0%;
  --ios-parallax-y: 0%;
}

html:not([data-theme="dark"]) .sd-desktop--hub-ios {
  --ios-home-label-color: rgba(20, 28, 40, 0.92);
  --ios-home-label-shadow: 0 1px 1px rgba(255, 255, 255, 0.55);
  --ios-home-badge: #ff3b30;
}

/*
 * SpringBoard full-bleed wallpaper.
 * trn-dock-ios shortens generic `.sd-desktop` above the floating Dock capsule;
 * that left a body `--sd-bg` letterbox under/around the Dock. Hub must paint
 * edge-to-edge; content still clears Dock via `.ios-home` + `--sd-chrome-bottom`.
 */
.sd-desktop--hub.sd-desktop--hub-ios {
  bottom: 0;
}

/* Parallax wallpaper */
.sd-desktop--hub.sd-desktop--hub-ios::before {
  inset: 0;
  min-height: 100%;
  background-position:
    calc(50% + var(--ios-parallax-x)) calc(50% + var(--ios-parallax-y));
  background-size: cover, auto;
  background-repeat: no-repeat, no-repeat;
  transition: background-position 120ms linear;
}

.sd-desktop--hub.sd-desktop--hub-ios::after {
  inset: 0;
}

.sd-desktop--hub-ios.ios-parallax-active::before {
  transition: none;
}

/* Kill legacy hub chrome */
.sd-desktop--hub-ios .sd-hub-stage,
.sd-desktop--hub-ios.has-widgets .sd-hub-stage,
.sd-desktop--hub-ios .sd-desktop-widgets {
  display: none !important;
}

/* ── Root shell ─────────────────────────────────────────────── */
.sd-desktop--hub-ios .ios-home {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 100%;
  box-sizing: border-box;
  padding:
    calc(var(--ios-home-pad-top) + env(safe-area-inset-top, 0px))
    var(--ios-home-pad-x)
    calc(var(--sd-chrome-bottom, 48px) + 20px + env(safe-area-inset-bottom, 0px));
  overscroll-behavior: contain;
}

/* ── Status (calm, centered) ────────────────────────────────── */
.ios-home__status {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  flex: 0 0 auto;
  width: 100%;
  max-width: 720px;
  margin: 0 auto 8px;
  padding: 0 52px;
}

.ios-home__status-main {
  min-width: 0;
}

.ios-home__time {
  display: block;
  font-family: Inter, Manrope, system-ui, sans-serif;
  font-weight: 200;
  font-size: clamp(44px, 5.5vw, 72px);
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--ios-home-label-color);
  text-shadow: var(--ios-home-label-shadow);
  font-variant-numeric: tabular-nums;
}

.ios-home__date {
  margin: 6px 0 0;
  font-size: clamp(15px, 1.4vw, 18px);
  font-weight: 600;
  color: var(--ios-home-label-color);
  text-shadow: var(--ios-home-label-shadow);
}

.ios-home__greet {
  margin: 4px 0 0;
  font-size: clamp(13px, 1.15vw, 15px);
  font-weight: 400;
  color: var(--ios-home-label-color);
  opacity: 0.78;
  text-shadow: var(--ios-home-label-shadow);
}

.ios-home__library-btn {
  position: absolute;
  top: 4px;
  right: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  min-width: 44px;
  min-height: 44px;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.14);
  color: var(--ios-home-label-color);
  backdrop-filter: blur(16px) saturate(160%);
  -webkit-backdrop-filter: blur(16px) saturate(160%);
  cursor: pointer;
  transition: transform 100ms ease-out, background 160ms ease;
}

.ios-home__library-btn:hover {
  background: rgba(255, 255, 255, 0.26);
}

.ios-home__library-btn:active {
  transform: scale(0.92);
}

.ios-home__library-btn:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: 2px;
}

html:not([data-theme="dark"]) .ios-home__library-btn {
  background: rgba(255, 255, 255, 0.5);
}

/* ── Pages / apps grid ──────────────────────────────────────── */
.ios-home__pages {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
}

.ios-home__page {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.ios-home__apps {
  display: grid;
  grid-template-columns: repeat(var(--ios-home-cols), minmax(0, 1fr));
  gap: var(--ios-home-gap) calc(var(--ios-home-gap) * 0.75);
  justify-items: center;
  align-content: center;
  width: 100%;
  max-width: min(920px, 100%);
  margin-inline: auto;
}

/* ── App squircle + label ───────────────────────────────────── */
.ios-home__app {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: 100%;
  max-width: calc(var(--ios-home-icon) + 32px);
  padding: 4px;
  text-decoration: none;
  color: inherit;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
  border-radius: 16px;
}

.ios-home__app:focus-visible {
  outline: none;
}

.ios-home__app:focus-visible .ios-home__app-icon {
  box-shadow:
    0 0 0 2px var(--module-color, #13c6d5),
    0 8px 20px rgba(0, 0, 0, 0.28);
}

.ios-home__app:focus-visible .ios-home__app-icon.ios-home__app-icon--image {
  box-shadow: none;
  outline: 2px solid var(--module-color, #13c6d5);
  outline-offset: 3px;
}

.ios-home__app-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--ios-home-icon);
  height: var(--ios-home-icon);
  border: 0;
  border-radius: var(--ios-home-radius-squircle);
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.22), transparent 55%),
    rgba(18, 28, 42, 0.55);
  box-shadow:
    0 6px 16px rgba(0, 0, 0, 0.28),
    inset 0 0.5px 0 rgba(255, 255, 255, 0.28);
  overflow: hidden;
  transition:
    transform 100ms ease-out,
    filter 100ms ease-out,
    box-shadow 160ms ease;
}

html:not([data-theme="dark"]) .ios-home__app-icon {
  background:
    linear-gradient(160deg, rgba(255, 255, 255, 0.65), transparent 50%),
    rgba(240, 244, 248, 0.92);
  box-shadow:
    0 4px 12px rgba(20, 40, 60, 0.16),
    inset 0 0.5px 0 rgba(255, 255, 255, 0.8);
}

.ios-home__app-icon img {
  width: 78%;
  height: 78%;
  object-fit: contain;
  pointer-events: none;
}

/* PNG emblems already include squircle — no CSS well / ring / inset frame */
.ios-home__app-icon.ios-home__app-icon--image {
  background: transparent;
  box-shadow: none;
  overflow: visible;
  border-radius: 0;
}

html:not([data-theme="dark"]) .ios-home__app-icon.ios-home__app-icon--image {
  background: transparent;
  box-shadow: none;
}

.ios-home__app-icon.ios-home__app-icon--image img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.32));
}

html:not([data-theme="dark"]) .ios-home__app-icon.ios-home__app-icon--image img {
  filter: drop-shadow(0 4px 10px rgba(20, 40, 60, 0.18));
}

.ios-home__app-icon .bi {
  font-size: calc(var(--ios-home-icon) * 0.42);
  color: var(--module-color-bright, var(--module-color, #13c6d5));
}

.ios-home__app .sd-module-icon--on-light {
  display: none;
}

html:not([data-theme="dark"]) .ios-home__app .sd-module-icon--on-dark {
  display: none;
}

html:not([data-theme="dark"]) .ios-home__app .sd-module-icon--on-light {
  display: block;
}

.ios-home__app:active .ios-home__app-icon,
.ios-home__app.is-pressed .ios-home__app-icon {
  transform: scale(0.92);
  filter: brightness(1.12);
}

.ios-home__app-label {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  width: 100%;
  max-width: calc(var(--ios-home-icon) + 24px);
  text-align: center;
  font-size: var(--ios-home-label);
  font-weight: 500;
  line-height: 1.2;
  color: var(--ios-home-label-color);
  text-shadow: var(--ios-home-label-shadow);
  word-break: break-word;
}

/* Live badge */
.ios-home__badge {
  position: absolute;
  top: 0;
  right: 0;
  transform: translate(25%, -25%);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--ios-home-badge);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  z-index: 2;
}

/* Widget enter → app enter */
@media (prefers-reduced-motion: no-preference) {
  .ios-home__app {
    animation: ios-home-app-enter 380ms cubic-bezier(0.22, 1, 0.36, 1) both;
  }

  .ios-home__app:nth-child(1) { animation-delay: 40ms; }
  .ios-home__app:nth-child(2) { animation-delay: 70ms; }
  .ios-home__app:nth-child(3) { animation-delay: 100ms; }
  .ios-home__app:nth-child(4) { animation-delay: 130ms; }
  .ios-home__app:nth-child(5) { animation-delay: 160ms; }
  .ios-home__app:nth-child(6) { animation-delay: 190ms; }
  .ios-home__app:nth-child(7) { animation-delay: 220ms; }
  .ios-home__app:nth-child(n+8) { animation-delay: 250ms; }
}

@keyframes ios-home-app-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* ── Empty state ────────────────────────────────────────────── */
.ios-home__empty {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 40px 16px;
  text-align: center;
  color: var(--ios-home-label-color);
  text-shadow: var(--ios-home-label-shadow);
}

.ios-home__empty-glyph {
  opacity: 0.55;
  margin-bottom: 4px;
}

.ios-home__empty-hint {
  margin: 0;
  font-size: 14px;
  opacity: 0.75;
  max-width: 280px;
}

/* ── App Library sheet ──────────────────────────────────────── */
.ios-home-library {
  position: fixed;
  inset: 0;
  z-index: 9400;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.ios-home-library[hidden] {
  display: none !important;
}

body.ios-home-library-open {
  overflow: hidden;
}

.ios-home-library__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  padding: 0;
  background: rgba(0, 0, 0, 0.45);
  cursor: pointer;
}

.ios-home-library__sheet {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(560px, 100%);
  max-height: min(86vh, 820px);
  border-radius: 20px 20px 0 0;
  background: rgba(28, 32, 40, 0.92);
  color: #fff;
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  animation: ios-home-sheet-up 280ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

html:not([data-theme="dark"]) .ios-home-library__sheet {
  background: rgba(248, 249, 252, 0.96);
  color: #1a1a1e;
}

@keyframes ios-home-sheet-up {
  from {
    opacity: 0.6;
    transform: translateY(24px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.ios-home-library__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 8px;
}

.ios-home-library__title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.ios-home-library__cancel {
  appearance: none;
  border: 0;
  background: transparent;
  color: #0a84ff;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 4px;
  min-height: 44px;
}

.ios-home-library__search {
  padding: 4px 16px 12px;
}

.ios-home-library__search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 12px;
  border-radius: 10px;
  background: rgba(120, 120, 128, 0.24);
}

html:not([data-theme="dark"]) .ios-home-library__search-field {
  background: rgba(120, 120, 128, 0.12);
}

.ios-home-library__search-icon {
  opacity: 0.55;
  flex-shrink: 0;
}

.ios-home-library__search-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 15px;
  outline: none;
}

body.sd-app .sd-desktop--hub-ios .ios-home-library__search-input[type="search"] {
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
  height: auto !important;
  min-height: 0 !important;
}

.ios-home-library__body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0 12px 24px;
  -webkit-overflow-scrolling: touch;
}

.ios-home-library__group {
  margin-bottom: 14px;
}

.ios-home-library__letter {
  margin: 0 8px 6px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0.55;
  text-transform: uppercase;
}

.ios-home-library__list {
  list-style: none;
  margin: 0;
  padding: 4px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.06);
}

html:not([data-theme="dark"]) .ios-home-library__list {
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.04);
}

.ios-home-library__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  min-height: 52px;
  text-decoration: none;
  color: inherit;
  border-radius: 10px;
}

.ios-home-library__row:hover {
  background: rgba(255, 255, 255, 0.08);
}

html:not([data-theme="dark"]) .ios-home-library__row:hover {
  background: rgba(0, 0, 0, 0.04);
}

.ios-home-library__row:focus-visible {
  outline: 2px solid #0a84ff;
  outline-offset: -2px;
}

.ios-home-library__row-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: var(--ios-home-radius-squircle);
  background: rgba(0, 0, 0, 0.2);
  overflow: hidden;
  flex-shrink: 0;
  color: var(--module-color, #13c6d5);
}

.ios-home-library__row-icon:has(img) {
  background: transparent;
  overflow: visible;
  border-radius: 0;
  box-shadow: none;
}

.ios-home-library__row-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.28));
}

.ios-home-library__row-label {
  font-size: 16px;
  font-weight: 500;
}

.ios-home-library__empty {
  margin: 24px 8px;
  text-align: center;
  opacity: 0.7;
  font-size: 15px;
}

@media (max-width: 720px) {
  .ios-home-library {
    align-items: stretch;
  }

  .ios-home-library__sheet {
    width: 100%;
    max-height: none;
    height: 100%;
    border-radius: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
}

/* ── Dock: always visible on hub; capsule look lives in trn-dock-ios.css ── */
.sd-desktop--hub-ios #sd-taskbar {
  display: flex !important;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 720px) {
  .sd-desktop--hub-ios {
    --ios-home-icon: 64px;
    --ios-home-gap: 18px;
    --ios-home-cols: 4;
    --ios-home-pad-top: 16px;
    --ios-home-pad-x: 20px;
    --ios-home-label: 11px;
  }

  .ios-home__status {
    padding: 0 48px;
    margin-bottom: 4px;
  }

  .ios-home__time {
    font-size: 48px;
  }

  .ios-home__page {
    justify-content: flex-start;
    padding-top: 28px;
  }
}

@media (min-width: 721px) and (max-width: 960px) {
  .sd-desktop--hub-ios {
    --ios-home-icon: 72px;
    --ios-home-gap: 24px;
    --ios-home-cols: 4;
    --ios-home-pad-top: 24px;
  }

  .ios-home__apps {
    max-width: 520px;
  }
}

@media (min-width: 961px) {
  .sd-desktop--hub-ios {
    --ios-home-icon: 78px;
    --ios-home-gap: 28px;
    --ios-home-cols: 4;
  }

  .ios-home__apps {
    max-width: 560px;
  }

  .sd-desktop--hub.sd-desktop--hub-ios {
    overflow-y: hidden;
  }
}

@media (min-width: 1280px) {
  .sd-desktop--hub-ios {
    --ios-home-cols: 4;
    --ios-home-icon: 80px;
    --ios-home-gap: 32px;
    --ios-home-pad-top: 32px;
  }

  .ios-home__apps {
    max-width: 600px;
  }

  .sd-desktop--hub.sd-desktop--hub-ios {
    overflow-y: hidden;
  }

  .sd-desktop--hub-ios .ios-home {
    height: 100%;
    max-height: 100%;
  }
}

/* 8 apps → 4×2 grid reads more like iPad Home than a single crowded row */
@media (min-width: 721px) {
  .sd-desktop--hub-ios {
    --ios-home-cols: 4;
  }
}

/* ── Reduced motion ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ios-home__app,
  .ios-home-library__sheet {
    animation: none !important;
  }

  .ios-home__app-icon,
  .ios-home__library-btn {
    transition: none !important;
  }

  .sd-desktop--hub.sd-desktop--hub-ios::before {
    transition: none !important;
  }
}

html.trn-lowend .sd-desktop--hub-ios .ios-home-library__sheet,
html.trn-lowend .sd-desktop--hub-ios #sd-taskbar,
html.trn-lowend .sd-desktop--hub-ios .ios-home__library-btn {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

html.trn-lowend .sd-desktop--hub.sd-desktop--hub-ios::before {
  --ios-parallax-x: 0% !important;
  --ios-parallax-y: 0% !important;
}

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  .ios-home__library-btn,
  .ios-home-library,
  .sd-desktop--hub-ios #sd-taskbar {
    display: none !important;
  }

  .ios-home__apps {
    break-inside: avoid;
  }
}

/* Legacy welcome fold */
.sd-desktop--hub-ios .sd-welcome--legacy {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
