/* ==========================================================================
   Layout: boot splash, desktop shell (right sidebar + top bar),
   courier mobile shell (sticky header + bottom tabs), bare layout,
   containers and grid / stack utilities.
   Breakpoints: sm 640 · md 768 · lg 1024 · xl 1280
   ========================================================================== */

#app { min-height: 100vh; min-height: 100dvh; }

/* ---- Boot splash ---------------------------------------------------- */
.boot {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-3);
  animation: fade-in var(--dur-5) var(--ease-out) both;
  animation-delay: 120ms;
}
.boot__logo { width: 56px; height: 56px; border-radius: 16px; box-shadow: var(--shadow-lg); }
.boot__name { font-weight: var(--fw-bold); font-size: var(--fs-lg); color: var(--text); letter-spacing: -0.01em; }
.boot__bar {
  position: relative;
  width: 120px;
  height: 3px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}
.boot__bar span {
  position: absolute;
  inset-block: 0;
  width: 40%;
  border-radius: inherit;
  background: var(--primary);
  animation: boot-slide 1.1s var(--ease-in-out) infinite;
}
@keyframes boot-slide {
  from { inset-inline-start: -40%; }
  to { inset-inline-start: 100%; }
}

/* ---- Shell (shared) ------------------------------------------------- */
.shell { min-height: 100vh; min-height: 100dvh; }
.shell__main { min-width: 0; outline: none; }

/* ---- Desktop shell -------------------------------------------------- */
.shell--desktop {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  transition: grid-template-columns var(--dur-4) var(--ease-out);
}
.shell--desktop.is-collapsed { grid-template-columns: var(--sidebar-w-collapsed) minmax(0, 1fr); }
.shell__body { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.shell--desktop .shell__main { flex: 1; }

/* Sidebar */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink-text);
  background:
    radial-gradient(120% 60% at 100% 0%, rgba(47, 91, 234, 0.22), transparent 60%),
    linear-gradient(180deg, var(--ink-2) 0%, var(--ink) 55%);
  border-inline-end: 1px solid var(--ink-border);
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-h);
  padding-inline: var(--space-5);
  flex-shrink: 0;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  color: inherit;
  text-decoration: none;
  min-width: 0;
}
.brand:hover { text-decoration: none; }
.brand__mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  flex-shrink: 0;
  box-shadow: 0 6px 16px -6px rgba(47, 91, 234, 0.7), inset 0 0 0 1px rgba(255, 255, 255, 0.12);
}
.brand__mark img, .brand__mark svg { width: 100%; height: 100%; border-radius: inherit; }
.brand__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand__name { font-weight: var(--fw-bold); font-size: 1.0625rem; letter-spacing: -0.01em; white-space: nowrap; }
.brand__tag { font-size: var(--fs-2xs); color: var(--ink-muted); white-space: nowrap; letter-spacing: 0.01em; }

