/* 요약 보고서 내용 스타일 (중앙 패널)
 *
 * 서버가 생성한 요약 HTML(app/services/summary/formatters.py)이 쓰는 클래스들.
 * 레이아웃(3분할)은 style.css 가 담당한다.
 */

/* 그룹 스타일 (대제목: 1, 2, 3) */
.summary-group {
    margin-bottom: 32px;
}

.group-title {
    font-size: 1.2rem;
    font-weight: 600;
    color: white;
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-accent-end) 100%);
    padding: 12px 16px;
    margin: 0 0 16px 0;
    border-radius: 6px;
}

/* 서브그룹 스타일 (중제목: 병리검사, 영상검사 등) */
.summary-subgroup {
    margin-bottom: 24px;
    padding: 16px;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.subgroup-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #212529;
    margin: 0 0 12px 0;
    padding-bottom: 6px;
    border-bottom: 2px solid #dee2e6;
}

/* 섹션 스타일 (소제목: 요약, 상세 정보 등) */
.summary-section {
    margin-bottom: 16px;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: #495057;
    margin: 0 0 8px 0;
}

.section-content {
    padding: 0 0 0 8px;
    font-size: 0.95rem;
    color: #495057;
    line-height: 1.8;
    /* 표가 화면보다 넓으면 이 블록 안에서만 가로로 민다.
     * 없으면 넘친 폭이 .summary-container 로 올라가 요약 패널 전체가 밀리고
     * 제목까지 화면 밖으로 나간다 (모바일에서 실제로 그랬다). */
    overflow-x: auto;
}

.section-content strong {
    color: var(--brand-primary);
    font-weight: 600;
}

/* 테이블 스타일 */
.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin-top: 8px;
}

.summary-table thead {
    background-color: #f8f9fa;
}

.summary-table th {
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: #495057;
    border-bottom: 2px solid #dee2e6;
    white-space: nowrap;
}

.summary-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #e9ecef;
    color: #495057;
    vertical-align: top;
}

.summary-table tbody tr:hover {
    background-color: #f8f9fa;
}

/* 검사 결과 비정상 값 하이라이트 */
.lab-high,
.lab-high strong {
    color: #dc3545;
    font-weight: 600;
}

.lab-low,
.lab-low strong {
    color: #0066cc;
    font-weight: 600;
}

/* 추가 결과 표시 */
.more-results {
    text-align: center;
    color: #6c757d;
    font-size: 0.9rem;
    padding: 10px;
    border-top: 1px solid #e9ecef;
}

/* 검사 결과 접기/펼치기 */
.lab-details {
    margin-top: 12px;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    overflow: hidden;
}

.lab-details summary {
    padding: 10px 16px;
    background: #f8f9fa;
    cursor: pointer;
    font-size: 0.9rem;
    color: #495057;
    user-select: none;
}

.lab-details summary:hover {
    background: #e9ecef;
}

.lab-details-content {
    padding: 16px;
    font-size: 0.85rem;
    color: #495057;
    line-height: 1.8;
    background: #fff;
    max-height: 300px;
    overflow-y: auto;
}

/* 주진단 강조 */
.diagnosis-chief {
    color: var(--brand-primary);
    font-weight: 600;
}

/* 날짜별 그룹화 */
.date-group {
    margin-bottom: 16px;
    padding: 12px;
    background: #ffffff;
    border-radius: 6px;
    border: 1px solid #e9ecef;
}

.date-group:last-child {
    margin-bottom: 0;
}

.date-header {
    font-weight: 600;
    color: #495057;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #dee2e6;
}

.diagnosis-item {
    padding: 4px 0;
    color: #495057;
    line-height: 1.6;
}

/* 날짜 그룹 내 테이블 */
.date-group .summary-table {
    margin-top: 8px;
}

