/* Waypoint v5: responsive fixes for laptops (1366x768, 1280x720, Windows 125% / 150% scaling) and phones.
   Load this LAST, after waypoint-v4.css. CSS only. No JS or backend change needed.
   Your 27" monitor (1920px and wider) is not touched by any rule that is not inside a media query. */

/* ---------- 0. Safety: nothing may push the page sideways ---------- */
/* 'clip' (not 'hidden') so html/body do not become scroll containers; otherwise the sticky sidebar scrolls away */
html, body { max-width: 100%; overflow-x: clip; }

/* Sidebar stays fixed in place while the page scrolls (desktop/laptop) */
@media (min-width: 861px) {
  .side { position: sticky !important; align-self: start; }
}
.app, .content, #view, main { min-width: 0; }
#view > * { max-width: 100%; }
img, svg, video, canvas { max-width: 100%; }

/* ---------- 1. Waypoint AI chat card: fixed, sensible height that scrolls INSIDE ---------- */
.aichat {
  display: flex !important;
  flex-direction: column !important;
  height: clamp(520px, calc(100dvh - 170px), 860px) !important;
  min-height: 520px !important;
  overflow: hidden;
}
.aimsgs {
  flex: 1 1 auto !important;
  min-height: 220px !important;
  overflow-y: auto !important;
  overscroll-behavior: contain;
}
.aiform { flex: none; }
.aiempty { margin: auto; padding: 8px 12px; max-width: 460px; }

/* Thin themed scrollbar instead of the big white one */
.aimsgs { scrollbar-width: thin; scrollbar-color: rgba(167,139,250,.6) transparent; }
.aimsgs::-webkit-scrollbar { width: 8px; }
.aimsgs::-webkit-scrollbar-track { background: transparent; }
.aimsgs::-webkit-scrollbar-thumb { background: rgba(167,139,250,.55); border-radius: 99px; }

/* ---------- 2. Short laptop screens (height 800px or less) ---------- */
@media (max-height: 800px) {
  .aiempty > div[style*="flex"] { display: none; }   /* duplicate suggestion buttons in the greeting */
  .aiempty p { font-size: .88rem; margin: 4px 0 0; }
  .aiempty h3 { font-size: 1.05rem; margin: 6px 0 0; }
  .aiempty > div:first-child svg { width: 30px; height: 30px; }
  .wp-aichips, .wp-aictx { padding-top: 6px; }
  .wp-aitabs { padding-top: 4px; }
  .hero { min-height: 150px; padding: 16px 22px; }
  .top { margin-bottom: 8px; }
}

/* ---------- 3. Laptop widths (<= 1366px, also 125% scaling of 1080p) ---------- */
@media (max-width: 1366px) {
  .app { grid-template-columns: 220px minmax(0, 1fr) !important; gap: 12px !important; padding: 10px !important; }
  .side { padding: 18px 12px; }
  .nav button { padding: 10px 12px; font-size: .9rem; gap: 10px; }
  .top h1 { font-size: 1.55rem; }
  .wp-split { grid-template-columns: minmax(0, 1fr) 260px !important; }
  .wp-split.wp-ai { grid-template-columns: minmax(0, 1fr) 270px !important; }
  .stats { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)) !important; }
  .cal2 { grid-template-columns: minmax(0, 1.5fr) minmax(260px, 1fr); }
}

/* ---------- 4. Small laptops / 150% scaling (<= 1200px) ---------- */
@media (max-width: 1200px) {
  .app { grid-template-columns: 190px minmax(0, 1fr) !important; }
  .brand b { font-size: 1.1rem; }
  .nav button { padding: 9px 10px; font-size: .86rem; }
  .nav button .navbadge { display: none; }
  .lvl { display: none; }                       /* level chip hides to save height */
  .upgrade { display: none; }
  .wp-row { grid-template-columns: 1fr !important; }
  .grid2 { grid-template-columns: 1fr; }
  .cal2, .setwrap { grid-template-columns: 1fr !important; }
  .setwrap .tabs { flex-direction: row; flex-wrap: wrap; position: static; }
  .wp-hl small { display: none; }
}

