/* ALLIANCE NEXT — Clean panel, layout & scroll repair 5.8.2
   Presentation-only overrides. Workflow, API and stored records are unchanged. */

:root {
  --an-sidebar-width: 232px;
  --an-edge-gap: 18px;
  --an-fixed-rail-height: 112px;
  --amber: #8ca1af !important;
  --yellow: #8ca1af !important;
  --warn: #8ca1af !important;
  --pro-amber: #8ca1af !important;
}

/* Clean neutral status palette. No yellow or amber frames remain in the panel. */
html.pro-suite :is(
  .notice, .banner, .warning, .warn, .amber, .gold, .environment, .env,
  .uat-band, .boundary, .boundary-box, .terminal-warning, .document-notice,
  .side-status, .waiting, .locked, .pill.warn, .badge.warn, .btn.warn,
  .btn.gold, .btn.hold
) {
  background-color: #0b1b27 !important;
  background-image: none !important;
  border-color: #2b4658 !important;
  color: #9eb4c2 !important;
  box-shadow: none !important;
}

html.pro-suite :is(
  [style*="#ffd"], [style*="#ffc"], [style*="#f6c"], [style*="#f4c"],
  [style*="#ffbd"], [style*="#d79e"], [style*="#b885"], [style*="#a879"]
) {
  background-color: #0b1b27 !important;
  background-image: none !important;
  border-color: #2b4658 !important;
  color: #9eb4c2 !important;
  box-shadow: none !important;
}

html.pro-suite .panel-clean-hidden {
  display: none !important;
}

/* The browser window is always the vertical scroll owner. */
html.pro-suite {
  min-width: 320px;
  min-height: 100%;
  height: auto !important;
  max-height: none !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior-y: auto !important;
  scrollbar-gutter: stable;
}

html.pro-suite body {
  min-width: 320px;
  min-height: 100dvh !important;
  height: auto !important;
  max-height: none !important;
  overflow-x: hidden !important;
  overflow-y: auto !important;
  overscroll-behavior-y: auto !important;
  position: relative !important;
  inset: auto !important;
}

/* Standalone terminals need room beneath the fixed utility controls. */
html.pro-suite body:not(:has(#app)) {
  padding-bottom: var(--an-fixed-rail-height) !important;
}

html.pro-suite body > :is(main, .shell, .wrap, .workspace, .layout, .container) {
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

html.pro-suite img,
html.pro-suite svg,
html.pro-suite canvas,
html.pro-suite video,
html.pro-suite iframe {
  max-width: 100%;
}

/* Main application shell: window scrolls, sidebar navigation scrolls independently. */
html.pro-suite #app {
  grid-template-columns: var(--an-sidebar-width) minmax(0, 1fr) !important;
  align-items: stretch;
  min-height: 100dvh !important;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
}

html.pro-suite #app > aside {
  position: sticky !important;
  top: 0;
  align-self: start;
  width: var(--an-sidebar-width);
  height: 100dvh !important;
  min-height: 0 !important;
  max-height: 100dvh !important;
  overflow: hidden !important;
  padding: 18px 12px 14px !important;
}

html.pro-suite #app > aside .side-head,
html.pro-suite #app > aside .side-search,
html.pro-suite #app > aside .side-bottom {
  flex: 0 0 auto;
}

html.pro-suite #app > aside nav {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: auto;
  scrollbar-gutter: stable;
  padding: 0 4px 84px 0;
}

html.pro-suite #app > aside .nav-group button {
  width: 100%;
  min-width: 0;
  white-space: normal;
  line-height: 1.25;
}

html.pro-suite #app > aside .side-bottom {
  margin-top: 10px !important;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, .07);
}

html.pro-suite #app > main {
  min-width: 0;
  width: 100%;
  min-height: 100dvh;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  padding-bottom: 132px !important;
}

html.pro-suite #app > main > header {
  width: 100%;
  min-width: 0;
  min-height: 76px;
  height: auto !important;
  gap: 18px;
  padding: 12px clamp(18px, 2vw, 30px) !important;
}

html.pro-suite #content {
  min-width: 0;
  height: auto !important;
  max-height: none !important;
  overflow: visible !important;
  padding: clamp(18px, 2.25vw, 30px) !important;
}

/* Grid rules are deliberately scoped to the main application. */
html.pro-suite #content > *,
html.pro-suite #content .cards > *,
html.pro-suite #content .grid > *,
html.pro-suite #content .grid2 > *,
html.pro-suite #content .layout > *,
html.pro-suite #content .panel,
html.pro-suite #content .card {
  min-width: 0;
}

html.pro-suite #content .cards {
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)) !important;
  gap: 16px !important;
}

html.pro-suite #content .grid2 {
  grid-template-columns: minmax(0, 1.65fr) minmax(280px, .85fr) !important;
  gap: 16px !important;
}

/* Panels may grow; only decorative cards keep clipped artwork. */
html.pro-suite #content .panel {
  overflow: visible !important;
}

html.pro-suite #content .card {
  overflow: clip;
}

html.pro-suite :is(.hero, .panel-head, .toolbar, .recordbar, .actions, .btn-row, .top-actions) {
  min-width: 0;
  flex-wrap: wrap;
}

html.pro-suite :is(.hero, .panel-head, .toolbar, .recordbar, .actions, .btn-row, .top-actions) > * {
  min-width: 0;
}

