/*
 * Self-managed GitLab setup panel.
 *
 * ## Why it is self-contained
 *
 * The panel ships in two hosts that share no CSS: the Productivity Tools page
 * (Bootstrap 5 + Metronic) and the guided setup (the approved prototype's own
 * stylesheet, which deliberately does not load the product bundle). A component
 * built out of `.form-control` / `.btn` would be unstyled in the wizard, and one
 * built out of the wizard's `.fld` / `.btn.pri` would collide with Bootstrap on
 * the product page. So every rule here is `.ct-glsh`-scoped and declares its own
 * values — nothing is inherited from either host except the font family.
 *
 * ## Why it looks like this
 *
 * The product's palette, from the tokens both hosts already use: celeste #1b84ff
 * for the one primary action and the selected choice, the Metronic grays for
 * copy (#4b5675 / #99a1b7 / #071437), #f1f1f4 hairlines, .625rem radii. Colour
 * is spent only where it carries meaning: the chosen option, the save button,
 * the green of "already set up", the amber of "everybody has to reconnect".
 *
 * ## The two rules this component is shaped by
 *
 * Nothing important is behind an icon: the copy control and the show/hide
 * control are buttons with words in them, and the "change these details" control
 * is a labelled button rather than a chevron. And nothing scrolls sideways: the
 * permission list is a stacked list rather than a table, the long values wrap
 * with `overflow-wrap: anywhere`, and every row collapses to one column at
 * narrow widths.
 *
 * Motion is transform/opacity only, ease-out, under 200ms, and drops to nothing
 * under prefers-reduced-motion.
 */

.ct-glsh {
    --ct-glsh-ink: #071437;
    --ct-glsh-body: #4b5675;
    --ct-glsh-muted: #99a1b7;
    --ct-glsh-line: #f1f1f4;
    --ct-glsh-line-strong: #dbdfe9;
    --ct-glsh-surface: #ffffff;
    --ct-glsh-surface-soft: #f9f9f9;
    --ct-glsh-primary: #1b84ff;
    --ct-glsh-primary-hover: #107eff;
    --ct-glsh-primary-soft: #e9f3ff;
    --ct-glsh-ok: #17c653;
    --ct-glsh-ok-soft: #dfffea;
    --ct-glsh-ok-ink: #0f9d58;
    --ct-glsh-warn: #f6c000;
    --ct-glsh-warn-soft: #fff8dd;
    --ct-glsh-warn-ink: #a07800;
    --ct-glsh-danger: #f8285a;
    --ct-glsh-ease: cubic-bezier(0.23, 1, 0.32, 1);

    color: var(--ct-glsh-body);
    font-size: 1rem;
    line-height: 1.55;
    text-align: left;
}

.ct-glsh *,
.ct-glsh *::before,
.ct-glsh *::after {
    box-sizing: border-box;
}

/* Both hosts style [hidden] differently (or not at all); the panel toggles
   whole sections with it, so it has to win over the display rules below. */
.ct-glsh [hidden] {
    display: none !important;
}

/* ---------------------------------------------------------------- typography */

.ct-glsh__h {
    margin: 0 0 0.25rem;
    color: var(--ct-glsh-ink);
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.35;
}

.ct-glsh__h4 {
    margin: 0 0 0.25rem;
    color: var(--ct-glsh-ink);
    font-size: 1.075rem;
    font-weight: 700;
    line-height: 1.4;
}

.ct-glsh__p {
    margin: 0 0 0.75rem;
    color: var(--ct-glsh-body);
}

.ct-glsh__block {
    padding: 0 0 1.5rem;
}

.ct-glsh__block--last {
    padding-bottom: 0;
}

.ct-glsh__panel {
    padding-top: 1.5rem;
    border-top: 1px solid var(--ct-glsh-line);
}

/* ------------------------------------------------------------- the question */

.ct-glsh__choices {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
    margin-top: 0.75rem;
}

/* A whole card is the hit area, and the card says what it is in words. The
   native radio stays in the DOM (keyboard, forms, :checked) but is painted by
   the mark next to it, because the browser default is a 13px dot next to two
   lines of text and reads like a footnote. */
