/* W-01/W-03: widget grid affordances, payload rendering and responsive manager. */

/* Bootstrap ships no min-width:0 utility and a flex item refuses to shrink below its content
   width without it, so the compact single-line titles would overflow instead of truncating. */
.min-w-0 {
    min-width: 0;
}

.widget-draggable .card-header {
    cursor: grab;
}

.widget-draggable .card-header[data-widget-drag-handle] {
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
}

.widget-drag-grip {
    color: var(--bs-secondary-color, #6c757d);
    margin-right: .35rem;
    letter-spacing: -.1em;
}

.widget-dragging {
    opacity: .6;
}

.widget-drop-target > .card {
    outline: 2px dashed var(--bs-primary, #0d6efd);
    outline-offset: 2px;
}

/* Default payload renderer: label/value pairs instead of raw JSON. */
.widget-payload dt {
    text-transform: uppercase;
    letter-spacing: .02em;
    font-size: .64rem;
}

.widget-payload dd {
    font-variant-numeric: tabular-nums;
    font-size: .85rem;
    line-height: 1.25;
}

.widget-payload-raw summary {
    cursor: pointer;
}

/* Widget icons (W-01 §6A): the plugin ships a 64x64 PNG/WebP and the host serves it read-only. */
.widget-icon {
    border-radius: .4rem;
    object-fit: cover;
    vertical-align: -0.2em;
}

.widget-icon-lg {
    border-radius: .5rem;
    flex: 0 0 auto;
}

.widget-catalog-icon {
    border-radius: .5rem;
    flex: 0 0 auto;
    object-fit: cover;
}

/* Compact card: the grid shows up to four widgets per row, so the chrome (header, actions and
   status line) must not steal space from the data. Cards are inline-size containers so the payload
   can reflow when the user resizes a card (see the @container rule below). */
.widget-card {
    container-type: inline-size;
}

.widget-card .card-header {
    padding: .4rem .6rem;
    gap: .35rem;
}

.widget-card .card-header .h6 {
    font-size: .9rem;
    line-height: 1.25;
}

.widget-card .widget-card-meta {
    font-size: .72rem;
    line-height: 1.3;
}

.widget-card .card-body {
    padding: .5rem .6rem;
}

.widget-card .widget-drag-grip {
    margin-right: .2rem;
    font-size: .85rem;
}

/* Card actions: comfortable tap targets on touch widths, compact icons on desktop. */
.widget-actions .btn {
    min-width: 2.75rem;
    min-height: 2.75rem;
    line-height: 1;
}

/* WCAG AA: Bootstrap's outline-secondary text (#6c757d) reaches only 4.41:1 on the card header
   background (#f8f8f9). Darkening the text to #5c636a gives ~5.7:1 without changing the look. */
.widget-actions .btn-outline-secondary {
    --bs-btn-color: #5c636a;
    --bs-btn-border-color: #6c757d;
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: #6c757d;
    --bs-btn-hover-border-color: #6c757d;
}

@media (min-width: 768px) {
    .widget-actions .btn {
        min-width: 1.75rem;
        min-height: 1.75rem;
        padding: .1rem .3rem;
        font-size: .85rem;
    }

    /* WCAG 2.5.8 asks for 24x24 px: the reorder arrows keep that floor and leave the title room. */
    .widget-actions .btn-group .btn {
        min-width: 1.5rem;
        padding: .1rem .2rem;
    }
}

/* W-01: floating widget launchers and cards. */
/* The launchers sit on the top bar surface, where the stock outline-secondary foreground lands at
   4.37:1 (below AA). A darker foreground keeps every launcher readable without touching the global
   palette; the border stays the Bootstrap grey (3:1 is the requirement for non-text UI). */
.widget-launcher-button,
.widget-launcher-more > summary {
    --bs-btn-color: #495057;
    --bs-btn-border-color: #6c757d;
    --bs-btn-hover-color: #212529;
    --bs-btn-hover-bg: #e9ecef;
    --bs-btn-hover-border-color: #6c757d;
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: #495057;
    --bs-btn-active-border-color: #495057;
}

.widget-launcher-button {
    min-width: 2.5rem;
    min-height: 2.5rem;
}

.widget-launcher-more {
    position: relative;
}

.widget-launcher-more > ul {
    position: absolute;
    right: 0;
    z-index: 1055;
    min-width: 15rem;
    max-height: 60vh;
    overflow: auto;
}

/* The canvas is a viewport overlay, not part of the document flow: a card opened from the top bar
   must stay visible whatever the scroll position. `pointer-events: none` keeps the page usable
   underneath; only the cards themselves capture the pointer. The top offset leaves the top bar
   (and its launchers) reachable. */
.floating-canvas {
    position: fixed;
    inset: 3.5rem 0 0 0;
    overflow: visible;
    pointer-events: none;
    z-index: 1045;
}

.floating-widget-card {
    position: absolute;
    pointer-events: auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1045;
    max-height: 60vh;
    box-shadow: 0 .5rem 1.5rem rgba(0, 0, 0, .18);
}

/* Only the body scrolls, so the header (drag handle and actions) stays reachable. */
.floating-widget-card .card-body {
    overflow: auto;
    min-height: 0;
}

/* Resize handle (bottom-right corner): pointer events are handled by widget-floating.js. */
.floating-widget-resize {
    position: absolute;
    right: 0;
    bottom: 0;
    width: 1rem;
    height: 1rem;
    cursor: nwse-resize;
    touch-action: none;
}

.floating-widget-resize::after {
    content: "";
    position: absolute;
    right: 3px;
    bottom: 3px;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--bs-secondary-color, #6c757d);
    border-bottom: 2px solid var(--bs-secondary-color, #6c757d);
    border-bottom-right-radius: 2px;
    opacity: .75;
}

.floating-resizing {
    user-select: none;
}

/* Narrow cards (resized by the user or the S preset) switch the payload to a single column. */
@container (max-width: 360px) {
    .widget-payload .col {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .widget-card-meta {
        font-size: .68rem;
    }

    .widget-payload dd {
        font-size: .8rem;
    }
}

.floating-widget-card [data-floating-handle] {
    cursor: grab;
    touch-action: none;
    user-select: none;
}

/* Keyboard users move the card from the title area (arrow keys); keep the focus visible. */
.floating-widget-card [role="group"]:focus-visible {
    outline: 2px solid var(--bs-primary, #0d6efd);
    outline-offset: 2px;
    border-radius: .25rem;
}

.floating-dragging {
    opacity: .9;
    cursor: grabbing;
}

/* Mobile: the launcher opens a full-screen sheet instead of a floating card. */
.floating-canvas-sheet .floating-widget-card {
    position: fixed;
    inset: 0;
    left: 0 !important;
    top: 0 !important;
    width: auto !important;
    height: auto !important;
    max-height: none;
    border-radius: 0;
    z-index: 1085;
}

.floating-canvas-sheet .floating-widget-resize {
    display: none;
}