/* Fit every screen.
   1. The Agent Assistant docks beside the page on tablets and computers. The app reserves the panel's width
      (--asst-w, set by v8/assistant.js) and the page reflows into the space that is left, so nothing is covered.
   2. The page picks its layout from the width it really has, not the window's. Every content breakpoint below
      mirrors an existing @media rule as a container query on .main. Thresholds are the media threshold minus
      the sidebar (264px) and never above 596px, the narrowest the page is shown in its wide layout today, so a
      screen only switches to its compact layout when it is narrower than it has ever been shown wide.
   3. Phones, touch screens and installed (PWA) use: touch targets, no zoom on focus, safe areas.
   Loaded last, so equal-specificity rules here win. */

/* ---------- 1. docked Agent Assistant ---------- */
:root { --asst-w: 440px; }
.main { container: main / inline-size; }
.app { transition: padding-right .22s cubic-bezier(.2, .8, .2, 1); }
body.asst-dock.asst-open .app { padding-right: var(--asst-w); }
body.asst-dock .asst, body.asst-dock .asst.wide { width: var(--asst-w); box-shadow: none; }
body.asst-dock.asst-open .asst { box-shadow: -1px 0 0 var(--border), -18px 0 40px -34px rgba(0, 0, 0, .35); }
body.asst-resizing, body.asst-resizing * { cursor: col-resize !important; user-select: none !important; }
body.asst-resizing .app, body.asst-resizing .asst { transition: none; }

.asst-grip { position: absolute; left: -4px; top: 0; bottom: 0; width: 8px; z-index: 2; cursor: col-resize; touch-action: none; outline: none; }
.asst-grip::after { content: ''; position: absolute; left: 3px; top: 50%; width: 2px; height: 44px; margin-top: -22px; border-radius: 2px; background: var(--border2); opacity: 0; transition: opacity .15s, background .15s; }
.asst-grip:hover::after, .asst-grip:focus-visible::after, body.asst-resizing .asst-grip::after { opacity: 1; background: var(--accent); }
@media (max-width: 760px) { .asst-grip { display: none; } }

