/**
 * Chat Log Admin Styles
 *
 * Professional styling for chat log list table and modal viewer
 *
 * @package    AnswerRails
 * @subpackage Admin/Assets
 * @since      3.3.0
 */

/* ========================================
   List Table Enhancements
   ======================================== */

.wp-list-table .column-turns {
    width: 80px;
    text-align: center;
}

.wp-list-table .column-session {
    width: 140px;
}

.wp-list-table .column-quality {
    width: 80px;
    text-align: center;
}

.wp-list-table .column-date {
    width: 100px;
}

/* ========================================
   Badge Styles
   ======================================== */

.turns-badge {
    display: inline-block;
    padding: 3px 8px;
    background: #f0f0f1;
    border-radius: 3px;
    font-weight: 500;
    font-size: 13px;
}

.badge-anonymous {
    display: inline-block;
    background: #2271b1;
    color: white;
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
}

.session-id {
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 12px;
    background: #f0f0f1;
    padding: 2px 6px;
    border-radius: 3px;
}
.turns-none {
    color: #999;
    font-style: italic;
}

/* ========================================
   Quality Score Badges
   ======================================== */

.quality-score {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 3px;
    font-weight: bold;
    font-size: 13px;
    min-width: 35px;
    text-align: center;
}

.quality-excellent {
    background: #46b450;
    color: white;
}

.quality-good {
    background: #ffb900;
    color: white;
}

.quality-fair {
    background: #f56e28;
    color: white;
}

.quality-poor {
    background: #dc3232;
    color: white;
}

.quality-none {
    background: #dcdcde;
    color: #666;
}

/* ========================================
   Modal Overlay
   ======================================== */

.chatlog-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.chatlog-modal {
    background: white;
    border-radius: 4px;
    box-shadow: 0 5px 25px rgba(0, 0, 0, 0.3);
    width: 100%;
    max-width: 800px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Modal Header
   ======================================== */

.chatlog-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #dcdcde;
}

.chatlog-modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chatlog-modal-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: #646970;
    transition: color 0.2s;
}

.chatlog-modal-close:hover {
    color: #1d2327;
}

.chatlog-modal-close .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
}

/* ========================================
   Modal Content
   ======================================== */

.chatlog-modal-content {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.chatlog-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: #646970;
}

.chatlog-loading .spinner {
    float: none;
    margin-right: 10px;
}

/* Conversation Metadata */
.conversation-metadata {
    background: #f9f9f9;
    border: 1px solid #dcdcde;
    border-radius: 4px;
    padding: 16px;
    margin-bottom: 24px;
}

.metadata-row {
    display: flex;
    gap: 20px;
    margin-bottom: 8px;
}

.metadata-row:last-child {
    margin-bottom: 0;
}

.metadata-label {
    font-weight: 600;
    color: #1d2327;
    min-width: 100px;
}

.metadata-value {
    color: #3c434a;
}

.privacy-notice {
    background: #e7f5fe;
    border-left: 4px solid #2271b1;
    padding: 12px 16px;
    margin-top: 16px;
}

.privacy-notice p {
    margin: 0;
    color: #1d2327;
}

/* Conversation Display */
.conversation-turns {
    margin-top: 24px;
}

.conversation-turn {
    padding: 16px;
    margin-bottom: 12px;
    border-radius: 4px;
    border: 1px solid #dcdcde;
}

.conversation-turn.user {
    background: #f0f6fc;
    border-left: 4px solid #2271b1;
}

.conversation-turn.assistant {
    background: #f9f9f9;
    border-left: 4px solid #46b450;
}

.turn-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    /* #128: the row must WRAP. A moderated turn's meta line carries the full
       #124 provenance form (action — provider-flagged: category · score ·
       model) which can exceed the modal width on its own; the path badge
       made that pre-existing overflow visible as a horizontal scrollbar. */
    flex-wrap: wrap;
}

.turn-role {
    font-weight: 600;
    color: #1d2327;
}

.turn-role.user {
    color: #2271b1;
}

