/* ============================================================
   Components & app shell — the new UI vocabulary.
   Ported/adapted from the RpsCRM design system. Loaded AFTER
   tokens.css and the legacy site.css so it wins on shared
   selectors during the migration.
   ============================================================ */

/* ---- Base ---- */
/* Global border-box reset. Bootstrap's Reboot used to provide this; now that
   the Bootstrap CDN is gone we own it. The whole design (fixed-width sidebar,
   width:100% inputs with padding, the grid compat layer) assumes border-box,
   so widths must include padding + border. */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    display: block;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

a {
    color: var(--brand);
    text-decoration: none;
}
a:hover {
    text-decoration: underline;
}

/* ---- Page layout ---- */
.page {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;                 /* fill the space beside the sidebar — no fixed offset */
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.page-content {
    padding: 24px;
    flex: 1;
}

/* ---- Sidebar ---- */
.sidebar {
    width: 220px;
    flex-shrink: 0;          /* hold its width; .main-content flexes to fill the rest */
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    padding: 20px 16px 8px;
    position: sticky;        /* in-flow so content sits beside it; sticks on scroll */
    top: 0;
    align-self: flex-start;
    height: 100vh;
    z-index: 100;
    overflow-y: hidden;
    transition: width 0.2s, padding 0.2s;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.sidebar-logo {
    display: block;
    height: 40px;
    width: auto;
    max-width: 100%;
}

.sidebar-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 14px 0;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.sidebar-nav a,
.sidebar-bottom a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13.5px;
    color: var(--sidebar-text);
    text-decoration: none;
    transition: background 0.15s;
}
.sidebar-nav a:hover,
.sidebar-bottom a:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text);
    text-decoration: none;
}
.sidebar-nav a.active,
.sidebar-bottom a.active {
    background: var(--sidebar-active);
    color: #fff;
}
.sidebar-nav svg,
.sidebar-bottom svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.nav-group {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 10px;
}

.nav-group-label {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--sidebar-muted);
    padding: 8px 12px 2px;
    user-select: none;
}

.sidebar-bottom {
    margin-top: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-top: 8px;
}

.sidebar-version {
    font-size: 0.68rem;
    color: var(--sidebar-muted);
    padding: 8px 12px 0;
    user-select: none;
    word-break: break-word;
}

/* ---- Anonymous (logged-out) top bar ---- */
.anon-topbar {
    background: var(--sidebar-bg);
    padding: 14px 24px;
    display: flex;
    align-items: center;
}
.anon-topbar img {
    height: 44px;
    width: auto;
}

/* ---- Page header / toolbar ---- */
.page-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    align-items: center;
    padding: 20px 24px 18px;
    margin: -24px -24px 0;
    background: var(--card);
    border-bottom: 1px solid var(--border);
}
.page-header h1 {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.4px;
    color: var(--text);
    margin: 0;
}
.page-header .muted {
    margin: 2px 0 0;
}

.page-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 20px;
    margin-bottom: 12px;
}
.page-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-left: auto;
    flex-shrink: 0;
}

/* ---- Cards ---- */
.card {
    display: block; /* override Bootstrap's .card flex so standalone buttons don't stretch */
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    box-shadow: var(--shadow-sm);
}
.card h2 {
    margin: 0 0 10px 0;
    font-size: 18px;
}

