/* UI P3–P9 · Product Finish Layer
   Desktop >= 900px · Mobile < 900px · tablet-specific mode intentionally unsupported. */

:root{
  --status-positive:#087653;--status-positive-bg:#e7f8f0;
  --status-watch:#946300;--status-watch-bg:#fff5dc;
  --status-risk:#a43832;--status-risk-bg:#fff0ee;
  --status-neutral:#64748b;--status-neutral-bg:#eef2f6;
  --product-max:1680px;--product-touch:44px;
}

/* P4 · common information hierarchy */
[data-ui-level="decision"]{--ui-accent:#2563eb}
[data-ui-level="execution"]{--ui-accent:#0f766e}
[data-ui-level="risk"]{--ui-accent:#dc2626}
[data-ui-level="evidence"]{--ui-accent:#7c3aed}
[data-ui-level="research"]{--ui-accent:#d97706}
[data-ui-level="model"]{--ui-accent:#64748b}
[data-ui-level] .p-workspace-section-head>span,
[data-ui-level] .so-flow-heading>span{color:var(--ui-accent)!important;background:#fff!important;border:1px solid var(--ui-accent)!important}

/* P5 · status language: colour is never the only cue */
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status,.pv-run,.bc-status,.sys-pill,.f-ai,.f-confidence).TRIGGERED::before,
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).CONFIRMED::before{content:"✓ ";font-weight:900}
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).READY::before{content:"● ";font-size:.72em}
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).SETUP::before,
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).MONITOR::before{content:"○ ";font-weight:900}
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).PULLBACK::before{content:"↘ ";font-weight:900}
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).INVALIDATED::before,
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).CLOSED::before{content:"× ";font-weight:900}
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).CHASE::before,
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).RISK::before{content:"! ";font-weight:900}

:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).TRIGGERED,
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).CONFIRMED{background:var(--status-positive-bg)!important;color:var(--status-positive)!important}
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).READY,
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).SETUP,
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).MONITOR{background:var(--status-watch-bg)!important;color:var(--status-watch)!important}
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).INVALIDATED,
:is(.badge,.d-badge,.c-state,.wp-state,.wp-status).CHASE{background:var(--status-risk-bg)!important;color:var(--status-risk)!important}

.d-badge.state-TRIGGERED::before{content:"✓ ";font-weight:900}
.d-badge.state-READY::before{content:"● ";font-size:.72em}
.d-badge.state-SETUP::before,.d-badge.state-MONITOR::before{content:"○ ";font-weight:900}
.d-badge.state-INVALIDATED::before,.d-badge.state-CLOSED::before{content:"× ";font-weight:900}
.d-badge.state-TRIGGERED{background:var(--status-positive-bg)!important;color:var(--status-positive)!important}
.d-badge.state-READY,.d-badge.state-SETUP,.d-badge.state-MONITOR{background:var(--status-watch-bg)!important;color:var(--status-watch)!important}
.d-badge.state-INVALIDATED{background:var(--status-risk-bg)!important;color:var(--status-risk)!important}

