/* Global TEMPLATE — preferred width stays 720px.
   A visible rail reserves one card column. Extra columns use leftover rail space. */

.client-portal-display-body:has(.cp-global-template),
.client-portal-display-body:has(.cp-global-template):has([data-cp-client-quick-search]) {
  --cp-template-track: min(100%, var(--cp-template-preferred));
  container-type: inline-size;
  container-name: cp-client-initial;
  display: grid;
  grid-template-columns: var(--cp-template-track) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  align-items: stretch;
  align-content: start;
  justify-content: start;
  overflow: hidden;
  padding: 0;
}

.client-portal-display-body:has(.cp-global-template):has([data-cp-display-rail]),
.client-portal-display-body:has(.cp-global-template):has([data-cp-completed-inbox]),
.client-portal-display-body:has(.cp-global-template):has([data-cp-note-inbox]),
.client-portal-display-body:has(.cp-global-template):has([data-cp-ccr-resolved-inbox]) {
  --cp-template-track: min(100%, clamp(var(--cp-template-min), calc(100% - var(--cp-rail-1col)), var(--cp-template-preferred)));
}

.client-portal-display-body:has(.cp-global-template) > [data-cp-client-quick-search] {
  grid-column: 1 / -1;
  grid-row: 1;
  flex: 0 0 auto;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  justify-self: stretch;
  align-self: start;
}

.cp-global-template {
  grid-column: 1;
  grid-row: 2;
  justify-self: start;
  align-self: stretch;
  flex: 0 0 auto;
  width: min(100cqi, var(--cp-template-preferred));
  max-width: 100%;
  min-width: 0;
  min-height: 0;
  height: auto;
  max-height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: flex-start;
}

.client-portal-display-body:has([data-cp-display-rail]) > .cp-global-template,
.client-portal-display-body:has([data-cp-completed-inbox]) > .cp-global-template,
.client-portal-display-body:has([data-cp-note-inbox]) > .cp-global-template,
.client-portal-display-body:has([data-cp-ccr-resolved-inbox]) > .cp-global-template {
  width: min(100cqi, clamp(var(--cp-template-min), calc(100cqi - var(--cp-rail-1col)), var(--cp-template-preferred)));
}

.client-portal-display-body:has(.cp-global-template) > [data-cp-display-rail],
.client-portal-display-body:has(.cp-global-template) > [data-cp-completed-inbox],
.client-portal-display-body:has(.cp-global-template) > [data-cp-note-inbox],
.client-portal-display-body:has(.cp-global-template) > [data-cp-ccr-resolved-inbox] {
  grid-column: 2;
  grid-row: 2;
  width: auto;
  max-width: 100%;
  min-width: 0;
}

/* The blocked-company image sits beside the template, under the search row.
   Notification cards move to the third column only while that image is present.
   The template keeps its preferred width. */
.client-portal-display-body:has(.cp-global-template):has([data-cp-blocked-message]) {
  --cp-template-track: min(100%, var(--cp-template-preferred));
}

@container cp-client-panel (min-width: 752px) {
  .client-portal-display-body:has(.cp-global-template):has([data-cp-blocked-message]) {
    grid-template-columns: var(--cp-template-track) max-content minmax(0, 1fr);
  }
}

.client-portal-display-body:has(.cp-global-template):has([data-cp-blocked-message]) > .cp-global-template {
  grid-column: 1;
  grid-row: 2;
  width: 100%;
  max-width: var(--cp-template-preferred);
  height: 100%;
  max-height: 100%;
}

.client-portal-display-body:has(.cp-global-template) > [data-cp-blocked-message] {
  grid-column: 2;
  grid-row: 2;
  align-self: start;
  justify-self: start;
  width: auto;
  max-width: none;
  min-width: 0;
  z-index: 1;
}

.client-portal-display-body:has(.cp-global-template):has([data-cp-blocked-message]) > [data-cp-display-rail],
.client-portal-display-body:has(.cp-global-template):has([data-cp-blocked-message]) > [data-cp-completed-inbox],
.client-portal-display-body:has(.cp-global-template):has([data-cp-blocked-message]) > [data-cp-note-inbox],
.client-portal-display-body:has(.cp-global-template):has([data-cp-blocked-message]) > [data-cp-ccr-resolved-inbox] {
  grid-column: 3;
  grid-row: 2;
}

