/*
 * django-commhub contact buttons.
 *
 * Self-contained: no CSS framework needed, every class is prefixed
 * "commhub-". Theme it by overriding these variables in your own CSS:
 *
 *   .commhub-contacts {
 *       --commhub-size: 48px;
 *       --commhub-gap: 12px;
 *       --commhub-z: 900;
 *       --commhub-card-bg: #0f1e35;
 *       --commhub-card-text: #eef2f9;
 *       --commhub-card-muted: #9db0c9;
 *       --commhub-card-border: #1c3252;
 *   }
 *
 * Position/offsets come from settings.COMMHUB_CONTACTS (see conf.py).
 */

/* Theme defaults with zero specificity (:where), so a site's own
   overrides win however the stylesheets are ordered. */
:where(.commhub-contacts) {
    --commhub-size: 48px;
    --commhub-gap: 12px;
    --commhub-z: 900;
    --commhub-card-bg: #ffffff;
    --commhub-card-text: #111827;
    --commhub-card-muted: #4b5563;
    --commhub-card-border: #e5e7eb;
    --commhub-card-code-bg: #f3f4f6;
}

.commhub-contacts {
    position: fixed;
    bottom: var(--commhub-bottom, 20px);
    z-index: var(--commhub-z);
    display: flex;
    /* First button (lowest "order") sits at the bottom. */
    flex-direction: column-reverse;
    align-items: center;
    gap: var(--commhub-gap);
    margin: 0;
    padding: 0;
}

.commhub-contacts--right { right: var(--commhub-side, 20px); }
.commhub-contacts--left { left: var(--commhub-side, 20px); }

.commhub-contacts *,
.commhub-contacts *::before,
.commhub-contacts *::after {
    box-sizing: border-box;
}

.commhub-button {
    position: relative;  /* for the live-chat unread badge */
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--commhub-size);
    height: var(--commhub-size);
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 9999px;
    background: var(--commhub-brand, #475569);
    color: #ffffff;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.25);
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.15s ease, filter 0.15s ease;
}

.commhub-button:hover { filter: brightness(1.08); transform: translateY(-1px); }
.commhub-button:focus { outline: none; }
.commhub-button:focus-visible {
    outline: 3px solid var(--commhub-brand, #475569);
    outline-offset: 3px;
}

.commhub-button svg {
    width: 58%;
    height: 58%;
    display: block;
}
.commhub-button--chat svg { width: 50%; height: 50%; }

/* --- Contact card (WeChat always; other channels on computers) ------- */

.commhub-card {
    position: fixed;
    bottom: var(--commhub-bottom, 20px);
    width: 20rem;
    max-width: calc(100vw - 24px);
    z-index: calc(var(--commhub-z) + 1);
    padding: 16px;
    border: 1px solid var(--commhub-card-border);
    border-radius: 12px;
    background: var(--commhub-card-bg);
    color: var(--commhub-card-text);
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
    font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
    text-align: left;
}

.commhub-card[hidden] { display: none; }

.commhub-contacts--right .commhub-card {
    right: calc(var(--commhub-side, 20px) + var(--commhub-size) + var(--commhub-gap));
}
.commhub-contacts--left .commhub-card {
    left: calc(var(--commhub-side, 20px) + var(--commhub-size) + var(--commhub-gap));
}

.commhub-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.commhub-card__title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.3;
    color: inherit;
}

.commhub-card__close {
    margin: -4px -6px 0 0;
    padding: 0 8px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--commhub-card-muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}
.commhub-card__close:hover { color: var(--commhub-card-text); }

.commhub-card__caption {
    margin: 12px 0 4px;
    font-size: 12px;
    color: var(--commhub-card-muted);
}

.commhub-card__id-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.commhub-card__id {
    flex: 1;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid var(--commhub-card-border);
    border-radius: 8px;
    background: var(--commhub-card-code-bg);
    color: inherit;
    font: 15px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    word-break: break-all;
    user-select: all;
}

.commhub-card__copy,
.commhub-card__open {
    padding: 8px 12px;
    border: 0;
    border-radius: 8px;
    background: var(--commhub-brand, #475569);
    color: #ffffff;
    font: inherit;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
}
.commhub-card__copy:hover,
.commhub-card__open:hover { filter: brightness(1.08); }

.commhub-card__copy:focus,
.commhub-card__open:focus,
.commhub-card__close:focus { outline: none; }
.commhub-card__copy:focus-visible,
.commhub-card__open:focus-visible,
.commhub-card__close:focus-visible {
    outline: 2px solid var(--commhub-brand, #475569);
    outline-offset: 2px;
}

.commhub-card__steps {
    margin: 12px 0 0;
    padding-left: 20px;
    color: var(--commhub-card-muted);
}

.commhub-card__qr {
    display: flex;
    justify-content: center;
    margin-top: 14px;
}
.commhub-card__qr svg {
    width: 168px;
    height: 168px;
    display: block;
    border-radius: 6px;
    /* Pixel-sharp modules at any zoom. */
    shape-rendering: crispEdges;
}

.commhub-card__actions:empty { display: none; }
.commhub-card__open {
    display: block;
    margin-top: 12px;
    text-align: center;
}
/* "Open the app" only makes sense where the app can be: touch devices. */
.commhub-card__open--phones { display: none; }
@media (hover: none), (pointer: coarse) {
    .commhub-card__open--phones { display: block; }
}

/* Narrow screens: full-width card above the buttons. */
@media (max-width: 639px) {
    .commhub-contacts--right .commhub-card,
    .commhub-contacts--left .commhub-card {
        left: 12px;
        right: 12px;
        width: auto;
        max-width: none;
        bottom: calc(var(--commhub-bottom, 20px) + var(--commhub-size) + var(--commhub-gap));
    }
}

/* Short screens (e.g. landscape laptops with a QR code): let the card scroll. */
.commhub-card { max-height: calc(100vh - 24px); overflow-y: auto; }

@media (prefers-reduced-motion: reduce) {
    .commhub-button { transition: none; }
    .commhub-button:hover { transform: none; }
}
