/*
 * COSIDAR mobile visual fixes — unified handoff, 2026-11-20.
 * Load AFTER the existing site.css / products.css and mobile styles.
 * The companion loader also inserts this file into the product ShadowRoot.
 * Scope: <= 767 CSS px. Existing page order, photo frames and desktop rules remain.
 * !important is needed only to override existing mobile !important declarations.
 */

@media (max-width: 767px) {
  /* IMG: fill existing photographic frames. No frame resizing; source shared with PC.
     Intentionally excludes diagrams, certificates, QR codes, logos and product detail
     packshots, for which showing the complete content remains appropriate. */
  #cosidar-site[data-mobile-ui="readable"] #cosidar-project-cases .pc-card-media img,
  #cosidar-site[data-mobile-ui="readable"] #cosidar-resources :is(.csr-portal-media, .csr-story-media) img,
  #cosidar-site[data-mobile-ui="readable"] #cosidar-solutions-view .application-image img {
    object-fit: cover !important;
  }

  /* 01: remove stacked blank space between homepage value statements and solutions.
     Existing last value padding-bottom stays 24px. 24 + 0 + 22 + 22 = 68px. */
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #values .value-grid {
    padding-bottom: 0 !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #values {
    padding-bottom: 22px !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #solutions {
    padding-top: 22px !important;
  }

  /* 02: homepage process icons match the 52px icons used on the later solution page.
     Slightly larger than the original 38px display, but not the rejected 1.5x size.
     Keep a dedicated icon column and a clear 18px gap before the text. */
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #method .process-step {
    display: grid !important;
    grid-template-columns: 52px minmax(0, 1fr) 30px !important;
    grid-template-rows: auto !important;
    align-items: center !important;
    column-gap: 18px !important;
    min-height: 68px !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #method .process-icon {
    flex: 0 0 52px !important;
    width: 52px !important;
    height: 52px !important;
    display: grid !important;
    place-items: center !important;
    overflow: visible !important;
    grid-column: 1 !important;
    grid-row: 1 !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #method .process-step h3 {
    grid-column: 2 !important;
    grid-row: 1 !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #method .process-step small {
    grid-column: 3 !important;
    grid-row: 1 !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #method .process-icon img {
    display: block !important;
    width: 52px !important;
    height: 52px !important;
    object-fit: contain !important;
    object-position: center center !important;
    margin: 0 auto !important;
    transform: translateX(1px) !important;
    transform-origin: center center !important;
  }

  /* 03: all three compact resource lists share these classes (nine current rows).
     The article remains fully readable after following its link. */
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #resources .resources-update-item {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) max-content !important;
    align-items: center !important;
    column-gap: 10px !important;
    row-gap: 0 !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #resources .resources-update-title {
    display: block !important;
    min-width: 0 !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    align-self: center;
  }
  #cosidar-site[data-mobile-ui="readable"] #cosidar-home-view #resources .resources-update-date {
    margin: 0 !important;
    white-space: nowrap !important;
    justify-self: end;
    align-self: center;
  }

  /* 05: inset the category label and field to match their following panel's copy.
     Top-level sticky navigation pickers are deliberately outside these selectors. */
  #cosidar-site[data-mobile-ui="readable"] #cosidar-solutions-view .system-right > .cos-mobile-picker--category,
  #cosidar-site[data-mobile-ui="readable"] #cosidar-solutions-view #materials-materials > .wrap > .cos-mobile-picker--category,
  #cosidar-site[data-mobile-ui="readable"] #research-main .rd-platform-layout > .cos-mobile-picker--category {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    padding-inline: 22px !important;
  }

  /* 07: senior team portraits stay above their names, centered, with full images.
     A higher-resolution original for Lu Hanfeng is recommended for crisp retina output. */
  #cosidar-site[data-mobile-ui="readable"] #research-main :is(#rd-team-industrial, #rd-team-forestry) .rd-team-lead figure {
    width: 180px !important;
    max-width: 100% !important;
    height: auto !important;
    flex: none;
  }
  /* Reserve each source image's natural ratio before lazy loading completes.
     Lu's live <img> has no width/height attributes; without this it can collapse. */
  #cosidar-site[data-mobile-ui="readable"] #research-main #rd-team-industrial .rd-team-lead figure {
    aspect-ratio: 142 / 202 !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #research-main #rd-team-forestry .rd-team-lead figure {
    aspect-ratio: 341 / 512 !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #research-main :is(#rd-team-industrial, #rd-team-forestry) .rd-team-lead figure img {
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    max-height: none !important;
    object-fit: contain !important;
  }

  /* 08: material-record image column grows from 120px to 160px at common phone widths.
     Cap at half of the card on very narrow screens so the text stays usable. */
  #cosidar-site[data-mobile-ui="readable"] #research-main .rd-record {
    grid-template-columns: min(160px, 50%) minmax(0, 1fr) !important;
  }
  #cosidar-site[data-mobile-ui="readable"] #research-main .rd-record > img {
    width: 100%;
    max-width: 100%;
    object-fit: cover;
  }
  #cosidar-site[data-mobile-ui="readable"] #research-main .rd-record > div {
    min-width: 0;
    padding-inline: 16px !important;
  }

  /* 06: product cards live inside the product center's open ShadowRoot.
     The loader inserts this SAME stylesheet there; ordinary document CSS cannot cross it.
     Adjacent block gaps become about a quarter of 30 / 34 / 38px: 8 / 8 / 10px.
     Image dimensions, text sizes, horizontal 20px padding and touch targets are retained. */
  :host([data-mobile-reflow]) #main .product-card .pc-identity {
    margin-bottom: 0 !important;
  }
  :host([data-mobile-reflow]) #main .product-card .pc-specific {
    margin: 8px 0 0 !important;
  }
  :host([data-mobile-reflow]) #main .product-card .pc-description {
    margin: 8px 0 0 !important;
  }
  :host([data-mobile-reflow]) #main .product-card .pc-meta {
    margin-top: 8px !important;
    gap: 6px;
  }
  :host([data-mobile-reflow]) #main .product-card .pc-meta > div {
    margin-bottom: 0 !important;
  }
  :host([data-mobile-reflow]) #main .product-card .pc-actions {
    margin-top: 10px !important;
    padding-top: 0 !important;
  }
}

