/* Web Builder Agent web-app add-on: mobile layout. Loaded after the app's stylesheet.
   The compiled app's Tailwind utilities live in cascade layers, so these unlayered rules win without !important.
   Selectors match class strings of the compiled bundle (see scripts/check_addon_selectors.py), and :has() keeps
   React-managed nodes untouched. mobile.js adds the editor's Chat | Preview switch (html[data-sgm-pane]) and the
   public header's menu button (.sgm-menu-btn, html[data-sgm-menu]).
   Editor root: #root .flex.h-screen:has(> aside[class~="w-[360px]"]) */

.sgm-switch, .sgm-menu-btn { display: none; }

/* ---------------------------------------------------------------- every screen size */
/* A card never grows wider than its grid column: a long site name, address or message preview is cut off with
   "..." inside the card instead of pushing the card, and the whole page, past the edge of the screen. */
#root main .grid > * { min-width: 0; }
#root main p.line-clamp-2 { overflow-wrap: anywhere; }

/* "Sign in with Google" sits in an iframe whose page is light. The app is color-scheme: dark, and when the two
   differ browsers paint an opaque white box behind the iframe. Matching the iframe's scheme keeps it transparent. */
iframe[src^="https://accounts.google.com/gsi/"] { color-scheme: light; }

@media (max-width: 1023.98px) {
  /* No sideways scrolling anywhere */
  #root { overflow-x: clip; }

  /* ---------------------------------------------------------------- editor: one pane at a time */
  #root .flex.h-screen:has(> aside[class~="w-[360px]"]) {
    height: 100vh;
    height: 100dvh; /* the chat input stays above the mobile browser bar */
    flex-direction: column;
    padding-top: calc(45px + env(safe-area-inset-top, 0px));
  }
  #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > aside {
    width: 100%;
    flex: 1 1 auto;
    min-height: 0;
    border-right: 0;
  }
  #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > section {
    flex: 1 1 auto;
    min-height: 0;
  }
  html[data-sgm-pane="chat"] #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > section { display: none; }
  html[data-sgm-pane="preview"] #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > aside { display: none; }
  /* The switch bar has its own back button */
  #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > aside a[aria-label="Back to your sites"] { display: none; }

  /* Preview toolbar: page tabs on the first row, controls on the next, wrapping when needed */
  #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > section > div:first-child {
    flex-wrap: wrap;
    justify-content: flex-end;
  }
  #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > section > div:first-child > .overflow-x-auto {
    flex: 1 1 100%;
    min-width: 0;
  }
  #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > section > div:first-child > div.px-3 {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 6px;
    margin-left: auto;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  /* The code-viewer add-on floats its buttons when Publish is hidden (Chat pane); they live in the Preview toolbar */
  html[data-sgm-editor] .scv-float { display: none; }

  /* ---------------------------------------------------------------- Chat | Preview switch (mobile.js) */
  html[data-sgm-editor] .sgm-switch {
    display: flex;
    align-items: center;
    gap: 8px;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 40; /* above the panes, below dialogs (z-50) and the Files viewer */
    height: 44px;
    box-sizing: content-box;
    padding: env(safe-area-inset-top, 0px) 12px 0;
    background: #09090b;
    border-bottom: 1px solid #27272a;
    font-family: inherit;
  }
  .sgm-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 8px;
    color: #a1a1aa;
    text-decoration: none;
  }
  .sgm-back:active, .sgm-back:hover { background: #18181b; color: #fafafa; }
  .sgm-seg {
    display: flex;
    flex: 1;
    max-width: 320px;
    margin: 0 auto;
    padding: 3px;
    gap: 3px;
    background: #18181b;
    border: 1px solid #27272a;
    border-radius: 10px;
  }
  .sgm-seg button {
    flex: 1;
    border: 0;
    border-radius: 7px;
    padding: 7px 0;
    background: transparent;
    color: #a1a1aa;
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .sgm-seg button[aria-pressed="true"] { background: #27272a; color: #fafafa; box-shadow: inset 0 -2px 0 #34d399; }
  .sgm-spacer { width: 36px; flex-shrink: 0; }
}

/* Touch screens: 16px text in form fields, otherwise iOS zooms in when you tap one */
@media (max-width: 1023.98px) and (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
  select,
  textarea {
    font-size: 16px !important; /* !important: beats the per-field text-sm / text-xs utilities */
  }
}

@media (max-width: 639.98px) {
  /* Editor: the screen already is a phone, so drop the desktop/mobile preview toggle (always the last two buttons) */
  #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > section > div:first-child > div.px-3 > button:nth-last-child(-n + 2) {
    display: none;
  }
  /* Edge-to-edge preview */
  #root .flex.h-screen:has(> aside[class~="w-[360px]"]) > section > div.relative.overflow-auto.p-4 { padding: 0; }

  /* Public pages (home, pricing, admin): tighter side padding. The header gets a menu button (below, < 768px);
     if mobile.js didn't run, its links at least wrap instead of running off the screen. */
  #root header.justify-between.px-6.py-3 { padding-left: 16px; padding-right: 16px; gap: 12px; }
  #root header.justify-between.px-6.py-3:not(:has(> .sgm-menu-btn)) > nav { gap: 12px; row-gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  #root main.px-6 { padding-left: 16px; padding-right: 16px; }
  #root main.px-6.py-20, #root main.px-6.py-16 { padding-top: 40px; padding-bottom: 40px; }
}

/* ---------------------------------------------------------------- public header (home, pricing, admin): menu */
/* Phones and small tablets: the name on the left, "Get started" (signed out) and a menu button on the right.
   The menu button (mobile.js) opens the header's own links as a panel under the bar. */
@media (max-width: 767.98px) {
  #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) {
    position: relative;
    z-index: 30; /* the open panel covers the page; dialogs (z-50) still go on top */
    gap: 8px;
    padding-left: 16px;
    padding-right: 12px;
  }
  /* On the narrowest screens the name is cut off with "...", it never pushes the buttons off */
  #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > a:first-child {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav {
    flex-shrink: 0;
    gap: 8px;
    margin-left: auto;
  }
  html:not([data-sgm-menu="open"]) #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav > :not([href="/signup"]) {
    display: none;
  }
  #root header.justify-between.px-6.py-3 > .sgm-menu-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    margin: -4px -4px -4px 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #d4d4d8;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  #root header.justify-between.px-6.py-3 > .sgm-menu-btn:hover,
  #root header.justify-between.px-6.py-3 > .sgm-menu-btn[aria-expanded="true"] { background: #18181b; color: #fafafa; }

  /* Open: a solid bar, the page dimmed behind it, and the links stacked in a panel under the bar */
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) { background: #09090b; }
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn)::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    background: rgba(0, 0, 0, 0.6);
  }
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin: 0;
    padding: 4px 16px 16px;
    max-height: calc(100dvh - 64px);
    overflow-y: auto;
    background: #09090b;
    border-bottom: 1px solid #27272a;
    font-size: 16px;
    line-height: 1.4;
  }
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav > a {
    display: block;
    padding: 12px 4px;
    border-bottom: 1px solid #18181b;
  }
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav > a[href="/admin"] {
    align-self: flex-start;
    margin: 12px 4px 4px;
    padding: 4px 10px;
    border-bottom: 0;
    font-size: 13px;
  }
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav > a[href="/signup"] {
    margin-top: 14px;
    padding: 11px 12px;
    border-bottom: 0;
    border-radius: 8px;
    text-align: center;
    font-weight: 500;
  }
  /* Signed in: picture, name and Sign out on one row */
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav > div {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
    padding-top: 14px;
    border-top: 1px solid #27272a;
  }
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav > div > img { width: 32px; height: 32px; }
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav > div > span {
    display: block;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
  }
  html[data-sgm-menu="open"] #root header.justify-between.px-6.py-3:has(> .sgm-menu-btn) > nav > div > button {
    margin-left: auto;
    padding: 8px 14px;
    border: 1px solid #3f3f46;
    border-radius: 8px;
    font-size: 14px;
    color: #e4e4e7;
  }
}

/* ---------------------------------------------------------------- dashboard pages */
@media (max-width: 1023.98px) {
  /* Inbox: the site picker in the top bar sizes itself to the longest site name; keep room for the title */
  #root header.gap-3.px-4.py-3 select { max-width: 42vw; }
}

@media (max-width: 639.98px) {
  /* Sites: full-width search, then the All | Live | Draft filter and the count */
  #root main input[placeholder="Search sites"] { flex: 1 1 100%; max-width: none; }

  /* Site cards: "Open editor" across the card, then View live / Rename / Delete as equal, easy-to-tap buttons */
  #root main article > .border-t.flex-wrap.gap-2 > * {
    flex: 1 1 0;
    margin-left: 0;
    padding-top: 9px;
    padding-bottom: 9px;
    text-align: center;
    white-space: nowrap;
  }
  #root main article > .border-t.flex-wrap.gap-2 > :first-child { flex-basis: 100%; }
  #root main article > .border-t.flex-wrap.gap-2 > button:last-child { border: 1px solid #27272a; }
}
