/**
 * css/views/mobile-shell.css
 * --------------------------
 * Phone and small-tablet layout. Imported last so it can override the desktop
 * shell without touching the individual view stylesheets.
 *
 * The two goals are:
 *   1. Nothing may ever scroll sideways. Widths collapse instead of overflowing,
 *      and the rail that used to sit beside the workspace moves to the bottom so
 *      the full screen width belongs to the report.
 *   2. The shell respects the physical device: notch insets, the home indicator,
 *      and the keyboard are all accounted for, and the layout is driven by
 *      dvh + fractions rather than fixed pixel gaps so it stretches to any
 *      phone aspect ratio instead of letterboxing.
 */

/* ════════════════════════ App-wide guards ════════════════════════ */

html {
  /* Stops iOS from inflating text when the phone is turned sideways. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Media can never push a column wider than its parent. */
img,
svg,
video,
canvas,
iframe {
  max-width: 100%;
}

/* Unexpected long strings (links, member ids, error text) wrap instead of
   widening the column they sit in. */
.msg-bubble,
.ai-response-card,
.card-box,
.history-item-title {
  overflow-wrap: break-word;
}

/* Grid tracks default to their content's min-content width, so one long URL or
   unbreakable headline can widen a whole column past the screen — the track
   itself has to be allowed to shrink. */
.audit-grid > *,
.ratios-trio > * {
  min-width: 0;
}

@media (max-width: 860px) {
  .audit-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* The install action lives beside the profile pill and only appears when the
   browser actually offers an install flow. */
.pwa-install-btn {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.12);
  color: var(--accent-emerald);
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
}

.pwa-install-btn.is-available {
  display: inline-flex;
}

.pwa-install-btn:hover {
  background: rgba(16, 185, 129, 0.22);
  border-color: rgba(16, 185, 129, 0.6);
}

.pwa-install-btn:active {
  transform: scale(0.97);
}

/* ════════════════════════ Phone shell ════════════════════════ */

/* A landscape phone is wide but very short, so height has to be part of the
   test — otherwise a 844x390 device would be treated as a desktop and lose a
   68px column to the rail on a 390px-tall screen. Keep this expression in sync
   with RT_PHONE_QUERY in js/views/report-timeline.js. */
@media (max-width: 720px), (max-width: 920px) and (max-height: 480px) and (orientation: landscape) {
  /* ── The side rail becomes a bottom tab bar ── */
  .side-rail {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: auto;
    min-height: var(--mobile-nav-h);
    flex-direction: row;
    align-items: stretch;
    justify-content: stretch;
    gap: 0;
    padding: 0 calc(2px + var(--safe-right)) var(--safe-bottom) calc(2px + var(--safe-left));
    border-right: none;
    border-top: 1px solid var(--border-color);
    background: rgba(9, 13, 24, 0.97);
    z-index: 120;
  }

  .side-rail .rail-divider,
  .side-rail .rail-bottom-group {
    display: none;
  }

  /* Dissolving the wrapper makes all eight actions equal siblings of the bar,
     so they divide the width evenly instead of the inner five sharing
     whatever the outer three leave behind. */
  .side-rail-scrollable {
    display: contents;
  }

  .rail-item {
    flex: 1 1 0;
    min-width: 0;
    width: auto;
    height: var(--mobile-nav-h);
    padding: 3px 1px;
    border-radius: 10px;
    gap: 1px;
  }

  .rail-item i {
    font-size: 1rem;
  }

  .rail-item span {
    max-width: 100%;
    font-size: 0.58rem;
    line-height: 1.15;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .rail-item.active {
    border-color: transparent;
    box-shadow: none;
  }

  .rail-item.rail-primary {
    margin-bottom: 0;
  }

  /* ── Workspace clearance for the tab bar and the home indicator ── */
  .workspace-footer {
    display: none;
  }

  .chat-workspace.is-new-chat {
    padding-top: calc(56px + var(--safe-top));
    padding-bottom: calc(var(--mobile-nav-space) + 8px);
  }

  .main-input-group {
    padding: 0 12px;
  }

  .chat-workspace:not(.is-new-chat) .main-input-group {
    margin-bottom: var(--mobile-nav-space);
    padding: 10px calc(12px + var(--safe-right)) 10px calc(12px + var(--safe-left));
  }

  /* ── Header sits inside the notch area instead of under it ── */
  .workspace-header {
    height: calc(56px + var(--safe-top));
    padding: var(--safe-top) calc(12px + var(--safe-right)) 0 calc(12px + var(--safe-left));
  }

  .profile-menu {
    width: min(310px, calc(100vw - 20px));
    max-height: 70dvh;
  }

  /* ── Cabinets overlay the workspace rather than squeezing it ──
     On a 390px phone a 320px in-flow drawer would leave the report 70px wide. */
  .prompts-cabinet,
  .history-cabinet {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    height: auto;
    z-index: 130;
  }

  .prompts-cabinet.active,
  .history-cabinet.active {
    width: min(320px, 86vw);
    box-shadow: 24px 0 60px rgba(0, 0, 0, 0.65);
  }

  .cabinet-header {
    padding-top: calc(18px + var(--safe-top));
  }

  .cabinet-content {
    padding-bottom: calc(12px + var(--safe-bottom));
  }

  /* ── Start screen ── */
  .new-chat-hero {
    margin-bottom: 18px;
  }

  .new-chat-hero h1 {
    font-size: clamp(1.35rem, 6.2vw, 1.75rem);
  }

  .new-chat-hero p {
    font-size: 0.85rem;
    padding: 0 2px;
  }

  .task-chips-row {
    gap: 6px;
    margin-top: 12px;
  }

  .task-chip {
    font-size: 0.74rem;
    padding: 6px 11px;
  }

  /* ── Composer ── */
  .chat-input-container {
    padding: 10px 12px;
    border-radius: 16px;
  }

  .context-status-bar {
    gap: 6px;
    padding-bottom: 8px;
    margin-bottom: 8px;
  }

  /* Chips stay legible, but the labels that only repeat the icon ("Tone:") and
     the HORIZON caption are dropped so both chips and all five pill widths fit
     one thumb-width row instead of wrapping into a second one. */
  .tone-chip,
  .horizon-mini-pill {
    font-size: 0.66rem;
    padding: 3px 7px;
  }

  .tone-chip i {
    font-size: 0.62rem;
  }

  .tone-label,
  .ctx-label {
    display: none;
  }

  .horizon-pill-group {
    gap: 5px;
  }

  /* "(Default)" is a desktop affordance. Without it the horizon strip drops a
     whole row on a phone, which is worth ~34px of thumb-visible conversation.
     The value itself lives in data-days, so the label stays decorative. */
  .horizon-default-tag {
    display: none;
  }

  .chat-input-row {
    gap: 8px;
  }

  .chat-input-row input {
    /* Below 16px iOS zooms the whole page when the field takes focus, which
       then leaves the member pinching back out. */
    font-size: 16px;
  }

  /* The submit button keeps only its magnifier so the field stays usable. */
  .send-btn-label {
    display: none;
  }

  #inspectBtn {
    padding: 9px 11px;
    border-radius: 9px;
  }

  /* ── Conversation ── */
  .chat-scroll-area {
    padding: calc(64px + var(--safe-top)) 10px 14px;
  }

  .messages-column-v4 {
    gap: 16px;
  }

  .chat-msg {
    gap: 8px;
  }

  .chat-msg.assistant .msg-avatar {
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .ai-response-card {
    padding: 12px 14px;
    font-size: 0.86rem;
  }

  /* ── Report internals ── */
  .audit-grid {
    gap: 12px;
  }

  .card-box {
    padding: 12px;
    border-radius: 14px;
  }

  .ratios-trio {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .pillar-name-cell {
    white-space: normal;
  }

  /* ── Toasts span the width above the tab bar ── */
  .toast-notice {
    left: calc(10px + var(--safe-left));
    right: calc(10px + var(--safe-right));
    bottom: calc(var(--mobile-nav-space) + 10px);
    max-width: none;
    font-size: 12.5px;
    padding: 10px 14px;
  }
}

/* Tiny phones: 8 tabs at 320px leave no room for labels. */
@media (max-width: 344px) {
  .rail-item span {
    display: none;
  }

  .rail-item {
    justify-content: center;
  }

  .rail-item i {
    font-size: 1.12rem;
  }
}

/* Touch devices keep hover styles pinned after a tap, which reads as a stuck
   selection. Neutralise them where there is no real pointer. */
@media (hover: none) {
  .rail-item:hover:not(.active) {
    background: transparent;
    border-color: transparent;
    color: var(--text-dim);
  }

  .rail-item:hover i {
    transform: none;
  }

  .task-chip:hover {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
    border-color: rgba(255, 255, 255, 0.08);
    transform: none;
  }

  .chat-send-btn:hover {
    transform: none;
  }
}

/* Landscape phones are only ~390px tall, so the chrome has to shrink. */
@media (max-width: 920px) and (max-height: 470px) and (orientation: landscape) {
  :root {
    --mobile-nav-h: 44px;
  }

  .rail-item span {
    display: none;
  }

  .rail-item i {
    font-size: 1.02rem;
  }

  .new-chat-hero {
    margin-bottom: 10px;
  }

  .new-chat-hero h1 {
    font-size: 1.2rem;
  }

  .new-chat-hero p,
  .task-chips-row {
    display: none;
  }

  .chat-scroll-area {
    padding-top: calc(56px + var(--safe-top));
  }
}

/* Installed app: the browser chrome is gone, so the install action is moot. */
@media (display-mode: standalone) {
  .pwa-install-btn {
    display: none !important;
  }
}
