/**
 * LinkDetailModal — Cyberpunk Link Detail Overlay
 * Shows full link metadata (Overview) + check history (History).
 * Follows the same design language as lgc-overlay / modal-overlay used elsewhere.
 */

/* ============================================================
   OVERLAY / BACKDROP
   ============================================================ */

.ldm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, 0.88);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99997; /* below confirm (99998) and toasts (99999) */
    padding: 16px;

    /* Hidden by default */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.ldm-overlay.ldm-overlay--visible {
    opacity: 1;
    visibility: visible;
}

/* ============================================================
   MODAL CONTAINER
   ============================================================ */

.ldm-modal {
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    background: rgba(13, 13, 20, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.12);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Cyberpunk angular corners — matches lgc-modal */
    clip-path: polygon(
        0 0,
        calc(100% - 18px) 0,
        100% 18px,
        100% 100%,
        18px 100%,
        0 calc(100% - 18px)
    );

    box-shadow:
        0 24px 64px rgba(0, 0, 0, 0.65),
        0 0 0 1px rgba(0, 245, 212, 0.08);

    transform: translateY(16px) scale(0.97);
    transition: transform 0.25s ease;
}

.ldm-overlay.ldm-overlay--visible .ldm-modal {
    transform: translateY(0) scale(1);
}

/* ============================================================
   HEADER
   ============================================================ */

.ldm-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 20px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    position: relative;
}

/* Animated top border line — cyan glow */
.ldm-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--neon-cyan), transparent);
    opacity: 0.5;
}

.ldm-header-icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 245, 212, 0.08);
    border: 1px solid rgba(0, 245, 212, 0.2);
    border-radius: 6px;
    color: var(--neon-cyan);
}

.ldm-header-icon svg {
    width: 18px;
    height: 18px;
}

.ldm-title {
    flex: 1;
    margin: 0;
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.8px;
    text-transform: uppercase;
    /* Long URLs should truncate */
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ldm-close-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.ldm-close-btn:hover {
    background: rgba(247, 37, 133, 0.12);
    border-color: rgba(247, 37, 133, 0.35);
    color: var(--neon-magenta);
}

.ldm-close-btn:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: 2px;
}

.ldm-close-btn svg {
    width: 14px;
    height: 14px;
}

/* ============================================================
   SCROLLABLE BODY
   ============================================================ */

.ldm-body {
    overflow-y: auto;
    flex: 1;
    padding: 20px;
    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 245, 212, 0.25) transparent;
}

.ldm-body::-webkit-scrollbar {
    width: 4px;
}

.ldm-body::-webkit-scrollbar-track {
    background: transparent;
}

.ldm-body::-webkit-scrollbar-thumb {
    background: rgba(0, 245, 212, 0.25);
    border-radius: 2px;
}

/* ============================================================
   LOADING STATE
   ============================================================ */

.ldm-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    gap: 16px;
}

.ldm-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 245, 212, 0.15);
    border-top-color: var(--neon-cyan);
    border-radius: 50%;
    animation: ldm-spin 0.85s linear infinite;
}

@keyframes ldm-spin {
    to { transform: rotate(360deg); }
}

.ldm-loading p {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    margin: 0;
}

/* ============================================================
   SECTION HEADINGS
   ============================================================ */

.ldm-section {
    margin-bottom: 24px;
}

.ldm-section:last-child {
    margin-bottom: 0;
}

.ldm-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--neon-cyan);
    margin: 0 0 12px 0;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(0, 245, 212, 0.15);
}

.ldm-section-title svg {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ============================================================
   OVERVIEW GRID  (label / value pairs)
   ============================================================ */

.ldm-overview-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 20px;
    align-items: start;
}

.ldm-overview-label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    white-space: nowrap;
    padding-top: 1px; /* optical alignment with value text */
}

.ldm-overview-value {
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--text-primary);
    word-break: break-all;
    min-width: 0;
}

/* URL value with copy button inline */
.ldm-url-value {
    display: flex;
    align-items: center;
    gap: 6px;
}

.ldm-url-text {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1;
}

