/* ReSiRai - clinical factors panel ("sharayet-e feli") in the visit card. */

.factors-panel { display: block; }

.factors-group { margin-top: 14px; }
.factors-group-title {
    font-size: 13px;
    font-weight: 700;
    color: #12333f;
    margin: 0 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #e2ebee;
}

.factor-row {
    display: grid;
    grid-template-columns: minmax(150px, 1.2fr) minmax(110px, 0.8fr) minmax(120px, 1fr);
    gap: 8px;
    align-items: center;
    padding: 5px 0;
}

.factor-row label { font-size: 12.5px; color: #33454e; direction: rtl; }
.factor-row label small { color: #7b8b96; font-size: 11px; margin-right: 4px; }
.factor-row label .factor-required { color: #c0392b; }
.factor-row label .factor-short { color: #14879b; font-weight: 600; }
.factor-trend { font-size: 10.5px; color: #7b8b96; white-space: nowrap; }
.factor-row .factor-derived {
    background: #eef3f6;
    color: #456;
    cursor: not-allowed;
}
.factor-weight-range {
    margin: 2px 0 8px;
    font-size: 11px;
    color: #12333f;
    background: #eef7fb;
    border: 1px dashed #9fd3e2;
    border-radius: 8px;
    padding: 6px 10px;
    line-height: 1.9;
}
.factor-weight-range .factor-weight-warn { color: #8a5a00; }

.factor-row input,
.factor-row select {
    width: 100%;
    padding: 5px 8px;
    font-size: 12.5px;
    border: 1px solid #cfdce2;
    border-radius: 8px;
    background: #fff;
    direction: ltr;
    text-align: left;
}

.factor-row input:focus,
.factor-row select:focus { outline: 2px solid #1ba7c0; border-color: #1ba7c0; }

.factor-ref {
    font-size: 11px;
    color: #7b8b96;
    direction: ltr;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.factor-flag {
    grid-column: 1 / -1;
    font-size: 11px;
    color: #b3261e;
    background: #fdecea;
    border-radius: 6px;
    padding: 2px 8px;
    display: none;
}

.factor-row.abnormal .factor-flag { display: inline-block; }
.factor-row.abnormal input { border-color: #b3261e; background: #fdf3f2; }

.factors-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid #e2ebee;
}

.factors-status { font-size: 12px; color: #455a64; }
.factors-status.error { color: #b3261e; }

.factors-empty { font-size: 12.5px; color: #7b8b96; padding: 8px 0; }

/* SuperAdmin test mode bar */
.factors-testbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    background: #fff8e8;
    border: 1px dashed #e2b968;
    border-radius: 10px;
    padding: 8px 12px;
    margin-bottom: 12px;
    font-size: 12.5px;
    color: #7a5a10;
}

.factors-testbar label { display: flex; align-items: center; gap: 6px; font-weight: 700; cursor: pointer; }
.factors-testbar-question { font-weight: 700; }

.factors-testbar select,
.factors-testbar input {
    padding: 4px 8px;
    border: 1px solid #e2b968;
    border-radius: 8px;
    background: #fff;
    font-size: 12px;
    min-width: 160px;
}

.factors-testbar-hint { flex-basis: 100%; color: #9a7a3a; font-size: 11px; }

/* Lab-report extraction review dialog */
.lab-extract-overlay {
    position: fixed;
    inset: 0;
    background: rgba(18, 51, 63, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.lab-extract-dialog {
    background: #fff;
    border-radius: 14px;
    width: min(860px, 94vw);
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 18px 50px rgba(12, 55, 70, 0.35);
}

.lab-extract-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid #e2ebee;
}

.lab-extract-head h3 { margin: 0; font-size: 16px; color: #12333f; }

.lab-extract-body { padding: 14px 18px; overflow: auto; }

.lab-extract-foot {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-top: 1px solid #e2ebee;
}

.lab-extract-status { font-size: 12px; color: #455a64; }
.lab-extract-status.error { color: #b3261e; }

.lab-extract-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 10px;
    margin: 10px 0 14px;
}

.lab-extract-pick {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    border: 1px solid #cfdce2;
    border-radius: 10px;
    padding: 8px;
    cursor: pointer;
    background: #f8fbfc;
}

.lab-extract-pick img {
    width: 100%;
    height: 90px;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
}

.panel-group { border: 1px solid var(--border, #d5dbe1); border-radius: 10px; margin: 10px 0; background: #fff; }
.panel-group > summary {
    cursor: pointer;
    font-weight: 700;
    padding: 9px 12px;
    color: #2c6e8f;
    list-style: none;
    user-select: none;
}
.panel-group > summary::-webkit-details-marker { display: none; }
.panel-group > summary::before { content: "▸ "; color: #888; }
.panel-group[open] > summary::before { content: "▾ "; }
.panel-group > .lab-extract-table { margin: 0; }

/* دسته‌هایِ بازشوندهٔ پنلِ شرایط فعلی (علائم حیاتی، آزمایشگاه، …). */
.factors-group > summary.factors-group-title {
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.factors-group > summary.factors-group-title::-webkit-details-marker { display: none; }
.factors-group > summary.factors-group-title::before { content: "▸ "; color: #888; }
.factors-group[open] > summary.factors-group-title::before { content: "▾ "; }

/* جست‌وجوی سریعِ تست‌ها در پنلِ شرایط فعلی. */
.factors-search { margin: 4px 0 12px; }
.factors-search input {
    width: 100%;
    padding: 9px 13px;
    border-radius: 10px;
    border: 1px solid var(--border, #d5dbe1);
    font-size: 14px;
    background: #fff;
}
.factors-search input:focus {
    outline: none;
    border-color: var(--primary, #2c6e8f);
    box-shadow: 0 0 0 3px rgba(44, 110, 143, .12);
}

.lab-extract-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-top: 10px;
}

.lab-extract-table th,
.lab-extract-table td {
    border: 1px solid #e2ebee;
    padding: 6px 8px;
    text-align: right;
    vertical-align: middle;
}

.lab-extract-table th { background: #f2f7f9; color: #12333f; font-weight: 700; }
.lab-extract-table select { width: 100%; padding: 4px 6px; border: 1px solid #cfdce2; border-radius: 6px; }
.lab-extract-add {
    margin-top: 6px;
    padding: 4px 8px;
    font-size: 11px;
    border: 1px dashed #1ba7c0;
    color: #14879b;
    background: #f0fbfd;
    border-radius: 6px;
    cursor: pointer;
}
.lab-extract-add:hover { background: #dff4f8; }
.lab-extract-summary {
    margin-bottom: 10px;
    padding: 10px 14px;
    border-radius: 8px;
    background: #f2f9f4;
    border: 1px solid #bfe3cb;
    font-size: 12px;
    line-height: 2;
}
.lab-extract-summary .sum-warn { color: #8a5a00; }
.lab-extract-summary .sum-ok { color: #1d7a3f; font-weight: 700; }
.lab-extract-summary .sum-item { color: #8a5a00; font-size: 11.5px; }
.lab-extract-summary .sum-hint { color: #7b8b96; font-size: 11px; }
.lab-extract-table tr.is-skipped { background: #fdecea; }
.lab-extract-table tr.is-skipped td { color: #b3261e; }
.lab-extract-table tr.is-saved { background: #eaf7ee; }
.lab-extract-table tr.is-suggested .lab-extract-value {
    background: #fff3d6;
    border-color: #e0b34d;
}
.lab-extract-table tr.is-suggested td:first-child::after {
    content: "پیشنهاد AI";
    display: inline-block;
    margin-right: 4px;
    font-size: 9.5px;
    color: #8a5a00;
    background: #fff3d6;
    border: 1px solid #e0b34d;
    border-radius: 5px;
    padding: 0 4px;
    vertical-align: middle;
}
.lab-extract-act {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin: 0 2px;
    padding: 2px 8px;
    font-size: 11px;
    font-family: inherit;
    border-radius: 6px;
    border: 1px solid #cdd9e0;
    background: #f4f7f9;
    color: #35576b;
    cursor: pointer;
    white-space: nowrap;
}
.lab-extract-act svg { display: block; }
.lab-extract-act:hover { background: #dff4f8; border-color: #9fc7d6; }
.act-peek { color: #2a7da8; }
.act-redo { color: #1d7a3f; border-color: #bfe3cb; background: #f2f9f4; }
.act-redo:hover { background: #e2f4e9; }
.lab-extract-act:disabled { opacity: 0.5; cursor: wait; }
.lab-extract-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 8px 0 6px;
}
.lab-extract-legend { font-size: 10.5px; color: #7b8b96; }
.act-filter.is-on { background: #fff3d6; border-color: #e0b34d; color: #8a5a00; }
.conf-badge {
    display: inline-block;
    margin-right: 6px;
    padding: 0 5px;
    border-radius: 5px;
    font-size: 9.5px;
    font-weight: 700;
    vertical-align: middle;
}
.conf-badge.b-high { background: #eaf7ee; color: #1d7a3f; border: 1px solid #bfe3cb; }
.conf-badge.b-mid { background: #fff3d6; color: #8a5a00; border: 1px solid #e0b34d; }
.conf-badge.b-low { background: #fdecea; color: #b3261e; border: 1px solid #f2b8b5; }
.lab-extract-table tr.conf-low td { background: #fff7f6; }
.lab-extract-table tr.conf-mid td { background: #fffdf5; }
.lab-extract-table .conf-cell { text-align: center; }
/* تحلیلِ ابتداییِ هر ردیف: تناقض قرمز، بیرون از بازه زرد، در محدوده خاکستری. */
.lab-extract-table .an-cell {
    max-width: 300px; overflow: hidden; text-overflow: ellipsis;
    font-size: 12px; color: #444;
}
.lab-extract-table .an-cell.an-error { background: #fdecea; color: #b3261e; font-weight: 600; }
.lab-extract-table .an-cell.an-warn { background: #fff7e0; color: #8a5a00; }
.lab-extract-table .an-cell.an-ok { color: #2e7d32; }
.sum-close { margin-top: 10px; }
.act-icon { padding: 3px 7px; }
.lab-extract-table td .act-icon { margin: 0 auto; display: flex; }
.lab-extract-table tr.is-reread { box-shadow: inset 3px 0 0 #2a7da8; }
.lab-extract-table tr.crop-row td { background: #f6f8fa; text-align: center; }
.crop-img {
    max-width: 100%;
    max-height: 220px;
    border: 1px solid #d7e0e6;
    border-radius: 8px;
    margin: 6px 0;
}
.lab-extract-value {
    width: 100%;
    box-sizing: border-box;
    padding: 3px 6px;
    border: 1px solid #d7e0e6;
    border-radius: 6px;
    font-size: 12px;
    font-family: inherit;
    background: #fffdf5;
}
.lab-extract-value:focus { outline: 2px solid #2a7da8; background: #fff; }
.consult-raw {
    white-space: pre-wrap;
    font-size: 11.5px;
    line-height: 1.9;
    background: #f6f8fa;
    border: 1px solid #d7e0e6;
    border-radius: 8px;
    padding: 10px 12px;
    max-height: 260px;
    overflow: auto;
}

/* AI consultation result */
.consult-meta {
    display: flex;
    gap: 16px;
    font-size: 11.5px;
    color: #7b8b96;
    margin-bottom: 10px;
}

.consult-warning {
    background: #fff6e5;
    border: 1px solid #f0d19b;
    color: #8a5a00;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12.5px;
    margin-bottom: 12px;
}

.consult-redflags {
    background: #fdecea;
    border: 1px solid #f2b8b5;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.consult-redflags h4 { margin: 0 0 6px; font-size: 13px; color: #b3261e; }
.consult-redflags ul,
.consult-workup ul,
.consult-reasons { margin: 0; padding-right: 18px; }

.consult-redflags li { font-size: 12.5px; color: #7a2b25; margin: 3px 0; }

/* Contradictions between values / suspected lab errors: amber, because the
   data itself needs a second look before any diagnosis is built on it. */
.consult-inconsistency {
    background: #fff6e5;
    border: 1px solid #f0cf94;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.consult-inconsistency h4 { margin: 0 0 6px; font-size: 13px; color: #8a5a00; }
.consult-inconsistency ul { margin: 0; padding-right: 18px; }
.consult-inconsistency li { font-size: 12.5px; color: #6e4a00; margin: 6px 0; }
.consult-inconsistency .retest {
    margin-top: 2px;
    font-size: 11.5px;
    color: #1d7a3f;
    background: #eaf7ee;
    border-radius: 6px;
    padding: 3px 8px;
    display: inline-block;
}

.consult-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
    margin: 10px 0 12px;
}

.consult-table th,
.consult-table td {
    border: 1px solid #e2ebee;
    padding: 7px 9px;
    text-align: right;
    vertical-align: top;
}

.consult-table th { background: #f2f7f9; color: #12333f; }

.consult-bar {
    width: 100%;
    height: 8px;
    background: #e6eef1;
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 4px;
}

.consult-bar-fill { height: 100%; background: #1ba7c0; }
.consult-prob { font-size: 11.5px; color: #455a64; direction: ltr; }
.consult-reasons li { font-size: 11.5px; color: #455a64; margin: 2px 0; }

.consult-workup {
    background: #eef7fa;
    border: 1px solid #cfe6ee;
    border-radius: 8px;
    padding: 10px 12px;
}

.consult-workup h4 { margin: 0 0 6px; font-size: 13px; color: #12333f; }
.consult-workup li { font-size: 12.5px; color: #33454e; margin: 3px 0; }
.consult-disclaimer { font-size: 11.5px; color: #7b8b96; }

/* ---- تاریخچهٔ فاکتور و گزارش روند (factors-history.js) ------------------ */
.factor-history-button {
    border: 1px solid #cfe0ee;
    background: #f4f9fe;
    color: #14608f;
    border-radius: 7px;
    padding: 3px 9px;
    font: inherit;
    font-size: 11.5px;
    cursor: pointer;
    white-space: nowrap;
}
.factor-history-button:hover { background: #e6f2fc; border-color: #9fc7e6; }

.factors-modal-overlay {
    position: fixed; inset: 0; z-index: 12000;
    background: rgba(16, 42, 61, .45);
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
}
.factors-modal {
    width: min(960px, 96vw); max-height: 92vh;
    background: #fff; border-radius: 16px;
    box-shadow: 0 24px 70px rgba(18, 51, 74, .35);
    display: flex; flex-direction: column; overflow: hidden;
}
.factors-modal-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 14px 20px; border-bottom: 1px solid #e3edf5; background: #f7fbff;
}
.factors-modal-head h2 { margin: 0; font-size: 16px; color: #0d4e7d; }
.factors-modal-head p { margin: 3px 0 0; font-size: 12px; color: #6b7d8c; }
.factors-modal-actions { display: flex; gap: 8px; }
.factors-modal-body { padding: 16px 20px 20px; overflow: auto; }

.factor-chart-figure { margin: 0 0 16px; }
.factor-chart { width: 100%; height: 240px; background: #fbfdff; border: 1px solid #e3edf5; border-radius: 10px; }
.factor-chart-line { fill: none; stroke: #0877df; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; }
.factor-chart-dot { fill: #fff; stroke: #0877df; stroke-width: 2; }
.factor-chart-band { fill: rgba(60, 190, 130, .13); }
.factor-chart-label { font-size: 11px; fill: #6b7d8c; direction: ltr; }

.factor-history-table td, .factor-history-table th { white-space: nowrap; }
.factor-flag-inline { color: #b42318; font-size: 11.5px; font-weight: 600; }

.factor-matrix-scroll { overflow: auto; max-height: 70vh; }
.factor-matrix th, .factor-matrix td { text-align: center; white-space: nowrap; }
.factor-matrix thead th { position: sticky; top: 0; background: #f2f8fd; z-index: 2; }
.factor-matrix-corner { text-align: right !important; }
.factor-matrix-name { text-align: right !important; position: sticky; right: 0; background: #fbfdff; z-index: 1; min-width: 180px; }
.factor-matrix-unit, .factor-matrix-computed { color: #7b8b96; font-size: 10.5px; }
.factor-matrix-empty { color: #c2cfd9; }
.factor-matrix td.abnormal { background: #fdecea; color: #b42318; }
.factor-matrix-more { margin-top: 12px; }

@media (max-width: 700px) {
    .factors-modal { width: 100vw; max-height: 100vh; border-radius: 0; }
    .factor-chart { height: 190px; }
}

