/* BitStream Digital final theme compatibility + CMS controls + safe ad preview.
   Loaded last so old hard-coded white/dark surfaces follow the shared site theme. */
html[data-theme][data-site-theme] body[class] :is(
  .cms-settings-main .panel,.ad-control-summary,.ad-demo-studio,.package-admin,.download-admin,
  .storage-delivery-guide,.inline-guide,.r2-existing-object,.release-list article,.download-callout,
  .coming-soon-purchase,.checkout-note,.payment-option,.free-access-box,.order-status-banner,
  .delivery-steps article,.delivery-unlocked,.license-box,.support-next a,.support-next button,
  .product-visibility-guide,.plan-readiness-grid>div,.ad-demo-page,.ad-demo-inline,.ad-demo-vignette-card
){
  background:var(--site-surface)!important;
  color:var(--site-ink)!important;
  border-color:var(--site-line)!important;
  box-shadow:var(--site-shadow)!important;
}
html[data-theme][data-site-theme] body[class] :is(
  .cms-settings-main .panel p,.cms-settings-main .panel small,.ad-control-summary small,.ad-demo-studio p,
  .ad-demo-studio small,.package-admin small,.download-admin small,.storage-delivery-guide small,
  .inline-guide small,.r2-existing-object small,.release-list article small,.download-callout small,
  .coming-soon-purchase p,.checkout-note,.payment-option small,.free-access-box p,.order-status-banner small,
  .delivery-steps article p,.delivery-unlocked p,.license-box small,.product-visibility-guide small,
  .plan-readiness-grid small,.ad-demo-vignette-card>span
){color:var(--site-muted)!important}
html[data-theme][data-site-theme] body[class] :is(
  .cms-settings-main h1,.cms-settings-main h2,.cms-settings-main h3,.ad-demo-inline b,.ad-demo-vignette-card h2,
  .coming-soon-purchase h3,.plan-readiness-grid b
){color:var(--site-ink)!important}
html[data-theme][data-site-theme] body[class] :is(.cms-table,.cms-table td,.cms-table th,.table-scroll,.release-actions){border-color:var(--site-line)!important;color:var(--site-ink)!important}
html[data-theme][data-site-theme] body[class] .cms-table tbody tr:hover{background:var(--site-soft)!important}
html[data-theme][data-site-theme] body[class] :is(.link-danger,.status.revoked){color:var(--site-danger)!important}

/* Real CMS-controlled coming-soon state. */
.coming-soon-status,.coming-soon-purchase .status{background:var(--site-warning-bg)!important;color:var(--site-warning)!important;border-color:color-mix(in srgb,var(--site-warning) 35%,transparent)!important}
.coming-soon-purchase{display:grid;gap:10px;padding:16px;border:1px solid var(--site-line);border-radius:16px;margin:18px 0}
.coming-soon-purchase .btn[aria-disabled="true"]{opacity:.72;pointer-events:none}

/* CMS visibility / payment readiness blocks. */
#public-app-visibility .check,.plan-readiness-grid>div{background:var(--site-soft)!important;border:1px solid var(--site-line)!important;border-radius:12px}
.plan-readiness-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px;margin:12px 0}
.plan-readiness-grid>div{display:grid;gap:4px;padding:12px}
.plan-readiness-grid span{font-size:10px;text-transform:uppercase;letter-spacing:.06em;color:var(--site-muted)}
.plan-readiness-grid b{font-size:12px}
.plan-readiness-grid small{line-height:1.55}