.sidebar__nav {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--space-2) var(--space-3) var(--space-4);
  scrollbar-color: rgba(255, 255, 255, 0.14) transparent;
}
.nav-section + .nav-section { margin-top: var(--space-5); }
.nav-section__label {
  padding: 0 var(--space-3) var(--space-2);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  white-space: nowrap;
  opacity: 0.9;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 42px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-input);
  color: rgba(233, 237, 248, 0.82);
  font-weight: var(--fw-medium);
  font-size: var(--fs-sm);
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--dur-2) var(--ease-out), color var(--dur-2) var(--ease-out);
}
.nav-item + .nav-item { margin-top: 2px; }
.nav-item:hover { background: var(--ink-hover); color: #fff; text-decoration: none; }
.nav-item.is-active {
  background: var(--ink-active);
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}
.nav-item.is-active::before {
  content: "";
  position: absolute;
  inset-inline-start: calc(-1 * var(--space-3));
  top: 9px;
  bottom: 9px;
  width: 3px;
  border-start-end-radius: 3px;
  border-end-end-radius: 3px;
  background: #7C9BFF;
  box-shadow: 0 0 12px rgba(124, 155, 255, 0.8);
}
.nav-item__icon { display: grid; place-items: center; width: 22px; height: 22px; flex-shrink: 0; opacity: 0.92; }
.nav-item.is-active .nav-item__icon { color: #A9BEFF; opacity: 1; }
.nav-item__label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-item__badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-grid;
  place-items: center;
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  background: rgba(124, 155, 255, 0.22);
  color: #DCE5FF;
}
.nav-item:focus-visible { outline-color: #A9BEFF; }

.sidebar__footer {
  flex-shrink: 0;
  padding: var(--space-3);
  border-top: 1px solid var(--ink-border);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar__footer .nav-item { min-height: 38px; color: var(--ink-muted); }
.sidebar__footer .nav-item:hover { color: #fff; }

/* Collapsed rail (icons only) */
.sidebar--collapsed .sidebar__brand { padding-inline: 20px; }
.sidebar--collapsed .brand__text,
.sidebar--collapsed .nav-item__label,
.sidebar--collapsed .nav-section__label { opacity: 0; width: 0; pointer-events: none; }
.sidebar--collapsed .nav-section__label { height: 0; padding: 0; overflow: hidden; }
.sidebar--collapsed .nav-section + .nav-section { margin-top: var(--space-3); padding-top: var(--space-3); border-top: 1px solid var(--ink-border); }
.sidebar--collapsed .nav-item { justify-content: center; padding-inline: 0; }
.sidebar--collapsed .nav-item__badge {
  position: absolute;
  top: 4px;
  inset-inline-end: 8px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  font-size: 10px;
}
.sidebar--collapsed .sidebar__collapse .icon { transform: scaleX(-1); }

.sidebar-scrim { display: none; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--topbar-h);
  padding-inline: var(--page-pad);
  background: var(--surface-overlay);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--border-subtle);
}
.topbar__menu { display: none; }
.topbar__title {
  min-width: 0;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-md);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-out);
}
.topbar__title.is-visible { opacity: 1; transform: none; }
.topbar__search { flex: 1; display: flex; justify-content: flex-start; min-width: 0; }
.topbar__search > * { width: 100%; max-width: 440px; }
.topbar__actions { display: flex; align-items: center; gap: var(--space-1); margin-inline-start: auto; }
.topbar__divider { width: 1px; height: 24px; background: var(--border); margin-inline: var(--space-2); }

@media (max-width: 1023.98px) {
  .shell--desktop, .shell--desktop.is-collapsed { grid-template-columns: minmax(0, 1fr); }
  .shell--desktop .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    width: min(var(--sidebar-w), 86vw);
    transform: translateX(105%);
    transition: transform var(--dur-4) var(--ease-out), visibility 0s linear var(--dur-4);
    visibility: hidden;
    box-shadow: var(--shadow-xl);
  }
  .shell--desktop.is-nav-open .sidebar {
    transform: none;
    visibility: visible;
    transition: transform var(--dur-4) var(--ease-out);
  }
  /* The off-canvas panel always shows full labels, whatever the desktop rail preference. */
  .shell--desktop .sidebar--collapsed .brand__text,
  .shell--desktop .sidebar--collapsed .nav-item__label { opacity: 1; width: auto; pointer-events: auto; }
  .shell--desktop .sidebar--collapsed .nav-section__label { opacity: 1; width: auto; height: auto; padding: 0 var(--space-3) var(--space-2); pointer-events: auto; }
  .shell--desktop .sidebar--collapsed .nav-section + .nav-section { margin-top: var(--space-5); padding-top: 0; border-top: 0; }
  .shell--desktop .sidebar--collapsed .nav-item { justify-content: flex-start; padding-inline: var(--space-3); }
  .shell--desktop .sidebar--collapsed .nav-item__badge { position: static; min-width: 20px; height: 20px; padding: 0 6px; font-size: var(--fs-2xs); }
  .shell--desktop .sidebar__collapse { display: none !important; }
  .sidebar-scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-sidebar) - 1);
    background: var(--backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur-4) var(--ease-out);
  }
  .shell--desktop.is-nav-open .sidebar-scrim { opacity: 1; pointer-events: auto; }
  .topbar__menu { display: inline-flex; }
  .topbar__title { opacity: 1; transform: none; }
}
@media (max-width: 767.98px) {
  :root { --page-pad: var(--space-4); }
  .topbar { gap: var(--space-2); }
  .topbar__search { display: none; }
  .topbar__divider { display: none; }
}