/* ---- Buttons ---- */
.btn {
    display: inline-block;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    font-weight: 700;
    color: var(--text);
    text-decoration: none;
}
button.btn {
    cursor: pointer;
    font-family: inherit;
}
button.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.btn.primary,
.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}
.btn.primary:hover,
.btn-primary:hover {
    background: var(--brand-hover);
    border-color: var(--brand-hover);
    color: #fff;
}
.btn-add {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--brand);
    border: 1px solid var(--brand);
    color: #fff;
    font-weight: 700;
    border-radius: 10px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13.5px;
    white-space: nowrap;
    transition: background 0.15s, box-shadow 0.15s;
    box-shadow: 0 1px 4px rgba(227,6,19,0.25);
}
.btn-add:hover {
    background: var(--brand-hover);
    border-color: var(--brand-hover);
    box-shadow: 0 2px 8px rgba(227,6,19,0.3);
    text-decoration: none;
    color: #fff;
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

/* ---- Flash / alert banners (token-driven, replaces legacy palette) ---- */
.app-alert {
    position: relative;
    padding: 14px 44px 14px 16px;
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: 10px;
    margin: 16px 24px 0;
    background: var(--card);
    box-shadow: var(--shadow-sm);
    font-weight: 500;
    transition: opacity 0.4s;
}
.app-alert--success { border-left-color: #16a34a; }
.app-alert--danger  { border-left-color: var(--brand); }
.app-alert--warning { border-left-color: #d97706; }
.app-alert--info    { border-left-color: #2563eb; }
.app-alert .closebtn {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 20px;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
}
.app-alert .closebtn:hover {
    color: var(--text);
}

/* ---- Footer (overrides legacy `footer` element styling in site.css) ---- */
.app-footer {
    background: transparent;
    color: inherit;
    flex-shrink: 0;
}
.app-footer a {
    color: var(--muted);
    text-decoration: underline;
}
.app-footer a:hover {
    color: var(--text);
}

/* ============================================================
   PHASE 2 — shared component vocabulary
   All additive / non-colliding so Bootstrap (still loaded) keeps
   styling un-migrated pages. Migrated pages (Phase 3) opt in to
   these classes; form element styling is scoped under .data-form.
   ============================================================ */

/* ---- Buttons: secondary / danger / icon / small ---- */
.btn.secondary,
.btn-secondary-ui {
    background: var(--card);
    border-color: var(--border);
    color: var(--text);
}
.btn.secondary:hover,
.btn-secondary-ui:hover {
    background: var(--bg);
    text-decoration: none;
    color: var(--text);
}
.btn.danger {
    border-color: rgba(227,6,19,0.35);
    color: var(--brand);
    background: var(--card);
}
.btn.danger:hover {
    background: rgba(227,6,19,0.08);
    text-decoration: none;
    color: var(--brand);
}
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
}
.btn.btn-icon {
    border-color: transparent;
    background: transparent;
}
.btn.btn-icon:hover {
    background: var(--bg);
    border-color: transparent;
    text-decoration: none;
}
.btn-sm {
    padding: 5px 10px;
    font-size: 12.5px;
    border-radius: 8px;
}

/* ---- Pills & status badges (generic, semantic) ---- */
.pill {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    background: rgba(227,6,19,0.12);
    color: var(--brand);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11.5px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
    white-space: nowrap;
    letter-spacing: 0.02em;
}
.status-badge--neutral { background: #F1EFE8; color: #444441; }
.status-badge--info    { background: #EEF3FD; color: #2C4F8A; }
.status-badge--success { background: #EAF3DE; color: #27500A; }
.status-badge--warning { background: #FEF3C7; color: #92400E; }
.status-badge--danger  { background: #FDE8E8; color: #7C0C0C; }

/* ---- Data table ---- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}
.data-table thead tr {
    border-bottom: 2px solid var(--border);
    text-align: left;
}
.data-table th {
    padding: 9px 14px;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    background: var(--bg);
}
.data-table td {
    padding: 11px 14px;
    font-size: 13.5px;
    overflow-wrap: anywhere;
}
.data-table tbody tr {
    border-bottom: 1px solid var(--border);
}
.data-table tbody tr.clickable {
    cursor: pointer;
}
.data-table tbody tr.clickable:hover {
    background: var(--bg);
}
.data-table .col-actions {
    text-align: right;
    white-space: nowrap;
}
.data-table .col-actions-inner {
    display: flex;
    gap: 4px;
    justify-content: flex-end;
}
.data-table .col-nowrap { white-space: nowrap; }
.data-table .col-bold { font-weight: 700; }
.col-truncate {
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

/* ---- Forms (scoped to .data-form so Bootstrap pages are untouched) ---- */
.data-form label {
    display: block;
    font-weight: 700;
    margin: 0 0 6px 0;
    color: var(--text);
}
.data-form input[type="text"],
.data-form input[type="email"],
.data-form input[type="url"],
.data-form input[type="tel"],
.data-form input[type="number"],
.data-form input[type="password"],
.data-form input[type="search"],
.data-form input[type="date"],
.data-form input[type="datetime-local"],
.data-form select,
.data-form textarea {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font: inherit;
    outline: none;
}
.data-form textarea {
    min-height: 110px;
    resize: vertical;
}
.data-form input:focus,
.data-form select:focus,
.data-form textarea:focus {
    border-color: rgba(227,6,19,0.55);
    box-shadow: 0 0 0 4px rgba(227,6,19,0.12);
}
.data-form .form-row {
    margin-bottom: 12px;
}
.data-form .cols-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
/* Town/city beside the two short codes that follow it (US state and ZIP). */
.data-form .cols-town {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 12px;
}
@media (max-width: 640px) {
    .data-form .cols-2 { grid-template-columns: 1fr; }
    .data-form .cols-town { grid-template-columns: 1fr; }
}
.form-hint {
    font-size: 12px;
    color: var(--muted);
    margin-top: 4px;
}

/* ---- Search input used in page toolbars ---- */
.toolbar-search {
    width: 280px;
    max-width: 100%;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font: inherit;
    outline: none;
}
.toolbar-search:focus {
    border-color: rgba(227,6,19,0.55);
    box-shadow: 0 0 0 4px rgba(227,6,19,0.12);
}

/* ---- Modal body section headings (multi-part forms, e.g. Add Licence) ---- */
.modal-section + .modal-section,
.modal-section + hr {
    margin-top: 14px;
}
.modal-section h5 {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}
.modal-section > .muted {
    display: block;
    margin-bottom: 10px;
}

/* ---- Modal (native <dialog>, namespaced to avoid Bootstrap collision) ---- */
dialog.app-modal {
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--modal-bg);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    width: 500px;
    max-width: 95vw;
    overflow: hidden;
    /* Reset inherited text-align/white-space: a <dialog> stays a DOM child of
       its trigger's cell, so a <confirm> emitted inside td.col-actions (right,
       nowrap) would otherwise render right-aligned and refuse to wrap. */
    text-align: left;
    white-space: normal;
}
dialog.app-modal.app-modal--wide { width: 640px; }
dialog.app-modal.app-modal--narrow { width: 420px; }
dialog.app-modal::backdrop {
    background: var(--backdrop);
}
.app-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
}
.app-modal__header h3,
.app-modal__header h4,
.app-modal__header h5 {
    margin: 0;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: -0.2px;
}
.app-modal__close {
    background: none;
    border: none;
    font-size: 1.4em;
    line-height: 1;
    cursor: pointer;
    color: var(--muted);
    padding: 2px 8px;
    border-radius: 8px;
}
.app-modal__close:hover {
    background: var(--bg);
    color: var(--text);
}
.app-modal__body {
    padding: 20px 24px;
}
.app-modal__footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 14px 24px;
    background: var(--bg);
    border-top: 1px solid var(--border);
}

/* ---- Tabs (wraps Bootstrap-driven tab JS; scoped to .app-tabs) ---- */
.app-tabs .nav-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    list-style: none;
    margin: 0;
    padding: 0;
    border-bottom: 1px solid var(--border);
}
.app-tabs .nav-item { margin: 0; }
.app-tabs .nav-link {
    display: block;
    padding: 9px 16px;
    border: none;
    border-bottom: 2px solid transparent;
    background: none;
    color: var(--muted);
    font-weight: 700;
    font-size: 13.5px;
    cursor: pointer;
    border-radius: 8px 8px 0 0;
}
.app-tabs .nav-link:hover {
    color: var(--text);
    text-decoration: none;
    background: var(--bg);
}
/* The brand underline already marks the selection, so the label only needs to darken from
 * muted to full-strength text rather than turn red as well. */
.app-tabs .nav-link.active {
    color: var(--text);
    border-bottom-color: var(--brand);
    background: none;
}
.app-tabs .tab-content {
    padding-top: 20px;
}

/* Payment method tabs carry a scheme logo alongside the label, and step down through three
 * arrangements as space runs out: one row of four, then a 2x2 grid, then a single column.
 *
 * Growing without shrinking is what makes the step-down work — a tab is never squeezed below
 * its label, so the row wraps instead, and whichever tabs share a row stretch to fill it. */
.payment-tabs .nav-tabs { gap: 0; }
.payment-tabs .nav-item {
    flex: 1 0 auto;
    display: flex;
}
.payment-tabs .nav-link {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 10px;
    white-space: nowrap;
}
.payment-tabs .nav-link img {
    height: 15px;
    width: auto;
}
/* The four labels need about 610px side by side. The payment card is half the page, so the
 * strip measures roughly (viewport / 2 - 62) — putting the point where the fourth tab no
 * longer fits at around 1350px of viewport. Below that, a 45% basis admits two tabs per row
 * but never three, so they fall into a balanced 2x2 rather than an odd 3+1. */
@media (max-width: 1350px) {
    .payment-tabs .nav-item { flex-basis: 45%; }
}
/* Narrower still and even two abreast stops working: the widest pair (SEPA + ACH) needs about
 * 375px, which the strip drops below at roughly 880px of viewport. Left at a 45% basis the
 * four would straggle into 2+1+1, so stack them into a single column instead. This covers
 * phones, where the two cards stack and the strip is narrower again. */
@media (max-width: 880px) {
    .payment-tabs .nav-item { flex-basis: 100%; }
}

/* ---- Recurly hosted card field ----
 * Recurly draws the card number / expiry / CVV inside a cross-origin iframe, so only the
 * wrapper it injects can be styled from here; the text inside it is styled through the
 * CardElement "style" options in recurlyops.js. These rules restate the sibling input
 * appearance so the hosted field does not read as a foreign control. recurly.css loads after
 * our stylesheet, hence the !important on the properties it sets on .recurly-element.
 *
 * The height is fixed because the iframe sizes to its container, so the wrapper cannot be
 * padded into shape the way a real input can. It is the height an input resolves to from
 * 10px/1px of padding/border around a 21px line box — keep the two in step. */
.data-form .recurly-element {
    height: 43px !important;
    padding: 0 12px !important;
    border: 1px solid var(--border) !important;
    border-radius: 12px !important;
    background: var(--input-bg) !important;
    box-shadow: none !important;
}
.data-form .recurly-element-focus {
    border-color: rgba(227,6,19,0.55) !important;
    box-shadow: 0 0 0 4px rgba(227,6,19,0.12) !important;
}
.data-form .recurly-element-invalid {
    border-color: rgba(227,6,19,0.55) !important;
}

/* ---- Key/value detail list (definition-style rows in a card) ---- */
.detail-list {
    width: 100%;
    border-collapse: collapse;
}
.detail-list td {
    padding: 8px 0;
    font-size: 13.5px;
    vertical-align: top;
    border-bottom: 1px solid var(--border);
}
.detail-list tr:last-child td { border-bottom: none; }
.detail-list td:first-child {
    color: var(--muted);
    width: 220px;
    padding-right: 16px;
}
.detail-list td:last-child { font-weight: 600; }

/* ---- Collapsible card (<details class="card app-details">) ---- */
details.app-details > summary {
    cursor: pointer;
    font-size: 18px;
    font-weight: 700;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
details.app-details > summary::-webkit-details-marker { display: none; }
details.app-details > summary::before {
    content: "▸";
    color: var(--muted);
    font-size: 13px;
    transition: transform 0.15s;
}
details.app-details[open] > summary::before {
    transform: rotate(90deg);
}

/* ---- Card grid (plan/pricing cards, etc.) ---- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.card.is-current {
    border-color: var(--brand);
    box-shadow: 0 0 0 1px var(--brand), var(--shadow-sm);
}
.plan-price {
    margin: 10px 0;
    padding: 10px 0;
    border-top: 1px solid var(--border);
}
.plan-price:first-of-type { border-top: none; }
.plan-price h4 { margin: 0 0 4px; font-size: 14px; }

/* ---- Tag chips (removable) ---- */
.tag-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.tag-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
    background: rgba(227,6,19,0.12);
    color: var(--brand);
}
.tag-chip input[type="submit"] {
    background: none;
    border: none;
    color: var(--brand);
    cursor: pointer;
    font-weight: 700;
    padding: 0;
    line-height: 1;
    font-size: 14px;
}

/* ============================================================
   PHASE 3 END — Bootstrap-compat layer
   Reproduces the Bootstrap 5 CSS for the markup shapes that
   remain in the app after the Bootstrap CDN is dropped (collapse,
   accordion, tab panes, dropdowns, modals, input-group, the
   form-control/select/check inputs, and the grid + utility
   classes still used by Admin/Products). Paired with the vanilla
   behaviour shim in ui.js. Everything here is additive and keyed
   on the existing Bootstrap class names, so no page markup changes
   are needed.

   CRITICAL: `.collapse` / `.collapse.show` and `.tab-pane.show`
   reproduce Bootstrap's show/hide exactly. recurlyops.js
   findActivePanel() picks the payment panel to tokenise by the `show`
   class on a known panel id, whether that panel is a collapse
   (ChangePaymentDetails) or a tab pane (Subscribe).
   ============================================================ */

/* ---- Collapse ---- */
.collapse:not(.show) { display: none; }
.collapse.show { display: block; }

/* ---- Accordion (Recurly payment panels) ---- */
.accordion { display: block; }
.accordion-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    overflow: hidden;
}
.accordion-header,
h2.accordion-header { margin: 0; }
.accordion-header h2 { margin: 0; }
.accordion-button {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 14px 16px;
    border: none;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}
.accordion-button:hover { background: var(--border); }
.accordion-body { padding: 14px 16px; }

/* ---- Tab panes (nav/link styling lives under .app-tabs above) ---- */
.tab-content > .tab-pane { display: none; }
.tab-content > .tab-pane.active { display: block; }
.fade { transition: opacity 0.15s linear; }
.tab-pane.fade:not(.show) { opacity: 0; }
.tab-pane.fade.show { opacity: 1; }

/* ---- Collapsible section header (subtle, click-to-expand) ---- */
.collapsible-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    border: none;
    background: none;
    color: var(--muted);
    font: inherit;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
}
.collapsible-toggle:hover { color: var(--text); }
.collapsible-toggle__chevron {
    display: inline-block;
    transition: transform 0.15s ease;
}
.collapsible-toggle[aria-expanded="true"] .collapsible-toggle__chevron {
    transform: rotate(90deg);
}

/* ---- Dropdowns ---- */
.dropdown,
.btn-group { position: relative; }
.dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 1000;
    display: none;
    min-width: 180px;
    margin: 4px 0 0;
    padding: 6px;
    list-style: none;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
}
.dropdown-menu.show { display: block; }
.dropdown-menu-end { right: 0; left: auto; }
.dropdown-menu li { list-style: none; }
.dropdown-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 8px;
    background: none;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-align: left;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}
