/* ================= 移动端优先 CRM 样式 ================= */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --text: #1f2937;
    --text-2: #6b7280;
    --text-3: #9ca3af;
    --bg: #f4f5f7;
    --card: #ffffff;
    --line: #e5e7eb;
    --danger: #ef4444;
    --warn: #f59e0b;
    --success: #10b981;
    --radius: 12px;
    --header-h: 52px;
    --tab-h: 58px;
    --shadow: 0 1px 3px rgba(17, 24, 39, .06), 0 6px 18px rgba(17, 24, 39, .04);
}

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

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

a { color: var(--primary); text-decoration: none; }

.app {
    max-width: 680px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
    padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom));
}

/* 顶部栏 */
.app-header {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--header-h);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 12px;
    background: rgba(255, 255, 255, .96);
    backdrop-filter: saturate(180%) blur(12px);
    border-bottom: 1px solid var(--line);
}

.hdr-btn {
    width: 36px;
    height: 36px;
    border: 0;
    background: transparent;
    border-radius: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text);
    position: relative;
    cursor: pointer;
    font-size: 16px;
}

.hdr-btn:active { background: #f3f4f6; }
.hdr-btn svg { width: 20px; height: 20px; }

.hdr-title {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge-dot {
    position: absolute;
    top: 5px;
    right: 4px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 9px;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    line-height: 16px;
    text-align: center;
    font-weight: 600;
}

/* 主体 */
.app-main {
    padding: 12px;
}

.page-title {
    font-size: 17px;
    font-weight: 600;
    margin: 2px 0 10px;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px;
    margin-bottom: 12px;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.card-title {
    font-size: 15px;
    font-weight: 600;
}

.card-more { font-size: 12px; color: var(--text-2); }

/* 统计 */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}

.kpi {
    background: var(--card);
    border-radius: var(--radius);
    padding: 12px 14px;
    box-shadow: var(--shadow);
}

.kpi-label { font-size: 12px; color: var(--text-2); }
.kpi-value {
    font-size: 21px;
    font-weight: 700;
    margin-top: 4px;
    letter-spacing: -.3px;
}
.kpi-value small { font-size: 12px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.kpi-value.primary { color: var(--primary); }

/* 列表 */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; margin-bottom: 12px; }

.list-item {
    display: block;
    padding: 13px 14px;
    border-bottom: 1px solid #f1f2f4;
    color: var(--text);
}

.list-item:last-child { border-bottom: 0; }
.list-item:active { background: #fafafa; }

.item-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.item-name {
    min-width: 0;
    font-size: 15px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.item-meta {
    margin-top: 5px;
    font-size: 12px;
    color: var(--text-2);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
}

.item-desc {
    margin-top: 6px;
    font-size: 13px;
    color: #4b5563;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.muted { color: var(--text-2); }
.small { font-size: 12px; }
.strong { font-weight: 600; }
.mt6 { margin-top: 6px; }
.mt10 { margin-top: 10px; }
.mt14 { margin-top: 14px; }
.tip-bar {
  background: #eff6ff;
  color: #1d4ed8;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 12px;
  margin-bottom: 10px;
}
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap8 { gap: 8px; }

/* 标签 */
.tag {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 6px;
    font-size: 11px;
    line-height: 18px;
    background: #f3f4f6;
    color: #4b5563;
    white-space: nowrap;
}
.tag-blue { background: #e0ecff; color: #1d4ed8; }
.tag-green { background: #dcfce7; color: #15803d; }
.tag-orange { background: #fef3c7; color: #b45309; }
.tag-red { background: #fee2e2; color: #b91c1c; }
.tag-gray { background: #f3f4f6; color: #6b7280; }
.tag-level-A { background: #fee2e2; color: #b91c1c; }
.tag-level-B { background: #fef3c7; color: #b45309; }
.tag-level-C { background: #e0ecff; color: #1d4ed8; }
.tag-level-D { background: #f3f4f6; color: #6b7280; }

/* 表单 */
.form-card { padding: 4px 14px 14px; }

.form-item {
    padding: 11px 0;
    border-bottom: 1px solid #f1f2f4;
}
.form-item:last-child { border-bottom: 0; }

.form-label {
    display: block;
    font-size: 13px;
    color: var(--text-2);
    margin-bottom: 6px;
}
.form-label .req { color: var(--danger); }

.input, .select, .textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 10px 12px;
    font-size: 15px;
    color: var(--text);
    background: #fff;
    outline: none;
    font-family: inherit;
}

.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); }
.textarea { min-height: 90px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }

.radio-group, .check-group { display: flex; flex-wrap: wrap; gap: 8px; }

.check-item {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 13px;
    background: #fff;
}
.check-item input { accent-color: var(--primary); }

.menu-group { border: 1px solid var(--line); border-radius: 9px; padding: 10px; margin-bottom: 10px; }
.menu-group-title { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.menu-children { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 44px;
    padding: 0 16px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    font-family: inherit;
}
.btn:active { opacity: .85; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.btn-link { border: 0; background: transparent; color: var(--primary); padding: 0; height: auto; }

.btn-row { display: flex; gap: 10px; margin-top: 14px; }

/* 筛选 */
.filters { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.filters .input, .filters .select { height: 40px; padding: 8px 10px; font-size: 14px; width: auto; }
.filters .input { flex: 1 1 auto; min-width: 0; }
.filters .select, .filters .btn { flex: 0 0 auto; }
.filters .btn { padding: 0 12px; }
.att { display: inline-flex; align-items: center; gap: 3px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.seg { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; -webkit-overflow-scrolling: touch; }
.seg a {
    flex: 0 0 auto;
    padding: 6px 12px;
    border-radius: 16px;
    background: #fff;
    color: var(--text-2);
    font-size: 13px;
    border: 1px solid var(--line);
}
.seg a.on { background: var(--primary); border-color: var(--primary); color: #fff; }

/* 底部导航 */
.tabbar {
    position: fixed;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    width: 100%;
    max-width: 680px;
    height: calc(var(--tab-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: rgba(255, 255, 255, .98);
    border-top: 1px solid var(--line);
    display: flex;
    z-index: 40;
}

.tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-3);
    font-size: 10px;
}
.tabbar a svg { width: 21px; height: 21px; }
.tabbar a.on { color: var(--primary); }

/* 抽屉菜单 */
.drawer-mask {
    position: fixed;
    inset: 0;
    background: rgba(17, 24, 39, .42);
    z-index: 50;
    opacity: 0;
    visibility: hidden;
    transition: .2s;
}
.drawer-mask.show { opacity: 1; visibility: visible; }

.drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 82%;
    max-width: 320px;
    background: #fff;
    z-index: 51;
    transform: translateX(-102%);
    transition: transform .24s ease;
    display: flex;
    flex-direction: column;
}
.drawer.show { transform: translateX(0); }

.drawer-head {
    padding: 18px 16px 14px;
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff;
}
.drawer-head .name { font-size: 17px; font-weight: 600; }
.drawer-head .sub { font-size: 12px; opacity: .85; margin-top: 4px; }

.drawer-body { flex: 1; overflow-y: auto; padding: 10px 10px 24px; }
.drawer-group { margin-bottom: 6px; }
.drawer-group > .g-title {
    font-size: 12px;
    color: var(--text-3);
    padding: 10px 8px 6px;
    letter-spacing: .5px;
}
.drawer-link {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 10px;
    border-radius: 9px;
    color: var(--text);
    font-size: 14px;
}
.drawer-link:active { background: #f3f4f6; }
.drawer-link.on { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.drawer-link .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--line); }
.drawer-link.on .dot { background: var(--primary); }
.drawer-foot { padding: 10px; border-top: 1px solid var(--line); }

/* 提示 */
.flash {
    margin: 10px 12px 0;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    display: flex;
    gap: 8px;
    align-items: flex-start;
}
.flash.ok { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.flash.err { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 100px;
    transform: translateX(-50%) translateY(10px);
    background: rgba(17, 24, 39, .9);
    color: #fff;
    padding: 9px 16px;
    border-radius: 20px;
    font-size: 13px;
    z-index: 99;
    opacity: 0;
    transition: .2s;
    pointer-events: none;
    max-width: 80%;
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* 空状态 */
.empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-3);
    font-size: 13px;
}
.empty svg { width: 42px; height: 42px; margin-bottom: 8px; opacity: .5; }

/* 数据管理 */
.mono { font-family: Consolas, "Courier New", monospace; }
.tag-gray { background: #f1f5f9; color: #475569; }

/* 分页 */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 6px 0 16px;
    font-size: 13px;
    color: var(--text-2);
}
.pagination a {
    padding: 7px 14px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--text);
}
.pagination a.disabled { opacity: .4; pointer-events: none; }

/* 仪表盘 */
.funnel-row { display: flex; align-items: center; gap: 8px; margin-bottom: 9px; }
.funnel-label { width: 84px; font-size: 12px; color: var(--text-2); flex: 0 0 auto; }
.funnel-bar { flex: 1; height: 9px; background: #f1f2f4; border-radius: 5px; overflow: hidden; }
.funnel-bar i { display: block; height: 100%; border-radius: 5px; background: linear-gradient(90deg, #60a5fa, #2563eb); }
.funnel-num { width: 104px; text-align: right; font-size: 12px; color: var(--text-2); flex: 0 0 auto; }

.todo-item { display: flex; gap: 10px; padding: 11px 0; border-bottom: 1px solid #f1f2f4; }
.todo-item:last-child { border-bottom: 0; }
.todo-icon { width: 34px; height: 34px; border-radius: 9px; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; flex: 0 0 auto; font-size: 11px; font-weight: 600; }
.todo-icon.overdue { background: #fee2e2; color: #b91c1c; }
.todo-main { flex: 1; min-width: 0; }
.todo-title { font-size: 14px; font-weight: 500; }
.todo-sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

/* 详情键值 */
.kv { display: flex; padding: 9px 0; border-bottom: 1px solid #f1f2f4; font-size: 14px; }
.kv:last-child { border-bottom: 0; }
.kv .k { width: 92px; color: var(--text-2); flex: 0 0 auto; }
.kv .v { flex: 1; word-break: break-all; }

/* 商机 */
.amount { font-size: 17px; font-weight: 700; color: var(--primary); letter-spacing: -.3px; }
.stage-flow { display: flex; align-items: center; gap: 4px; overflow-x: auto; padding: 2px 0 6px; -webkit-overflow-scrolling: touch; }
.stage-flow .step { flex: 0 0 auto; font-size: 11px; padding: 3px 8px; border-radius: 12px; background: #f3f4f6; color: var(--text-2); }
.stage-flow .step.done { background: #dbeafe; color: #1d4ed8; }
.stage-flow .step.on { background: var(--primary); color: #fff; }
.stage-flow .step.won { background: #dcfce7; color: #15803d; }
.stage-flow .step.lost { background: #fee2e2; color: #b91c1c; }
.stage-flow .arrow { color: var(--text-3); font-size: 11px; flex: 0 0 auto; }

/* 售后工单 */
.ticket-flow .step { flex: 1 1 0; text-align: center; white-space: nowrap; font-size: 12px; padding: 4px 2px; }
.ticket-flow .arrow { font-size: 12px; }
.ticket-logs .todo-icon { width: 54px; height: auto; min-height: 30px; padding: 4px 2px; font-size: 11px; line-height: 1.25; white-space: nowrap; text-align: center; border-radius: 8px; }

/* 合同回款 */
.progress { height: 8px; background: #f1f2f4; border-radius: 5px; overflow: hidden; margin: 8px 0 4px; }
.progress i { display: block; height: 100%; border-radius: 5px; background: linear-gradient(90deg, #34d399, #10b981); }
.plan-row { display: flex; gap: 8px; align-items: flex-start; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.plan-row:last-child { border-bottom: 0; }
.plan-row .plan-fields { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.plan-row .plan-line { display: flex; gap: 6px; align-items: center; }
.plan-row .input { padding: 8px 10px; font-size: 14px; }
.plan-row .plan-line input[type="date"] { flex: 0 0 45%; min-width: 0; }
.plan-row .plan-line input[type="number"] { flex: 1 1 auto; min-width: 0; }
.plan-row .plan-line input[type="text"] { flex: 1 1 auto; min-width: 0; }
.plan-row .plan-del { flex: 0 0 auto; height: 34px; padding: 0 10px; }
.sum-bar { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--text-2); padding: 10px 0 2px; }
.diff-red { color: #b91c1c; font-weight: 600; }

/* 登录 */
.login-wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 28px 22px 60px;
    background: linear-gradient(160deg, #1e3a8a 0%, #2563eb 46%, #60a5fa 100%);
}
.login-card {
    background: #fff;
    border-radius: 18px;
    padding: 26px 20px 22px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, .18);
    max-width: 420px;
    width: 100%;
    margin: 0 auto;
}
.login-brand { text-align: center; margin-bottom: 20px; }
.login-brand .logo {
    width: 54px; height: 54px; border-radius: 14px;
    background: linear-gradient(135deg, #2563eb, #1e40af);
    color: #fff; display: inline-flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 700; margin-bottom: 10px;
}
.login-brand h1 { font-size: 19px; margin: 0; }
.login-brand p { font-size: 12px; color: var(--text-2); margin: 6px 0 0; }
.login-field { margin-bottom: 12px; }
.login-field label { font-size: 12px; color: var(--text-2); display: block; margin-bottom: 5px; }
.login-error { background: #fef2f2; color: #b91c1c; border-radius: 9px; padding: 9px 12px; font-size: 13px; margin-bottom: 12px; }
.login-tip { text-align: center; font-size: 12px; color: rgba(255, 255, 255, .8); margin-top: 18px; }

/* 桌面宽屏：保持移动端布局居中，避免表格化 */
@media (min-width: 720px) {
    body { background: #eceef2; }
    .app { box-shadow: 0 0 0 1px rgba(17, 24, 39, .05); }
    .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}


/* ================= 报表看板 ================= */
.range-card { padding: 10px 12px; }
.range-form { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.range-form .input { flex: 1 1 118px; min-width: 0; height: 38px; padding: 6px 10px; font-size: 13px; }
.range-form .btn { flex: 0 0 auto; height: 38px; }
.range-card .seg { margin: 9px 0 8px; }
.kpi-sub { font-size: 11px; color: var(--text-3); margin-top: 2px; }
.report-total { background: #f8fafc; }

/* ================= 产品报价 ================= */
.q-item { padding: 10px 0; border-bottom: 1px dashed var(--line); display: flex; flex-direction: column; gap: 6px; }
.q-item:last-child { border-bottom: 0; }
.q-line { display: flex; gap: 6px; align-items: center; }
.q-line .select, .q-line .input { padding: 8px 10px; font-size: 14px; min-width: 0; }
.q-line .q-product { flex: 1 1 auto; }
.q-line .q-price { flex: 1 1 auto; }
.q-line .q-qty { flex: 0 0 78px; }
.q-amount { flex: 0 0 82px; text-align: right; font-size: 13px; font-weight: 600; color: var(--primary); }
.q-line .field { flex: 1 1 auto; min-width: 0; }
.q-item.has-error { background: #fff5f5; box-shadow: inset 0 0 0 1px #fecaca; border-radius: 8px; padding: 10px 8px; }

/* 字段级校验提示 */
.field-error { display: none; font-size: 12px; line-height: 1.4; color: #dc2626; margin-top: 4px; }
.field-error:not(:empty) { display: block; }
.is-invalid { border-color: #ef4444 !important; background: #fff7f7; }
.is-invalid:focus { border-color: #dc2626 !important; box-shadow: 0 0 0 3px rgba(239, 68, 68, .12); }

.doc { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px; }
.doc-hd { display: flex; justify-content: space-between; align-items: flex-start; border-bottom: 2px solid var(--primary); padding-bottom: 8px; }
.doc-brand { font-size: 18px; font-weight: 700; color: var(--primary); }
.doc-sub { font-size: 11px; color: var(--text-2); letter-spacing: .5px; }
.doc-title { font-size: 16px; font-weight: 600; margin: 12px 0 8px; line-height: 1.4; }
.doc-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; font-size: 12px; color: var(--text-2); }
.doc-meta .k { margin-right: 4px; color: var(--text-3); }
.doc-meta .v { color: var(--text); }
.doc-block { margin-top: 12px; }
.doc-block-title { font-size: 12px; color: var(--text-2); margin-bottom: 4px; }
.doc-customer { background: #f5f7fb; border-radius: 8px; padding: 8px 10px; }
.doc-table { width: 100%; border-collapse: collapse; margin-top: 12px; font-size: 11px; }
.doc-table th { background: #eef4ff; color: #1d4ed8; font-weight: 600; }
.doc-table th, .doc-table td { border: 1px solid #e2e8f0; padding: 5px 4px; text-align: left; word-break: break-all; }
.doc-table .tr { text-align: right; }
.doc-total { margin-top: 10px; margin-left: auto; width: 200px; font-size: 12px; }
.doc-total > div { display: flex; justify-content: space-between; padding: 3px 0; }
.doc-total .final { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; font-size: 15px; font-weight: 700; color: var(--primary); }
.doc-foot { margin-top: 14px; border-top: 1px solid #f1f2f4; padding-top: 8px; line-height: 1.6; }
