.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.app-header {
  flex-shrink: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-12);
  height: var(--header-height);
  padding: 0 var(--space-12);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-default);
  box-shadow: var(--shadow-none);
}

.app-header__start,
.app-header__end {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.app-header__quick-actions {
  display: flex;
  align-items: center;
  gap: var(--space-8);
}

.app-brand {
  display: flex;
  align-items: center;
  gap: var(--identity-gap);
  color: var(--text-primary);
}

.app-brand__mark {
  display: grid;
  place-items: center;
  width: var(--identity-icon-size);
  height: var(--identity-icon-size);
  border-radius: var(--radius-8);
  background: var(--brand-primary);
  color: var(--text-inverse);
  font-size: var(--text-l);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  transform: translateY(calc(var(--identity-text-offset-y) * -1));
  flex-shrink: 0;
}

.app-brand__text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--identity-text-gap);
  line-height: var(--leading-tight);
}

.app-brand__name {
  font-size: var(--text-m);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  color: var(--text-primary);
}

.app-brand__subtitle {
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

@media (min-width: 768px) {
  .app-header .profile-trigger__text {
    align-items: flex-end;
    text-align: right;
  }
}

/* Body: sidebar + workspace */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

.app-sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-default);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow-y: auto;
  transition: width var(--duration-base) var(--ease-standard),
    transform var(--duration-base) var(--ease-standard);
}


.app-sidebar-overlay {
  display: none;
}

.app-nav__mobile-content { display: none; }

.app-workspace {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  background: var(--bg-page);
}

.workspace {
  padding: var(--page-padding);
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
  max-width: 1440px;
  margin: 0 auto;
  /* Paint the complete design-system surface immediately. A fade here
     briefly exposes the grey shell during every navigation and looks like a
     colour flash on slower connections. */
  animation: none;
}

@media (max-width: 767.98px) {
  /* Keep POS on the same first-paint title inset as the other mobile pages. */
  .app-shell:not(.site-shell) .app-workspace .workspace:has(#posMobileApp) {
    padding-top: var(--space-16);
    padding-inline: var(--space-12);
  }
}

/* Shared application frame: quiet chrome gives dense operational pages room
   while keeping navigation and workspace surfaces visually related. */
.app-header {
  height: var(--header-height);
  padding-inline: var(--space-12);
  border-bottom-color: var(--border-light);
  box-shadow: var(--shadow-header);
}

.app-sidebar { border-right-color: var(--border-light); }

.page-header__desc { color: var(--text-tertiary); }