.turn-role.assistant {
    color: #46b450;
}

.turn-timestamp {
    font-size: 12px;
    color: #646970;
}

.turn-content {
    color: #3c434a;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ========================================
   Modal Footer
   ======================================== */

.chatlog-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid #dcdcde;
    background: #f9f9f9;
}

/* ========================================
   Responsive Design
   ======================================== */

@media (max-width: 782px) {
    .chatlog-modal {
        max-width: 100%;
        max-height: 95vh;
    }

    .chatlog-modal-header,
    .chatlog-modal-content,
    .chatlog-modal-footer {
        padding: 16px;
    }

    .metadata-row {
        flex-direction: column;
        gap: 4px;
    }

    .metadata-label {
        min-width: auto;
    }

    .wp-list-table .column-session {
        display: none;
    }
}

/* ========================================
   Loading States
   ======================================== */

.chatlog-modal.loading .chatlog-modal-content {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}
/* Per-turn provider / model / API metadata (#69) */
.conversation-turn .turn-provider-meta {
    margin-left: auto;
    font-size: 11px;
    color: #787c82;
    background: #f0f0f1;
    border-radius: 3px;
    padding: 1px 6px;
    /* #128: was `nowrap`, which forced a long provenance string to extend the
       header row past the modal edge. It wraps now; the path badge keeps its
       own nowrap because it is short and must not break mid-label. */
    white-space: normal;
    overflow-wrap: anywhere;
    min-width: 0;
}

/* Per-turn cited sources (#69 follow-up) */
.conversation-turn .turn-citations {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px dashed #dcdcde;
    font-size: 12px;
    color: #646970;
}

/* Sales-lead flag on a turn (#70) */
.conversation-turn .turn-lead {
    margin-top: 6px;
    padding: 4px 8px;
    background: #fcf9e8;
    border-left: 3px solid #dba617;
    font-size: 12px;
    color: #646970;
}

/* Idea captured on this turn (v3.4.0) */
.conversation-turn .turn-idea {
    margin-top: 6px;
    padding: 4px 8px;
    background: #fdf3e7;
    border-left: 3px solid #e07b00;
    font-size: 12px;
    color: #646970;
}

/* Ideas count badge in the Chat Log list (v3.4.0) */
.ideas-count-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    background: #fdf3e7;
    border: 1px solid #e07b00;
    color: #8a4b00;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.ideas-none {
    color: #8c8f94;
}

/* ========================================
   Privacy subject-search panel (#110)
   ======================================== */

.answerrails-privacy-panel {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-left: 4px solid #2271b1;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.04);
    margin: 12px 0;
    padding: 0;
}

.answerrails-privacy-panel > summary {
    cursor: pointer;
    font-weight: 600;
    padding: 10px 12px;
    user-select: none;
}

.answerrails-privacy-panel > summary .dashicons {
    margin-right: 4px;
    vertical-align: text-bottom;
}

.answerrails-privacy-panel-body {
    border-top: 1px solid #f0f0f1;
    padding: 12px;
}

.answerrails-privacy-search-row {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 8px 0;
}

.answerrails-privacy-search-row input[type="text"] {
    min-width: 240px;
}

.answerrails-privacy-search-row #answerrails-privacy-phone {
    min-width: 180px;
}

.answerrails-privacy-search-row .spinner {
    float: none;
    margin: 0;
}

.answerrails-privacy-results {
    border: 1px solid #f0f0f1;
    margin: 8px 0;
    padding: 4px 12px;
}

.answerrails-privacy-group h4 {
    margin: 10px 0 4px;
}

.answerrails-privacy-group ul {
    margin: 0 0 8px 16px;
}

.answerrails-privacy-actions {
    display: flex;
    gap: 8px;
    margin: 8px 0;
}

.answerrails-privacy-delete {
    border-color: #d63638 !important;
    color: #d63638 !important;
}

.answerrails-privacy-ledger h4 {
    margin: 12px 0 4px;
}

.answerrails-privacy-ledger-list {
    font-size: 12px;
    margin: 0 0 4px 16px;
}