.dropdown-item:hover {
    background: var(--bg);
    color: var(--text);
    text-decoration: none;
}
.dropdown-item.danger { color: var(--brand); }
.dropdown-item.danger:hover { background: rgba(227,6,19,0.08); color: var(--brand); }
.dropdown-divider {
    height: 1px;
    margin: 6px 4px;
    background: var(--border);
    border: none;
}
.dropdown-toggle::after {
    display: inline-block;
    margin-left: 6px;
    vertical-align: middle;
    content: "";
    border-top: 4px solid;
    border-right: 4px solid transparent;
    border-left: 4px solid transparent;
}

/* ---- Remaining Bootstrap button variants (map to component look) ---- */
.btn-secondary {
    background: var(--card);
    border-color: var(--border);
    color: var(--text);
}
.btn-secondary:hover {
    background: var(--bg);
    text-decoration: none;
    color: var(--text);
}

/* ---- Form controls not covered by .data-form (Bootstrap markup) ---- */
.form-control,
.form-select {
    display: block;
    width: 100%;
    padding: 8px 12px;
    font: inherit;
    color: var(--text);
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    outline: none;
}
.form-control:focus,
.form-select:focus {
    border-color: rgba(227,6,19,0.55);
    box-shadow: 0 0 0 3px rgba(227,6,19,0.12);
}
.form-select { appearance: auto; }
.form-check {
    display: flex;
    align-items: center;
    gap: 6px;
}
.form-check-input {
    width: 16px;
    height: 16px;
    margin: 0;
}
.col-form-label {
    padding-top: 8px;
    padding-bottom: 8px;
    margin-bottom: 0;
    font-weight: 600;
}