@keyframes workspace-in {
  from {
    opacity: 0;
    transform: translateY(var(--space-4));
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .workspace {
    animation: none;
  }
}

.workspace-section {
  display: flex;
  flex-direction: column;
  gap: var(--space-12);
}

/* Footer */
.app-footer {
  height: var(--footer-height);
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: var(--space-12);
  /* Same side padding as the page content above it. */
  padding: 0 var(--page-padding);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-default);
  font-size: var(--text-xs);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

/* All three footer columns centre their item on the same line. */
.app-footer__start,
.app-footer__center,
.app-footer__end {
  display: flex;
  align-items: center;
}

.app-footer__center {
  justify-self: center;
}

.app-footer__end {
  display: flex;
  justify-self: end;
  gap: var(--space-12);
}

.app-footer__meta {
  display: inline-flex;
  align-items: center;
  gap: var(--space-4);
  line-height: 1;
}

.app-footer__meta .material-symbols-rounded {
  font-size: var(--icon-size-s);
  color: var(--text-muted);
}

/* Desktop toggle hides the complete sidebar instead of leaving an icon rail. */
.app-header .sidebar-toggle-btn {
  width: var(--control-height-m);
  min-width: var(--control-height-m);
  padding: 0;
}

@media (min-width: 768px) {
  .app-shell.is-sidebar-collapsed .app-sidebar { display: none; }
}

/* Responsive breakpoints */
@media (max-width: 767.98px) {
  .app-header .sidebar-toggle-btn { width: var(--avatar-size); min-width: var(--avatar-size); }

  .app-sidebar {
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    z-index: 45;
    transform: translateX(-100%);
    width: var(--sidebar-width);
  }

  .app-shell.is-sidebar-open .app-sidebar {
    transform: translateX(0);
  }

  .app-shell.is-sidebar-open .app-sidebar-overlay {
    display: block;
    position: fixed;
    inset: var(--header-height) 0 0 0;
    background: var(--overlay-scrim);
    z-index: 44;
  }

  .app-shell.is-sidebar-collapsed .app-sidebar {
    width: var(--sidebar-width);
  }

  .app-shell.is-sidebar-collapsed .app-nav__text {
    display: initial;
  }
}

@media (max-width: 767.98px) {
  .app-shell:not(.site-shell) .app-sidebar,
  .app-shell.is-sidebar-collapsed:not(.site-shell) .app-sidebar {
    width: min(320px, calc(100vw - var(--space-32)));
  }

  .app-shell:not(.site-shell) .app-sidebar { border-right: 0; }
  .app-shell:not(.site-shell) .app-sidebar .app-nav { padding: var(--space-12); }
  .app-shell:not(.site-shell) .app-nav__link,
  .app-shell:not(.site-shell) .app-nav__group-toggle {
    min-height: 48px;
    padding-block: var(--space-12);
  }

  .app-brand__text {
    display: none;
  }

  .app-shell:not(.site-shell) .app-sidebar {
    width: min(360px, calc(100vw - var(--space-24)));
    background: var(--bg-surface);
  }

  .app-shell:not(.site-shell) .app-sidebar .app-nav {
    height: 100%;
    overflow-y: auto;
    padding: var(--space-12);
    overscroll-behavior: contain;
  }

  .app-shell:not(.site-shell) .app-nav__list { gap: var(--space-4); }

  .app-shell:not(.site-shell) .app-nav__link,
  .app-shell:not(.site-shell) .app-nav__group-toggle {
    min-height: 48px;
    gap: var(--space-12);
    padding: var(--space-8) var(--space-12);
    border-radius: var(--radius-12);
  }

  .app-shell:not(.site-shell) .app-nav__icon {
    display: grid;
    width: var(--icon-size-2xl);
    height: var(--icon-size-2xl);
    flex: 0 0 var(--icon-size-2xl);
    place-items: center;
    border-radius: var(--radius-8);
    background: var(--bg-subtle);
    color: var(--text-tertiary);
    font-size: var(--icon-size-m);
  }

  .app-shell:not(.site-shell) .app-nav__group-toggle::after {
    content: 'chevron_right';
    font-family: 'Material Symbols Rounded';
    font-size: var(--icon-size-m);
    color: var(--text-muted);
  }

  .app-shell:not(.site-shell) .app-nav__group-toggle .app-nav__caret { display: none; }
  .app-shell:not(.site-shell) .app-nav__link.is-active { background: var(--brand-primary-light); color: var(--brand-primary); font-weight: var(--weight-semibold); }
  .app-shell:not(.site-shell) .app-nav__link.is-active::before { display: none; }
  .app-shell:not(.site-shell) .app-nav__link.is-active .app-nav__icon { background: var(--brand-primary-soft); color: var(--brand-primary); }
  .app-shell:not(.site-shell) .app-nav__group:has(.app-nav__link.is-active) > .app-nav__group-toggle { background: var(--bg-subtle); color: var(--brand-primary); }
  .app-shell:not(.site-shell) .app-nav__group:has(.app-nav__link.is-active) > .app-nav__group-toggle .app-nav__icon { background: var(--brand-primary-light); color: var(--brand-primary); }
  .app-shell:not(.site-shell) .app-nav__list { display: none; }
  .app-shell:not(.site-shell) .app-nav__mobile-content { display: block; }
  .app-shell:not(.site-shell) .app-nav__mobile-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: var(--space-8); }
  .app-shell:not(.site-shell) .app-nav__mobile-grid:has(> :nth-child(4):last-child)::after { content: ''; min-height: 68px; }
  .app-shell:not(.site-shell) .app-nav__mobile-section + .app-nav__mobile-section { margin-top: var(--space-20); }
  .app-shell:not(.site-shell) .app-nav__mobile-section-title { display: flex; align-items: center; gap: var(--space-8); margin: 0 0 var(--space-8); color: var(--text-primary); font-size: var(--text-m); font-weight: var(--weight-semibold); }
  .app-shell:not(.site-shell) .app-nav__mobile-section-title .material-symbols-rounded { color: var(--brand-primary); font-size: var(--icon-size-m); }
  .app-shell:not(.site-shell) .app-nav__mobile-section:nth-of-type(4n + 1) :is(.app-nav__mobile-section-title, .app-nav__mobile-tile) > .material-symbols-rounded { color: var(--info); }
  .app-shell:not(.site-shell) .app-nav__mobile-section:nth-of-type(4n + 2) :is(.app-nav__mobile-section-title, .app-nav__mobile-tile) > .material-symbols-rounded { color: var(--success); }
  .app-shell:not(.site-shell) .app-nav__mobile-section:nth-of-type(4n + 3) :is(.app-nav__mobile-section-title, .app-nav__mobile-tile) > .material-symbols-rounded { color: var(--danger); }
  .app-shell:not(.site-shell) .app-nav__mobile-section:nth-of-type(4n) :is(.app-nav__mobile-section-title, .app-nav__mobile-tile) > .material-symbols-rounded { color: var(--warning); }
  .app-shell:not(.site-shell) .app-nav__mobile-tile { display: flex; min-width: 0; min-height: 68px; flex-direction: column; align-items: center; justify-content: center; gap: var(--space-4); padding: var(--space-8) var(--space-4); border: 0; border-radius: var(--radius-12); background: transparent; color: var(--text-secondary); font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: var(--leading-tight); text-align: center; text-decoration: none; }
  .app-shell:not(.site-shell) .app-nav__mobile-tile > .material-symbols-rounded { display: grid; width: var(--icon-size-2xl); height: var(--icon-size-2xl); place-items: center; border-radius: var(--radius-8); background: var(--bg-subtle); color: var(--text-tertiary); font-size: var(--icon-size-m); }
  .app-shell:not(.site-shell) .app-nav__mobile-tile > span:last-child { max-width: 100%; overflow-wrap: anywhere; }
  .app-shell:not(.site-shell) .app-nav__mobile-tile.is-active { border-color: var(--brand-primary-soft); background: var(--brand-primary-light); color: var(--brand-primary); font-weight: var(--weight-semibold); }
  .app-shell:not(.site-shell) .app-nav__mobile-tile.is-active > .material-symbols-rounded { background: var(--brand-primary-soft); }
  .app-shell:not(.site-shell) .app-nav__mobile-tile.is-disabled { color: var(--text-muted); }

  .app-shell.is-sidebar-open:not(.site-shell) .app-sidebar {
    top: var(--header-height);
    bottom: calc(var(--header-height) + env(safe-area-inset-bottom, 0px));
    left: 0;
    z-index: 45;
    width: 100vw;
    max-width: none;
    border: 0;
    transform: translateX(0);
  }
  .app-shell.is-sidebar-open:not(.site-shell) .app-sidebar-overlay {
    inset: var(--header-height) 0 calc(var(--header-height) + env(safe-area-inset-bottom, 0px));
    z-index: 44;
  }
  .app-shell.is-sidebar-open:not(.site-shell) .app-sidebar .app-nav { padding: max(var(--space-12), env(safe-area-inset-top, 0px)) var(--space-16) max(var(--space-12), env(safe-area-inset-bottom, 0px)); }

  .app-shell:not(.site-shell) .app-nav__mobile-bar {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    min-height: 48px;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-12);
    margin-bottom: var(--space-16);
    padding: var(--space-4) 0;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-size: var(--text-l);
    font-weight: var(--weight-semibold);
  }
  .app-shell:not(.site-shell) .app-nav__mobile-bar button {
    display: grid;
    width: 40px;
    height: 40px;
    place-items: center;
    border: 1px solid var(--border-light);
    border-radius: var(--radius-12);
    background: var(--bg-subtle);
    color: var(--text-secondary);
    cursor: pointer;
  }
  .app-shell:not(.site-shell) .app-nav__mobile-bar button .material-symbols-rounded { font-size: var(--icon-size-m); }
}

