/* === Medical Memo — 移动端样式（原型版）=== */

:root {
    --blue: #3B82F6;
    --blue-light: #EFF6FF;
    --green: #10B981;
    --red: #EF4444;
    --orange: #F59E0B;
    --bg: #F3F4F6;
    --card: #FFFFFF;
    --text: #1F2937;
    --text2: #6B7280;
    --text3: #9CA3AF;
    --border: #E5E7EB;
    --radius: 12px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    max-width: 430px;
    margin: 0 auto;
    min-height: 100vh;
    padding-bottom: 72px;
}

/* ===== 登录 ===== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(150deg, #3B82F6 0%, #6366F1 50%, #8B5CF6 100%);
    padding: 24px;
    max-width: 100vw;
}
.login-card {
    background: var(--card);
    border-radius: 20px;
    padding: 36px 28px;
    width: 100%;
    max-width: 360px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-icon { font-size: 52px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin-bottom: 4px; }
.login-card .login-subtitle { font-size: 13px; color: var(--text2); margin-bottom: 24px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 14px; color: var(--text2); margin-bottom: 6px; text-align: left; }

.form-input {
    width: 100%;
    padding: 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-size: 17px;
    text-align: center;
    outline: none;
    -webkit-appearance: none;
    background: var(--card);
    color: var(--text);
}
.form-input:focus { border-color: var(--blue); }

/* Buttons */
.btn { padding: 11px 22px; border-radius: 8px; font-size: 15px; font-weight: 500; cursor: pointer; border: none; }
.btn-blue { background: var(--blue); color: #fff; white-space: nowrap; }
.btn-blue:active { transform: scale(0.96); opacity: 0.85; }
.btn-gray { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-primary {
    width: 100%;
    padding: 14px;
    background: var(--blue);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 16px;
}
.btn-primary:disabled { opacity: 0.6; }
.error-message { color: var(--red); font-size: 13px; margin-top: 10px; padding: 8px 12px; background: #FDEDEC; border-radius: 6px; }

/* === Topbar === */
.app-header {
    background: linear-gradient(135deg, #667EEA 0%, #764BA2 100%);
    color: #fff;
    padding: 16px 20px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: left;
}
.app-header .header-count-badge {
    background: rgba(255,255,255,0.25);
    font-size: 13px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 20px;
    margin-left: auto;
}

/* ===== Bottom Nav ===== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 430px;
    background: var(--card);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 10;
}
.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 7px 0 5px;
    color: var(--text3);
    font-size: 11px;
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
}
.nav-item.active { color: var(--blue); }
.nav-icon { font-size: 24px; }

/* ===== Upload Page ===== */
.upload-page { padding: 16px; }
.upload-zone {
    background: var(--card);
    border-radius: var(--radius);
    padding: 40px 24px;
    text-align: center;
    border: 2px dashed var(--border);
    cursor: pointer;
    margin-bottom: 16px;
}
.upload-zone:active { border-color: var(--blue); background: var(--blue-light); }
.upload-icon { font-size: 56px; margin-bottom: 12px; }
.upload-title { font-size: 17px; font-weight: 500; margin-bottom: 4px; }
.upload-hint { font-size: 13px; color: var(--text2); }

/* Preview */
.preview-block { display: none; margin-bottom: 16px; text-align: center; }
.preview-block img { max-height: 280px; border-radius: 10px; max-width: 100%; }
.preview-actions { display: flex; gap: 10px; margin-top: 12px; justify-content: center; }
.preview-submitted { text-align: center; margin-top: 12px; }
.preview-submitted .submitted-icon { font-size: 36px; margin-bottom: 4px; }
.preview-submitted .submitted-text { font-size: 14px; color: var(--text2); margin-bottom: 10px; }
.bg-toggle { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; color: var(--text2); cursor: pointer; }
.bg-toggle input { accent-color: var(--blue); }

/* Progress Panel */
.progress-panel {
    display: none;
    background: var(--card);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.progress-step { display: flex; align-items: center; gap: 12px; padding: 10px 0; }
.progress-step + .progress-step { border-top: 1px solid var(--border); }
.step-dot {
    width: 28px; height: 28px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; flex-shrink: 0;
    background: var(--border); color: var(--text2);
}
.progress-step.doing .step-dot {
    background: var(--blue-light); color: var(--blue);
}
.progress-step.doing .step-dot::after {
    content: ''; width: 12px; height: 12px; border-radius: 50%;
    border: 2px solid var(--blue); border-top-color: transparent;
    animation: spin 0.8s linear infinite;
}
.progress-step.done .step-dot { background: #D1FAE5; color: var(--green); }
.progress-step .step-label { font-size: 14px; color: var(--text3); }
.progress-step.doing .step-label, .progress-step.done .step-label { color: var(--text); font-weight: 500; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Error in progress */
.progress-step.error .step-dot { background: #FEE2E2; color: var(--red); }
.progress-step.error .step-label { color: var(--red); font-weight: 500; }

/* Result Card */
.result-block { display: none; background: var(--card); border-radius: var(--radius); padding: 16px; margin-top: 12px; }
.result-block h3 { font-size: 17px; margin-bottom: 6px; }
.result-img { width: 100%; border-radius: 8px; margin: 10px 0; border: 1px solid var(--border); }
.result-meta { display: flex; justify-content: space-between; font-size: 14px; color: var(--text2); margin-bottom: 12px; }
.result-badge {
    display: inline-block;
    padding: 3px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 500;
}
.badge-ok { background: #D1FAE5; color: #065F46; }
.badge-warn { background: #FEF3C7; color: #92400E; }
.result-body { font-size: 14px; padding: 8px 12px; background: var(--bg); border-radius: 8px; margin-bottom: 8px; }
.result-tags { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.result-tags span {
    font-size: 11px; padding: 2px 6px; border-radius: 3px;
    background: var(--card); color: var(--text2);
    border: 1px solid var(--border);
}
.result-tags span.warn { background: #FEF2F2; color: #DC2626; border-color: #FEE2E2; }
.result-actions { display: flex; gap: 10px; margin-top: 12px; }

/* ===== View Page ===== */
.view-page { padding: 16px; }
.month-divider {
    text-align: center; font-size: 12px; color: var(--text3);
    padding: 14px 0 8px; letter-spacing: 0.5px;
}
.doc-card {
    display: block; background: var(--card); border-radius: var(--radius);
    padding: 14px; margin-bottom: 10px; cursor: pointer;
    color: var(--text); text-decoration: none;
}
.doc-card:active { transform: scale(0.98); }
.doc-card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 6px;
}
.doc-type-label {
    font-size: 12px; padding: 2px 8px; border-radius: 4px;
    background: var(--bg); font-weight: 500;
}
.doc-date { font-size: 12px; color: var(--text3); }
.doc-body { display: flex; gap: 12px; align-items: flex-start; }
.doc-thumb {
    width: 72px; height: 72px; border-radius: 6px;
    object-fit: cover; flex-shrink: 0;
    background: var(--bg); border: 1px solid var(--border);
}
.doc-info { flex: 1; min-width: 0; }
.doc-info strong { display: block; font-size: 14px; margin-bottom: 2px; }
.doc-info p { font-size: 13px; color: var(--text2); line-height: 1.4; }
.doc-tags { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.doc-tags span {
    font-size: 11px; padding: 2px 6px; border-radius: 3px;
    background: var(--bg); color: var(--text2);
}
.doc-tags span.warn { background: #FEF2F2; color: #DC2626; }

/* Empty State */
.empty-state {
    text-align: center; padding: 60px 24px; color: var(--text3);
}
.empty-icon { font-size: 56px; margin-bottom: 12px; }
.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ===== Document Detail ===== */
.back-link {
    display: inline-block; margin-bottom: 12px;
    font-size: 14px; color: var(--blue);
}

.doc-image-section {
    background: var(--card); border-radius: var(--radius);
    overflow: hidden; margin-bottom: 12px;
}
.doc-full-image { width: 100%; display: block; }
.doc-meta-bar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 10px 0; margin-bottom: 12px;
}
.doc-meta-date { font-size: 13px; color: var(--text2); }

.doc-extracted-section {
    background: var(--card); border-radius: var(--radius);
    padding: 16px; margin-bottom: 12px;
}
.doc-extracted-section h3 { font-size: 16px; margin-bottom: 12px; }
.doc-extracted-section h4 { font-size: 14px; color: var(--text2); margin-bottom: 8px; margin-top: 16px; }

.info-row { display: flex; padding: 6px 0; font-size: 14px; border-bottom: 1px solid var(--border); }
.info-row:last-child { border-bottom: none; }
.info-label { color: var(--text2); min-width: 48px; flex-shrink: 0; }
.info-value { flex: 1; }

.med-item {
    padding: 8px 12px; margin-bottom: 6px;
    background: var(--bg); border-radius: 6px; font-size: 14px;
}
.tag {
    display: inline-block; padding: 1px 6px;
    background: var(--card); border: 1px solid var(--border);
    border-radius: 3px; font-size: 12px; color: var(--text2);
    margin-left: 4px;
}
.tag-category {
    background: #E8F0FE; border-color: #C6D9F7; color: #1A73E8;
}

.lab-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.lab-table th {
    text-align: left; padding: 4px 8px; font-weight: 500;
    font-size: 12px; color: var(--text2); border-bottom: 1px solid var(--border);
}
.lab-table td { padding: 4px 8px; border-bottom: 1px solid var(--border); }
.lab-abnormal td { color: var(--red); font-weight: 500; }

.doc-ocr-section {
    background: var(--card); border-radius: var(--radius);
    padding: 14px; margin-bottom: 12px;
}
.doc-ocr-section summary { font-size: 14px; cursor: pointer; color: var(--text2); }
.ocr-text {
    font-size: 13px; line-height: 1.6; white-space: pre-wrap; word-break: break-all;
    background: var(--bg); padding: 12px; border-radius: 8px;
    margin-top: 8px; max-height: 300px; overflow-y: auto;
}

.doc-actions { display: flex; gap: 12px; margin: 12px 0; }
.btn-danger {
    display: inline-block; padding: 10px 20px;
    background: #fff; color: var(--red);
    border: 1px solid var(--red); border-radius: 8px;
    font-size: 14px; cursor: pointer;
}
.btn-secondary {
    display: inline-block; padding: 10px 20px;
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 14px; cursor: pointer;
}
.doc-note-display {
    font-size: 14px; padding: 10px; background: var(--bg); border-radius: 6px; margin-top: 12px;
}

/* ===== 就诊记录首页 ===== */
.index-page { padding: 16px; padding-bottom: 80px; }

/* ── 月份分割线 ── */
.month-label {
    font-size: 12px; font-weight: 600; color: #A0AEC0;
    letter-spacing: 1px;
    margin: 8px 0 10px 4px;
}

/* ── 卡片 ── */
.episode-card {
    display: block;
    background: #FFFFFF;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 14px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    transition: transform 0.15s;
    color: var(--text);
    text-decoration: none;
}
.episode-card:active { transform: scale(0.985); }

/* 卡片顶部色条 */
.ep-card-accent {
    height: 4px;
    background: linear-gradient(90deg, #667EEA, #764BA2);
}

/* 卡片主体 */
.ep-card-body { padding: 14px 16px; }

/* 日期 + 单据数行 */
.ep-card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 12px;
}
.ep-date {
    font-size: 14px; font-weight: 700; color: #2D3748;
}
.ep-badge-count {
    font-size: 11px; font-weight: 600;
    background: #EBF4FF; color: #4A6CF7;
    padding: 3px 10px; border-radius: 12px;
}

/* 患者 + 医院行 */
.ep-patient-row {
    display: flex; align-items: center; gap: 6px;
    font-size: 15px; font-weight: 700; color: #1A202C;
    margin-bottom: 4px;
}
.ep-patient-extra {
    font-weight: 400; font-size: 13px; color: #718096;
}
.ep-hospital-row {
    font-size: 13px; color: #718096;
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 4px;
}

/* ── 关键词标签 ── */
.ep-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.ep-tag {
    font-size: 11px; font-weight: 600; padding: 4px 10px;
    border-radius: 6px; background: #F7FAFC; color: #4A5568;
    display: flex; align-items: center; gap: 3px;
}
.ep-tag.red { background: #FFF5F5; color: #E53E3E; }
.ep-tag.blue { background: #EBF8FF; color: #3182CE; }
.ep-tag.green { background: #F0FFF4; color: #38A169; }
.ep-tag.purple { background: #FAF5FF; color: #805AD5; }
.ep-tag.orange { background: #FFFAF0; color: #DD6B20; }

/* ── 缩略图行 ── */
.ep-thumbs { display: flex; gap: 8px; margin-bottom: 10px; align-items: center; }
.ep-thumb-item { display: block; width: 56px; height: 56px; flex-shrink: 0; position: relative; }
.ep-thumb {
    width: 56px; height: 56px; border-radius: 10px;
    object-fit: cover; border: 1px solid #E2E8F0;
    display: block;
}
.ep-thumb-label {
    position: absolute; bottom: -1px; right: -1px;
    background: rgba(0,0,0,0.45); color: #fff;
    font-size: 10px; padding: 1px 4px; border-radius: 4px 0 0 0;
}
.ep-thumb-more {
    width: 56px; height: 56px; border-radius: 10px;
    background: #F7FAFC; color: #A0AEC0;
    display: flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 600; flex-shrink: 0;
}

/* ── 摘要 ── */
.ep-summary {
    font-size: 12px; color: #A0AEC0; line-height: 1.5;
    padding-top: 10px; border-top: 1px solid #F0F4F8;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── 空状态 ── */
.empty-state {
    text-align: center; padding: 80px 24px;
}
.empty-state .empty-icon { font-size: 64px; margin-bottom: 16px; }
.empty-state .empty-title { font-size: 18px; font-weight: 600; color: #4A5568; margin-bottom: 6px; }
.empty-state .empty-sub  { font-size: 14px; color: #A0AEC0; margin-bottom: 24px; }
.empty-state .btn-primary { display: block; width: auto; margin: 24px 0 0 0; }
.btn-primary {
    display: inline-flex; align-items: center; gap: 6px;
    background: linear-gradient(135deg, #667EEA, #764BA2);
    color: #fff; font-size: 15px; font-weight: 600;
    padding: 12px 28px; border-radius: 12px;
    text-decoration: none; border: none; cursor: pointer;
    box-shadow: 0 4px 14px rgba(102, 126, 234, 0.4);
}

/* ===== Episode 详情页 ===== */
.ep-detail-container { padding: 16px; padding-bottom: 80px; }

.back-link {
    display: inline-flex; align-items: center; gap: 4px;
    margin-bottom: 14px;
    font-size: 14px; color: #667EEA;
    text-decoration: none; font-weight: 500;
}

.ep-detail-card {
    background: #FFFFFF;
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 14px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
.ep-detail-card .card-accent {
    height: 4px;
    background: linear-gradient(90deg, #667EEA, #764BA2);
}
.ep-detail-card .card-body { padding: 14px 16px; }
.ep-detail-card .card-header {
    font-size: 15px; font-weight: 700; color: #2D3748;
    margin-bottom: 12px; display: flex; align-items: center; gap: 6px;
}
.ep-detail-card .info-row {
    display: flex; padding: 8px 0; font-size: 14px;
    border-bottom: 1px solid #F0F4F8;
}
.ep-detail-card .info-row:last-child { border-bottom: none; }
.ep-detail-card .info-label {
    color: #A0AEC0; min-width: 52px; flex-shrink: 0; font-size: 13px;
}
.ep-detail-card .info-value { flex: 1; color: #1A202C; }

/* 药品卡片 */
.ep-med-item {
    padding: 10px 12px; margin-bottom: 8px;
    background: #F7FAFC; border-radius: 10px;
    border-left: 3px solid #667EEA;
}
.ep-med-item:last-child { margin-bottom: 0; }
.ep-med-name-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 14px; }
.ep-med-tag {
    display: inline-block; padding: 1px 6px;
    background: #EBF8FF; border-radius: 4px;
    font-size: 11px; color: #3182CE; font-weight: 500;
}
.ep-med-detail-row { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.ep-med-detail-row .tag {
    font-size: 11px; padding: 2px 8px;
    background: #FFFFFF; color: #718096;
    border-radius: 4px; border: 1px solid #E2E8F0;
}
.ep-med-count {
    font-size: 12px; font-weight: 400; color: #A0AEC0;
    margin-left: auto;
}

/* 化验表格 */
.lab-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.lab-table th {
    text-align: left; padding: 6px 10px; font-weight: 500;
    font-size: 12px; color: #A0AEC0; border-bottom: 2px solid #F0F4F8;
}
.lab-table td { padding: 6px 10px; border-bottom: 1px solid #F0F4F8; color: #4A5568; }
.lab-abnormal td { color: #E53E3E; font-weight: 500; background: #FFF5F5; }

/* 单据网格 */
.doc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.doc-grid-item {
    display: block; text-decoration: none; color: var(--text);
    border-radius: 10px; overflow: hidden; border: 1px solid #E2E8F0;
    background: #F7FAFC; transition: transform 0.15s;
}
.doc-grid-item:active { transform: scale(0.95); }
.doc-grid-img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; }
.doc-grid-label {
    display: block; text-align: center; font-size: 11px; padding: 5px;
    color: #718096; font-weight: 500;
}

/* 摘要 */
.ep-summary-block {
    background: #F7FAFC; padding: 14px; border-radius: 10px;
    font-size: 14px; line-height: 1.7; white-space: pre-wrap;
    color: #4A5568;
}

/* 操作栏 */
.ep-actions {
    display: flex; gap: 12px; margin-top: 16px;
}
.btn-secondary {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 10px 20px; background: #FFFFFF;
    color: #4A5568; border: 1px solid #E2E8F0;
    border-radius: 10px; font-size: 14px; cursor: pointer; text-decoration: none;
}
.btn-danger {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 10px 20px; background: #FFFFFF;
    color: #E53E3E; border: 1px solid #FED7D7;
    border-radius: 10px; font-size: 14px; cursor: pointer;
}

/* 原始单据按钮 */
.ep-doc-btn {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px; margin-top: 8px;
    background: #F7FAFC; border: 1px solid #E2E8F0;
    border-radius: 10px; text-decoration: none; color: #2D3748;
    transition: background 0.15s;
}
.ep-doc-btn:hover { background: #EDF2F7; }
.ep-doc-btn-icon { font-size: 20px; flex-shrink: 0; }
.ep-doc-btn-label { flex: 1; font-size: 14px; font-weight: 500; }
.ep-doc-btn-arrow { color: #A0AEC0; font-size: 14px; flex-shrink: 0; }

/* 姓名编辑 */
.inline-edit-btn {
    font-size: 14px; cursor: pointer; opacity: 0.5;
    transition: opacity 0.15s; margin-left: 4px;
}
.inline-edit-btn:hover { opacity: 1; }
.patient-edit-row {
    display: flex; gap: 6px; align-items: center;
    margin-bottom: 12px;
}
.patient-edit-row .inline-input {
    flex: 1; padding: 8px 12px; font-size: 14px; text-align: left;
}
.btn-save-sm, .btn-cancel-sm {
    padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
    border: none; cursor: pointer; white-space: nowrap;
}
.btn-save-sm { background: var(--blue); color: #fff; }
.btn-cancel-sm { background: var(--bg); color: var(--text2); border: 1px solid var(--border); }