.ldm-copy-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.ldm-copy-btn:hover {
    border-color: rgba(0, 245, 212, 0.4);
    color: var(--neon-cyan);
    background: rgba(0, 245, 212, 0.06);
}

.ldm-copy-btn:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: 2px;
}

.ldm-copy-btn svg {
    width: 12px;
    height: 12px;
}

/* Rel/anchor mismatch display */
.ldm-rel-match {
    color: var(--neon-cyan);
    font-family: var(--font-mono);
    font-size: 11px;
}

.ldm-rel-mismatch {
    color: var(--neon-magenta);
    font-family: var(--font-mono);
    font-size: 11px;
    text-shadow: 0 0 8px rgba(247, 37, 133, 0.3);
}

.ldm-rel-pending {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
}

/* Tag pills */
.ldm-tag-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.ldm-tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    border-radius: 3px;
    clip-path: polygon(0 0, calc(100% - 4px) 0, 100% 4px, 100% 100%, 4px 100%, 0 calc(100% - 4px));
    background: rgba(76, 201, 240, 0.1);
    border: 1px solid rgba(76, 201, 240, 0.3);
    color: var(--neon-blue);
}

/* Consecutive errors badge */
.ldm-errors-badge {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--neon-magenta);
    text-shadow: 0 0 8px rgba(247, 37, 133, 0.4);
}

/* Cost and expires — mono */
.ldm-mono-value {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
}

/* Notes text block */
.ldm-notes-text {
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
    white-space: pre-wrap;
    margin: 0;
}

/* ============================================================
   CHECK HISTORY TIMELINE
   ============================================================ */

.ldm-history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Single history row */
.ldm-history-row {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.07);
    padding: 10px 14px;
    clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
    transition: border-color 0.2s ease;
}

.ldm-history-row:hover {
    border-color: rgba(0, 245, 212, 0.15);
}

.ldm-history-row--error {
    border-color: rgba(247, 37, 133, 0.25);
    background: rgba(247, 37, 133, 0.04);
}

/* Transient / self-healing checks (upstream timeout, SERP-provider retry, …) —
   amber, not the red hard-failure treatment. */
.ldm-history-row--transient {
    border-color: rgba(254, 228, 64, 0.22);
    background: rgba(254, 228, 64, 0.04);
}

