/* Admin campaign links (Pages/Admin/Marketing/CampaignLinks.razor and its dialogs).
   Namespaced with .cl- to avoid collisions; loaded globally via App.razor. The page header,
   summary tiles, card surface and framed grid reuse the shared .wl- classes from
   admin-waitlist.css (as the community digest page does); this file only adds what is specific
   to campaign links. Theme CSS variables only so light and dark both track. */

/* ---- Controls row (range, archived switch, new link) ---- */
.cl-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 16px;
}

.cl-controls .mud-switch {
    margin: 0;
}

/* ---- Empty state (inside a .wl-card) ---- */
.cl-state {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    color: var(--mud-palette-text-secondary);
}

.cl-state__body {
    flex: 1 1 240px;
    min-width: 0;
}

.cl-state__title {
    font-weight: 600;
    color: var(--mud-palette-text-primary);
}

.cl-state__desc {
    margin-top: 2px;
    font-size: 0.85rem;
}

/* ---- Data grid (framed by .wl-grid); the wide table scrolls inside its frame ---- */
.cl-grid .mud-table-container {
    overflow-x: auto;
}

.cl-row--archived td {
    color: var(--mud-palette-text-secondary);
}

.cl-num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.cl-name {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.cl-name__text {
    font-weight: 600;
    color: var(--mud-palette-text-primary);
    overflow-wrap: anywhere;
}

.cl-name__note {
    margin-left: 4px;
    vertical-align: middle;
    color: var(--mud-palette-text-secondary);
}

.cl-shortlink {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    white-space: nowrap;
}

/* Monospace short link, shared by the grid and the QR dialog. */
.cl-code {
    font-family: "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
    font-size: 0.82rem;
    padding: 2px 6px;
    border-radius: 6px;
    color: var(--mud-palette-text-primary);
    background: var(--mud-palette-action-default-hover);
}

.cl-utm {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
}

.cl-chip {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.72rem;
    line-height: 1.5;
    white-space: nowrap;
    color: var(--mud-palette-text-secondary);
    border: 1px solid var(--mud-palette-lines-default);
}

.cl-muted {
    font-size: 0.82rem;
    white-space: nowrap;
    color: var(--mud-palette-text-secondary);
}

.cl-actions {
    text-align: end;
    white-space: nowrap;
}

.cl-actions__row {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

/* ---- Create / edit dialog ---- */
.cl-dialog__group-label {
    margin-bottom: 8px;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--mud-palette-text-secondary);
}

.cl-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.cl-code-field input {
    font-family: "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
}

/* ---- QR dialog ---- */
.cl-qr__name {
    font-weight: 600;
    color: var(--mud-palette-text-primary);
    overflow-wrap: anywhere;
}

/* The code is always black on white (it scans best that way), so the well stays white in dark mode too. */
.cl-qr__preview {
    display: flex;
    justify-content: center;
    padding: 16px;
    border-radius: 14px;
    background: #ffffff;
    border: 1px solid var(--mud-palette-lines-default);
}

.cl-qr__image {
    display: block;
    width: 256px;
    height: auto;
    aspect-ratio: 1;
    max-width: 100%;
    object-fit: contain;
    image-rendering: pixelated;
}

.cl-qr__url {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
}

.cl-qr__url-text {
    overflow-wrap: anywhere;
}

.cl-qr__downloads {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.cl-qr__size {
    flex: 1 1 160px;
    min-width: 140px;
}

/* ---- Responsive ---- */
@media (max-width: 600px) {
    .cl-controls > .mud-button-root {
        width: 100%;
    }

    /* Range toggle spans the row with equal, thumb-sized segments (row actions get the 44px
       minimum from the shared .wl-grid rule). */
    .cl-range {
        width: 100%;
    }

    .cl-range .mud-toggle-item {
        flex: 1 1 0;
        min-height: 44px;
        padding-inline: 6px;
    }

    .cl-qr__downloads .mud-button-root {
        min-height: 44px;
    }

    .cl-qr__url .mud-icon-button {
        min-width: 44px;
        min-height: 44px;
    }

    .cl-presets {
        gap: 8px;
    }

    .cl-presets .mud-chip {
        min-height: 36px;
    }
}

/* Live code-availability line under the Code field. */
.cl-code-status {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: -6px 0 0 14px;
    font-size: 0.78rem;
    color: var(--mud-palette-text-secondary);
}

.cl-code-status--free {
    color: var(--mud-palette-success);
}

.cl-code-status--taken {
    color: var(--mud-palette-error);
}

/* ---- Detail page (Pages/Admin/Marketing/CampaignLinkDetail.razor) ---- */
.cl-detail-back {
    margin-left: -8px;
}

.cl-detail-head__main {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px 24px;
}

.cl-detail-head__text {
    flex: 1 1 320px;
    min-width: 0;
}

.cl-detail-title {
    flex-wrap: wrap;
}

.cl-detail-title__text {
    min-width: 0;
    overflow-wrap: anywhere;
}

.cl-detail-row {
    margin-top: 8px;
}

.cl-detail-dest {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    font-size: 0.88rem;
    color: var(--mud-palette-text-secondary);
}

.cl-detail-dest__label {
    font-weight: 600;
}

.cl-detail-dest__path {
    color: var(--mud-palette-text-primary);
    overflow-wrap: anywhere;
}

.cl-detail-created {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
    white-space: normal;
}

.cl-detail-created__by {
    overflow-wrap: anywhere;
}

.cl-detail-notes {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--mud-palette-text-secondary);
    overflow-wrap: anywhere;
}

.cl-detail-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

/* The QR stays black on white (it scans best that way), so its well is white in dark mode too. */
.cl-detail-qr {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 144px;
    height: 144px;
    padding: 8px;
    box-sizing: border-box;
    cursor: pointer;
    border-radius: 14px;
    background: #ffffff;
    border: 1px solid var(--mud-palette-lines-default);
    transition: box-shadow 0.15s ease, border-color 0.15s ease;
}

.cl-detail-qr:hover,
.cl-detail-qr:focus-visible {
    border-color: var(--mud-palette-primary);
    box-shadow: 0 0 0 3px var(--mud-palette-primary-hover);
    outline: none;
}

/* The thumbnail is the 256px PNG shown at 128px (96px on phones), so it downsamples smoothly. */
.cl-detail-qr__image {
    display: block;
    width: 128px;
    height: 128px;
    object-fit: contain;
}

/* The loading placeholder uses the same well, but it is not a button. */
.cl-detail-qr--skeleton {
    cursor: default;
}

/* Fixed-height slot for the reload bar under the range toggle, so it never moves the tiles. */
.cl-detail-progress {
    height: 4px;
    margin-top: 8px;
}

.cl-detail-qr__fallback {
    color: var(--mud-palette-text-secondary);
}

/* Five KPI tiles: as many per row as fit, one per row on phones. */
.cl-detail-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
}