/* ---- Input groups (AccountDetails / Organisation / SignUp) ---- */
.input-group {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    width: 100%;
}
.input-group > .form-control,
.input-group > .form-select,
.input-group > input,
.input-group > select {
    position: relative;
    flex: 1 1 auto;
    width: 1%;
    min-width: 0;
}
/* The .data-form input rules above are more specific than the selectors just
   above, so on a form carrying both classes the field takes the full row and
   wraps onto its own line. Re-assert the flex width for that combination. */
.data-form .input-group > .form-control,
.data-form .input-group > .form-select,
.data-form .input-group > input,
.data-form .input-group > select,
.data-form .input-group > textarea {
    width: 1%;
}
/* The children join into one visual control: square every edge, then round only
   the outer two. --ig-radius matches whatever the standalone fields in the same
   context use, so a group lines up with the inputs above and below it. */
.input-group { --ig-radius: 10px; }
.data-form .input-group { --ig-radius: 12px; }

.input-group > * {
    border-radius: 0;
}
.input-group > :first-child {
    border-top-left-radius: var(--ig-radius);
    border-bottom-left-radius: var(--ig-radius);
}
.input-group > :last-child {
    border-top-right-radius: var(--ig-radius);
    border-bottom-right-radius: var(--ig-radius);
}

