/*
 * Chart annotations overlay (public/assets/js/custom/chart-annotations.js; plan
 * claude-work/chart-annotations-plan.md D3, A6, A11, A16, A22).
 *
 * Classes:
 *   axi-ann-host            the chart host (made a positioning context)
 *   axi-ann-layer           one per host, covers it, pointer-events none
 *   axi-ann-band            shaded band of a date range (inert)
 *   axi-ann-line            dashed vertical line above a dot (inert)
 *   axi-ann-dot             the marker <button> on the x axis baseline
 *     axi-ann-dot--cluster  several notes in one dot (with axi-ann-count)
 *     axi-ann-dot--all-day  hourly one-day chart: one dot at the left edge
 *   axi-ann-count           count badge of a cluster
 *   axi-ann-all-day         the "all day" label next to that dot
 *   axi-ann-error           visible "could not be loaded" badge
 *     axi-ann-truncated     the same badge for "Some annotations are not shown"
 *   axi-ann--<category>     colour: site_change, campaign, promotion, tracking,
 *                           external, other; axi-ann--mixed for a mixed cluster
 *
 * Interactions (chart-annotations-ui.js, plan Task 5):
 *   axi-ann-chip            "+ Add annotation on {date}" on the baseline after a plot click
 *   axi-ann-card            preview (hover/focus) or pinned card (click) of a dot;
 *     axi-ann-card--pinned  pinned; a bottom sheet below 576px
 *   axi-ann-card-close, -note, -head, -date, -title, -desc, -meta, -meta-line, -actions
 *   axi-ann-cat             category chip (with axi-ann-swatch and an axi-ann--<category>)
 *   axi-ann-swatch          small colour square of a category (card, control)
 *   axi-ann-badge           "via Axi" / "via API" source badge
 *   axi-ann-control, axi-ann-menu   the "Annotations" dropdown next to the period button
 *
 * List page (templates/admin/annotations/index.html.twig, inside .axi-ann-list):
 *   axi-ann-col-title, axi-ann-col-desc   fluid columns: share the width left over, clip
 *   axi-ann-col-people      one Author cell: axi-ann-person lines (created, then is-edit)
 *     axi-ann-person-name, axi-ann-person-when
 *   axi-ann-col-acts        Edit/Delete, never squeezed out of view
 *
 * Positions come from CSS custom properties the script sets through CSSOM:
 * --axi-ann-x, --axi-ann-y, --axi-ann-top, --axi-ann-h, --axi-ann-w; the card:
 * --axi-ann-card-x, --axi-ann-card-y (viewport position of its dot).
 * Colours only from --axi-* / --vt-* / --bs-* variables.
 */
.axi-ann-host {
    position: relative;
}

.axi-ann-layer {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 2;
    --axi-ann-c: var(--axi-muted);
}

.axi-ann--site_change { --axi-ann-c: var(--vt-blue); }
.axi-ann--campaign { --axi-ann-c: var(--vt-purple); }
.axi-ann--promotion { --axi-ann-c: var(--vt-green); }
.axi-ann--tracking { --axi-ann-c: var(--vt-yellow); }
.axi-ann--external { --axi-ann-c: var(--axi-n-bg); }
.axi-ann--other,
.axi-ann--mixed { --axi-ann-c: var(--axi-muted); }

.axi-ann-band {
    position: absolute;
    left: var(--axi-ann-x);
    top: var(--axi-ann-top);
    width: var(--axi-ann-w);
    height: var(--axi-ann-h);
    background: var(--axi-ann-c);
    opacity: .08;
}

.axi-ann-line {
    position: absolute;
    left: var(--axi-ann-x);
    top: var(--axi-ann-top);
    height: var(--axi-ann-h);
    width: 0;
    border-left: 1px dashed var(--axi-ann-c);
    opacity: .7;
}

.axi-ann-dot {
    position: absolute;
    left: var(--axi-ann-x);
    top: var(--axi-ann-y);
    width: 12px;
    height: 12px;
    padding: 0;
    margin: 0;
    transform: translate(-50%, -50%);
    border: 2px solid var(--vt-card-bg, var(--bs-body-bg));
    border-radius: 50%;
    background: var(--axi-ann-c);
    box-shadow: 0 0 0 1px var(--axi-ann-c);
    cursor: pointer;
    pointer-events: auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.axi-ann-dot:focus-visible {
    outline: 2px solid var(--axi-accent);
    outline-offset: 2px;
}

.axi-ann-dot--cluster {
    width: 18px;
    height: 18px;
}

.axi-ann-count {
    color: var(--bs-white);
    font-size: 10px;
    font-weight: 600;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.axi-ann-all-day {
    position: absolute;
    left: var(--axi-ann-x);
    top: var(--axi-ann-y);
    transform: translate(12px, -50%);
    color: var(--axi-muted);
    font-size: 11px;
    white-space: nowrap;
}

.axi-ann-error {
    position: absolute;
    top: 4px;
    right: 4px;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--vt-red-soft);
    color: var(--vt-red-text);
    font-size: 11px;
    pointer-events: auto;
}

.axi-ann-truncated {
    background: var(--vt-yellow-soft);
    color: var(--bs-gray-800, #3f4254);
}

/* ---- Interactions (chart-annotations-ui.js) ---- */

.axi-ann-chip {
    position: absolute;
    left: var(--axi-ann-x);
    top: var(--axi-ann-y);
    z-index: 3;
    transform: translate(-50%, 8px);
    padding: 3px 10px;
    border: 1px solid var(--axi-accent);
    border-radius: 999px;
    background: var(--vt-card-bg, var(--bs-body-bg));
    color: var(--axi-accent);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(var(--axi-ink-rgb), .12);
}

.axi-ann-chip:focus-visible {
    outline: 2px solid var(--axi-accent);
    outline-offset: 2px;
}

.axi-ann-card {
    position: fixed;
    left: var(--axi-ann-card-x);
    top: var(--axi-ann-card-y);
    z-index: 1060;
    transform: translate(-50%, calc(-100% - 12px));
    width: 320px;
    max-width: calc(100vw - 24px);
    max-height: 60vh;
    overflow-y: auto;
    padding: 12px 14px;
    border: 1px solid var(--axi-line);
    border-radius: 12px;
    background: var(--vt-card-bg, var(--bs-body-bg));
    color: var(--axi-ink);
    font-size: 12.5px;
    box-shadow: 0 8px 24px rgba(var(--axi-ink-rgb), .16);
    pointer-events: none;
}

.axi-ann-card--pinned {
    pointer-events: auto;
    padding-top: 28px;
}

.axi-ann-card-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 10px;
    height: 10px;
}

.axi-ann-card-note + .axi-ann-card-note {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--axi-line-2, var(--axi-line));
}