.ldm-history-row-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.ldm-history-row-left {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.ldm-history-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.ldm-history-icon--error {
    color: var(--neon-magenta);
    filter: drop-shadow(0 0 4px rgba(247, 37, 133, 0.5));
}

.ldm-history-icon--transient {
    color: var(--neon-yellow);
    filter: drop-shadow(0 0 4px rgba(254, 228, 64, 0.45));
}

.ldm-history-icon svg {
    width: 14px;
    height: 14px;
}

.ldm-history-label {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ldm-history-detail {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 2px;
}

.ldm-history-detail-value {
    color: var(--text-secondary);
}

.ldm-history-detail-value--ok {
    color: var(--neon-cyan);
}

.ldm-history-detail-value--warn {
    color: var(--neon-yellow);
}

/* Error block inside a history row */
.ldm-error-block {
    margin-top: 8px;
    padding: 8px 12px;
    background: rgba(247, 37, 133, 0.08);
    border: 1px solid rgba(247, 37, 133, 0.25);
    clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 6px 100%, 0 calc(100% - 6px));
}

.ldm-error-code {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 700;
    color: var(--neon-magenta);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.ldm-error-message {
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: rgba(247, 37, 133, 0.85);
    line-height: 1.5;
    margin: 0;
}

/* Amber variant of the error block for transient / self-healing checks. */
.ldm-error-block--transient {
    background: rgba(254, 228, 64, 0.08);
    border-color: rgba(254, 228, 64, 0.25);
}

.ldm-error-block--transient .ldm-error-code {
    color: var(--neon-yellow);
}

.ldm-error-block--transient .ldm-error-message {
    color: rgba(254, 228, 64, 0.9);
}

/* ============================================================
   "WHY THIS STATUS" PANEL — plain-language status explanation,
   shown at the top of the modal for every status.
   ============================================================ */

.ldm-why {
    margin: 0 0 18px;
    padding: 14px 16px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-left-width: 3px;
    clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
}

.ldm-why-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.ldm-why-icon {
    flex: 0 0 auto;
    width: 16px;
    height: 16px;
    display: inline-flex;
}
.ldm-why-icon svg { width: 16px; height: 16px; }

.ldm-why-title {
    font-family: var(--font-display, var(--font-body));
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: 0.2px;
}

.ldm-why-detail {
    margin: 0;
    font-family: var(--font-body);
    font-size: 0.85rem;
    line-height: 1.55;
    color: var(--text-secondary, #b8c0c8);
}

.ldm-why-action {
    margin: 8px 0 0;
    font-family: var(--font-body);
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-primary);
    opacity: 0.9;
}
.ldm-why-action::before {
    content: "→ ";
    color: var(--neon-cyan);
    font-weight: 700;
}

/* Tone variants — accent the left border + icon. */
.ldm-why--ok      { border-left-color: var(--neon-cyan); }
.ldm-why--ok      .ldm-why-icon { color: var(--neon-cyan); }
.ldm-why--warn    { border-left-color: var(--neon-yellow); background: rgba(254, 228, 64, 0.05); }
.ldm-why--warn    .ldm-why-icon { color: var(--neon-yellow); }
.ldm-why--risk    { border-left-color: var(--neon-magenta); background: rgba(247, 37, 133, 0.06); }
.ldm-why--risk    .ldm-why-icon { color: var(--neon-magenta); }
.ldm-why--neutral { border-left-color: var(--neon-blue, #4895ef); }
.ldm-why--neutral .ldm-why-icon { color: var(--neon-blue, #4895ef); }
.ldm-why--info    { border-left-color: rgba(255, 255, 255, 0.4); }
.ldm-why--info    .ldm-why-icon { color: var(--text-secondary, #b8c0c8); }

/* ============================================================
   EMPTY HISTORY STATE
   ============================================================ */

.ldm-empty-history {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 32px 20px;
    gap: 12px;
}

.ldm-empty-history-icon {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 245, 212, 0.05);
    border: 1px solid rgba(0, 245, 212, 0.15);
    border-radius: 50%;
    color: var(--neon-cyan);
    opacity: 0.6;
}

.ldm-empty-history-icon svg {
    width: 22px;
    height: 22px;
}

.ldm-empty-history p {
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--text-muted);
    margin: 0;
    line-height: 1.5;
}

/* Run Check button inside empty history state */
.ldm-run-check-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    background: rgba(0, 245, 212, 0.08);
    border: 1px solid rgba(0, 245, 212, 0.3);
    color: var(--neon-cyan);
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    cursor: pointer;
    transition: all 0.2s ease;
    clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 6px 100%, 0 calc(100% - 6px));
}

.ldm-run-check-btn:hover {
    background: rgba(0, 245, 212, 0.15);
    border-color: var(--neon-cyan);
    box-shadow: 0 0 14px rgba(0, 245, 212, 0.2);
    transform: translateY(-1px);
}

.ldm-run-check-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.ldm-run-check-btn svg {
    width: 13px;
    height: 13px;
}

/* btn-spinner re-use */
.ldm-run-check-btn .btn-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(0, 245, 212, 0.3);
    border-top-color: var(--neon-cyan);
    border-radius: 50%;
    animation: ldm-spin 0.7s linear infinite;
    flex-shrink: 0;
}

/* ============================================================
   CLICKABLE ROW STYLES (monitoring table / cards)
   ============================================================ */

/* Table rows */
.monitoring-table tbody tr[data-link-id] {
    cursor: pointer;
}

.monitoring-table tbody tr[data-link-id]:hover {
    background: rgba(0, 245, 212, 0.05);
}

.monitoring-table tbody tr[data-link-id]:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: -2px;
}

/* Mobile cards */
.monitoring-link-card[data-link-id] {
    cursor: pointer;
}

.monitoring-link-card[data-link-id]:hover {
    border-color: rgba(0, 245, 212, 0.25);
    background: rgba(0, 245, 212, 0.03);
}

.monitoring-link-card[data-link-id]:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: 2px;
}

/* group_detail.html table row clickable */
.link-table tbody tr[data-link-id],
.links-table tbody tr[data-link-id] {
    cursor: pointer;
}

.link-table tbody tr[data-link-id]:hover,
.links-table tbody tr[data-link-id]:hover {
    background: rgba(0, 245, 212, 0.04);
}

.link-table tbody tr[data-link-id]:focus-visible,
.links-table tbody tr[data-link-id]:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: -2px;
}