/* The live platform detail panel already uses 18px insets at this width. */
@media (max-width: 359px) {
  #cosidar-site[data-mobile-ui="readable"] #research-main .rd-platform-layout > .cos-mobile-picker--category {
    padding-inline: 18px !important;
  }
}

/* Unified selection popup. Concatenate after the shared mobile fixes.
 * A native <dialog> supplies the top layer; all visible UI is site-styled.
 */
.cosidar-choice-trigger { display: none; --cosidar-choice-ready: 1; }
.cosidar-choice-dialog:not([open]) { display: none !important; }

@media (max-width: 767px) {
  :root { --cosidar-mobile-unified-ready: 1; }

  /* Hide only selects that the successfully initialized adapter owns. */
  select[data-cosidar-choice-enhanced],
  #cosidar-site[data-mobile-ui="readable"] .cos-mobile-picker select[data-cosidar-choice-enhanced],
  :host([data-mobile-reflow]) .cos-mobile-picker select[data-cosidar-choice-enhanced],
  :host #main .mobile-group-picker select[data-cosidar-choice-enhanced] {
    display: none !important;
  }

  .cosidar-choice-trigger,
  #cosidar-site[data-mobile-ui="readable"] .cosidar-choice-trigger,
  :host([data-mobile-reflow]) .cosidar-choice-trigger,
  :host #main .mobile-group-picker > .cosidar-choice-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex: 1 1 0;
    min-width: 0;
    width: 100%;
    max-width: none;
    height: 46px;
    min-height: 46px;
    box-sizing: border-box;
    margin: 0;
    padding: 9px 17px;
    border: 1px solid #d7e4dd;
    border-radius: 999px;
    color: #004337 !important;
    background: #f1f6f3 !important;
    box-shadow: none;
    transition: none;
    font: inherit;
    font-size: 16px !important;
    font-weight: 500;
    line-height: 1.4 !important;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .cosidar-choice-trigger .cosidar-choice-trigger__text {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: inherit !important;
    font: inherit !important;
  }
  .cosidar-choice-trigger > svg {
    display: block;
    width: 18px;
    height: 18px;
    flex: 0 0 18px;
    margin: 0;
    color: inherit;
    transition: transform 150ms ease;
  }
  .cos-mobile-picker--category > .cosidar-choice-trigger,
  #cosidar-site[data-mobile-ui="readable"] .cos-mobile-picker--category > .cosidar-choice-trigger,
  :host([data-mobile-reflow]) .cos-mobile-picker--category > .cosidar-choice-trigger {
    height: 50px;
    min-height: 50px;
  }
  .mobile-group-picker > .cosidar-choice-trigger,
  :host #main .mobile-group-picker > .cosidar-choice-trigger {
    height: 48px;
    min-height: 48px;
    flex: none;
  }
  .cosidar-choice-trigger[aria-expanded="true"],
  #cosidar-site[data-mobile-ui="readable"] .cosidar-choice-trigger[aria-expanded="true"],
  :host([data-mobile-reflow]) .cosidar-choice-trigger[aria-expanded="true"],
  :host #main .mobile-group-picker > .cosidar-choice-trigger[aria-expanded="true"] {
    background: #009143 !important;
    border-color: #009143;
    color: #fff !important;
  }
  .cosidar-choice-trigger[aria-expanded="true"] > svg { transform: rotate(180deg); }
  .cosidar-choice-trigger:disabled { cursor: default; opacity: .55; }
  .cosidar-choice-trigger:focus-visible { outline: 2px solid #009143; outline-offset: 3px; }
  .cosidar-choice-trigger[hidden],
  #cosidar-site[data-mobile-ui="readable"] .cosidar-choice-trigger[hidden],
  :host([data-mobile-reflow]) .cosidar-choice-trigger[hidden] { display: none !important; }

  .cosidar-choice-dialog {
    position: fixed;
    inset: auto 0 12px;
    inset-block-end: max(12px, env(safe-area-inset-bottom));
    width: calc(100% - 24px);
    max-width: 520px;
    max-height: 80vh;
    max-height: 80dvh;
    box-sizing: border-box;
    margin: 0 auto;
    padding: 0;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.75);
    border-radius: 24px;
    background: rgba(248,252,249,.97);
    color: #004337;
    box-shadow: 0 18px 60px rgba(0,40,29,.24);
    font-family: Arial, "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 16px;
    line-height: 1.5;
    text-align: left;
    -webkit-text-size-adjust: 100%;
  }
  .cosidar-choice-dialog[open] { display: flex; flex-direction: column; }
  .cosidar-choice-dialog::backdrop {
    background: rgba(4,30,23,.32);
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
  }
  @supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .cosidar-choice-dialog {
      background: rgba(248,252,249,.89);
      -webkit-backdrop-filter: blur(22px);
      backdrop-filter: blur(22px);
    }
  }
  .cosidar-choice-header {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 16px 10px 22px;
    border-bottom: 1px solid rgba(0,67,55,.08);
  }
  .cosidar-choice-header h2 {
    margin: 0;
    padding: 0;
    font: inherit;
    font-size: 19px;
    font-weight: 600;
    line-height: 1.5;
    color: #004337;
  }
  .cosidar-choice-close {
    display: grid;
    place-items: center;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    min-height: 44px;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: rgba(0,67,55,.07);
    color: #004337;
    font: inherit;
    font-size: 29px;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
  }
  .cosidar-choice-options {
    display: flex;
    flex-direction: column;
    gap: 7px;
    flex: 1 1 auto;
    min-height: 0;
    box-sizing: border-box;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 14px;
    scroll-padding-block: 14px;
  }
  .cosidar-choice-option {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    box-sizing: border-box;
    margin: 0;
    padding: 12px 18px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: transparent;
    color: #004337;
    font: inherit;
    font-size: 16px;
    font-weight: 500;
    line-height: 1.5;
    text-align: left;
    white-space: normal;
    text-transform: none;
    letter-spacing: normal;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
  }
  .cosidar-choice-option > span { min-width: 0; overflow-wrap: anywhere; }
  .cosidar-choice-option > svg { width: 20px; height: 20px; flex: 0 0 20px; visibility: hidden; }
  .cosidar-choice-option[aria-pressed="true"] { background: #009143; border-color: #009143; color: #fff; }
  .cosidar-choice-option[aria-pressed="true"] > svg { visibility: visible; }
  .cosidar-choice-option:disabled { opacity: .4; cursor: default; }
  .cosidar-choice-option:focus-visible,
  .cosidar-choice-close:focus-visible { outline: 2px solid #007636; outline-offset: 2px; }
  .cosidar-choice-group { margin: 9px 18px 0; color: #5e716a; font-size: 13px; font-weight: 600; }
  .cosidar-choice-empty { margin: 16px; color: #5e716a; text-align: center; }

  /* 11. Independent-technology series card: match the preceding series cards.
     Only the /products/technology/ card is targeted; geometry and copy stay. */
  :host([data-mobile-reflow]) #main .series-card[href="/products/technology/"] {
    position: relative !important;
    isolation: isolate !important;
  }
  :host([data-mobile-reflow]) #main .series-card[href="/products/technology/"] > img {
    position: relative !important;
    z-index: 0 !important;
  }
  :host([data-mobile-reflow]) #main .series-card[href="/products/technology/"]::after {
    content: "" !important;
    display: block !important;
    position: absolute !important;
    inset: 0 !important;
    z-index: 1 !important;
    pointer-events: none !important;
    background: linear-gradient(
      180deg,
      transparent 20%,
      #00372e55 38%,
      #00372eee 64%,
      #00372e 100%
    ) !important;
  }
  :host([data-mobile-reflow]) #main .series-card[href="/products/technology/"] .sc-copy {
    position: relative !important;
    z-index: 2 !important;
  }

}

@media (prefers-reduced-motion: reduce) {
  .cosidar-choice-trigger > svg { transition: none; }
}