/* ---------- 5. Right panel (Quick actions / Today's briefing) drops under the chat ---------- */
@media (max-width: 1100px) {
  .wp-split, .wp-split.wp-ai { grid-template-columns: minmax(0, 1fr) !important; }
  .wp-split > .wp-card { position: static !important; text-align: left; }
  .wp-acts { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
}

/* ---------- 6. Tablet and phone (<= 860px) ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr !important; padding: 10px 10px 96px !important; gap: 0 !important; }

  /* bottom navigation bar; ten items scroll sideways instead of being squashed */
  .side {
    position: fixed !important; left: 8px; right: 8px; bottom: 8px; top: auto !important;
    height: auto !important; z-index: 50; flex-direction: row; padding: 6px !important; border-radius: 20px !important; gap: 0;
  }
  .brand, .upgrade, .me, .push, .lvl { display: none !important; }
  .nav {
    display: flex !important; width: 100%; gap: 2px; justify-content: flex-start;
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav button {
    flex: 0 0 auto; min-width: 66px; flex-direction: column; gap: 3px;
    padding: 8px 8px !important; font-size: .62rem !important; text-align: center; white-space: nowrap;
  }
  .nav button:hover { transform: none; }

  /* top bar */
  .top { flex-wrap: wrap; gap: 10px; }
  .top h1 { font-size: 1.4rem; }
  .top h1::after { display: none; }
  .tools { margin-left: auto; }
  #wpSearch { order: 3; flex-basis: 100%; max-width: none; margin: 0; }
  #wpHud .wp-hl { display: none; }

  /* content blocks go single column */
  .stats { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .grid2, .grid3, .board, .prof, .wp-row, .qgrid, .ds-top { grid-template-columns: 1fr !important; }
  .pgrid { grid-template-columns: 1fr !important; }
  .hero { padding: 18px; min-height: 0; }
  .hero h2 { font-size: 1.7rem; }
  .wp-trav { display: none; }
  .bar { grid-template-columns: 1fr 1fr; }
  .bar .field:first-child { grid-column: 1 / -1; }
  .tabs, .wp-ctabs, .pills { max-width: 100%; overflow-x: auto; }
  .trow { flex-wrap: wrap; }
  .claimcard, .wp-cell > .card { padding-right: 14px !important; }
  .wp-chest { display: none; }
  .ptitle { align-items: flex-start; }
}

/* ---------- 7. Phones (<= 600px) ---------- */
@media (max-width: 600px) {
  .aichat { height: calc(100dvh - 210px) !important; min-height: 440px !important; border-radius: 16px !important; }
  .aiempty > div[style*="flex"] { display: none; }
  .aiform { flex-direction: column; align-items: stretch !important; padding: 10px !important; }
  .aiform .btn { width: 100%; }
  .aim { max-width: 94%; }
  .wp-aichips, .wp-aictx, .wp-aitabs { overflow-x: auto; flex-wrap: nowrap !important; padding-left: 12px; padding-right: 12px; scrollbar-width: none; }
  .wp-aichips::-webkit-scrollbar, .wp-aictx::-webkit-scrollbar, .wp-aitabs::-webkit-scrollbar { display: none; }
  .wp-chip, .wp-cx { flex: 0 0 auto; white-space: nowrap; }
  .smartrow .btn { flex: 1 1 calc(50% - 8px); }
  .bar { grid-template-columns: 1fr; }
  .atiles { grid-template-columns: 1fr 1fr; }
  .calhead2 { flex-wrap: wrap; }
  .day2 { min-height: 42px !important; padding: 4px !important; }
  .dd small { display: none; }
  .mbox { width: calc(100vw - 20px) !important; padding: 20px !important; }
  .modal { padding: 10px; }
  .qa .field { min-width: 100%; }
  .toast { max-width: calc(100vw - 24px); text-align: center; }
}

/* ---------- 8. Very small phones (<= 380px) ---------- */
@media (max-width: 380px) {
  .stats { grid-template-columns: 1fr !important; }
  .nav button { min-width: 58px; }
}

/* ---------- 9. Touch devices: bigger tap targets ---------- */
@media (pointer: coarse) {
  .iconbtn, .chk, .fchk, .wkck, .pick, .tool { min-width: 42px; min-height: 42px; }
  input, select, textarea { font-size: 16px; }   /* stops iOS zooming into fields */
}
