/* 养顺堂财务档案制度管理系统 —— 样式 */
:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f4f6fb;
  --card: #ffffff;
  --border: #e5e9f2;
  --text: #1f2937;
  --text-muted: #6b7280;
  --green: #16a34a;
  --green-bg: #ecfdf3;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --amber: #d97706;
  --amber-bg: #fffbeb;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #2563eb 55%, #3b82f6 100%);
  padding: 20px;
}
.login-card {
  width: 380px; max-width: 100%;
  background: #fff; border-radius: 16px; padding: 36px 32px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-logo {
  width: 64px; height: 64px; border-radius: 16px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff; font-size: 26px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px; overflow: hidden;
  box-shadow: 0 8px 20px rgba(37,99,235,.35);
}
.login-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.login-title { font-size: 20px; font-weight: 700; text-align: center; }
.login-sub { font-size: 13px; color: var(--text-muted); text-align: center; margin: 6px 0 24px; }
#login-form label { display: block; font-size: 13px; color: var(--text-muted); margin: 12px 0 6px; }
#login-form input {
  width: 100%; height: 42px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
  transition: border .15s, box-shadow .15s;
}
#login-form input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.login-tip { font-size: 12px; color: var(--text-muted); text-align: center; margin-top: 18px; }

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border: none; border-radius: 8px;
  font-size: 14px; cursor: pointer; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: #f3f4f6; }
