/* ==========================================================================
   CleanWhale Buildings — Apple Maps Native Sheet Mobile UI (<= 768px)
   + Global Surgical Fixes for Firms, Tailwind Ring, 3D Sun Toolbar & Cookies
   Zero AI/Material bloat: native iOS sheet rhythm (#F2F2F7 + pure #FFFFFF).
   ========================================================================== */

/* ---------- 1. GLOBAL FIXES (Mobile + Desktop) ---------- */

/* Fix clipped Tailwind Score circular text ("AILWIND SCOR" -> clean fit) */
.tws-ring-kicker {
  font-size: 7.5px !important;
  letter-spacing: 0.05em !important;
  max-width: 82px !important;
  line-height: 1.15 !important;
  white-space: normal !important;
}
.tws-ring-val {
  padding: 0 14px !important;
}

/* Compact, non-blocking Cookie Consent Bar (<10% mobile viewport height) */
.bw-consent {
  position: fixed !important;
  left: 10px !important;
  right: 10px !important;
  bottom: 10px !important;
  max-width: 560px !important;
  margin: 0 auto !important;
  padding: 10px 12px !important;
  border-radius: 14px !important;
  background: rgba(255, 255, 255, 0.96) !important;
  backdrop-filter: blur(12px) !important;
  -webkit-backdrop-filter: blur(12px) !important;
  border: 1px solid rgba(0, 0, 0, 0.08) !important;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14) !important;
  display: flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px !important;
  z-index: 90 !important;
}
.bw-consent p {
  margin: 0 !important;
  font-size: 11.5px !important;
  line-height: 1.3 !important;
  color: #3a3a3c !important;
  flex: 1 1 auto !important;
}
.bw-consent-actions {
  display: flex !important;
  flex-direction: row !important;
  gap: 6px !important;
  flex-shrink: 0 !important;
  width: auto !important;
}
.bw-consent-no,
.bw-consent-yes {
  min-height: 32px !important;
  padding: 6px 11px !important;
  border-radius: 9px !important;
  font-size: 12px !important;
  font-weight: 700 !important;
  white-space: nowrap !important;
  width: auto !important;
  flex: none !important;
}
.bw-consent-no {
  background: #e5e5ea !important;
  color: #1c1c1e !important;
  border: none !important;
}
.bw-consent-yes {
  background: #000000 !important;
  color: #ffffff !important;
  border: none !important;
}

