/*
 * Legacy bridge: classes used all over the older views (Bootstrap alerts, soft/solid badges, nav-tabs,
 * the .switch toggle, .empty-state-*) restyled onto the shared tokens, so every page that still uses them
 * matches the new look. New code uses the .ui-* components instead; pages move off these classes
 * page by page. !important only where style.css/darkmode.css already force the old values.
 */

/* ---------- Alerts → notes ---------- */
.alert {
    --bs-alert-border-color: transparent;
    border: 0;
    border-radius: var(--ui-radius);
    font-size: var(--ui-fs-sm);
    line-height: 1.5;
    padding: 10px 14px;
}

.alert-info {
    --bs-alert-bg: var(--ui-info-tint);
    --bs-alert-color: var(--ui-info-text);
}

.alert-success {
    --bs-alert-bg: var(--ui-success-tint);
    --bs-alert-color: var(--ui-success-text);
}

.alert-warning {
    --bs-alert-bg: var(--ui-warning-tint);
    --bs-alert-color: var(--ui-warning-text);
}

.alert-danger {
    --bs-alert-bg: var(--ui-danger-tint);
    --bs-alert-color: var(--ui-danger-text);
}

.alert-secondary,
.alert-light {
    --bs-alert-bg: var(--ui-subtle);
    --bs-alert-color: var(--ui-body);
}

.alert-primary {
    --bs-alert-bg: var(--ui-primary-soft);
    --bs-alert-color: var(--ui-text);
}

