/* «Медкарта» (TASK-020F): labs over time, comparison table, documents. */
.medcard-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.medcard-actions .btn .icon { width: 16px; height: 16px; }
.medcard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.medcard-grid > .medcard-labs { grid-column: 1 / -1; }
.medcard-card { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.medcard-card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.medcard-card-head .card-title { margin: 0; margin-right: auto; }
.medcard-card-head .btn .icon { width: 15px; height: 15px; }
.medcard-view { gap: 4px; }
.medcard-filter:empty { display: none; }
.medcard-filter .chip-btn.active, .medcard-view .chip-btn.active, #doc-kinds .chip-btn.active, #lab-panels .chip-btn.active {
  background: var(--accent-soft); color: var(--accent); border-color: transparent;
}
.lab-chip-out { color: var(--red); }
.medcard-note { margin-top: 14px; }
.medcard-flash { background: var(--ok-bg); color: var(--green); border-radius: 10px; padding: 8px 12px; font-size: 13px; }

/* value colours: above / below the lab's reference range */
.lab-num { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lab-num.high, .lab-cell.high { color: var(--red); }
.lab-num.low, .lab-cell.low { color: var(--c-lab-low); }
.lab-num.normal { color: var(--green); }
.lab-cell.high { background: var(--err-bg); }
.lab-cell.low { background: var(--c-lab-low-bg); }
.lab-cell.normal { background: var(--ok-bg); }
.lab-meta { display: block; font-size: 12px; color: var(--text-muted); line-height: 1.35; }
.lab-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.lab-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-left: 4px; }
.lab-dot.high { background: var(--red); }
.lab-dot.low { background: var(--c-lab-low); }
.lab-dot.normal { background: var(--green); }

/* list view */
.lab-list { display: flex; flex-direction: column; }
.lab-group { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); padding: 12px 2px 4px; }
.lab-row {
  display: grid; grid-template-columns: minmax(0, 1fr) 84px minmax(96px, auto); align-items: center; gap: 12px;
  width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--border);
  padding: 10px 4px; font: inherit; color: var(--text); cursor: pointer; border-radius: 8px;
}
.lab-row:hover { background: var(--surface-hover); }
.lab-row:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.lab-name { min-width: 0; }
.lab-title { display: block; font-weight: 550; overflow: hidden; text-overflow: ellipsis; }
.lab-value { text-align: right; }
.lab-value .lab-num { font-size: 16px; }
.lab-spark { width: 84px; height: 28px; color: var(--text-muted); --spark: var(--text-muted); }
.lab-spark.high { --spark-dot: var(--red); }
.lab-spark.low { --spark-dot: var(--c-lab-low); }
.lab-spark.normal { --spark-dot: var(--green); }

