/* =====================================================================
 * 企微自建应用 - 共享设计系统 (app.css)
 * 所有模块页统一引用，保证小程序式一致观感。
 * 色卡沿用既有 #2d6a4f 主色。
 * ===================================================================== */

:root {
    --primary: #2d6a4f;
    --primary-light: #40916c;
    --primary-dark: #1b4332;
    --secondary: #0891b2;
    --success: #16a34a;
    --warning: #e6a23c;
    --danger: #f56c6c;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --bg-page: #f5f7fb;
    --bg-card: #ffffff;
    --bg-soft: #f8fafc;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --header-h: 52px;
    --tabbar-h: 58px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}

a { color: inherit; text-decoration: none; }

/* ===================== 顶栏 ===================== */
.app-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: #fff;
    padding: 10px 16px;
    padding-top: calc(10px + env(safe-area-inset-top, 0px));
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: calc(var(--header-h) + env(safe-area-inset-top, 0px));
}
.app-header .back {
    width: 34px; height: 34px; border-radius: 50%;
    background: rgba(255,255,255,.15); border: none; color: #fff;
    font-size: 20px; cursor: pointer; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
}
.app-header .title { flex: 1; min-width: 0; font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.app-header .subtitle { font-size: 12px; opacity: .9; margin-top: 2px; }
.app-header .action { background: rgba(255,255,255,.15); border: none; color: #fff; padding: 7px 14px; border-radius: 20px; font-size: 13px; cursor: pointer; flex: 0 0 auto; }

/* 无 tab 栏的详情/表单页：去掉底部留白 */
body.no-tabbar { padding-bottom: 0; }

/* ===================== 内容容器 ===================== */
.app-main { max-width: 820px; margin: 0 auto; padding: 16px; }

/* ===================== 卡片 ===================== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 14px;
}
.card-title { font-size: 15px; font-weight: 600; color: var(--primary); margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }

/* 统计卡 */
.stats-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-card { background: var(--bg-card); border-radius: var(--radius-md); padding: 16px 12px; text-align: center; box-shadow: var(--shadow-sm); border: 2px solid var(--primary); cursor: pointer; transition: transform .15s; }
.stat-card:active { transform: scale(.98); }
.stat-card .num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-card .lbl { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }

/* ===================== 按钮 ===================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    background: var(--bg-card); color: var(--primary);
    border: 1.5px solid var(--primary); border-radius: var(--radius-sm);
    padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer;
    transition: all .15s; text-align: center;
}
.btn:hover { background: var(--bg-soft); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #94a3b8; color: #fff; border-color: #94a3b8; }
.btn-warning { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 10px; font-size: 13px; border-radius: 20px; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .btn { flex: 1; min-width: 80px; }

/* ===================== 列表项 ===================== */
.list-item { background: var(--bg-card); border-radius: var(--radius-md); padding: 14px; box-shadow: var(--shadow-sm); margin-bottom: 12px; }
.list-item .item-title { font-size: 16px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.list-item .item-meta { font-size: 13px; color: var(--text-secondary); }
.list-item .item-actions { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.list-item .item-actions .btn { flex: 1; min-width: 84px; }

/* ===================== 表单 ===================== */
.form-group { margin-bottom: 12px; width: 100%; }
.form-group > label { border-left: 3px solid var(--primary); padding-left: 10px; margin-bottom: 8px; display: block; font-weight: 600; font-size: 14px; }
input, select, textarea, input[type="date"], input[type="datetime-local"] {
    width: 100%; max-width: 100%; box-sizing: border-box;
    padding: 10px 12px; border: 1px solid #cbd5e1; border-radius: var(--radius-sm);
    font-size: 14px; font-family: inherit; background: #fff; color: var(--text-primary);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(45,106,79,.12); }
textarea { resize: vertical; }
select[multiple] { min-height: 80px; }
input[type="date"], input[type="datetime-local"] { width: auto; min-width: 150px; }
.checkbox-group { display: flex; flex-direction: column; gap: 4px; }
.checkbox-group-columns { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px 8px; }
.checkbox-item { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; font-weight: normal; border-left: none; padding-left: 0; }
.checkbox-item input { width: auto; margin: 0; transform: scale(.9); }

/* ===================== 筛选 tab ===================== */
.filter-tabs { display: flex; gap: 8px; overflow-x: auto; padding: 0 2px 12px; -webkit-overflow-scrolling: touch; }
.filter-tab { flex: 0 0 auto; background: var(--bg-card); border: 1px solid var(--border); color: var(--text-secondary); padding: 7px 16px; border-radius: 20px; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap; }
.filter-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ===================== 搜索栏 ===================== */
.search-bar { display: flex; gap: 8px; background: var(--bg-card); border-radius: 24px; padding: 6px 6px 6px 16px; box-shadow: var(--shadow-sm); margin-bottom: 14px; }
.search-bar input { flex: 1; min-width: 0; border: none; outline: none; font-size: 15px; padding: 8px 0; background: transparent; }
.search-bar input:focus { box-shadow: none; }
.search-bar .btn { border-radius: 20px; }

/* ===================== 底部 tab 栏（小程序观感） ===================== */
.tab-bar {
    position: fixed; left: 0; right: 0; bottom: 0;
    background: var(--bg-card); border-top: 1px solid var(--border);
    display: flex; z-index: 200;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    min-height: var(--tabbar-h);
}
.tab-bar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; color: var(--text-muted); font-size: 11px; padding: 6px 0; cursor: pointer;
}
.tab-bar a .ico { font-size: 20px; line-height: 1; }
.tab-bar a.active { color: var(--primary); font-weight: 600; }
.tab-bar a.disabled { opacity: .35; pointer-events: none; }

/* ===================== 状态/辅助 ===================== */
.empty { text-align: center; color: var(--text-muted); padding: 48px 20px; font-size: 14px; }
.loading { text-align: center; color: var(--text-secondary); padding: 32px; }
.tag { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.tag-pending { background: #fef3c7; color: #92400e; }
.tag-done { background: #dcfce7; color: #166534; }
.tag-warn { background: #fee2e2; color: #991b1b; }
hr { margin: 16px 0; border: none; border-top: 1px solid var(--border); }
.muted { color: var(--text-muted); }
.center { text-align: center; }
.row { display: flex; gap: 8px; align-items: center; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }

/* ===================== Toast ===================== */
.toast { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%) scale(.9); background: rgba(30,41,59,.92); color: #fff; padding: 12px 20px; border-radius: var(--radius-sm); font-size: 14px; z-index: 9999; opacity: 0; pointer-events: none; transition: all .2s; max-width: 80%; text-align: center; }
.toast.show { opacity: 1; transform: translate(-50%,-50%) scale(1); }

/* ===================== 模块启动器（首页）卡片 ===================== */
.module-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.module-card { background: var(--bg-card); border-radius: var(--radius-md); padding: 18px 14px; text-align: center; cursor: pointer; box-shadow: var(--shadow-sm); border: 2px solid var(--primary); transition: transform .15s; }
.module-card:active { transform: scale(.97); }
.module-card .ico { font-size: 30px; }
.module-card .name { font-size: 15px; font-weight: 600; color: var(--primary); margin-top: 8px; }
.module-card .desc { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.section-title { grid-column: 1 / -1; margin: 8px 0 -4px; font-size: 13px; font-weight: 700; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.section-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ===================== 预约模块补充样式 ===================== */
/* 状态标签变体：0 待处理 / 1 已联系 / 2 已完成 / 3 已取消 */
.tag-info { background: #dbeafe; color: #1e40af; }
.tag-success { background: #dcfce7; color: #166534; }
.tag-muted { background: #e2e8f0; color: #475569; }
.tag-small { font-size: 11px; padding: 1px 8px; }

/* 列表卡左侧状态色条 */
.list-item.has-bar { border-left: 4px solid var(--border); }
.list-item.bar-pending { border-left-color: var(--warning); }
.list-item.bar-confirmed { border-left-color: #3b82f6; }
.list-item.bar-completed { border-left-color: var(--success); }
.list-item.bar-cancelled { border-left-color: var(--text-muted); }

/* 患者行：头像 + 姓名 */
.pt-row { display: flex; align-items: center; gap: 10px; }
.pt-avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; background: var(--bg-soft); flex: 0 0 auto; }
.pt-avatar.placeholder { display: flex; align-items: center; justify-content: center; background: var(--primary-light); color: #fff; font-size: 16px; font-weight: 600; }
.pt-main { flex: 1; min-width: 0; }
.pt-name { font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pt-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* 详情键值表 */
.kv { display: grid; grid-template-columns: 92px 1fr; gap: 8px 12px; font-size: 14px; }
.kv .k { color: var(--text-secondary); }
.kv .v { color: var(--text-primary); word-break: break-all; }

/* 图片画廊 / 全屏查看 */
.img-gallery { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.img-gallery .thumb { width: 72px; height: 72px; object-fit: cover; border-radius: var(--radius-sm); cursor: pointer; border: 1px solid var(--border); }
.image-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 9999; display: none; align-items: center; justify-content: center; padding: 20px; }
.image-overlay.show { display: flex; }
.image-overlay img { max-width: 100%; max-height: 100%; object-fit: contain; }
.image-overlay .close { position: absolute; top: 16px; right: 20px; background: rgba(255,255,255,.2); border: none; color: #fff; width: 40px; height: 40px; border-radius: 50%; font-size: 24px; cursor: pointer; }

/* 上传图片预览（回复表单） */
.upload-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.upload-thumb { position: relative; }
.upload-thumb img { width: 72px; height: 72px; object-fit: cover; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.upload-thumb .rm { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: var(--danger); color: #fff; border: none; font-size: 14px; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; }

/* 快捷回复 chips */
.chip-group { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-secondary); padding: 6px 12px; border-radius: 16px; font-size: 13px; cursor: pointer; }
.chip:active { transform: scale(.96); }

/* 筛选行（日期 + 下拉） */
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.filter-row.full { grid-template-columns: 1fr; }
.filter-row label { font-size: 12px; color: var(--text-secondary); display: block; margin-bottom: 4px; }
.filter-row input, .filter-row select { width: 100%; }

/* 分页 */
.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 16px 0 4px; }
.pagination button { min-width: 72px; }
.pagination .info { font-size: 13px; color: var(--text-secondary); }

/* 底部操作条（详情页） */
.action-bar { position: sticky; bottom: 0; left: 0; right: 0; background: var(--bg-card); border-top: 1px solid var(--border); padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 8px; flex-wrap: wrap; box-shadow: 0 -2px 8px rgba(0,0,0,.04); }
.action-bar .btn { flex: 1; min-width: 96px; }

/* 信息小节标题 */
.sec-title { font-size: 14px; font-weight: 600; color: var(--primary); margin: 4px 0 10px; display: flex; align-items: center; gap: 6px; }
.sec-title::before { content: ""; width: 3px; height: 14px; background: var(--primary); border-radius: 2px; }
