* {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--color-text);
  background-color: var(--color-background);
  font-family: var(--font-body);
  font-size: var(--font-size-md);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
h4 {
  margin: 0 0 var(--space-16);
  color: var(--color-text);
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.2;
}

h1 {
  font-size: var(--font-size-headline-mobile);
}

h2 {
  font-size: var(--font-size-headline-sm);
}

h3 {
  font-size: var(--font-size-md);
}

body.auth,
.shell {
  background-color: var(--color-background);
}

.shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.shell-body {
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
}

.shell-topbar,
.shell-mobile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--color-background);
  border-bottom: 1px solid var(--color-outline-variant);
}

.shell-topbar {
  display: none;
}

.shell-mobile-header {
  min-height: var(--shell-mobile-header-height);
  padding: var(--space-8) var(--shell-mobile-margin);
}

.shell-brand,
.shell-mobile-brand {
  color: var(--color-primary-strong);
  font-family: var(--font-display);
  font-size: var(--font-size-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.shell-brand:hover,
.shell-mobile-brand:hover {
  color: var(--color-primary);
}

.shell-mobile-brand {
  font-size: var(--font-size-headline-sm);
}

.topbar-search {
  display: flex;
  align-items: center;
  flex: 1 1 auto;
  width: min(100%, 28rem);
  min-width: 0;
  gap: var(--space-8);
  color: var(--color-on-surface-variant);
}

.topbar-search input {
  width: 100%;
  min-width: 0;
  padding: var(--space-8) 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--color-text);
  font: inherit;
}

.topbar-search input::placeholder {
  color: var(--color-text-muted);
}

.topbar-meta {
  display: flex;
  align-items: center;
  flex: 0 1 auto;
  min-width: 0;
  gap: var(--space-12);
  white-space: nowrap;
  color: var(--color-text-muted);
  font-size: var(--font-size-sm);
}

.topbar-avatar,
.mobile-profile {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  border: 1px solid var(--color-outline-variant);
  border-radius: 50%;
  color: var(--color-primary-strong);
}

.topbar-avatar {
  background-color: var(--color-surface-container-high);
}

.mobile-profile {
  width: 36px;
  height: 36px;
  flex-basis: 36px;
}

.shell-header {
  display: none;
}

.shell-content {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-24) var(--shell-mobile-margin);
  padding-bottom: calc(
    var(--space-16) + 72px + env(safe-area-inset-bottom, 0px)
  );
}

.app-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background-color: var(--color-surface);
  border-top: 1px solid var(--color-outline-variant);
  border-radius: var(--radius-card) var(--radius-card) 0 0;
  box-shadow: 0 -4px 20px rgb(25 28 25 / 8%);
}

.nav-brand {
  display: none;
}

.nav-links {
  display: flex;
  width: 100%;
  gap: var(--space-4);
  padding: var(--space-8) var(--shell-mobile-margin);
}

.nav-item {
  display: inline-flex;
  min-width: 44px;
  min-height: 48px;
  flex: 1;
  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-field);
  background: transparent;
  color: var(--color-text-muted);
  font-family: var(--font-body);
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1.1;
  text-decoration: none;
  cursor: pointer;
}

.nav-item:hover {
  background-color: var(--color-surface-container-low);
  color: var(--color-text);
}

.nav-item-active {
  background-color: var(--color-surface-container-low);
  color: var(--color-primary-strong);
  font-weight: 700;
}

.nav-item-primary {
  color: var(--color-primary-strong);
}

.nav-item-logout {
  margin: 0;
}

.nav-link {
  display: inline-flex;
  width: 100%;
  min-height: 48px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-4);
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.nav-item:focus-visible,
.nav-link:focus-visible,
.topbar-search:focus-within,
.shell-mobile-brand:focus-visible,
.shell-brand:focus-visible {
  outline: var(--focus-ring);
  outline-offset: 2px;
}

.shell-clinical .shell-body {
  padding-bottom: 0;
}

@media (max-width: 767px) {
  .shell-clinical .mobile-dock {
    display: none;
  }
}

@media (min-width: 768px) {
  .shell {
    display: block;
  }

  .shell-body {
    min-height: 100vh;
    margin-left: 256px;
    margin-left: var(--shell-sidebar-width);
    padding-bottom: 0;
  }

  .shell-topbar {
    position: sticky;
    top: 0;
    z-index: 8;
    display: flex;
    min-height: var(--shell-topbar-height);
    gap: var(--space-16);
    padding: var(--space-8) clamp(16px, 2.5vw, var(--space-32));
  }

  .shell-mobile-header {
    display: none;
  }

  .shell-content {
    max-width: 1280px;
    padding: clamp(20px, 2vw, var(--space-32)) clamp(20px, 3vw, var(--space-40));
  }

  .app-nav {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 256px;
    width: var(--shell-sidebar-width);
    height: 100vh;
    align-items: stretch;
    padding: var(--space-24) var(--space-16);
    border-top: 0;
    border-right: 1px solid var(--color-outline-variant);
    border-radius: 0;
    box-shadow: none;
    background-color: var(--color-surface-container-low);
  }

  .nav-brand {
    display: flex;
    align-items: center;
    min-height: 48px;
    margin-bottom: var(--space-24);
    padding: 0 var(--space-8);
    color: var(--color-primary-strong);
    font-family: var(--font-display);
    font-size: var(--font-size-headline-sm);
    font-weight: 700;
    text-decoration: none;
  }

  .nav-links {
    flex: 1;
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-4);
    padding: 0;
  }

  .nav-item {
    flex: none;
    min-height: 48px;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    padding: var(--space-8) var(--space-12);
    font-size: var(--font-size-sm);
  }

  .nav-item:hover {
    background-color: var(--color-surface-container-highest);
    color: var(--color-on-surface-variant);
  }

  .nav-item-active,
  .nav-item-active:hover {
    background-color: var(--color-primary-container);
    color: var(--color-on-primary-container);
  }

  .nav-link {
    flex-direction: row;
    justify-content: flex-start;
  }

  .nav-item-logout {
    margin-top: auto;
  }
}

@media (min-width: 768px) and (max-width: 1023px) {
  .topbar-meta > span:first-child {
    display: none;
  }
}