.client-portal-display:has(.cp-global-template) {
  container-type: inline-size;
  container-name: cp-client-panel;
}

/* Stack only when the template minimum plus one usable card column cannot fit.
   The row sizes live on the parent container because a container cannot restyle itself. */
@container cp-client-panel (max-width: 751px) {
  .client-portal-display-body:has(.cp-global-template):has([data-cp-display-rail]),
  .client-portal-display-body:has(.cp-global-template):has([data-cp-completed-inbox]),
  .client-portal-display-body:has(.cp-global-template):has([data-cp-note-inbox]),
  .client-portal-display-body:has(.cp-global-template):has([data-cp-ccr-resolved-inbox]) {
    --cp-template-track: min(100%, var(--cp-template-preferred));
    grid-template-rows: auto minmax(180px, 42%) minmax(0, 1fr);
  }
}

@container cp-client-initial (max-width: 751px) {
  .client-portal-display-body:has(.cp-global-template):has([data-cp-display-rail]) > .cp-global-template,
  .client-portal-display-body:has(.cp-global-template):has([data-cp-completed-inbox]) > .cp-global-template,
  .client-portal-display-body:has(.cp-global-template):has([data-cp-note-inbox]) > .cp-global-template,
  .client-portal-display-body:has(.cp-global-template):has([data-cp-ccr-resolved-inbox]) > .cp-global-template,
  .client-portal-display-body:has([data-cp-client-quick-search]):has(.cp-global-template):has([data-cp-display-rail]) > .cp-global-template {
    grid-column: 1;
    grid-row: 2;
    justify-self: start;
    width: min(100cqi, var(--cp-template-preferred));
    max-width: 100%;
    height: 100%;
    max-height: 100%;
  }

  .client-portal-display-body:has(.cp-global-template):has([data-cp-display-rail]) > [data-cp-display-rail],
  .client-portal-display-body:has(.cp-global-template) > [data-cp-completed-inbox],
  .client-portal-display-body:has(.cp-global-template) > [data-cp-note-inbox],
  .client-portal-display-body:has(.cp-global-template) > [data-cp-ccr-resolved-inbox],
  .client-portal-display-body:has([data-cp-client-quick-search]):has(.cp-global-template) > [data-cp-display-rail] {
    grid-column: 1 / -1;
    grid-row: 3;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
  }
}

.cp-global-template-pane {
  width: 100% !important;
  max-width: none;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: #1b1e21;
  border-right: 1px solid rgba(255, 255, 255, 0.10);
}

.cp-global-template-scroll {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
}

.cp-global-template-frame {
  display: block;
  width: 100%;
  min-height: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  pointer-events: auto;
}

.cp-global-template-status {
  padding: 24px 16px;
  color: rgba(242, 245, 248, 0.7);
  font-size: 13px;
}

.cp-global-template-status.is-error {
  color: #f0b4b1;
}

.cp-blocked-message {
  position: relative;
  flex: 0 0 auto;
  align-self: flex-start;
  height: 62%;
  max-height: 62%;
  width: auto;
  margin: 12px 16px 0 12px;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: auto;
}

.cp-blocked-message img {
  display: block;
  height: 100%;
  width: auto;
  max-height: 100%;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.cp-blocked-message-reason {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  height: 30%;
  box-sizing: border-box;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  background: #000;
  color: #ffffff;
  -webkit-text-fill-color: #ffffff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  text-align: center;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: auto;
  pointer-events: none;
}

.cp-blocked-message:hover .cp-blocked-message-reason,
.cp-blocked-message.is-hover .cp-blocked-message-reason {
  display: flex;
}

.cp-client-quick-search.cp-all-projects-toolbar {
  margin: 0;
  border-radius: 0;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  box-sizing: border-box;
}

.client-portal-display-body:not(:has(.cp-global-template)) > [data-cp-client-quick-search] {
  width: calc(100% + 32px);
  max-width: none;
  margin-left: -16px;
  margin-right: -16px;
}

.cp-client-quick-search .cp-all-projects-search-input:focus-visible,
.cp-client-quick-search .cp-all-projects-search-btn:focus-visible,
.cp-client-quick-search .cp-all-projects-search-clear:focus-visible,
.cp-client-quick-search .cp-all-projects-clear-filters:focus-visible,
.cp-client-quick-search select:focus-visible {
  outline: 2px solid #59b7de;
  outline-offset: 2px;
}