/* Floating pieces move left with the panel instead of hiding under it. */
body.asst-dock.asst-open .vp:not(.vp-inline), body.asst-dock.asst-open .vp-standby { right: calc(var(--asst-w) + 16px); }
body.asst-dock.asst-open .toast { left: calc((100vw - var(--asst-w)) / 2); }
body.asst-dock.asst-open.ws-open #wsPanel.max { right: var(--asst-w); }
body.asst-dock.asst-open.ws-open .main { grid-template-columns: minmax(0, 1fr) min(50%, var(--wsw, 46%)); }
@media (max-width: 860px) { body.asst-dock.asst-open.ws-open #wsPanel { right: var(--asst-w); } }
@media (max-width: 1240px) { body.asst-dock.asst-open.ws-open .main { display: flex; flex-direction: column; } body.asst-dock.asst-open.ws-open #wsPanel { position: fixed; inset: 52px var(--asst-w) 0 auto; width: min(560px, calc(100vw - var(--asst-w))); z-index: 90; box-shadow: var(--shadow-lg); } body.asst-dock.asst-open.ws-open #wsPanel.max { left: 0; width: auto; box-shadow: none; } }
@media (prefers-reduced-motion: reduce) { .app { transition: none; } }

/* ---------- 2. layouts that follow the page's own width ---------- */
/* index.html (max-width: 900px) hero */
@container main (max-width: 636px) {
  .ob-card.ob-hero { max-width: 540px; }
  .hero2 { grid-template-columns: 1fr; gap: 26px; }
  .hero2-l h1 { font-size: 30px; letter-spacing: -0.8px; margin: 22px 0 10px; }
  .hero2-cta { justify-content: flex-start; }
  .hero2-r { grid-template-columns: repeat(3, 1fr); }
  .pr-wrap { grid-template-columns: 1fr; } .pr-side { border-left: none; border-top: 1px solid var(--border); }
}
/* projects.css (max-width: 1000px) */
@container main (max-width: 736px) {
  .pj-detail { grid-template-columns: minmax(0, 1fr); }
  .pj-aside { padding-top: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); }
}
/* agent pages: four starter cards become two rows before they get cramped */
@container main (max-width: 720px) {
  .agent-intro .welcome-orb-wrap > :nth-child(3) { grid-template-columns: 1fr 1fr !important; }
}
/* index.html, v8.css, refine.css, faces.css, polish.css, home.css, projects.css: 860, 760, 720, 640 and 620px rules */
@container main (max-width: 596px) {
  .content { padding: 18px 16px 30px; } .dock { padding: 8px 12px 12px; }
  .home { padding: 24px 16px 60px; }
  .home-head { flex-wrap: wrap; } .seg { margin-left: 0; }
  .plans { grid-template-columns: 1fr; }
  .settings { flex-direction: column; } .set-nav { width: auto; border-right: none; border-bottom: 1px solid var(--border); display: flex; overflow-x: auto; padding: 8px; }
  .set-nav .nav-item { width: auto; white-space: nowrap; }
  .set-body { padding: 20px 16px 40px; }
  .feat-row { grid-template-columns: 1fr; }
  .limits { grid-template-columns: 1fr 1fr; } .set-group { display: none; }
  .top-actions .hide-sm { display: none; }
  .run-actions { margin-left: 0; }
  .stage-grid { grid-template-columns: 1fr; }
  .proof-row { grid-template-columns: 1fr; }
  .pg { padding: 18px 16px 40px; }
  .mk-grid { grid-template-columns: 1fr; } .mk-grid .mk-row:nth-child(odd) { border-right: none; }
  .cards3 { grid-template-columns: 1fr; }
  .mem-wrap { grid-template-columns: 1fr; } .mem-tree { border-right: none; border-bottom: 1px solid var(--border); }
  .page, .pad { padding: 20px 16px 40px; }
  .content.agent-intro { padding: 20px 16px 110px; }
  .agent-intro .welcome-orb-wrap { grid-template-columns: 1fr; grid-template-areas: 'face' 'info' 'cta' 'cards'; text-align: center; }
  .agent-intro .welcome-orb-wrap > :nth-child(1) { transform: scale(.7); margin: -30px 0 -26px; }
  .agent-intro .welcome-orb-wrap > :nth-child(4) { justify-self: center; }
  .agent-intro .welcome-orb-wrap > div > div[style*="max-width"] { margin: 10px auto 0 !important; }
  .agent-intro .welcome-orb-wrap > :nth-child(3) { grid-template-columns: 1fr 1fr !important; }
  .ags-hero, .ags.flip .ags-hero { grid-template-columns: 1fr; } .ags-hero > .ags-stage { width: min(100%, 340px); order: -1; } .ags-grid { grid-template-columns: 1fr 1fr; }
  .hp-hero { gap: 8px; align-items: flex-start; }
  .hp-grp-b.grid { grid-template-columns: 1fr; }
  .hp-ox-row { grid-template-columns: repeat(3, 1fr); } .hp-ox-h { flex-wrap: wrap; } .hp-ox-go { width: 100%; }
  .pj-wrap, .pj-detail { padding: 20px 16px 48px; }
  .pj-title { flex-direction: column; align-items: stretch; gap: 14px; }
  .pj-tpls { grid-template-columns: 1fr; }
  .ad-caps-grid, .ad-caps-full-grid { grid-template-columns: 1fr; }
  .tbl-wrap, .card:has(> table) { overflow-x: auto; }
}
/* index.html, faces.css (max-width: 560px) */
@container main (max-width: 560px) {
  .hero2-r { grid-template-columns: 1fr; }
  section.ags { margin: 16px 0; border-radius: 22px; } .ags-grid { grid-template-columns: 1fr; }
}
/* index.html (max-width: 430px) */
@container main (max-width: 430px) {
  .limits { grid-template-columns: 1fr 1fr; }
  .ob-card h1 { font-size: 22px; }
}

/* ---------- 3. phones, touch and installed app ---------- */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body { -webkit-tap-highlight-color: transparent; }
button, a, [role="button"], .chip, .nav-item, .sess { touch-action: manipulation; }

/* Fingers need bigger targets than a mouse (Apple asks for 44pt, Google for 48dp). Visual size stays the same:
   only the hit area grows where the design is tight. */
@media (pointer: coarse) {
  .icon-btn { min-width: 40px; min-height: 40px; }
  .side-sec .icon-btn { width: 36px; height: 36px; }
  .nav-item, .sess { min-height: 44px; }
  .btn { min-height: 40px; }
  .asst-send { width: 40px; height: 40px; }
  .chip { min-height: 36px; min-width: 36px; }
  .nav-sub, .asst-title { min-height: 40px; }
  .vp-ib { min-width: 36px; min-height: 36px; }
  .asst-sug { padding: 12px 14px; }
  /* iOS zooms into any field under 16px when it gets focus; keep fields at 16px on touch screens. */
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea { font-size: max(16px, 1em); }
}

/* Notches and rounded corners in landscape and in the installed app. */
.topbar { padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.asst-h { padding-right: max(10px, env(safe-area-inset-right, 0px)); }
@media (max-width: 760px) {
  .asst-h { padding-top: max(10px, env(safe-area-inset-top, 0px)); }
  .asst { height: 100dvh; }
}

/* ---------- 4. sidebar on short screens ---------- */
/* The list scrolls under the Upgrade card and footer; a soft fade says there is more below. */
.side-scroll-wrap { scrollbar-width: thin; -webkit-mask-image: linear-gradient(#000 calc(100% - 28px), transparent); mask-image: linear-gradient(#000 calc(100% - 28px), transparent); padding-bottom: 20px; }
@media (max-height: 860px) and (pointer: fine) {
  .side .nav-item { padding-top: 5px; padding-bottom: 5px; }
  .side .nav-sub { margin-top: 2px; }
  .side-head { padding-top: 8px; padding-bottom: 4px; }
}

/* ---------- 5. no pop-up covers the page (v8/sheets.js) ---------- */
/* Dialogs, walls and voice screens open as a sheet in reserved space; the page shrinks beside or above it. */
:root { --asst-res: 0px; --vp-res: 0px; --sheet-res: 0px; --gr-res: 0px; }
@media (min-width: 1024px) { html.gr-dock body { --gr-res: 336px; } } /* the welcome agent's column (v8/greeter.css) */
body.asst-dock.asst-open { --asst-res: var(--asst-w); }
body.sheet-dock { --sheet-res: var(--sheet-w, 0px); }
.app { transition: padding-right .22s cubic-bezier(.2, .8, .2, 1), padding-bottom .22s cubic-bezier(.2, .8, .2, 1); }
body.sheet-dock .app { padding-right: calc(var(--asst-res) + var(--sheet-res)) !important; }

@media (min-width: 761px) {
  /* The voice panel docks as its own column from tablet width up (it used to float below 1180px). */
  body.vp-on { --vp-res: 372px; }
  .vp:not(.vp-min):not(.vp-inline) { top: 12px; bottom: 12px; right: 12px; max-height: none; }
  body.vp-on .main { padding-right: 372px; transition: padding-right .22s ease; }
  body.vp-on .asst-fab { right: 384px; }
  body.asst-dock.asst-open .vp:not(.vp-min):not(.vp-inline) { right: calc(var(--asst-w) + 12px); }

  body.sheet-dock :is(.v8-scrim, .sc-wrap, .pw.open, #cancelFlow.open, #vault-modal.show, .vm-overlay, #voiceOverlay.active, .cog-ov, .cmp-sheet) {
    inset: 0 calc(var(--asst-res) + var(--vp-res) + var(--mt-res, 0px) + var(--gr-res)) 0 auto !important; width: var(--sheet-w) !important; max-width: none !important;
    padding: 0 !important; display: flex; flex-direction: column; align-items: stretch !important; justify-content: flex-start;
    overflow-y: auto; overscroll-behavior: contain; border-left: 1px solid var(--border); border-radius: 0;
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
    box-shadow: -18px 0 40px -34px rgba(0, 0, 0, .35); animation: sheetIn .24s cubic-bezier(.2, .8, .2, 1) both;
  }
  body.sheet-dock :is(.vm-overlay, #voiceOverlay.active) { justify-content: center !important; align-items: center !important; }
}
@keyframes sheetIn { from { opacity: 0; transform: translateX(28px); } to { opacity: 1; transform: none; } }

/* Light dialogs take the panel colour; the premium walls and voice screens keep their dark look. */
body.sheet-dock :is(.v8-scrim, .sc-wrap, #cancelFlow.open, #vault-modal.show, .cog-ov, .cmp-sheet) { background: var(--panel) !important; }
body.sheet-dock :is(.pw.open, .vm-overlay, #voiceOverlay.active) { background: #0A0A10 !important; }
/* The dialog fills its sheet. */
body.sheet-dock :is(.v8-modal, .pal, .sc, #cancelFlow .cf-card, #vault-modal-box, .cog-ov > div, .cmp-sheet > div, .pw-card) {
  width: 100% !important; max-width: none !important; min-height: 100%; margin: 0 !important; border: none !important; border-radius: 0 !important; box-shadow: none !important;
}
body.sheet-dock .v8-modal { display: flex; flex-direction: column; }
body.sheet-dock .v8-modal-b { flex: 1; max-height: none; }
body.sheet-dock .v8-modal-f { position: sticky; bottom: 0; }
body.sheet-dock .pal-list { max-height: none; }
body.sheet-dock .sc { height: auto; min-height: 100%; }
body.sheet-dock .pw-card { display: flex; flex-direction: column; justify-content: safe center; padding-top: 56px; }
body.sheet-dock #cancelFlow .cf-card { display: flex; flex-direction: column; }
body.sheet-dock #vault-modal-box { max-height: none; }

/* Phones: a sheet along the bottom; the page ends where the sheet starts and scrolls above it. */
@media (max-width: 760px) {
  body.sheet-dock .app { padding-right: 0 !important; padding-bottom: var(--sheet-h, 0px); }
  body.sheet-dock :is(.v8-scrim, .sc-wrap, .pw.open, #cancelFlow.open, #vault-modal.show, .vm-overlay, #voiceOverlay.active, .cog-ov, .cmp-sheet) {
    inset: auto 0 0 0 !important; top: auto !important; height: auto !important; max-height: 70dvh !important; width: auto !important;
    padding: 0 0 env(safe-area-inset-bottom, 0px) !important; display: flex; flex-direction: column; align-items: stretch !important; justify-content: flex-start !important;
    overflow-y: auto; overscroll-behavior: contain; border-top: 1px solid var(--border); border-radius: 18px 18px 0 0 !important;
    backdrop-filter: none !important; -webkit-backdrop-filter: none !important;
    box-shadow: 0 -18px 40px -30px rgba(0, 0, 0, .4); animation: sheetUp .26s cubic-bezier(.2, .8, .2, 1) both;
  }
  body.sheet-dock :is(.vm-overlay, #voiceOverlay.active) { align-items: center !important; padding-top: 18px !important; gap: 14px !important; }
  body.sheet-dock :is(.v8-modal, .sc, .cog-ov > div, .cmp-sheet > div, .pw-card, #cancelFlow .cf-card, #vault-modal-box) { min-height: 0; }
  body.sheet-dock .sc { height: 70dvh; }
  body.sheet-dock .pw-card { padding: 30px 22px 22px; }
  body.sheet-dock .pal-list { max-height: 46dvh; }
}
@keyframes sheetUp { from { opacity: 0; transform: translateY(40px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { body.sheet-dock :is(.v8-scrim, .sc-wrap, .pw.open, #cancelFlow.open, #vault-modal.show, .vm-overlay, #voiceOverlay.active, .cog-ov, .cmp-sheet) { animation: none; } }

/* Small bars that stay on screen (voice standby, minimised call, screen control): the page can scroll clear of them. */
body.pill-on .view { padding-bottom: 76px; }

/* Notifications sit in the top bar's free middle instead of over the page. */
.toast { top: 10px; bottom: auto; left: calc(50% + var(--side-res, 0px) / 2 - (var(--asst-res) + var(--vp-res) + var(--sheet-res)) / 2); transform: translate(-50%, -8px); max-width: min(560px, 50vw); line-height: 1.35; padding: 8px 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toast.show { transform: translate(-50%, 0); }
@media (max-width: 760px) { .toast { left: 50%; top: calc(8px + env(safe-area-inset-top, 0px)); max-width: calc(100vw - 120px); } }
/* The Ask button waits while a sheet is open, so it never sits on the sheet's own buttons. */
body.sheet-dock :is(.asst-fab, .gr.gr-min) { opacity: 0; pointer-events: none; transform: translateY(8px); transition: opacity .15s, transform .15s; }

/* Phones: page actions in the top bar (a search box and a button) stay on the bar's one line instead of
   spilling out above and below it; the search box gives up width first. */
@media (max-width: 640px) {
  .topbar .top-actions { min-width: 0; flex: 0 1 auto; }
  .topbar .top-actions .hstack { flex-wrap: nowrap; min-width: 0; }
  .topbar .top-actions .field { width: 100% !important; min-width: 64px; max-width: 38vw; }
  .topbar .top-actions > select { min-width: 0; max-width: 34vw; text-overflow: ellipsis; }
}
