* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, "Microsoft YaHei", "PingFang SC", sans-serif; font-size: 13px; color: #1f2d3d; background: #f0f2f5; }
:root { --primary: #2b5aac; --primary-d: #1f3f7a; --line: #e4e7ed; --bg: #f0f2f5; --side: #1f2937; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 13px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; outline: none; }
input:focus, select:focus { border-color: var(--primary); }
.btn { background: var(--primary); color: #fff; border: none; padding: 7px 16px; border-radius: 4px; }
.btn:hover { background: var(--primary-d); }
.btn-mini { background: #fff; color: var(--primary); border: 1px solid var(--primary); padding: 4px 10px; border-radius: 4px; }
.btn-ghost { background: #fff; border: 1px solid var(--line); padding: 6px 14px; border-radius: 4px; }
.btn-danger { background: #e35d6a; color: #fff; border: none; padding: 6px 12px; border-radius: 4px; }
.btn-success { background: #2a9d54; color: #fff; border: none; padding: 6px 12px; border-radius: 4px; }

/* 登录 */
#login-view { position: fixed; inset: 0; background: linear-gradient(135deg, #2b5aac, #1f3f7a); display: flex; align-items: center; justify-content: center; }
.login-box { width: 320px; background: #fff; border-radius: 8px; padding: 36px 32px; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.login-logo { font-size: 22px; font-weight: 700; color: var(--primary); text-align: center; }
.login-sub { font-size: 12px; color: #888; text-align: center; margin: 6px 0 24px; }
.login-box input { width: 100%; margin-bottom: 14px; }
.login-box button { width: 100%; padding: 9px; font-size: 15px; margin-top: 4px; }
#login-err { color: #e35d6a; text-align: center; margin-top: 10px; min-height: 18px; }

/* 框架 */
#app-view { display: flex; height: 100vh; }
.sidebar { width: 230px; background: var(--side); color: #cbd5e1; display: flex; flex-direction: column; }
.logo { color: #fff; font-size: 18px; font-weight: 700; padding: 18px 16px; border-bottom: 1px solid #374151; }
.sidebar ul { list-style: none; overflow-y: auto; flex: 1; }
.sidebar .group { border-bottom: 1px solid #374151; }
.sidebar .group-title { padding: 13px 16px 13px 18px; color: #cbd5e1; font-size: 14px; font-weight: 600; letter-spacing: .3px; display: flex; align-items: center; gap: 8px; cursor: pointer; transition: background .15s, color .15s; }
.sidebar .group-title:hover { background: #374151; color: #fff; }
.sidebar .group-title .nav-icon { width: 16px; height: 16px; flex: 0 0 16px; fill: currentColor; opacity: .9; }
.sidebar .group-title .gt-arrow { margin-left: auto; font-size: 10px; opacity: .7; transition: transform .2s; }
.sidebar .group.open .gt-arrow { transform: rotate(90deg); }
.sidebar .submenu { overflow: hidden; max-height: 0; transition: max-height .25s ease; }
.sidebar .group.open .submenu { max-height: 600px; }
.sidebar .submenu .item { padding: 10px 16px 10px 42px; cursor: pointer; display: flex; align-items: center; font-size: 14px; transition: background .15s, color .15s; }
.sidebar .submenu .item:hover { background: #374151; color: #fff; }
.sidebar .submenu .item.active { background: var(--primary); color: #fff; }
.sidebar li.item.solo { padding: 13px 16px 13px 18px; font-weight: 600; border-bottom: 1px solid #374151; margin-bottom: 4px; cursor: pointer; display: flex; align-items: center; gap: 8px; transition: background .15s, color .15s; }
.sidebar li.item.solo:hover { background: #374151; color: #fff; }
.sidebar li.item.solo.active { background: var(--primary); color: #fff; }
.sidebar li.item.solo .nav-icon { width: 16px; height: 16px; flex: 0 0 16px; fill: currentColor; opacity: .9; }
.sidebar li.item.solo:hover .nav-icon, .sidebar li.item.solo.active .nav-icon { opacity: 1; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar { height: 48px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; padding: 0 18px; }
.topbar .company { font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .user-info { margin-right: 12px; color: #555; }
.content { flex: 1; overflow-y: auto; padding: 18px; }

/* 页面 */
.page-title { font-size: 16px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; }
.page-title .actions { margin-left: auto; }
.toolbar { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { min-width: 140px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 14px; margin-bottom: 14px; }
.stat-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 16px; }
.stat { flex: 1; min-width: 150px; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 16px; }
.stat .num { font-size: 24px; font-weight: 700; color: var(--primary); }
.stat .label { color: #888; margin-top: 4px; }
.stat.warn .num { color: #e35d6a; }

table { width: 100%; border-collapse: collapse; background: #fff; font-size: 12.5px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { background: #fafbfc; color: #555; font-weight: 600; }
tbody tr:hover { background: #f7f9fc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 1px 7px; border-radius: 3px; font-size: 11px; }
.tag-wait { background: #fff2e0; color: #d97706; }
.tag-done { background: #e3f5e9; color: #2a9d54; }
.tag-cus { background: #e6f0ff; color: #2b5aac; }
.tag-sup { background: #f0e9ff; color: #6d28d9; }
.tag-half { background: #e0ecff; color: #1d4ed8; }
.muted { color: #888; font-size: 12px; }
.readonly { display: inline-block; padding: 6px 8px; color: #333; }
.alloc-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px dashed #eee; }
.alloc-row b { color: #d97706; }

/* 模态框 */
#modal-root { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: none; align-items: flex-start; justify-content: center; padding-top: 60px; z-index: 50; }
.modal { background: #fff; border-radius: 8px; width: 720px; max-width: 94vw; max-height: 84vh; overflow-y: auto; }
.modal-head { padding: 14px 18px; border-bottom: 1px solid var(--line); font-size: 15px; font-weight: 600; display: flex; }
.modal-head .x { margin-left: auto; cursor: pointer; color: #999; }
.modal-body { padding: 18px; }
.modal-foot { padding: 12px 18px; border-top: 1px solid var(--line); text-align: right; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.form-grid label { display: block; color: #666; margin-bottom: 4px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid input, .form-grid select { width: 100%; }

/* 开单明细 */
.bill-items { width: 100%; margin: 10px 0; }
.bill-items th, .bill-items td { padding: 5px 6px; }
.bill-items input { width: 100%; padding: 4px 6px; }
.row-actions button { margin-right: 6px; }
.empty { text-align: center; color: #aaa; padding: 30px; }
.pager { margin-top: 10px; color: #888; }
.section-hint { color: #888; font-size: 12px; margin-bottom: 8px; }
.opening-row { background: #fff7e6; font-weight: 600; }

/* ---------- 单据打印 ---------- */
#print-area { display: none; }
.print-doc { color: #000; font-size: 13px; line-height: 1.7; padding: 10px 4px; }
.pd-head { text-align: center; margin-bottom: 12px; }
.pd-company { font-size: 20px; font-weight: 700; }
.pd-title { font-size: 16px; font-weight: 600; margin-top: 4px; letter-spacing: 4px; }
.pd-meta { margin: 8px 0; }
.pd-tab { width: 100%; border-collapse: collapse; margin: 8px 0; }
.pd-tab th, .pd-tab td { border: 1px solid #000; padding: 5px 8px; text-align: left; }
.pd-tab .r, .pd-tab td.r { text-align: right; }
.pd-tab tfoot td { font-weight: 600; }
.pd-sum { margin: 8px 0; font-weight: 600; }
.pd-big { margin: 18px 0; font-size: 15px; font-weight: 600; }
.pd-foot { margin: 8px 0; }
.pd-sign { display: flex; justify-content: space-between; margin-top: 30px; }
.pd-range { margin: 4px 0 14px; font-size: 13px; color: #555; }
.pd-range input[type=date] { padding: 4px 8px; border: 1px solid #d9d9d9; border-radius: 4px; }
.pd-tab .pd-total td { font-weight: 600; background: #fafafa; }

@media print {
  body { background: #fff; }
  #login-view, #app-view, #modal-root { display: none !important; }
  #print-area { display: block !important; padding: 0; }
  .print-doc { font-size: 13px; }
  @page { margin: 12mm; }
}
