/* Mobile Ask PSXL: compact, edge-aware chat layout inspired by native chat apps. */
@media (max-width: 767px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: clip;
  }

  .app-mobile-main:has(.wab-composer) {
    height: 100dvh;
    max-height: 100dvh;
    min-height: 0;
    overflow: hidden;
  }

  .wab-composer-area {
    flex: 0 0 auto;
    width: 100%;
    max-width: 100%;
    padding: 8px 12px max(8px, env(safe-area-inset-bottom, 0px)) !important;
    background: var(--background);
  }

  .wab-composer-area > div {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  /* Suggestions consume valuable vertical space on phones; keep them on desktop. */
  .wab-composer-area > div > .wab-fade-up {
    display: none !important;
  }

  .wab-composer-area > div > p {
    display: none;
  }

  .wab-composer [data-slot="input-group"] {
    width: 100%;
    max-width: 100%;
    border-radius: 26px;
    box-shadow: 0 1px 3px oklch(0 0 0 / 8%) !important;
  }

  .wab-composer textarea {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 44px !important;
    max-height: min(30dvh, 168px) !important;
    padding: 11px 16px 7px !important;
    font-family: var(--font-body);
    font-size: 16px !important;
    line-height: 1.45 !important;
    letter-spacing: -0.01em;
    overscroll-behavior: contain;
    -webkit-appearance: none;
  }

  .wab-composer [data-slot="input-group-addon"] {
    min-width: 0;
    padding-inline: 10px;
    padding-bottom: 9px;
  }

  .wab-composer .wab-send,
  .wab-composer button[aria-label="Attach files"] {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
  }

  .chat-scroll [class*="max-w-[48rem]"] {
    width: 100%;
    max-width: 100%;
    padding-inline: 16px;
  }

  .wab-composer-area .wab-composer {
    width: 100%;
    max-width: 100%;
  }

  /* Keep the transcript's own scrollbar visible on touch devices too. */
  .chat-scroll {
    scrollbar-width: thin;
    scrollbar-color: var(--chat-scrollbar-thumb) var(--chat-scrollbar-track);
  }

  .chat-scroll::-webkit-scrollbar {
    display: block;
    width: 8px;
  }

  .chat-scroll::-webkit-scrollbar-thumb {
    background-color: var(--chat-scrollbar-thumb);
    border-radius: 99px;
  }

  .chat-scroll [class*="max-w-[48rem]"] {
    width: 100%;
    max-width: 42rem;
    margin-inline: auto;
  }

  [data-slot="conversation-content"],
  .wab-composer-area ~ * {
    min-width: 0;
    max-width: 100%;
  }

  .wab-md,
  [data-slot="message-response"] {
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: normal;
    font-size: 16px;
    line-height: 1.6;
    letter-spacing: -0.01em;
  }

  .wab-md p,
  .wab-md li {
    line-height: 1.6;
  }

  .wab-md pre,
  .wab-md table,
  .wab-md img,
  .wab-md svg {
    max-width: 100%;
  }

  .wab-md pre,
  .wab-md > div {
    overflow-x: auto;
  }

  .wab-composer-area::before {
    top: -14px;
    height: 14px;
  }

  /* Preserve the app's own scrolling while the software keyboard is open. */
  .app-mobile-main,
  .app-mobile-main > *,
  .app-mobile-main .min-h-0 {
    min-width: 0;
  }

  .app-mobile-main .chat-scroll {
    -webkit-overflow-scrolling: touch;
    scroll-padding-bottom: 12px;
  }
}

@media (min-width: 768px) {
  .wab-composer-area > div,
  .wab-composer-area .wab-composer,
  .wab-composer-area > div > .wab-fade-up {
    max-width: 42rem;
  }
}