.alert .alert-link,
.alert a:not(.btn) {
    color: inherit;
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.alert > :is(i, svg):first-child {
    opacity: .85;
}

/* ---------- .btn-secondary → the quiet secondary button (same as .btn-light) ----------
   The theme renders it near-black, which made Cancel/Close look like the primary action. */
.btn-secondary {
    --bs-btn-color: var(--ui-text);
    --bs-btn-bg: var(--ui-surface);
    --bs-btn-border-color: var(--ui-border-strong);
    --bs-btn-hover-color: var(--ui-text);
    --bs-btn-hover-bg: var(--ui-subtle);
    --bs-btn-hover-border-color: var(--ui-faint);
    --bs-btn-active-color: var(--ui-text);
    --bs-btn-active-bg: var(--ui-subtle);
    --bs-btn-active-border-color: var(--ui-faint);
    --bs-btn-disabled-color: var(--ui-muted);
    --bs-btn-disabled-bg: var(--ui-surface);
    --bs-btn-disabled-border-color: var(--ui-border);
    background-color: var(--bs-btn-bg) !important;
    border-color: var(--bs-btn-border-color) !important;
    color: var(--bs-btn-color) !important;
}

.btn-secondary:hover,
.btn-secondary:focus-visible {
    background-color: var(--ui-subtle) !important;
    border-color: var(--ui-faint) !important;
}

/* ---------- Badges → pills (same tones as .ui-pill / .ui-status) ---------- */
.badge {
    font-size: var(--ui-fs-xs);
    font-weight: 600;
    line-height: 1.5;
    padding: 2px 9px;
    letter-spacing: 0;
}

.badge.badge-soft-success,
.badge.bg-success { background-color: var(--ui-success-tint) !important; color: var(--ui-success-text) !important; }
.badge.badge-soft-danger,
.badge.bg-danger { background-color: var(--ui-danger-tint) !important; color: var(--ui-danger) !important; }
.badge.badge-soft-warning,
.badge.bg-warning { background-color: var(--ui-warning-tint) !important; color: var(--ui-warning-text) !important; }
.badge.badge-soft-info,
.badge.bg-info { background-color: var(--ui-info-tint) !important; color: var(--ui-info-text) !important; }
.badge.badge-soft-primary,
.badge.bg-primary { background-color: var(--ui-primary-tint) !important; color: var(--ui-primary) !important; }
.badge.badge-soft-secondary,
.badge.badge-soft-dark,
.badge.badge-light,
.badge.bg-secondary,
.badge.bg-light,
.badge.bg-dark { background-color: var(--ui-subtle) !important; color: var(--ui-body) !important; }

/* ---------- nav-tabs → underline tabs (same as .ui-tabs) ---------- */
.nav-tabs {
    gap: var(--ui-space-6);
    border-bottom: 1px solid var(--ui-border) !important;
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
    display: none;
}

.nav-tabs .nav-item {
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}

/* Justified tab bars read like the other tabs: left aligned, sized to their label */
.nav-tabs.nav-justified .nav-item {
    flex: 0 0 auto !important;
}

.nav-tabs .nav-link {
    /* no negative margin: the scrolling tab bar would clip the active underline */
    margin-bottom: 0 !important;
    padding: 10px 0 !important;
    border: 0 !important;
    border-bottom: 2px solid transparent !important;
    border-radius: 0 !important;
    background: transparent !important;
    color: var(--ui-muted) !important;
    font-size: var(--ui-fs-base);
    font-weight: 600;
    white-space: nowrap;
    transition: color var(--ui-ease), border-color var(--ui-ease);
}

.nav-tabs .nav-link:hover {
    color: var(--ui-text) !important;
}

.nav-tabs .nav-link.active,
.nav-tabs .nav-item.show .nav-link {
    color: var(--ui-primary) !important;
    border-bottom: 2px solid var(--ui-primary) !important; /* style.css zeroes it with !important at 0,3,0 */
    background: transparent !important;
}

.nav-tabs .nav-link .ui-tab__count {
    margin-left: 6px;
}

/* Tabs inside a card header that already draws the divider */
.ui-card__head .nav-tabs,
.sh-chart-card__head .nav-tabs {
    border-bottom: 0 !important;
    align-self: stretch;
    align-items: flex-end;
}

.nav-tabs .nav-link h4 {
    margin: 0;
    padding: 0;
    font-size: inherit;
    font-weight: inherit;
    color: inherit;
}

/* ---------- .switch toggle (label.switch > input + .slider) ---------- */
.switch {
    width: 40px;
    height: 22px;
    flex: 0 0 auto;
    vertical-align: middle;
}

.switch .slider {
    background-color: var(--ui-border-strong);
    border-radius: var(--ui-radius-pill);
    transition: background-color var(--ui-ease);
}

.switch .slider::before {
    width: 16px;
    height: 16px;
    left: 3px;
    bottom: 3px;
    border-radius: 50%;
    background-color: var(--ui-surface);
    box-shadow: 0 1px 2px rgba(0, 0, 0, .2);
    transition: transform var(--ui-ease);
}

/* the checked knob sits against the track's right edge whatever the track and knob size: pages that size their
   own switch (40, 48, 50, 60px tracks; 12–22px knobs) used to keep a translateX for another size and overshot */
.switch .slider::before {
    transition: left var(--ui-ease), transform var(--ui-ease);
}
.switch input:checked + .slider::before {
    left: calc(100% - 3px) !important;
    transform: translateX(-100%) !important;
}

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

body[data-theme=dark] .switch .slider::before {
    background-color: var(--ui-logo-bg);
}

/* ---------- .empty-state-* → same look as .ui-empty ---------- */
.empty-state-container {
    min-height: 220px;
    padding: 28px 16px;
}

.empty-state-icon {
    width: 56px;
    height: 56px;
    margin-bottom: var(--ui-space-3);
    background: var(--ui-primary-tint);
    color: var(--ui-primary);
}

.empty-state-icon :is(i, svg) {
    font-size: 1.35rem;
}

.empty-state-title {
    margin-bottom: 4px;
    font-size: var(--ui-fs-lg);
    font-weight: 700;
    color: var(--ui-text);
}

.empty-state-message {
    margin-bottom: var(--ui-space-3);
    max-width: 420px;
    font-size: var(--ui-fs-sm);
    line-height: 1.55;
    color: var(--ui-muted);
}

/* ---------- Page header (legacy .page-header used by most views) ---------- */
.page-header .subtitle {
    color: var(--ui-muted);
    max-width: 70ch;
}

/* Centered headers (scan screens, wizards) keep the subtitle centered */
.text-center .page-header .subtitle,
.page-header.text-center .subtitle {
    margin-left: auto;
    margin-right: auto;
}

/* Channel / carrier / integration logos are drawn for light backgrounds. In dark mode they sit
   on the shared light logo tile instead of disappearing (white-variant logos are left alone). */
body[data-theme=dark] :is(img.channel-img, img.add-channel-img, img[src*="/images/channels/"], img[src*="/images/carriers/"]):not([src*="white"]):not(.ui-logo) {
    background: var(--ui-logo-bg);
    border-radius: var(--ui-radius-xs);
    padding: 2px 4px;
}

/* Legacy .bg-soft-* badges: tinted on the shared tokens so they follow light/dark like .ui-pill */
.badge.bg-soft-secondary,
.bg-soft-secondary { background: var(--ui-subtle) !important; color: var(--ui-text) !important; }
.badge.bg-soft-primary,
.bg-soft-primary { background: var(--ui-primary-tint) !important; color: var(--ui-primary) !important; }
.badge.bg-soft-success,
.bg-soft-success { background: var(--ui-success-tint) !important; color: var(--ui-success-text) !important; }
.badge.bg-soft-danger,
.bg-soft-danger { background: var(--ui-danger-tint) !important; color: var(--ui-danger-text) !important; }
.badge.bg-soft-info,
.bg-soft-info { background: var(--ui-info-tint) !important; color: var(--ui-info-text) !important; }
.badge.bg-soft-warning,
.bg-soft-warning { background: var(--ui-warning-tint) !important; color: var(--ui-warning-text) !important; }

/* CKEditor 5 (PIM descriptions, settings): brand action colour and the shared border */
:root {
    --ck-color-base-action: var(--ui-primary);
    --ck-color-base-border: var(--ui-border-strong);
}

/* Bootstrap shadow utilities on content cards: the shared card elevation (.shadow-lg stays for raised panels) */
.content .card.shadow-sm,
.content .card.shadow {
    box-shadow: var(--ui-shadow) !important;
}

/* TouchSpin +/− buttons default to btn-primary squares: show them as the light secondary control */
.bootstrap-touchspin .bootstrap-touchspin-down.btn-primary,
.bootstrap-touchspin .bootstrap-touchspin-up.btn-primary {
    background: var(--ui-subtle);
    border-color: var(--ui-border-strong);
    color: var(--ui-text);
}

.bootstrap-touchspin .bootstrap-touchspin-down.btn-primary:hover,
.bootstrap-touchspin .bootstrap-touchspin-up.btn-primary:hover {
    background: var(--ui-primary-tint);
    color: var(--ui-primary);
}

/* ---------- Order reference / quantity pills (.order-qty-badge, OrderInfo): quiet for a single unit,
   colour only where more than one needs attention ---------- */
.order-qty-badge {
    padding: 4px 9px;
    border: 1px solid transparent;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* body + dark selector: same weight as the darkmode.css colours they replace */
:is(body, body[data-theme=dark]) .order-qty-badge:is([data-qty="1"], [data-qty="default"]) { background: var(--ui-subtle); color: var(--ui-body); border-color: var(--ui-border); }
:is(body, body[data-theme=dark]) .order-qty-badge[data-qty="2"] { background: var(--ui-info-tint); color: var(--ui-info-text); border-color: transparent; }
:is(body, body[data-theme=dark]) .order-qty-badge[data-qty="3"] { background: var(--ui-purple-tint); color: var(--ui-purple); border-color: transparent; }
:is(body, body[data-theme=dark]) .order-qty-badge:is([data-qty="4"], [data-qty="5"]) { background: var(--ui-warning-tint); color: var(--ui-warning-text); border-color: transparent; }
:is(body, body[data-theme=dark]) .order-qty-badge:is([data-qty="6"], [data-qty="7"], [data-qty="8"], [data-qty="9"], [data-qty="10"]) { background: var(--ui-danger-tint); color: var(--ui-danger-text); border-color: transparent; }

/* ---------- Stacked product thumbnails (order lists): small rounded tiles that overlap slightly ---------- */
.stacked-images-wrapper {
    display: flex;
    justify-content: flex-start;
    width: auto;
    min-width: 0;
    padding-left: 6px;
}

.stacked-product-image {
    width: 34px;
    height: 34px;
    margin: 0 0 0 -6px;
    border: 2px solid var(--ui-surface);
    border-radius: var(--ui-radius-sm);
    /* Product photos are made for white; the tile stays white in dark mode too */
    background-color: var(--ui-logo-bg);
    background-size: 82%;
    box-shadow: 0 0 0 1px var(--ui-border);
}

/* darkmode.css paints the tiles with the input colour: real photos get their white tile back */
body[data-theme="dark"] .stacked-product-image:not([style*="no_product_image"]) {
    background-color: var(--ui-logo-bg) !important; /* darkmode.css uses !important */
}

/* More than three products: three tiles and a "+N" tile instead of a long pile */
.stacked-images-wrapper > .stacked-product-image:nth-child(n+4) {
    display: none;
}

.stacked-more {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    margin-left: -6px;
    padding: 0 6px;
    border: 2px solid var(--ui-surface);
    border-radius: var(--ui-radius-sm);
    background: var(--ui-subtle);
    box-shadow: 0 0 0 1px var(--ui-border);
    color: var(--ui-muted);
    font-size: var(--ui-fs-xs);
    font-weight: 600;
}

/* ---------- Channel / carrier logo badges in tables ---------- */
.channel-logo-badge {
    min-width: 48px;
    height: 30px;
    padding: 4px 8px;
    border-color: var(--ui-border);
    border-radius: var(--ui-radius);
}

.channel-logo-img {
    max-width: 56px;
    max-height: 18px;
}

.dataTables_wrapper .carrier-logo-img {
    max-height: 30px !important;
    padding: 4px 8px;
    border-color: var(--ui-border);
    border-radius: var(--ui-radius);
}

/* Country flags in tables get a hairline so white flags do not vanish */
.dataTables_wrapper .fi:not(.fi-) {
    border-radius: 3px;
    box-shadow: 0 0 0 1px var(--ui-border);
}
