/* ========================================
   VSP 医启三阶 —— 虚拟标准病人问诊练习
   Professional Desktop Medical App Styles
   ======================================== */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    margin: 0; padding: 0; box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
    background: #E0F0F7;
    color: #1a1a2e;
    height: 100vh;
    overflow: hidden;
    line-height: 1.5;
}

/* ---------- Login Page ---------- */
#loginPage {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #d6eaf4 0%, #E0F0F7 50%, #edf5fa 100%);
}

.login-card {
    background: #ffffff;
    padding: 52px 44px 44px;
    border-radius: 18px;
    text-align: center;
    width: 400px;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.06),
        0 4px 12px rgba(0, 0, 0, 0.04);
}

.login-card h1 {
    font-size: 15px;
    font-weight: 600;
    color: #3B82F6;
    letter-spacing: 6px;
    margin-bottom: 18px;
    display: inline-block;
    padding: 6px 18px 6px 24px;
    background: #EBF3FE;
    border-radius: 999px;
}

.login-card p {
    color: #1a1a2e;
    font-size: 25px;
    font-weight: 700;
    letter-spacing: 1px;
    margin-bottom: 30px;
}

.login-card p::after {
    content: '';
    display: block;
    width: 48px;
    height: 3px;
    background: #3B82F6;
    border-radius: 2px;
    margin: 14px auto 0;
}

.login-card input {
    width: 100%;
    height: 50px;
    font-size: 17px;
    font-family: inherit;
    padding: 0 16px;
    border: 1.5px solid #d0d5dd;
    border-radius: 10px;
    display: block;
    margin: 0 auto 18px;
    outline: none;
    color: #1a1a2e;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.login-card input::placeholder {
    color: #a0a5ad;
}
.login-card input:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3.5px rgba(59, 130, 246, 0.15);
}

.login-card button {
    width: 100%;
    height: 50px;
    font-size: 17px;
    font-weight: 600;
    font-family: inherit;
    background: #3B82F6;
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: background 0.2s ease, transform 0.1s ease;
}
.login-card button:hover {
    background: #2563EB;
}
.login-card button:active {
    transform: scale(0.98);
}

.error-msg {
    color: #EF4444;
    font-size: 14px;
    margin-top: 10px;
    min-height: 20px;
}

/* ---------- Main Page Layout ---------- */
#mainPage {
    height: 100vh;
    display: none;  /* JS overrides to flex */
}

.container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* ---------- Left Panel ---------- */
.left-panel {
    width: 380px;
    min-width: 380px;
    display: flex;
    flex-direction: column;
    padding: 26px 22px 22px;
}

.input-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
}

/* User & Case rows */
.user-info,
.case-select {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.user-info label,
.case-select label {
    font-size: 17px;
    font-weight: 600;
    color: #1a1a2e;
    min-width: 95px;
    white-space: nowrap;
}

.user-info span {
    font-size: 18px;
    font-weight: 600;
    color: #1a1a2e;
}

/* Logout button */
.btn-logout {
    margin-left: auto;
    height: 36px;
    padding: 0 16px;
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    color: #ffffff;
    background: #EF4444;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}
.btn-logout:hover {
    background: #DC2626;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}
.btn-logout:active {
    transform: scale(0.96);
}

.case-select select {
    flex: 1;
    height: 44px;
    font-size: 16px;
    font-family: inherit;
    border-radius: 7px;
    padding: 0 10px;
    border: 1.5px solid #d0d5dd;
    background: #ffffff;
    color: #1a1a2e;
    outline: none;
    cursor: pointer;
    transition: border-color 0.2s ease;
}
.case-select select:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.case-select select:disabled {
    background: #f0f2f5;
    cursor: not-allowed;
    opacity: 0.7;
}

/* Input section heading */
.input-label {
    font-size: 20px;
    font-weight: 700;
    color: #1a1a2e;
    margin-top: 4px;
    padding-bottom: 4px;
    border-bottom: 2.5px solid #3B82F6;
    align-self: flex-start;
    letter-spacing: 0.5px;
}

/* Text input area */
#msgInput {
    flex: 1;
    width: 100%;
    font-size: 16px;
    font-family: inherit;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1.5px solid #d0d5dd;
    background: #ffffff;
    color: #1a1a2e;
    resize: none;
    outline: none;
    line-height: 1.7;
    min-height: 90px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
#msgInput:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
#msgInput:disabled {
    background: #f0f2f5;
    cursor: not-allowed;
    opacity: 0.7;
}
#msgInput::placeholder {
    color: #a0a5ad;
}

/* 确认（发送）按钮 */
.btn-send {
    width: 100%;
    margin-top: 10px;
    background: #3B82F6;
    color: #ffffff;
}

/* 电脑端：确认按钮比通用按钮矮一些（ID 选择器优先于 .btn）；
   必须 flex:none —— 它在纵向 flex 容器里，.btn 的 flex:1 会把它沿竖直方向拉伸/压垮 */
#sendBtn {
    flex: none;
    height: 40px;
    font-size: 16px;
}