.ct-glsh__choice {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    margin: 0;
    padding: 0.875rem 1rem;
    border: 1px solid var(--ct-glsh-line-strong);
    border-radius: 0.625rem;
    background: var(--ct-glsh-surface);
    cursor: pointer;
    transition: border-color 160ms var(--ct-glsh-ease), background-color 160ms var(--ct-glsh-ease);
}

.ct-glsh__choice:hover {
    border-color: var(--ct-glsh-primary);
}

.ct-glsh__radio {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    padding: 0;
    border: 0;
    opacity: 0;
    pointer-events: none;
}

.ct-glsh__choice-mark {
    flex: none;
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.175rem;
    border: 2px solid var(--ct-glsh-line-strong);
    border-radius: 50%;
    background: var(--ct-glsh-surface);
    transition: border-color 160ms var(--ct-glsh-ease), box-shadow 160ms var(--ct-glsh-ease);
}

.ct-glsh__radio:checked ~ .ct-glsh__choice-mark {
    border-color: var(--ct-glsh-primary);
    box-shadow: inset 0 0 0 0.25rem var(--ct-glsh-surface), inset 0 0 0 1rem var(--ct-glsh-primary);
}

.ct-glsh__choice:has(.ct-glsh__radio:checked) {
    border-color: var(--ct-glsh-primary);
    background: var(--ct-glsh-primary-soft);
}

/* :has() is not everywhere yet; keyboard focus must be visible regardless. */
.ct-glsh__radio:focus-visible ~ .ct-glsh__choice-mark {
    outline: 2px solid var(--ct-glsh-primary);
    outline-offset: 3px;
}

.ct-glsh__choice-text {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    min-width: 0;
}

.ct-glsh__choice-title {
    color: var(--ct-glsh-ink);
    font-size: 1.05rem;
    font-weight: 600;
}

.ct-glsh__choice-desc {
    color: var(--ct-glsh-body);
    font-size: 0.925rem;
    line-height: 1.5;
}

.ct-glsh__badge {
    align-self: flex-start;
    margin-top: 0.375rem;
    padding: 0.1875rem 0.5rem;
    border-radius: 0.375rem;
    background: var(--ct-glsh-surface-soft);
    color: var(--ct-glsh-body);
    font-size: 0.825rem;
    font-weight: 600;
    line-height: 1.4;
}

.ct-glsh__badge--ok {
    background: var(--ct-glsh-ok-soft);
    color: var(--ct-glsh-ok-ink);
}

/* -------------------------------------------------------- GitLab.com is fine */

.ct-glsh__calm {
    padding: 0.875rem 1rem;
    border: 1px solid var(--ct-glsh-line);
    border-radius: 0.625rem;
    background: var(--ct-glsh-surface-soft);
}

.ct-glsh__calm-title {
    margin-bottom: 0.25rem;
    color: var(--ct-glsh-ink);
    font-weight: 600;
}

.ct-glsh__calm .ct-glsh__p:last-child {
    margin-bottom: 0;
}

/* --------------------------------------------------------- the five steps */

.ct-glsh__steps {
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
    counter-reset: ct-glsh-step;
}

.ct-glsh__step {
    position: relative;
    padding: 0 0 1.125rem 2.375rem;
    counter-increment: ct-glsh-step;
}

.ct-glsh__step:last-child {
    padding-bottom: 0;
}

/* A numbered circle, and a rule joining it to the next one, so the five steps
   read as a sequence to walk rather than as five paragraphs. */
.ct-glsh__step::before {
    content: counter(ct-glsh-step);
    position: absolute;
    top: 0;
    left: 0;
    display: grid;
    place-items: center;
    width: 1.625rem;
    height: 1.625rem;
    border-radius: 50%;
    background: var(--ct-glsh-primary-soft);
    color: var(--ct-glsh-primary);
    font-size: 0.875rem;
    font-weight: 700;
    line-height: 1;
}

.ct-glsh__step::after {
    content: "";
    position: absolute;
    top: 2rem;
    bottom: 0.25rem;
    left: 0.8125rem;
    width: 2px;
    background: var(--ct-glsh-line);
}

.ct-glsh__step:last-child::after {
    display: none;
}