/* Advanced Ads safe preview. */
.ad-demo-studio{position:relative;overflow:visible;margin-bottom:18px}
.ad-demo-controls{display:flex;align-items:end;justify-content:space-between;gap:14px;flex-wrap:wrap;margin:14px 0}
.ad-demo-controls label{min-width:min(320px,100%);display:grid;gap:7px}
.ad-demo-stage{border:1px solid var(--site-line);border-radius:16px;padding:14px;background:var(--site-soft)}
.ad-demo-page{position:relative;min-height:330px;border:1px solid var(--site-line);border-radius:14px;overflow:hidden;padding:64px 22px 24px}
.ad-demo-browser{position:absolute;inset:0 0 auto;height:44px;display:flex;align-items:center;gap:7px;padding:0 14px;border-bottom:1px solid var(--site-line);background:var(--site-soft);color:var(--site-muted);font-size:11px}
.ad-demo-browser i{width:8px;height:8px;border-radius:50%;background:var(--site-line)}
.ad-demo-browser span{margin-left:7px}
.ad-demo-page-content{display:grid;gap:10px;margin:15px 0 28px}
.ad-demo-copy-line{height:11px;border-radius:999px;background:var(--site-line);opacity:.7;width:72%}.ad-demo-copy-line.wide{width:92%}.ad-demo-copy-line.short{width:48%}
.ad-demo-inline{display:grid;grid-template-columns:86px minmax(0,1fr) auto;align-items:center;gap:14px;padding:14px;border:1px solid var(--site-line);border-radius:14px;background:var(--site-surface)}
.ad-demo-inline img,.ad-demo-art{width:86px;height:68px;border-radius:10px;object-fit:cover}.ad-demo-art{display:grid;place-items:center;background:linear-gradient(135deg,var(--site-primary),#7c3aed);color:#fff;font-weight:900;letter-spacing:.08em}
.ad-demo-inline>div{display:grid;gap:4px}.ad-demo-inline p{margin:0;line-height:1.5}.ad-demo-inline.is-playing{animation:bitstreamAdPreview .65s ease}
.ad-demo-stage[data-placement="catalog_top"] .ad-demo-inline{margin-top:0}.ad-demo-stage[data-placement="product_inline"] .ad-demo-inline{max-width:760px;margin-inline:auto}
@keyframes bitstreamAdPreview{0%{opacity:.2;transform:translateY(8px) scale(.99)}100%{opacity:1;transform:none}}
.ad-demo-vignette{position:fixed;inset:0;z-index:99999;background:#020817d9;backdrop-filter:blur(7px);display:grid;place-items:center;padding:20px}
.ad-demo-vignette.hidden{display:none!important}.ad-demo-vignette-card{position:relative;width:min(560px,100%);max-height:90vh;overflow:auto;border:1px solid var(--site-line);border-radius:22px;padding:24px;text-align:center;display:grid;gap:12px}
.ad-demo-close{position:absolute;right:12px;top:10px;width:36px;height:36px;border-radius:50%;border:1px solid var(--site-line);background:var(--site-soft);color:var(--site-ink);font-size:21px}
.ad-demo-vignette-card>small{justify-self:center;padding:5px 9px;border-radius:999px;background:var(--site-soft);color:var(--site-muted)}
.ad-demo-vignette-card img,.ad-demo-vignette-art{width:100%;height:min(260px,35vh);object-fit:cover;border-radius:15px}.ad-demo-vignette-art{display:grid;place-items:center;background:linear-gradient(135deg,var(--site-primary),#7c3aed);color:#fff;font-size:24px;font-weight:900}
body.ad-demo-open{overflow:hidden}

/* Buttons/inputs that used legacy fixed colors. */
html[data-theme][data-site-theme] body[class] :is(.release-test-link,.release-actions a:not(.btn)){color:var(--site-accent)!important}
html[data-theme][data-site-theme] body[class] :is(.checkout-form,.checkout-summary,.checkout-page,.payment-option){color:var(--site-ink)!important}
html[data-theme="dark"][data-site-theme] body[class] .product-info :is(.package-option,.version-row span){background:var(--site-soft)!important}

@media(max-width:800px){
  .plan-readiness-grid{grid-template-columns:1fr}
  .ad-demo-inline{grid-template-columns:64px minmax(0,1fr)}
  .ad-demo-inline img,.ad-demo-art{width:64px;height:58px}.ad-demo-inline>.btn{grid-column:1/-1;width:100%}
}

/* ==========================================================
   2026-10-09 DARK THEME + PUBLIC CHAT + CMS SURFACE FIX
   Loaded last. Removes legacy hard-coded white surfaces while
   keeping official printed documents intentionally white.
========================================================== */

/* Lock the page behind the support chat. The message thread itself remains scrollable. */
html.chat-open,
html.chat-open body{
  overflow:hidden!important;
  overscroll-behavior:none!important;
}
body.chat-open{
  position:fixed!important;
  left:0!important;
  right:0!important;
  width:100%!important;
}

/* Public chat follows the active site theme. */
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-panel{
  background:var(--site-surface)!important;
  color:var(--site-ink)!important;
  border-color:var(--site-line)!important;
  box-shadow:0 24px 70px #00000038!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-head{
  background:var(--site-chrome)!important;
  color:var(--site-ink)!important;
  border-bottom:1px solid var(--site-line)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-head b,
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-head button{
  color:var(--site-ink)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-head small{
  color:var(--site-muted)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-head button:hover{
  background:var(--site-soft)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-messages{
  background:var(--site-bg)!important;
  color:var(--site-ink)!important;
  scrollbar-color:var(--site-line) transparent;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-bubble{
  background:var(--site-surface)!important;
  color:var(--site-ink)!important;
  border-color:var(--site-line)!important;
  box-shadow:none!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-bubble.customer{
  background:var(--site-accent-soft)!important;
  color:var(--site-ink)!important;
  border-color:color-mix(in srgb,var(--site-accent) 42%,var(--site-line))!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-bubble.staff,
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-bubble.telegram{
  background:var(--site-success-bg)!important;
  color:var(--site-ink)!important;
  border-color:color-mix(in srgb,var(--site-success) 36%,var(--site-line))!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-bubble.system{
  background:var(--site-warning-bg)!important;
  color:var(--site-ink)!important;
  border-color:color-mix(in srgb,var(--site-warning) 38%,var(--site-line))!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-bubble b{
  color:var(--site-muted)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-bubble>span{
  color:var(--site-ink)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-product-card{
  background:var(--site-surface)!important;
  color:var(--site-ink)!important;
  border-color:var(--site-line)!important;
  box-shadow:none!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-product-card:hover{
  background:var(--site-soft)!important;
  border-color:var(--site-accent)!important;
  box-shadow:0 8px 24px #00000018!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-product-copy strong{
  color:var(--site-ink)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-product-copy small,
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-product-copy span{
  color:var(--site-muted)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-start-fields{
  background:var(--site-surface)!important;
  color:var(--site-ink)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget form.chat-compose-form{
  background:var(--site-surface)!important;
  color:var(--site-ink)!important;
  border-top-color:var(--site-line)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-input-shell textarea{
  background:var(--site-input)!important;
  color:var(--site-ink)!important;
  border-color:var(--site-line)!important;
  box-shadow:none!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-input-shell textarea:focus{
  border-color:var(--site-accent)!important;
  box-shadow:0 0 0 3px color-mix(in srgb,var(--site-accent) 18%,transparent)!important;
  outline:none!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-image-inline{
  background:var(--site-soft)!important;
  color:var(--site-ink)!important;
  box-shadow:inset 0 0 0 1px var(--site-line)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-image-inline:hover{
  background:var(--site-accent-soft)!important;
  color:var(--site-accent)!important;
  box-shadow:inset 0 0 0 1px var(--site-accent)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-file-note{
  background:var(--site-surface)!important;
  color:var(--site-muted)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-login-gate{
  background:var(--site-surface)!important;
  color:var(--site-ink)!important;
}
html[data-theme][data-site-theme] body.public-body .header-chat-widget .chat-login-gate p{
  color:var(--site-muted)!important;
}

/* CMS legacy surfaces that still used fixed #fff/#f8fafc colors. */
html[data-theme][data-site-theme] body.cms-body :is(
  .invoice-finance-list,.invoice-print-card,.invoice-print-hint,.signer-preview,
  .cms-chat-product-card,.team-signature-mini,.license-popover,.side-sponsor-card,
  .account-shortcuts a,.r2-existing-object,.release-list article,.package-admin,.download-admin
){
  background:var(--site-surface)!important;
  color:var(--site-ink)!important;
  border-color:var(--site-line)!important;
  box-shadow:var(--site-shadow)!important;
}
html[data-theme][data-site-theme] body.cms-body :is(
  .signer-preview-media,.team-signature-mini img,.invoice-edit-table th
){
  background:var(--site-soft)!important;
  color:var(--site-ink)!important;
  border-color:var(--site-line)!important;
}
html[data-theme][data-site-theme] body.cms-body :is(
  .invoice-footer-fields label,.invoice-mini-note,.signer-preview small,.signer-status,
  .cms-chat-product-card small,.cms-chat-product-card p,.team-signature-mini span
){
  color:var(--site-muted)!important;
}
html[data-theme][data-site-theme] body.cms-body .cms-chat-product-card strong{
  color:var(--site-ink)!important;
}
html[data-theme][data-site-theme] body.cms-body .invoice-edit-table td,
html[data-theme][data-site-theme] body.cms-body .invoice-edit-table input{
  color:var(--site-ink)!important;
  border-color:var(--site-line)!important;
}
html[data-theme][data-site-theme] body.cms-body .invoice-edit-table input:focus{
  background:var(--site-soft)!important;
  box-shadow:inset 0 0 0 1px var(--site-accent)!important;
}
html[data-theme][data-site-theme] body.cms-body .invoice-remove-row{
  background:var(--site-danger-bg)!important;
  color:var(--site-danger)!important;
  border-color:var(--site-danger)!important;
}
html[data-theme][data-site-theme] body.cms-body .invoice-summary-v4 .balance-card{
  background:linear-gradient(180deg,var(--site-surface),var(--site-soft))!important;
  color:var(--site-ink)!important;
  border-color:var(--site-line)!important;
  box-shadow:var(--site-shadow)!important;
}
html[data-theme][data-site-theme] body.cms-body .invoice-summary-v4 .balance-card small{
  color:var(--site-muted)!important;
}
html[data-theme][data-site-theme] body.cms-body .invoice-finance-list .vat{
  color:var(--site-accent)!important;
}
html[data-theme][data-site-theme] body.cms-body .invoice-finance-list .net{
  color:var(--site-success)!important;
  border-color:var(--site-line)!important;
}

/* Keep actual invoice/quotation/contract documents white for PDF/print output. */
html[data-theme="dark"][data-site-theme] body.cms-body :is(
  .invoice-print-sheet,.official-document,.contract-sheet-v5,.quotation-sheet
){
  color-scheme:light;
}

/* Mobile support chat becomes a fixed app-like screen. The page behind it cannot scroll. */
@media(max-width:700px){
  .header-chat-widget .chat-panel,
  .header-chat-widget .chat-panel.chat-panel-guest{
    position:fixed!important;
    inset:0!important;
    width:100vw!important;
    max-width:100vw!important;
    height:100dvh!important;
    max-height:100dvh!important;
    min-height:100dvh!important;
    border:0!important;
    border-radius:0!important;
    z-index:5000!important;
    grid-template-rows:auto minmax(0,1fr) auto auto auto!important;
  }
  .header-chat-widget .chat-panel.chat-panel-guest{
    grid-template-rows:auto minmax(0,1fr)!important;
  }
  .header-chat-widget .chat-head{
    padding-top:max(14px,env(safe-area-inset-top))!important;
    padding-left:max(14px,env(safe-area-inset-left))!important;
    padding-right:max(14px,env(safe-area-inset-right))!important;
  }
  .header-chat-widget .chat-messages{
    min-height:0!important;
    overflow-y:auto!important;
    overflow-x:hidden!important;
    overscroll-behavior:contain!important;
    -webkit-overflow-scrolling:touch;
  }
  .header-chat-widget form.chat-compose-form{
    margin:0!important;
    padding-left:max(8px,env(safe-area-inset-left))!important;
    padding-right:max(8px,env(safe-area-inset-right))!important;
  }
  .header-chat-widget .chat-file-note{
    margin:0!important;
    padding-bottom:max(9px,env(safe-area-inset-bottom))!important;
  }
  .header-chat-widget .chat-compose-row,
  .header-chat-widget .chat-input-shell{
    width:100%!important;
    max-width:100%!important;
    min-width:0!important;
  }
  .header-chat-widget .chat-send-button{
    flex:0 0 auto!important;
    min-width:64px!important;
  }
}