/* The .data-form field rules are more specific than `.input-group > *`, so the
   joins have to be repeated for form fields inside a .data-form. */
.data-form .input-group > input,
.data-form .input-group > select,
.data-form .input-group > textarea {
    border-radius: 0;
}
.data-form .input-group > input:first-child,
.data-form .input-group > select:first-child,
.data-form .input-group > textarea:first-child {
    border-top-left-radius: var(--ig-radius);
    border-bottom-left-radius: var(--ig-radius);
}
.data-form .input-group > input:last-child,
.data-form .input-group > select:last-child,
.data-form .input-group > textarea:last-child {
    border-top-right-radius: var(--ig-radius);
    border-bottom-right-radius: var(--ig-radius);
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    white-space: nowrap;
}

/* ---- Utility: danger text (validation messages, delete actions) ---- */
.text-danger { color: var(--brand) !important; }

/* ---- Bootstrap grid + utility compat (Admin/Products config forms) ---- */
.container-fluid {
    width: 100%;
    padding-right: 12px;
    padding-left: 12px;
    margin-right: auto;
    margin-left: auto;
}
.row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -8px;
    margin-left: -8px;
}
.row > * {
    box-sizing: border-box;
    padding-right: 8px;
    padding-left: 8px;
}
.row.g-2 { margin-right: -4px; margin-left: -4px; }
.row.g-2 > * { padding-right: 4px; padding-left: 4px; }
.col { flex: 1 0 0%; }
.col-auto { flex: 0 0 auto; width: auto; }
.col-3 { flex: 0 0 auto; width: 25%; }
.col-9 { flex: 0 0 auto; width: 75%; }
.col-md-2 { flex: 0 0 auto; width: 16.6667%; }
.col-md-6 { flex: 0 0 auto; width: 50%; }
.col-md-10 { flex: 0 0 auto; width: 83.3333%; }
@media (max-width: 767.98px) {
    .col-md-2,
    .col-md-6,
    .col-md-10 { width: 100%; }
}
.d-none { display: none !important; }
.d-flex { display: flex !important; }
.d-block { display: block !important; }
.d-inline-block { display: inline-block !important; }
.align-items-center { align-items: center !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-end { justify-content: flex-end !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-2 { margin-bottom: 0.5rem !important; }
.mt-3 { margin-top: 1rem !important; }
.ms-2 { margin-left: 0.5rem !important; }

/* ---- Responsive: collapse sidebar to a top strip on small screens ---- */
@media (max-width: 800px) {
    .page {
        flex-direction: column;
    }
    .sidebar {
        width: 100%;
        position: relative;
        top: auto;
        height: auto;
        align-self: auto;
        padding: 12px 16px;
        overflow-y: visible;
    }
    .sidebar-nav {
        flex-direction: row;
        flex-wrap: wrap;
        overflow-y: visible;
    }
    .nav-group {
        margin-bottom: 0;
    }
}

/* ---- Multi-column form layout: one column on narrow screens, two from 900px up ---- */
.data-form .form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 20px;
}
@media (min-width: 900px) {
    .data-form .form-grid { grid-template-columns: 1fr 1fr; }
    .data-form .form-grid .span-full { grid-column: 1 / -1; }
}
.data-form textarea.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
}
/* Read-only JSON, e.g. configurator documents on Admin/ConfigurationDocuments. */
.json-view {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px;
    max-height: 600px;
    overflow: auto;
}
.json-view--short { max-height: 400px; }

