/* =====================================================================
   Bientôt — shared UI pieces (ui.js): draggable sheets, dialogs, loading skeletons,
   pull-to-refresh, empty / error states, field errors. Uses the v3 tokens only, so the
   dark theme (app.css) applies by itself.
   ===================================================================== */

/* ---------- sheets: ui.js moves them (springs), CSS only draws them ---------- */
#popup-sheet,
#qr-popup {
    transition: none;
    will-change: transform;
    overscroll-behavior: contain;
}

#popup-overlay {
    transition: none;
}

#popup-sheet .popup-handle,
#qr-popup .popup-handle {
    position: relative;
    cursor: grab;
    touch-action: none;
}

/* a finger-sized grip around the 5 px handle */
#popup-sheet .popup-handle::before,
#qr-popup .popup-handle::before {
    content: "";
    position: absolute;
    inset: -14px -70px -10px;
}

#popup-sheet .sheet-head,
#qr-popup .sheet-head {
    cursor: grab;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

#popup-sheet.dragging,
#qr-popup.dragging,
#popup-sheet.dragging .popup-handle,
#qr-popup.dragging .popup-handle,
#popup-sheet.dragging .sheet-head,
#qr-popup.dragging .sheet-head {
    cursor: grabbing;
}

#popup-sheet.dragging .popup-handle,
#qr-popup.dragging .popup-handle {
    background: var(--muted);
}

/* the page behind a sheet or dialog doesn't scroll */
html.sheet-open .app-page {
    overflow: hidden;
}

/* ---------- dialogs ---------- */
#dialog-layer {
    position: absolute;
    inset: 0;
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(10, 12, 30, .45);
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s;
}

#dialog-layer:empty {
    display: none;
}

#dialog-layer.show {
    opacity: 1;
    visibility: visible;
}

.dialog {
    width: 100%;
    max-width: 340px;
    max-height: calc(100% - 32px);
    overflow-y: auto;
    background: var(--surface);
    color: var(--text);
    border-radius: 24px;
    padding: 24px 20px 16px;
    text-align: center;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .28);
    transform: scale(.9) translateY(10px);
    transition: transform .34s cubic-bezier(.34, 1.45, .64, 1);
}

#dialog-layer.show .dialog {
    transform: none;
}

#dialog-layer.hide .dialog {
    transform: scale(.96);
    transition-duration: .18s;
}

.dialog-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    margin: 0 auto 14px;
    display: grid;
    place-items: center;
    background: var(--fill);
    color: var(--primary);
}

.dialog-icon .ic {
    width: 26px;
    height: 26px;
}

.tone-danger .dialog-icon {
    background: var(--pill-negative-bg);
    color: var(--negative);
}

.tone-warning .dialog-icon {
    background: var(--pill-warning-bg);
    color: var(--pill-warning-ink);
}

.tone-positive .dialog-icon {
    background: var(--pill-positive-bg);
    color: var(--positive);
}

.dialog-title {
    font-family: var(--display);
    font-size: 21px;
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.2;
}

.dialog-msg {
    margin-top: 8px;
    color: var(--muted);
    font-size: var(--fs-body);
    line-height: 1.45;
}

.dialog-hint {
    margin-top: 14px;
    font-size: 14px;
    color: var(--muted);
}

.dialog-hint b {
    color: var(--text);
    font-weight: 600;
    user-select: all;
}

.dialog-field {
    display: block;
    margin-top: 12px;
    text-align: left;
}

.dialog-field .form-label {
    margin: 0 0 6px 4px;
}

.dialog-input {
    width: 100%;
    height: 48px;
    border: 0;
    border-radius: 14px;
    background: var(--fill);
    padding: 0 14px;
    font: inherit;
    font-size: 16px;
    color: var(--text);
    outline: none;
}

.dialog-input:focus {
    box-shadow: inset 0 0 0 2px var(--primary);
}

.dialog-error {
    display: block;
    margin: 6px 4px 0;
    color: var(--negative);
    font-size: 13px;
}

.dialog-error:empty {
    display: none;
}

.dialog-actions {
    display: flex;
    gap: 10px;
    margin-top: 22px;
}

.dialog-actions .btn {
    flex: 1;
    min-width: 0;
}

.dialog-actions.stack {
    flex-direction: column-reverse;
}

.btn-danger-solid {
    background: var(--negative);
    color: #fff;
}

.dialog-actions .btn:disabled {
    opacity: .4;
    pointer-events: none;
}

/* ---------- loading skeletons ---------- */
.skel {
    background: linear-gradient(90deg, var(--fill) 25%, var(--raised) 50%, var(--fill) 75%);
    background-size: 300% 100%;
    animation: skel 1.3s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes skel {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}

.skel-row {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 12px 16px;
}

.skel-thumb {
    width: 56px;
    height: 56px;
    border-radius: var(--r-thumb);
    flex: none;
}

.skel-lines {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.skel-line {
    height: 12px;
}

.skel-line.w70 { width: 70%; }
.skel-line.w40 { width: 40%; }

.skel-card {
    margin-bottom: 18px;
}

.skel-media {
    height: 170px;
    border-radius: var(--r-card);
    margin-bottom: 12px;
}

.skel-card .skel-line {
    margin-top: 8px;
}

@media (prefers-reduced-motion: reduce) {
    .skel { animation: none; }
}

/* ---------- empty / error states ---------- */
.empty-sub {
    display: block;
}

.empty-action {
    margin-top: 16px;
}

.view-error .ic {
    color: var(--muted);
}

/* ---------- load more ---------- */
.paged-more {
    width: 100%;
    margin-top: 10px;
    background: var(--surface);
    border-radius: var(--r-card);
    min-height: 48px;
}

.group .paged-more {
    margin-top: 0;
    border-radius: 0;
}

/* ---------- pull to refresh ---------- */
.ptr {
    position: absolute;
    top: calc(var(--native-top, 0px) + 10px);
    left: 50%;
    z-index: 30;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: var(--surface);
    box-shadow: 0 6px 18px rgba(0, 0, 0, .14);
    display: grid;
    place-items: center;
    opacity: 0;
    transform: translate3d(-50%, -44px, 0);
    pointer-events: none;
}

.ptr-spin {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2.2px solid var(--fill);
    border-top-color: var(--muted);
}

.ptr.ready .ptr-spin {
    border-top-color: var(--accent);
}

.ptr.spinning .ptr-spin {
    border-top-color: var(--accent);
    animation: spin .8s linear infinite;
}

/* ---------- server field errors under form fields ---------- */
.field-error {
    display: block;
    margin-top: 4px;
    color: var(--negative);
    font-size: 13px;
    line-height: 1.35;
}

.has-error .form-label,
.has-error .auth-label {
    color: var(--negative);
}
