/* =========================================================
   合同管理工具 · 移动端样式 (m.css)
   基准宽度 375px 竖屏；仅服务 /mobile/m.html
   ========================================================= */
:root {
  --primary: #1a73e8;
  --primary-dark: #1558b0;
  --danger: #e74c3c;
  --success: #27ae60;
  --warning: #e67e22;
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #1f2937;
  --text-sub: #6b7280;
  --line: #e5e7eb;
  --tabbar-h: 56px;
  --topbar-h: 48px;
  --radius: 12px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0;
  width: 100%;
  max-width: 480px;
  margin-left: auto; margin-right: auto;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
body { min-height: 100vh; }
input, select, textarea, button { font-family: inherit; font-size: 16px; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }

/* ---------- 登录页 ---------- */
.login-view {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: linear-gradient(160deg, #1a73e8 0%, #1558b0 100%);
}
.login-box {
  width: 100%; max-width: 340px;
  background: #fff; border-radius: 20px;
  padding: 36px 26px 32px;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.login-logo {
  width: 64px; height: 64px; margin: 0 auto 12px;
  background: var(--primary); color: #fff;
  border-radius: 18px; display: flex; align-items: center; justify-content: center;
  font-size: 32px; font-weight: 700;
}
.login-title { text-align: center; margin: 0; font-size: 22px; color: var(--text); }
.login-sub { text-align: center; color: var(--text-sub); font-size: 13px; margin: 4px 0 24px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 14px; color: var(--text-sub); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fafbfc; outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); background: #fff; }
.login-msg { min-height: 20px; font-size: 13px; color: var(--danger); margin-bottom: 8px; text-align: center; }
.login-msg.ok { color: var(--success); }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-block; border: none; border-radius: 10px;
  padding: 10px 18px; font-size: 16px; font-weight: 500;
  background: #eef1f5; color: var(--text); text-align: center;
}
.btn-block { width: 100%; }
.btn-lg { padding: 13px 18px; font-size: 17px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--primary); }
.btn-sm { padding: 6px 12px; font-size: 14px; border-radius: 8px; }
.btn:active { opacity: .85; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ---------- 顶部栏 ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0;
  max-width: 480px; margin: 0 auto;
  height: var(--topbar-h);
  background: var(--primary); color: #fff;
  display: flex; align-items: center;
  padding: 0 12px;
  z-index: 20;
}
.topbar-back { display: flex; align-items: center; gap: 2px; font-size: 15px; color: #fff; }
.back-arrow { font-size: 26px; line-height: 1; }
.topbar-title { flex: 1; text-align: center; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { min-width: 44px; text-align: right; font-size: 14px; }

/* ---------- 内容区 ---------- */
.view {
  padding: calc(var(--topbar-h) + 12px) 12px calc(var(--tabbar-h) + 20px);
  min-height: 100vh;
}
.view.plain { padding-top: calc(var(--topbar-h) + 12px); }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card-title { font-size: 16px; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; justify-content: space-between; }
.card-title .sub { font-size: 12px; color: var(--text-sub); font-weight: 400; }
.section { margin-bottom: 16px; }
.section > .section-head { font-size: 14px; color: var(--text-sub); margin: 4px 2px 8px; display: flex; justify-content: space-between; align-items: center; }

/* ---------- 统计块 ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kpi-grid.kpi-2 { grid-template-columns: repeat(2, 1fr); }
.kpi {
  background: var(--card); border-radius: var(--radius);
  padding: 12px 8px; text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.kpi .num { font-size: 20px; font-weight: 700; color: var(--primary); }
.kpi .num.danger { color: var(--danger); }
.kpi .num.warn { color: var(--warning); }
.kpi .num.success { color: var(--success); }
.kpi .lbl { font-size: 12px; color: var(--text-sub); margin-top: 4px; }

/* ---------- 列表 ---------- */
.list { margin: 0; }
.list-item {
  background: var(--card); border-radius: var(--radius);
  padding: 13px 14px; margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.list-item .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.list-item .row + .row { margin-top: 6px; }
.list-item .main { font-size: 16px; font-weight: 600; }
.list-item .main .tag { font-size: 12px; font-weight: 400; }
.list-item .sub { font-size: 13px; color: var(--text-sub); }
.list-item .sub .val { color: var(--text); }
.detail-row { display: flex; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.detail-row:last-child { border-bottom: none; }
.detail-row .k { width: 96px; color: var(--text-sub); flex-shrink: 0; }
.detail-row .v { flex: 1; word-break: break-all; }

/* ---------- 搜索框 ---------- */
.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.search-bar input { flex: 1; border: none; outline: none; background: transparent; font-size: 15px; }
.search-bar .clear { color: var(--text-sub); font-size: 18px; padding: 0 4px; }

/* ---------- 徽标 ---------- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 6px;
  font-size: 12px; line-height: 1.6; white-space: nowrap;
}
.badge-success { background: #e8f5ee; color: var(--success); }
.badge-danger { background: #fdecea; color: var(--danger); }
.badge-warning { background: #fdf0e3; color: var(--warning); }
.badge-info { background: #e8f0fe; color: var(--primary); }
.badge-gray { background: #f0f1f3; color: var(--text-sub); }

/* ---------- 底部 Tab ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  max-width: 480px; margin: 0 auto;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff; border-top: 1px solid var(--line);
  display: flex; z-index: 20;
}
.tab-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  color: var(--text-sub); font-size: 11px;
}
.tab-item .tab-icon { width: 22px; height: 22px; }
.tab-item.active { color: var(--primary); font-weight: 600; }
.tab-item.active .tab-icon { filter: brightness(0) saturate(100%) invert(34%) sepia(93%) saturate(3486%) hue-rotate(203deg) brightness(94%) contrast(93%); }
/* 图标（内联 SVG data-uri，不使用 emoji） */
.tab-icon-home { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 10.5 12 3l9 7.5'/%3E%3Cpath d='M5 9.5V21h14V9.5'/%3E%3C/svg%3E") no-repeat center / contain; }
.tab-icon-shop { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 4h16l2 6a3 3 0 0 1-6 0 3 3 0 0 1-6 0 3 3 0 0 1-6 0z'/%3E%3Cpath d='M6 11v9h12v-9'/%3E%3C/svg%3E") no-repeat center / contain; }
.tab-icon-fee { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='6' width='18' height='13' rx='2'/%3E%3Cpath d='M3 10h18'/%3E%3Cpath d='M7 15h4'/%3E%3C/svg%3E") no-repeat center / contain; }
.tab-icon-report { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 20V4'/%3E%3Cpath d='M4 20h16'/%3E%3Cpath d='M8 16l4-6 3 4 4-7'/%3E%3C/svg%3E") no-repeat center / contain; }
.tab-icon-mine { background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='8' r='4'/%3E%3Cpath d='M4 21c1.5-3.5 4.5-5 8-5s6.5 1.5 8 5'/%3E%3C/svg%3E") no-repeat center / contain; }

/* ---------- 弹层 ---------- */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  width: 100%; max-width: 480px;
  background: #fff; border-radius: 16px 16px 0 0;
  padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
}
.sheet-title { font-size: 17px; font-weight: 600; margin-bottom: 14px; text-align: center; }
.sheet .field { margin-bottom: 12px; }
.sheet .field label { font-size: 13px; }
.sheet .field input, .sheet .field select, .sheet .field textarea {
  padding: 11px 12px; font-size: 15px;
}
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet-actions .btn { flex: 1; }

/* ---------- 附件列表 ---------- */
.att-list { margin-top: 4px; }
.att-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  margin-bottom: 6px; font-size: 13px;
}
.att-item .att-name { flex: 1; word-break: break-all; color: var(--primary); }
.att-del { color: var(--danger); font-size: 13px; flex-shrink: 0; }

/* ---------- 状态行 / 金额 ---------- */
.money { font-weight: 600; color: var(--text); }
.money.primary { color: var(--primary); }
.money.danger { color: var(--danger); }
.money.success { color: var(--success); }

/* ---------- 分段切换 ---------- */
.seg {
  display: flex; background: #e9ecf1; border-radius: 10px; padding: 3px;
  margin-bottom: 12px;
}
.seg .seg-item { flex: 1; text-align: center; padding: 8px 4px; font-size: 14px; border-radius: 8px; color: var(--text-sub); }
.seg .seg-item.active { background: #fff; color: var(--primary); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- 表格 ---------- */
.m-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.m-table th, .m-table td { padding: 8px 6px; text-align: left; border-bottom: 1px solid var(--line); }
.m-table th { color: var(--text-sub); font-weight: 500; white-space: nowrap; }
.m-table tr:last-child td { border-bottom: none; }
.m-table tr.clickable { cursor: pointer; }
.m-table tr.clickable:active td { background: rgba(0,0,0,0.05); }

/* ---------- 提示条 ---------- */
.empty { text-align: center; color: var(--text-sub); font-size: 14px; padding: 30px 10px; }
.hint { font-size: 12px; color: var(--text-sub); margin-top: 6px; }
.msg-error { color: var(--danger); font-size: 14px; padding: 10px; text-align: center; }
.msg-ok { color: var(--success); font-size: 14px; padding: 10px; text-align: center; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; top: 45%; transform: translate(-50%, -50%);
  background: rgba(0,0,0,.78); color: #fff;
  padding: 10px 18px; border-radius: 10px; font-size: 14px;
  z-index: 100; max-width: 80%; text-align: center;
}

/* ---------- 我的页 ---------- */
.mine-header {
  background: var(--card); border-radius: var(--radius);
  padding: 18px 16px; margin-bottom: 12px;
  display: flex; align-items: center; gap: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.mine-avatar {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
}
.mine-name { font-size: 17px; font-weight: 600; }
.mine-sub { font-size: 13px; color: var(--text-sub); margin-top: 2px; }
.mine-menu { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.mine-menu .mm-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); font-size: 15px;
}
.mine-menu .mm-item:last-child { border-bottom: none; }
.mine-menu .mm-item .arrow { color: var(--text-sub); font-size: 16px; }

/* ---------- 分隔 ---------- */
.divider { height: 1px; background: var(--line); margin: 10px 0; }

/* ---------- 加载 ---------- */
.loading { text-align: center; color: var(--text-sub); padding: 40px 10px; font-size: 14px; }

/* A2 修正：窄屏下 flex/grid 容器解除固有宽度传导，防横向溢出 */
.m-view, .card, .kpi-grid { min-width: 0; }