.axi-ann-card-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    margin-bottom: 4px;
}

.axi-ann-card-date {
    color: var(--axi-muted);
}

.axi-ann-card-title {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.axi-ann-card-desc {
    margin: 4px 0 0;
    color: var(--axi-ink-2, var(--axi-ink));
    white-space: pre-line;
    overflow-wrap: anywhere;
}

.axi-ann-card-meta {
    margin-top: 8px;
    color: var(--axi-muted);
    font-size: 11.5px;
}

.axi-ann-card-meta-line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.axi-ann-card-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.axi-ann-cat {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 1px 8px;
    border-radius: 999px;
    background: var(--axi-page);
    font-size: 11.5px;
    font-weight: 600;
}

.axi-ann-swatch {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 2px;
    background: var(--axi-ann-c, var(--axi-muted));
}

.axi-ann-badge {
    padding: 0 6px;
    border-radius: 6px;
    background: var(--vt-purple-soft);
    color: var(--vt-purple);
    font-size: 11px;
    font-weight: 600;
}

.axi-ann-menu {
    min-width: 260px;
}

/* "+ Annotation" in the menu is the same orange primary as on the list page and in the modal:
   the global rule turns a focused btn-primary ink-black, and the button keeps the focus a
   mouse click gave it (opening the modal, a click inside the menu), so outside a real hover,
   press or keyboard focus it stays orange with white text. */
.axi-ann-menu .btn.btn-primary.axi-ann-menu-add:not(:hover):not(:active):not(:focus-visible) {
    background-color: #ff7f00 !important;
    border-color: #ff7f00 !important;
    color: #fff !important;
}

/* The trigger's label: hidden on a phone, and next to the docked Axi panel (which takes 420px
   of the content from xl) until the screen is wide enough for the header row to stay on one
   line; the icon keeps the label as its title and aria-label. */
.axi-ann-control-label {
    display: none;
}

@media (min-width: 768px) {
    .axi-ann-control-label {
        display: inline;
    }
}

@media (min-width: 1200px) and (max-width: 1919.98px) {
    .axi-root--asst-docked .axi-ann-control-label {
        display: none;
    }
}

@media (max-width: 575.98px) {
    .axi-ann-card,
    .axi-ann-card--pinned {
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        width: 100%;
        max-width: none;
        max-height: 70vh;
        transform: none;
        border-radius: 14px 14px 0 0;
    }
}

/* List page: the table fits the content next to the docked Axi panel (about 700px at 1440px)
   without a sideways scroll. Title and description take no min-content width (max-width: 0)
   and share what the fixed columns leave, clipping with an ellipsis (full text in `title`);
   the title keeps a readable minimum. */
.axi-ann-list .axi-lst-table td.axi-ann-col-title {
    width: 30%;
    min-width: 72px;
    max-width: 0;
}

.axi-ann-list .axi-lst-table td.axi-ann-col-desc {
    width: 40%;
    max-width: 0;
}

.axi-ann-list .axi-lst-table td.axi-ann-col-title .axi-lst-clip,
.axi-ann-list .axi-lst-table td.axi-ann-col-desc .axi-lst-clip {
    max-width: 100%;
}

.axi-ann-list .axi-lst-table td.axi-ann-col-date {
    min-width: 104px;
}

/* A date range may break after its dash instead of widening the table. */
.axi-ann-list .axi-lst-table td.axi-ann-col-date .axi-lst-l1 {
    white-space: normal;
}

.axi-ann-person {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 6px;
    max-width: 150px;
    white-space: nowrap;
}

/* The name takes what the date leaves and clips (full text in the line's `title`); a "via Axi"
   badge drops below when the line is full. */
.axi-ann-person-name {
    flex: 1 1 0;
    min-width: 56px;
    overflow: hidden;
    font-weight: 600;
    color: var(--axi-ink);
    text-overflow: ellipsis;
}

.axi-ann-person-when {
    flex-shrink: 0;
    font-size: 12px;
    color: var(--axi-muted, #6B7494);
}

.axi-ann-person.is-edit {
    margin-top: 1px;
}

.axi-ann-person.is-edit .axi-ann-person-name i {
    margin-right: 3px;
    font-size: 11px;
}

.axi-ann-person.is-edit .axi-ann-person-name {
    font-size: 12px;
    font-weight: 400;
    color: var(--axi-muted, #6B7494);
}

.axi-ann-list .axi-lst-table td.axi-ann-col-acts {
    width: 1%;
    white-space: nowrap;
}