/* table view */
.lab-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 12px; }
.lab-table { border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 100%; }
.lab-table th, .lab-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; text-align: right; font-variant-numeric: tabular-nums; }
.lab-table thead th { position: sticky; top: 0; background: var(--bg3); font-weight: 600; color: var(--text-sub); z-index: 1; }
.lab-table .lab-th-name { position: sticky; left: 0; background: var(--bg2); text-align: left; z-index: 2; max-width: 220px; white-space: normal; }
.lab-table thead .lab-th-name { background: var(--bg3); z-index: 3; }
.lab-table .lab-td-ref { color: var(--text-muted); }
.lab-tr-group th { text-align: left; background: var(--bg3); font-size: 12px; font-weight: 650; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.lab-tr-group th span { position: sticky; left: 10px; }
.lab-link { background: none; border: 0; padding: 0; font: inherit; font-weight: 550; color: var(--text); cursor: pointer; text-align: left; }
.lab-link:hover { color: var(--accent); }
.lab-cell { font-weight: 600; }

/* entry form */
.lab-modal-content.card { max-width: 760px; max-height: calc(100vh - 32px); overflow-y: auto; }
#doc-modal .modal-content.card { max-height: calc(100vh - 32px); overflow-y: auto; }
.form-label { display: block; font-size: 13px; font-weight: 600; color: var(--text-sub); margin-bottom: 6px; }
#lab-panels { gap: 6px; }
.lab-chip-repeat { font-weight: 600; }
.lab-rows-head, .lab-input-row { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(70px, 1fr) minmax(64px, .8fr) minmax(130px, 1.4fr) 34px; gap: 6px; align-items: center; }
.lab-rows-head { font-size: 12px; color: var(--text-muted); margin: 12px 0 4px; padding: 0 4px; }
.lab-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.lab-input-row { border-left: 3px solid transparent; padding-left: 4px; border-radius: 4px; }
.lab-input-row.high { border-left-color: var(--red); }
.lab-input-row.low { border-left-color: var(--c-lab-low); }
.lab-input-row.normal { border-left-color: var(--green); }
.modal-content .lab-in { width: 100%; min-width: 0; padding: 8px 9px; font-size: 14px; }
.lab-input-row.high .lab-in-value { color: var(--red); font-weight: 650; }
.lab-input-row.low .lab-in-value { color: var(--c-lab-low); font-weight: 650; }
.lab-in-ref { display: flex; align-items: center; gap: 4px; min-width: 0; }
.lab-dash { color: var(--text-muted); }
.lab-del { width: 34px; height: 34px; border: 0; background: none; color: var(--text-muted); border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.lab-del:hover { background: var(--surface-hover); color: var(--red); }
.lab-del .icon { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

/* detail */
.lab-chart-box { position: relative; height: 240px; margin: 12px 0; }
.lab-history { display: flex; flex-direction: column; }
.lab-hist-row { display: grid; grid-template-columns: 92px 90px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 8px 2px; border-bottom: 1px solid var(--border); }
.lab-hist-row.editing { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.lab-hist-row.editing .lab-hist-actions { grid-column: 1 / -1; justify-content: flex-end; }
.lab-hist-actions { display: flex; gap: 4px; justify-content: flex-end; }
.lab-note { grid-column: 1 / -1; }
.lab-edit-field input { width: 100%; }
.btn-danger-text { color: var(--red); }

/* documents */
.doc-list { display: flex; flex-direction: column; }
.doc-item { display: flex; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--border); }
.doc-icon { flex: none; width: 36px; height: 36px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; background: var(--accent-soft); color: var(--accent); }
.doc-icon .icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.doc-icon.kind-lab { background: var(--ok-bg); color: var(--green); }
.doc-icon.kind-consultation { background: var(--warn-bg); color: var(--yellow); }
.doc-body { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 3px; }
.doc-title { font-weight: 600; overflow-wrap: anywhere; }
.doc-conclusion { font-size: 13px; color: var(--text-sub); white-space: pre-wrap; overflow-wrap: anywhere; }
.doc-conclusion.clamped { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; }
.doc-actions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.medcard-mini-list { display: flex; flex-direction: column; gap: 8px; }
.medcard-mini-row { display: flex; gap: 10px; align-items: center; }

@media (max-width: 860px) {
  .medcard-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .medcard-actions .btn { flex: 1 1 auto; justify-content: center; }
  .lab-row { grid-template-columns: minmax(0, 1fr) auto; }
  .lab-spark { display: none; }
  .lab-rows-head { display: none; }
  .lab-input-row { grid-template-columns: minmax(0, 1fr) 84px 34px; grid-template-areas: "name name del" "value unit unit" "ref ref ref"; padding: 8px 0 8px 8px; border-bottom: 1px solid var(--border); }
  .lab-in-name { grid-area: name; }
  .lab-in-value { grid-area: value; }
  .lab-in-unit { grid-area: unit; }
  .lab-in-ref { grid-area: ref; }
  .lab-del { grid-area: del; }
  .lab-hist-row { grid-template-columns: 84px minmax(0, 1fr); }
  .lab-hist-row .lab-meta:not(.lab-note) { grid-column: 1 / -1; }
  .lab-hist-actions { grid-column: 1 / -1; }
  .lab-hist-row.editing { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lab-modal-content.card { padding: 18px 14px; }
}
.lab-legend-item { white-space: nowrap; }
