/* ==========================================================================
   Layout: splash, app shell, demo banner, header, navigation
   (bottom tab bar on phones, side rail on desktop), page containers.
   ========================================================================== */

/* ---- Splash (shown while the app boots and the demo data is prepared) ---- */
.splash {
  position: fixed;
  inset: 0;
  z-index: var(--z-splash);
  display: grid;
  place-items: center;
  background: radial-gradient(120% 80% at 50% 0%, var(--teal-500), var(--teal-800) 70%);
  color: #fff;
  transition: opacity var(--dur-4) var(--ease), visibility var(--dur-4);
}

.splash.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-2);
  text-align: center;
  padding: var(--sp-3);
}

.splash-logo {
  width: 88px;
  height: 88px;
  border-radius: 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
  animation: splashPulse 1.8s var(--ease) infinite;
}

.splash-name {
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  letter-spacing: 0.01em;
}

.splash-status {
  min-height: 1.5em;
  font-size: var(--fs-sm);
  opacity: 0.85;
}

.splash-bar {
  width: 160px;
  height: 4px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.2);
  overflow: hidden;
}

.splash-bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--mint-400);
  border-radius: inherit;
  transition: width var(--dur-3) var(--ease);
}

.splash-error {
  max-width: 320px;
  font-size: var(--fs-sm);
  background: rgba(0, 0, 0, 0.25);
  padding: var(--sp-2);
  border-radius: var(--r-md);
}

@keyframes splashPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* ---- App shell ---- */
.app {
  min-height: 100vh;
  min-height: 100dvh;
}

.app-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Sticky top area: demo banner + page header */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  padding-top: var(--safe-top);
}

/* ---- Demo banner (always visible, small) ---- */
.demo-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-1);
  min-height: 28px;
  padding: 2px var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--warn-text);
  background: var(--warn-soft);
  border-bottom: 1px solid var(--warn-border);
  text-align: center;
}

.demo-banner .icon {
  width: 14px;
  height: 14px;
}

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  height: var(--header-h);
  padding-inline: var(--sp-1);
  border-bottom: 1px solid transparent;
  transition: border-color var(--dur-2) var(--ease);
}

.app.is-scrolled .app-header {
  border-bottom-color: var(--border);
}

.app-header-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  padding-inline: var(--sp-1);
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-2) var(--ease-out);
}

/* The small header title appears once the page's large title scrolls away. */
.app-header-title.is-collapsed {
  opacity: 0;
  transform: translateY(6px);
}

.app-header-title .brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 10px;
}

.app-header-actions {
  display: flex;
  align-items: center;
  gap: var(--sp-0);
}

/* ---- Main content ---- */
.app-main {
  flex: 1 1 auto;
  min-width: 0;
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--sp-3));
}

.app-main:focus {
  outline: none;
}

.page {
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
  padding: var(--sp-2);
}

.page-wide {
  max-width: var(--wide-max);
}

.page-flush {
  padding-inline: 0;
}

.page-enter {
  animation: pageIn var(--dur-3) var(--ease-out) both;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

.section {
  margin-top: var(--sp-4);
}

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.section-title {
  font-size: var(--fs-lg);
  font-weight: var(--fw-bold);
}

/* ---- Navigation: bottom tab bar (phones) ---- */
.nav {
  position: fixed;
  inset-inline: 0;
  bottom: 0;
  z-index: var(--z-tabbar);
  padding-bottom: var(--safe-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--border);
}

.nav-brand {
  display: none;
}

.nav-list {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  align-items: end;
  height: var(--tabbar-h);
  margin: 0 auto;
  max-width: 560px;
  padding: 0;
  list-style: none;
}

.nav-item {
  display: flex;
  justify-content: center;
}

.nav-link {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 100%;
  height: var(--tabbar-h);
  color: var(--text-3);
  font-size: 11px;
  font-weight: var(--fw-medium);
  text-decoration: none;
  transition: color var(--dur-2) var(--ease);
}

.nav-link:hover {
  color: var(--text);
  text-decoration: none;
}

.nav-link .icon {
  width: 24px;
  height: 24px;
  transition: transform var(--dur-2) var(--ease);
}

.nav-link[aria-current="page"] {
  color: var(--brand-text);
}

.nav-link[aria-current="page"] .icon {
  stroke-width: 2.2;
}

.nav-link[aria-current="page"]::before {
  content: "";
  position: absolute;
  top: 0;
  width: 28px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--brand);
}

.nav-label {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-inline: 2px;
}

.nav-badge {
  position: absolute;
  top: 8px;
  inset-inline-start: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--r-pill);
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: var(--fw-bold);
  line-height: 18px;
  text-align: center;
  box-shadow: 0 0 0 2px var(--surface);
}

