/* Coach screen alignment: keep the header, conversation and composer on one
   measured mobile grid. This is presentation-only; chat handlers stay intact. */
#screenContent:has(#chatMessages) {
  box-sizing: border-box;
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  height: auto !important;
  min-height: 0;
  overflow: hidden !important;
  padding-bottom: 0 !important;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up {
  display: flex;
  flex: 1 1 auto;
  height: auto !important;
  min-height: 0;
  max-height: none;
  padding-top: 0 !important;
  overflow: hidden;
  padding-bottom: calc(112px + env(safe-area-inset-bottom)) !important;
  box-sizing: border-box;
  width: 100%;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 76px;
  overflow: hidden;
  padding: 14px 4px !important;
  border-bottom-color: rgba(207, 232, 239, .12) !important;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child > div:first-child {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 15px;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child > div:nth-child(2) {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 9px;
  overflow: hidden;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child > div:nth-child(2) > p {
  flex: 0 0 auto;
  max-width: 92px;
  font-size: 18px !important;
  font-weight: 800;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child > div:nth-child(2) > div {
  display: flex;
  align-items: center;
  gap: 5px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child > div:nth-child(2) > div > div {
  flex: 0 0 8px;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child > div:nth-child(2) > div > p {
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px !important;
  line-height: 1.2;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child p {
  margin: 0;
  min-width: 0;
  text-align: left;
  line-height: 1.25;
  overflow-wrap: normal;
}

#screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child button {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#chatMessages {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  height: auto !important;
  min-height: 0;
  max-height: none;
  overflow-y: auto !important;
  overflow-x: hidden;
  align-content: flex-start;
  overscroll-behavior: contain;
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

#chatMessages > * { flex: 0 0 auto; }

#chatMessages > .flex {
  width: 100%;
  min-width: 0;
  align-items: flex-start;
}

#chatMessages .chat-bubble-ai {
  width: min(100%, 680px);
  max-width: none;
  min-width: 0;
  text-align: left;
  overflow-wrap: anywhere;
}

#chatMessages .chat-bubble-ai p,
#chatMessages .chat-bubble-ai ul {
  max-width: 100%;
  text-align: left;
}

#chatSuggestions {
  min-width: 0;
  min-height: 52px;
  align-items: center;
  gap: 8px !important;
  padding: 8px 0 !important;
  scrollbar-width: none;
}

#chatSuggestions::-webkit-scrollbar { display: none; }
#chatSuggestions button {
  min-height: 44px;
  max-width: 100%;
  min-width: 0;
  text-align: left;
  line-height: 1.15;
  white-space: nowrap !important;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-input-bar {
  width: 100%;
  padding: 10px 0 max(12px, env(safe-area-inset-bottom)) !important;
}

.chat-input-bar > .flex {
  width: 100%;
  min-width: 0;
  align-items: stretch !important;
  gap: 10px !important;
}

.chat-input-bar .chat-input {
  width: 100%;
  min-width: 0;
  min-height: 52px;
  padding: 13px 16px;
  line-height: 1.35;
}

.chat-input-bar #sendBtn {
  width: 52px !important;
  height: 52px !important;
  min-width: 52px !important;
  min-height: 52px !important;
  flex: 0 0 52px;
  border-radius: 17px !important;
}

/* Compact refresh/sync actions use a transparent lime outline instead of a
   filled block. Existing click handlers and labels remain unchanged. */
#screenContent button:has(.fa-arrows-rotate),
#screenContent button:has(.fa-rotate-right) {
  color: #b7ff00 !important;
  background: rgba(183, 255, 0, .045) !important;
  border: 1px solid rgba(183, 255, 0, .62) !important;
  box-shadow: inset 0 0 0 1px rgba(183, 255, 0, .08), 0 0 16px rgba(183, 255, 0, .06);
}

#screenContent button:has(.fa-arrows-rotate) i,
#screenContent button:has(.fa-rotate-right) i {
  color: #b7ff00 !important;
}

@media (max-width: 430px) {
  #screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child {
    min-height: 68px;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  #screenContent > div.flex.flex-col.h-full.fade-in-up > div:first-child > div:first-child {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
  }

  #chatMessages { padding-left: 0 !important; padding-right: 0 !important; }
  #chatSuggestions { padding-left: 0 !important; padding-right: 0 !important; }
}

/* v7: one scroll owner for the coach screen. The previous nested flex setup
   could calculate an unbounded messages area, leaving touch scrolling trapped
   behind the preview shell. */
#screenContent:has(#chatMessages) {
  display: flex !important;
  flex: 1 1 0% !important;
  height: 0 !important;
  min-height: 0 !important;
  overflow: hidden !important;
  overscroll-behavior: contain;
}

#screenContent:has(#chatMessages) > .fade-in-up {
  display: flex !important;
  flex: 1 1 0% !important;
  flex-direction: column !important;
  height: 100% !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow: hidden !important;
  box-sizing: border-box;
}

#screenContent:has(#chatMessages) > .fade-in-up > div:first-child,
#screenContent:has(#chatMessages) > .fade-in-up > .mx-4 {
  flex: 0 0 auto !important;
}

#screenContent:has(#chatMessages) #chatMessages {
  flex: 1 1 0% !important;
  height: 0 !important;
  min-height: 0 !important;
  max-height: none !important;
  overflow-y: scroll !important;
  overflow-x: hidden !important;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  padding-bottom: 28px !important;
}

/* Keep the presence line compact and readable on narrow screens. */
#screenContent:has(#chatMessages) > .fade-in-up > div:first-child > div:nth-child(2) {
  min-width: 0 !important;
  flex: 1 1 auto !important;
  overflow: hidden !important;
}

#screenContent:has(#chatMessages) > .fade-in-up > div:first-child > div:nth-child(2) > p,
#screenContent:has(#chatMessages) > .fade-in-up > div:first-child > div:nth-child(2) > div,
#screenContent:has(#chatMessages) > .fade-in-up > div:first-child > div:nth-child(2) > div > p {
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

#screenContent:has(#chatMessages) > .fade-in-up > div:first-child > div:nth-child(2) > div {
  display: flex !important;
  align-items: center !important;
  flex-wrap: nowrap !important;
  gap: 5px !important;
}

#screenContent:has(#chatMessages) > .fade-in-up > div:first-child > button {
  flex: 0 0 44px !important;
}
