/* V3 Studio navigation and mobile shell. Load after the base styles.
   State belongs to mobile.js; this file never changes workflow controls or APIs. */

/* Author display:flex/grid rules must not defeat the hidden attribute used by UI. */
[hidden] { display: none !important; }

.mobile-section-title,
.mobile-action-dock { display: none; }

:root {
  --studio-nav-height: 72px;
  --studio-nav-safe: env(safe-area-inset-bottom, 0px);
  --studio-action-height: 70px;
}

/* One permanent menu for every viewport. Its height is reserved in the scroller. */
#views { padding-bottom: calc(var(--studio-nav-height) + var(--studio-nav-safe) + 24px); }
.studio-bottom-nav {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(var(--studio-nav-height) + var(--studio-nav-safe));
  padding: 6px max(12px, env(safe-area-inset-right), calc((100vw - 900px) / 2)) calc(6px + var(--studio-nav-safe)) max(12px, env(safe-area-inset-left), calc((100vw - 900px) / 2));
  border-top: 1px solid var(--line-hi);
  background: var(--panel);
  box-shadow: 0 -4px 20px rgba(15, 32, 51, .06);
  backdrop-filter: blur(16px);
}
.studio-bottom-nav > a,
.studio-bottom-nav > button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  min-height: 44px;
  margin: 0;
  padding: 4px 5px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font: 500 13px/1.3 var(--font);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
.studio-bottom-nav svg { width: 21px; height: 21px; flex: 0 0 auto; }
.studio-bottom-nav span { max-width: 100%; overflow-wrap: anywhere; }
.studio-bottom-nav > .is-on,
.studio-bottom-nav > [aria-current="page"],
.studio-bottom-nav > [aria-expanded="true"] {
  color: var(--signal-text, var(--signal));
  background: var(--signal-lo);
}
.studio-bottom-nav > :hover { background: var(--panel-hi); }
#nav.studio-more-menu {
  position: fixed;
  z-index: 40;
  right: max(12px, env(safe-area-inset-right), calc((100vw - 900px) / 2));
  bottom: calc(var(--studio-nav-height) + var(--studio-nav-safe) + 10px);
  display: grid;
  gap: 6px;
  width: min(360px, calc(100vw - 24px));
  max-height: calc(100dvh - var(--studio-nav-height) - var(--studio-nav-safe) - 32px);
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--line-hi);
  border-radius: var(--r-lg);
  background: var(--panel);
  box-shadow: 0 8px 30px rgba(15, 32, 51, .16);
}
.studio-more-menu .nav-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-height: 56px;
  padding: 10px 12px;
  white-space: normal;
}
.studio-more-menu b { font-size: 15px; font-weight: 600; }
.studio-more-menu span { color: var(--muted); font-size: 12px; }
.studio-bottom-nav > :focus-visible,
.studio-more-menu > :focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: -3px;
}

.mobile-advanced {
  grid-column: 1 / -1;
  min-width: 0;
  border-top: 1px solid var(--line);
}
.mobile-advanced > summary {
  min-height: 44px;
  padding: 12px 0;
  color: var(--text-soft);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  list-style-position: inside;
}
.mobile-advanced > summary::marker { color: var(--signal); }
.mobile-advanced > summary:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
  border-radius: var(--r-sm);
}
.advanced-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 20px;
  padding-top: 8px;
}
.advanced-fields > .trait { min-width: 0; }
.advanced-fields > .trait-wide { grid-column: 1 / -1; }

/* The old wrapped header retained a 56px flex-basis. Its navigation needs to
   contribute to its actual block height before the guest banner is laid out. */
@media (max-width: 1100px) {
  .topbar {
    position: relative;
    height: auto;
    min-height: 64px;
    flex: 0 0 auto;
    flex-wrap: wrap;
    padding-top: 10px;
    padding-bottom: 10px;
    row-gap: 8px;
  }
  .tophav {
    display: flex;
    order: 10;
    flex: 0 0 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    padding-top: 4px;
    scrollbar-width: thin;
  }
  .tophav .nav-item {
    flex: 0 0 auto;
    white-space: nowrap;
  }
}