html.pro-suite .status-row {
  grid-template-columns: 10px minmax(0, 1fr) auto !important;
}

html.pro-suite :is(.status-row, .card, .panel, .record, .doc) :is(b, small, span, p, code) {
  overflow-wrap: anywhere;
}

html.pro-suite .table-wrap,
html.pro-suite .tablewrap {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow-x: auto !important;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

html.pro-suite #content .decision {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 230px;
}

html.pro-suite #content td:last-child {
  white-space: normal;
}

/* Fixed utilities occupy predictable rails instead of covering content. */
html.pro-suite #app ~ #liveTxButton {
  left: calc(var(--an-sidebar-width) + var(--an-edge-gap)) !important;
  right: auto !important;
  bottom: 62px !important;
  max-width: min(260px, calc(100vw - var(--an-sidebar-width) - 44px));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.pro-suite #app ~ .pro-suite-meta {
  left: calc(var(--an-sidebar-width) + var(--an-edge-gap)) !important;
  right: auto !important;
  bottom: 18px !important;
  max-width: min(320px, calc(100vw - var(--an-sidebar-width) - 44px));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

html.pro-suite body > #liveTxButton:not(#app ~ #liveTxButton) {
  left: 18px !important;
  right: auto !important;
  bottom: 58px !important;
}

html.pro-suite body > .pro-suite-meta:not(#app ~ .pro-suite-meta) {
  left: 18px !important;
  right: auto !important;
  bottom: 18px !important;
}

html.pro-suite .pro-app-dock {
  right: 18px !important;
  bottom: 18px !important;
}

html.pro-suite .pro-app-menu {
  max-height: min(68dvh, 640px);
  overflow-y: auto;
  overscroll-behavior: contain;
}

html.pro-suite .pro-signout {
  right: 82px !important;
  bottom: 18px !important;
}

html.pro-suite #allianceSupportButton,
html.pro-suite .chaport-launcher-button {
  position: fixed !important;
  left: auto !important;
  right: 188px !important;
  bottom: 18px !important;
  margin: 0 !important;
}

html.pro-suite #allianceSupportPreview,
html.pro-suite .toast {
  left: auto !important;
  right: 18px !important;
  bottom: 84px !important;
  max-width: min(420px, calc(100vw - 36px));
}

/* Common standalone terminal grids. Native page rules still take priority at desktop sizes. */
@media (max-width: 1380px) {
  :root { --an-sidebar-width: 220px; }

  html.pro-suite #content .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  html.pro-suite #content .grid2 {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  html.pro-suite body:not(:has(#app)) .cards,
  html.pro-suite body:not(:has(#app)) .evidence-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  html.pro-suite body:not(:has(#app)) .docs {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 1000px) {
  html.pro-suite body:not(:has(#app)) :is(.layout, .main, .grid2, .global-console-grid, .terminal-grid) {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  html.pro-suite body:not(:has(#app)) :is(.form-grid, .form.three) {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  html.pro-suite body:not(:has(#app)) .docs {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

@media (max-width: 880px) {
  :root { --an-sidebar-width: 100%; }

  html.pro-suite #app {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  html.pro-suite #app > aside {
    position: relative !important;
    width: 100%;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  html.pro-suite #app > aside nav {
    overflow: visible;
    padding: 0;
  }

  html.pro-suite #app > main {
    min-height: 0;
    padding-bottom: 142px !important;
  }

  html.pro-suite #app ~ #liveTxButton {
    left: 12px !important;
    bottom: 72px !important;
    max-width: calc(100vw - 24px);
  }

  html.pro-suite #app ~ .pro-suite-meta {
    display: none !important;
  }

  html.pro-suite #allianceSupportButton,
  html.pro-suite .chaport-launcher-button {
    right: 150px !important;
    bottom: 12px !important;
  }

  html.pro-suite .pro-signout {
    right: 76px !important;
    bottom: 12px !important;
    height: 48px !important;
    padding-inline: 14px !important;
  }

  html.pro-suite .pro-app-dock {
    right: 12px !important;
    bottom: 12px !important;
  }
}

@media (max-width: 680px) {
  html.pro-suite #app > main > header {
    align-items: flex-start;
    flex-direction: column;
  }

  html.pro-suite #app .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  html.pro-suite #content .cards,
  html.pro-suite body:not(:has(#app)) :is(.cards, .docs, .evidence-grid, .form-grid, .form.three, .status-grid, .service-grid, .dap-documents) {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  html.pro-suite :is(.btn-row, .toolbar, .recordbar, .actions) {
    align-items: stretch;
    flex-direction: column;
  }

  html.pro-suite :is(.btn-row, .toolbar, .recordbar, .actions) > :is(button, .btn, select, input) {
    width: 100% !important;
  }

  html.pro-suite body:not(:has(#app)) {
    padding-bottom: 92px !important;
  }

  html.pro-suite #allianceSupportButton,
  html.pro-suite .chaport-launcher-button {
    display: none !important;
  }
}

@media print {
  html.pro-suite,
  html.pro-suite body,
  html.pro-suite body > :is(main, .shell, .wrap, .workspace, .layout, .container) {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    padding-bottom: 0 !important;
  }

  #liveTxButton,
  .pro-suite-meta,
  .pro-app-dock,
  .pro-signout,
  #allianceSupportButton,
  #allianceSupportPreview,
  .chaport-container {
    display: none !important;
  }
}
