/* =====================================================================
   components.css — reusable UI components for the MCP Portal
   Sections: sections/headings · buttons · badges · cards · forms ·
             detail lists · tools editor · auth card · utilities
   ===================================================================== */

/* ---- Sections ---- */
.portal-section {
    margin-bottom: 2rem;
}

.portal-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* The names in these headings can run to 200 characters, so the heading is the item that gives:
   it clamps to two lines while whatever sits opposite it keeps its natural width and stays put.
   Pair with a title attribute for the full text on hover. */
.portal-section-head h1,
.portal-section-head h2 {
    margin: 0;
    flex: 1 1 0;
    min-width: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* The Configure page wraps its heading in an icon + breadcrumb column; it is the flex item there. */
.portal-section-head > .configure-heading {
    flex: 1 1 0;
}

/* Whatever the heading shares its row with: a button, a link, a badge, or a cluster of them. */
.portal-section-head > .portal-actions,
.portal-section-head > .portal-link,
.portal-section-head > .portal-button,
.portal-section-head > .portal-badge,
.portal-section-head > .portal-hint {
    flex: 0 0 auto;
    /* ...but it may still wrap inside itself when it alone is wider than the row. */
    max-width: 100%;
}

.portal-link {
    color: var(--muted);
    font-size: 0.9rem;
}

/* ---- Buttons ----
   Three weights, and which one a button gets is not a matter of taste:
     .portal-button            the one action the screen exists for. At most one per screen, so that a
                               filled button always means "this is what you came here to do". The
                               exception is a page built from self-contained form cards (the profile
                               page), where each card is its own screen and carries its own.
     -secondary                everything else that is still a button: cancel, a step to one side,
                               a state change the page is not steering you towards.
     -danger                   deletes and other destructive actions.
   Plain navigation (back, breadcrumbs, clear) is a .portal-link, not a button, and a filter bar
   applies itself rather than being pressed (see the auto-submitting controls in site.js). */
.portal-button {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.55rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--accent-grad);
    color: var(--on-accent);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: transform 0.06s ease, filter 0.15s ease;
}

.portal-button:hover {
    filter: brightness(1.08);
    text-decoration: none;
}

.portal-button:active {
    transform: translateY(1px);
}

.portal-button:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

/* Any button held while its work runs, e.g. the tool test while its call is in flight, or unavailable
   until something else changes. Ignoring the pointer stops the hover and press styles of every variant,
   and lets a title on a wrapping element show instead. */
.portal-button:disabled {
    filter: none;
    opacity: 0.6;
    pointer-events: none;
}

.portal-button-secondary {
    background: var(--surface-2);
    color: var(--text);
    border-color: var(--border);
}

.portal-button-secondary:hover {
    background: var(--surface-3);
    filter: none;
}

.portal-button-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

/* Copy buttons swap this label to "Copied" for a moment, and reveal buttons swap between "Show" and
   "Hide". Holding it at a fixed width stops the button resizing mid-swap, which would reflow whatever
   shares its row. em rather than rem so the reserved space tracks the button's own font size, which
   differs between the normal and -sm buttons. */
[data-copy-label],
[data-reveal-label] {
    display: inline-block;
    min-width: 4em;
    text-align: center;
}

.portal-button-danger {
    background: transparent;
    color: var(--danger);
    border-color: var(--danger);
}

.portal-button-danger:hover {
    background: var(--danger-bg);
    filter: none;
}

/* ---- Switch ----
   An on/off control shaped like a switch. The checkbox itself is the control and stays in the page,
   only hidden, so focus, keyboard operation and the reported state are the browser's own. Applying the
   change is left to the form around it (see site.js). */
.portal-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
}

.portal-switch input {
    position: absolute;
    width: 0;
    height: 0;
    opacity: 0;
}

.portal-switch-track {
    position: relative;
    flex: 0 0 auto;
    width: 2.4rem;
    height: 1.3rem;
    border-radius: var(--radius-pill);
    background: var(--surface-3);
    border: 1px solid var(--border-strong);
    transition: background 0.15s ease, border-color 0.15s ease;
}

/* The knob. It sits 0.15rem in from the left, and travels the width of the track less its own
   width and that inset at each end. */
.portal-switch-track::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 0.15rem;
    width: 0.9rem;
    height: 0.9rem;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
    transform: translateY(-50%);
    transition: transform 0.15s ease;
}

.portal-switch input:checked + .portal-switch-track {
    background: var(--success);
    border-color: transparent;
}