/* 수술 정보 카드 */
.surgical-card {
    margin-bottom: 16px;
    padding: 16px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.surgical-card:last-child {
    margin-bottom: 0;
}

.surgical-header {
    font-weight: 600;
    color: #495057;
    margin-bottom: 10px;
}

.surgical-findings {
    color: #495057;
    line-height: 1.6;
    margin-left: 20px;
    padding-top: 8px;
    border-top: 1px solid #dee2e6;
}

/* 외래 진료 카드 */
.outpatient-card {
    margin-bottom: 16px;
    padding: 16px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.outpatient-card:last-child {
    margin-bottom: 0;
}

.outpatient-header {
    font-weight: 600;
    color: #495057;
    margin-bottom: 10px;
}

.outpatient-content {
    color: #495057;
    line-height: 1.6;
    padding-top: 8px;
    border-top: 1px solid #dee2e6;
}

/* 리스트 스타일 */
.section-content ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.section-content ul li {
    padding: 8px 0;
    border-bottom: 1px solid #e9ecef;
    position: relative;
    padding-left: 16px;
}

.section-content ul li:last-child {
    border-bottom: none;
}

.section-content ul li::before {
    content: "•";
    color: var(--brand-primary);
    font-weight: bold;
    position: absolute;
    left: 0;
}

/* 정의 리스트 스타일 */
.section-content dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 16px;
    margin: 0;
}

.section-content dt {
    font-weight: 600;
    color: var(--brand-primary);
}

.section-content dd {
    margin: 0;
    color: #495057;
}

/* 카드형 섹션 공통 (입원/퇴원 정보) */
.admission-card,
.discharge-card {
    margin-bottom: 16px;
    padding: 16px;
    background: #ffffff;
    border-radius: 8px;
    border: 1px solid #e9ecef;
}

.admission-card:last-child,
.discharge-card:last-child {
    margin-bottom: 0;
}

.admission-header,
.discharge-header {
    font-weight: 600;
    color: #495057;
    margin-bottom: 10px;
}

.admission-details,
.discharge-details {
    color: #495057;
    line-height: 1.6;
    padding-top: 8px;
    border-top: 1px solid #dee2e6;
}

.surgical-meta {
    color: #6c757d;
    font-size: 0.9rem;
    margin-bottom: 8px;
}

.surgical-complications {
    color: #dc3545;
    margin-top: 8px;
}

.no-data {
    text-align: center;
    color: #6c757d;
    padding: 40px 20px;
    font-size: 0.95rem;
}

/* -------------------------------------------------------------------------
 * 출처 표기 — 원본 위치가 있는 항목
 * 클릭하면 우측 문서 뷰어가 해당 페이지로 이동해 하이라이트한다.
 * ---------------------------------------------------------------------- */
.location-item {
    cursor: pointer;
    transition: background-color 0.15s ease, box-shadow 0.15s ease;
}

tr.location-item:hover,
div.location-item:hover {
    background-color: rgba(var(--brand-primary-rgb), 0.08);
}

.location-item.active {
    background-color: rgba(var(--brand-primary-rgb), 0.12);
    box-shadow: inset 3px 0 0 var(--brand-primary);
}

/* 출처 항목이 선택됐을 때 — 왼쪽 막대 없이 배경 색만으로 표시한다 */
[data-brand="upstage"] .location-item.active {
    box-shadow: none;
    background-color: rgba(var(--brand-primary-rgb), 0.16);
}

/* Upstage 톤 — 대제목
 *
 * 진한 보라로 폭 전체를 채우면 보고서 한 장에 같은 면이 여러 번 반복돼
 * 값싸 보인다. Upstage 가 쓰는 .notice-pill 규격(purple-50 바탕 + 검은 글씨 +
 * 100px 반경 + .5rem 1rem 여백)을 그대로 가져와, 띠가 아니라 제목 길이만큼의
 * 알약으로 만든다. 면적이 줄어 색이 강조로 작동하고 여백이 살아난다. */
[data-brand="upstage"] .group-title {
    display: inline-flex;
    align-items: center;
    background: var(--brand-primary-soft);
    color: #0a0d14;
    border-radius: 100px;
    padding: 0.5rem 1rem;
    font-size: 1.05rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* -------------------------------------------------------------------------
 * 모바일 — 표를 최대한 화면 안에 넣는다
 *
 * 폭을 잡아먹던 두 가지를 푼다: 머리글 줄바꿈 금지와 넉넉한 좌우 여백.
 * 그래도 넘치는 표는 .section-content 안에서만 가로로 밀린다.
 * ---------------------------------------------------------------------- */
@media (max-width: 768px) {
    .summary-table {
        font-size: 0.8rem;
    }

    .summary-table th {
        white-space: normal;  /* 머리글이 접히면 표 최소 폭이 크게 준다 */
        word-break: keep-all;
    }

    .summary-table th,
    .summary-table td {
        padding: 8px 6px;
    }

    .summary-subgroup {
        padding: 12px;
    }

    .section-content {
        padding-left: 0;
    }
}
