/*
 * LogDog AI — Phase D.5: QA mode + confidence heatmap.
 *
 * Strategy (per AGENTIC.md §9.1): heatmap shows where the AI is confident,
 * NOT where it's wrong. Clean (>=0.80) renders invisibly; only yellow / orange
 * / red get a subtle left border.
 *
 * Tiers
 *   .conf-clean   >= 0.80          no treatment
 *   .conf-yellow  0.65 - 0.80      soft yellow border
 *   .conf-orange  0.50 - 0.65      amber border
 *   .conf-red      < 0.50          red border
 *
 * QA mode (body.qa-mode-active) flips cells to contenteditable and opens
 * the source ROI side panel. Outside QA mode, cells are read-only.
 */

/* ------------------------------------------------------------------ *
 * Heatmap base — only visible when the user has the heatmap toggle on.
 * The body class .heatmap-off suppresses all heatmap treatments.
 * ------------------------------------------------------------------ */

.cell-conf {
    position: relative;
    transition: background-color 0.15s, border-left-color 0.15s;
}

.cell-conf.conf-clean {
    /* No visual marker. Clean is invisible by design. */
}

.cell-conf.conf-yellow {
    border-left: 3px solid #f5d27a;
    padding-left: 6px;
}
.cell-conf.conf-orange {
    border-left: 3px solid #e0a14a;
    padding-left: 6px;
}
.cell-conf.conf-red {
    border-left: 3px solid #d65555;
    padding-left: 6px;
}

/* User-corrected cells have a faint blue underline regardless of score. */
.cell-conf.conf-corrected {
    background: rgba(59, 93, 232, 0.06);
}

/* Heatmap off: drop the left border. */
body.heatmap-off .cell-conf.conf-yellow,
body.heatmap-off .cell-conf.conf-orange,
body.heatmap-off .cell-conf.conf-red {
    border-left: none;
    padding-left: inherit;
}

/* ------------------------------------------------------------------ *
 * Read-mode tooltip
 * ------------------------------------------------------------------ */

.qa-tooltip {
    position: fixed;
    z-index: 9999;
    background: #1a2238;
    color: #f4f6fc;
    font-family: 'Space Mono', ui-monospace, monospace;
    font-size: 12px;
    padding: 8px 10px;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    pointer-events: none;
    max-width: 320px;
    line-height: 1.4;
}
.qa-tooltip .qa-tip-score {
    font-weight: bold;
    color: #ffd66e;
}
.qa-tooltip .qa-tip-why {
    color: #c9d3e6;
    margin-top: 2px;
}
.qa-tooltip .qa-tip-thumb {
    margin-top: 6px;
    max-width: 100%;
    border-radius: 4px;
    border: 1px solid #2b3556;
    background: #0f1629;
}

/* ------------------------------------------------------------------ *
 * QA mode toolbar controls
 * ------------------------------------------------------------------ */

.qa-toolbar {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
    flex-shrink: 0;
}
/* Bucket A3 — Data View Redesign: mockup .tbtn treatment (matches
   header Import/Export buttons). ONLY .qa-toggle-btn gets this treatment;
   .qa-corrections-btn + .qa-heatmap-toggle keep their prior styling. */
.qa-toggle-btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    appearance: none;
    background: var(--s1);
    color: var(--tx);
    border: 1px solid var(--bd);
    padding: .42rem .8rem;
    border-radius: var(--rs);
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s;
    white-space: nowrap;
}
.qa-toggle-btn:hover {
    border-color: var(--txm);
}
body.qa-mode-active .qa-toggle-btn {
    background: var(--ac2);
    color: var(--ac);
    border-color: var(--ac);
}

/* qa-corrections-btn + qa-heatmap-toggle — keep legacy treatment, lightly
   refreshed against tokens. */