/* Collapsible panel inside a card, e.g. a list or a JSON view: <details class="sub-details">. */
details.sub-details {
    margin-top: 12px;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
}
details.sub-details > summary {
    cursor: pointer;
    font-weight: 600;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 8px;
}
details.sub-details > summary::-webkit-details-marker { display: none; }
details.sub-details > summary::before {
    content: "▸";
    color: var(--muted);
    font-size: 12px;
    transition: transform 0.15s;
}
details.sub-details[open] > summary::before { transform: rotate(90deg); }
details.sub-details[open] > summary { margin-bottom: 8px; }
details.sub-details .json-view { margin: 0; }

/* An add form behind its button: <details class="add-panel"><summary><span class="btn primary
   add-panel__open">+ Add</span><span class="add-panel__title">Add</span></summary>. Closed, the
   summary is the button; open, it is the form's heading, and clicking it closes the form. */
details.add-panel { margin-top: 16px; }
details.add-panel > summary {
    list-style: none;
    cursor: pointer;
    display: inline-block;
}
details.add-panel > summary::-webkit-details-marker { display: none; }
details.add-panel .add-panel__title { display: none; }
details.add-panel[open] .add-panel__open { display: none; }
details.add-panel[open] .add-panel__title {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
}
details.add-panel[open] .add-panel__title::before {
    content: "▸";
    color: var(--muted);
    font-size: 12px;
    transform: rotate(90deg);
}
details.add-panel[open] {
    border-top: 1px solid var(--border);
    padding-top: 16px;
}