.ct-glsh__step-title {
    display: block;
    padding-top: 0.1875rem;
    color: var(--ct-glsh-ink);
    font-weight: 600;
}

.ct-glsh__step-body {
    display: block;
    margin-top: 0.125rem;
    color: var(--ct-glsh-body);
}

/* ------------------------------------------------------- the six permissions */

.ct-glsh__scopes {
    display: grid;
    gap: 0.5rem;
    margin: 0.75rem 0 0;
    padding: 0.75rem;
    border: 1px solid var(--ct-glsh-line);
    border-radius: 0.625rem;
    background: var(--ct-glsh-surface-soft);
    list-style: none;
}

/* Name and explanation stack under one tick: the alternative — a two-column
   table — is what starts scrolling sideways the moment the panel is narrow. */
.ct-glsh__scope {
    display: grid;
    grid-template-columns: 1.125rem minmax(0, 1fr);
    gap: 0.125rem 0.5rem;
    align-items: start;
}

.ct-glsh__scope-box {
    grid-row: 1;
    display: grid;
    place-items: center;
    width: 1.125rem;
    height: 1.125rem;
    margin-top: 0.1875rem;
    border-radius: 0.25rem;
    background: var(--ct-glsh-ok);
    color: #fff;
}

.ct-glsh__scope-box svg {
    width: 0.6875rem;
    height: 0.6875rem;
}

.ct-glsh__scope-name {
    grid-column: 2;
    font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.925rem;
    font-weight: 600;
    color: var(--ct-glsh-ink);
    overflow-wrap: anywhere;
}

.ct-glsh__scope-desc {
    grid-column: 2;
    color: var(--ct-glsh-body);
    font-size: 0.925rem;
    line-height: 1.5;
}

/* ------------------------------------------------------------------- fields */

.ct-glsh__field {
    margin-top: 1rem;
}

.ct-glsh__label-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    margin: 0.75rem 0 0.375rem;
}

.ct-glsh__step .ct-glsh__label-row {
    margin-top: 0.625rem;
}

.ct-glsh__label {
    margin: 0;
    color: var(--ct-glsh-ink);
    font-size: 0.95rem;
    font-weight: 600;
}

.ct-glsh__input {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding: 0.5625rem 0.75rem;
    border: 1px solid var(--ct-glsh-line-strong);
    border-radius: 0.475rem;
    background: var(--ct-glsh-surface);
    color: var(--ct-glsh-ink);
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    transition: border-color 160ms var(--ct-glsh-ease), box-shadow 160ms var(--ct-glsh-ease);
}

.ct-glsh__input--mono {
    font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.925rem;
}

.ct-glsh__input:focus {
    border-color: var(--ct-glsh-primary);
    box-shadow: 0 0 0 3px rgba(27, 132, 255, 0.12);
    outline: none;
}

.ct-glsh__input[readonly] {
    background: var(--ct-glsh-surface-soft);
    color: var(--ct-glsh-body);
}

.ct-glsh__hint {
    display: block;
    margin-top: 0.3125rem;
    color: var(--ct-glsh-muted);
    font-size: 0.9rem;
    line-height: 1.5;
}

/* An input with one button welded to its right edge. Wraps to two rows under
   ~22rem so the button never squeezes the field into a sliver. */
.ct-glsh__copyrow {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: stretch;
}

.ct-glsh__copyrow > .ct-glsh__input {
    flex: 1 1 12rem;
}

/* ------------------------------------------------------------------ buttons */

.ct-glsh__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5625rem 1rem;
    border: 1px solid var(--ct-glsh-line-strong);
    border-radius: 0.475rem;
    background: var(--ct-glsh-surface);
    color: var(--ct-glsh-ink);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.4;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: background-color 160ms var(--ct-glsh-ease), border-color 160ms var(--ct-glsh-ease),
                color 160ms var(--ct-glsh-ease), opacity 160ms var(--ct-glsh-ease);
}

.ct-glsh__btn:hover {
    border-color: var(--ct-glsh-primary);
    color: var(--ct-glsh-primary);
}

.ct-glsh__btn:focus-visible {
    outline: 2px solid var(--ct-glsh-primary);
    outline-offset: 2px;
}