/* ---------- Control Buttons ---------- */
.controls {
    flex-shrink: 0;
    padding-top: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.btn-row {
    display: flex;
    gap: 12px;
}

.btn {
    flex: 1;
    height: 50px;
    font-size: 17px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: 9px;
    cursor: pointer;
    padding: 0 10px;
    letter-spacing: 0.5px;
    transition:
        background 0.2s ease,
        opacity 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.1s ease;
}
.btn:hover:not(:disabled) {
    opacity: 0.92;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.10);
}
.btn:active:not(:disabled) {
    transform: scale(0.97);
}
.btn:disabled {
    background: #7F8C8D !important;
    cursor: not-allowed;
    opacity: 0.55;
    box-shadow: none;
    transform: none;
}

.btn-green {
    background: #22C55E;
    color: white;
}
.btn-red {
    background: #EF4444;
    color: white;
}
.btn-blue {
    background: #3B82F6;
    color: white;
}

/* ---------- Right Panel ---------- */
.right-panel {
    flex: 1;
    background: #FFF8F0;
    display: flex;
    flex-direction: column;
    padding: 26px 26px 22px;
    min-width: 0;
}

.dialog-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* 考官评估：加宽至约三分之一 */
.result-section {
    width: 33%;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    padding: 26px 26px 22px;
    background: #FFF8F0;
}

.section-title {
    font-size: 20px;
    font-weight: 700;
    color: #1a1a2e;
    margin-bottom: 10px;
    flex-shrink: 0;
    letter-spacing: 0.3px;
}

/* Scrollable content areas */
#dialogView,
#resultView {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 18px;
    border-radius: 10px;
    font-size: 16px;
    line-height: 1.75;
    color: #1a1a2e;
}

#dialogView {
    background: #F5F5F9;
    border: 1px solid #e2e2e8;
}

#resultView {
    background: #FFF3CD;
    border: 1px solid #FFD700;
}

/* 评估反馈空白占位提示 */
.result-placeholder {
    color: #8a6d1a;
    line-height: 2;
}
.result-placeholder p {
    margin-bottom: 10px;
}
.result-placeholder p:last-child {
    margin-bottom: 0;
}

/* ---------- Dialog Messages ---------- */
.dialog-msg {
    margin-bottom: 10px;
    padding: 10px 14px;
    border-radius: 9px;
    background: rgba(255, 255, 255, 0.75);
    word-wrap: break-word;
}
.dialog-msg:last-child {
    margin-bottom: 0;
}

.dialog-role {
    font-weight: 700;
}

.dialog-role.user {
    color: #1d4ed8;  /* slightly deeper blue for contrast */
}

.dialog-role.assistant {
    color: #059669;
}

.dialog-role.system {
    color: #888;
    font-size: 14px;
}

.dialog-role.system b {
    font-weight: 600;
}

/* ---------- Scrollbar Styling ---------- */
#dialogView::-webkit-scrollbar,
#resultView::-webkit-scrollbar {
    width: 6px;
}

#dialogView::-webkit-scrollbar-track,
#resultView::-webkit-scrollbar-track {
    background: transparent;
}