/* A checkbox and its label on one line, e.g. a toolbar filter. */
.inline-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-weight: 600;
}

/* A View row under a document's row in a version list. */
.data-table tr.view-row > td { padding-top: 0; }
.data-form .form-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.data-form .form-row.form-check { align-self: end; padding-bottom: 10px; }
.data-form .form-check label { margin: 0; }
.col-truncate.url-cell { max-width: 260px; }
.section-title { margin: 0 0 12px; }

/* ---- Searchable select (App Family picker): looks like a .data-form select, opens a searchable list ---- */
.combo { position: relative; }
.data-form .combo-toggle {
    display: block;
    width: 100%;
    padding: 10px 40px 10px 12px;
    text-align: left;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    font: inherit;
    cursor: pointer;
    position: relative;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.combo-toggle::after {
    content: "";
    position: absolute;
    right: 14px;
    top: 50%;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--muted);
    border-bottom: 2px solid var(--muted);
    transform: translateY(-70%) rotate(45deg);
}
.combo-toggle:focus-visible,
.combo-toggle[aria-expanded="true"] {
    outline: none;
    border-color: rgba(227,6,19,0.55);
    box-shadow: 0 0 0 4px rgba(227,6,19,0.12);
}
.combo-placeholder { color: var(--muted); }
.combo-panel {
    position: absolute;
    z-index: 20;
    left: 0;
    right: 0;
    margin-top: 6px;
    padding: 8px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
}
.combo-panel[hidden] { display: none; }
.data-form .combo-search { margin-bottom: 6px; }
.combo-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 260px;
    overflow-y: auto;
}
.combo-list li {
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
}
.combo-list li[hidden] { display: none; }
.combo-list li.active { background: var(--bg); }
.combo-list li[aria-selected="true"] { font-weight: 700; }
.combo-list li.combo-empty { color: var(--muted); cursor: default; }
.combo.is-loading .combo-toggle { cursor: progress; opacity: 0.75; }
.combo.is-loading .combo-toggle::after {
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    transform: translateY(-50%);
    animation: combo-spin 0.7s linear infinite;
}
@keyframes combo-spin { to { transform: translateY(-50%) rotate(360deg); } }

