/* ==========================================================================
   礼向往来系统 —— 样式
   移动优先。视觉语言取自 king.jinzhiming.cn 的 .dc-* 设计系统
   （圆角 14px、琥珀色主色 #f59e0b、卡片 + 胶囊），另加它没有的底部 tab bar。
   全部自包含，不引任何 CDN。
   ========================================================================== */

:root {
    --primary:        #f59e0b;
    --primary-dark:   #d97706;
    --primary-soft:   rgba(245, 158, 11, .1);

    --bg:             #f1f5f9;
    --card:           #fff;
    --text:           #1e293b;
    --muted:          #94a3b8;
    --border:         #e2e8f0;
    --line-soft:      #f1f5f9;

    --ink:            #0f1729;   /* 顶部栏 / 登录页的深色 */
    --ink-2:          #1e293b;

    --in-color:       #2563eb;   /* 来礼（收） */
    --in-soft:        #dbeafe;
    --out-color:      #b45309;   /* 送礼（出） */
    --out-soft:       #fef3c7;
    --pos:            #16a34a;
    --neg:            #dc2626;

    --radius:         14px;
    --radius-sm:      10px;
    --shadow:         0 1px 3px rgba(0, 0, 0, .04), 0 1px 2px rgba(0, 0, 0, .03);
    --shadow-lg:      0 12px 32px rgba(0, 0, 0, .18);

    --tabbar-h:       62px;
}

* { box-sizing: border-box; }

/* 页面整体不允许左右滑。这里必须用 clip 而不是 hidden：
   hidden 会把 html/body 变成滚动容器，顶上那条 .topbar 是 sticky 的，
   sticky 会跟着失效。clip 只裁剪、不创建滚动容器。
   老浏览器不认 clip 会忽略这一行，退回原来的行为（不会更糟）。 */
html { -webkit-text-size-adjust: 100%; overflow-x: clip; }

body {
    margin: 0;
    font-family: 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', system-ui, sans-serif;
    font-size: .9375rem;
    line-height: 1.6;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    /* 给底部 tab bar 留位，并躲开 iPhone 的横条 */
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
}

a { color: inherit; text-decoration: none; }
.ico { display: block; }

/* 金额、序号一律等宽数字，列表里不会跳 */
.amount, .num, .item-meta, .stat-val, .tabbar { font-variant-numeric: tabular-nums; }

/* ---------------- 顶部栏 ---------------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: linear-gradient(135deg, var(--ink), var(--ink-2));
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
    padding-top: env(safe-area-inset-top, 0px);
}
.topbar-in {
    max-width: 640px;
    margin: 0 auto;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.topbar-title { font-size: 17px; font-weight: 700; letter-spacing: .5px; }
.topbar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    border-radius: 10px;
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .15);
    color: #fff;
    flex-shrink: 0;
}
.topbar-btn:active { background: rgba(255, 255, 255, .2); }

/* ---------------- 容器与卡片 ---------------- */

.container { max-width: 640px; margin: 0 auto; padding: 14px; }

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 14px;
    overflow: hidden;
}
.card-head {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.card-head .sub { font-weight: 400; font-size: 12px; color: var(--muted); }
.card-body { padding: 14px 16px; }
.card-body.tight { padding: 0; }

/* ---------------- 胶囊筛选 ---------------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f1f5f9;
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 7px 15px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    white-space: nowrap;
    user-select: none;
    transition: .15s;
}
.chip:active { transform: scale(.96); }
.chip.on {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
}

/* ---------------- 表单 ---------------- */

.field { margin-bottom: 13px; }
.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .02em;
    margin-bottom: 5px;
}
.field-label .req { color: var(--neg); margin-left: 2px; }
.field-label .hint { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }

.input, .select, .textarea {
    display: block;
    width: 100%;
    padding: 11px 14px;
    /* 必须 ≥16px：iOS（含微信/企微内置浏览器）聚焦字号小于 16px 的输入框时
       会自动放大页面，放大后视觉视口宽过布局视口 —— 表现就是整页能左右拖，
       表单看着「太宽」。viewport 里的 maximum-scale=1 在部分内置浏览器里
       并不管用，字号才是可靠的解法，顺手字也更好读了。 */
    font-size: 16px;
    font-family: inherit;
    line-height: 1.5;
    color: var(--text);
    background: #f8fafc;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: .2s;
}
.input:focus, .select:focus, .textarea:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.textarea { resize: vertical; min-height: 66px; }
.select {
    appearance: none;
    padding-right: 36px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M6 8L1 3h10z' fill='%2394a3b8'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

/* 金额输入：大号字，一眼看清 */
.input-amount {
    font-size: 26px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 1px;
    padding: 10px;
}
.amount-row { display: flex; align-items: center; gap: 8px; }
.amount-row .yuan { font-size: 15px; color: var(--muted); flex-shrink: 0; }

/* 快捷金额 */
.quick-amounts { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.quick-amounts .chip { padding: 5px 13px; font-size: 13px; }

/* 两列排布（关系 / 地点之类） */
.field-row { display: flex; gap: 10px; }
.field-row > * { flex: 1; min-width: 0; }

/* ---------------- 按钮 ---------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 18px;
    font-size: 15px;
    font-family: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: .15s;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-gray { background: #e5e7eb; color: #374151; }
.btn-danger { background: #ef4444; color: #fff; }
.btn-block { display: flex; width: 100%; height: 48px; font-size: 16px; }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------------- 列表项 ---------------- */

.item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 16px;
    border-bottom: 1px solid var(--line-soft);
}
.item:last-child { border-bottom: none; }
.item-main { flex: 1; min-width: 0; }
.item-title {
    font-size: 15px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
    margin-bottom: 3px;
}
.item-meta {
    font-size: 12px;
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
}
.item-note {
    font-size: 13px;
    color: #475569;
    background: #f8fafc;
    border-radius: 8px;
    padding: 5px 9px;
    margin-top: 6px;
    line-height: 1.45;
}
.item-side { flex-shrink: 0; text-align: right; }
.item-actions { display: flex; gap: 6px; margin-top: 7px; justify-content: flex-end; }

/* ---------------- 金额与徽标 ---------------- */

.amount { font-weight: 700; }
.amount-in { color: var(--in-color); }
.amount-out { color: var(--out-color); }
.amount-big { font-size: 17px; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-in { background: var(--in-soft); color: var(--in-color); }
.badge-out { background: var(--out-soft); color: var(--out-color); }
.badge-gray { background: #f1f5f9; color: #64748b; }
.badge-pos { background: #dcfce7; color: var(--pos); }
.badge-neg { background: #fee2e2; color: var(--neg); }

/* ---------------- 统计块 ---------------- */

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 15px;
}
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat-val { font-size: 22px; font-weight: 800; line-height: 1.25; }
.stat-val small { font-size: 12px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.stat-in .stat-val { color: var(--in-color); }
.stat-out .stat-val { color: var(--out-color); }

/* 分布条 */
.bars { margin-top: 4px; }
.bar-row {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 7px 0;
    font-size: 13px;
}
.bar-name { width: 62px; flex-shrink: 0; color: var(--text); }
.bar-track {
    flex: 1;
    height: 8px;
    background: var(--line-soft);
    border-radius: 5px;
    overflow: hidden;
    min-width: 0;
}
.bar-fill { height: 100%; border-radius: 5px; background: var(--primary); }
.bar-num { width: 66px; text-align: right; flex-shrink: 0; color: var(--muted); font-size: 12px; }

/* ---------------- 空态与提示 ---------------- */

.empty { text-align: center; padding: 34px 16px; color: var(--muted); }
.empty-ico { font-size: 34px; display: block; margin-bottom: 8px; }

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: 13px;
    line-height: 1.5;
}
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.alert-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ---------------- 底部 tab bar ---------------- */

.tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 200;
    display: flex;
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    height: var(--tabbar-h);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    transition: color .15s;
}
.tab.on { color: var(--primary); }
.tab:active { opacity: .6; }

/* 悬浮登记按钮：压在 tab bar 上方 */
.fab {
    position: fixed;
    right: 18px;
    bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 16px);
    z-index: 190;
    width: 54px; height: 54px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(245, 158, 11, .45);
    transition: .15s;
}
.fab:active { transform: scale(.94); }

/* ---------------- 底部弹出表单（sheet） ---------------- */

.sheet-mask {
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0, 0, 0, .45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s;
}
.sheet-mask.open { opacity: 1; pointer-events: auto; }

.sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    /* 跟 .container / .topbar-in 用同一个上限，桌面上别拉满整屏
       （不设的话 1280px 窗口里输入框能有 870px 宽） */
    max-width: 640px;
    margin: 0 auto;
    z-index: 310;
    /* vh 在手机上按「地址栏收起后」的最大视口算，工具栏一露出来 sheet 就比
       可视区还高，底部按钮会被浏览器工具栏盖住。dvh 跟随实际可视高度；
       老浏览器不认 dvh，上一行 vh 兜底。 */
    max-height: 92vh;
    max-height: 92dvh;
    display: flex;
    flex-direction: column;
    background: var(--card);
    border-radius: 20px 20px 0 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(101%);
    transition: transform .26s cubic-bezier(.32, .72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet.open { transform: translateY(0); }

.sheet-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.sheet-head h3 { margin: 0; font-size: 16px; font-weight: 700; }
.sheet-close {
    background: none;
    border: none;
    font-size: 24px;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    padding: 0 4px;
}
/* 表单自己也得是 flex 容器并允许收缩（min-height:0），高度链才能从 .sheet
   一路传到 .sheet-body。少了这一条，.sheet-body 的高度就只是「内容多高就多高」，
   下面的 overflow-y:auto 形同虚设 —— 表现是弹层被内容撑破、保存按钮跑到屏幕外、
   整页还滑不动（因为溢出的是 sheet，不是可滚动区）。 */
#gift-form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; }
/* 只给上下滚。overflow-y:auto 时 overflow-x 会自动算成 auto，
   内容一旦偏宽就能横向拖 —— 这里显式钉成 hidden。 */
.sheet-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 14px 18px;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.sheet-foot {
    padding: 12px 18px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 10px;
    flex-shrink: 0;
}
.sheet-foot .btn { flex: 1; height: 48px; font-size: 16px; }

/* 自动补全下拉 */
.suggest {
    position: absolute;
    left: 0; right: 0; top: 100%;
    z-index: 20;
    background: #fff;
    border: 1.5px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: 0 8px 20px rgba(0, 0, 0, .1);
    max-height: 210px;
    overflow-y: auto;
}
.suggest.hide { display: none; }
.suggest-item { padding: 10px 14px; font-size: 15px; cursor: pointer; }
.suggest-item:active, .suggest-item.hover { background: var(--primary-soft); }
.suggest-wrap { position: relative; }

/* ---------------- 提示浮层（toast） ---------------- */

.toast-mask {
    position: fixed;
    inset: 0;
    z-index: 400;
    background: rgba(0, 0, 0, .35);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 70px;
    animation: fadein .18s;
}
.toast {
    background: #fff;
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    width: 92%;
    max-width: 380px;
    overflow: hidden;
    animation: pop .24s ease;
}
.toast-head { display: flex; align-items: center; gap: 10px; padding: 17px 20px 10px; }
.toast-ico {
    width: 40px; height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}
.toast-ico.ok { background: #dcfce7; }
.toast-ico.bad { background: #fee2e2; }
.toast-head h4 { margin: 0; font-size: 16px; font-weight: 700; }
.toast-body { padding: 0 20px 6px; }
.toast-row {
    display: flex;
    gap: 9px;
    padding: 6px 0;
    font-size: 14px;
    border-bottom: 1px solid var(--line-soft);
}
.toast-row:last-child { border-bottom: none; }
.toast-label { color: var(--muted); font-size: 12px; min-width: 42px; padding-top: 2px; }
.toast-val { font-weight: 600; flex: 1; word-break: break-all; }
.toast-foot { display: flex; justify-content: flex-end; padding: 6px 20px 16px; }

/* ---------------- 确认弹窗（居中） ---------------- */

/* 卡片内部直接复用上面的 .toast-* 系列；只有遮罩不一样 ——
   .toast-mask 是顶部对齐的（结果提示从上方弹出来更自然），
   而输口令这种要「停下来处理」的弹窗得居中。 */
.modal-mask {
    position: fixed;
    inset: 0;
    z-index: 410;
    background: rgba(0, 0, 0, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    animation: fadein .18s;
}
.modal-field { padding: 0 20px 6px; }
/* .alert 自带 margin-bottom，在弹窗里要的是 margin-top */
.modal-err { margin: 12px 0 0; }
.modal-err.hide { display: none; }
.modal-foot { display: flex; gap: 10px; padding: 14px 20px 16px; }
.modal-foot .btn { flex: 1; height: 42px; }

@keyframes fadein { from { opacity: 0 } to { opacity: 1 } }
@keyframes pop { from { opacity: 0; transform: translateY(-10px) scale(.97) } to { opacity: 1; transform: none } }

/* ---------------- 登录页 ---------------- */

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, var(--ink) 0%, var(--ink-2) 50%, var(--ink) 100%);
}
.login-page::before,
.login-page::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
}
.login-page::before {
    top: -30%; right: -20%;
    width: 500px; height: 500px;
    background: radial-gradient(circle, rgba(245, 158, 11, .12), transparent 70%);
}
.login-page::after {
    bottom: -20%; left: -10%;
    width: 400px; height: 400px;
    background: radial-gradient(circle, rgba(59, 130, 246, .06), transparent 70%);
}
.login-card {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 400px;
    padding: 38px 30px;
    background: rgba(255, 255, 255, .04);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, .08);
    border-radius: 20px;
    animation: pop .5s ease;
}
.login-logo {
    width: 56px; height: 56px;
    margin: 0 auto 16px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    background: linear-gradient(135deg, rgba(245, 158, 11, .3), rgba(217, 119, 6, .3));
}
.login-card h3 {
    margin: 0 0 4px;
    color: #fff;
    font-size: 20px;
    font-weight: 700;
    text-align: center;
    letter-spacing: 1px;
}
.login-sub {
    margin: 0 0 22px;
    color: rgba(255, 255, 255, .4);
    font-size: 13px;
    text-align: center;
}
.login-label {
    display: block;
    margin-bottom: 6px;
    color: rgba(255, 255, 255, .6);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .5px;
}
.login-input {
    width: 100%;
    padding: 13px 14px;
    font-size: 16px;
    font-family: inherit;
    color: #fff;
    background: rgba(255, 255, 255, .06);
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 12px;
    outline: none;
    transition: .2s;
}
.login-input::placeholder { color: rgba(255, 255, 255, .2); }
.login-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, .15);
}
.login-btn {
    width: 100%;
    height: 48px;
    margin-top: 16px;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-family: inherit;
    font-weight: 700;
    letter-spacing: 1px;
    color: #fff;
    cursor: pointer;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    transition: .2s;
}
.login-btn:active { transform: scale(.985); }
.login-btn[disabled] { opacity: .5; cursor: not-allowed; }
.login-card .alert { background: rgba(239, 68, 68, .12); border-color: rgba(239, 68, 68, .3); color: #fca5a5; }
.login-foot {
    margin: 16px 0 0;
    text-align: center;
    color: rgba(255, 255, 255, .3);
    font-size: 12px;
}

/* ---------------- 杂项 ---------------- */

.section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    letter-spacing: .5px;
    margin: 18px 4px 8px;
}
.pager { display: flex; gap: 10px; align-items: center; justify-content: center; padding: 14px; }
.pager-info { font-size: 13px; color: var(--muted); }
.text-muted { color: var(--muted); }
.mt-10 { margin-top: 10px; }
.mb-0 { margin-bottom: 0; }
.right { text-align: right; }

@media (max-width: 480px) {
    .topbar-in { padding: 10px 12px; }
    .container { padding: 10px; }
    .card-head { padding: 12px 14px; font-size: 14px; }
    .card-body { padding: 12px 14px; }
    .item { padding: 12px 14px; }
    .stat-val { font-size: 20px; }
    .sheet-body { padding: 12px 14px; }
    .bar-name { width: 52px; }
}

/* 尊重系统的「减少动态效果」偏好 */
@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