.answerrails-privacy-notice {
    border-left: 4px solid #00a32a;
    margin: 8px 0;
    padding: 8px 12px;
    white-space: pre-line;
}

.answerrails-privacy-notice.notice-error {
    border-left-color: #d63638;
}

/* #119 moderation column (D7): flag badge, legal-hold label, hold toggle */
.moderation-flag-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    background: #fcf0e4;
    color: #996800;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.legal-hold-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    background: #b32d2e;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

/* #130: hold lifted, erasure still owed. Amber rather than the hold's red —
   this is an action the controller still has to take, not a restriction. */
.erasure-pending-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    background: #bd5b00;
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.ar-erasure-deferred-list {
    margin: 6px 0 0;
}

.ar-erasure-deferred-list li {
    margin: 0 0 4px;
}

.ar-hold-toggle {
    display: inline-block;
    margin-left: 4px;
    font-size: 11px;
    text-decoration: none;
}

/* ------------------------------------------------------------------
 * #128 — per-turn pipeline path + deflected-payload disclosure.
 * The path badge sits BESIDE the provider meta line, never inside it:
 * on a moderated turn that line carries the #124 provenance judgment,
 * and a path label must never read as the verdict (D3).
 * ------------------------------------------------------------------ */
.conversation-turn .turn-path {
    margin-left: 6px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 3px;
    padding: 1px 6px;
    white-space: nowrap;
    background: #f0f0f1;
    color: #50575e;
    border: 1px solid #dcdcde;
}

/* The three deflection/block branches read as interventions, not answers. */
.conversation-turn .turn-path.ar-path-moderated,
.conversation-turn .turn-path.ar-path-fabricated,
.conversation-turn .turn-path.ar-path-ungrounded_deflected {
    background: #fcf0f1;
    color: #8a2424;
    border-color: #f0c3c3;
}

.conversation-turn .turn-path.ar-path-handoff,
.conversation-turn .turn-path.ar-path-answered_ungrounded {
    background: #fcf9e8;
    color: #7a5b00;
    border-color: #ecd98a;
}

.conversation-turn .turn-path.ar-path-grounded {
    background: #edfaef;
    color: #1e5e2a;
    border-color: #b8e0c0;
}

/* D4: inert disclosure of what the model said before the deflection. */
.conversation-turn .turn-deflection {
    margin-top: 6px;
    padding: 4px 8px;
    background: #f6f7f7;
    border-left: 3px solid #a7aaad;
    font-size: 12px;
    color: #646970;
}

.conversation-turn .turn-deflection > summary {
    cursor: pointer;
    font-weight: 600;
}

.conversation-turn .turn-deflection-meta,
.conversation-turn .turn-deflection-urls {
    margin: 6px 0 0;
    font-size: 11px;
    color: #787c82;
}

.conversation-turn .turn-deflection-body {
    margin-top: 6px;
    padding: 6px 8px;
    background: #fff;
    border: 1px solid #dcdcde;
    border-radius: 3px;
    white-space: pre-wrap;
}

/* #128 D5: a send that failed. Read as an interruption, not an answer. */
.conversation-turn.system.failed-turn {
    border-left: 3px solid #b32d2e;
    background: #fcf0f1;
}

.conversation-turn .turn-failed-note {
    margin: 4px 0 6px;
    font-size: 11px;
    color: #8a2424;
}

.conversation-turn .turn-failed-shown {
    font-size: 11px;
    font-weight: 600;
    color: #646970;
}

/* #135: citations recorded but never served to the visitor. Muted, so the
   admin reads it as a record rather than as what the visitor saw. */
.conversation-turn .turn-citations.withheld {
    color: #787c82;
    font-style: italic;
}

/* #152: on a grounded turn, recorded sources the used-vs-retrieved filter
   did NOT serve — dimmed beside the served group, so the record stays whole
   without reading as the visitor's view. */
.conversation-turn .turn-citations .turn-citations-not-served {
    color: #787c82;
    font-style: italic;
    opacity: 0.75;
}