/* Fix overlapping firm cards (KRS / Profil firmy) on mobile & narrow viewports */
@media (max-width: 768px) {
  html,
  body {
    max-width: 100% !important;
    overflow-x: clip !important;
  }
  .sn-table,
  table.bw-table {
    display: block !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }
  .bw-ok-comp-item {
    padding: 13px 14px !important;
    border-radius: 14px !important;
    background: #ffffff !important;
    border: 1px solid #ececef !important;
  }
  .bw-ok-comp-top {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .bw-ok-comp-ico {
    display: none !important;
  }
  .bw-ok-comp-main {
    width: 100% !important;
    min-width: 0 !important;
  }
  .bw-ok-comp-main h3 {
    margin: 0 !important;
    font-size: 14.5px !important;
    line-height: 1.3 !important;
    word-break: normal !important;
    overflow-wrap: break-word !important;
    hyphens: auto;
  }
  .bw-ok-comp-krs {
    margin: 3px 0 0 !important;
    font-size: 12px !important;
    color: #636366 !important;
  }
  .bw-ok-comp-pills {
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 5px !important;
    margin-top: 6px !important;
  }
  /* Avoid double-badge clutter: keep single crisp trust/tailwind badge */
  .bw-ok-comp-pills .bw-comp-pill--score + .bw-comp-pill--score {
    display: none !important;
  }
  .bw-ok-btn-pill.bw-comp-cta {
    position: static !important;
    align-self: flex-start !important;
    margin-top: 2px !important;
    padding: 7px 13px !important;
    border-radius: 9px !important;
    font-size: 12.5px !important;
    font-weight: 700 !important;
    background: #f2f2f7 !important;
    color: #007aff !important;
    border: none !important;
    white-space: nowrap !important;
  }

  /* Fix 3D Sun floating toolbar covering the building & mouse wheel hint */
  .sn-stage-toolbar {
    position: static !important;
    padding: 8px 10px !important;
    background: #ffffff !important;
    border-top: 1px solid #e5e5ea !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 6px !important;
    pointer-events: auto !important;
  }
  .sn-view-switch,
  .sn-cam-ctrls {
    box-shadow: none !important;
    background: #f2f2f7 !important;
    border: none !important;
  }
  .sn-orbit-hint {
    display: none !important;
  }

  /* Fix Transit widget icon/title alignment */
  .tl-nearby-details > summary {
    padding: 13px 14px !important;
    gap: 10px !important;
    align-items: center !important;
  }
  .tl-nearby-details > summary svg {
    width: 18px !important;
    height: 18px !important;
    flex: 0 0 18px !important;
  }
  .tl-nearby-details > summary span {
    font-size: 14.5px !important;
    line-height: 1.25 !important;
  }
  .tl-live-chip {
    flex-shrink: 0 !important;
    font-size: 11px !important;
    padding: 3px 9px !important;
  }

  /* Cleaners widget -> crisp full-width vertical cards (top 2 visible + expand) — ZERO horizontal overflow */
  .cww-section,
  .cww-box {
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
  }
  .cww-box {
    padding: 14px !important;
    border-radius: 14px !important;
    border: none !important;
    box-shadow: none !important;
  }
  .cww-grid,
  .cww-cards {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important;
  }
  .cww-card {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    padding: 13px 14px !important;
    border-radius: 13px !important;
  }

  .bw-consent {
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-width: calc(100% - 20px) !important;
    min-width: 0 !important;
    transform: none !important;
    box-sizing: border-box !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .bw-consent p {
    min-width: 0 !important;
    overflow-wrap: break-word !important;
  }
  .bw-consent-actions {
    justify-content: flex-end !important;
  }
}

/* ---------- 2. APPLE MAPS NATIVE SHEET SHELL (Active only on mobile <= 768px) ---------- */
.ams-only-mobile {
  display: none;
}

@media (max-width: 768px) {
  body.ams-active {
    background: #f2f2f7 !important;
    color: #000000 !important;
  }

  /* Slim 46px native top bar; remove duplicate dark "Zapytaj mapę" header button */
  body.ams-active .bw-top {
    min-height: 46px !important;
    padding: 6px 14px !important;
    background: rgba(255, 255, 255, 0.94) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08) !important;
    position: sticky !important;
    top: 0 !important;
    z-index: 45 !important;
  }
  body.ams-active .bw-top .atlas-ask-entry {
    display: none !important;
  }
  body.ams-active .bw-crumbs {
    display: none !important;
  }

  /* Full-bleed Map Top Hero */
  .ams-only-mobile {
    display: block;
  }
  .ams-map-top {
    position: relative;
    width: 100%;
    height: 190px;
    background: #eceae2;
    overflow: hidden;
  }
  .ams-map-top--compact {
    height: 46px;
    background: #f2f2f7;
  }
  .ams-sheet--no-map {
    margin-top: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding-top: 2px !important;
  }
  .ams-sheet--no-map .ams-grabber {
    display: none;
  }
  .ams-map-top .bw-map-stage,
  .ams-map-top .bw-bhero-map,
  .ams-map-top .bw-map-stage > svg,
  .ams-map-top .bw-map-stage > img,
  .ams-map-top .bw-bhero-map > svg,
  .ams-map-top .bw-bhero-map > img {
    width: 100% !important;
    height: 100% !important;
    max-height: 190px !important;
    border-radius: 0 !important;
    border: none !important;
    object-fit: cover !important;
    display: block !important;
  }
  .ams-map-top .bw-bhero-cta-top,
  .ams-map-top .bw-bhero-cta,
  .ams-map-top .atlas-3d-btn,
  .ams-map-top .bw-3d-btn,
  .ams-map-top .bw-map-stage > a,
  .ams-map-top .bw-map-stage > button {
    display: none !important;
  }
  .ams-map-overlay {
    position: absolute;
    top: 10px;
    left: 12px;
    right: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: none;
    z-index: 6;
  }
  .ams-float-pill {
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.93);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: #000000 !important;
    font-size: 12.5px;
    font-weight: 700;
    text-decoration: none !important;
    border: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    cursor: pointer;
  }

  /* Rounded iOS Native Sheet rising over map */
  .ams-sheet {
    position: relative;
    z-index: 10;
    margin-top: -18px;
    border-radius: 22px 22px 0 0;
    background: #f2f2f7;
    padding: 9px 14px 12px;
    box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.08);
  }
  .ams-grabber {
    width: 36px;
    height: 4px;
    border-radius: 999px;
    background: #c7c7cc;
    margin: 0 auto 10px;
  }
  .ams-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
  }
  body.ams-active .ams-sheet h1.ams-title,
  .ams-title {
    margin: 0 !important;
    font-size: 22px !important;
    font-weight: 800 !important;
    line-height: 1.15 !important;
    letter-spacing: -0.025em !important;
    color: #000000 !important;
  }
  .ams-sub {
    margin: 4px 0 0;
    font-size: 13px;
    color: #636366;
    line-height: 1.35;
  }
  .ams-score-chip {
    flex-shrink: 0;
    padding: 4px 9px;
    border-radius: 8px;
    background: #e5e5ea;
    color: #000000;
    font-size: 12px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    border: none;
    cursor: pointer;
  }

  /* Quiet Native iOS Ask Search Input (NO 606px wall!) */
  .ams-ask-trigger {
    width: 100%;
    margin-top: 12px;
    padding: 9px 13px;
    border-radius: 11px;
    background: #e5e5ea;
    color: #636366;
    border: none;
    font: inherit;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
    cursor: pointer;
  }
  .ams-ask-trigger:active {
    background: #d1d1d6;
  }

  /* Sticky Single-Row Pill Switcher */
  .ams-tabs-wrap {
    position: sticky;
    top: var(--ams-top-h, 56px);
    z-index: 35;
    background: rgba(242, 242, 247, 0.94);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    padding: 9px 14px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  }
  .ams-tabs {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .ams-tabs::-webkit-scrollbar {
    display: none;
  }
  .ams-pill {
    flex: none;
    appearance: none;
    border: none;
    border-radius: 999px;
    padding: 7px 14px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    background: #e5e5ea;
    color: #3a3a3c;
    cursor: pointer;
    transition: background-color 0.14s ease, color 0.14s ease;
  }
  .ams-pill[aria-selected="true"] {
    background: #000000;
    color: #ffffff;
  }

  /* Overview Panel (2x2 Apple Widgets + Grouped Inset List + Compact Score Bar) */
  .ams-overview {
    padding: 12px 14px 20px;
    background: #f2f2f7;
  }
  .ams-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    margin-bottom: 12px;
  }
  .ams-stat-card {
    appearance: none;
    border: none;
    background: #ffffff;
    border-radius: 14px;
    padding: 11px 13px;
    text-align: left;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  .ams-stat-card:active {
    background: #ebebef;
  }
  .ams-stat-k {
    font-size: 11.5px;
    font-weight: 600;
    color: #8e8e93;
  }
  .ams-stat-v {
    font-size: 17px;
    font-weight: 800;
    color: #000000;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .ams-stat-v--danger { color: #ff3b30; }
  .ams-stat-v--warn { color: #d97706; }
  .ams-stat-v--ok { color: #16a34a; }
  .ams-stat-sub {
    font-size: 11.5px;
    color: #007aff;
    font-weight: 600;
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ams-group {
    background: #ffffff;
    border-radius: 14px;
    overflow: hidden;
    margin-bottom: 12px;
  }
  .ams-row {
    width: 100%;
    appearance: none;
    border: none;
    border-bottom: 1px solid #f2f2f7;
    background: #ffffff;
    padding: 13px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    text-align: left;
    cursor: pointer;
    font: inherit;
  }
  .ams-row:last-child {
    border-bottom: none;
  }
  .ams-row:active {
    background: #f2f2f7;
  }
  .ams-row-title {
    font-size: 14.5px;
    font-weight: 600;
    color: #000000;
  }
  .ams-row-val {
    font-size: 13.5px;
    color: #8e8e93;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 52%;
  }

  .ams-tw-bar-card {
    width: 100%;
    appearance: none;
    border: none;
    background: #ffffff;
    border-radius: 14px;
    padding: 13px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    text-align: left;
    cursor: pointer;
    font: inherit;
  }
  .ams-tw-track {
    width: 96px;
    height: 6px;
    border-radius: 999px;
    background: #e5e5ea;
    overflow: hidden;
    margin-top: 4px;
  }
  .ams-tw-fill {
    height: 100%;
    border-radius: 999px;
    background: #34c759;
  }

  /* Hide legacy hero & giant inline ask wall once Apple Sheet is mounted */
  body.ams-active .atlas-address-head,
  body.ams-active .bw-bhead {
    display: none !important;
  }
  body.ams-active #zapytaj-ai.ams-tucked,
  body.ams-active [data-ask-widget].ams-tucked {
    position: fixed !important;
    left: -9999px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    opacity: 0 !important;
    pointer-events: none !important;
  }

  /* SEO-safe panel hiding (until-found + graceful fallback) */
  body.ams-active [data-ams-hidden="1"] {
    content-visibility: hidden !important;
    height: 0 !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
  }

  /* Unified clean iOS sheet container padding for active panel sections */
  body.ams-active main > section:not([data-ams-hidden="1"]):not(.ams-sheet):not(.ams-overview),
  body.ams-active main > div[id]:not([data-ams-hidden="1"]):not(.ams-only-mobile) {
    background: transparent !important;
    padding: 10px 14px 16px !important;
    margin: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }
  body.ams-active .bw-facts-wrap.bw-facts-strip:not([data-ams-hidden="1"]) {
    margin: 10px 14px 14px !important;
    width: calc(100% - 28px) !important;
    background: #ffffff !important;
    border-radius: 14px !important;
    border: none !important;
    padding: 14px !important;
  }

  /* Clean iOS cards inside active panels (remove inconsistent borders/margins) */
  body.ams-active .bw-price-box,
  body.ams-active .bw-nearby-card,
  body.ams-active .bw-ok-card,
  body.ams-active .cww-card-wrap,
  body.ams-active .sn-card,
  body.ams-active .tws-card {
    border-radius: 14px !important;
    border: none !important;
    box-shadow: none !important;
  }

  /* Collapsible House Services groups so #uslugi isn't 8051px long! */
  .ams-hs-fold {
    background: #ffffff;
    border-radius: 14px;
    margin-bottom: 10px;
    overflow: hidden;
  }
  .ams-hs-fold > summary {
    list-style: none;
    padding: 14px 15px;
    font-size: 14.5px;
    font-weight: 700;
    color: #000000;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
  }
  .ams-hs-fold > summary::-webkit-details-marker { display: none; }
  .ams-hs-fold > summary::after {
    content: "›";
    font-size: 18px;
    color: #8e8e93;
    transition: transform 0.15s ease;
  }
  .ams-hs-fold[open] > summary::after {
    transform: rotate(90deg);
  }
  .ams-hs-fold-body {
    padding: 0 14px 14px;
    border-top: 1px solid #f2f2f7;
  }

  /* Polish Ask Dialog when opened from Apple Sheet search bar */
  dialog.atlas-dialog {
    border-radius: 20px 20px 0 0 !important;
    max-height: 84dvh !important;
    margin-top: auto !important;
    margin-bottom: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    background: #f2f2f7 !important;
  }
  dialog.atlas-dialog .atlas-chat {
    background: #f2f2f7 !important;
  }

  /* Show-more button for firms list */
  .ams-more-btn {
    width: 100%;
    margin-top: 10px;
    padding: 11px;
    border-radius: 11px;
    border: none;
    background: #e5e5ea;
    color: #000000;
    font: inherit;
    font-size: 13.5px;
    font-weight: 700;
    cursor: pointer;
  }
}