/* ============================================================
   RESPONSIVE — full-screen on small screens
   ============================================================ */

@media (max-width: 768px) {
    .ldm-overlay {
        padding: 8px;
        align-items: flex-start;
        padding-top: 5vh;
    }

    .ldm-modal {
        max-width: 100%;
        max-height: 90vh;
    }

    /* Expand close button to meet 44px touch target on mobile */
    .ldm-close-btn {
        width: 44px;
        height: 44px;
    }

    .ldm-overview-grid {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .ldm-overview-label {
        margin-top: 8px;
    }

    .ldm-overview-label:first-child {
        margin-top: 0;
    }
}

@media (max-width: 480px) {
    .ldm-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .ldm-modal {
        max-height: 96vh;
        clip-path: polygon(
            0 0,
            calc(100% - 14px) 0,
            100% 14px,
            100% 100%,
            0 100%
        );
    }
}

/* ============================================================
   REDUCED MOTION
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .ldm-overlay,
    .ldm-modal,
    .ldm-run-check-btn {
        transition: none !important;
        animation: none !important;
    }

    .ldm-loading-spinner,
    .ldm-run-check-btn .btn-spinner {
        animation: none !important;
    }
}

/* ============================================================
   EDIT BUTTON (header)
   ============================================================ */

.ldm-edit-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: rgba(0, 245, 212, 0.07);
    border: 1px solid rgba(0, 245, 212, 0.25);
    color: var(--neon-cyan);
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 6px 100%, 0 calc(100% - 6px));
    flex-shrink: 0;
}

.ldm-edit-btn:hover {
    background: rgba(0, 245, 212, 0.15);
    border-color: var(--neon-cyan);
    box-shadow: 0 0 12px rgba(0, 245, 212, 0.2);
    transform: translateY(-2px);
}

.ldm-edit-btn:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: 2px;
}

.ldm-edit-btn svg {
    width: 12px;
    height: 12px;
    flex-shrink: 0;
}

/* ============================================================
   MODAL FOOTER (edit mode)
   ============================================================ */

.ldm-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    background: rgba(10, 10, 15, 0.6);
}

.ldm-footer-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ldm-footer-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ============================================================
   FOOTER BUTTONS (.ldm-btn)
   ============================================================ */

.ldm-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
    clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 6px, 100% 100%, 6px 100%, 0 calc(100% - 6px));
}

.ldm-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.ldm-btn:focus-visible {
    outline: 2px solid var(--neon-cyan);
    outline-offset: 2px;
}

.ldm-btn svg {
    width: 13px;
    height: 13px;
    flex-shrink: 0;
}

.ldm-btn .btn-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(0, 245, 212, 0.3);
    border-top-color: var(--neon-cyan);
    border-radius: 50%;
    animation: ldm-spin 0.7s linear infinite;
    flex-shrink: 0;
}

/* Primary — cyan */
.ldm-btn--primary {
    background: rgba(0, 245, 212, 0.12);
    border-color: rgba(0, 245, 212, 0.4);
    color: var(--neon-cyan);
}

.ldm-btn--primary:not(:disabled):hover {
    background: rgba(0, 245, 212, 0.22);
    border-color: var(--neon-cyan);
    box-shadow: 0 0 16px rgba(0, 245, 212, 0.25);
    transform: translateY(-2px);
}

/* Ghost — transparent */
.ldm-btn--ghost {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.15);
    color: var(--text-secondary);
}

.ldm-btn--ghost:not(:disabled):hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.3);
    color: var(--text-primary);
    transform: translateY(-2px);
}

/* Danger — magenta outline */
.ldm-btn--danger {
    background: transparent;
    border-color: rgba(247, 37, 133, 0.3);
    color: var(--neon-magenta);
}

