/* =========================================================
   Image labels (includes/image-labels.js). Linked by the topic viewer
   (learn/view.php), the admin editor (admin.php), the presentation view
   (learn/includes/present.php) and bundled into the SCORM export
   (api/export-scorm.php). An image card with labels
   wraps its <img> in .simg-frame, a box that shrink-wraps the image
   exactly, so the parts' left/top percentages mean the same spot at any
   size. Each label is a red dot on the spot it names, a pill with its
   text, and a thin line between them (an SVG over the frame, 0-100
   viewBox, stretched to the image). Each pill is centred on its line's
   end by a .simg-slot row (see image-labels.js); a pill too wide to
   centre stops at the image edge. A label with a description is a
   <button data-def>: the topic viewer's glossary popover shows the
   description. Everything stays light on the photo in both themes and
   prints as it looks on screen.
   ========================================================= */
.simg-frame {
    position: relative;
    display: block;
    width: fit-content;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
}
.simg-frame > img {
    display: block;
    max-width: 100%;
    height: auto;
}
.simg-align-left .simg-frame { margin-left: 0; }
.simg-align-right .simg-frame { margin-right: 0; }

/* Drawings and text (image-labels.js): an SVG whose viewBox is the
   image's pixel size, so everything scales with the picture. Under the
   label lines, dots and pills; never catches clicks. */
.simg-draw {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}
.simg-lines {
    position: absolute;
    inset: 0;
    z-index: 1;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}
.simg-lines line {
    stroke: #17375C;
    stroke-width: 1.5px;
    stroke-linecap: round;
    vector-effect: non-scaling-stroke;
}
.simg-lines line.simg-halo {
    stroke: #fff;
    stroke-width: 4px;
}
.simg-dot {
    position: absolute;
    z-index: 2;
    box-sizing: border-box;
    width: 11px;
    height: 11px;
    margin: 0;
    padding: 0;
    translate: -50% -50%;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #E03131;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45);
    pointer-events: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

/* The pill's row: a zero-height flex line across the image (left / width
   / top / direction written inline; right-half rows are rtl so "safe"
   falls back to the right edge). "safe" keeps a pill that cannot be
   centred inside the image; browsers without it simply centre. */
.simg-slot {
    position: absolute;
    z-index: 3;
    height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    justify-content: safe center;
    pointer-events: none;
}

/* Absolute + inline left/top/translate is the markup labels were saved
   with before the slots (2026-10-16); it keeps working until the topic is
   saved again in the editor, which writes slots. */
.simg-label {
    position: absolute;
    z-index: 3;
    box-sizing: border-box;
    max-width: 100%;
    margin: 0;
    padding: 0.2em 0.6em;
    border: 1.5px solid #17375C;
    border-radius: 999px;
    background: #fff;
    color: #17375C;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    font-style: normal;
    line-height: 1.3;
    letter-spacing: 0;
    text-align: center;
    text-transform: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    cursor: default;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.simg-slot > .simg-label {
    position: relative;
    direction: ltr;
    flex: none;
    max-width: none;
    pointer-events: auto;
}
button.simg-label {
    cursor: pointer;
    text-decoration: underline dotted;
    text-underline-offset: 0.18em;
}
button.simg-label:hover,
button.simg-label[aria-describedby] {
    background: #17375C;
    color: #fff;
}
button.simg-label:focus-visible {
    outline: var(--focus-outline, 2px solid #3A6FA8);
    outline-offset: 2px;
}
@media (max-width: 600px) {
    .simg-label { font-size: 0.68rem; padding: 0.15em 0.45em; border-width: 1px; }
}
/* Hide / show labels: a pill in the image's bottom corner (image-labels.js).
   Hiding is a screen-only state; paper always shows the labels and never
   the button. The editor and the Image Details preview show no button. */
.simg-toggle {
    position: absolute;
    right: 6px;
    bottom: 6px;
    z-index: 4;
    display: inline-flex;
    align-items: center;
    gap: 0.3em;
    margin: 0;
    padding: 0.28em 0.65em;
    border: 0;
    border-radius: 999px;
    background: rgba(23, 55, 92, 0.82);
    color: #fff;
    font-family: inherit;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.simg-toggle:hover { background: rgba(23, 55, 92, 0.95); }
.simg-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.ql-editor .simg-toggle,
.iml-preview .simg-toggle { display: none; }
@media screen {
    .simg-labels-hidden :is(.simg-lines, .simg-dot, .simg-slot),
    .simg-labels-hidden > .simg-label { display: none; }
}
@media print {
    .simg-toggle { display: none; }
    /* The topic print styles turn overflow back on, so a long label wraps
       inside its pill instead of running past it. */
    .simg-label,
    button.simg-label { box-shadow: none; text-decoration: none; white-space: normal; font-size: 0.68rem; }
}

/* Click-to-zoom copy (flImageLabels.zoomCopy) in the topic viewer's and
   the SCORM package's enlarged view: the script sizes the image in px,
   so the enlarged view's own image sizing must not apply. */
.simg-frame.simg-zoom { margin: 0; cursor: default; }
.simg-zoom > img {
    min-width: 0 !important;
    max-width: none !important;
    max-height: none !important;
    object-fit: fill !important;
    border-radius: 12px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
    cursor: default;
}
.simg-zoom .simg-label { font-size: 0.95rem; }
.simg-zoom .simg-dot { width: 14px; height: 14px; }