#dialogView::-webkit-scrollbar-thumb,
#resultView::-webkit-scrollbar-thumb {
    background: #c8c8cc;
    border-radius: 3px;
}

#dialogView::-webkit-scrollbar-thumb:hover,
#resultView::-webkit-scrollbar-thumb:hover {
    background: #a8a8ad;
}

/* ========================================
   Responsive —— 平板与手机适配
   ======================================== */

/* 触屏通用优化 */
@media (hover: none) and (pointer: coarse) {
    .btn,
    .login-card button,
    .btn-logout,
    .case-select select {
        touch-action: manipulation;  /* 去除双击缩放延迟 */
    }
    body {
        -webkit-tap-highlight-color: transparent;
    }
}

/* ---------- 平板（≤1024px）：评估区移到下方 ---------- */
@media (max-width: 1024px) {
    .container {
        flex-wrap: wrap;
    }
    .left-panel {
        width: 320px;
        min-width: 280px;
        height: 62vh;
        overflow-y: auto;
        padding: 20px 18px 16px;
    }
    .right-panel {
        flex: 1;
        min-width: 0;
        height: 62vh;
        padding: 20px 18px 16px;
    }
    .result-section {
        width: 100%;
        min-width: 0;
        height: 38vh;
        flex-shrink: 0;
        padding: 6px 18px 16px;
    }
}

/* ---------- 手机（≤768px）：单列纵向布局，整页滚动 ---------- */
@media (max-width: 768px) {
    body {
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    /* 登录页 */
    #loginPage {
        min-height: 100vh;
        height: auto;
        padding: 20px 0;
        padding-bottom: calc(20px + env(safe-area-inset-bottom));
    }
    .login-card {
        width: min(400px, calc(100vw - 40px));
        padding: 36px 24px 28px;
        border-radius: 14px;
    }
    .login-card h1 {
        font-size: 13px;
        letter-spacing: 4px;
        padding: 5px 14px 5px 18px;
    }
    .login-card p {
        font-size: 20px;
        margin-bottom: 26px;
    }

    /* 主界面：纵向堆叠 */
    #mainPage {
        height: auto;
        min-height: 100vh;
    }
    .container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .left-panel {
        width: 100%;
        min-width: 0;
        height: auto;
        padding: 16px 14px 8px;
    }
    .input-section {
        flex: none;
        gap: 10px;
    }
    .user-info label,
    .case-select label {
        font-size: 15px;
        min-width: 78px;
    }
    .user-info span {
        font-size: 16px;
    }
    .case-select select {
        height: 44px;
        font-size: 16px;  /* ≥16px 防止 iOS 聚焦自动放大 */
    }
    .input-label {
        font-size: 17px;
    }
    #msgInput {
        flex: none;
        height: 100px;
        min-height: 0;
        font-size: 16px;  /* ≥16px 防止 iOS 聚焦自动放大 */
    }
    .btn {
        height: 46px;
        font-size: 16px;
    }
    /* 手机端：确认按钮加高，便于拇指点按 */
    #sendBtn {
        flex: none;
        height: 52px;
    }
    .controls {
        padding-top: 10px;
        gap: 10px;
    }
    .btn-row {
        gap: 10px;
    }

    /* 对话区：固定高度内部滚动 */
    .right-panel {
        width: 100%;
        height: auto;
        padding: 14px 14px 8px;
    }
    .dialog-section {
        flex: none;
    }
    .section-title {
        font-size: 17px;
        margin-bottom: 8px;
    }
    #dialogView {
        flex: none;
        height: 46vh;
        font-size: 15px;
        padding: 12px 14px;
        -webkit-overflow-scrolling: touch;
    }

    /* 评估区 */
    .result-section {
        width: 100%;
        min-width: 0;
        height: auto;
        padding: 10px 14px 16px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    #resultView {
        flex: none;
        height: 36vh;
        font-size: 15px;
        padding: 12px 14px;
        -webkit-overflow-scrolling: touch;
    }
}

/* ---------- 小屏手机（≤380px） ---------- */
@media (max-width: 380px) {
    .login-card h1 {
        font-size: 28px;
    }
    .btn {
        height: 44px;
        font-size: 15px;
        padding: 0 6px;
    }
    #dialogView {
        height: 42vh;
    }
}