@media (min-width: 621px) and (max-width: 980px) {
  .auto-opts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auto-opts > .trait { min-width: 0; }
  .auto-opts select { min-width: 0; max-width: 100%; }
  .result-acts { flex-wrap: wrap; }
}

@media (max-width: 620px) {
  html, body { height: auto; overflow: visible; }
  .app { height: auto; min-height: 100vh; min-height: 100svh; }
  .views { flex: 1 0 auto; overflow: visible; min-width: 0; }
  .view { padding: 18px 12px 36px; min-width: 0; }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 8px 6px;
    flex: 0 0 auto;
    height: auto;
    min-height: 0;
    padding: 10px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
  }
  .topbar .brand { grid-column: 1; grid-row: 1; min-width: 0; gap: 7px; }
  .topbar .brand > span:last-child { min-width: 0; }
  .topbar .brand-meter { width: 18px; flex: 0 0 18px; }
  .topbar .brand-name {
    display: block;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar .brand-sub,
  .topbar-spacer { display: none; }
  .topbar .acct {
    grid-column: 2;
    grid-row: 1;
    min-height: 44px;
    max-width: 90px;
    padding: 7px 8px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
  }
  .topbar .status {
    grid-column: 3;
    grid-row: 1;
    gap: 5px;
    max-width: 96px;
    padding: 6px;
    font-size: 10.5px;
    line-height: 1.4;
  }

  .studio-bottom-nav > a,
  .studio-bottom-nav > button { font-size: 11px; padding: 3px 2px; }

  .banner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 44px;
    align-items: center;
    gap: 6px 10px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.6;
  }
  .banner > span { grid-column: 1 / -1; overflow-wrap: anywhere; }
  .banner-btn { justify-self: start; min-height: 44px; padding: 9px 12px; }
  .banner-x { width: 44px; min-height: 44px; margin: 0; font-size: 16px; }

  .view-head { margin-bottom: 16px; gap: 8px; }
  .view-title { font-size: 24px; line-height: 1.4; }
  .view-sub { font-size: 14px; line-height: 1.65; }
  .mobile-section-title {
    display: block;
    margin: 22px 0 10px;
    color: var(--text-soft);
    font-size: 16px;
    font-weight: 600;
    line-height: 1.5;
  }
  .mobile-section-title:first-child { margin-top: 0; }
  .drop-bulk { padding: 18px 12px; font-size: 14px; line-height: 1.6; }
  .drop-bulk b { display: block; font-size: 18px; line-height: 1.45; }
  .drop-bulk span { font-size: 12px; overflow-wrap: anywhere; }
  .drop-bulk-ic { width: 44px; height: 44px; margin-bottom: 9px; }

  .auto-opts { grid-template-columns: minmax(0, 1fr); gap: 18px; padding: 14px; margin-top: 0; }
  .auto-opts > .trait { min-width: 0; }
  .advanced-fields { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .mobile-advanced > summary { font-size: 15px; }
  .trait label { font-family: var(--font); font-size: 13px; letter-spacing: 0; text-transform: none; }
  .views input:not([type="range"]):not([type="checkbox"]):not([type="radio"]):not([type="file"]),
  .views select,
  .views textarea,
  .modal input {
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    font-size: 16px;
  }
  .range-full { min-height: 44px; margin-top: 0; }
  .seg-b { min-height: 44px; font-size: 14px; }
  .sub-swatch { min-height: 44px; }
  .subtitle-size-heading { gap: 8px; align-items: center; }
  .subtitle-size-heading label,
  .subtitle-size-heading output { font-size: 14px; }
  .trait .subtitle-size-auto { min-height: 44px; margin: 3px 0 5px; font-size: 14px; }
  .subtitle-size-auto input { width: 20px; height: 20px; }
  .subtitle-size-inputs { gap: 8px; }
  .subtitle-size-inputs input[type="number"] { min-height: 44px; font-size: 16px; }
  .subtitle-size-hint,
  .subtitle-batch-note { font-size: 13px; line-height: 1.6; }

  .auto-bar { gap: 10px; }
  .auto-bar > .go { flex: 1 0 100%; min-height: 48px; margin-top: 0; }
  .auto-bar .btn-quiet,
  .auto-bar .link-btn { min-height: 44px; }
  .auto-count { margin-left: 0; width: 100%; font-size: 12px; overflow-wrap: anywhere; }
  .result-acts { flex-wrap: wrap; align-items: center; }
  .result-acts > label { flex: 1 0 100%; font-size: 14px; }
  .result-acts > select { flex: 1 0 100%; width: 100%; }
  .result-acts > .btn-quiet { min-height: 44px; flex: 1 1 130px; }
  .cinputs,
  .cvoices { min-width: 0; }
  .cinput,
  .cvoice { min-width: 0; max-width: 100%; flex-wrap: wrap; overflow-wrap: anywhere; }
  .cinput .cx { min-width: 44px; min-height: 44px; font-size: 16px; }
  .qrow { grid-template-columns: 56px minmax(0, 1fr); gap: 10px; padding: 10px; }
  .qthumb { width: 56px; height: 56px; }
  .qname { white-space: normal; overflow-wrap: anywhere; font-size: 14px; }
  .qmeta { display: block; margin: 3px 0 0; }
  .qmsg { flex-wrap: wrap; gap: 4px 7px; font-size: 13px; overflow-wrap: anywhere; }
  .qmsg > * { min-width: 0; }
  .qacts { gap: 6px; }
  .qacts .btn-quiet,
  .qacts a.btn-quiet,
  .qacts .qx { min-height: 44px; padding: 10px; font-size: 13px; }
  .qacts .qx { min-width: 44px; }
  .qrecipe,
  .qscript { overflow-wrap: anywhere; }
  .qpreview video { max-height: 65vh; max-height: 65svh; }

  body[data-mobile-flow="auto"] #views,
  body[data-mobile-flow="autocute"] #views,
  body[data-mobile-flow="autocutegreen"] #views,
  body[data-mobile-flow="voiceonly"] #views {
    padding-bottom: calc(var(--studio-nav-height) + var(--studio-nav-safe) + var(--studio-action-height) + 24px);
  }
  body[data-mobile-flow="auto"] .mobile-action-dock,
  body[data-mobile-flow="autocute"] .mobile-action-dock,
  body[data-mobile-flow="autocutegreen"] .mobile-action-dock,
  body[data-mobile-flow="voiceonly"] .mobile-action-dock {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;
    position: fixed;
    z-index: 20;
    left: 0;
    right: 0;
    bottom: calc(var(--studio-nav-height) + var(--studio-nav-safe));
    min-height: var(--studio-action-height);
    padding: 10px max(12px, env(safe-area-inset-right)) 10px max(12px, env(safe-area-inset-left));
    border-top: 1px solid var(--line-hi);
    background: var(--panel);
    box-shadow: 0 -8px 24px rgba(15, 32, 51, .08);
  }
  .mobile-action-dock .go,
  .mobile-action-dock .btn-quiet {
    min-width: 0;
    min-height: 48px;
    margin: 0;
    padding: 10px 14px;
    font-size: 15px;
    line-height: 1.4;
  }
  .mobile-action-dock .go { width: 100%; justify-content: center; }
  .mobile-action-dock .btn-quiet { max-width: 122px; font-size: 13px; }
  body.mobile-keyboard-open .mobile-action-dock,
  body.mobile-keyboard-open .studio-bottom-nav,
  body.mobile-keyboard-open .studio-more-menu { display: none !important; }

  #nav .nav-item:focus-visible,
  .mobile-action-dock > :focus-visible,
  .drop-bulk:focus-visible {
    outline: 2px solid var(--signal);
    outline-offset: 3px;
  }
}