/* ---------- Responsive chrome ----------
   Mobile browsers count the area behind their URL bar in 100vh, which pushed
   the footer and the last rows off-screen; dvh is the visible height. */
.app-shell {
  height: 100dvh;
}

/* Profile-menu copies of header links, only while those header icons are hidden. */
.header-menu__item.header-menu__item--compact {
  display: none;
}

/* Tablet and phone: the header keeps only everyday controls. Fullscreen is
   not useful on touch devices; Logout, Website and My Account stay in the
   profile menu. */
@media (max-width: 767.98px) {
  .app-header .header-optional-lg {
    display: none;
  }

  .header-menu__item.header-menu__item--compact {
    display: flex;
  }

  .app-header .profile-trigger__text {
    display: none;
  }

  .app-footer__center {
    display: none;
  }

  .app-footer {
    grid-template-columns: 1fr auto;
  }
}

@media (max-width: 767.98px) {
  .app-shell:not(.site-shell) .app-header {
    position: relative;
  }

  .app-shell:not(.site-shell) .app-header__end {
    position: static;
    flex: 1;
    justify-content: flex-end;
  }

  .app-shell:not(.site-shell) .app-header__quick-actions {
    position: absolute;
    left: 50%;
    top: 50%;
    gap: var(--space-8);
    transform: translate(-50%, -50%);
  }

  .app-shell:not(.site-shell) .app-header__end > .profile-menu {
    position: relative;
    z-index: 1;
    margin-left: auto;
  }

  .app-header__quick-actions #fullscreenToggle,
  .app-header__quick-actions #headerLogoutBtn {
    display: none;
  }

  .app-header .icon-btn {
    display: grid;
    place-items: center;
    flex: 0 0 auto;
  }

  .app-header .icon-btn > .material-symbols-rounded {
    display: grid;
    width: var(--icon-size-m);
    height: var(--icon-size-m);
    place-items: center;
    line-height: 1;
    text-align: center;
  }

  .workspace {
    padding: var(--space-12);
    gap: var(--space-12);
  }

  /* One line only: the copyright. */
  .app-footer {
    grid-template-columns: 1fr;
    padding: 0 var(--space-12);
  }

  .app-footer__end {
    display: none;
  }

  .app-footer__start {
    justify-content: center;
    min-width: 0;
  }

  .app-footer__meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