.cl-detail-card {
    height: 100%;
}

.cl-detail-card__head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px 12px;
    margin-bottom: 10px;
}

.cl-detail-card__title {
    font-weight: 700;
    color: var(--mud-palette-text-primary);
}

.cl-detail-card__sub {
    font-size: 0.8rem;
    color: var(--mud-palette-text-secondary);
}

/* The chart fills this box (SfChart Height="100%"), so the phone rule below can shorten it. */
.cl-detail-chart {
    width: 100%;
    min-width: 0;
    height: 320px;
}

/* The sign-ups scroll region is focusable for keyboard scrolling; show where focus is. */
.cl-detail-table:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
    border-radius: 6px;
}

.cl-detail-empty {
    padding: 18px 0;
    text-align: center;
    font-size: 0.88rem;
    color: var(--mud-palette-text-secondary);
}

/* Breakdown rows: label and count on one line, a thin proportional bar under them. */
.cl-breakdown {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cl-breakdown__line {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    font-size: 0.88rem;
}

.cl-breakdown__label {
    min-width: 0;
    overflow-wrap: anywhere;
    color: var(--mud-palette-text-primary);
}

.cl-breakdown__count {
    flex: none;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--mud-palette-text-primary);
}

.cl-breakdown__track {
    margin-top: 4px;
    height: 4px;
    border-radius: 999px;
    overflow: hidden;
    background: var(--mud-palette-action-default-hover);
}

.cl-breakdown__bar {
    height: 100%;
    min-width: 2px;
    border-radius: 999px;
    background: var(--mud-palette-primary);
}

/* Sign-ups table: scrolls sideways inside its card on narrow screens. */
.cl-detail-table {
    overflow-x: auto;
}

.cl-detail-table table {
    min-width: 560px;
}

.cl-detail-table td,
.cl-detail-table th {
    white-space: nowrap;
}

.cl-detail-table__email {
    color: var(--mud-palette-text-secondary);
}

.cl-detail-status {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

@media (max-width: 600px) {
    /* Two tiles per row; the fifth (crawler hits) spans the row instead of sitting alone. */
    .cl-detail-tiles {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .cl-detail-tiles > .wl-tile:last-child {
        grid-column: 1 / -1;
    }

    .cl-detail-chart {
        height: 240px;
    }

    .cl-detail-back,
    .cl-alert-retry {
        min-height: 44px;
    }

    .cl-detail-row .mud-icon-button {
        min-width: 44px;
        min-height: 44px;
    }

    .cl-detail-qr {
        width: 112px;
        height: 112px;
    }

    .cl-detail-qr__image {
        width: 96px;
        height: 96px;
    }

    .cl-detail-actions .mud-button-root {
        min-height: 44px;
    }
}
