* { box-sizing: border-box; }
:root {
  --primary: #1677ff; --primary-d: #0958d9; --danger: #e5484d; --ok: #18a058; --warn: #f08c00;
  --bg: #f4f6f9; --card: #fff; --line: #e5e7eb; --text: #1f2328; --muted: #6b7280;
}
html, body { margin: 0; height: 100%; }
body { font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
a { color: var(--primary); text-decoration: none; cursor: pointer; }
a:hover { text-decoration: underline; }
button { font: inherit; }

/* 布局 */
.layout { display: flex; min-height: 100vh; }
/* 菜单栏：浅蓝底 + 黑色字（白色太刺眼，已按用户要求改掉） */
.side { width: 224px; position: sticky; top: 0; height: 100vh; background: linear-gradient(180deg, #eef5ff 0%, #e2edff 55%, #d5e6ff 100%); color: #1f2328; border-right: 1px solid #cfe0f7; flex-shrink: 0; display: flex; flex-direction: column; }
.side .brand { height: 56px; flex-shrink: 0; padding: 0 14px; font-size: 15px; white-space: nowrap; font-weight: bold; color: #111827; background: rgba(255,255,255,.6); border-bottom: 1px solid #d5e3f7; display: flex; align-items: center; gap: 10px; line-height: 1.3; }
.side .brand .logo { flex-shrink: 0; width: 30px; height: 30px; border-radius: 8px; background: #1677ff; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-size: 17px; font-weight: bold; }
.side nav { flex: 1; overflow-y: auto; padding: 8px 0 14px; }
.side nav::-webkit-scrollbar { width: 6px; }
.side nav::-webkit-scrollbar-button { display: none; }
.side nav::-webkit-scrollbar-track { background: transparent; }
.side nav::-webkit-scrollbar-thumb { background: #b9cfeb; border-radius: 3px; }
@supports not selector(::-webkit-scrollbar) { .side nav { scrollbar-width: thin; scrollbar-color: #b9cfeb transparent; } }

/* 一级栏目：字体加大、可点击折叠 */
.side .grp { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 10px 10px 6px; padding: 0 12px; height: 40px; border-radius: 9px; background: #cfe2ff; color: #10233f; font-size: 16px; font-weight: bold; letter-spacing: .5px; cursor: pointer; user-select: none; transition: background .15s; }
.side .grp:hover { background: #bcd7ff; }
.side .grp:focus-visible { outline: 2px solid #1677ff; outline-offset: 1px; }
.side .grp .grp-t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.side .grp .arw { flex-shrink: 0; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 7px solid #3b5a86; transform: rotate(0deg); transition: transform .18s; }
.side .grp.off .arw { transform: rotate(-90deg); }
.side .grp.off { background: #e0ebfb; color: #4b5563; }

.side .grp-body.solo { margin-top: 8px; }
.side .grp-body.hide { display: none; }
.side nav a { display: flex; align-items: center; padding: 9px 16px 9px 30px; color: #1f2328; font-size: 14px; border-radius: 8px; margin: 2px 10px; }
.side nav a::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: #93b2e0; margin-right: 10px; flex-shrink: 0; }
.side nav a:hover { background: rgba(22,119,255,.14); text-decoration: none; color: #000; }
.side nav a.on { background: #fff; color: #000; font-weight: bold; box-shadow: 0 1px 4px rgba(16,42,84,.14); border-left: 3px solid #1677ff; padding-left: 27px; }
.side nav a.on::before { background: #1677ff; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { height: 52px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; }
.top .title { font-size: 16px; font-weight: bold; }
.top .me { color: var(--muted); }
.top .me a { margin-left: 12px; }
.menu-btn { display: none; background: none; border: 0; font-size: 22px; margin-right: 8px; cursor: pointer; }
.content { padding: 18px 20px 24px; flex: 1; }
.top-l { display: flex; align-items: center; min-width: 0; }
.top .title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top { position: sticky; top: 0; z-index: 30; gap: 12px; }
.side-mask { display: none; }

/* 卡片、表单 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 16px; font-weight: 700; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .sp { flex: 1; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 4px; height: 32px; padding: 0 14px; border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 6px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--primary); color: var(--primary); text-decoration: none; }
.btn.pri { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.pri:hover { background: var(--primary-d); color: #fff; }
.btn.danger { color: var(--danger); border-color: #f3c2c4; }
.btn.danger:hover { background: var(--danger); color: #fff; }
.btn.sm { height: 26px; padding: 0 8px; font-size: 13px; }
.btn.lg { height: 40px; padding: 0 24px; font-size: 15px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: inherit; height: 34px; padding: 0 8px; border: 1px solid #d0d5dd; border-radius: 6px; background: #fff; color: var(--text); min-width: 0; }
.form input, .form select, .form textarea, .login input { font-size: 15px; }
textarea { height: 64px; padding: 6px 8px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd6ff; border-color: var(--primary); }
.form { display: grid; grid-template-columns: repeat(auto-fill, minmax(312px, 1fr)); gap: 12px 16px; }
/* 下拉框留够宽度：能完整显示 12 个汉字，不用截断 */
.form select { min-width: 212px; }
.form input, .form textarea { min-width: 160px; }
.toolbar select { min-width: 180px; }
/* 下拉 + 旁边按钮（如“+ 新客户”）：按钮放不下时自动换行，不挤压下拉 */
.row-flex { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row-flex > select { flex: 1 1 200px; }
.row-flex > input { flex: 1 1 160px; }
.row-flex > .btn { flex: 0 0 auto; }
.form .f { display: flex; flex-direction: column; gap: 4px; }
.form .f.wide { grid-column: 1 / -1; }
/* 表单标题（客户、备注、日期等）统一加大加粗 */
label { color: #333; font-weight: 700; }
.form label, .lbl { font-size: 15px; }
.login label { font-size: 14px; }
.perm-tbl label { font-weight: 400; }
.req::after { content: " *"; color: var(--danger); }
.hint { color: var(--muted); font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; user-select: none; }
.check input { height: auto; }

/* 表格 */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; background: #fff; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.tbl th { background: #f7f8fa; font-weight: 700; color: #333; position: sticky; top: 0; }
.tbl tr:hover td { background: #fafbfc; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.wrap { white-space: normal; min-width: 160px; }
.tbl tr.void td { color: #aaa; text-decoration: line-through; }
.tbl tr.void td.ops { text-decoration: none; }
.tbl tr.sum td { font-weight: bold; background: #f7f8fa; }
.tbl .ops { display: flex; gap: 6px; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* 明细行编辑 */
.lines .tbl input, .lines .tbl select { width: 100%; }
.lines .tbl td { padding: 6px; }

/* 标签 */
.tag { display: inline-block; padding: 0 8px; line-height: 20px; border-radius: 10px; font-size: 12px; background: #eef1f5; color: #555; }
.tag.ok { background: #e3f6eb; color: var(--ok); }
.tag.warn { background: #fff3e0; color: var(--warn); }
.tag.danger { background: #fdecec; color: var(--danger); }
.tag.blue { background: #e8f1ff; color: var(--primary); }
.red { color: var(--danger); }
.green { color: var(--ok); }
.muted { color: var(--muted); }
.big { font-size: 18px; font-weight: bold; }

/* 统计卡 */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.stat .k { color: #555; font-size: 14px; font-weight: 700; }
.stat .v { font-size: 22px; font-weight: bold; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { color: var(--muted); font-size: 12px; margin-top: 2px; }

/* 合计栏 */
.totalbar { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; padding: 12px 0 0; }
.totalbar .amt { font-size: 22px; font-weight: bold; color: var(--danger); }

/* 弹窗 */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-start; justify-content: center; z-index: 100; padding: 50px 12px; overflow-y: auto; }
.dlg { background: #fff; border-radius: 10px; width: 100%; max-width: 560px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.dlg.wide { max-width: 900px; }
.dlg .hd { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: bold; font-size: 15px; display: flex; justify-content: space-between; }
.dlg .hd button { border: 0; background: none; font-size: 20px; line-height: 1; cursor: pointer; color: #999; }
.dlg .bd { padding: 16px 18px; }
.dlg .ft { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 6px 16px; margin-bottom: 12px; }
.kv div span { color: #555; font-weight: 700; }

/* 提示 */
#toast { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
#toast div { padding: 9px 18px; border-radius: 6px; background: #333; color: #fff; box-shadow: 0 4px 12px rgba(0,0,0,.15); }
#toast div.err { background: var(--danger); }
#toast div.ok { background: var(--ok); }

/* 登录 */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1e2633, #1677ff); }
.login .box { background: #fff; padding: 32px; border-radius: 12px; width: 340px; }
.login h2 { margin: 0 0 20px; text-align: center; }
.login .f { margin-bottom: 14px; display: flex; flex-direction: column; gap: 4px; }
.login input { height: 38px; }
.login .btn { width: 100%; height: 40px; }

/* 权限勾选 */
.perm-tbl td, .perm-tbl th { text-align: center; }
.perm-tbl td:first-child, .perm-tbl th:first-child { text-align: left; }

/* “+ 新增/新建”类按钮：加粗标红 */
.btn-add { color: var(--danger); border-color: #f0b4b6; font-weight: 700; }
.btn-add:hover { background: #fdecec; color: var(--danger); border-color: var(--danger); }
.btn.pri.btn-add { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.pri.btn-add:hover { background: #c93a3e; color: #fff; }
.btn-add .plus { font-weight: 700; }

/* 模式切换 */
.seg { display: inline-flex; border: 1px solid #d0d5dd; border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 0 10px; height: 30px; cursor: pointer; }
.seg button.on { background: var(--primary); color: #fff; }


/* 底部版权 */
.foot { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 4px 10px; padding: 14px 16px; color: #5f6670; font-size: 12px; border-top: 1px solid var(--line); background: #fff; }
.foot i { font-style: normal; color: #d0d5dd; }
.login { flex-direction: column; gap: 20px; padding: 20px; }
.login .foot { background: none; border: 0; color: rgba(255,255,255,.9); }
.login .foot i { color: rgba(255,255,255,.4); }
.login .box { max-width: 100%; }

/* ---------- 自适应 ---------- */
img, svg { max-width: none; }

/* 平板：侧栏变窄 */
@media (max-width: 1100px) {
  .side { width: 208px; }
  .side .brand { font-size: 13px; padding: 0 10px; }
  .side .grp { font-size: 15px; height: 38px; margin: 8px 8px 5px; }
  .side nav a { padding: 9px 12px 9px 24px; margin: 2px 8px; }
  .form { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .stats { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
}

/* 手机 / 小平板：侧栏抽屉 */
@media (max-width: 860px) {
  .side { position: fixed; left: -260px; top: 0; bottom: 0; width: 246px; height: auto; z-index: 60; transition: left .22s; box-shadow: 2px 0 14px rgba(0,0,0,.28); }
  .side.open { left: 0; }
  .side-mask { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 55; }
  body.side-open .side-mask { display: block; }
  body.side-open { overflow: hidden; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; margin: 0 6px 0 -6px; }
  .side .grp { height: 44px; font-size: 17px; }
  .side nav a { padding: 12px 14px 12px 28px; font-size: 15px; }
  .side nav a.on { padding-left: 25px; }
  .top { padding: 0 12px; }
  .content { padding: 12px 12px calc(16px + env(safe-area-inset-bottom)); }
  .card { padding: 12px; border-radius: 6px; }
}

/* 手机 */
@media (max-width: 640px) {
  body { font-size: 15px; }
  .top { height: 50px; }
  .top .title { font-size: 15px; }
  .top .me .who { display: none; }
  .top .me a { margin-left: 10px; }
  input, select, textarea { height: 40px; font-size: 16px; }   /* 16px 防止 iOS 自动放大 */
  textarea { height: 80px; }
  .btn { height: 38px; }
  .btn.sm { height: 32px; padding: 0 10px; }
  .btn.lg { height: 44px; }
  .form { grid-template-columns: 1fr; gap: 10px; }
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px 12px; }
  .stat .v { font-size: 18px; }
  .toolbar { gap: 6px; }
  .toolbar > input, .toolbar > select { flex: 1 1 140px; }
  .toolbar > input[type=date] { flex: 1 1 130px; }
  .toolbar .sp { flex-basis: 100%; height: 0; }
  .toolbar .lbl { width: 100%; }
  .totalbar { gap: 10px; }
  .totalbar .btn.lg { width: 100%; }
  .totalbar .sp { display: none; }
  .kv { grid-template-columns: 1fr; }

  /* 列表表格变卡片 */
  .tbl.cards thead { display: none; }
  .tbl.cards, .tbl.cards tbody, .tbl.cards tr, .tbl.cards td { display: block; width: 100%; }
  .tbl.cards tr { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 10px; padding: 6px 10px; background: #fff; }
  .tbl.cards tr.sum { background: #f7f8fa; }
  .tbl.cards td { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 6px 0; border-bottom: 1px dashed #eef0f3; white-space: normal; text-align: right; }
  .tbl.cards td:last-child { border-bottom: 0; }
  .tbl.cards td::before { content: attr(data-label); color: #555; font-weight: 700; text-align: left; flex-shrink: 0; max-width: 45%; }
  .tbl.cards td[data-label=""]::before { display: none; }
  .tbl.cards td[data-label=""] { justify-content: flex-end; }
  .tbl.cards td:empty { display: none; }
  .tbl.cards td.wrap { min-width: 0; }
  .tbl.cards td.ops { justify-content: flex-end; flex-wrap: wrap; }
  .tbl.cards tr:hover td { background: none; }
  .tbl-wrap { overflow: visible; }
  .tbl-wrap:has(svg), .tbl-wrap:has(.perm-tbl) { overflow-x: auto; }

  /* 开单明细行变卡片 */
  .lines .tbl thead { display: none; }
  .lines .tbl, .lines .tbl tbody { display: block; }
  .lines .tbl tr { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; position: relative; }
  .lines .tbl td { display: flex; flex-direction: column; gap: 3px; padding: 0; border: 0; white-space: normal; }
  .lines .tbl td::before { content: attr(data-label); color: #555; font-size: 13px; font-weight: 700; }
  .lines .tbl td.full { grid-column: 1 / -1; padding-right: 50px; }
  .lines .tbl td.num { text-align: left; font-weight: bold; }
  .lines .tbl td.del { position: absolute; top: 10px; right: 10px; }
  .lines .tbl td.del::before { display: none; }
  .lines .tbl .seg { display: flex; }
  .lines .tbl .seg button { flex: 1; height: 38px; }

  /* 送货弹窗里的明细表 */
  .dlg .tbl input { width: 100% !important; }

  /* 弹窗占满屏幕 */
  .mask { padding: 0; align-items: stretch; }
  .dlg, .dlg.wide { max-width: none; min-height: 100%; border-radius: 0; display: flex; flex-direction: column; }
  .dlg .bd { flex: 1; padding: 12px; }
  .dlg .hd { position: sticky; top: 0; background: #fff; z-index: 2; }
  .dlg .ft { position: sticky; bottom: 0; background: #fff; flex-wrap: wrap; }
  .dlg .ft .btn { flex: 1 1 auto; }


  /* 手机：开单页合计栏吸底，快捷按钮两列 */
  .card:has(> .totalbar) .totalbar, .card > .totalbar:has(.btn.lg) { position: sticky; bottom: 0; background: #fff; margin: 0 -12px -12px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); box-shadow: 0 -4px 10px rgba(0,0,0,.05); z-index: 5; }
  .card > .toolbar:has(> .btn.lg) { display: grid; grid-template-columns: 1fr 1fr; }
  .card > .toolbar > .btn.lg { width: 100%; padding: 0 8px; }
  .stat .v { overflow-wrap: anywhere; }
  .lines .tbl td.full .hint { margin-top: 2px; }
  .login .box { padding: 24px 20px; }
  .foot { flex-direction: column; gap: 2px; }
  .foot i { display: none; }
  #toast { left: 12px; right: 12px; transform: none; }
}

@media print {
  .side, .top, .foot, .side-mask, .toolbar { display: none !important; }
  .content { padding: 0; }
}