.ldm-btn--danger:not(:disabled):hover {
    background: rgba(247, 37, 133, 0.1);
    border-color: var(--neon-magenta);
    box-shadow: 0 0 14px rgba(247, 37, 133, 0.25);
    transform: translateY(-2px);
}

/* Danger solid — filled (confirm state) */
.ldm-btn--danger-solid {
    background: rgba(247, 37, 133, 0.18);
    border-color: rgba(247, 37, 133, 0.55);
    color: var(--neon-magenta);
}

.ldm-btn--danger-solid:not(:disabled):hover {
    background: rgba(247, 37, 133, 0.28);
    border-color: var(--neon-magenta);
    box-shadow: 0 0 18px rgba(247, 37, 133, 0.35);
    transform: translateY(-2px);
}

.ldm-btn--danger-solid .btn-spinner {
    border-color: rgba(247, 37, 133, 0.3);
    border-top-color: var(--neon-magenta);
}

/* ============================================================
   DELETE INLINE CONFIRM
   ============================================================ */

.ldm-delete-confirm {
    display: flex;
    align-items: center;
    gap: 8px;
    animation: ldm-fade-in 0.15s ease;
}

@keyframes ldm-fade-in {
    from { opacity: 0; transform: translateX(-6px); }
    to   { opacity: 1; transform: translateX(0); }
}

.ldm-delete-confirm-label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--neon-magenta);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

/* ============================================================
   EDIT FORM
   ============================================================ */

.ldm-edit-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ldm-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.ldm-field-label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
}

.ldm-field-required {
    color: var(--neon-magenta);
    margin-left: 2px;
}

.ldm-field-input,
.ldm-field-select {
    width: 100%;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    border-radius: 4px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
    appearance: none;
    -webkit-appearance: none;
}

.ldm-field-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%238899a6' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
    cursor: pointer;
}

.ldm-field-textarea {
    resize: vertical;
    min-height: 60px;
    line-height: 1.5;
    font-family: var(--font-body);
}

.ldm-field-input:focus,
.ldm-field-select:focus {
    outline: none;
    border-color: rgba(0, 245, 212, 0.5);
    box-shadow: 0 0 0 2px rgba(0, 245, 212, 0.1);
}

.ldm-field-input--error,
.ldm-field-input--error:focus {
    border-color: rgba(247, 37, 133, 0.6) !important;
    box-shadow: 0 0 0 2px rgba(247, 37, 133, 0.1) !important;
}

.ldm-field-error {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--neon-magenta);
    min-height: 14px;
    display: block;
}

.ldm-field-help {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-muted);
}

/* Dark option styling for selects */
.ldm-field-select option {
    background: #0d0d14;
    color: var(--text-primary);
}

/* ============================================================
   RESPONSIVE — edit form
   ============================================================ */

@media (max-width: 480px) {
    .ldm-footer {
        flex-wrap: wrap;
        gap: 8px;
    }

    .ldm-footer-left,
    .ldm-footer-right {
        flex-wrap: wrap;
        gap: 6px;
    }

    .ldm-delete-confirm {
        flex-wrap: wrap;
    }

    /* Prevent iOS input zoom — all form inputs must be >= 16px on mobile */
    .ldm-field-input,
    .ldm-field-select {
        font-size: 16px;
    }
}

/* ============================================================
   REDUCED MOTION — edit additions
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
    .ldm-edit-btn,
    .ldm-btn,
    .ldm-delete-confirm {
        transition: none !important;
        animation: none !important;
    }
}

/* ============================================================
   PURCHASE PANEL (Recovery Ledger P2) — mounted inside the modal
   ============================================================ */

.pp-empty {
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.5;
    margin: 2px 0 14px;
}

.pp-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
}

.pp-form .pp-actions {
    margin-top: 18px;
}

/* ============================================================
   RECOVERY PANEL (Recovery Ledger P3) — lifecycle timeline + states
   ============================================================ */

.rp-current {
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 14px;
}