/* ---------- 修改密码弹窗 ---------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal-card {
    width: min(360px, 90vw);
    background: #ffffff;
    border-radius: 12px;
    padding: 24px 22px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.2);
}
.modal-card h3 {
    margin: 0 0 4px;
    font-size: 18px;
    color: #1a1a2e;
}
.modal-card input {
    width: 100%;
    box-sizing: border-box;
    font-size: 16px;
    font-family: inherit;
    padding: 11px 12px;
    border-radius: 8px;
    border: 1.5px solid #d0d5dd;
    outline: none;
}
.modal-card input:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
.modal-btns {
    display: flex;
    gap: 10px;
    margin-top: 4px;
}
.btn-cancel {
    background: #e5e7eb;
    color: #374151;
}

/* ---------- 考官答疑区 ---------- */
#qaSection {
    display: flex;
    flex-direction: column;
    min-height: 0;
    flex: 1 1 0;
    max-height: 45%;
    margin-top: 12px;
}
#qaSection .section-title {
    font-size: 16px;
    margin-bottom: 8px;
}
#qaRounds {
    font-size: 12px;
    font-weight: 400;
    color: #8a6d1a;
}
#qaView {
    flex: 1 1 0;
    overflow-y: scroll;
    min-height: 80px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #FFF3CD;
    border: 1px solid #FFD700;
    font-size: 14px;
    line-height: 1.7;
    color: #1a1a2e;
    scrollbar-width: thin;
    scrollbar-color: #c9a227 transparent;
}
#qaView::-webkit-scrollbar {
    width: 6px;
}
#qaView::-webkit-scrollbar-track {
    background: transparent;
}
#qaView::-webkit-scrollbar-thumb {
    background: #c9a227;
    border-radius: 3px;
}
#qaInput {
    width: 100%;
    flex-shrink: 0;
    margin-top: 8px;
    font-size: 14px;
    font-family: inherit;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1.5px solid #d0d5dd;
    background: #ffffff;
    color: #1a1a2e;
    resize: none;
    outline: none;
    line-height: 1.6;
    min-height: 56px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    box-sizing: border-box;
}
#qaInput:focus {
    border-color: #3B82F6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}
#qaInput:disabled {
    background: #f0f2f5;
    cursor: not-allowed;
    opacity: 0.7;
}
#qaSection .btn-send {
    flex: none;
    flex-shrink: 0;
    height: 25px;
    font-size: 13px;
    border-radius: 6px;
    margin-top: 6px;
}

/* ---------- 问诊历史弹窗 ---------- */
.history-card {
    width: min(900px, 92vw);
    height: min(620px, 85vh);
}
.history-body {
    display: flex;
    flex: 1;
    min-height: 0;
    gap: 12px;
    margin-top: 8px;
}
#historyList {
    width: 220px;
    flex-shrink: 0;
    overflow-y: auto;
    border: 1px solid #e2e2e8;
    border-radius: 8px;
    padding: 6px;
}
.history-item {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 4px;
}
.history-item:hover {
    background: #f0f4ff;
}
.history-item.active {
    background: #e0eaff;
}
.history-item-title {
    font-weight: 600;
    font-size: 14px;
    color: #1a1a2e;
}
.history-item-time {
    font-size: 12px;
    color: #888;
    margin-top: 2px;
}
#historyDetail {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    border: 1px solid #e2e2e8;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: 14px;
    line-height: 1.7;
    background: #fafafc;
}
.history-hint {
    color: #a0a5ad;
    text-align: center;
    margin-top: 30px;
    font-size: 14px;
}
.history-section-title {
    font-weight: 700;
    font-size: 15px;
    color: #1a1a2e;
    margin: 14px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid #e2e2e8;
}
.history-section-title:first-child {
    margin-top: 0;
}
.history-feedback {
    background: #FFF3CD;
    border: 1px solid #FFD700;
}
@media (max-width: 768px) {
    .history-card {
        width: 94vw;
        height: 88vh;
    }
    .history-body {
        flex-direction: column;
    }
    #historyList {
        width: 100%;
        max-height: 140px;
    }
}

