/* ALLIANCE NEXT — Professional responsive layout polish 5.8.0
   Safe presentation-only overrides. No workflow or API behavior changes. */

:root {
  --an-sidebar-width: 232px;
  --an-shell-gap: 22px;
  --an-dock-bottom: 18px;
  --an-dock-size: 52px;
}

html.pro-suite,
html.pro-suite body {
  min-width: 320px;
  overflow-x: hidden;
}

/* Stable application shell. The navigation scrolls without moving the page. */
html.pro-suite #app {
  grid-template-columns: var(--an-sidebar-width) minmax(0, 1fr) !important;
  align-items: stretch;
  min-height: 100dvh;
}

html.pro-suite #app > aside {
  position: sticky !important;
  top: 0;
  width: var(--an-sidebar-width);
  height: 100dvh;
  min-height: 0 !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: contain;
  scrollbar-gutter: stable;
  padding: 0 4px 90px 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 .nav-group button i {
  flex: 0 0 18px;
}

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

html.pro-suite #app > main {
  min-width: 0;
  width: 100%;
  padding-bottom: 126px;
}

/* Header content remains legible instead of compressing into itself. */
html.pro-suite #app > main > header {
  width: 100%;
  min-width: 0;
  min-height: 76px;
  height: auto;
  gap: 18px;
  padding: 12px clamp(18px, 2vw, 30px) !important;
}

html.pro-suite #app .top-actions {
  min-width: 0;
  flex: 0 1 auto;
  justify-content: flex-end;
}

html.pro-suite #app #identity {
  min-width: 0;
  max-width: 190px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

/* Defensive grid sizing prevents cards and long labels from overlapping. */
html.pro-suite #content > *,
html.pro-suite .cards > *,
html.pro-suite .grid > *,
html.pro-suite .grid2 > *,
html.pro-suite .layout > *,
html.pro-suite .panel,
html.pro-suite .card {
  min-width: 0;
}

html.pro-suite .cards {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 16px !important;
}

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

html.pro-suite .panel,
html.pro-suite .card {
  overflow: hidden;
}

html.pro-suite .panel-head,
html.pro-suite .hero,
html.pro-suite .toolbar,
html.pro-suite .recordbar {
  min-width: 0;
  flex-wrap: wrap;
}

html.pro-suite .panel-head > *,
html.pro-suite .hero > *,
html.pro-suite .toolbar > *,
html.pro-suite .recordbar > * {
  min-width: 0;
}

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

html.pro-suite .status-row > *,
html.pro-suite .status-row b,
html.pro-suite .status-row small,
html.pro-suite .card,
html.pro-suite .panel {
  overflow-wrap: anywhere;
}

html.pro-suite .status-row > :last-child,
html.pro-suite .badge,
html.pro-suite .pill {
  justify-self: end;
  white-space: nowrap;
}

html.pro-suite .table-wrap,
html.pro-suite .tablewrap {
  width: 100%;
  min-width: 0;
  overflow: auto;
  overscroll-behavior-inline: contain;
}

/* Bottom utility rail: each control has its own reserved position. */
html.pro-suite #app ~ #liveTxButton {
  left: calc(var(--an-sidebar-width) + var(--an-shell-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-shell-gap)) !important;
  right: auto !important;
  bottom: var(--an-dock-bottom) !important;
  max-width: min(320px, calc(100vw - var(--an-sidebar-width) - 44px));
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

html.pro-suite .pro-signout {
  right: 82px !important;
  bottom: var(--an-dock-bottom) !important;
}

/* Both the native support button and Chaport are moved away from the left rail. */
html.pro-suite #allianceSupportButton,
html.pro-suite .chaport-launcher-button {
  position: fixed !important;
  left: auto !important;
  right: 188px !important;
  bottom: var(--an-dock-bottom) !important;
  margin: 0 !important;
}

html.pro-suite .chaport-launcher {
  left: auto !important;
  right: 0 !important;
}

html.pro-suite #allianceSupportPreview {
  left: auto !important;
  right: 18px !important;
  bottom: 84px !important;
}

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

/* Standalone terminals also keep database controls in a clean vertical rail. */
html.pro-suite body > #liveTxButton:not(#app ~ #liveTxButton) {
  left: 18px !important;
  bottom: 58px !important;
}

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

@media (max-width: 1280px) {
  :root { --an-sidebar-width: 220px; --an-shell-gap: 18px; }

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

  html.pro-suite .grid2 {
    grid-template-columns: 1fr !important;
  }

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

@media (max-width: 900px) {
  :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;
    min-height: 0 !important;
    overflow: visible !important;
  }

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

  html.pro-suite #app > main {
    padding-bottom: 138px;
  }

  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: 620px) {
  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 .cards {
    grid-template-columns: minmax(0, 1fr) !important;
  }

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

  html.pro-suite .btn-row > *,
  html.pro-suite .toolbar > button,
  html.pro-suite .recordbar > button {
    width: 100% !important;
  }

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

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