/* Phone: compact 32px header controls with tighter spacing, so menu +
   clock + counter + reminders + notifications + sound + profile fit 320px. */
@media (max-width: 767.98px) {
  .app-header {
    gap: var(--space-8);
    padding: 0 var(--space-8);
  }

  .app-header__start,
  .app-header__end {
    gap: var(--space-4);
    min-width: 0;
  }

  .app-header .icon-btn {
    width: var(--avatar-size);
    height: var(--avatar-size);
  }

  .app-shell:not(.site-shell) .app-brand,
  .app-header .profile-trigger__caret {
    display: none;
  }

  .app-header .profile-trigger {
    padding: 0;
    height: auto;
  }

  /* Header dropdowns would open off the left edge from mid-header icons;
     on phones they drop down full width under the header instead. */
  .app-header .header-menu__panel {
    position: fixed;
    top: calc(var(--header-height) + var(--space-4));
    left: var(--space-8);
    right: var(--space-8);
    width: auto;
    max-height: calc(100dvh - var(--header-height) - var(--space-16));
    overflow-y: auto;
  }
}

/* Shared phone navigation for every signed-in application page. */
.app-mobile-nav { display: none; }

@media (max-width: 767.98px) {
  .app-shell:not(.site-shell) { --mobile-navigation-total-height: calc(var(--header-height) + env(safe-area-inset-bottom, 0px)); }

  .app-shell:not(.site-shell) .app-mobile-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 55;
    display: flex;
    gap: 0;
    box-sizing: border-box;
    height: var(--mobile-navigation-total-height);
    padding: 0 var(--space-4) env(safe-area-inset-bottom, 0px);
    border-top: 1px solid var(--border-light);
    background: rgb(255 255 255 / 96%);
    box-shadow: 0 -5px 20px rgb(25 44 79 / 7%);
    backdrop-filter: blur(14px);
  }

  .app-mobile-nav__item {
    display: flex;
    flex: 1 1 0;
    min-width: 0;
    min-height: 0;
    align-self: stretch;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-4);
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-tertiary);
    font-family: inherit;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    line-height: 1.1;
    text-align: center;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
  }

  .app-mobile-nav__icon { display: grid; width: var(--icon-size-2xl); height: var(--icon-size-2xl); place-items: center; border-radius: var(--radius-8); color: inherit; }
  .app-mobile-nav__item .material-symbols-rounded { font-size: var(--icon-size-l); }
  .app-mobile-nav__item > span:last-child { display: none; }

  .app-mobile-nav__item.is-active { color: var(--brand-primary); }
  .app-mobile-nav__item.is-active .app-mobile-nav__icon { background: var(--brand-primary-light); }

  .app-shell:not(.site-shell) #appWorkspace {
    padding-bottom: calc(var(--header-height) + var(--space-16) + env(safe-area-inset-bottom, 0px));
  }

  .app-shell:not(.site-shell) .app-footer { display: none; }

  .app-shell:not(.site-shell) .app-sidebar { bottom: calc(var(--header-height) + env(safe-area-inset-bottom, 0px)); }
  .app-shell:not(.site-shell) .app-sidebar-overlay { bottom: calc(var(--header-height) + env(safe-area-inset-bottom, 0px)); }

  .app-shell:not(.site-shell) .app-header {
    min-height: 54px;
    height: 54px;
    padding-inline: var(--space-12);
  }
}

/* Keep app branding visible and align the drawer edge with the shared header
   token after the narrow-phone overrides above. */
@media (max-width: 767.98px) {
  .app-shell:not(.site-shell) .app-brand { display: flex; }

  .app-shell:not(.site-shell) .app-header {
    min-height: var(--header-height);
    height: var(--header-height);
    padding-inline: var(--space-12);
  }
}