.rp-badge {
    display: inline-block;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    padding: 3px 9px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: var(--text-secondary);
    clip-path: polygon(4px 0, 100% 0, 100% calc(100% - 4px), calc(100% - 4px) 100%, 0 100%, 0 4px);
}
.rp-badge--alerted              { border-color: rgba(254, 228, 64, 0.5);  color: #fee440; }
.rp-badge--outreach_sent        { border-color: rgba(0, 245, 212, 0.5);   color: #00f5d4; }
.rp-badge--replacement_promised { border-color: rgba(0, 245, 212, 0.5);   color: #00f5d4; }
.rp-badge--replaced             { border-color: rgba(80, 220, 140, 0.6);  color: #50dc8c; }
.rp-badge--refund_requested     { border-color: rgba(0, 245, 212, 0.5);   color: #00f5d4; }
.rp-badge--refund_received      { border-color: rgba(80, 220, 140, 0.7);  color: #50dc8c; }
.rp-badge--written_off          { border-color: rgba(255, 255, 255, 0.22); color: var(--text-muted); }

.rp-timeline { list-style: none; margin: 0 0 4px; padding: 0; }
.rp-event { display: flex; gap: 12px; padding: 8px 0; }
.rp-event-dot {
    flex: 0 0 auto;
    width: 8px; height: 8px; margin-top: 7px;
    background: var(--neon-cyan, #00f5d4);
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
}
.rp-event-body { flex: 1 1 auto; }
.rp-event-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rp-event-time { font-size: 12px; color: var(--text-muted); }
.rp-amount { font-family: var(--font-mono, monospace); font-size: 12px; color: #50dc8c; }
.rp-note { font-size: 13px; color: var(--text-secondary); line-height: 1.45; margin-top: 4px; }

.rp-action-row { flex-wrap: wrap; justify-content: flex-start; }
.rp-form-title {
    font-family: var(--font-display, 'Orbitron', sans-serif);
    font-size: 15px; color: var(--text-primary); margin: 0 0 12px;
}
.rp-draft { margin: 2px 0 6px; }
.rp-draft a { color: var(--neon-cyan, #00f5d4); }
.rp-terminal { font-size: 13px; color: var(--text-muted); margin: 12px 0 0; }

/* Seller reliability tier badge (Recovery Ledger P4) */
.pp-rel {
    display: inline-block;
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 10px; font-weight: 600; letter-spacing: 0.4px; text-transform: uppercase;
    padding: 2px 7px; margin-left: 6px; vertical-align: middle;
    border: 1px solid rgba(255, 255, 255, 0.2); color: var(--text-muted);
    clip-path: polygon(3px 0, 100% 0, 100% calc(100% - 3px), calc(100% - 3px) 100%, 0 100%, 0 3px);
}
.pp-rel:empty { display: none; }
.pp-rel--trusted  { color: #50dc8c; border-color: rgba(80, 220, 140, 0.6); }
.pp-rel--moderate { color: #00f5d4; border-color: rgba(0, 245, 212, 0.5); }
.pp-rel--risky    { color: #f72585; border-color: rgba(247, 37, 133, 0.6); }
.pp-rel--new      { color: var(--text-muted); border-color: rgba(255, 255, 255, 0.2); }

/* ===== Email draft panel (Auto email drafts) ===== */

.edp-block { margin: 0 0 14px; }
.edp-block-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 10px; margin-bottom: 6px;
}
.edp-label {
    font-family: var(--font-mono, 'JetBrains Mono', monospace);
    font-size: 11px; font-weight: 600; letter-spacing: 0.6px;
    text-transform: uppercase; color: var(--text-muted);
}
.edp-text {
    margin: 0; padding: 12px 14px;
    font-family: inherit; font-size: 13px; line-height: 1.55;
    color: var(--text-secondary);
    white-space: pre-wrap; word-break: break-word;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    clip-path: polygon(6px 0, 100% 0, 100% calc(100% - 6px), calc(100% - 6px) 100%, 0 100%, 0 6px);
}
.edp-alt { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.edp-tips { margin: 0 0 12px; }
.edp-action-row { flex-wrap: wrap; justify-content: flex-start; }
.edp-cost { font-size: 11px; opacity: 0.75; font-weight: 400; }
