/* ==========================================================================
   App-style mobile layer: bottom tab bar, safe areas, touch sizing and
   phone layouts for SIMA+ and account settings. Loaded after every other sheet.
   ========================================================================== */

/* ---- Touch basics (all sizes) ---- */
html { -webkit-tap-highlight-color: transparent; }
a, button, label, summary, select, input[type='checkbox'], input[type='radio'] { touch-action: manipulation; }
#main { outline: none; }
#main.page-in { animation: page-in .22s var(--ease, ease) both; }
@keyframes page-in { from { opacity: 0; transform: translateY(6px); } }

/* Private forecasts list headings (was in a stylesheet no page loaded). */
.rq-h { font-size: 1.15rem; margin: 22px 0 12px; display: flex; align-items: center; gap: 8px; }
.rq-h span { font-size: .8rem; background: var(--line); border-radius: 99px; padding: 1px 9px; }

/* Account section bar: icons stay hidden on desktop, where it is a vertical list. */
.acct-nav a { display: flex; align-items: center; gap: 8px; }
.acct-nav a svg { width: 16px; height: 16px; flex: none; opacity: .75; }
.acct-nav a.on { background: var(--ice-3); color: var(--cobalt); }
.acct-quick { gap: 8px; margin: 2px 0 6px; }
.wz-note { position: relative; }
.wz-note .since-x { margin-left: auto; color: var(--ink-2); flex: none; }

/* ---- Bottom tab bar (hidden on desktop) ---- */
.tabbar { display: none; }

@media (max-width: 820px) {
  :root { --tabbar-h: 62px; }

  .tabbar {
    display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 900;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--surface) 94%, transparent);
    -webkit-backdrop-filter: saturate(1.6) blur(16px); backdrop-filter: saturate(1.6) blur(16px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 18px rgba(20, 40, 60, .07);
  }
  .tabbar-in { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); height: var(--tabbar-h); padding: 0 max(4px, env(safe-area-inset-left, 0px)) 0 max(4px, env(safe-area-inset-right, 0px)); }
  .tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-width: 0; color: var(--muted); text-decoration: none; font: 700 .7rem/1 var(--f-ui); letter-spacing: .01em; position: relative; }
  .tab-ic { position: relative; display: grid; place-items: center; width: 54px; height: 30px; border-radius: 999px; transition: background .2s, color .2s; }
  .tab-ic svg { width: 22px; height: 22px; }
  .tab-l { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
  .tab.on { color: var(--cobalt); }
  .tab.on .tab-ic { background: var(--ice-2); }
  .tab:active .tab-ic { background: var(--ice-3); transform: scale(.94); }
  .tab-dot { position: absolute; top: 2px; right: 12px; width: 10px; height: 10px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 2px var(--surface); }

  /* Room for the tab bar, and floating UI lifted above it. */
  body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px)); }
  .toast { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px); max-width: calc(100% - 32px); text-align: center; }
  .consent { bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 10px); left: 10px; right: 10px; padding: 16px; border-radius: 18px; max-height: 60vh; overflow-y: auto; }
  .consent .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .consent .btn { height: 44px; }
  .site-footer { margin-top: 24px; }
  .foot-top { padding: 36px 0 24px; gap: 24px; }
  .foot-bottom { padding-bottom: 20px; }

  /* Header: compact app bar. The tab bar now covers the main links, so the menu stays for everything else. */
  .site-header { padding-top: env(safe-area-inset-top, 0px); }
  .hdr-cta { display: none; }
  .icon-btn, .search-trigger { width: 40px; height: 40px; }

  /* Drawer: a full-screen sheet that clears the notch and the home indicator. */
  .drawer-hd { padding-top: env(safe-area-inset-top, 0px); height: calc(var(--header-h) + env(safe-area-inset-top, 0px)); }
  .drawer-bd { padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px)); }
  .drawer-list a { min-height: 50px; }

  /* Search: a top sheet on phones. */
  .palette-scrim { padding: calc(10px + env(safe-area-inset-top, 0px)) 10px 10px; }
  .palette { border-radius: 18px; max-height: calc(100dvh - 20px - env(safe-area-inset-top, 0px)); display: flex; flex-direction: column; }
  .palette-results { overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; min-height: 0; max-height: none; }
  .palette-foot { display: none; }
  .palette-in kbd { display: none; }

  /* Install sheet and other bottom sheets clear the home indicator. */
  .inst-sheet { padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }

  /* Inputs at 16px stop iPhone zooming the page when a field is tapped. */
  .input, .select, .textarea, input[type='text'], input[type='email'], input[type='password'], input[type='search'], input[type='tel'], input[type='number'], select, textarea { font-size: 16px; }
  .input, .select { min-height: 48px; }

  /* Comfortable tap targets. */
  .btn { min-height: 44px; }
  .btn-sm { height: 40px; min-height: 40px; }
  .check { min-height: 40px; align-items: center; }
  .check input { width: 22px; height: 22px; margin-top: 0; flex: none; }
  .chip { height: 32px; }
}