/* Compact, viewport-fitted mobile chat: balanced like a native chat client. */
@media (max-width: 767px) {
  .app-mobile-main:has(.wab-composer) {
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    flex: 1 1 0%;
    overflow: hidden !important;
    padding-bottom: calc(6.25rem + env(safe-area-inset-bottom, 0px)) !important;
  }
  .app-mobile-main:has(.wab-composer) > * { height: 100%; min-height: 0; }
  .app-mobile-main:has(.wab-composer) header { padding-top: 7px; padding-bottom: 7px; }
  .app-mobile-main [data-slot="conversation-content"] {
    gap: 1.25rem !important;
    padding: 12px 14px 8px !important;
  }
  .app-mobile-main [data-slot="conversation-content"] > .wab-fade-up {
    flex: 1 1 auto;
    min-height: 0 !important;
    justify-content: center;
    padding: 12px 8px 18px;
  }
  .app-mobile-main [data-slot="conversation-content"] > .wab-fade-up h1 {
    max-width: 320px;
    font-size: 1.4rem !important;
    line-height: 1.2 !important;
    letter-spacing: -0.04em;
  }
  .app-mobile-main [data-slot="conversation-content"] > .wab-fade-up p {
    max-width: 310px;
    margin-top: 10px;
    font-size: 0.98rem !important;
    line-height: 1.5 !important;
  }
  .wab-composer-area { padding: 6px 12px max(8px, env(safe-area-inset-bottom, 0px)) !important; }
  .wab-composer [data-slot="input-group"] { min-height: 108px; border-radius: 22px; }
  .wab-composer textarea {
    min-height: 42px !important;
    max-height: min(22dvh, 120px) !important;
    padding: 10px 14px 4px !important;
    font-size: 15px !important;
    line-height: 1.45 !important;
  }
  .wab-composer [data-slot="input-group-addon"] { padding-inline: 8px; padding-bottom: 7px; }
  .wab-composer .wab-send,
  .wab-composer button[aria-label="Attach files"] {
    width: 34px; height: 34px; min-width: 34px; min-height: 34px;
  }
}

/* Fine-tune phone typography and give the composer more horizontal room. */
@media (max-width: 767px) {
  .app-mobile-main [data-slot="conversation-content"] h1 {
    font-size: 1.2rem !important;
    line-height: 1.22 !important;
    letter-spacing: -0.035em;
  }
  .app-mobile-main [data-slot="conversation-content"] h2 {
    font-size: 1.02rem !important;
    line-height: 1.3 !important;
  }
  .app-mobile-main [data-slot="conversation-content"] h3 {
    font-size: 0.92rem !important;
    line-height: 1.35 !important;
  }
  .app-mobile-main [data-slot="conversation-content"] > .wab-fade-up h1 {
    max-width: 300px;
    font-size: 1.22rem !important;
    line-height: 1.22 !important;
  }
  .app-mobile-main [data-slot="conversation-content"] > .wab-fade-up p {
    max-width: 300px;
    font-size: 0.88rem !important;
    line-height: 1.48 !important;
  }
  .wab-md,
  [data-slot="message-response"] {
    font-size: 14px !important;
    line-height: 1.55 !important;
  }
  .wab-md p,
  .wab-md li {
    font-size: 14px;
    line-height: 1.55;
  }
  .wab-composer-area {
    padding-left: 6px !important;
    padding-right: 6px !important;
    padding-top: 4px !important;
  }
  .wab-composer-area > div,
  .wab-composer-area .wab-composer {
    width: 100% !important;
    max-width: none !important;
  }
  .wab-composer [data-slot="input-group"] {
    min-height: 88px !important;
    border-radius: 20px !important;
  }
  .wab-composer textarea {
    min-height: 38px !important;
    max-height: min(18dvh, 104px) !important;
    padding: 8px 12px 3px !important;
    font-size: 14px !important;
    line-height: 1.4 !important;
  }
  .wab-composer [data-slot="input-group-addon"] {
    padding-inline: 7px !important;
    padding-bottom: 5px !important;
  }
  .wab-composer .wab-send,
  .wab-composer button[aria-label="Attach files"] {
    width: 32px !important;
    height: 32px !important;
    min-width: 32px !important;
    min-height: 32px !important;
  }
}