.portal-switch input:checked + .portal-switch-track::after {
    transform: translate(1.1rem, -50%);
}

.portal-switch input:focus-visible + .portal-switch-track {
    box-shadow: var(--ring);
}

.portal-switch input:disabled + .portal-switch-track {
    opacity: 0.6;
}

@media (prefers-reduced-motion: reduce) {
    .portal-switch-track,
    .portal-switch-track::after {
        transition: none;
    }
}

/* ---- Badges ---- */
.portal-badge {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    white-space: nowrap;
    gap: 0.35rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-pill);
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 600;
}

.portal-badge.is-on {
    background: var(--success-bg);
    border-color: transparent;
    color: var(--success);
}

.portal-badge.is-off {
    background: var(--surface-2);
    color: var(--faint);
}

.portal-badge.is-error {
    background: var(--danger-bg);
    border-color: transparent;
    color: var(--danger);
}

/* ---- Cards ---- */
.portal-card-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

/* Full-width cards one above another, spaced like the cards in .portal-card-list. */
.portal-card-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* A card's title with its status and actions on the right. The title takes the remaining width and clamps. */
.portal-card-title-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.portal-card-title-row .portal-card-title {
    flex: 1 1 auto;
    min-width: 0;
    margin: 0;
}

.portal-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1.1rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s ease, transform 0.06s ease;
}

.portal-card:hover {
    border-color: var(--border-strong);
}

.portal-card-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text);
}

a.portal-card-title:hover {
    color: var(--accent-2);
    text-decoration: none;
}