/* ---------- Phones: account settings ---------- */
@media (max-width: 820px) {
  .acct-grid { gap: 14px; }
  .acct-nav {
    position: sticky; top: calc(var(--header-h) + env(safe-area-inset-top, 0px)); z-index: 30;
    display: flex; gap: 6px; padding: 8px 16px; margin: 0 -16px; overflow-x: auto; scrollbar-width: none;
    border-radius: 0; border: 0; border-bottom: 1px solid var(--line); box-shadow: none;
    background: color-mix(in srgb, var(--bg) 90%, transparent);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
  }
  .acct-nav::-webkit-scrollbar { display: none; }
  .acct-nav a { flex: none; height: 38px; padding: 0 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); font-size: .86rem; }
  .acct-nav a.on { background: var(--cobalt); border-color: var(--cobalt); color: #fff; }
  .acct-nav a.on svg { opacity: 1; }
  .acct-main > .card { scroll-margin-top: calc(var(--header-h) + 72px); }
  .acct-main { gap: 14px; }
  .acct-main .h-section { font-size: 1.2rem; }

  .acct-list li { padding: 10px; gap: 8px; }
  .acct-list .switch-row { flex: 1 1 100%; min-width: 0; }
  .acct-list .switch-row > span:last-child { min-width: 0; }
  .acct-list li > .btn-sm { flex: 1 1 0; }
  .acct-list li > .btn-sm[data-up], .acct-list li > .btn-sm[data-down] { flex: 0 0 48px; font-size: 1.1rem; }
  .acct-list li:has(.switch-row) { justify-content: flex-end; }
  input.switch { width: 50px; height: 30px; }
  input.switch::after { width: 24px; height: 24px; }
  input.switch:checked::after { transform: translateX(20px); }

  .presets { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -4px; padding: 2px 4px; }
  .presets::-webkit-scrollbar { display: none; }
  .presets .btn { flex: none; }
  .checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 12px; }

  /* Primary save buttons go full width, like a native settings screen. */
  .acct-main .form > .btn-primary, .acct-main #x-save-layout, .acct-main #x-install { width: 100%; justify-self: stretch; }
  .acct-main .form > .row > .btn { flex: 1 1 auto; }
  #pl-region + .btn, .acct-main .field .row .btn { flex: none; }
}

/* ---------- Phones: compact hero banners in accounts ---------- */
@media (max-width: 640px) {
  .page-hero .wrap { padding: 18px 0 20px; }
  .page-hero .display { font-size: clamp(1.6rem, 7vw, 2rem); line-height: 1.12; }
  .page-hero .lede { font-size: .98rem; margin-top: 6px; }
  .page-hero .crumbs { display: none; }
  .page-hero .hero-meta { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; gap: 8px; margin-inline: -16px; padding: 2px 16px; }
  .page-hero .hero-meta::-webkit-scrollbar { display: none; }
  .page-hero .hero-meta > * { flex: none; }
  .page-hero .lede { overflow-wrap: anywhere; }
}

/* ---------- SIMA+ personal home ---------- */
/* The quick-jump bar used to stick at the very top, sliding under the sticky header. */
.qt-bar { top: var(--header-h); }
.qt-target { scroll-margin-top: calc(var(--header-h) + 64px); }
.hub-edit .hub-tools { top: calc(var(--header-h) + 58px); }