.ct-glsh__btn--attached {
    flex: none;
}

.ct-glsh__btn--primary {
    border-color: var(--ct-glsh-primary);
    background: var(--ct-glsh-primary);
    color: #fff;
}

.ct-glsh__btn--primary:hover {
    border-color: var(--ct-glsh-primary-hover);
    background: var(--ct-glsh-primary-hover);
    color: #fff;
}

.ct-glsh__btn[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.ct-glsh__btn[disabled]:hover {
    border-color: var(--ct-glsh-line-strong);
    color: var(--ct-glsh-ink);
}

.ct-glsh__btn--primary[disabled]:hover {
    border-color: var(--ct-glsh-primary);
    background: var(--ct-glsh-primary);
    color: #fff;
}

.ct-glsh__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.625rem;
    margin-top: 1rem;
}

/* ---------------------------------------------------------------- messages */

.ct-glsh__inline-note {
    display: block;
    color: var(--ct-glsh-muted);
    font-size: 0.9rem;
}

.ct-glsh__status,
.ct-glsh__error,
.ct-glsh__warn {
    display: block;
    margin: 0.75rem 0 0;
    padding: 0.625rem 0.75rem;
    border-radius: 0.475rem;
    font-size: 0.925rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.ct-glsh__status {
    border: 1px solid var(--ct-glsh-ok);
    background: var(--ct-glsh-ok-soft);
    color: var(--ct-glsh-ok-ink);
}

/* Same box while something is still in flight. Green is reserved for things that
   already happened — a success-coloured "reading your setup..." claims an outcome
   the request has not produced yet. */
.ct-glsh__status--busy {
    border-color: var(--ct-glsh-line-strong);
    background: var(--ct-glsh-surface-soft);
    color: var(--ct-glsh-body);
}

.ct-glsh__error {
    border: 1px solid var(--ct-glsh-danger);
    background: #ffeef3;
    color: #c01a44;
}

.ct-glsh__warn {
    border: 1px solid var(--ct-glsh-warn);
    background: var(--ct-glsh-warn-soft);
    color: var(--ct-glsh-warn-ink);
}

/* The one message that must survive being ignored: a whole organization has to
   reconnect. Louder than the inline warnings, and it stays put. */
.ct-glsh__alarm {
    margin: 1.25rem 0 0;
    padding: 0.875rem 1rem;
    border: 1px solid var(--ct-glsh-warn);
    border-left-width: 4px;
    border-radius: 0.625rem;
    background: var(--ct-glsh-warn-soft);
    color: var(--ct-glsh-warn-ink);
}

.ct-glsh__alarm-title {
    margin-bottom: 0.25rem;
    color: var(--ct-glsh-ink);
    font-size: 1.025rem;
    font-weight: 700;
}

.ct-glsh__alarm .ct-glsh__p {
    margin-bottom: 0;
    color: var(--ct-glsh-warn-ink);
}

/* ------------------------------------------------------- already set up */

.ct-glsh__saved {
    padding: 1rem;
    border: 1px solid var(--ct-glsh-line);
    border-radius: 0.625rem;
    background: var(--ct-glsh-surface-soft);
}

.ct-glsh__saved-head {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
}

.ct-glsh__saved-check {
    flex: none;
    display: grid;
    place-items: center;
    width: 1.375rem;
    height: 1.375rem;
    margin-top: 0.125rem;
    border-radius: 50%;
    background: var(--ct-glsh-ok);
    color: #fff;
}

.ct-glsh__saved-check svg {
    width: 0.75rem;
    height: 0.75rem;
}

.ct-glsh__saved-title {
    display: block;
    color: var(--ct-glsh-ink);
    font-size: 1.05rem;
    font-weight: 700;
}

.ct-glsh__saved-hint {
    display: block;
    margin-top: 0.125rem;
    color: var(--ct-glsh-body);
    font-size: 0.925rem;
}

/* Label above value, one pair per row. A two-column grid put an application id
   next to a URL and both of them wrapped mid-string. */
.ct-glsh__facts {
    margin: 0.875rem 0 0;
}

.ct-glsh__facts dt {
    margin: 0;
    color: var(--ct-glsh-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.ct-glsh__facts dd {
    margin: 0.0625rem 0 0.625rem;
    color: var(--ct-glsh-ink);
    font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.925rem;
    overflow-wrap: anywhere;
}

.ct-glsh__facts dd:last-of-type {
    margin-bottom: 0;
}

.ct-glsh__saved-when {
    margin: 0.75rem 0 0;
    color: var(--ct-glsh-muted);
    font-size: 0.9rem;
}

/* --------------------------------------------------- the definition triggers */

/*
 * term-tip.js only needs `data-lm-tip` on a trigger; the look is the caller's.
 * `.lm-tip` is styled globally in custom.css for the product page, but the
 * wizard's layout does not load custom.css at all — so the trigger paints itself
 * here, scoped to the component, and works identically in both hosts.
 */
.ct-glsh .lm-tip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.125rem;
    height: 1.125rem;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--ct-glsh-muted);
    font: inherit;
    cursor: pointer;
    transition: color 160ms var(--ct-glsh-ease);
}

.ct-glsh .lm-tip svg {
    width: 100%;
    height: 100%;
}

.ct-glsh .lm-tip:hover,
.ct-glsh .lm-tip[aria-expanded="true"] {
    color: var(--ct-glsh-primary);
}

.ct-glsh .lm-tip:focus-visible {
    outline: 2px solid var(--ct-glsh-primary);
    outline-offset: 2px;
}

/*
 * The panel term-tip.js appends to <body>. custom.css already styles it on the
 * product page; this is the same treatment for the wizard, which loads neither
 * custom.css nor the bundle. Scoped to the wizard's body class so the product
 * page keeps exactly the panel it has today.
 */
.lm-onboarding .lm-tip__panel {
    position: fixed;
    z-index: 1085;
    display: none;
    padding: 0.75rem 0.875rem;
    border: 1px solid #f1f1f4;
    border-radius: 0.475rem;
    background: #fff;
    box-shadow: 0 0.5rem 1.5rem rgba(76, 87, 125, 0.15);
    color: #4b5675;
    font-size: 0.9rem;
    font-weight: 400;
    line-height: 1.55;
    letter-spacing: normal;
    text-transform: none;
    white-space: normal;
}

.lm-onboarding .lm-tip__panel--open {
    display: block;
}

/* ---------------------------------------------------------------- reduced */

@media (prefers-reduced-motion: reduce) {
    .ct-glsh *,
    .ct-glsh *::before,
    .ct-glsh *::after {
        transition: none !important;
    }
}

/* The one action of a step sits at the trailing edge, where the eye lands after
   reading the block above it and where every other confirm in the product is. */
.ct-glsh__actions--end {
    justify-content: flex-end;
}

/* The opener the guided setup puts beside the tool name, mirroring the quiet link
   on the Productivity Tools card: the panel behind it is five steps of setup that
   only a self-managed organization needs, so it stays closed until asked for. */
.glsh-open {
    margin-left: .5rem;
    padding: 0;
    border: 0;
    background: none;
    color: var(--ct-glsh-muted, #99a1b7);
    font: inherit;
    font-size: .8125rem;
    text-decoration: underline;
    cursor: pointer;
    white-space: nowrap;
}

.glsh-open:hover,
.glsh-open:focus-visible {
    color: var(--ct-glsh-primary, #1b84ff);
}

/* The wizard's .modal already handles the shell: fixed, centred, flex column,
   max-height 88vh. Only two things are missing for this panel — it is wider than
   the team editor it was sized for, and .m-b ships with no padding because that
   editor pads from its own inner markup. */
.glsh-modal {
    width: 820px;
}

.glsh-modal .m-b {
    padding: 22px;
    /* A column flex item defaults to min-height:auto and refuses to shrink below
       its content, so the base rule's overflow:auto would never scroll and the
       close button would end up unreachable on a laptop. */
    min-height: 0;
}

/* The base .modal sets display:flex unconditionally, which beats the UA rule for
   [hidden] — so without this the dialog renders open before the JS runs, which is
   the exact failure the attribute is there to prevent. */
.glsh-modal[hidden] {
    display: none !important;
}
