/* MediaBridge — frontend styles
   Scoped under .ab-modal / .ab-busy / .ab-result so they don't bleed
   into theme styles. Loaded only on single posts that have the
   MediaBridge payload localized. */

.ab-modal {
    position: fixed;
    inset: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
}
.ab-modal[hidden] { display: none; }

.ab-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 15, 20, 0.65);
    backdrop-filter: blur(2px);
}

.ab-modal-box {
    position: relative;
    background: #1f2024;
    color: #f1f1f3;
    border-radius: 12px;
    padding: 28px 24px 22px;
    min-width: 320px;
    max-width: 460px;
    width: 92%;
    box-shadow: 0 18px 48px rgba(0,0,0,0.5);
    direction: rtl;
}

.ab-modal-title {
    margin: 0 0 14px;
    font-size: 17px;
    font-weight: 600;
    text-align: center;
}

.ab-modal-body {
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ab-modal-close {
    position: absolute;
    top: 8px;
    left: 8px;
    background: transparent;
    color: #aaa;
    border: 0;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
}
.ab-modal-close:hover { color: #fff; background: rgba(255,255,255,0.08); }

body.ab-modal-open { overflow: hidden; }

/* ── Spinner ───────────────────────────────── */
.ab-spinner {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 8px;
}
.ab-spinner-dot {
    width: 22px; height: 22px;
    border: 3px solid rgba(255,255,255,0.15);
    border-top-color: #4f9cff;
    border-radius: 50%;
    animation: ab-spin 0.9s linear infinite;
}
.ab-spinner-text { font-size: 14px; opacity: 0.92; }
@keyframes ab-spin { to { transform: rotate(360deg); } }

/* ── Result ────────────────────────────────── */
.ab-result {
    width: 100%;
    text-align: center;
}
.ab-result-ok {
    color: #4ade80;
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 6px;
}
.ab-result-file {
    color: #d0d0d4;
    font-size: 12px;
    word-break: break-all;
    margin-bottom: 14px;
    opacity: 0.85;
}
.ab-result-actions {
    display: flex;
    gap: 8px;
    justify-content: center;
    margin-bottom: 10px;
}
.ab-btn {
    background: #2c2e33;
    color: #f1f1f3;
    border: 1px solid rgba(255,255,255,0.1);
    padding: 8px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    transition: background 0.15s;
}
.ab-btn:hover { background: #3a3c43; }
.ab-btn-primary {
    background: #4f9cff;
    border-color: #4f9cff;
    color: #fff;
}
.ab-btn-primary:hover { background: #3b8cf0; }

.ab-result-link {
    width: 100%;
    background: #15161a;
    color: #d0d0d4;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 11px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    direction: ltr;
    text-align: left;
    margin-top: 4px;
}

.ab-result-err {
    color: #ff8a8a;
    font-size: 14px;
    padding: 16px 8px;
}

/* Inner wrapper for the error message text inside .ab-result-err,
   so the action row can sit directly below it inside the same
   coloured block instead of stacking as a separate top-level row. */
.ab-result-err-msg {
    margin-bottom: 0;
}

/* When the bot call fails, the error modal surfaces a single
   "use direct link" button so the user isn't stranded on a dead
   error. The action row lives inside .ab-result.ab-result-err so
   the whole block reads as one cohesive error card; .ab-result-fallback
   is the inner slim wrapper that centres the button. */
.ab-result-fallback {
    margin-top: 12px;
    justify-content: center;
}
.ab-result-fallback .ab-btn-primary {
    min-width: 160px;
}

/* ── Button state during generation ────────── */
.ab-busy {
    opacity: 0.7;
    cursor: progress;
    pointer-events: none;
}

/* ── Source chooser modal (scanner vs bot) ── */
.ab-source-choice {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0;
}
.ab-source-title {
    margin: 0 0 4px;
    font-size: 15px;
    font-weight: 600;
    color: #f1f1f5;
    text-align: center;
}
.ab-source-row {
    display: grid;
    grid-template-columns: 40px 1fr auto;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    transition: background 0.15s ease, border-color 0.15s ease;
}
.ab-source-row:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.18);
}
.ab-source-icon {
    font-size: 22px;
    line-height: 1;
    text-align: center;
}
.ab-source-meta {
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: start;
}
.ab-source-meta strong {
    color: #f1f1f5;
    font-size: 14px;
    font-weight: 600;
}
.ab-source-meta span {
    color: #999;
    font-size: 12px;
}

/* ────────────────────────────────────────────
   Three-option chooser enhancements
   ──────────────────────────────────────────── */
.ab-source-row[data-disabled="1"] {
    opacity: 0.45;
    cursor: not-allowed;
}
.ab-source-row[data-disabled="1"] .ab-btn {
    cursor: not-allowed;
}
.ab-source-meta small {
    display: inline-block;
    margin-top: 2px;
    font-size: 11.5px;
}

/* Bulk runner */
.ab-bulk {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 320px;
}
.ab-bulk-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.ab-bulk-progress {
    margin: 0;
    font-size: 12.5px;
    color: #999;
}
.ab-bulk-progress-count {
    font-weight: 800;
    color: #fff;
}
.ab-bulk-list {
    max-height: 50vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px 0;
}
.ab-bulk-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: var(--ab-panel2, rgba(255,255,255,0.04));
    border: 1px solid var(--ab-line, rgba(255,255,255,0.08));
    border-radius: 8px;
    font-size: 12.5px;
    transition: background 0.18s, border-color 0.18s;
}
.ab-bulk-row[data-status="done"] {
    border-color: rgba(31,157,77,0.45);
    background: rgba(31,157,77,0.10);
}
.ab-bulk-row[data-status="error"] {
    border-color: rgba(225,29,42,0.45);
    background: rgba(225,29,42,0.08);
}
.ab-bulk-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid rgba(255,255,255,0.25);
    border-top-color: #fff;
    border-radius: 50%;
    flex: 0 0 auto;
    animation: ab-bulk-spin 0.8s linear infinite;
}
.ab-bulk-row[data-status="done"] .ab-bulk-spinner,
.ab-bulk-row[data-status="error"] .ab-bulk-spinner {
    display: none;
}
@keyframes ab-bulk-spin {
    to { transform: rotate(360deg); }
}
.ab-bulk-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ab-bulk-status {
    flex: 0 0 auto;
    font-size: 13px;
}