/* P6 · loading / empty / error states */
@keyframes site-skeleton{0%{background-position:200% 0}100%{background-position:-200% 0}}
:is(.loading,.p-loading,.sca-loading,.p-chart-loading,.so-chart-loading,.site-state-loading){
  position:relative;overflow:hidden!important;min-height:72px;
  border:1px solid #e3e9f0;border-radius:12px;padding:18px!important;color:#7c8a9e!important;
  background:linear-gradient(100deg,#f5f7fa 20%,#edf2f7 40%,#f5f7fa 60%)!important;
  background-size:220% 100%!important;animation:site-skeleton 1.35s ease-in-out infinite!important
}
:is(.loading,.p-loading,.sca-loading,.p-chart-loading,.so-chart-loading,.site-state-loading)::after{
  content:"";display:block;width:58%;height:10px;margin-top:10px;border-radius:999px;background:rgba(148,163,184,.18)
}
:is(.p-empty,.wp-empty,.pv-empty,.bc-empty,.dc-empty,.c-inspector-empty,.di-empty,.site-state-empty){
  border:1px dashed #cfd9e5!important;border-radius:12px!important;background:#fbfcfe!important;color:#708096!important
}
:is(.standalone,.site-state-error) a,
:is(.standalone,.site-state-error) button{min-height:var(--product-touch);display:inline-flex;align-items:center;justify-content:center}
.site-state-error>div{border-left:4px solid #dc4c64!important}
@media(prefers-reduced-motion:reduce){:is(.loading,.p-loading,.sca-loading,.p-chart-loading,.so-chart-loading,.site-state-loading){animation:none!important}}

/* P7 · browser rendering / navigation performance */
:is(.p-workspace-section,.so-flow-block,.f-report-sec,.wp-section,.bc-section,.pv-section,.sys-section,.di-card,.dc-event){
  content-visibility:auto;contain-intrinsic-size:auto 240px
}
img{content-visibility:auto}
.site-prefetching{cursor:progress}

/* P8 · Desktop polish */
@media(min-width:900px){
  :is(.d-shell main,.p-main,.wp-main,.pv-main,.bc-main,.sys-main,.so-main){max-width:var(--product-max);margin-inline:auto}
  :is(.p-table,.wp-table,.pv-table,.bc-table,.sys-table,.c-table,.f-table) thead th{
    position:sticky;top:0;z-index:4;background:#f8fafc!important;box-shadow:0 1px 0 #e2e8f0
  }
  :is(.p-hero,.wp-kpis,.pv-kpis,.bc-kpis,.sys-kpis,.f-kpis,.c-kpis)>*{height:100%}
  :is(.p-card,.wp-card,.pv-card,.bc-card,.sys-card,.so-panel){scroll-margin-top:16px}
  .p-desktop-detail{scrollbar-gutter:stable}
  .p-left-stack{scrollbar-gutter:stable}
  :is(.p-btn,.wp-btn,.pv-btn,.bc-btn,.sys-btn,.so-actions a,.c-actions a,.f-actions a){transition:transform .12s ease,box-shadow .12s ease,background .12s ease}
  @media(hover:hover){
    :is(.p-btn,.wp-btn,.pv-btn,.bc-btn,.sys-btn,.so-actions a,.c-actions a,.f-actions a):hover{transform:translateY(-1px)}
  }
}

/* P3 + P9 · Mobile interaction / polish */
@media(max-width:899px){
  html,body{max-width:100%;overflow-x:hidden;overscroll-behavior-x:none}
  body.site-sheet-open{overflow:hidden!important}
  :is(a,button,input,select,textarea,summary,[role="button"]){min-height:var(--product-touch)}
  :is(a,button,summary){touch-action:manipulation}
  :is(.p-card,.wp-card,.pv-card,.bc-card,.sys-card,.so-panel,.di-card,.dc-event){max-width:100%;min-width:0}
  :is(.asx-ticker-link,.p-mobile-title b,.wp-mobile-card summary b,.f-mobile-card summary b,.so-head h1){
    overflow-wrap:anywhere;word-break:normal
  }
  :is(.so-price strong,.wp-mobile-price strong,.p-mobile-core b,.dm-card-grid b){font-variant-numeric:tabular-nums}
  details>summary{cursor:pointer}
  details>summary::-webkit-details-marker{display:none}
  .site-sticky-actions{
    position:sticky!important;bottom:calc(68px + env(safe-area-inset-bottom));z-index:40;
    padding:8px!important;margin-inline:-2px!important;border:1px solid #dfe7f0!important;border-radius:12px!important;
    background:rgba(255,255,255,.96)!important;box-shadow:0 8px 28px rgba(15,23,42,.12)!important;
    backdrop-filter:blur(12px);-webkit-backdrop-filter:blur(12px)
  }
  .site-sticky-actions :is(a,button){min-height:44px!important}
  .site-sheet-backdrop{
    position:fixed;inset:0;z-index:94;border:0;padding:0;background:rgba(15,23,42,.28);opacity:0;pointer-events:none;
    transition:opacity .16s ease
  }
  body.site-sheet-open .site-sheet-backdrop{opacity:1;pointer-events:auto}
  .site-mobile-more,.site-mobile-signals{
    max-height:min(76dvh,620px)!important;border-radius:20px 20px 14px 14px!important;
    overscroll-behavior:contain;scrollbar-gutter:stable
  }
  .site-mobile-more.open,.site-mobile-signals.open{transform:translateY(0)}
  .site-mobile-more a,.site-mobile-signals a{min-height:64px!important}
  .p2-chart-shell:not(.p2-chart-full):not(.p2-landscape-full) .p2-indicators[open]>div{
    position:fixed!important;left:12px!important;right:12px!important;bottom:calc(76px + env(safe-area-inset-bottom))!important;
    z-index:96!important;display:grid!important;grid-template-columns:1fr 1fr!important;gap:8px!important;
    width:auto!important;padding:14px!important;border:1px solid #dbe3ed!important;border-radius:18px!important;
    background:#fff!important;box-shadow:0 18px 46px rgba(15,23,42,.2)!important
  }
  .p2-chart-shell:not(.p2-chart-full):not(.p2-landscape-full) .p2-indicators[open]>div label{min-height:48px!important}
  :is(input,select,textarea){max-width:100%}
  :is(.p-table-wrap,.wp-table-wrap,.pv-table-wrap,.bc-table-wrap,.sys-table-wrap,.c-table-wrap,.f-table-wrap){
    overscroll-behavior-x:contain;-webkit-overflow-scrolling:touch
  }
  .site-horizontal-fade{position:relative}
  .site-horizontal-fade::after{
    content:"";position:sticky;right:0;float:right;width:24px;height:100%;pointer-events:none;
    background:linear-gradient(90deg,transparent,rgba(247,249,252,.95))
  }
  @supports(height:100dvh){.site-mobile-more,.site-mobile-signals{max-height:76dvh!important}}
}

@media(max-width:430px){
  :is(.d-shell main,.p-main,.wp-main,.pv-main,.bc-main,.sys-main,.so-main){padding-left:12px!important;padding-right:12px!important}
  .site-sticky-actions{display:grid!important;grid-template-columns:1fr 1fr!important;gap:7px!important}
  .site-sticky-actions>*:only-child{grid-column:1/-1}
}

@media(max-width:899px) and (orientation:landscape){
  body.site-mobile-nav-enabled:not(.site-chart-full-active){padding-bottom:calc(68px + env(safe-area-inset-bottom))!important}
  .site-mobile-nav{height:calc(58px + env(safe-area-inset-bottom))!important}
}

/* coarse pointer = touch-first; no hover-only information */
@media(pointer:coarse){
  [title]{-webkit-user-select:none}
  :is(.p-btn,.wp-btn,.pv-btn,.bc-btn,.sys-btn,.so-actions a,.c-actions a,.f-actions a){min-height:44px}
}