.qa-corrections-btn,
.qa-heatmap-toggle {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    appearance: none;
    background: var(--s1);
    color: var(--tx);
    border: 1px solid var(--bd);
    padding: .42rem .8rem;
    border-radius: var(--rs);
    font-size: .82rem;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
    transition: all .15s;
    white-space: nowrap;
}
.qa-corrections-btn:hover,
.qa-heatmap-toggle:hover {
    border-color: var(--txm);
}
.qa-corrections-btn .qa-corr-badge {
    background: #3b5de8;
    color: #fff;
    border-radius: 99px;
    padding: 1px 6px;
    margin-left: 0;
    font-size: .66rem;
    font-weight: 600;
}

/* ------------------------------------------------------------------ *
 * QA mode editable cells
 * ------------------------------------------------------------------ */

body.qa-mode-active .cell-conf {
    cursor: pointer;
}
body.qa-mode-active .cell-conf:hover {
    outline: 1px dashed #3b5de8;
    outline-offset: -1px;
}
body.qa-mode-active .cell-conf.editing {
    outline: 2px solid #3b5de8;
    outline-offset: -2px;
    background: #fff;
}
.cell-conf .qa-saved-flash {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    background: #1f9d55;
    color: #fff;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 99px;
    pointer-events: none;
    animation: qaFlash 1.4s ease forwards;
}
@keyframes qaFlash {
    0%   { opacity: 0; }
    20%  { opacity: 1; }
    80%  { opacity: 1; }
    100% { opacity: 0; }
}

/* ------------------------------------------------------------------ *
 * Corrections log dropdown
 * ------------------------------------------------------------------ */

.qa-corrections-panel {
    position: absolute;
    z-index: 8000;
    background: #fff;
    border: 1px solid #d6dbe7;
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.15);
    width: 460px;
    max-width: 92vw;
    max-height: 60vh;
    overflow: auto;
    padding: 10px 12px;
    font-size: 12px;
    color: var(--tx, #0f1629);
}
.qa-corrections-panel .qa-corr-hdr {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid #eaecf3;
}
.qa-corrections-panel .qa-corr-list {
    list-style: none;
    margin: 0;
    padding: 0;
}
.qa-corrections-panel .qa-corr-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
    padding: 6px 4px;
    border-bottom: 1px solid #f1f3f9;
}
.qa-corrections-panel .qa-corr-row:last-child {
    border-bottom: none;
}
.qa-corrections-panel .qa-corr-meta {
    color: #6b7485;
    font-family: 'Space Mono', ui-monospace, monospace;
    font-size: 11px;
}
.qa-corrections-panel .qa-corr-undo {
    appearance: none;
    background: transparent;
    border: 1px solid #d6dbe7;
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    cursor: pointer;
}
.qa-corrections-panel .qa-corr-undo:hover {
    background: #fef3f3;
    border-color: #d65555;
    color: #b13a3a;
}
.qa-corrections-panel .qa-corr-empty {
    color: #6b7485;
    text-align: center;
    padding: 18px;
}

/* ------------------------------------------------------------------ *
 * Smart-propagation prompt
 * ------------------------------------------------------------------ */

.qa-prop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 22, 41, 0.45);
    z-index: 9500;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qa-prop-modal {
    background: #fff;
    border-radius: 10px;
    padding: 20px 22px;
    max-width: 480px;
    width: 92vw;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.3);
    font-size: 13px;
    color: var(--tx, #0f1629);
}
.qa-prop-modal h3 {
    margin: 0 0 8px;
    font-size: 15px;
}
.qa-prop-modal .qa-prop-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}
.qa-prop-modal .qa-prop-actions button {
    appearance: none;
    background: transparent;
    border: 1px solid #d6dbe7;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 12px;
    cursor: pointer;
}
.qa-prop-modal .qa-prop-actions button.primary {
    background: #3b5de8;
    color: #fff;
    border-color: #3b5de8;
}
.qa-prop-modal label {
    display: flex;
    gap: 6px;
    margin: 8px 0;
}