/* Big center Scan button */
.scan-fab {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  margin-bottom: 6px;
  color: var(--brand-text);
  font-size: 11px;
  font-weight: var(--fw-semibold);
  text-decoration: none;
}

.scan-fab:hover {
  text-decoration: none;
}

.scan-fab-circle {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  margin-top: -26px;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--teal-400), var(--teal-700));
  color: #fff;
  box-shadow: var(--shadow-brand), 0 0 0 5px var(--bg);
  transition: transform var(--dur-2) var(--ease), box-shadow var(--dur-2) var(--ease);
}

.scan-fab-circle .icon {
  width: 28px;
  height: 28px;
  stroke-width: 2;
}

.scan-fab:hover .scan-fab-circle {
  transform: translateY(-2px);
}

.scan-fab:active .scan-fab-circle {
  transform: scale(0.95);
}

.scan-fab[aria-current="page"] .scan-fab-circle {
  box-shadow: var(--shadow-brand), 0 0 0 5px var(--bg), 0 0 0 7px var(--brand-soft-2);
}

/* ---- Chrome modes set by the router ---- */
.app[data-chrome="none"] .nav,
.app[data-chrome="none"] .app-header,
.app[data-chrome="minimal"] .nav {
  display: none;
}

.app[data-chrome="none"] .app-main,
.app[data-chrome="minimal"] .app-main {
  padding-bottom: calc(var(--safe-bottom) + var(--sp-4));
}

/* ---- Desktop: side rail ---- */
@media (min-width: 960px) {
  .app[data-chrome="full"] {
    display: grid;
    grid-template-columns: var(--rail-w) minmax(0, 1fr);
  }

  .app[data-chrome="full"] .nav {
    position: sticky;
    top: 0;
    grid-column: 1;
    grid-row: 1;
    height: 100vh;
    height: 100dvh;
    padding: var(--sp-3) var(--sp-2);
    border-top: 0;
    border-inline-end: 1px solid var(--border);
    background: var(--surface);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
  }

  .app[data-chrome="full"] .app-body {
    grid-column: 2;
    grid-row: 1;
  }

  /* The rail already shows the logo, so the header keeps the space empty. */
  .app[data-chrome="full"] .app-header-title.is-brand {
    visibility: hidden;
  }

  .nav-brand {
    display: flex;
    align-items: center;
    gap: var(--sp-1);
    padding-inline: var(--sp-1);
    color: var(--text);
    font-size: var(--fs-xl);
    font-weight: var(--fw-bold);
    text-decoration: none;
  }

  .nav-brand:hover {
    text-decoration: none;
  }

  .nav-brand .brand-mark {
    width: 40px;
    height: 40px;
    border-radius: 12px;
  }

  .nav-brand small {
    display: block;
    font-size: var(--fs-xs);
    font-weight: var(--fw-medium);
    color: var(--text-3);
  }

  .nav-list {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: var(--sp-0);
    height: auto;
    max-width: none;
    margin: 0;
  }

  .nav-item {
    justify-content: stretch;
  }

  /* Scan button first and prominent on desktop */
  .nav-item-scan {
    order: -1;
    margin-bottom: var(--sp-2);
  }

  .nav-link {
    flex-direction: row;
    justify-content: flex-start;
    gap: var(--sp-2);
    height: 48px;
    padding-inline: var(--sp-2);
    border-radius: var(--r-md);
    font-size: var(--fs-md);
  }

  .nav-link:hover {
    background: var(--surface-hover);
  }

  .nav-link[aria-current="page"] {
    background: var(--brand-soft);
  }

  .nav-link[aria-current="page"]::before {
    display: none;
  }

  .nav-badge {
    position: static;
    margin-inline-start: auto;
    box-shadow: none;
  }

  .scan-fab {
    flex-direction: row;
    justify-content: center;
    gap: var(--sp-1);
    width: 100%;
    height: 52px;
    margin: 0;
    border-radius: var(--r-md);
    background: linear-gradient(160deg, var(--teal-500), var(--teal-700));
    color: #fff;
    font-size: var(--fs-md);
    box-shadow: var(--shadow-brand);
  }

  .scan-fab-circle {
    width: auto;
    height: auto;
    margin: 0;
    background: none;
    box-shadow: none !important;
  }

  .scan-fab-circle .icon {
    width: 22px;
    height: 22px;
  }

  .scan-fab:hover .scan-fab-circle {
    transform: none;
  }

  .nav-foot {
    margin-top: auto;
    font-size: var(--fs-xs);
    color: var(--text-3);
    padding-inline: var(--sp-1);
  }

  .app[data-chrome="full"] .app-main {
    padding-bottom: var(--sp-6);
  }

  .page {
    padding: var(--sp-3);
  }
}

.nav-foot {
  display: none;
}

@media (min-width: 960px) {
  .nav-foot {
    display: block;
  }
}