/* ── iPad / tablet layout ──────────────────────────────────────────────────
   Give the 768–1023px range its own layout instead of stretching the phone UI.
   Desktop navigation takes over at 1024px; phone rules remain untouched. */
@media (min-width: 768px) and (max-width: 1023px) {
  html,
  body {
    max-width: 100%;
    overflow-x: clip;
  }

  .app-mobile-main {
    min-width: 0;
    padding-bottom: calc(5.75rem + env(safe-area-inset-bottom, 0px)) !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  .app-mobile-main:not(:has(.wab-composer)) {
    padding-inline: clamp(16px, 2.5vw, 28px);
  }

  /* A floating, centered dock with proper iPad touch targets. */
  nav.fixed.inset-x-0.bottom-0.z-40 {
    left: 50%;
    right: auto;
    width: min(100%, 760px);
    padding-inline: 18px;
    padding-bottom: max(14px, env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
  }

  nav.fixed.inset-x-0.bottom-0.z-40 > div {
    max-width: none;
    gap: 6px;
    padding: 8px;
    border-radius: 20px;
  }

  nav.fixed.inset-x-0.bottom-0.z-40 a,
  nav.fixed.inset-x-0.bottom-0.z-40 button {
    min-height: 56px;
    gap: 5px;
    padding: 7px 8px;
    font-size: 11px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }

  nav.fixed.inset-x-0.bottom-0.z-40 svg {
    width: 21px;
    height: 21px;
  }

  /* Keep the app header balanced and controls easy to tap. */
  .app-mobile-main ~ header {
    min-height: 58px;
  }

  header button,
  header a {
    min-height: 40px;
  }

  /* Dashboard: use the available width without forcing desktop's cramped
     four-column cards or leaving tablet-sized blank gutters. */
  .app-mobile-main > div.mx-auto {
    max-width: 100%;
    padding: 22px 4px 30px;
  }

  .overview-hero h1 {
    font-size: 1.9rem !important;
    line-height: 1.15;
  }

  .app-mobile-main .grid.gap-4[class~="sm:grid-cols-2"][class~="lg:grid-cols-4"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .app-mobile-main .grid.gap-4[class~="lg:grid-cols-2"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .app-mobile-main .rounded-xl.bg-surface,
  .app-mobile-main .rounded-2xl.bg-surface {
    min-width: 0;
  }

  .app-mobile-main table {
    min-width: 620px;
  }

  .app-mobile-main [role="tabpanel"],
  .app-mobile-main [data-slot="card"] {
    min-width: 0;
  }

  /* Avoid tiny chart labels and clipped chart cards on touch screens. */
  .app-mobile-main .recharts-responsive-container {
    min-width: 0;
  }

  .app-mobile-main button,
  .app-mobile-main a,
  .app-mobile-main input,
  .app-mobile-main select {
    touch-action: manipulation;
  }

  /* The assistant workspace needs the full tablet height above the dock. */
  .app-mobile-main:has(.wab-composer) {
    padding-bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px)) !important;
  }

  .wab-composer-area {
    padding-inline: 22px;
    padding-bottom: 14px;
  }

  .chat-scroll [class*="max-w-[48rem]"] {
    width: 100%;
    max-width: 48rem;
    margin-inline: auto;
  }
}

/* Wider iPad portrait / compact landscape: give the dashboard's insight
   column room beside the main timeline without over-compressing cards. */
@media (min-width: 900px) and (max-width: 1023px) {
  .app-mobile-main .grid.items-start.gap-5[class~="lg:grid-cols-[minmax(0,1fr)_340px]"] {
    grid-template-columns: minmax(0, 1fr) 300px;
    align-items: start;
  }
}