/* Clamp long names to 1 line with an ellipsis; pair with a title attribute for the full text on hover. */
.portal-card-title-clamp {
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Whole-card link (e.g. server cards). */
a.portal-card-clickable {
    color: inherit;
    text-decoration: none;
}

a.portal-card-clickable:hover {
    border-color: var(--border-strong);
    text-decoration: none;
}

a.portal-card-clickable:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

a.portal-card-clickable:hover .portal-card-title {
    color: var(--accent-2);
}

.portal-card-sub {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

/* Clamp long text to 3 lines with an ellipsis; pair with a title attribute for the full text on hover. */
.portal-card-sub-clamp {
    overflow-wrap: anywhere;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.portal-card-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    margin-top: auto;
}

/* Icon + name/description header row inside a card. The min-width: 0 on both is load-bearing:
   without it the title/description line clamps stop ellipsising inside the flex row. */
.portal-card-head {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    min-width: 0;
}

/* Reserves the name plus two lines of description, so a connector without one is the same height as a
   connector with one. Cards otherwise stretch to the tallest in their grid row, which left a gap of a
   different size in every card that had no description. */
.portal-card-head-text {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
    min-height: 3.9rem;
}

/* Two lines, to match the space reserved above; three would push past it and grow the card again. */
.portal-card-head-text .portal-card-sub-clamp {
    -webkit-line-clamp: 2;
    line-clamp: 2;
}

/* Actions along the foot of a card, set off from the content and pinned to the bottom so cards of
   different heights still line their actions up. */
.portal-card-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-top: auto;
    padding-top: 0.85rem;
    border-top: 1px solid var(--border);
}

/* Holds the icon actions at the far end of the row, away from the labelled one. */
.portal-card-actions-end {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    margin-left: auto;
}

/* Which connectors a server exposes tools from. Squared off so they don't read as status badges. */
.portal-card-connectors {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.portal-connector-chip {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
}

/* ---- Forms ---- */
.portal-form {
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* A form laid out as one row rather than a column, so it needs more width than the default column. */
.portal-form-wide {
    max-width: 760px;
}

/* Lets a form line up with a table or panel above it rather than sitting in the narrower column a
   form takes by default. */
.portal-form-full {
    max-width: none;
}

/* A single field and its submit sharing a line. Aligned to the bottom so the button sits level with the
   input rather than with the label above it. */
.portal-form-row {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
}

.portal-form-row .portal-field {
    flex: 1;
    min-width: 0;
}

.portal-form-row .portal-button {
    flex: 0 0 auto;
}

.portal-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.portal-field label {
    font-weight: 600;
    font-size: 0.9rem;
}

.portal-field input,
.portal-field textarea,
.portal-field select {
    width: 100%;
    padding: 0.6rem 0.7rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
}

/* Height is worth dragging (JSON, a certificate); width is not. Dragging a textarea wider sets an inline
   width that ignores the layout around it, so it ends up out of line with everything above it. The
   max-width holds even if a browser resizes it some other way. */
.portal-field textarea {
    resize: vertical;
    max-width: 100%;
}

.portal-field input:focus,
.portal-field textarea:focus,
.portal-field select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}

/* A read-only field carries a value the user cannot change (the address their invite was sent to), so it
   reads as settled rather than as an empty box waiting for input, and gains no focus ring when tabbed past. */
.portal-field input[readonly] {
    background: var(--surface-3);
    color: var(--muted);
    cursor: default;
}

.portal-field input[readonly]:focus {
    border-color: var(--border);
    box-shadow: none;
}

/* aria-invalid is set by site.js after a blocked submit; input-validation-error by the input tag helper. */
.portal-field input[aria-invalid="true"],
.portal-field input.input-validation-error {
    border-color: var(--danger);
}

.portal-field input[aria-invalid="true"]:focus,
.portal-field input.input-validation-error:focus {
    box-shadow: var(--danger-ring);
}

.portal-field-inline {
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.portal-field-inline input {
    width: auto;
}

.portal-fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    margin-bottom: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.portal-fieldset legend {
    padding: 0 0.4rem;
    color: var(--muted);
    font-size: 0.85rem;
}

.portal-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
}

/* Flex rather than inline: a line box would sit the switch on a text baseline and leave descender space
   beneath it, so a row holding one would be taller below the switch than above it. The min-height gives
   the switch room above and below, and is tall enough that a small button beside it does not stretch
   the row. */
.portal-inline-form {
    display: inline-flex;
    align-items: center;
    min-height: 2rem;
}

.portal-form-errors {
    color: var(--danger);
    font-size: 0.9rem;
}

.portal-form-errors ul {
    margin: 0;
    padding-left: 1.1rem;
}

.portal-field span.field-validation-error {
    color: var(--danger);
    font-size: 0.85rem;
}

/* A validation span with no message to show is still a flex item, so it claims the field's row gap and
   makes that field taller than one written without a span at all (Email on the profile page). Taking it
   out of the layout keeps every field the same height, which is what lets forms sitting side by side
   line up. A span holding an actual message is not :empty, so it still shows. */
.portal-field > span:empty {
    display: none;
}

/* ---- Notices ---- */
.portal-notice {
    padding: 0.7rem 1rem;
    background: var(--success-bg);
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--success);
    margin-bottom: 1rem;
}

.portal-empty {
    color: var(--muted);
    padding: 1.5rem;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    text-align: center;
}

.portal-warning {
    padding: 0.85rem 1.1rem;
    margin: 1rem 0;
    background: var(--danger-bg);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    color: var(--text);
}

.portal-warning p {
    margin: 0 0 0.5rem;
}

.portal-warning p:last-child {
    margin-bottom: 0;
}

.portal-warning i {
    color: var(--danger);
    margin-right: 0.35rem;
}

.portal-warning ul {
    margin: 0;
    padding-left: 1.4rem;
}

.portal-hint {
    color: var(--faint);
    font-size: 0.8rem;
    margin: 0.35rem 0 0;
}

.portal-hint-intro {
    margin-bottom: 0.5rem;
}

/* Unmet rules only turn red after a blocked submit (is-attempted), not while typing. */
.portal-password-rules {
    display: grid;
    gap: 0.15rem;
    margin: 0.35rem 0 0;
    padding: 0 0 0 0.3rem;
    list-style: none;
    color: var(--faint);
    font-size: 0.75rem;
}

.portal-password-rules i {
    width: 1em;
    margin-right: 0.35rem;
    font-size: 0.85em;
    text-align: center;
}

.portal-password-message {
    margin: 0;
    padding-left: 0.3rem;
    color: var(--faint);
    font-size: 0.75rem;
}

/* Out of the layout rather than display: none, which would drop it from the accessibility tree; a live region
   has to exist before its message arrives to be announced. */
.portal-password-message:empty {
    position: absolute;
}

.portal-password-rules li.is-met,
.portal-password-message.is-met {
    color: var(--success);
}

.portal-password-rules.is-attempted li:not(.is-met),
.portal-password-message.is-unmet {
    color: var(--danger);
}

/* ---- Detail list ---- */
.portal-detail {
    display: grid;
    grid-template-columns: 180px minmax(0, 1fr);
    gap: 0.4rem 1.5rem;
    margin: 1.5rem 0;
    padding: 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

/* Centred like the value beside it: a row is as tall as its value, and a value that is a boxed field
   or a wrapped set of controls is taller than the label's single line. Left to sit at the top of the
   row, the label would then read as if it belonged to the line above. */
.portal-detail dt {
    display: flex;
    align-items: center;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.9rem;
}

.portal-detail dd {
    margin: 0;
    min-width: 0;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
}

/* A note on the row above, in a dd of its own so that row's label stays centred on its controls rather
   than on the controls and the note together. Block rather than flex so the text and its links flow as
   one line, and the grid's row gap spaces it. */
.portal-detail dd.portal-hint {
    grid-column: 2;
    display: block;
}

/* A secret shown in the page but masked until its reveal button is pressed. The text stays in the
   DOM so the copy button still yields the real value while it is hidden. Browsers without
   -webkit-text-security (Firefox before 117) simply show the value, as they did before. */
.portal-secret {
    -webkit-text-security: disc;
}

.portal-secret.is-revealed {
    -webkit-text-security: none;
}

/* A read-only value shaped like a form field, with its actions inline against the right edge. Padding
   and height match .portal-field input so a page mixing the two reads as one set of controls. */
.portal-copy-field {
    display: flex;
    align-items: center;
    gap: 0.15rem;
    flex: 1;
    min-width: 0;
    min-height: 2.75rem;
    padding: 0.25rem 0.3rem 0.25rem 0.7rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* The field is the box, so the value inside it drops the chrome base.css gives a bare <code>. A value
   too long for the row is truncated rather than wrapped: pair it with a title attribute for the full
   text on hover, and note the copy button reads the element's text rather than what is rendered, so it
   still yields the whole value. */
.portal-copy-field code {
    flex: 1;
    min-width: 0;
    padding: 0;
    background: none;
    border: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Outside a detail row or a form field the box has no column to fill, so it is held to the width of
   the form controls it sits with (.portal-form). */
.portal-copy-field-standalone {
    max-width: 520px;
    margin-bottom: 1rem;
}

/* An action reduced to its icon, for sitting inside a field without crowding the value. */
.portal-icon-button {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.9rem;
    height: 1.9rem;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: none;
    color: var(--faint);
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease;
}

.portal-icon-button:hover {
    background: var(--surface-3);
    color: var(--text);
}

/* A destructive icon action: neutral until pointed at, rather than shouting from the card. */
.portal-icon-button-danger:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.portal-icon-button:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.portal-tool-list {
    margin: 0.4rem 0 0;
    padding-left: 1.2rem;
    color: var(--muted);
}

.portal-tool-list li {
    margin: 0.15rem 0;
}

/* ---- Tools editor (split layout) ---- */
.portal-split {
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 1.5rem;
}

/* Below the sidebar breakpoint the fixed connector column leaves the tool list too little room. */
@media (max-width: 820px) {
    .portal-split {
        grid-template-columns: 1fr;
    }
}

.portal-aside {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
}

.portal-aside-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.portal-aside-head h2 {
    margin: 0;
}

.portal-aside-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.portal-aside-list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
}

.portal-aside-list li.is-active {
    background: var(--surface-3);
}

/* Clamped to two lines rather than one: the aside is only 280px wide, and connectors sharing a prefix
   are indistinguishable from the first line alone. The count badge beside it keeps its place either way.
   Pair with a title attribute for the full name on hover. */
.portal-aside-list li a {
    flex: 1;
    min-width: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
    color: var(--text);
}

.portal-tools-edit {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.2rem;
}

/* Methods grouped into collapsible categories */
.portal-method-groups {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-bottom: 1.2rem;
    max-height: 520px;
    overflow-y: auto;
}

.portal-method-group {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
}

.portal-method-group > summary {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    cursor: pointer;
    font-weight: 600;
    list-style: none;
    user-select: none;
}

.portal-method-group > summary::-webkit-details-marker {
    display: none;
}

.portal-method-group > summary::before {
    content: "\25B8"; /* ▸ */
    color: var(--muted);
    font-size: 0.85rem;
    transition: transform 0.15s ease;
}

.portal-method-group[open] > summary::before {
    transform: rotate(90deg);
}

.portal-method-group-name {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.portal-method-list {
    list-style: none;
    margin: 0;
    padding: 0.2rem 0.5rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

/* Wraps so the optional hint can take a line of its own beneath the tool name. */
.portal-method {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.portal-method label {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
}

.portal-method label:hover {
    background: var(--surface-2);
}

.portal-method-name {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.portal-method-cat {
    color: var(--faint);
    font-size: 0.8rem;
}

.portal-method-test {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-pill);
    color: var(--accent-2);
    font-size: 0.8rem;
    font-weight: 600;
}

.portal-method-test:hover {
    background: var(--surface-2);
    text-decoration: none;
}

/* Takes the full width of the row, indented to line up with the tool name rather than the
   checkbox, so a group of tools still scans down its names. */
/* Shrinkable, because the 100% basis is measured before the margins are added — without it the
   field runs past the right edge of the group by exactly the width of its own margins.
   min-width overrides the intrinsic width an input carries, which would block the shrink. */
.portal-method-hint {
    flex: 1 1 100%;
    min-width: 0;
    margin: 0 0.6rem 0.25rem 2rem;
    padding: 0.3rem 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    font-size: 0.8rem;
    transition: border-color 0.2s ease, background 0.2s ease;
}

.portal-method-hint::placeholder {
    color: var(--faint);
}

/* Brief acknowledgement that an edit saved. The checkboxes don't need one — their own state is
   the confirmation — but a text field gives nothing back. */
.portal-method-hint.is-saved {
    border-color: var(--success);
    background: var(--success-bg);
}

.portal-method-hint:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}

/* ---- Test tool ---- */

/* Column widths for the tool test arguments table. The name column carries two lines of its own
   (display name over key), so it is given room rather than squeezing them; the description column has
   no width and takes the remainder. */
.portal-col-arg-name {
    width: 15rem;
}

.portal-col-arg-type {
    width: 6rem;
}

.portal-col-arg-required {
    width: 7rem;
}

/* The connector's label for an argument, above the key a caller actually sends. */
.portal-arg-name {
    font-weight: 600;
    margin-bottom: 0.2rem;
}

/* The values an argument accepts, listed under its description. */
.portal-arg-values {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin-top: 0.4rem;
}

.portal-code-input {
    font-family: "Cascadia Code", "Consolas", ui-monospace, monospace;
    font-size: 0.85rem;
}

.portal-test-result {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.portal-test-response {
    margin: 0;
    padding: 0.7rem 0.8rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 360px;
    overflow: auto;
    font-family: "Cascadia Code", "Consolas", ui-monospace, monospace;
    font-size: 0.8rem;
}

/* ---- Rendered payloads ----
   Request/response bodies are highlighted by Prism and folded by site.js. The server renders
   the raw text in the <pre>; everything below only applies once site.js has enhanced it, so
   without scripting the payload still reads as plain text. */
.portal-code {
    position: relative;
}

/* Sits over the top-right of the payload, out of the way until the panel is hovered. */
.portal-code-copy {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    z-index: 1;
    padding: 0.15rem 0.5rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--muted);
    font-size: 0.7rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.portal-code:hover .portal-code-copy,
.portal-code-copy:focus-visible {
    opacity: 1;
}

/* Everything here stays inline: the <pre>'s own newlines lay the lines out, so a fold only needs
   elements around the parts it has to hide. */

/* Chevron closing a foldable line, e.g. the `"items": [` that opens an array. */
.portal-code-toggle {
    margin-left: 0.4rem;
    padding: 0;
    border: 0;
    background: none;
    color: var(--faint);
    font: inherit;
    cursor: pointer;
}

.portal-code-toggle:hover {
    color: var(--accent);
}

.portal-code-ellipsis {
    display: none;
    color: var(--faint);
}

.portal-code-fold.is-collapsed > .portal-code-nest,
.portal-code-fold.is-collapsed > .portal-code-close {
    display: none;
}

.portal-code-fold.is-collapsed > .portal-code-ellipsis {
    display: inline;
}

/* Prism token map. Only the tokens these payloads actually produce are listed: JSON bodies,
   HTTP request lines and headers, and XML/HTML bodies. */
.portal-code .token.property,
.portal-code .token.keyword,
.portal-code .token.header-name,
.portal-code .token.tag {
    color: var(--code-key);
}

.portal-code .token.string,
.portal-code .token.header-value,
.portal-code .token.attr-value {
    color: var(--code-string);
}

.portal-code .token.number,
.portal-code .token.boolean,
.portal-code .token.null,
.portal-code .token.attr-name {
    color: var(--code-number);
}

.portal-code .token.url,
.portal-code .token.request-target {
    color: var(--code-url);
}

.portal-code .token.method,
.portal-code .token.http-version {
    color: var(--code-key);
    font-weight: 600;
}

.portal-code .token.punctuation,
.portal-code .token.operator {
    color: var(--code-punct);
}

/* ---- Auth card ---- */
.portal-auth {
    max-width: 420px;
    margin: 3rem auto;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.portal-auth h1 {
    text-align: center;
    margin-bottom: 1.5rem;
}

.portal-auth-logo {
    display: block;
    width: 260px;
    max-width: 100%;
    height: auto;
    margin: 0 auto 1.5rem;
}

/* Views/Shared/_AuthBrand.cshtml emits both variants; only the one matching the theme is shown.
   display: none also keeps the hidden one out of the accessibility tree. */
.portal-auth-logo-dark {
    display: none;
}

[data-theme="dark"] .portal-auth-logo-light {
    display: none;
}

[data-theme="dark"] .portal-auth-logo-dark {
    display: block;
}

.portal-auth-alt {
    margin-top: 1.25rem;
    text-align: center;
    color: var(--muted);
}

/* ---- Filter bar / search ---- */
.portal-filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.portal-search {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    max-width: 420px;
    padding: 0.5rem 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.portal-search:focus-within {
    border-color: var(--accent);
    box-shadow: var(--ring);
}

.portal-search i {
    color: var(--muted);
}

.portal-search input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font: inherit;
}

.portal-search input:focus {
    outline: none;
}

/* Pinned to the end of the bar, so the controls before it never shift when it appears.
   Overrides .portal-link's smaller size to sit level with the controls it follows. */
.portal-filter-clear {
    margin-left: auto;
    font-size: inherit;
}

/* Compact dropdown for the filter bar; .portal-field select is a full-width block control.
   Padding and font match .portal-search so every control on the bar is the same height. */
.portal-filter-select {
    /* A connector name can be long enough to stretch the select past the page; cap it and let the
       full name show when the list is open. */
    max-width: min(100%, 22rem);
    padding: 0.5rem 0.75rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
}

.portal-filter-select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}

/* ---- Tag / category chips ---- */
.portal-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1.5rem;
}

.portal-tag {
    padding: 0.35rem 0.75rem;
    border-radius: var(--radius-pill);
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
}

.portal-tag:hover {
    color: var(--text);
    border-color: var(--border-strong);
    text-decoration: none;
}

.portal-tag.is-active {
    background: var(--accent-grad);
    border-color: transparent;
    color: var(--on-accent);
}

/* ---- Connector cards with thumbnails ---- */
.portal-connector-card {
    padding: 0;
}

.portal-connector-link {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 1rem 1.1rem;
    color: var(--text);
}

.portal-connector-link:hover {
    text-decoration: none;
}

.portal-connector-icon {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 9px;
    background: var(--icon-chip-bg);
    object-fit: contain;
    padding: 4px;
    box-shadow: inset 0 0 0 1px var(--icon-chip-ring);
}

.portal-connector-text {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.portal-connector-text .portal-card-title,
.portal-connector-text .portal-card-sub {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Date/time filter inputs (filter bar, enhanced by flatpickr) ---- */
.portal-datetime {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--muted);
    font-size: 0.85rem;
    white-space: nowrap;
}

.portal-datetime-input {
    padding: 0.45rem 0.55rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    min-width: 9.5rem;
}

.portal-datetime-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}

/* Theme the flatpickr popup for dark mode using our tokens (light mode uses flatpickr defaults). */
[data-theme="dark"] .flatpickr-calendar {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    color: var(--text);
}

[data-theme="dark"] .flatpickr-calendar.arrowTop::before,
[data-theme="dark"] .flatpickr-calendar.arrowTop::after {
    border-bottom-color: var(--surface);
}

[data-theme="dark"] .flatpickr-calendar.arrowBottom::before,
[data-theme="dark"] .flatpickr-calendar.arrowBottom::after {
    border-top-color: var(--surface);
}

[data-theme="dark"] .flatpickr-months .flatpickr-month,
[data-theme="dark"] .flatpickr-current-month .flatpickr-monthDropdown-months,
[data-theme="dark"] .flatpickr-weekday {
    color: var(--text);
    fill: var(--text);
}

[data-theme="dark"] .flatpickr-months .flatpickr-prev-month svg,
[data-theme="dark"] .flatpickr-months .flatpickr-next-month svg {
    fill: var(--text);
}

[data-theme="dark"] .flatpickr-day {
    color: var(--text);
}

[data-theme="dark"] .flatpickr-day:hover,
[data-theme="dark"] .flatpickr-day:focus {
    background: var(--surface-3);
    border-color: var(--surface-3);
}

[data-theme="dark"] .flatpickr-day.flatpickr-disabled,
[data-theme="dark"] .flatpickr-day.prevMonthDay,
[data-theme="dark"] .flatpickr-day.nextMonthDay {
    color: var(--faint);
}

[data-theme="dark"] .flatpickr-day.selected,
[data-theme="dark"] .flatpickr-day.selected:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

[data-theme="dark"] .flatpickr-time input,
[data-theme="dark"] .flatpickr-time .flatpickr-time-separator,
[data-theme="dark"] .flatpickr-time .flatpickr-am-pm {
    color: var(--text);
}

[data-theme="dark"] .flatpickr-time input:hover,
[data-theme="dark"] .flatpickr-time input:focus,
[data-theme="dark"] .flatpickr-time .flatpickr-am-pm:hover {
    background: var(--surface-2);
}

[data-theme="dark"] .flatpickr-time,
[data-theme="dark"] .flatpickr-innerContainer {
    border-color: var(--border);
}

/* ---- Transactions table ---- */
.portal-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.portal-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

/* Fixed layout so expanding a detail row can't recalculate (shift) the columns. */
.portal-table-expandable {
    table-layout: fixed;
}

.portal-col-toggle {
    width: 2.75rem;
}

.portal-col-when {
    width: 230px;
}

.portal-col-status {
    width: 120px;
}

/* Descriptions and payloads can be long free text: wrap them in the cell rather than let them widen
   the table, which would push the trailing action column out of view behind .portal-table-wrap's
   horizontal scroll. Columns that must stay on one line opt out with .portal-nowrap. */
.portal-table th,
.portal-table td {
    overflow-wrap: anywhere;
    text-align: left;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.portal-table thead th {
    background: var(--surface-2);
    color: var(--muted);
    font-weight: 600;
    white-space: nowrap;
}

.portal-table tbody tr:last-child td {
    border-bottom: none;
}

.portal-table tbody tr:hover {
    background: var(--surface-2);
}

/* The trailing column of a table that holds only row actions: no header, sized to its icons and
   aligned to the table edge. */
.portal-table-actions {
    width: 3rem;
    text-align: right;
}

.portal-nowrap {
    white-space: nowrap;
}

/* Expandable rows */
.portal-tx-toggle-col {
    text-align: center;
}

.portal-tx-row {
    cursor: pointer;
}

.portal-tx-row:focus-visible {
    outline: none;
    box-shadow: inset var(--ring);
}

.portal-tx-chevron {
    color: var(--faint);
    transition: transform 0.15s ease;
}

.portal-tx-row.is-open .portal-tx-chevron {
    transform: rotate(90deg);
    color: var(--accent);
}

.portal-tx-row.is-open {
    background: var(--surface-2);
}

.portal-tx-detail-row td {
    background: var(--surface-2);
}

.portal-tx-detail-row[hidden] {
    display: none;
}

.portal-tx-body {
    margin: 0;
}

.portal-tx-body h4 {
    margin: 0.5rem 0 0.25rem;
    font-size: 0.8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.portal-tx-body pre {
    margin: 0;
    padding: 0.6rem 0.7rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 320px;
    overflow: auto;
    font-family: "Cascadia Code", "Consolas", ui-monospace, monospace;
    font-size: 0.8rem;
}

/* Placeholder for content that hasn't arrived yet, shaped like the thing it stands in for:
   the fetched transaction detail, or the result of a tool test. It stays invisible for the
   first moment, so a fast load goes straight to the real content without a flash; only a slow
   one fades up and starts pulsing. */
.portal-skeleton {
    opacity: 0;
    animation: portal-skeleton-in 0.35s ease-out 0.45s forwards;
}

.portal-skeleton pre {
    height: 2.5rem;
    background: var(--border);
    border-color: transparent;
    animation: portal-skeleton-pulse 1.6s ease-in-out 0.45s infinite;
}

/* The response is the larger of the two fields, so reserve more for it and the content has
   less distance to travel when it arrives. */
.portal-skeleton pre:last-of-type {
    height: 6rem;
}

@keyframes portal-skeleton-in {
    to {
        opacity: 1;
    }
}

@keyframes portal-skeleton-pulse {
    50% {
        opacity: 0.45;
    }
}

/* Loaded content eases in rather than snapping, so a fast fetch reads as a transition instead
   of a flash. site.js sets data-loaded once the partial is in place. */
[data-loaded="true"] {
    animation: portal-content-in 0.25s ease-out;
}

@keyframes portal-content-in {
    from {
        opacity: 0;
        transform: translateY(-2px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .portal-skeleton,
    .portal-skeleton pre,
    [data-loaded="true"] {
        animation: none;
        opacity: 1;
    }
}

/* Failure state, in place of the content that couldn't be loaded */
.portal-inline-error {
    margin: 0;
    padding: 0.6rem 0;
    color: var(--muted);
    font-size: 0.85rem;
}

.portal-tx-retry {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent-2);
    font: inherit;
    text-decoration: underline;
    cursor: pointer;
}

/* ---- Pager ---- */
.portal-pager {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.portal-pager-info {
    color: var(--muted);
    font-size: 0.9rem;
}

/* ---- Dashboard ---- */
.portal-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.portal-stat {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: 1.1rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.portal-stat-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
}

.portal-stat-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-weight: 600;
    color: var(--text);
}

.portal-stat-label i {
    color: var(--accent);
}

.portal-stat-sub {
    color: var(--faint);
    font-size: 0.85rem;
}

.portal-dashboard-cols {
    display: grid;
    /* minmax(0, ...) rather than a bare 1fr: an auto-sized track grows to its content, so one long
       server name in either column would push the page into horizontal scroll. */
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 1.5rem;
}

@media (max-width: 820px) {
    .portal-dashboard-cols {
        grid-template-columns: 1fr;
    }
}

.portal-activity-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.portal-activity-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.portal-activity-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* min-width: 0 is what lets the ellipsis fire. A nowrap flex item otherwise refuses to shrink
   below its text and pushes the timestamp off the row. */
.portal-activity-server {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.portal-activity-time {
    flex: 0 0 auto;
    margin-left: auto;
    color: var(--faint);
    font-size: 0.85rem;
    white-space: nowrap;
}

/* ---- Configure connector page ---- */

/* Page heading with icon chip + breadcrumb */
.configure-heading {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
}

/* The breadcrumb/name column, so the clamped h1 inside it can shrink. */
.configure-heading > div {
    min-width: 0;
}

.configure-breadcrumb {
    margin: 0 0 0.1rem;
    font-size: 0.78rem;
    color: var(--faint);
}

.configure-heading h1 {
    margin: 0;
    font-size: 1.4rem;
}

/* Step indicator */
.configure-steps {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    font-size: 0.82rem;
    color: var(--faint);
}

.configure-step {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.configure-step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: var(--radius-pill);
    border: 1.5px solid var(--border-strong);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
}

.configure-step.is-active {
    color: var(--accent);
    font-weight: 600;
}

.configure-step.is-active .configure-step-num {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.configure-step-divider {
    color: var(--border-strong);
    font-size: 0.65rem;
}

/* Form card wrapper */
.configure-form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.75rem 2rem;
}

/* Optional field label modifier */
.configure-optional {
    color: var(--faint);
    font-weight: 400;
    font-size: 0.8em;
}

/* Single auth-method badge */
.configure-auth-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    color: var(--muted);
}

.configure-auth-badge i {
    color: var(--accent);
}

/* Auth description info box */
.configure-auth-desc {
    display: flex;
    gap: 0.6rem;
    padding: 0.7rem 1rem;
    margin-bottom: 0.5rem;
    background: rgba(124, 92, 255, 0.07);
    border: 1px solid rgba(124, 92, 255, 0.2);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    color: var(--text);
    line-height: 1.5;
}

.configure-auth-desc i {
    color: var(--accent);
    flex-shrink: 0;
    margin-top: 0.15rem;
}

.configure-auth-desc a {
    color: var(--accent-2);
}

/* Fields region loading state */
.configure-fields-region {
    transition: opacity 0.15s ease;
}

.configure-fields-region.is-loading {
    opacity: 0.4;
    pointer-events: none;
}

/* Actions row separator */
.configure-actions {
    border-top: 1px solid var(--border);
    padding-top: 1.25rem;
    margin-top: 0.5rem;
}

/* Icon spacing inside fieldset legends */
.portal-fieldset legend i {
    margin-right: 0.3rem;
    opacity: 0.7;
}

/* Password reveal toggle */
.configure-password-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.configure-password-wrap input {
    padding-right: 2.4rem;
}

.configure-reveal {
    position: absolute;
    right: 0.55rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--faint);
    padding: 0.2rem;
    line-height: 1;
    font-size: 0.9rem;
    transition: color 0.12s ease;
}

.configure-reveal:hover {
    color: var(--muted);
}

/* ---- Utilities ---- */
.is-hidden {
    display: none !important;
}

/* The destructive action at the foot of a page, set off from the content above it. Not for a
   delete button inside a row or a card, where the margin and rule only read as a divider at the end. */
.portal-danger-form {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}