/* ---- Mobile (courier) shell ----------------------------------------- */
.shell--mobile {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: var(--courier-max);
  margin-inline: auto;
  background: var(--canvas);
  font-size: var(--fs-md);
}
.mobile-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: calc(var(--mobile-header-h) + var(--safe-top));
  padding: var(--safe-top) calc(var(--space-3) + var(--safe-right)) 0 calc(var(--space-3) + var(--safe-left));
  background: var(--surface-overlay);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur-3) var(--ease-out), box-shadow var(--dur-3) var(--ease-out);
}
.mobile-header.is-scrolled { border-bottom-color: var(--border-subtle); box-shadow: 0 1px 0 rgba(16, 24, 40, 0.02), 0 6px 16px -10px rgba(16, 24, 40, 0.18); }
.mobile-header__start { display: flex; align-items: center; gap: var(--space-2); min-width: 0; flex: 1; }
/* The brand never shrinks or wraps; the title only takes the space that is left (flex-basis 0),
   so a hidden (opacity 0) title can no longer squeeze "מסירה חכמה" onto two lines.
   Tap target: at least --touch (48px) tall and wide, also when only the 30px logo shows (scrolled).
   The inline padding is given back by an equal negative margin, so the logo does not move. */
.mobile-header__brand {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
  white-space: nowrap;
  font-weight: var(--fw-bold);
  color: var(--text);
  text-decoration: none;
  min-width: var(--touch);
  min-height: var(--touch);
  padding-inline: 9px;
  margin-inline: -9px;
  border-radius: var(--radius-input);
}
.mobile-header__brand:hover { text-decoration: none; }
.mobile-header__brand img { width: 30px; height: 30px; border-radius: 9px; flex-shrink: 0; }
.mobile-header__start > .icon-btn { flex-shrink: 0; }
.mobile-header__actions { flex-shrink: 0; }
.mobile-header__title {
  flex: 1 1 0;
  min-width: 0;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-lg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-out);
}
.mobile-header__title.is-hidden { opacity: 0; transform: translateY(4px); pointer-events: none; }
.mobile-header__actions { display: flex; align-items: center; gap: var(--space-1); }

.shell--mobile .shell__main {
  flex: 1;
  padding: var(--space-4) calc(var(--space-4) + var(--safe-right)) calc(var(--bottomnav-h) + var(--safe-bottom) + var(--space-6)) calc(var(--space-4) + var(--safe-left));
}
.shell--mobile.no-bottom-nav .shell__main { padding-bottom: calc(var(--safe-bottom) + var(--space-6)); }

.bottom-nav {
  position: fixed;
  bottom: 0;
  inset-inline: 0;
  z-index: var(--z-header);
  max-width: var(--courier-max);
  margin-inline: auto;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding: 6px calc(var(--space-2) + var(--safe-right)) var(--safe-bottom) calc(var(--space-2) + var(--safe-left));
  background: var(--surface-overlay);
  -webkit-backdrop-filter: saturate(1.6) blur(16px);
  backdrop-filter: saturate(1.6) blur(16px);
  border-top: 1px solid var(--border-subtle);
  box-shadow: 0 -8px 24px -16px rgba(16, 24, 40, 0.25);
}
.bottom-nav__item {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--touch);
  padding: 4px 2px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
  transition: color var(--dur-2) var(--ease-out);
}
.bottom-nav__item:hover { text-decoration: none; color: var(--text); }
.bottom-nav__icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 56px;
  height: 30px;
  border-radius: 999px;
  transition: background var(--dur-3) var(--ease-out), transform var(--dur-3) var(--ease-spring);
}
.bottom-nav__item.is-active { color: var(--primary-text); font-weight: var(--fw-semibold); }
.bottom-nav__item.is-active .bottom-nav__icon { background: var(--primary-soft); }
.bottom-nav__item:active .bottom-nav__icon { transform: scale(0.92); }
.bottom-nav__badge {
  position: absolute;
  top: -2px;
  inset-inline-end: 10px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: var(--fw-bold);
  color: #fff;
  background: var(--danger);
  box-shadow: 0 0 0 2px var(--surface);
}