/* ---- Layout helpers ----
   Single-purpose classes that replace repeated inline style="" values. They are !important
   on purpose: they stand in for inline styles, which beat every component rule, so they must
   keep doing so (e.g. `.card h2` must not override `.m-0`). Values are the exact px used by
   the pages; add a class here rather than writing a new inline style. */
.mt-0  { margin-top: 0 !important; }
.mt-6  { margin-top: 6px !important; }
.mt-8  { margin-top: 8px !important; }
.mt-10 { margin-top: 10px !important; }
.mt-12 { margin-top: 12px !important; }
.mt-16 { margin-top: 16px !important; }
.mt-20 { margin-top: 20px !important; }
.mt-24 { margin-top: 24px !important; }
.mb-6  { margin-bottom: 6px !important; }
.m-0   { margin: 0 !important; }
.mr-20 { margin-right: 20px !important; }
.pr-20 { padding-right: 20px !important; }
.h-42  { height: 42px !important; }
.w-full { width: 100% !important; }
.w-auto { width: auto !important; }
.min-w-30 { min-width: 30% !important; }
.mw-160  { max-width: 160px !important; }
.mw-200  { max-width: 200px !important; }
.mw-280  { max-width: 280px !important; }
.mw-320  { max-width: 320px !important; }
.mw-420  { max-width: 420px !important; }
.mw-480  { max-width: 480px !important; }
.mw-520  { max-width: 520px !important; }
.mw-560  { max-width: 560px !important; }
.mw-640  { max-width: 640px !important; }
.mw-720  { max-width: 720px !important; }
.mw-760  { max-width: 760px !important; }
.mw-1000 { max-width: 1000px !important; }
.mt-18 { margin-top: 18px !important; }
/* "flush" = that top/bottom margin, and 0 on the other sides (what `margin: 8px 0 0` meant) */
.mt-8-flush  { margin: 8px 0 0 !important; }
.mt-12-flush { margin: 12px 0 0 !important; }
.mb-5-flush  { margin: 0 0 5px !important; }
.h-400 { height: 400px !important; }
.mh-48 { max-height: 48px !important; }
.w-10 { width: 10% !important; }
.w-15 { width: 15% !important; }
.shadow-none { box-shadow: none !important; }
.text-brand { color: var(--brand) !important; }
.pre-line { white-space: pre-line !important; }
.pre-wrap-break { white-space: pre-wrap !important; word-break: break-word !important; }
.clickable-bold { cursor: pointer !important; font-weight: 700 !important; }
.row-between {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    gap: 12px !important;
}

/* Recurly validation messages start hidden. recurlyops.js reveals and re-hides them with
   inline !important styles (ShowElement/HideElement), which still win over this rule. Anything
   else that shows one of these must do the same: clearing `el.style.display` would leave it
   hidden, because this rule now applies. The ACH consent message is addressed by id and
   handled the same way. */
[data-error-for],
#invalidAchConsentMessage { display: none; }

/* ---- Subscription cards (User/Subscriptions) ---- */
.sub-card {
    display: flex;
    align-items: center;
    gap: 32px;
    max-width: 760px;
    margin-bottom: 16px;
    padding: 20px;
}
.sub-card__logo {
    flex: 0 0 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sub-card__logo img {
    max-width: 100%;
    max-height: 120px;
}
.sub-card__details {
    flex: 1;
}
@media (max-width: 640px) {
    .sub-card { flex-direction: column; gap: 12px; }
    .sub-card__logo { flex-basis: auto; }
}