@media (max-width: 820px) {
  .qt-bar { top: calc(var(--header-h) + env(safe-area-inset-top, 0px)); padding: 8px 0; }
  .qt-chip { height: 38px; padding: 0 14px; }
  .my-hero .hb-glance { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin-inline: -16px; padding: 2px 16px; }
  .my-hero .hb-glance::-webkit-scrollbar { display: none; }
  .my-hero .hb-glance .chip { flex: none; }
  .rq-card { margin-top: 14px; }
  .my-hero .rq-card + .btn { width: 100%; }

  .my-wh { flex-wrap: wrap; gap: 10px; align-items: flex-end; }
  .my-wh > div:first-child { flex: 1 1 auto; min-width: 0; }
  .my-wh > .row, .my-wh > span.row { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .my-wh > .row::-webkit-scrollbar, .my-wh > span.row::-webkit-scrollbar { display: none; }
  .my-wh .btn, .my-wh .hb-pick { flex: none; }
  .hb-pick button { min-width: 36px; height: 34px; }

  .hub-more { flex-direction: column; align-items: stretch; text-align: left; }
  .hub-more .row { display: grid; grid-template-columns: 1fr 1fr; }
  .hub-edit .qt-target { width: calc(100% - 12px); border-radius: 18px; }
  .hub-tools button span { display: none; }
  .hub-tools button { min-width: 40px; height: 40px; }
  .hub-add { grid-template-columns: 1fr; }

  /* Hourly strip and planner scroll sideways instead of squashing on narrow screens. */
  .nw-hours { -webkit-overflow-scrolling: touch; scrollbar-width: none; margin-inline: -4px; padding-inline: 4px; }
  .nw-hours::-webkit-scrollbar { display: none; }
  .nw-main .nw-wx { width: 64px; height: 64px; }
  .cmp-wrap { margin-inline: -16px; padding-inline: 16px; -webkit-overflow-scrolling: touch; }
  .my-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .my-hero .display { font-size: clamp(1.5rem, 6.6vw, 1.9rem); }
  .my-hero .lede { display: none; }
  .section { padding: 20px 0; }
  .my-links { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Private forecasts and sign-in screens ---------- */
@media (max-width: 640px) {
  .rq-bar { flex-direction: column; align-items: stretch; }
  .rq-tabs { display: flex; }
  .rq-tabs button { flex: 1; min-height: 40px; }
  .rq-bar > .btn { width: 100%; }
  .auth-sec { padding-block: 14px 28px; }
  .auth-card { border-radius: 20px; }
  .auth-card .btn-primary, .auth-google { width: 100%; min-height: 50px; }
  .wz { padding: 18px 16px; }
  .wz-foot { position: sticky; bottom: calc(var(--tabbar-h, 0px) + env(safe-area-inset-bottom, 0px)); z-index: 5; margin-inline: -16px; padding: 12px 16px; background: color-mix(in srgb, var(--surface) 96%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); }
  .wz-foot .btn { flex: 1 1 auto; }
  .wz-regions, .wz-areas, .wz-cards { grid-template-columns: minmax(0, 1fr); }
}

/* ---------- Installed app (home-screen mode) ---------- */
.is-app .inst-banner { display: none; }
@media (max-width: 820px) {
  /* No browser chrome: nudge the header colour so it reads as an app bar. */
  .is-app .site-header { box-shadow: 0 1px 0 var(--line); }
}

@media (prefers-reduced-motion: reduce) {
  #main.page-in { animation: none; }
  .tab-ic { transition: none; }
}

@media print {
  .tabbar { display: none !important; }
  body { padding-bottom: 0 !important; }
}

/* Sign-out row at the end of account settings */
.acct-out { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.acct-out b { overflow-wrap: anywhere; }
@media (max-width: 820px) { .acct-out .btn { width: 100%; color: var(--high-fg, #8e1c1c); } }

/* Keep the account page inside the screen: grid/flex children may not grow past the viewport. */
.acct-main, .acct-main > *, .acct-main .card, .acct-main .form, .acct-main .field, .acct-main fieldset { min-width: 0; max-width: 100%; }
.acct-main .select, .acct-main .input, .acct-main .textarea { max-width: 100%; min-width: 0; }
.acct-main .wz-note > span, .acct-main .alert-inline > span { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 820px) {
  .acct-main .presets { max-width: 100%; }
  #pl-region { flex: 1 1 auto; width: auto; }
  .acct-main .lede, .page-hero .lede { overflow-wrap: anywhere; }
}
@media (max-width: 380px) { .checks { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Phones: nothing may be cut off at the screen edge ----------
   Rows of chips and buttons in page heroes wrap onto a second line instead of running off the screen.
   Rows that genuinely scroll sideways (status ribbon, SIMA+ jump bar) run edge to edge with a soft fade,
   so they read as scrollable rather than clipped. */
@media (max-width: 820px) {
  .page-hero .hero-meta, .my-hero .hb-glance { flex-wrap: wrap; overflow: visible; margin-inline: 0; padding: 0; }
  .page-hero .hero-meta > *, .my-hero .hb-glance > * { flex: 0 1 auto; max-width: 100%; }
  .page-hero .hero-meta .chip, .my-hero .hb-glance .chip { height: auto; min-height: 34px; padding-block: 7px; white-space: normal; line-height: 1.2; text-align: left; }
  .my-hero .hero-meta .btn { flex: 1 1 auto; min-width: 0; }

  .ribbon-in, .qt-row, .subnav-in {
    width: 100%; margin-inline: 0; padding-inline: 16px 28px; scroll-padding-inline: 16px;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
    mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent);
  }
  .ribbon-in > *, .qt-row > *, .subnav-in > * { flex: none; }

  /* Picker and preset rows inside cards wrap too, so every option is visible without sideways scrolling. */
  .presets, .my-wh > .row, .my-wh > span.row, .hb-places, .hb-acts { flex-wrap: wrap; overflow: visible; margin-inline: 0; padding-inline: 0; }
  .presets .btn { flex: 0 1 auto; }
  .hb-places, .hb-acts { display: flex; border-radius: 18px; max-width: 100%; padding: 3px; }

  .acct-nav { -webkit-mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent); mask-image: linear-gradient(90deg, #000 calc(100% - 24px), transparent); padding-right: 28px; }
}
@media (max-width: 640px) {
  /* Announcements show their full message and link on phones instead of being cut off with "…". */
  .notice-banner .wrap { flex-wrap: wrap; align-items: flex-start; row-gap: 6px; }
  .notice-banner svg { margin-top: 2px; }
  .notice-banner p { display: block; flex: 1 1 0; overflow: visible; -webkit-line-clamp: unset; }
  .notice-banner .btn { display: inline-flex; order: 3; margin-left: 27px; }
  .notice-banner .x { order: 2; margin-top: -4px; }
  .app-notice-link > span:first-of-type b { white-space: nowrap; }
}
@media (max-width: 380px) {
  .my-hero .hero-meta .btn { flex: 1 1 100%; }
}

/* ---------- Scrolling must always work, including in the installed app ---------- */
html, body { height: auto; min-height: 100%; overflow-y: visible; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; }
html.is-app, html.is-app body { position: static; overflow-y: auto; overscroll-behavior-y: auto; }
body.scroll-locked { overflow: hidden; }
.inst-modal, .palette-scrim, .lightbox, .ma-scrim { overscroll-behavior: contain; }

/* ---------- Readable text on dark surfaces ---------- */
.inst-banner :is(h1,h2,h3,h4,p,span,b,strong,small,li,div),
.join-ad-card :is(h1,h2,h3,h4,p,span,b,strong,small,li),
.page-hero :is(h1,h2,h3,h4,.lede),
.home-hero :is(h1,h2,h3,h4),
.mega-aside :is(h1,h2,h3,h4,p,span,b,strong,small),
.media-card :is(h1,h2,h3,h4,p,span,b,strong,small),
.push-ask :is(p,span,b,strong,small),
.comp-note :is(p,span,b,strong,small,li) { color: inherit; }
.comp-note { max-height: calc(100dvh - 24px); overflow-y: auto; }
@media (max-width: 820px) {
  .comp-note { bottom: calc(var(--tabbar-h, 64px) + env(safe-area-inset-bottom, 0px) + 8px); }
  body:has(#push-ask) .comp-note { bottom: calc(var(--tabbar-h, 64px) + env(safe-area-inset-bottom, 0px) + 150px); }
}

/* Light surfaces inside dark panels always get dark text (never inherit white from the panel). */
.q-town-card.on, .q-town-card.on * { color: #0e2a42; }
.consent, .consent p, .consent .btn-glass { color: #0e2a42; }
.consent .btn-ice { color: #fff; }