.btn-danger { background: var(--red-bg); color: var(--red); }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; margin-top: 20px; height: 44px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Tab 条 ---------- */
.tab-bar { display: inline-flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab-bar .tab {
  padding: 8px 16px; cursor: pointer; color: var(--muted);
  font-size: 14px; font-weight: 500; border-bottom: 2px solid transparent;
  transition: all .15s;
}
.tab-bar .tab:hover { color: var(--text); }
.tab-bar .tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ---------- 布局 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0; background: #0f1c3d;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.side-logo {
  width: 38px; height: 38px; border-radius: 10px; background: #2563eb;
  color: #fff; font-size: 18px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex: 0 0 auto;
}
.side-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.side-title { color: #fff; font-size: 15px; font-weight: 700; }
.side-sub { color: rgba(255,255,255,.5); font-size: 11px; }
.nav { flex: 1; overflow-y: auto; padding: 6px 0 16px; scrollbar-width: thin; }
.nav::-webkit-scrollbar { width: 4px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 4px; }
/* 仪表盘独立置顶 */
.nav-top { padding: 2px 0 6px; border-bottom: 1px solid rgba(255,255,255,.06); margin-bottom: 2px; }
.nav-top .nav-item { font-weight: 700; }
.nav-group { margin: 0 0 2px; }
.nav-group-title {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 18px 6px; color: rgba(255,255,255,.45);
  font-size: 11px; font-weight: 600; letter-spacing: 1.5px; cursor: pointer; user-select: none;
  border-bottom: 1px solid transparent; transition: color .15s;
}
.nav-group:not(.collapsed) > .nav-group-title {
  color: rgba(255,255,255,.72);
  border-bottom: 1px solid rgba(255,255,255,.06);
}
.nav-group-title:hover { color: #fff; }
.nav-group-title i { font-style: normal; font-size: 10px; transition: transform .15s; opacity:.7; }
.nav-group.collapsed .nav-group-title { padding: 7px 18px; }
.nav-group.collapsed .nav-group-title i { transform: rotate(-90deg); }
.nav-group.collapsed .nav-group-items { display: none; }
.nav-group-items { padding: 3px 0 6px; }
.nav-group-items .nav-item { padding: 9px 18px 9px 34px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 18px; color: rgba(255,255,255,.72); cursor: pointer;
  font-size: 14px; border-left: 3px solid transparent; transition: all .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: rgba(37,99,235,.28); color: #fff; border-left-color: #3b82f6; font-weight: 600; }
.nav-item .ico { width: 18px; text-align: center; }
.side-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); color: rgba(255,255,255,.6); font-size: 12px; }
.side-foot b { color: #fff; display: block; font-size: 13px; margin-bottom: 2px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 58px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px;
  position: sticky; top: 0; z-index: 10;
}
.page-title { font-size: 17px; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-date { color: var(--text-muted); font-size: 13px; }
.topbar-company {
  color: #2563eb; font-size: 13px; font-weight: 600;
  background: rgba(37,99,235,.08); padding: 5px 12px; border-radius: 20px;
  max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.content { padding: 22px 24px 40px; }

/* ---------- 卡片 ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-title { font-size: 15px; font-weight: 700; }
.card-body { padding: 20px; }
.card-body.no-pad { padding: 0; }

/* ---------- 统计卡片 ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat {
  background: #fff; border-radius: var(--radius); border: 1px solid var(--border);
  box-shadow: var(--shadow); padding: 18px;
}
.stat-label { font-size: 13px; color: var(--text-muted); }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 8px; }
.stat-value.money { font-variant-numeric: tabular-nums; }
.stat.sub .stat-value { color: var(--primary); }
.stat.inc .stat-value { color: var(--green); }
.stat.exp .stat-value { color: var(--red); }
.stat.warn .stat-value { color: var(--amber); }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #f8fafc; color: var(--text-muted); font-weight: 600; font-size: 12px; }
tbody tr:hover { background: #f9fafb; }
.ta-r { text-align: right; }
.ta-c { text-align: center; }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.amount.inc { color: var(--green); }
.amount.exp { color: var(--red); }

/* 徽章 */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.amber { background: var(--amber-bg); color: var(--amber); }
.badge.gray { background: #f3f4f6; color: var(--text-muted); }
.badge.blue { background: #eff6ff; color: var(--primary); }
.badge.ok { background: var(--green-bg); color: var(--green); }
.badge.warn { background: var(--amber-bg); color: var(--amber); }
.filter-bar { background: #f9fafb; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.filter-bar label { font-size: 13px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.filter-bar .muted { font-size: 12px; color: var(--text-muted); }

/* ---------- 工具栏 ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.toolbar .spacer { flex: 1; }
.input, .select {
  height: 36px; padding: 0 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff; color: var(--text);
}
.input:focus, .select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
.input.w-full { width: 100%; }
.input.num { text-align: right; }

/* ---------- 表单 ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.field .req { color: var(--red); }

/* 产品/收益行、合作商多选 */
.prod-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.prod-row select { flex: 1; min-width: 0; }
.prod-row input { width: 150px; flex: none; }
.prod-row .btn { flex: none; }
.checkbox-box { display: flex; flex-wrap: wrap; gap: 10px 20px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #f9fafb; }
.checkbox-line { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text); cursor: pointer; }
.checkbox-line input { cursor: pointer; }

/* 包邮规则行 */
.ship-rule-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.ship-rule-row select { flex: 1; min-width: 0; }
.ship-rule-row input { width: 150px; flex: none; }
.ship-rule-row .btn { flex: none; }
.field .hint { color: var(--text-muted); font-size: 12px; margin-left: 4px; }

/* ---------- 模态框 ---------- */
.modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; }
.modal-mask { position: absolute; inset: 0; background: rgba(15,23,42,.45); }
.modal-box {
  position: relative; width: 560px; max-width: calc(100vw - 32px); max-height: 86vh;
  background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 24px; color: var(--text-muted); cursor: pointer; line-height: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--border); }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
  background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,.2);
  animation: fadeIn .2s;
}
.toast.err { background: var(--red); }
.toast.ok { background: var(--green); }
@keyframes fadeIn { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 其他 ---------- */
.empty { text-align: center; color: var(--text-muted); padding: 40px 0; }
.link { color: var(--primary); cursor: pointer; }
.muted { color: var(--text-muted); }
.section-title { font-size: 14px; font-weight: 700; margin: 18px 0 10px; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }

.row-actions { display: flex; gap: 6px; }
.action-link { color: var(--primary); cursor: pointer; font-size: 13px; }
.action-link.danger { color: var(--red); }
.action-link:hover { text-decoration: underline; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } .form-grid { grid-template-columns: 1fr; } }

.profit-card {
  background: linear-gradient(135deg, #2563eb, #1d4ed8); color: #fff;
  border-radius: var(--radius); padding: 22px; margin-bottom: 20px;
}
.profit-card .lbl { font-size: 13px; opacity: .85; }
.profit-card .val { font-size: 30px; font-weight: 700; margin-top: 6px; }

.profit-lines { display: flex; flex-direction: column; }
.profit-lines .pl { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.profit-lines .pl b { font-variant-numeric: tabular-nums; }
.profit-lines .pl.deduct b { color: var(--red); }
.profit-lines .pl.subtotal { border-bottom: 1px solid var(--border); font-weight: 700; }
.profit-lines .pl.total { border-bottom: none; padding-top: 12px; font-size: 17px; font-weight: 700; }
.profit-lines .pl.total b { color: var(--primary); font-size: 22px; }
.cf-badge-pos { color: var(--green); font-weight: 700; }
.cf-badge-neg { color: var(--red); font-weight: 700; }

/* 利润表四层公式 */
.profit-formula {
  background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 18px; font-size: 14px; line-height: 1.8;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
}
.profit-formula .pf-lbl { font-weight: 700; color: var(--text); }
.profit-formula .pf-item { color: var(--text-muted); }
.profit-formula .pf-item.pf-emp { font-weight: 700; color: var(--primary); }
.profit-formula .pf-op { color: var(--text-muted); font-weight: 700; }

/* 数据健康检查 / 审计 */
.audit-list { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; }
.audit-row {
  background: #fff; padding: 12px 14px; border-radius: 6px;
  border: 1px solid var(--border);
}
.audit-row .audit-hdr { font-size: 14px; }

/* 收支明细·产品详情 */
.tx-items { margin-top: 6px; border-left: 3px solid var(--primary); padding-left: 8px; }
.tx-item { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.tx-item .tx-item-name { font-weight: 600; color: var(--text); }
.tx-item .tx-item-qty { color: var(--primary); }
.tx-item .tx-item-amount { color: var(--green); font-weight: 700; }

/* ============ 进销存：采购明细行 / 库存 / 结算单 ============ */
/* 明细行改「卡片式」：字段自动换行，保证每个输入框都有可读宽度。
   旧版 6 列挤在 560px 弹窗里，规格/单位/进货价/数量 被压得几乎看不见。 */
.items-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px 12px;
  align-items: end;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fafbfc;
  position: relative;
}
.items-row .fld { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.items-row .fld > span { font-size: 11px; color: var(--text-muted); }
.items-row .fld.wide { grid-column: span 2; }
.items-row .fld .input, .items-row .fld .select { width: 100%; }
.items-row > .btn { align-self: end; }
.items-head { display: none; }   /* 表头由每行字段自带 label 取代 */
@media (max-width: 620px) {
  .items-row .fld.wide { grid-column: span 1; }
}
/* 结算单状态标签 */
.tag-settle-off { background: #fee2e2; color: #b91c1c; }
.tag-settle-on { background: #dcfce7; color: #15803d; }

/* 明细行操作区（右侧删除按钮，卡片式下换到独立一行） */
.items-row .row-del { align-self: end; }
/* 宽弹窗（采购/门店等字段较多的表单） */
.modal-box.wide { width: 880px; }
@media (max-width: 920px) { .modal-box.wide { width: calc(100vw - 24px); } }
/* 超宽弹窗（送货单明细列多，窄了会挤掉「平台运费/包装/备注」） */
.modal-box.xwide { width: 1180px; max-height: 90vh; }
@media (max-width: 1220px) { .modal-box.xwide { width: calc(100vw - 24px); } }
/* 明细表在窄屏下允许横向滚动，避免列被压扁 */
#del-items-box { overflow-x: auto; }
#del-items-box table { min-width: 980px; }

/* ============ 可点击的统计卡片（仪表盘下钻） ============ */
.stat-clickable { cursor: pointer; transition: transform .12s, box-shadow .12s, border-color .12s; position: relative; }
.stat-clickable:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(37,99,235,.14); border-color: var(--primary); }
.stat-clickable:active { transform: translateY(0); }
.stat-arrow { position: absolute; top: 10px; right: 12px; font-size: 18px; line-height: 1; color: var(--text-muted); opacity: .45; }
.stat-clickable:hover .stat-arrow { opacity: 1; color: var(--primary); }