.ab-bulk-result {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 320px;
}
.ab-bulk-summary {
    font-size: 13.5px;
    font-weight: 700;
    color: #fff;
}
.ab-bulk-textarea {
    width: 100%;
    min-width: 320px;
    box-sizing: border-box;
    background: var(--ab-panel2, rgba(255,255,255,0.04));
    border: 1px solid var(--ab-line, rgba(255,255,255,0.12));
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--ab-text, #e7eaee);
    font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
    font-size: 12.5px;
    line-height: 1.7;
    resize: vertical;
    direction: ltr;
    text-align: left;
}
.ab-bulk-textarea:focus {
    outline: 0;
    border-color: rgba(31,157,77,0.5);
}
.ab-bulk-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}
.ab-bulk-empty {
    padding: 14px;
    background: rgba(225,29,42,0.06);
    border: 1px dashed rgba(225,29,42,0.32);
    border-radius: 8px;
    color: #999;
    font-size: 13px;
    text-align: center;
}

/* ────────────────────────────────────────────
   Play-button ±5 pre-fetch UX
   ──────────────────────────────────────────── */

/* Inline "Please wait; the link is being generated" status
   shown when the user navigates outside the pre-fetched
   window. Kept inside the same .ab-result frame so the modal
   padding/spacing matches the other states. */
.ab-play-generating {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 4px 4px;
}
.ab-play-generating-title {
    font-size: 15px;
    font-weight: 700;
    color: #f1f1f3;
    text-align: center;
}
.ab-play-generating-sub {
    font-size: 12.5px;
    color: #b0b0b6;
    text-align: center;
    opacity: 0.9;
}
.ab-play-generating .ab-spinner {
    padding: 4px 8px;
}
.ab-play-generating .ab-spinner-dot {
    border-top-color: #D4AF67;
}

/* Soft "from cache" hint appended to the result headline. */
.ab-result-cached {
    font-size: 12px;
    font-weight: 500;
    color: #8aa6c0;
    margin-inline-start: 4px;
}

/* Soft "your ±5 window is now ready" banner that briefly appears
   inside the modal after a successful background pre-fetch. Uses
   a subtle gold accent so it doesn't look like an error. */
.ab-play-window-ready {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
    padding: 7px 12px;
    background: rgba(212, 175, 103, 0.10);
    border: 1px solid rgba(212, 175, 103, 0.32);
    border-radius: 8px;
    color: #D4AF67;
    font-size: 12.5px;
    font-weight: 500;
}
.ab-play-window-icon { font-size: 14px; }