/* 已过关病例（第二次问诊较上次进步）标黄 */
#caseSelect option.case-passed {
    background: #FFE58F;
    color: #7a5c00;
    font-weight: 600;
}

/* 历史记录达标对勾 */
.pass-mark {
    color: #16a34a;
    margin-right: 4px;
    font-weight: 700;
}

/* 历史记录分级展示 */
.history-group {
    margin-bottom: 4px;
}
.history-group-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: #1a1a2e;
}
.history-group-head:hover {
    background: #f0f4ff;
}
.history-group-arrow {
    font-size: 12px;
    color: #888;
    width: 12px;
    flex-shrink: 0;
}
.history-group-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.history-group-count {
    font-size: 12px;
    font-weight: 400;
    color: #888;
    background: #eef1f6;
    border-radius: 10px;
    padding: 1px 8px;
}
.history-group-body .history-item {
    padding-left: 28px;
}

/* ---------- 排行榜 ---------- */
.lb-card {
    width: min(640px, 94vw);
    max-height: min(720px, 88vh);
    overflow-y: auto;
}
.lb-tabs {
    display: flex;
    gap: 8px;
    margin: 8px 0;
}
.lb-tab {
    border: 1.5px solid #d0d5dd;
    background: #f6f7f9;
    color: #374151;
    border-radius: 20px;
    padding: 5px 16px;
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
}
.lb-tab.active {
    background: #3B82F6;
    border-color: #3B82F6;
    color: #fff;
    font-weight: 600;
}
.lb-section-title {
    font-weight: 700;
    font-size: 15px;
    color: #1a1a2e;
    margin: 14px 0 8px;
    border-left: 3px solid #3B82F6;
    padding-left: 8px;
}
.lb-groups { display: flex; flex-direction: column; gap: 6px; }
.lb-group-row { display: flex; align-items: center; gap: 8px; }
.lb-group-name { width: 52px; flex-shrink: 0; font-size: 13px; color: #374151; }
.lb-bar {
    flex: 1; height: 14px; background: #eef1f6; border-radius: 7px; overflow: hidden;
}
.lb-bar-fill {
    display: block; height: 100%;
    background: linear-gradient(90deg, #60a5fa, #3B82F6);
    border-radius: 7px;
    transition: width .4s ease;
}
.lb-group-num { width: 64px; flex-shrink: 0; text-align: right; font-size: 12px; color: #666; }
.lb-wall {
    display: flex; flex-wrap: wrap; gap: 8px;
}
.lb-wall-item {
    background: #fffbeb; border: 1px solid #fde68a; border-radius: 16px;
    padding: 4px 12px; font-size: 13px; color: #7a5c00;
}
.lb-wall-item small { color: #a08a3c; margin-left: 4px; }
.lb-wall-count { margin-top: 8px; font-size: 13px; color: #555; }
.lb-top { margin: 0; padding-left: 0; list-style: none; }
.lb-top li {
    display: flex; align-items: center; gap: 10px;
    padding: 6px 8px; border-radius: 6px; font-size: 14px;
}
.lb-top li:nth-child(odd) { background: #f8fafc; }
.lb-rank { width: 34px; text-align: center; font-weight: 600; flex-shrink: 0; }
.lb-name { flex: 1; }
.lb-cov { font-weight: 700; color: #2563eb; }
.lb-me {
    margin-top: 10px; padding: 10px 12px; border-radius: 8px;
    background: #eff6ff; border: 1px solid #bfdbfe;
    font-size: 14px; color: #1d4ed8;
}
.lb-me-good { background: #f0fdf4; border-color: #bbf7d0; color: #15803d; }

/* 输入区标题行的小排行榜按钮 */
.lb-mini-btn {
    border: 1px solid #3B82F6;
    background: #eff6ff;
    color: #2563eb;
    font-size: 12px;
    font-family: inherit;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 12px;
    cursor: pointer;
    line-height: 1.4;
}
.lb-mini-btn:active {
    transform: scale(0.96);
}