@media (min-width: 640px) {
  body:has(.shell--mobile) {
    background:
      radial-gradient(900px 500px at 100% -10%, rgba(47, 91, 234, 0.10), transparent 60%),
      radial-gradient(700px 400px at 0% 110%, rgba(14, 159, 110, 0.07), transparent 60%),
      var(--surface-sunken);
  }
  .shell--mobile {
    box-shadow: var(--shadow-xl);
    border-inline: 1px solid var(--border-subtle);
  }
}

/* ---- Bare layout (auth, statement, gallery) ------------------------- */
.shell--bare { display: flex; flex-direction: column; }
.shell--bare .shell__main { flex: 1; display: flex; flex-direction: column; }

/* ---- Pages & containers --------------------------------------------- */
.page {
  width: 100%;
  max-width: var(--container-xl);
  margin-inline: auto;
  padding: var(--space-6) var(--page-pad) var(--space-12);
  /* Opacity-only entrance. Never animate transform/filter here: either would make .page the
     containing block of its position:fixed descendants (mobile .action-bar, overlays rendered
     in place), pinning them to the page box instead of the viewport. */
  animation: page-in var(--dur-4) var(--ease-out) backwards; /* nothing lingers after it ends */
}
.page--narrow { max-width: calc(var(--container-md) + 2 * var(--page-pad)); }
.page--medium { max-width: calc(var(--container-lg) + 2 * var(--page-pad)); }
.page--full { max-width: none; }
.shell--mobile .page { padding: 0; max-width: none; }

.container { width: 100%; margin-inline: auto; padding-inline: var(--page-pad); }
.container--sm { max-width: calc(var(--container-sm) + 2 * var(--page-pad)); }
.container--md { max-width: calc(var(--container-md) + 2 * var(--page-pad)); }
.container--lg { max-width: calc(var(--container-lg) + 2 * var(--page-pad)); }
.container--xl { max-width: calc(var(--container-xl) + 2 * var(--page-pad)); }

/* ---- Stack / row / cluster ----------------------------------------- */
.stack { display: flex; flex-direction: column; gap: var(--gap, var(--space-4)); }
.stack-xs { --gap: var(--space-1); }
.stack-sm { --gap: var(--space-2); }
.stack-md { --gap: var(--space-3); }
.stack-lg { --gap: var(--space-6); }
.stack-xl { --gap: var(--space-8); }
.row { display: flex; align-items: center; gap: var(--gap, var(--space-3)); min-width: 0; }
.row-start { align-items: flex-start; }
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.row-wrap, .cluster { flex-wrap: wrap; }
.cluster { display: flex; align-items: center; gap: var(--gap, var(--space-2)); }
.spacer { flex: 1; }
.grow { flex: 1; min-width: 0; }
.shrink-0 { flex-shrink: 0; }

/* ---- Grids ---------------------------------------------------------- */
.grid { display: grid; gap: var(--gap, var(--space-4)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(min(var(--min, 240px), 100%), 1fr)); }
.grid-fit { grid-template-columns: repeat(auto-fit, minmax(min(var(--min, 220px), 100%), 1fr)); }
.span-2 { grid-column: span 2; }
.span-full { grid-column: 1 / -1; }
@media (max-width: 1279.98px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 1023.98px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 767.98px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .span-2 { grid-column: auto; }
  .hide-mobile { display: none !important; }
}
@media (min-width: 768px) { .show-mobile { display: none !important; } }

/* ---- Spacing helpers ------------------------------------------------ */
.gap-1 { --gap: var(--space-1); } .gap-2 { --gap: var(--space-2); } .gap-3 { --gap: var(--space-3); }
.gap-4 { --gap: var(--space-4); } .gap-6 { --gap: var(--space-6); } .gap-8 { --gap: var(--space-8); }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); } .mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--space-2); } .mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); } .mb-8 { margin-bottom: var(--space-8); }
.p-0 { padding: 0 !important; }
.w-full { width: 100%; }

/* ---- Sidebar lists -------------------------------------------------- */
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-list > li { margin: 0; }
.nav-list .nav-item + .nav-item { margin-top: 0; }
button.nav-item { width: 100%; text-align: start; font-family: inherit; }
